We now have a working preference screen and can rebind the interface!
[dhcpcd-ui] / main.c
diff --git a/main.c b/main.c
index 9375c08b5831f47613e6dbcf620a0f9d4690c852..3965699dfd9f8867c67877ce90e27d04e16ee8d9 100644 (file)
--- a/main.c
+++ b/main.c
 #include "menu.h"
 
 DBusGProxy *dbus = NULL;
-GList *interfaces = NULL;
+GSList *interfaces = NULL;
 
 static GtkStatusIcon *status_icon;
-static gint ani_timer;
+static int ani_timer;
 static int ani_counter;
-static gboolean online;
-static gboolean carrier;
+static bool online;
+static bool carrier;
 static char **interface_order;
 static NotifyNotification *nn;
 
@@ -55,6 +55,7 @@ const char *const up_reasons[] = {
        "REBOOT",
        "IPV4LL",
        "INFORM",
+       "STATIC",
        "TIMEOUT",
        NULL
 };
@@ -68,21 +69,50 @@ const char *const down_reasons[] = {
        NULL
 };
 
-static gboolean
+static bool
 ignore_if_msg(const struct if_msg *ifm)
 {
        if (g_strcmp0(ifm->reason, "STOP") == 0 ||
            g_strcmp0(ifm->reason, "RELEASE") == 0)
-               return TRUE;
-       return FALSE;
+               return true;
+       return false;
+}
+
+static struct if_msg *
+find_if_msg(const char *iface)
+{
+       GSList *gl;
+       struct if_msg *ifm;
+
+       for (gl = interfaces; gl; gl = gl->next) {
+               ifm = (struct if_msg *)gl->data;
+               if (g_strcmp0(ifm->ifname, iface) == 0)
+                       return ifm;
+       }
+       return NULL;
+}
+
+static void
+free_if_ap(struct if_ap *ifa)
+{
+       g_free(ifa->ifname);
+       g_free(ifa->bssid);
+       g_free(ifa->flags);
+       g_free(ifa->ssid);
+       g_free(ifa);
 }
 
 static void
 free_if_msg(struct if_msg *ifm)
 {
-       g_free(ifm->name);
+       GSList *gl;
+
+       g_free(ifm->ifname);
        g_free(ifm->reason);
        g_free(ifm->ssid);
+       for (gl = ifm->scan_results; gl; gl = gl->next)
+               free_if_ap((struct if_ap *)gl->data);
+       g_slist_free(ifm->scan_results);
        g_free(ifm);
 }
 
@@ -93,21 +123,13 @@ error_exit(const char *msg, GError *error)
 
        if (error) {
                g_critical("%s: %s", msg, error->message);
-               dialog = gtk_message_dialog_new(NULL,
-                                               0,
-                                               GTK_MESSAGE_ERROR,
-                                               GTK_BUTTONS_CLOSE,
-                                               "%s: %s",
-                                               msg,
-                                               error->message);
+               dialog = gtk_message_dialog_new(NULL, 0,
+                   GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
+                   "%s: %s", msg, error->message);
        } else {
                g_critical("%s", msg);
-               dialog = gtk_message_dialog_new(NULL,
-                                               0,
-                                               GTK_MESSAGE_ERROR,
-                                               GTK_BUTTONS_CLOSE,
-                                               "%s",
-                                               msg);
+               dialog = gtk_message_dialog_new(NULL, 0,
+                   GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", msg);
        }
        gtk_dialog_run(GTK_DIALOG(dialog));
        gtk_widget_destroy(dialog);
@@ -117,53 +139,55 @@ error_exit(const char *msg, GError *error)
                exit(EXIT_FAILURE);
 }
 
-GList *
-get_scan_results(const char *iface)
+static GSList *
+get_scan_results(struct if_msg *ifm)
 {
        GType otype;
-       GPtrArray *array = NULL;
-       GValueArray *item;
-       GError *error = NULL;
-       GList *list = NULL;
+       GError *error;
+       GPtrArray *array;
+       GHashTable *config;
+       GSList *list = NULL;
        struct if_ap *ifa;
        guint i;
-       GValue *v;
+       GValue *val;
 
-       /* Below code causes dbus to go belly up for some reason :/ */
-       return NULL;
-       otype = dbus_g_type_get_struct("GValueArray",
-                                      G_TYPE_STRING,
-                                      G_TYPE_UINT,
-                                      G_TYPE_UINT,
-                                      G_TYPE_STRING,
-                                      G_TYPE_STRING,
-                                      G_TYPE_INVALID);
+       otype = dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE);
        otype = dbus_g_type_get_collection("GPtrArray", otype);
-       if (!dbus_g_proxy_call(dbus, "GetScanResults", &error,
-                              G_TYPE_STRING, &iface, G_TYPE_INVALID,
-                              otype, &array, G_TYPE_INVALID)) {
-               g_message("GetScanResults: %s\n", error->message);
-               g_clear_error(&error);
-               return NULL;
-       }
 
-       printf ("got %d\n", array->len);
+       error = NULL;
+       if (!dbus_g_proxy_call(dbus, "ScanResults", &error,
+               G_TYPE_STRING, ifm->ifname, G_TYPE_INVALID,
+               otype, &array, G_TYPE_INVALID))
+               error_exit(_("ScanResults"), error);
+
        for (i = 0; i < array->len; i++) {
-               ifa = g_malloc(sizeof(*ifa));
-               item = g_ptr_array_index(array, i);
-               v = g_value_array_get_nth(item, 0);
-               ifa->bssid = g_strdup(g_value_get_string(v));
-               v = g_value_array_get_nth(item, 1);
-               ifa->freq = g_value_get_uint(v);
-               v = g_value_array_get_nth(item, 2);
-               ifa->level = g_value_get_uint(v);
-               v = g_value_array_get_nth(item, 3);
-               ifa->flags = g_strdup(g_value_get_string(v));
-               v = g_value_array_get_nth(item, 3);
-               ifa->ssid = g_strdup(g_value_get_string(v));
-               list = g_list_append(list, ifa);
+               config = g_ptr_array_index(array, i);
+               val = g_hash_table_lookup(config, "BSSID");
+               if (val == NULL)
+                       continue;
+               ifa = g_malloc0(sizeof(*ifa));
+               ifa->ifname = g_strdup(ifm->ifname);
+               ifa->bssid = g_strdup(g_value_get_string(val));
+               val = g_hash_table_lookup(config, "Frequency");
+               if (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);
+               val = g_hash_table_lookup(config, "Level");
+               if (val)
+                       ifa->level = g_value_get_int(val);
+               val = g_hash_table_lookup(config, "Flags");
+               if (val)
+                       ifa->flags = g_strdup(g_value_get_string(val));
+               val = g_hash_table_lookup(config, "SSID");
+               if (val)
+                       ifa->ssid = g_strdup(g_value_get_string(val));
+               list = g_slist_append(list, ifa);
        }
-       g_ptr_array_free(array, TRUE);
        return list;
 }
 
@@ -177,7 +201,7 @@ make_if_msg(GHashTable *config)
        if (val == NULL)
                return NULL;
        ifm = g_malloc0(sizeof(*ifm));
-       ifm->name = g_strdup(g_value_get_string(val));
+       ifm->ifname = g_strdup(g_value_get_string(val));
        val = g_hash_table_lookup(config, "Reason");
        if (val)
                ifm->reason = g_strdup(g_value_get_string(val));
@@ -200,20 +224,18 @@ make_if_msg(GHashTable *config)
                g_strfreev(interface_order);
                interface_order = g_strsplit(g_value_get_string(val), " ", 0);
        }
-       if (ifm->wireless)
-               ifm->scan_results = get_scan_results(ifm->name);
        return ifm;
 }
 
-static gboolean
+static bool
 if_up(const struct if_msg *ifm)
 {
        const char *const *r;
 
        for (r = up_reasons; *r; r++)
                if (g_strcmp0(*r, ifm->reason) == 0)
-                       return TRUE;
-       return FALSE;
+                       return true;
+       return false;
 }
 
 static char *
@@ -222,10 +244,10 @@ print_if_msg(const struct if_msg *ifm)
        char *msg, *p;
        const char *reason = NULL;
        size_t len;
-       gboolean showip, showssid;
+       bool showip, showssid;
     
-       showip = TRUE;
-       showssid = FALSE;
+       showip = true;
+       showssid = false;
        if (if_up(ifm))
                reason = N_("Acquired address");
        else {
@@ -235,26 +257,26 @@ print_if_msg(const struct if_msg *ifm)
                        if (ifm->wireless) {
                                reason = N_("Asssociated with");
                                if (ifm->ssid != NULL)
-                                       showssid = TRUE;
+                                       showssid = true;
                        } else
                                reason = N_("Cable plugged in");
-                       showip = FALSE;
+                       showip = false;
                } else if (g_strcmp0(ifm->reason, "NOCARRIER") == 0) {
                        if (ifm->wireless) {
                                if (ifm->ssid != NULL || ifm->ip.s_addr != 0) {
                                        reason = N_("Disassociated from");
-                                       showssid = TRUE;
+                                       showssid = true;
                                } else
-                                   reason = N_("Not associated");
+                                       reason = N_("Not associated");
                        } else
                                reason = N_("Cable unplugged");
-                       showip = FALSE;
+                       showip = false;
                }
        }
        if (reason == NULL)
                reason = ifm->reason;
        
-       len = strlen(ifm->name) + 3;
+       len = strlen(ifm->ifname) + 3;
        len += strlen(reason) + 1;
        if (ifm->ip.s_addr != 0) {
                len += 16; /* 000. * 4 */
@@ -264,7 +286,7 @@ print_if_msg(const struct if_msg *ifm)
        if (showssid)
                len += strlen(ifm->ssid) + 1;
        msg = p = g_malloc(len);
-       p += g_snprintf(msg, len, "%s: %s", ifm->name, reason);
+       p += g_snprintf(msg, len, "%s: %s", ifm->ifname, reason);
        if (showssid)
                p += g_snprintf(p, len - (p - msg), " %s", ifm->ssid);
        if (ifm->ip.s_addr != 0 && showip) {
@@ -275,7 +297,7 @@ print_if_msg(const struct if_msg *ifm)
        return msg;
 }
 
-static gint
+static int
 if_msg_comparer(gconstpointer a, gconstpointer b)
 {
        const struct if_msg *ifa, *ifb;
@@ -284,9 +306,9 @@ if_msg_comparer(gconstpointer a, gconstpointer b)
        ifa = (const struct if_msg *)a;
        ifb = (const struct if_msg *)b;
        for (order = (const char *const *)interface_order; *order; order++) {
-               if (g_strcmp0(*order, ifa->name) == 0)
+               if (g_strcmp0(*order, ifa->ifname) == 0)
                        return -1;
-               if (g_strcmp0(*order, ifb->name) == 0)
+               if (g_strcmp0(*order, ifb->ifname) == 0)
                        return 1;
        }
        return 0;
@@ -295,61 +317,65 @@ if_msg_comparer(gconstpointer a, gconstpointer b)
 static gboolean
 animate_carrier(_unused gpointer data)
 {
+       const char *icon;
+       
        if (ani_timer == 0)
-               return FALSE;
+               return false;
 
        switch(ani_counter++) {
        case 0:
-               gtk_status_icon_set_from_icon_name(status_icon, "network-transmit");
+               icon = "network-transmit";
                break;
        case 1:
-               gtk_status_icon_set_from_icon_name(status_icon, "network-receive");
+               icon = "network-receive";
                break;
        default:
-               gtk_status_icon_set_from_icon_name(status_icon, "network-idle");
+               icon = "network-idle";
                ani_counter = 0;
                break;
        }
-       return TRUE;
+       gtk_status_icon_set_from_icon_name(status_icon, icon);
+       return true;
 }
 
 static gboolean
-animate_online(gpointer data)
+animate_online(_unused gpointer data)
 {
+       const char *icon;
+       
        if (ani_timer == 0)
-               return FALSE;
+               return false;
 
        if (ani_counter++ > 6) {
                ani_timer = 0;
                ani_counter = 0;
-               return FALSE;
+               return false;
        }
 
-       if (ani_counter % 2 == GPOINTER_TO_INT(data))
-               gtk_status_icon_set_from_icon_name(status_icon, "network-idle");
+       if (ani_counter % 2 == 0)
+               icon = "network-idle";
        else
-               gtk_status_icon_set_from_icon_name(status_icon, "network-transmit-receive");
-       return TRUE;
+               icon = "network-transmit-receive";
+       gtk_status_icon_set_from_icon_name(status_icon, icon);
+       return true;
 }
 
 static void
-update_online(char **buffer)
+update_online(void)
 {
-       gboolean ison, iscarrier;
+       bool ison, iscarrier;
        char *msg, *msgs, *tmp;
-       GSourceFunc ani_func;
-       const GList *gl;
+       const GSList *gl;
        const struct if_msg *ifm;
-       gpointer toggle;
 
-       ison = iscarrier = FALSE;
+       ison = iscarrier = false;
        msgs = NULL;
        for (gl = interfaces; gl; gl = gl->next) {
                ifm = (const struct if_msg *)gl->data;
                if (if_up(ifm))
-                       ison = iscarrier = TRUE;
+                       ison = iscarrier = true;
                if (!iscarrier && g_strcmp0(ifm->reason, "CARRIER") == 0)
-                       iscarrier = TRUE;
+                       iscarrier = true;
                msg = print_if_msg(ifm);
                if (msgs) {
                        tmp = g_strconcat(msgs, "\n", msg, NULL);
@@ -368,23 +394,18 @@ update_online(char **buffer)
                        ani_counter = 0;
                }
                if (ison) {
-                       toggle = GINT_TO_POINTER(0);
-                       ani_func = animate_online;
+                       animate_online(NULL);
+                       ani_timer = g_timeout_add(300, animate_online, NULL);
                } else if (iscarrier) {
-                       toggle = NULL;
-                       ani_func = animate_carrier;
+                       animate_carrier(NULL);
+                       ani_timer = g_timeout_add(500, animate_carrier, NULL);
                } else {
-                       toggle = GINT_TO_POINTER(1);
-                       ani_func = animate_online;
+                       gtk_status_icon_set_from_icon_name(status_icon,
+                           "network-offline");
                }
-               ani_timer = g_timeout_add(300, ani_func, toggle);
-               ani_func(toggle);
        }
        gtk_status_icon_set_tooltip(status_icon, msgs);
-       if (buffer)
-               *buffer = msgs;
-       else
-               g_free(msgs);
+       g_free(msgs);
 }
 
 void
@@ -413,9 +434,7 @@ notify(const char *title, const char *msg, const char *icon)
                notify_notification_close(nn, NULL);
        if (gtk_status_icon_get_visible(status_icon))
                nn = notify_notification_new_with_status_icon(title,
-                                                             msg,
-                                                             icon,
-                                                             status_icon);
+                   msg, icon, status_icon);
        else
                nn = notify_notification_new(title, msg, icon, NULL);
        notify_notification_set_timeout(nn, 5000);
@@ -427,8 +446,8 @@ static void
 dhcpcd_event(_unused DBusGProxy *proxy, GHashTable *config, _unused void *data)
 {
        struct if_msg *ifm, *ifp;
-       gboolean rem;
-       GList *gl;
+       bool rem;
+       GSList *gl;
        char *msg, *title;
        const char *act, *net;
        const char *const *r;
@@ -442,19 +461,22 @@ dhcpcd_event(_unused DBusGProxy *proxy, GHashTable *config, _unused void *data)
        ifp = NULL;
        for (gl = interfaces; gl; gl = gl->next) {
                ifp = (struct if_msg *)gl->data;
-               if (g_strcmp0(ifp->name, ifm->name) == 0) {
+               if (g_strcmp0(ifp->ifname, ifm->ifname) == 0) {
+                       ifm->scan_results = ifp->scan_results;
+                       ifp->scan_results = NULL;
                        free_if_msg(ifp);
                        if (rem)
-                               interfaces = g_list_delete_link(interfaces, gl);
+                               interfaces =
+                                   g_slist_delete_link(interfaces, gl);
                        else
                                gl->data = ifm;
                        break;
                }
        }
        if (ifp == NULL && !rem)
-               interfaces = g_list_prepend(interfaces, ifm);
-       interfaces = g_list_sort(interfaces, if_msg_comparer);
-       update_online(NULL);
+               interfaces = g_slist_prepend(interfaces, ifm);
+       interfaces = g_slist_sort(interfaces, if_msg_comparer);
+       update_online();
 
        /* We should ignore renew and stop so we don't annoy the user */
        if (g_strcmp0(ifm->reason, "RENEW") == 0 ||
@@ -488,7 +510,7 @@ dhcpcd_event(_unused DBusGProxy *proxy, GHashTable *config, _unused void *data)
                notify(title, msg, GTK_STOCK_NETWORK);
                g_free(title);
        } else
-               notify("Interface event", msg, GTK_STOCK_NETWORK);
+               notify(N_("Interface event"), msg, GTK_STOCK_NETWORK);
        g_free(msg);
 }
 
@@ -501,7 +523,7 @@ foreach_make_ifm(_unused gpointer key, gpointer value, _unused gpointer data)
        if (ignore_if_msg(ifm))
                g_free(ifm);
        else if (ifm)
-               interfaces = g_list_prepend(interfaces, ifm);
+               interfaces = g_slist_prepend(interfaces, ifm);
 }
 
 static void
@@ -510,13 +532,15 @@ dhcpcd_get_interfaces()
        GHashTable *ifs;
        GError *error = NULL;
        GType otype;
-       char *msg;
+       GSList *gl, *gsl;
+       GPtrArray *array;
+       struct if_msg *ifm;
 
        otype = dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE);
        otype = dbus_g_type_get_map("GHashTable", G_TYPE_STRING, otype);
        if (!dbus_g_proxy_call(dbus, "GetInterfaces", &error,
-                              G_TYPE_INVALID,
-                              otype, &ifs, G_TYPE_INVALID))
+               G_TYPE_INVALID,
+               otype, &ifs, G_TYPE_INVALID))
                error_exit("GetInterfaces", error);
        g_hash_table_foreach(ifs, foreach_make_ifm, NULL);
        g_hash_table_unref(ifs);
@@ -526,50 +550,66 @@ dhcpcd_get_interfaces()
        g_strfreev(interface_order);
        interface_order = NULL;
        if (!dbus_g_proxy_call(dbus, "ListInterfaces", &error,
-                              G_TYPE_INVALID,
-                              G_TYPE_STRV, &interface_order, G_TYPE_INVALID))
+               G_TYPE_INVALID,
+               G_TYPE_STRV, &interface_order, G_TYPE_INVALID))
                error_exit("ListInterfaces", error);
-       interfaces = g_list_sort(interfaces, if_msg_comparer);
-       msg = NULL;
-       update_online(&msg);
-       // GTK+ 2.16 msg = gtk_status_icon_get_tooltip_text(status_icon);
-       if (msg != NULL) {
-               notify("Interface status", msg, GTK_STOCK_NETWORK);
-               g_free(msg);
+       interfaces = g_slist_sort(interfaces, if_msg_comparer);
+
+       otype = dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE);
+       otype = dbus_g_type_get_collection("GPtrArray", otype);
+       for (gl = interfaces; gl; gl = gl->next) {
+               ifm = (struct if_msg *)gl->data;
+               if (!ifm->wireless)
+                       continue;
+               if (!dbus_g_proxy_call(dbus, "ScanResults", &error,
+                       G_TYPE_STRING, ifm->ifname, G_TYPE_INVALID,
+                       otype, &array, G_TYPE_INVALID)) 
+               {
+                       g_message("ScanResults: %s", error->message);
+                       g_clear_error(&error);
+                       continue;
+               }
+               for (gsl = ifm->scan_results; gsl; gsl = gsl->next)
+                       g_free(gsl->data);
+               g_slist_free(ifm->scan_results);
+               ifm->scan_results = get_scan_results(ifm);
        }
