c94b567
diff -up gnome-applets-2.21.2/gweather/gweather-applet.c.gweather-network gnome-applets-2.21.2/gweather/gweather-applet.c
c94b567
--- gnome-applets-2.21.2/gweather/gweather-applet.c.gweather-network	2007-11-27 03:59:41.000000000 -0500
c94b567
+++ gnome-applets-2.21.2/gweather/gweather-applet.c	2008-01-05 23:05:00.000000000 -0500
211c304
@@ -29,6 +29,10 @@
211c304
 #include <libnotify/notification.h>
211c304
 #endif
211c304
 
211c304
+#include <dbus/dbus-glib.h>
211c304
+#include <dbus/dbus-glib-lowlevel.h>
211c304
+#include <NetworkManager/NetworkManager.h>
211c304
+
211c304
 #include "gweather.h"
211c304
 #include "gweather-about.h"
211c304
 #include "gweather-pref.h"
c94b567
@@ -288,6 +292,8 @@ applet_destroy (GtkWidget *widget, GWeat
211c304
     weather_info_abort (gw_applet->gweather_info);
211c304
 }
211c304
 
211c304
+static void setup_network_monitor (GWeatherApplet *gw_applet);
211c304
+
211c304
 void gweather_applet_create (GWeatherApplet *gw_applet)
211c304
 {
211c304
     AtkObject *atk_obj;
c94b567
@@ -323,7 +329,7 @@ void gweather_applet_create (GWeatherApp
211c304
     g_signal_connect (GTK_OBJECT(gw_applet->applet), "button_press_event",
211c304
                        GTK_SIGNAL_FUNC(clicked_cb), gw_applet);
211c304
     g_signal_connect (G_OBJECT(gw_applet->applet), "key_press_event",           
211c304
-			G_CALLBACK(key_press_cb), gw_applet);                    
211c304
+			G_CALLBACK(key_press_cb), gw_applet);
211c304
                      
211c304
     gtk_widget_set_tooltip_text (GTK_WIDGET(gw_applet->applet), _("GNOME Weather"));
211c304
 
c94b567
@@ -353,9 +359,9 @@ void gweather_applet_create (GWeatherApp
211c304
 					  NULL);
211c304
     }
211c304
 	
211c304
-    place_widgets(gw_applet);
211c304
-  
211c304
-	return;
211c304
+    place_widgets(gw_applet);        
211c304
+
211c304
+    setup_network_monitor (gw_applet);     
211c304
 }
211c304
 
211c304
 gint timeout_cb (gpointer data)
c94b567
@@ -520,3 +526,88 @@ void gweather_update (GWeatherApplet *gw
211c304
 						    update_finish, gw_applet);
211c304
     }
211c304
 }
211c304
+
c94b567
+static void
c94b567
+state_notify (DBusPendingCall *pending, gpointer data)
c94b567
+{
c94b567
+	GWeatherApplet *gw_applet = data;
c94b567
+
c94b567
+        DBusMessage *msg = dbus_pending_call_steal_reply (pending);
c94b567
+
c94b567
+        if (!msg)
c94b567
+                return;
c94b567
+
c94b567
+        if (dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
c94b567
+                dbus_uint32_t result;
c94b567
+
c94b567
+                if (dbus_message_get_args (msg, NULL,
c94b567
+                                           DBUS_TYPE_UINT32, &result,
c94b567
+                                           DBUS_TYPE_INVALID)) {
c94b567
+                        if (result == NM_STATE_CONNECTED) {
c94b567
+				gweather_update (gw_applet);
c94b567
+                        }
c94b567
+                }
c94b567
+        }
c94b567
+
c94b567
+        dbus_message_unref (msg);
c94b567
+}
c94b567
+
c94b567
+static void
c94b567
+check_network (DBusConnection *connection, gpointer user_data)
c94b567
+{
c94b567
+        DBusMessage *message;
c94b567
+        DBusPendingCall *reply;
c94b567
+
c94b567
+        message = dbus_message_new_method_call (NM_DBUS_SERVICE,
c94b567
+                                                NM_DBUS_PATH,
c94b567
+                                                NM_DBUS_INTERFACE,
c94b567
+                                                "state");
c94b567
+        if (dbus_connection_send_with_reply (connection, message, &reply, -1)) {
c94b567
+                dbus_pending_call_set_notify (reply, state_notify, user_data, NULL);
c94b567
+                dbus_pending_call_unref (reply);
c94b567
+        }
c94b567
+
c94b567
+        dbus_message_unref (message);
c94b567
+}
c94b567
+
211c304
+static DBusHandlerResult
211c304
+filter_func (DBusConnection *connection, DBusMessage *message, void *user_data)
211c304
+{
c94b567
+    if (dbus_message_is_signal (message, 
c94b567
+				NM_DBUS_INTERFACE, 
c94b567
+				"StateChanged")) {
c94b567
+	check_network (connection, user_data);
211c304
+
211c304
+        return DBUS_HANDLER_RESULT_HANDLED;
211c304
+    }
211c304
+
211c304
+    return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
211c304
+}
211c304
+
211c304
+static void
211c304
+setup_network_monitor (GWeatherApplet *gw_applet)
211c304
+{
211c304
+    GError *error;
211c304
+    static DBusGConnection *bus = NULL;
211c304
+    DBusConnection *dbus;
211c304
+
211c304
+    if (bus == NULL) {
211c304
+        error = NULL;
211c304
+        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
211c304
+        if (bus == NULL) {
211c304
+            g_warning ("Couldn't connect to system bus: %s",
211c304
+                       error->message);
211c304
+            g_error_free (error);
211c304
+
211c304
+            return;
211c304
+        }
211c304
+
211c304
+        dbus = dbus_g_connection_get_connection (bus);	
211c304
+        dbus_connection_add_filter (dbus, filter_func, gw_applet, NULL);
211c304
+        dbus_bus_add_match (dbus,
211c304
+                            "type='signal',"
211c304
+                            "interface='" NM_DBUS_INTERFACE_DEVICE "'",
211c304
+                            NULL);
211c304
+    }
211c304
+}	
211c304
+