network-manager-applet r1180 - in trunk: . src



Author: dcbw
Date: Wed Feb 18 16:16:19 2009
New Revision: 1180
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=1180&view=rev

Log:
2009-02-18  Dan Williams  <dcbw redhat com>

	* src/applet.c
		- (ICON_LOAD): don't segfault if err is NULL (bgo #548062)
		- (finalize): dispose of the settings proxies after disposing
			of the NMClient so that the new-ap-notification stuff
			in applet-device-wifi.c does log errors when disposing
			of its data
		- (constructor): ensure the missing gladefile warning dialog sticks around
		- (nma_icons_load): ensure the missing icon warning dialog sticks around

	* src/applet-dialogs.c
	  src/applet-dialogs.h
		- (applet_warning_dialog_show): return the dialog object so the caller
			can do something useful with it (like gtk_dialog_run()); fix
			focus-stealing prevention, and set a title and icon

	* src/main.c
		- Pass the mainloop to the applet



Modified:
   trunk/ChangeLog
   trunk/src/applet-dialogs.c
   trunk/src/applet-dialogs.h
   trunk/src/applet.c
   trunk/src/applet.h
   trunk/src/main.c

Modified: trunk/src/applet-dialogs.c
==============================================================================
--- trunk/src/applet-dialogs.c	(original)
+++ trunk/src/applet-dialogs.c	Wed Feb 18 16:16:19 2009
@@ -613,22 +613,24 @@
 }
 
 
-gboolean
+GtkWidget *
 applet_warning_dialog_show (const char *message)
 {
 	GtkWidget *dialog;
 
-	dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, message, NULL);
+	dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, message, NULL);
 
 	/* Bash focus-stealing prevention in the face */
 	gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ALWAYS);
+	gtk_window_set_default_icon_name (GTK_STOCK_DIALOG_ERROR);
+	gtk_window_set_title (GTK_WINDOW (dialog), _("Missing resources"));
 	gtk_widget_realize (dialog);
-	gdk_x11_window_set_user_time (dialog->window, gdk_x11_get_server_time (dialog->window));
-	gtk_window_present (GTK_WINDOW (dialog));
+	gtk_widget_show (dialog);
+	gtk_window_present_with_time (GTK_WINDOW (dialog), gdk_x11_get_server_time (dialog->window));
 
 	g_signal_connect_swapped (dialog, "response",
 	                          G_CALLBACK (gtk_widget_destroy),
 	                          dialog);
-	return FALSE;
+	return dialog;
 }
 

Modified: trunk/src/applet-dialogs.h
==============================================================================
--- trunk/src/applet-dialogs.h	(original)
+++ trunk/src/applet-dialogs.h	Wed Feb 18 16:16:19 2009
@@ -31,7 +31,7 @@
 
 void applet_about_dialog_show (NMApplet *applet);
 
-gboolean applet_warning_dialog_show (const char *message);
+GtkWidget *applet_warning_dialog_show (const char *message);
 
 
 #endif /* __APPLET_DIALOGS_H__ */

Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c	(original)
+++ trunk/src/applet.c	Wed Feb 18 16:16:19 2009
@@ -2233,12 +2233,13 @@
 	applet->icons_loaded = FALSE;
 }
 