+
+       update_online();
 }
 
 static void
 check_status(const char *status)
 {
        static char *last = NULL;
-       GList *gl;
+       GSList *gl;
        char *version;
        const char *msg;
-       gboolean refresh;
+       bool refresh;
        GError *error = NULL;
 
        g_message("Status changed to %s", status);
        if (g_strcmp0(status, "down") == 0) {
                for (gl = interfaces; gl; gl = gl->next)
                        free_if_msg((struct if_msg *)gl->data);
-               g_list_free(interfaces);
+               g_slist_free(interfaces);
                interfaces = NULL;
-               update_online(NULL);
-               msg = N_(last? "Connection to dhcpcd lost" : "dhcpcd not running");
+               update_online();
+               msg = N_(last ?
+                   "Connection to dhcpcd lost" : "dhcpcd not running");
                gtk_status_icon_set_tooltip(status_icon, msg);
                notify(_("No network"), msg, GTK_STOCK_NETWORK);
        }
 
-       refresh = FALSE;
+       refresh = false;
        if (last == NULL) {
                if (g_strcmp0(status, "down") != 0)
-                       refresh = TRUE;
+                       refresh = true;
        } else {
                if (g_strcmp0(status, last) == 0)
                        return;
                if (g_strcmp0(last, "down") == 0)
-                       refresh = TRUE;
+                       refresh = true;
                g_free(last);
        }
        last = g_strdup(status);
@@ -577,8 +617,8 @@ check_status(const char *status)
        if (!refresh)
                return;
        if (!dbus_g_proxy_call(dbus, "GetDhcpcdVersion", &error,
-                              G_TYPE_INVALID,
-                              G_TYPE_STRING, &version, G_TYPE_INVALID))
+               G_TYPE_INVALID,
+               G_TYPE_STRING, &version, G_TYPE_INVALID))
                error_exit(_("GetDhcpcdVersion"), error);
        g_message(_("Connected to %s-%s"), "dhcpcd", version);
        g_free(version);
@@ -586,11 +626,54 @@ check_status(const char *status)
 }
 
 static void
-dhcpcd_status(_unused DBusGProxy *proxy, const char *status, _unused void *data)
+dhcpcd_status(_unused DBusGProxy *proxy, const char *status,
+    _unused void *data)
 {
        check_status(status);
 }
 
+static void
+dhcpcd_scan_results(_unused DBusGProxy *proxy, const char *iface,
+    _unused void *data)
+{
+       struct if_msg *ifm;
+       struct if_ap *ifa, *ifa2;
+       GSList *gl, *aps, *l;
+       char *txt, *ntxt;
+
+       ifm = find_if_msg(iface);
+       if (ifm == NULL)
+               return;
+       g_message(_("%s: Received scan results"), ifm->ifname);
+       aps = get_scan_results(ifm);
+       txt = NULL;
+       for (gl = aps; gl; gl = gl->next) {
+               ifa = (struct if_ap *)gl->data;
+               for (l = ifm->scan_results; l; l = l->next) {
+                       ifa2 = (struct if_ap *)l->data;
+                       if (g_strcmp0(ifa->ssid, ifa2->ssid) == 0)
+                               break;
+               }
+               if (l == NULL) {
+                       if (txt == NULL)
+                               txt = g_strdup(ifa->ssid);
+                       else {
+                               ntxt = g_strconcat(txt, "\n", ifa->ssid, NULL);
+                               g_free(txt);
+                               txt = ntxt;
+                       }
+               }
+       }
+       for (gl = ifm->scan_results; gl; gl = gl->next)
+               free_if_ap((struct if_ap *)gl->data);
+       g_slist_free(ifm->scan_results);
+       ifm->scan_results = aps;
+       if (txt != NULL) {
+               notify(N_("Found new AP"), txt, GTK_STOCK_NETWORK);
+               g_free(txt);
+       }
+}
+
 int
 main(int argc, char *argv[])
 {
@@ -599,7 +682,6 @@ main(int argc, char *argv[])
        char *version = NULL;
        GType otype;
        int tries = 5;
-
                
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, NULL);
@@ -610,11 +692,13 @@ main(int argc, char *argv[])
        g_set_application_name("dhcpcd Monitor");
        status_icon = gtk_status_icon_new_from_icon_name("network-offline");
        if (status_icon == NULL)
