Typo
[dhcpcd-ui] / menu.c
diff --git a/menu.c b/menu.c
index 54e72493cdf91044543f03c751ae49a1dfe6593b..63cd2db0d588dfb4746896ca1530f865c0148d5e 100644 (file)
--- a/menu.c
+++ b/menu.c
 
 #include "dhcpcd-gtk.h"
 #include "menu.h"
 
 #include "dhcpcd-gtk.h"
 #include "menu.h"
+#include "prefs.h"
+#include "wpa.h"
 
 static const char *copyright = "Copyright (c) 2009 Roy Marples";
 
 static const char *copyright = "Copyright (c) 2009 Roy Marples";
+static const char *authors[] = { "Roy Marples <roy@marples.name>", NULL };
+
+static void
+on_pref(_unused GtkMenuItem *item, _unused gpointer data)
+{
+       dhcpcd_prefs_show();
+}
 
 
-static const char *authors[] = {
-       "Roy Marples <roy@marples.name>",
-       NULL
-};
 
 static void
 on_quit(_unused GtkMenuItem *item, _unused gpointer data)
 
 static void
 on_quit(_unused GtkMenuItem *item, _unused gpointer data)
@@ -71,19 +76,25 @@ url_hook(GtkAboutDialog *dialog, const char *url, _unused gpointer p)
 }
 
 static void
 }
 
 static void
+ssid_hook(_unused GtkMenuItem *item, gpointer data)
+{
+       wpa_configure((const struct if_ap *)data);
+}
+
+static void
 on_about(_unused GtkMenuItem *item, _unused gpointer data)
 {
        gtk_window_set_default_icon_name(GTK_STOCK_NETWORK);
        gtk_about_dialog_set_email_hook(email_hook, NULL, NULL);
        gtk_about_dialog_set_url_hook(url_hook, NULL, NULL);
        gtk_show_about_dialog(NULL,
 on_about(_unused GtkMenuItem *item, _unused gpointer data)
 {
        gtk_window_set_default_icon_name(GTK_STOCK_NETWORK);
        gtk_about_dialog_set_email_hook(email_hook, NULL, NULL);
        gtk_about_dialog_set_url_hook(url_hook, NULL, NULL);
        gtk_show_about_dialog(NULL,
-                             "version", VERSION,
-                             "copyright", copyright,
-                             "website-label", "dhcpcd Website",
-                             "website", "http://roy.marples.name/projects/dhcpcd",
-                             "authors", authors,
-                             "logo-icon-name", GTK_STOCK_NETWORK,
-                             NULL);
+           "version", VERSION,
+           "copyright", copyright,
+           "website-label", "dhcpcd Website",
+           "website", "http://roy.marples.name/projects/dhcpcd",
+           "authors", authors,
+           "logo-icon-name", GTK_STOCK_NETWORK,
+           NULL);
 }
 
 static void
 }
 
 static void
@@ -94,6 +105,8 @@ add_scan_results(GtkMenu *menu, const struct if_msg *ifm)
        GtkWidget *item, *image, *box, *label, *bar;
        double perc;
        int strength;
        GtkWidget *item, *image, *box, *label, *bar;
        double perc;
        int strength;
+       const char *icon;
+       char *tip;
 
        for (gl = ifm->scan_results; gl; gl = gl->next) {
                ifa = (const struct if_ap *)gl->data;
 
        for (gl = ifm->scan_results; gl; gl = gl->next) {
                ifa = (const struct if_ap *)gl->data;
@@ -107,11 +120,11 @@ add_scan_results(GtkMenu *menu, const struct if_msg *ifm)
                if (g_strcmp0(ifm->ssid, ifa->ssid) == 0)
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
                if (ifa->flags == NULL)
                if (g_strcmp0(ifm->ssid, ifa->ssid) == 0)
                        gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
                if (ifa->flags == NULL)
-                       image = gtk_image_new_from_icon_name("network-wireless",
-                                                            GTK_ICON_SIZE_MENU);
+                       icon = "network-wireless";
                else
                else
-                       image = gtk_image_new_from_icon_name("network-wireless-encrypted",
-                                                            GTK_ICON_SIZE_MENU);
+                       icon = "network-wireless-encrypted";
+               image = gtk_image_new_from_icon_name(icon,
+                   GTK_ICON_SIZE_MENU);
                gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
 
                bar = gtk_progress_bar_new();
                gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
 
                bar = gtk_progress_bar_new();
@@ -121,10 +134,16 @@ add_scan_results(GtkMenu *menu, const struct if_msg *ifm)
                perc = strength / 100.0;
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar), perc);
 
                perc = strength / 100.0;
                gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar), perc);
 
