aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDongxiao Xu <dongxiao.xu@intel.com>2011-03-25 15:19:44 +0800
committerSamuel Ortiz <sameo@linux.intel.com>2011-03-25 12:19:49 +0100
commitc51cfafba7f4182d9e9f0d5922089193b3a47bd7 (patch)
treeb52615f44354ead7463b0ba409eb6f9ec22c05fc
parent3c7883e6562acfe87e3ab01903516f2b116e953f (diff)
downloadconnman-gnome-c51cfafba7f4182d9e9f0d5922089193b3a47bd7.tar.gz
Enable connman-gnome applet
Let connman-applet have the ability to pop up connman-properties and show "About"
-rw-r--r--Makefile.am2
-rw-r--r--applet/main.c94
2 files changed, 93 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index 280e4de..77520e2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
-SUBDIRS = po icons common properties
+SUBDIRS = po icons common properties applet
EXTRA_DIST = intltool-extract.in intltool-update.in intltool-merge.in
diff --git a/applet/main.c b/applet/main.c
index 73c915e..224e2fd 100644
--- a/applet/main.c
+++ b/applet/main.c
@@ -47,10 +47,12 @@ static void service_property_changed(DBusGProxy *proxy, const char *property,
if (g_strcmp0(type, "ethernet") == 0)
global_strength = -1;
+ else if (g_strcmp0(type, "wifi") == 0)
+ global_strength = g_value_get_uchar(value);
} else if (g_str_equal(property, "State") == TRUE) {
const gchar *state = g_value_get_string(value);
- if (g_strcmp0(state, "ready") == 0)
+ if (g_strcmp0(state, "ready") == 0 || g_strcmp0(state, "online") == 0)
global_ready = TRUE;
else
global_ready = FALSE;
@@ -142,6 +144,94 @@ static void name_owner_changed(DBusGProxy *proxy, const char *name,
}
}
+static void open_uri(GtkWindow *parent, const char *uri)
+{
+ GtkWidget *dialog;
+ GdkScreen *screen;
+ GError *error = NULL;
+ gchar *cmdline;
+
+ screen = gtk_window_get_screen(parent);
+
+ cmdline = g_strconcat("xdg-open ", uri, NULL);
+
+ if (gdk_spawn_command_line_on_screen(screen,
+ cmdline, &error) == FALSE) {
+ dialog = gtk_message_dialog_new(parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE, "%s", error->message);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ g_error_free(error);
+ }
+
+ g_free(cmdline);
+}
+
+static void about_url_hook(GtkAboutDialog *dialog,
+ const gchar *url, gpointer data)
+{
+ open_uri(GTK_WINDOW(dialog), url);
+}
+
+static void about_email_hook(GtkAboutDialog *dialog,
+ const gchar *email, gpointer data)
+{
+ gchar *uri;
+
+ uri = g_strconcat("mailto:", email, NULL);
+ open_uri(GTK_WINDOW(dialog), uri);
+ g_free(uri);
+}
+
+static void about_callback(GtkWidget *item, gpointer user_data)
+{
+ const gchar *authors[] = {
+ "Marcel Holtmann <marcel@holtmann.org>",
+ NULL
+ };
+
+ gtk_about_dialog_set_url_hook(about_url_hook, NULL, NULL);
+ gtk_about_dialog_set_email_hook(about_email_hook, NULL, NULL);
+
+ gtk_show_about_dialog(NULL, "version", VERSION,
+ "copyright", "Copyright \xc2\xa9 2008 Intel Corporation",
+ "comments", _("A connection manager for the GNOME desktop"),
+ "authors", authors,
+ "translator-credits", _("translator-credits"),
+ "logo-icon-name", "network-wireless", NULL);
+}
+
+static void settings_callback(GtkWidget *item, gpointer user_data)
+{
+ const char *command = "connman-properties";
+
+ if (g_spawn_command_line_async(command, NULL) == FALSE)
+ g_printerr("Couldn't execute command: %s\n", command);
+}
+
+static gboolean menu_callback(GtkMenu *menu)
+{
+ GtkWidget *item;
+
+ item = gtk_separator_menu_item_new();
+ gtk_widget_show(item);
+
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+ item = gtk_image_menu_item_new_from_stock(GTK_STOCK_PREFERENCES, NULL);
+ g_signal_connect(item, "activate", G_CALLBACK(settings_callback), NULL);
+ gtk_widget_show(item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+
+ item = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT, NULL);
+ g_signal_connect(item, "activate", G_CALLBACK(about_callback), NULL);
+ gtk_widget_show(item);
+ gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+
+ return TRUE;
+}
+
+
int main(int argc, char *argv[])
{
DBusGConnection *connection;
@@ -168,7 +258,7 @@ int main(int argc, char *argv[])
return 1;
}
- status_init(NULL, NULL);
+ status_init(menu_callback, NULL);
proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS,
DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS);