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



Author: dcbw
Date: Sun Jan 13 15:02:17 2008
New Revision: 444
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=444&view=rev

Log:
2008-01-12  Dan Williams  <dcbw redhat com>

	* src/applet.c
		- Rearrange constructor() and finalize() closer to the rest of the
			applet GObject related functions, and move icons-related functions
			there as well to reduce the need to prototypes.



Modified:
   trunk/ChangeLog
   trunk/src/applet.c

Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c	(original)
+++ trunk/src/applet.c	Sun Jan 13 15:02:17 2008
@@ -77,12 +77,10 @@
 #include "vpn-connection-info.h"
 #include "connection-editor/nm-connection-list.h"
 
-static GObject * nma_constructor (GType type, guint n_props, GObjectConstructParam *construct_props);
-static void      nma_icons_init (NMApplet *applet);
-static void      nma_icons_free (NMApplet *applet);
-static void      nma_icons_zero (NMApplet *applet);
-static gboolean  nma_icons_load_from_disk (NMApplet *applet);
-static void      nma_finalize (GObject *object);
+static void nma_icons_init (NMApplet *applet);
+static void nma_icons_free (NMApplet *applet);
+static gboolean nma_icons_load (NMApplet *applet);
+
 static void      foo_set_icon (NMApplet *applet, GdkPixbuf *pixbuf, guint32 layer);
 static void		 foo_update_icon (NMApplet *applet);
 static void      foo_device_state_changed (NMDevice *device, NMDeviceState state, gpointer user_data, gboolean synthetic);
@@ -116,28 +114,6 @@
 	return dev;
 }
 
