summaryrefslogtreecommitdiff
path: root/mateweather/mateweather-applet.c
diff options
context:
space:
mode:
authorinfirit <[email protected]>2014-11-26 19:02:40 +0100
committerinfirit <[email protected]>2014-11-26 19:02:40 +0100
commit3f46f5fe76c4e48dde9d1bb6f8953bbce9e09702 (patch)
treed6aa5eac0e75bf555f63fc9c4ad2e08439834cf7 /mateweather/mateweather-applet.c
parent43317956a07ab6e4d70716d82beebd6751bd68d0 (diff)
downloadmate-applets-3f46f5fe76c4e48dde9d1bb6f8953bbce9e09702.tar.bz2
mate-applets-3f46f5fe76c4e48dde9d1bb6f8953bbce9e09702.tar.xz
mateweather, invest: use GNetworkMonitor
Rather than talking to NetworkManager over D-Bus, use GNetworkMonitor to monitor the network state. Taken from gnome-applets commit: 9b53c7156b61d51777dbe2f60c55125c86b3409c From: Dan Winship <[email protected]>
Diffstat (limited to 'mateweather/mateweather-applet.c')
-rw-r--r--mateweather/mateweather-applet.c122
1 files changed, 20 insertions, 102 deletions
diff --git a/mateweather/mateweather-applet.c b/mateweather/mateweather-applet.c
index fcaa7295..4dc26a16 100644
--- a/mateweather/mateweather-applet.c
+++ b/mateweather/mateweather-applet.c
@@ -33,12 +33,6 @@
#define MATEWEATHER_I_KNOW_THIS_IS_UNSTABLE
-#ifdef HAVE_NETWORKMANAGER
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <NetworkManager/NetworkManager.h>
-#endif
-
#include "mateweather.h"
#include "mateweather-about.h"
#include "mateweather-pref.h"
@@ -280,8 +274,19 @@ key_press_cb (GtkWidget *widget, GdkEventKey *event, MateWeatherApplet *gw_apple
}
static void
+network_changed (GNetworkMonitor *monitor, gboolean available, MateWeatherApplet *gw_applet)
+{
+ if (available) {
+ mateweather_update (gw_applet);
+ }
+}
+
+
+static void
applet_destroy (GtkWidget *widget, MateWeatherApplet *gw_applet)
{
+ GNetworkMonitor *monitor;
+
if (gw_applet->pref_dialog)
gtk_widget_destroy (gw_applet->pref_dialog);
@@ -303,18 +308,20 @@ applet_destroy (GtkWidget *widget, MateWeatherApplet *gw_applet)
gw_applet->settings = NULL;
}
+ monitor = g_network_monitor_get_default ();
+ g_signal_handlers_disconnect_by_func (monitor,
+ G_CALLBACK (network_changed),
+ gw_applet);
+
weather_info_abort (gw_applet->mateweather_info);
}
-#ifdef HAVE_NETWORKMANAGER
-static void setup_network_monitor (MateWeatherApplet *gw_applet);
-#endif
-
void mateweather_applet_create (MateWeatherApplet *gw_applet)
{
GtkActionGroup *action_group;
gchar *ui_path;
AtkObject *atk_obj;
+ GNetworkMonitor*monitor;
gw_applet->mateweather_pref.location = NULL;
gw_applet->mateweather_pref.show_notifications = FALSE;
@@ -381,10 +388,9 @@ void mateweather_applet_create (MateWeatherApplet *gw_applet)
place_widgets(gw_applet);
-#ifdef HAVE_NETWORKMANAGER
- setup_network_monitor (gw_applet);
-#endif
-}
+ monitor = g_network_monitor_get_default();
+ g_signal_connect (monitor, "network-changed",
+ G_CALLBACK (network_changed), gw_applet);}
gint timeout_cb (gpointer data)
{
@@ -545,91 +551,3 @@ void mateweather_update (MateWeatherApplet *gw_applet)
update_finish, gw_applet);
}
}
-
-#ifdef HAVE_NETWORKMANAGER
-static void
-state_notify (DBusPendingCall *pending, gpointer data)
-{
- MateWeatherApplet *gw_applet = data;
-
- DBusMessage *msg = dbus_pending_call_steal_reply (pending);
-
- if (!msg)
- return;
-
- if (dbus_message_get_type (msg) == DBUS_MESSAGE_TYPE_METHOD_RETURN) {
- dbus_uint32_t result;
-
- if (dbus_message_get_args (msg, NULL,
- DBUS_TYPE_UINT32, &result,
- DBUS_TYPE_INVALID)) {
- if (result == NM_STATE_CONNECTED) {
- /* thank you, glibc */
- res_init ();
- mateweather_update (gw_applet);
- }
- }
- }
-
- dbus_message_unref (msg);
-}
-
-static void
-check_network (DBusConnection *connection, gpointer user_data)
-{
- DBusMessage *message;
- DBusPendingCall *reply;
-
- message = dbus_message_new_method_call (NM_DBUS_SERVICE,
- NM_DBUS_PATH,
- NM_DBUS_INTERFACE,
- "state");
- if (dbus_connection_send_with_reply (connection, message, &reply, -1)) {
- dbus_pending_call_set_notify (reply, state_notify, user_data, NULL);
- dbus_pending_call_unref (reply);
- }
-
- dbus_message_unref (message);
-}
-
-static DBusHandlerResult
-filter_func (DBusConnection *connection, DBusMessage *message, void *user_data)
-{
- if (dbus_message_is_signal (message,
- NM_DBUS_INTERFACE,
- "StateChanged")) {
- check_network (connection, user_data);
-
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-}
-
-static void
-setup_network_monitor (MateWeatherApplet *gw_applet)
-{
- GError *error;
- static DBusGConnection *bus = NULL;
- DBusConnection *dbus;
-
- if (bus == NULL) {
- error = NULL;
- bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
- if (bus == NULL) {
- g_warning ("Couldn't connect to system bus: %s",
- error->message);
- g_error_free (error);
-
- return;
- }
-
- dbus = dbus_g_connection_get_connection (bus);
- dbus_connection_add_filter (dbus, filter_func, gw_applet, NULL);
- dbus_bus_add_match (dbus,
- "type='signal',"
- "interface='" NM_DBUS_INTERFACE "'",
- NULL);
- }
-}
-#endif /* HAVE_NETWORKMANAGER */