From 092fe0793b39c6feb6464bfbd568b050960d62c0 Mon Sep 17 00:00:00 2001 From: Jussi Kukkonen Date: Wed, 2 Mar 2016 15:47:49 +0200 Subject: [PATCH] Port to Gtk3 Some unused (or not useful) code was removed, functionality should stay the same, although applet now loads icons based on actual size available to it. Code still contains quite a few uses of deprecated API. Upstream-Status: Submitted Signed-off-by: Jussi Kukkonen --- applet/agent.c | 3 +-- applet/main.c | 43 ------------------------------ applet/status.c | 74 +++++++++++++++++++++++++++++++++------------------ configure.ac | 3 +-- properties/ethernet.c | 14 +++++----- properties/main.c | 2 +- properties/wifi.c | 12 ++++----- 7 files changed, 64 insertions(+), 87 deletions(-) diff --git a/applet/agent.c b/applet/agent.c index 65bed08..04fe86a 100644 --- a/applet/agent.c +++ b/applet/agent.c @@ -126,7 +126,6 @@ static void request_input_dialog(GHashTable *request, gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); gtk_window_set_keep_above(GTK_WINDOW(dialog), TRUE); gtk_window_set_urgency_hint(GTK_WINDOW(dialog), TRUE); - gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); input->dialog = dialog; gtk_dialog_add_button(GTK_DIALOG(dialog), @@ -139,7 +138,7 @@ static void request_input_dialog(GHashTable *request, gtk_table_set_row_spacings(GTK_TABLE(table), 4); gtk_table_set_col_spacings(GTK_TABLE(table), 20); gtk_container_set_border_width(GTK_CONTAINER(table), 12); - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), table); + gtk_container_add(GTK_CONTAINER(gtk_dialog_get_content_area (GTK_DIALOG(dialog))), table); label = gtk_label_new(_("Please provide some network information:")); gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.0); diff --git a/applet/main.c b/applet/main.c index c7b3c7f..f2ce46b 100644 --- a/applet/main.c +++ b/applet/main.c @@ -157,46 +157,6 @@ 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[] = { @@ -204,9 +164,6 @@ static void about_callback(GtkWidget *item, gpointer user_data) 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"), diff --git a/applet/status.c b/applet/status.c index aed6f1e..6ecbf3a 100644 --- a/applet/status.c +++ b/applet/status.c @@ -30,13 +30,14 @@ static gboolean available = FALSE; static GtkStatusIcon *statusicon = NULL; +static gint icon_size = 0; static GdkPixbuf *pixbuf_load(GtkIconTheme *icontheme, const gchar *name) { GdkPixbuf *pixbuf; GError *error = NULL; - pixbuf = gtk_icon_theme_load_icon(icontheme, name, 22, 0, &error); + pixbuf = gtk_icon_theme_load_icon(icontheme, name, icon_size, 0, &error); if (pixbuf == NULL) { g_warning("Missing icon %s: %s", name, error->message); @@ -102,8 +103,6 @@ static void icon_animation_start(IconAnimation *animation, { available = TRUE; - gtk_status_icon_set_tooltip(statusicon, NULL); - animation->start = start; animation->end = (end == 0) ? animation->count - 1 : end; @@ -120,8 +119,6 @@ static void icon_animation_stop(IconAnimation *animation) { available = TRUE; - gtk_status_icon_set_tooltip(statusicon, NULL); - if (animation->id > 0) g_source_remove(animation->id); @@ -190,6 +187,42 @@ static GdkPixbuf *pixbuf_none; static GdkPixbuf *pixbuf_wired; static GdkPixbuf *pixbuf_signal[5]; +static void +load_icons (gint size) +{ + // educated guess to preload correct size + if (size == 0) + size = 34; + + if (icon_size == size) + return; + + icon_size = size; + + if(pixbuf_none) + status_cleanup(); + + g_debug ("Loading icons at size %d", icon_size); + animation = icon_animation_load(icontheme, "connman-connecting", 33); + pixbuf_signal[0] = pixbuf_load(icontheme, "connman-signal-01"); + pixbuf_signal[1] = pixbuf_load(icontheme, "connman-signal-02"); + pixbuf_signal[2] = pixbuf_load(icontheme, "connman-signal-03"); + pixbuf_signal[3] = pixbuf_load(icontheme, "connman-signal-04"); + pixbuf_signal[4] = pixbuf_load(icontheme, "connman-signal-05"); + + pixbuf_none = pixbuf_load(icontheme, "connman-type-none"); + pixbuf_wired = pixbuf_load(icontheme, "connman-type-wired"); + pixbuf_notifier = pixbuf_load(icontheme, "connman-notifier-unavailable"); +} + +static gboolean +size_changed_cb (GtkStatusIcon *statusicon, + gint size, + gpointer user_data) +{ + load_icons (size); +} + int status_init(StatusCallback activate, GtkWidget *popup) { GdkScreen *screen; @@ -204,17 +237,9 @@ int status_init(StatusCallback activate, GtkWidget *popup) gtk_icon_theme_append_search_path(icontheme, ICONDIR); - animation = icon_animation_load(icontheme, "connman-connecting", 33); - - pixbuf_signal[0] = pixbuf_load(icontheme, "connman-signal-01"); - pixbuf_signal[1] = pixbuf_load(icontheme, "connman-signal-02"); - pixbuf_signal[2] = pixbuf_load(icontheme, "connman-signal-03"); - pixbuf_signal[3] = pixbuf_load(icontheme, "connman-signal-04"); - pixbuf_signal[4] = pixbuf_load(icontheme, "connman-signal-05"); - - pixbuf_none = pixbuf_load(icontheme, "connman-type-none"); - pixbuf_wired = pixbuf_load(icontheme, "connman-type-wired"); - pixbuf_notifier = pixbuf_load(icontheme, "connman-notifier-unavailable"); + g_signal_connect (statusicon, "size-changed", + G_CALLBACK(size_changed_cb), NULL); + load_icons (gtk_status_icon_get_size (statusicon)); if (activate != NULL) g_signal_connect(statusicon, "activate", @@ -231,17 +256,18 @@ void status_cleanup(void) int i; icon_animation_free(animation); + animation = NULL; for (i = 0; i < 5; i++) - g_object_unref(pixbuf_signal[i]); + g_clear_object(&pixbuf_signal[i]); - g_object_unref(pixbuf_none); - g_object_unref(pixbuf_wired); - g_object_unref(pixbuf_notifier); + g_clear_object(&pixbuf_none); + g_clear_object(&pixbuf_wired); + g_clear_object(&pixbuf_notifier); - g_object_unref(icontheme); + g_clear_object(&icontheme); - g_object_unref(statusicon); + g_clear_object(&statusicon); } void status_unavailable(void) @@ -251,8 +277,6 @@ void status_unavailable(void) available = FALSE; gtk_status_icon_set_from_pixbuf(statusicon, pixbuf_notifier); - gtk_status_icon_set_tooltip(statusicon, - "Connection Manager daemon is not running"); gtk_status_icon_set_visible(statusicon, TRUE); } @@ -299,7 +323,6 @@ static void set_ready(gint signal) if (signal < 0) { gtk_status_icon_set_from_pixbuf(statusicon, pixbuf_wired); - gtk_status_icon_set_tooltip(statusicon, NULL); return; } @@ -311,7 +334,6 @@ static void set_ready(gint signal) index = 4; gtk_status_icon_set_from_pixbuf(statusicon, pixbuf_signal[index]); - gtk_status_icon_set_tooltip(statusicon, NULL); } struct timeout_data { diff --git a/configure.ac b/configure.ac index b972e07..a4dad5d 100644 --- a/configure.ac +++ b/configure.ac @@ -55,8 +55,7 @@ AC_SUBST(DBUS_LIBS) DBUS_BINDING_TOOL="dbus-binding-tool" AC_SUBST(DBUS_BINDING_TOOL) -PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.8, dummy=yes, - AC_MSG_ERROR(gtk+ >= 2.8 is required)) +PKG_CHECK_MODULES(GTK, gtk+-3.0) AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) diff --git a/properties/ethernet.c b/properties/ethernet.c index 31db7a0..0b6b423 100644 --- a/properties/ethernet.c +++ b/properties/ethernet.c @@ -82,7 +82,7 @@ void add_ethernet_switch_button(GtkWidget *mainbox, GtkTreeIter *iter, gtk_container_set_border_width(GTK_CONTAINER(vbox), 24); gtk_box_pack_start(GTK_BOX(mainbox), vbox, FALSE, FALSE, 0); - table = gtk_table_new(1, 1, TRUE); + table = gtk_table_new(1, 1, FALSE); gtk_table_set_row_spacings(GTK_TABLE(table), 10); gtk_table_set_col_spacings(GTK_TABLE(table), 10); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); @@ -136,7 +136,7 @@ void add_ethernet_service(GtkWidget *mainbox, GtkTreeIter *iter, struct config_d gtk_container_set_border_width(GTK_CONTAINER(vbox), 24); gtk_box_pack_start(GTK_BOX(mainbox), vbox, FALSE, FALSE, 0); - table = gtk_table_new(5, 5, TRUE); + table = gtk_table_new(5, 5, FALSE); gtk_table_set_row_spacings(GTK_TABLE(table), 10); gtk_table_set_col_spacings(GTK_TABLE(table), 10); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); @@ -144,9 +144,9 @@ void add_ethernet_service(GtkWidget *mainbox, GtkTreeIter *iter, struct config_d label = gtk_label_new(_("Configuration:")); gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 0, 1); - combo = gtk_combo_box_new_text(); - gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "DHCP"); - gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "MANUAL"); + combo = gtk_combo_box_text_new(); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "DHCP"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "MANUAL"); gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combo), separator_function, NULL, NULL); gtk_table_attach_defaults(GTK_TABLE(table), combo, 2, 4, 0, 1); @@ -219,7 +219,7 @@ void update_ethernet_ipv4(struct config_data *data, guint policy) case CONNMAN_POLICY_DHCP: gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); for (i = 0; i < 3; i++) { - gtk_entry_set_editable(GTK_ENTRY(entry[i]), 0); + gtk_editable_set_editable(GTK_EDITABLE(entry[i]), 0); gtk_widget_set_sensitive(entry[i], 0); gtk_entry_set_text(GTK_ENTRY(entry[i]), _("")); } @@ -227,7 +227,7 @@ void update_ethernet_ipv4(struct config_data *data, guint policy) case CONNMAN_POLICY_MANUAL: gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 1); for (i = 0; i < 3; i++) { - gtk_entry_set_editable(GTK_ENTRY(entry[i]), 1); + gtk_editable_set_editable(GTK_EDITABLE(entry[i]), 1); gtk_widget_set_sensitive(entry[i], 1); } break; diff --git a/properties/main.c b/properties/main.c index c05f443..6f76361 100644 --- a/properties/main.c +++ b/properties/main.c @@ -429,7 +429,7 @@ static GtkWidget *create_interfaces(GtkWidget *window) scrolled = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_OUT); gtk_box_pack_start(GTK_BOX(hbox), scrolled, FALSE, TRUE, 0); diff --git a/properties/wifi.c b/properties/wifi.c index bd325ef..a5827e0 100644 --- a/properties/wifi.c +++ b/properties/wifi.c @@ -125,7 +125,7 @@ void add_wifi_switch_button(GtkWidget *mainbox, GtkTreeIter *iter, gtk_container_set_border_width(GTK_CONTAINER(vbox), 24); gtk_box_pack_start(GTK_BOX(mainbox), vbox, FALSE, FALSE, 0); - table = gtk_table_new(1, 1, TRUE); + table = gtk_table_new(1, 1, FALSE); gtk_table_set_row_spacings(GTK_TABLE(table), 10); gtk_table_set_col_spacings(GTK_TABLE(table), 10); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0); @@ -185,9 +185,9 @@ static void wifi_ipconfig(GtkWidget *table, struct config_data *data, GtkTreeIte gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 3, 4); data->ipv4.label[0] = label; - combo = gtk_combo_box_new_text(); - gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "DHCP"); - gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Manual"); + combo = gtk_combo_box_text_new(); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "DHCP"); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "Manual"); gtk_combo_box_set_row_separator_func(GTK_COMBO_BOX(combo), separator_function, NULL, NULL); @@ -335,14 +335,14 @@ void update_wifi_ipv4(struct config_data *data, guint policy) case CONNMAN_POLICY_DHCP: gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); for (i = 0; i < 3; i++) { - gtk_entry_set_editable(GTK_ENTRY(entry[i]), 0); + gtk_editable_set_editable(GTK_EDITABLE(entry[i]), 0); gtk_widget_set_sensitive(entry[i], 0); } break; case CONNMAN_POLICY_MANUAL: gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 1); for (i = 0; i < 3; i++) { - gtk_entry_set_editable(GTK_ENTRY(entry[i]), 1); + gtk_editable_set_editable(GTK_EDITABLE(entry[i]), 1); gtk_widget_set_sensitive(entry[i], 1); } break; -- 2.1.4