netspeed r121 - trunk/src



Author: bdejean
Date: Mon Jun 30 21:51:21 2008
New Revision: 121
URL: http://svn.gnome.org/viewvc/netspeed?rev=121&view=rev

Log:
Merged duplicate code into new function set_applet_devinfo(applet, iface).


Modified:
   trunk/src/netspeed.c

Modified: trunk/src/netspeed.c
==============================================================================
--- trunk/src/netspeed.c	(original)
+++ trunk/src/netspeed.c	Mon Jun 30 21:51:21 2008
@@ -520,6 +520,25 @@
 	g_object_unref(G_OBJECT(window));
 }
 
+
+static gboolean
+set_applet_devinfo(NetspeedApplet* applet, const char* iface)
+{
+	DevInfo info;
+
+	get_device_info(iface, &info);
+
+	if (info.running) {
+		free_device_info(&applet->devinfo);
+		applet->devinfo = info;
+		applet->device_has_changed = TRUE;
+		return TRUE;
+	}
+
+	free_device_info(&info);
+	return FALSE;
+}
+
 /* Find the first available device, that is running and != lo */
 static void
 search_for_up_if(NetspeedApplet *applet)
@@ -531,28 +550,16 @@
 	default_route = get_default_route();
     
 	if (default_route != NULL) {
-		get_device_info(default_route, &info);
-		if (info.running) {
-			free_device_info(&applet->devinfo);
-			applet->devinfo = info;
-			applet->device_has_changed = TRUE;
+		if (set_applet_devinfo(applet, default_route))
 			return;
-		}
-		free_device_info(&info);
 	}
 
 	devices = get_available_devices();
 	for (tmp = devices; tmp; tmp = g_list_next(tmp)) {
 		if (is_no_dummy_device(tmp->data) == FALSE)
 			continue;
-		get_device_info(tmp->data, &info);
-		if (info.running) {
-			free_device_info(&applet->devinfo);
-			applet->devinfo = info;
-			applet->device_has_changed = TRUE;
+		if (set_applet_devinfo(applet, tmp->data))
 			break;
-		}
-		free_device_info(&info);
 	}
 	free_devices_list(devices);
 }



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