+               tip = g_strconcat(ifa->bssid, " ", ifa->flags, NULL);
+               gtk_widget_set_tooltip_text(item, tip);
+               g_free(tip);
+
                gtk_widget_show(label);
                gtk_widget_show(bar);
                gtk_widget_show(image);
                gtk_widget_show(box);
                gtk_widget_show(label);
                gtk_widget_show(bar);
                gtk_widget_show(image);
                gtk_widget_show(box);
+               g_signal_connect(G_OBJECT(item), "activate",
+                   G_CALLBACK(ssid_hook), gl->data);
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
        }
 }
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
        }
 }
@@ -134,25 +153,28 @@ on_activate(GtkStatusIcon *icon, _unused guint button, _unused guint32 atime, _u
 {
        GtkMenu *menu;
        const struct if_msg *ifm;
 {
        GtkMenu *menu;
        const struct if_msg *ifm;
-       GList *gl;
-       size_t n;
+       GSList *l;
+       size_t n, na;
 
        notify_close();
 
 
        notify_close();
 
-       n = 0;
-       for (gl = interfaces; gl; gl = gl->next) {
-               ifm = (const struct if_msg *)gl->data;
-               if (ifm->wireless)
-                       if (++n > 1)
+       n = na =0;
+       for (l = interfaces; l; l = l->next) {
+               ifm = (const struct if_msg *)l->data;
+               if (ifm->wireless) {
+                       if (ifm->scan_results != NULL)
+                               ++na;
+                       if (++n > 1 && na != 0)
                                break;
                                break;
+               }
        }
        }
-       if (n == 0)
+       if (n == 0 || (n == 1 && na == 0))
                return;
 
        menu = (GtkMenu *)gtk_menu_new();
 
                return;
 
        menu = (GtkMenu *)gtk_menu_new();
 
-       for (gl = interfaces; gl; gl = gl->next) {
-               ifm = (const struct if_msg *)gl->data;
+       for (l = interfaces; l; l = l->next) {
+               ifm = (const struct if_msg *)l->data;
                if (!ifm->wireless)
                        continue;
                if (n == 1) {
                if (!ifm->wireless)
                        continue;
                if (n == 1) {
@@ -162,7 +184,7 @@ on_activate(GtkStatusIcon *icon, _unused guint button, _unused guint32 atime, _u
 #if 0
                item = gtk_image_menu_item_new_with_label(ifm->name);
                image = gtk_image_new_from_icon_name("network-wireless",
 #if 0
                item = gtk_image_menu_item_new_with_label(ifm->name);
                image = gtk_image_new_from_icon_name("network-wireless",
-                                                    GTK_ICON_SIZE_MENU);
+                   GTK_ICON_SIZE_MENU);
                gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
 
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
                gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
 
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
@@ -170,8 +192,8 @@ on_activate(GtkStatusIcon *icon, _unused guint button, _unused guint32 atime, _u
        }
        gtk_widget_show_all(GTK_WIDGET(menu));
        gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
        }
        gtk_widget_show_all(GTK_WIDGET(menu));
        gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
-                      gtk_status_icon_position_menu, icon,
-                      1, gtk_get_current_event_time());
+           gtk_status_icon_position_menu, icon,
+           1, gtk_get_current_event_time());
 }
 
 static void
 }
 
 static void
@@ -184,12 +206,12 @@ on_popup(GtkStatusIcon *icon, guint button, guint32 atime, gpointer data)
 
        menu = (GtkMenu *)gtk_menu_new();
 
 
        menu = (GtkMenu *)gtk_menu_new();
 
-       item = gtk_image_menu_item_new_with_mnemonic(_("_Quit"));
-       image = gtk_image_new_from_icon_name(GTK_STOCK_QUIT,
-                                            GTK_ICON_SIZE_MENU);
+       item = gtk_image_menu_item_new_with_mnemonic(_("_Preferences"));
+       image = gtk_image_new_from_icon_name(GTK_STOCK_PREFERENCES,
+           GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
        g_signal_connect(G_OBJECT(item), "activate",
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
        g_signal_connect(G_OBJECT(item), "activate",
-                        G_CALLBACK(on_quit), icon);
+           G_CALLBACK(on_pref), icon);
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
        item = gtk_separator_menu_item_new();
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
        item = gtk_separator_menu_item_new();
@@ -197,23 +219,31 @@ on_popup(GtkStatusIcon *icon, guint button, guint32 atime, gpointer data)
 
        item = gtk_image_menu_item_new_with_mnemonic(_("_Help"));
        image = gtk_image_new_from_icon_name(GTK_STOCK_HELP,
 
        item = gtk_image_menu_item_new_with_mnemonic(_("_Help"));
        image = gtk_image_new_from_icon_name(GTK_STOCK_HELP,
-                                            GTK_ICON_SIZE_MENU);
+           GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
        g_signal_connect(G_OBJECT(item), "activate",
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
        g_signal_connect(G_OBJECT(item), "activate",
-                        G_CALLBACK(on_help), icon);
+           G_CALLBACK(on_help), icon);
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
        item = gtk_image_menu_item_new_with_mnemonic(_("_About"));
        image = gtk_image_new_from_icon_name(GTK_STOCK_ABOUT,
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
        item = gtk_image_menu_item_new_with_mnemonic(_("_About"));
        image = gtk_image_new_from_icon_name(GTK_STOCK_ABOUT,
-                                            GTK_ICON_SIZE_MENU);
+           GTK_ICON_SIZE_MENU);
+       gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
+       g_signal_connect(G_OBJECT(item), "activate",
+           G_CALLBACK(on_about), icon);
+       gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+
+       item = gtk_image_menu_item_new_with_mnemonic(_("_Quit"));
+       image = gtk_image_new_from_icon_name(GTK_STOCK_QUIT,
+           GTK_ICON_SIZE_MENU);
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
        g_signal_connect(G_OBJECT(item), "activate",
        gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item), image);
        g_signal_connect(G_OBJECT(item), "activate",
-                        G_CALLBACK(on_about), icon);
+           G_CALLBACK(on_quit), icon);
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
        gtk_widget_show_all(GTK_WIDGET(menu));
        gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
 
        gtk_widget_show_all(GTK_WIDGET(menu));
        gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
-                      gtk_status_icon_position_menu, data, button, atime);
+           gtk_status_icon_position_menu, data, button, atime);
        if (button == 0)
                gtk_menu_shell_select_first(GTK_MENU_SHELL(menu), FALSE);
 }
        if (button == 0)
                gtk_menu_shell_select_first(GTK_MENU_SHELL(menu), FALSE);
 }
@@ -222,7 +252,7 @@ void
 menu_init(GtkStatusIcon *icon)
 {
        g_signal_connect_object(G_OBJECT(icon), "activate",
 menu_init(GtkStatusIcon *icon)
 {
        g_signal_connect_object(G_OBJECT(icon), "activate",
-                               G_CALLBACK(on_activate), icon, 0);
+           G_CALLBACK(on_activate), icon, 0);
        g_signal_connect_object(G_OBJECT(icon), "popup_menu",
        g_signal_connect_object(G_OBJECT(icon), "popup_menu",
-                               G_CALLBACK(on_popup), icon, 0);
+           G_CALLBACK(on_popup), icon, 0);
 }
 }