Add a radio and progress bar to the ssid menu.
authorRoy Marples <roy@marples.name>
Mon, 2 Feb 2009 22:57:36 +0000 (22:57 +0000)
committerRoy Marples <roy@marples.name>
Mon, 2 Feb 2009 22:57:36 +0000 (22:57 +0000)
dhcpcd-gtk.h
main.c
menu.c

index 10bf0082f8273c680e4972e39ab0bef168ff7469..f3b42f2eb8dbcaab31a635b3e86ad5d54244f9e8 100644 (file)
@@ -53,8 +53,8 @@
 
 struct if_ap {
        char *bssid;
-       int freq;
-       int qual;
+       int frequency;
+       int quality;
        int noise;
        int level;
        char *flags;
diff --git a/main.c b/main.c
index 25d15b62cfcf90b39fb14c3fc891a40726138f33..0bb38a77b0bcc60d10faedd74161dcf3bbaa8e4e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -174,7 +174,10 @@ get_scan_results(struct if_msg *ifm)
                ifa->bssid = g_strdup(g_value_get_string(val));
                val = g_hash_table_lookup(config, "Frequency");
                if (val)
-                       ifa->freq = g_value_get_int(val);
+                       ifa->frequency = g_value_get_int(val);
+               val = g_hash_table_lookup(config, "Quality");
+               if (val)
+                       ifa->quality = g_value_get_int(val);
                val = g_hash_table_lookup(config, "Noise");
                if (val)
                        ifa->noise = g_value_get_int(val);
diff --git a/menu.c b/menu.c
index 1a658088277aba983d3c6feafe98b00c4d688f02..54e72493cdf91044543f03c751ae49a1dfe6593b 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -91,21 +91,40 @@ add_scan_results(GtkMenu *menu, const struct if_msg *ifm)
 {
        GSList *gl;
        const struct if_ap *ifa;
-       GtkWidget *item, *image;
+       GtkWidget *item, *image, *box, *label, *bar;
+       double perc;
+       int strength;
 
        for (gl = ifm->scan_results; gl; gl = gl->next) {
                ifa = (const struct if_ap *)gl->data;
-               item = gtk_image_menu_item_new_with_label(ifa->ssid);
-               image = NULL;
+               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);
+               gtk_container_add(GTK_CONTAINER(item), box); 
+               label = gtk_label_new(ifa->ssid);
+               gtk_box_pack_start(GTK_BOX(box), label, TRUE, TRUE, 0);
+
                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);
-               if (!image && ifa->flags != NULL)
-                       image = gtk_image_new_from_icon_name("lock",
+               else
+                       image = gtk_image_new_from_icon_name("network-wireless-encrypted",
                                                             GTK_ICON_SIZE_MENU);
-               if (image)
-                       gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(item),
-                                                     image);
+               gtk_box_pack_start(GTK_BOX(box), image, FALSE, FALSE, 0);
+
+               bar = gtk_progress_bar_new();
+               gtk_widget_set_size_request(bar, 100, -1);
+               gtk_box_pack_end(GTK_BOX(box), bar, FALSE, TRUE, 0);
+               strength = CLAMP(ifa->quality, 0, 100);
+               perc = strength / 100.0;
+               gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(bar), perc);
+
+               gtk_widget_show(label);
+               gtk_widget_show(bar);
+               gtk_widget_show(image);
+               gtk_widget_show(box);
                gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
        }
 }