-static void nma_init (NMApplet *applet)
-{
-	applet->animation_id = 0;
-	applet->animation_step = 0;
-	applet->icon_theme = NULL;
-	applet->notification = NULL;
-	applet->size = -1;
-
-	nma_icons_zero (applet);
-
-/*	gtk_window_set_default_icon_from_file (ICONDIR"/NMApplet/wireless-applet.png", NULL); */
-}
-
-static void nma_class_init (NMAppletClass *klass)
-{
-	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
-	gobject_class->constructor = nma_constructor;
-	gobject_class->finalize = nma_finalize;
-}
-
-
 typedef struct {
 	NMApplet *applet;
 	NMDevice *device;
@@ -1800,7 +1776,7 @@
 	nma_icons_free (applet);
 
 	applet->size = size;
-	nma_icons_load_from_disk (applet);
+	nma_icons_load (applet);
 
 	list = nm_client_get_devices (applet->nm_client);
 	if (list) {
@@ -2966,126 +2942,36 @@
 
 /*****************************************************************************/
 
-/*
- * nma_finalize
- *
- * Destroy the applet and clean up its data
- *
- */
-static void nma_finalize (GObject *object)
-{
-	NMApplet *applet = NM_APPLET (object);
-
-	nma_menu_clear (applet);
-	nma_icons_free (applet);
-
-	if (applet->notification) {
-		notify_notification_close (applet->notification, NULL);
-		g_object_unref (applet->notification);
-	}
-
-	g_free (applet->glade_file);
-	if (applet->info_dialog_xml)
-		g_object_unref (applet->info_dialog_xml);
-
-	g_object_unref (applet->gconf_client);
-
-	if (applet->status_icon)
-		g_object_unref (applet->status_icon);
-
-	g_hash_table_destroy (applet->vpn_connections);
-	g_object_unref (applet->vpn_manager);
-	g_object_unref (applet->nm_client);
-
-	clear_active_connections (applet);
-
-	if (applet->nm_client)
-		g_object_unref (applet->nm_client);
-
-	crypto_deinit ();
-
-	G_OBJECT_CLASS (nma_parent_class)->finalize (object);
-}
-
-static GObject *
-nma_constructor (GType type,
-                 guint n_props,
-                 GObjectConstructParam *construct_props)
+static void nma_icons_zero (NMApplet *applet)
 {
-	NMApplet *applet;
-	AppletDBusManager * dbus_mgr;
-	GError *error = NULL;
-
-	if (!crypto_init (&error)) {
-		g_warning ("Couldn't initilize crypto system: %d %s",
-		           error->code, error->message);
-		g_error_free (error);
-		return NULL;
-	}
-
-	applet = NM_APPLET (G_OBJECT_CLASS (nma_parent_class)->constructor (type, n_props, construct_props));
-
-	g_set_application_name (_("NetworkManager Applet"));
-	gtk_window_set_default_icon_name (GTK_STOCK_NETWORK);
-
-	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)."));
-		goto error;
-	}
+	int i, j;
 
-	applet->info_dialog_xml = glade_xml_new (applet->glade_file, "info_dialog", NULL);
-	if (!applet->info_dialog_xml)
-        goto error;
-
-	applet->gconf_client = gconf_client_get_default ();
-	if (!applet->gconf_client)
-	    goto error;
+	applet->no_connection_icon = NULL;
+	applet->wired_icon = NULL;
+	applet->adhoc_icon = NULL;
+	applet->gsm_icon = NULL;
+	applet->vpn_lock_icon = NULL;
 
-	/* Load pixmaps and create applet widgets */
-	if (!nma_setup_widgets (applet))
-	    goto error;
-	nma_icons_init (applet);
+	applet->wireless_00_icon = NULL;
+	applet->wireless_25_icon = NULL;
+	applet->wireless_50_icon = NULL;
+	applet->wireless_75_icon = NULL;
+	applet->wireless_100_icon = NULL;
 
-	applet->active_connections = NULL;
-	
-	dbus_mgr = applet_dbus_manager_get ();
-	if (dbus_mgr == NULL) {
-		nm_warning ("Couldn't initialize the D-Bus manager.");
-		g_object_unref (applet);
-		return NULL;
+	for (i = 0; i < NUM_CONNECTING_STAGES; i++) {
+		for (j = 0; j < NUM_CONNECTING_FRAMES; j++)
+			applet->network_connecting_icons[i][j] = NULL;
 	}
 
-	applet->settings = applet_dbus_settings_new ();
-	g_signal_connect (G_OBJECT (applet->settings), "new-secrets-requested",
-	                  (GCallback) applet_settings_new_secrets_requested_cb,
-	                  applet);
-
-	applet_add_default_ethernet_connection ((AppletDbusSettings *) applet->settings);
-
-    /* Start our DBus service */
-    if (!applet_dbus_manager_start_service (dbus_mgr)) {
-		g_object_unref (applet);
-		return NULL;
-    }
-
-	foo_client_setup (applet);
-	applet->vpn_manager = nm_vpn_manager_new ();
-	applet->vpn_connections = g_hash_table_new_full (g_str_hash, g_str_equal,
-										    (GDestroyNotify) g_free,
-										    (GDestroyNotify) g_object_unref);
-
-	return G_OBJECT (applet);
+	for (i = 0; i < NUM_VPN_CONNECTING_FRAMES; i++)
+		applet->vpn_connecting_icons[i] = NULL;
 
-error:
-	g_object_unref (applet);
-	return NULL;
+	applet->icons_loaded = FALSE;
 }
 
-
 static void nma_icons_free (NMApplet *applet)
 {
-	int i;
+	int i, j;
 
 	if (!applet->icons_loaded)
 		return;
@@ -3118,8 +3004,6 @@
 		g_object_unref (applet->wireless_100_icon);
 
 	for (i = 0; i < NUM_CONNECTING_STAGES; i++) {
-		int j;
-
 		for (j = 0; j < NUM_CONNECTING_FRAMES; j++)
 			if (applet->network_connecting_icons[i][j])
 				g_object_unref (applet->network_connecting_icons[i][j]);
@@ -3132,36 +3016,6 @@
 	nma_icons_zero (applet);
 }
 
-static void nma_icons_zero (NMApplet *applet)
-{
-	int i;
-
-	applet->no_connection_icon = NULL;
-	applet->wired_icon = NULL;
-	applet->adhoc_icon = NULL;
-	applet->gsm_icon = NULL;
-	applet->vpn_lock_icon = NULL;
-
-	applet->wireless_00_icon = NULL;
-	applet->wireless_25_icon = NULL;
-	applet->wireless_50_icon = NULL;
-	applet->wireless_75_icon = NULL;
-	applet->wireless_100_icon = NULL;
-
-	for (i = 0; i < NUM_CONNECTING_STAGES; i++)
-	{
-		int j;
-
-		for (j = 0; j < NUM_CONNECTING_FRAMES; j++)
-			applet->network_connecting_icons[i][j] = NULL;
-	}
-
-	for (i = 0; i < NUM_VPN_CONNECTING_FRAMES; i++)
-		applet->vpn_connecting_icons[i] = NULL;
-
-	applet->icons_loaded = FALSE;
-}
-
 #define ICON_LOAD(x, y)	\
 	{		\
 		GError *err = NULL; \
@@ -3175,7 +3029,7 @@
 	}
 
 static gboolean
-nma_icons_load_from_disk (NMApplet *applet)
+nma_icons_load (NMApplet *applet)
 {
 	int 		size, i;
 	gboolean	success;
@@ -3243,7 +3097,7 @@
 static void nma_icon_theme_changed (GtkIconTheme *icon_theme, NMApplet *applet)
 {
 	nma_icons_free (applet);
-	nma_icons_load_from_disk (applet);
+	nma_icons_load (applet);
 }
 
 static void nma_icons_init (NMApplet *applet)
@@ -3279,6 +3133,135 @@
 	g_signal_connect (applet->icon_theme, "changed", G_CALLBACK (nma_icon_theme_changed), applet);
 }
 
+static GObject *
+constructor (GType type,
+             guint n_props,
+             GObjectConstructParam *construct_props)
+{
+	NMApplet *applet;
+	AppletDBusManager * dbus_mgr;
+	GError *error = NULL;
+
+	if (!crypto_init (&error)) {
+		g_warning ("Couldn't initilize crypto system: %d %s",
+		           error->code, error->message);
+		g_error_free (error);
+		return NULL;
+	}
+
+	applet = NM_APPLET (G_OBJECT_CLASS (nma_parent_class)->constructor (type, n_props, construct_props));
+
+	g_set_application_name (_("NetworkManager Applet"));
+	gtk_window_set_default_icon_name (GTK_STOCK_NETWORK);
+
+	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)."));
+		goto error;
+	}
+
+	applet->info_dialog_xml = glade_xml_new (applet->glade_file, "info_dialog", NULL);
+	if (!applet->info_dialog_xml)
+        goto error;
+
+	applet->gconf_client = gconf_client_get_default ();
+	if (!applet->gconf_client)
+	    goto error;
+
+	/* Load pixmaps and create applet widgets */
+	if (!nma_setup_widgets (applet))
+	    goto error;
+	nma_icons_init (applet);
+
+	applet->active_connections = NULL;
+	
+	dbus_mgr = applet_dbus_manager_get ();
+	if (dbus_mgr == NULL) {
+		nm_warning ("Couldn't initialize the D-Bus manager.");
+		g_object_unref (applet);
+		return NULL;
+	}
+
+	applet->settings = applet_dbus_settings_new ();
+	g_signal_connect (G_OBJECT (applet->settings), "new-secrets-requested",
+	                  (GCallback) applet_settings_new_secrets_requested_cb,
+	                  applet);
+
+	applet_add_default_ethernet_connection ((AppletDbusSettings *) applet->settings);
+
+    /* Start our DBus service */
+    if (!applet_dbus_manager_start_service (dbus_mgr)) {
+		g_object_unref (applet);
+		return NULL;
+    }
+
+	foo_client_setup (applet);
+	applet->vpn_manager = nm_vpn_manager_new ();
+	applet->vpn_connections = g_hash_table_new_full (g_str_hash, g_str_equal,
+										    (GDestroyNotify) g_free,
+										    (GDestroyNotify) g_object_unref);
+
+	return G_OBJECT (applet);
+
+error:
+	g_object_unref (applet);
+	return NULL;
+}
+
+static void finalize (GObject *object)
+{
+	NMApplet *applet = NM_APPLET (object);
+
+	nma_menu_clear (applet);
+	nma_icons_free (applet);
+
+	if (applet->notification) {
+		notify_notification_close (applet->notification, NULL);
+		g_object_unref (applet->notification);
+	}
+
+	g_free (applet->glade_file);
+	if (applet->info_dialog_xml)
+		g_object_unref (applet->info_dialog_xml);
+
+	g_object_unref (applet->gconf_client);
+
+	if (applet->status_icon)
+		g_object_unref (applet->status_icon);
+
+	g_hash_table_destroy (applet->vpn_connections);
+	g_object_unref (applet->vpn_manager);
+	g_object_unref (applet->nm_client);
+
+	clear_active_connections (applet);
+
+	if (applet->nm_client)
+		g_object_unref (applet->nm_client);
+
+	crypto_deinit ();
+
+	G_OBJECT_CLASS (nma_parent_class)->finalize (object);
+}
+
+static void nma_init (NMApplet *applet)
+{
+	applet->animation_id = 0;
+	applet->animation_step = 0;
+	applet->icon_theme = NULL;
+	applet->notification = NULL;
+	applet->size = -1;
+
+	nma_icons_zero (applet);
+}
+
+static void nma_class_init (NMAppletClass *klass)
+{
+	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+	gobject_class->constructor = constructor;
+	gobject_class->finalize = finalize;
+}
+
 NMApplet *
 nm_applet_new ()
 {



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