-               status_icon = gtk_status_icon_new_from_stock(GTK_STOCK_DISCONNECT);
+               status_icon =
+                   gtk_status_icon_new_from_stock(GTK_STOCK_DISCONNECT);
        //network_offline = gtk_status_icon_get_pixbuf(status_icon);
        
-       gtk_status_icon_set_tooltip(status_icon, _("Connecting to dhcpcd ..."));
-       gtk_status_icon_set_visible(status_icon, TRUE);
+       gtk_status_icon_set_tooltip(status_icon,
+           _("Connecting to dhcpcd ..."));
+       gtk_status_icon_set_visible(status_icon, true);
 
        notify_init(PACKAGE);
 
@@ -623,21 +707,16 @@ main(int argc, char *argv[])
        if (bus == NULL || error != NULL)
                error_exit(_("Could not connect to system bus"), error);
        dbus = dbus_g_proxy_new_for_name(bus,
-                                             DHCPCD_SERVICE,
-                                             DHCPCD_PATH,
-                                             DHCPCD_SERVICE);
+           DHCPCD_SERVICE,
+           DHCPCD_PATH,
+           DHCPCD_SERVICE);
 
        g_message(_("Connecting to dhcpcd-dbus ..."));
        while (--tries > 0) {
                g_clear_error(&error);
-               if (dbus_g_proxy_call_with_timeout(dbus,
-                                                  "GetVersion",
-                                                  500,
-                                                  &error,
-                                                  G_TYPE_INVALID,
-                                                  G_TYPE_STRING,
-                                                  &version,
-                                                  G_TYPE_INVALID))
+               if (dbus_g_proxy_call_with_timeout(dbus, "GetVersion", 500,
+                       &error, G_TYPE_INVALID,
+                       G_TYPE_STRING, &version, G_TYPE_INVALID))
                        break;
        }
        if (tries == 0)
@@ -646,27 +725,29 @@ main(int argc, char *argv[])
        g_free(version);
 
        gtk_status_icon_set_tooltip(status_icon, _("Triggering dhcpcd ..."));
-       online = FALSE;
+       online = false;
        menu_init(status_icon);
 
        if (!dbus_g_proxy_call(dbus, "GetStatus", &error,
-                              G_TYPE_INVALID,
-                              G_TYPE_STRING, &version, G_TYPE_INVALID))
+               G_TYPE_INVALID,
+               G_TYPE_STRING, &version, G_TYPE_INVALID))
                error_exit(_("GetStatus"), error);
        check_status(version);
        g_free(version);
 
        otype = dbus_g_type_get_map("GHashTable", G_TYPE_STRING, G_TYPE_VALUE);
        dbus_g_proxy_add_signal(dbus, "Event",
-                               otype, G_TYPE_INVALID);
+           otype, G_TYPE_INVALID);
        dbus_g_proxy_connect_signal(dbus, "Event",
-                                   G_CALLBACK(dhcpcd_event),
-                                   NULL, NULL);
+           G_CALLBACK(dhcpcd_event), bus, NULL);
        dbus_g_proxy_add_signal(dbus, "StatusChanged",
-                               G_TYPE_STRING, G_TYPE_INVALID);
+           G_TYPE_STRING, G_TYPE_INVALID);
        dbus_g_proxy_connect_signal(dbus, "StatusChanged",
-                                   G_CALLBACK(dhcpcd_status),
-                                   NULL, NULL);
+           G_CALLBACK(dhcpcd_status), bus, NULL);
+       dbus_g_proxy_add_signal(dbus, "ScanResults",
+           G_TYPE_STRING, G_TYPE_INVALID);
+       dbus_g_proxy_connect_signal(dbus, "ScanResults",
+           G_CALLBACK(dhcpcd_scan_results), bus, NULL);
 
        gtk_main();
        return 0;