-#define ICON_LOAD(x, y)	\
+#define ICON_LOAD(icon, name) \
 	{ \
-		x = gtk_icon_theme_load_icon (applet->icon_theme, y, applet->size, 0, &err); \
-		if (x == NULL) { \
-			g_warning ("Icon %s missing: %s", y, err->message); \
-			g_error_free (err); \
+		icon = gtk_icon_theme_load_icon (applet->icon_theme, name, applet->size, 0, &err); \
+		if (icon == NULL) { \
+			g_warning ("Icon %s missing: %s", name, \
+			           (err && err->message) ? err->message : "unknown"); \
+			g_clear_error (&err); \
 			goto out; \
 		} \
 	}
@@ -2288,8 +2289,11 @@
 
 out:
 	if (!applet->icons_loaded) {
-		applet_warning_dialog_show (_("The NetworkManager applet could not find some required resources.  It cannot continue.\n"));
-		nma_icons_free (applet);
+		GtkWidget *dialog;
+
+		dialog = applet_warning_dialog_show (_("The NetworkManager applet could not find some required resources.  It cannot continue.\n"));
+		gtk_dialog_run (GTK_DIALOG (dialog));
+		g_main_loop_quit (applet->loop);
 	}
 
 	return applet->icons_loaded;
@@ -2469,7 +2473,7 @@
              GObjectConstructParam *construct_props)
 {
 	NMApplet *applet;
-	AppletDBusManager * dbus_mgr;
+	AppletDBusManager *dbus_mgr;
 
 	applet = NM_APPLET (G_OBJECT_CLASS (nma_parent_class)->constructor (type, n_props, construct_props));
 
@@ -2478,21 +2482,23 @@
 
 	applet->glade_file = g_build_filename (GLADEDIR, "applet.glade", NULL);
 	if (!applet->glade_file || !g_file_test (applet->glade_file, G_FILE_TEST_IS_REGULAR)) {
-		applet_warning_dialog_show (_("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
+		GtkWidget *dialog;
+		dialog = applet_warning_dialog_show (_("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
+		gtk_dialog_run (GTK_DIALOG (dialog));
 		goto error;
 	}
 
 	applet->info_dialog_xml = glade_xml_new (applet->glade_file, "info_dialog", NULL);
 	if (!applet->info_dialog_xml)
-        goto error;
+		goto error;
 
 	applet->gconf_client = gconf_client_get_default ();
 	if (!applet->gconf_client)
-	    goto error;
+		goto error;
 
 	/* Load pixmaps and create applet widgets */
 	if (!setup_widgets (applet))
-	    goto error;
+		goto error;
 	nma_icons_init (applet);
 
 	if (!notify_is_initted ())
@@ -2513,14 +2519,14 @@
 	                  applet);
 
 	dbus_g_connection_register_g_object (applet_dbus_manager_get_connection (dbus_mgr),
-										 NM_DBUS_PATH_SETTINGS,
-										 G_OBJECT (applet->gconf_settings));
+	                                     NM_DBUS_PATH_SETTINGS,
+	                                     G_OBJECT (applet->gconf_settings));
 
-    /* Start our DBus service */
-    if (!applet_dbus_manager_start_service (dbus_mgr)) {
-		g_object_unref (applet);
-		return NULL;
-    }
+	/* Start our DBus service */
+	if (!applet_dbus_manager_start_service (dbus_mgr)) {
+			g_object_unref (applet);
+			return NULL;
+	}
 
 	/* Initialize device classes */
 	applet->wired_class = applet_device_wired_get_class (applet);
@@ -2580,12 +2586,8 @@
 	if (applet->info_dialog_xml)
 		g_object_unref (applet->info_dialog_xml);
 
-	g_object_unref (applet->gconf_settings);
-	applet->gconf_settings = NULL;
-	g_object_unref (applet->dbus_settings);
-	applet->dbus_settings = NULL;
-
-	g_object_unref (applet->gconf_client);
+	if (applet->gconf_client)
+		g_object_unref (applet->gconf_client);
 
 	if (applet->status_icon)
 		g_object_unref (applet->status_icon);
@@ -2593,6 +2595,15 @@
 	if (applet->nm_client)
 		g_object_unref (applet->nm_client);
 
+	if (applet->gconf_settings) {
+		g_object_unref (applet->gconf_settings);
+		applet->gconf_settings = NULL;
+	}
+	if (applet->dbus_settings) {
+		g_object_unref (applet->dbus_settings);
+		applet->dbus_settings = NULL;
+	}
+
 	G_OBJECT_CLASS (nma_parent_class)->finalize (object);
 }
 
@@ -2605,17 +2616,44 @@
 	applet->size = -1;
 }
 
+enum {
+	PROP_0,
+	PROP_LOOP,
+	LAST_PROP
+};
+
+static void
+set_property (GObject *object, guint prop_id,
+              const GValue *value, GParamSpec *pspec)
+{
+	NMApplet *applet = NM_APPLET (object);
+
+	switch (prop_id) {
+	case PROP_LOOP:
+		applet->loop = g_value_get_pointer (value);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
 static void nma_class_init (NMAppletClass *klass)
 {
-	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+	GObjectClass *oclass = G_OBJECT_CLASS (klass);
+	GParamSpec *pspec;
+
+	oclass->set_property = set_property;
+	oclass->constructor = constructor;
+	oclass->finalize = finalize;
 
-	gobject_class->constructor = constructor;
-	gobject_class->finalize = finalize;
+	pspec = g_param_spec_pointer ("loop", "Loop", "Applet mainloop", G_PARAM_CONSTRUCT | G_PARAM_WRITABLE);
+	g_object_class_install_property (oclass, PROP_LOOP, pspec);
 }
 
 NMApplet *
-nm_applet_new ()
+nm_applet_new (GMainLoop *loop)
 {
-	return g_object_new (NM_TYPE_APPLET, NULL);
+	return g_object_new (NM_TYPE_APPLET, "loop", loop, NULL);
 }
 

Modified: trunk/src/applet.h
==============================================================================
--- trunk/src/applet.h	(original)
+++ trunk/src/applet.h	Wed Feb 18 16:16:19 2009
@@ -80,6 +80,7 @@
 {
 	GObject parent_instance;
 
+	GMainLoop *loop;
 	NMClient *nm_client;
 
 	NMDBusSettings *dbus_settings;
@@ -187,7 +188,7 @@
 
 GType nma_get_type (void);
 
-NMApplet *nm_applet_new (void);
+NMApplet *nm_applet_new (GMainLoop *loop);
 
 void applet_schedule_update_icon (NMApplet *applet);
 

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Wed Feb 18 16:16:19 2009
@@ -68,11 +68,12 @@
 	gtk_init (&argc, &argv);
 	textdomain (GETTEXT_PACKAGE);
 
-	applet = nm_applet_new ();
+	loop = g_main_loop_new (NULL, FALSE);
+
+	applet = nm_applet_new (loop);
 	if (applet == NULL)
 		exit (1);
 
-	loop = g_main_loop_new (NULL, FALSE);
 	setup_signals ();
 	g_main_loop_run (loop);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]