Port to GTK+-3
authorRoy Marples <roy@marples.name>
Tue, 17 Jul 2012 22:49:19 +0000 (22:49 +0000)
committerRoy Marples <roy@marples.name>
Tue, 17 Jul 2012 22:49:19 +0000 (22:49 +0000)
configure
src/dhcpcd-gtk/dhcpcd-gtk.h
src/dhcpcd-gtk/main.c
src/dhcpcd-gtk/menu.c
src/dhcpcd-gtk/prefs.c
src/dhcpcd-gtk/wpa.c

index 06c4ae287674d92a1cc939df89e10033e81bfbae..487e71512eb6f216e51564ed8ce60e3802870a3f 100755 (executable)
--- a/configure
+++ b/configure
@@ -274,7 +274,20 @@ echo "DBUS_LIBS=   $DBUS_LIBS" >>$CONFIG_MK
 
 UI=
 if [ "$WITH_GTK" = yes -o -z "$WITH_GTK" ]; then
-       PKG="dbus-1 gtk+-2.0"
+       if pkg-config --cflags gtk+-3.0 >/dev/null 2>&1; then
+               WITH_GTK="gtk+-3.0"
+       elif pkg-config --cflags gtk+-2.0 >/dev/null 2>&1; then
+               WITH_GTK="gtk+-2.0"
+       fi
+elif [ -n "$WITH_GTK" -a "$WITH_GTK" != no ]; then
+       if ! pkg-config --cflags $WITH_GTK >/dev/null; then
+               echo "$0: no suitable GTK+ library has been found" >&2
+               exit 1
+       fi
+fi
+
+if [ -n "$WITH_GTK" ]; then
+       PKG="dbus-1 $WITH_GTK"
        if [ "$NOTIFY" = yes ]; then
                PKG="$PKG${PKG:+ }libnotify"
                echo "NOTIFY=           -DNOTIFY" >>$CONFIG_MK
@@ -291,7 +304,7 @@ if [ "$WITH_GTK" = yes -o -z "$WITH_GTK" ]; then
 fi
 
 if [ -z "$UI" ]; then
-       echo "no UI is available, not building." >&2
+       echo "$0: no UI is available, not building." >&2
        exit 1
 fi
 echo "UI=              $UI" >>config.mk
index 610b14eed0e954055c08d9bb9e7d5dfa9171cf68..6025595ec25852bfcb93eb41855eac4f86a06ad4 100644 (file)
@@ -81,4 +81,9 @@ void dhcpcd_prefs_show(DHCPCD_CONNECTION *con);
 void dhcpcd_prefs_abort(void);
 
 bool wpa_configure(DHCPCD_CONNECTION *, DHCPCD_IF *, DHCPCD_WI_SCAN *);
+
+#if GTK_MAJOR_VERSION == 2
+GtkWidget *gtk_box_new(GtkOrientation, gint);
+#endif
+
 #endif
index 332d205be339ad1c844f417a0d0e71e9edd8741e..1a349e9af20cf217ab6efc310ac06698cc5a7b78 100644 (file)
@@ -179,7 +179,7 @@ update_online(DHCPCD_CONNECTION *con, bool showif)
                            "network-offline");
                }
        }
-       gtk_status_icon_set_tooltip(status_icon, msgs);
+       gtk_status_icon_set_tooltip_text(status_icon, msgs);
        g_free(msgs);
 }
 
@@ -219,11 +219,14 @@ notify(const char *title, const char *msg, const char *icon)
                g_message("%s", *m);
        g_strfreev(msgs);
 
-#if NOTIFY_CHECK_VERSION(0,7,0)
-       nn = nn = notify_notification_new(title, msg, icon);
-#else
        if (nn != NULL)
                notify_notification_close(nn, NULL);
+
+#if NOTIFY_CHECK_VERSION(0,7,0)
+       nn = notify_notification_new(title, msg, icon);
+       notify_notification_set_hint(nn, "transient",
+           g_variant_new_boolean(TRUE));
+#else
        if (gtk_status_icon_get_visible(status_icon))
                nn = notify_notification_new_with_status_icon(title,
                    msg, icon, status_icon);
@@ -284,7 +287,7 @@ status_cb(DHCPCD_CONNECTION *con, const char *status, _unused void *data)
                }
                gtk_status_icon_set_from_icon_name(status_icon,
                    "network-offline");
-               gtk_status_icon_set_tooltip(status_icon, msg);
+               gtk_status_icon_set_tooltip_text(status_icon, msg);
                notify(_("No network"), msg, "network-offline");
                dhcpcd_prefs_abort();
                while (wi_scans) {
@@ -444,8 +447,8 @@ main(int argc, char *argv[])
        gtk_icon_theme_append_search_path(gtk_icon_theme_get_default(),
            ICONDIR);
        status_icon = gtk_status_icon_new_from_icon_name("network-offline");
-       
-       gtk_status_icon_set_tooltip(status_icon,
+
+       gtk_status_icon_set_tooltip_text(status_icon,
            _("Connecting to dhcpcd ..."));
        gtk_status_icon_set_visible(status_icon, true);
 
@@ -460,7 +463,8 @@ main(int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       gtk_status_icon_set_tooltip(status_icon, _("Triggering dhcpcd ..."));
+       gtk_status_icon_set_tooltip_text(status_icon,
+           _("Triggering dhcpcd ..."));
        online = false;
 
        if (!dhcpcd_command(con, "GetVersion", NULL, &version)) {
index 6345af6c0cf899c3b664435331ed42a08202f65c..16c1d5995570af9ce77fd6adc27ecb0607213e36 100644 (file)
@@ -31,7 +31,7 @@ static const char *copyright = "Copyright (c) 2009-2012 Roy Marples";
 static const char *authors[] = { "Roy Marples <roy@marples.name>", NULL };
 
 static void
-on_pref(_unused GtkObject *o, gpointer data)
+on_pref(_unused GObject *o, gpointer data)
 {
        dhcpcd_prefs_show((DHCPCD_CONNECTION *)data);
 }
@@ -42,6 +42,7 @@ on_quit(void)
        gtk_main_quit();
 }
 
+#if GTK_MAJOR_VERSION == 2
 static void
 url_show(GtkAboutDialog *dialog, const char *url)
 {
@@ -61,11 +62,13 @@ email_hook(GtkAboutDialog *dialog, const char *url, _unused gpointer data)
        g_free(address);
 }
 
+
 static void
 url_hook(GtkAboutDialog *dialog, const char *url, _unused gpointer data)
 {
        url_show(dialog, url);
 }
+#endif
 
 static void
 ssid_hook(_unused GtkMenuItem *item, gpointer data)
@@ -83,8 +86,10 @@ static void
 on_about(_unused GtkMenuItem *item)
 {
        gtk_window_set_default_icon_name("network-transmit-receive");
+#if GTK_MAJOR_VERSION == 2
        gtk_about_dialog_set_email_hook(email_hook, NULL, NULL);
        gtk_about_dialog_set_url_hook(url_hook, NULL, NULL);
+#endif
        gtk_show_about_dialog(NULL,
            "version", VERSION,
            "copyright", copyright,
@@ -113,7 +118,7 @@ add_scans(WI_SCAN *scan)
                item = gtk_check_menu_item_new();
                gtk_check_menu_item_set_draw_as_radio(
                        GTK_CHECK_MENU_ITEM(item), true); 
-               box = gtk_hbox_new(false, 6);
+               box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
                gtk_container_add(GTK_CONTAINER(item), box); 
                label = gtk_label_new(wis->ssid);
                gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
@@ -244,3 +249,16 @@ menu_init(GtkStatusIcon *icon, DHCPCD_CONNECTION *con)
        g_signal_connect(G_OBJECT(icon), "popup_menu",
            G_CALLBACK(on_popup), con);
 }
+
+
+#if GTK_MAJOR_VERSION == 2
+GtkWidget *
+gtk_box_new(GtkOrientation o, gint s)
+{
+
+       if (o == GTK_ORIENTATION_HORIZONTAL)
+               return gtk_hbox_new(false, s);
+       else
+               return gtk_vbox_new(false, s);
+}
+#endif
index 7bf4868dcaf841aa4419bf87e8c0b458bf70912f..45148f846e4f560a81662478eb2b0cd6f170d85f 100644 (file)
@@ -365,7 +365,7 @@ entry_lost_focus(GtkEntry *entry)
 }
 
 static void
-on_clear(_unused GtkObject *o, gpointer data)
+on_clear(_unused GtkWidget *o, gpointer data)
 {
        DHCPCD_CONNECTION *con;
 
@@ -379,7 +379,7 @@ on_clear(_unused GtkObject *o, gpointer data)
 }
 
 static void
-on_rebind(_unused GtkWidget *widget, gpointer data)
+on_rebind(_unused GObject *widget, gpointer data)
 {
        DHCPCD_CONNECTION *con;
        DHCPCD_IF *i;
@@ -404,7 +404,7 @@ on_rebind(_unused GtkWidget *widget, gpointer data)
 }
 
 static void
-on_destroy(_unused GtkObject *o, gpointer data)
+on_destroy(_unused GObject *o, gpointer data)
 {
        if (name != NULL) {
                if (make_config(&config))
@@ -436,6 +436,18 @@ dhcpcd_prefs_abort(void)
        dhcpcd_prefs_close();
 }
 
+#if GTK_MAJOR_VERSION == 2
+static GtkWidget *
+gtk_separator_new(GtkOrientation o)
+{
+
+       if (o == GTK_ORIENTATION_HORIZONTAL)
+               return gtk_hseparator_new();
+       else
+               return gtk_vseparator_new();
+}
+#endif
+
 void
 dhcpcd_prefs_show(DHCPCD_CONNECTION *con)
 {
@@ -465,11 +477,11 @@ dhcpcd_prefs_show(DHCPCD_CONNECTION *con)
        gtk_window_set_type_hint(GTK_WINDOW(dialog),
            GDK_WINDOW_TYPE_HINT_DIALOG);
 
-       dialog_vbox = gtk_vbox_new(false, 10);
+       dialog_vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
        gtk_container_set_border_width(GTK_CONTAINER(dialog), 10);
        gtk_container_add(GTK_CONTAINER(dialog), dialog_vbox);
 
-       hbox = gtk_hbox_new(false, 0);
+       hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
        gtk_box_pack_start(GTK_BOX(dialog_vbox), hbox, false, false, 3);
        w = gtk_label_new("Configure:");
        gtk_box_pack_start(GTK_BOX(hbox), w, false, false, 3);
@@ -509,12 +521,12 @@ dhcpcd_prefs_show(DHCPCD_CONNECTION *con)
        g_signal_connect(G_OBJECT(names), "changed",
            G_CALLBACK(names_on_change), con);
        
-       w = gtk_hseparator_new();
+       w = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
        gtk_box_pack_start(GTK_BOX(dialog_vbox), w, true, false, 3);
-       controls = gtk_vbox_new(false, 10);
+       controls = gtk_box_new(GTK_ORIENTATION_VERTICAL, 10);
        gtk_widget_set_sensitive(controls, false);
        gtk_box_pack_start(GTK_BOX(dialog_vbox), controls, true, true, 0);
-       vbox = gtk_vbox_new(false, 3);
+       vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 3);
        gtk_box_pack_start(GTK_BOX(controls), vbox, false, false, 0);
        autoconf = gtk_check_button_new_with_label(
                _("Automatically configure empty options"));
@@ -560,7 +572,7 @@ dhcpcd_prefs_show(DHCPCD_CONNECTION *con)
        attach_label(w, 0, 1, 4, 5);
        attach_entry(dns_search, 1, 2, 4, 5);
 
-       hbox = gtk_hbox_new(false, 10);
+       hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 10);
        gtk_box_pack_start(GTK_BOX(dialog_vbox), hbox, true, true, 3);
        clear = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
        gtk_widget_set_sensitive(clear, false);
@@ -584,3 +596,4 @@ dhcpcd_prefs_show(DHCPCD_CONNECTION *con)
        show_config(NULL);
        gtk_widget_show_all(dialog);
 }
+
index 5fd6f7b19a068bda0f19150e43236cda0182d25f..36ee133aeaaeb8a7586d9a5f71b6ba168e88d626 100644 (file)
@@ -112,9 +112,9 @@ wpa_configure(DHCPCD_CONNECTION *con, DHCPCD_IF *i, DHCPCD_WI_SCAN *s)
            "network-wireless-encrypted");
        gtk_dialog_set_default_response(GTK_DIALOG(dialog),
            GTK_RESPONSE_ACCEPT);
-       vbox = GTK_DIALOG(dialog)->vbox;
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
 
-       hbox = gtk_hbox_new(false, 2);
+       hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
        label = gtk_label_new(_("Pre Shared Key:"));
        gtk_box_pack_start(GTK_BOX(hbox), label, false, false, 0);
        psk = gtk_entry_new();