network-manager-applet r463 - in trunk: . src
- From: dcbw svn gnome org
- To: svn-commits-list gnome org
- Subject: network-manager-applet r463 - in trunk: . src
- Date: Sat, 19 Jan 2008 17:24:59 +0000 (GMT)
Author: dcbw
Date: Sat Jan 19 17:24:59 2008
New Revision: 463
URL: http://svn.gnome.org/viewvc/network-manager-applet?rev=463&view=rev
Log:
2008-01-19 Dan Williams <dcbw redhat com>
* src/applet-device-gsm.c
- (add_connection_items): new function; add each applicable connection
as a menu item
- (gsm_add_menu_item): when more than one connection applies, add each
one as a menu item; when <= 1 apply, add the device as an active
menu item; when multiple subitems are present, make the parent menu
item text gray
* src/applet-device-wireless.c
- (add_new_ap_item): fix crash assigning a conneciton to the menu item
- (add_one_ap_menu_item): pass active connection down too
- (label_expose): remove
- (wireless_add_menu_item): when multiple subitems are present, make the
parent menu item text gray
* src/applet-device-wired.c
- (add_connection_items): new function; add each applicable connection
as a menu item
- (gsm_add_menu_item): when more than one connection applies, add each
one as a menu item; when <= 1 apply, add the device as an active
menu item; when multiple subitems are present, make the parent menu
item text gray
* src/applet.c
src/applet.h
- (find_active_connection_for_device): new function; given a device,
if the device is active or activating, find it's NMConnection
- (nma_menu_add_devices): find the active connection for the device,
and pass that to the device class' add_menu_item() handler
Modified:
trunk/ChangeLog
trunk/src/applet-device-gsm.c
trunk/src/applet-device-wired.c
trunk/src/applet-device-wireless.c
trunk/src/applet.c
trunk/src/applet.h
Modified: trunk/src/applet-device-gsm.c
==============================================================================
--- trunk/src/applet-device-gsm.c (original)
+++ trunk/src/applet-device-gsm.c Sat Jan 19 17:24:59 2008
@@ -102,15 +102,55 @@
}
static void
+add_connection_items (NMDevice *device,
+ GSList *connections,
+ NMConnection *active,
+ GtkWidget *menu,
+ NMApplet *applet)
+{
+ GSList *iter;
+ GSMMenuItemInfo *info;
+
+ for (iter = connections; iter; iter = g_slist_next (iter)) {
+ NMConnection *connection = NM_CONNECTION (iter->data);
+ NMSettingConnection *s_con;
+ GtkWidget *item;
+
+ s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+ item = gtk_check_menu_item_new_with_label (s_con->id);
+ gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+ if (connection == active)
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+ info = g_slice_new0 (GSMMenuItemInfo);
+ info->applet = applet;
+ info->device = g_object_ref (G_OBJECT (device));
+ info->connection = g_object_ref (connection);
+
+ g_signal_connect_data (item, "activate",
+ G_CALLBACK (gsm_menu_item_activate),
+ info,
+ (GClosureNotify) gsm_menu_item_info_destroy, 0);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ }
+}
+
+static void
gsm_add_menu_item (NMDevice *device,
guint32 n_devices,
+ NMConnection *active,
GtkWidget *menu,
NMApplet *applet)
{
- GSMMenuItemInfo *info;
char *text;
- GtkCheckMenuItem *item;
- GSList *connections, *all, *iter;
+ GtkWidget *item;
+ GSList *connections, *all;
+
+ all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
+ connections = utils_filter_connections_for_device (device, all);
+ g_slist_free (all);
if (n_devices > 1) {
const char *desc;
@@ -122,47 +162,44 @@
if (!dev_name)
dev_name = nm_device_get_iface (device);
g_assert (dev_name);
- text = g_strdup_printf (_("GSM Modem (%s)"), dev_name);
+
+ if (g_slist_length (connections) > 1)
+ text = g_strdup_printf (_("GSM Connections (%s)"), dev_name);
+ else
+ text = g_strdup_printf (_("GSM Modem (%s)"), dev_name);
g_free (dev_name);
- } else
- text = g_strdup (_("_GSM Modem"));
+ } else {
+ if (g_slist_length (connections) > 1)
+ text = g_strdup (_("GSM Connections"));
+ else
+ text = g_strdup (_("_GSM Modem"));
+ }
- item = GTK_CHECK_MENU_ITEM (gtk_check_menu_item_new_with_mnemonic (text));
+ if (g_slist_length (connections) > 1) {
+ item = gtk_menu_item_new_with_label (text);
+ } else {
+ item = gtk_check_menu_item_new_with_mnemonic (text);
+ gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
+ }
g_free (text);
- all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
- connections = utils_filter_connections_for_device (device, all);
- g_slist_free (all);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- /* If there's only one connection, don't show the submenu */
if (g_slist_length (connections) > 1) {
- GtkWidget *submenu;
+ GtkWidget *label;
+ char *bold_text;
- submenu = gtk_menu_new ();
+ label = gtk_bin_get_child (GTK_BIN (item));
+ bold_text = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
+ gtk_label_get_text (GTK_LABEL (label)));
+ gtk_label_set_markup (GTK_LABEL (label), bold_text);
+ g_free (bold_text);
- for (iter = connections; iter; iter = g_slist_next (iter)) {
- NMConnection *connection = NM_CONNECTION (iter->data);
- NMSettingConnection *s_con;
- GtkWidget *subitem;
+ gtk_widget_set_sensitive (item, FALSE);
- s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
- subitem = gtk_menu_item_new_with_label (s_con->id);
-
- info = g_slice_new0 (GSMMenuItemInfo);
- info->applet = applet;
- info->device = g_object_ref (G_OBJECT (device));
- info->connection = g_object_ref (connection);
-
- g_signal_connect_data (subitem, "activate",
- G_CALLBACK (gsm_menu_item_activate),
- info,
- (GClosureNotify) gsm_menu_item_info_destroy, 0);
-
- gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (subitem));
- }
-
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+ add_connection_items (device, connections, active, menu, applet);
} else {
+ GSMMenuItemInfo *info;
NMConnection *connection;
info = g_slice_new0 (GSMMenuItemInfo);
@@ -174,28 +211,18 @@
info->connection = g_object_ref (G_OBJECT (connection));
}
+ if ( (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED)
+ || (info->connection && info->connection == active))
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
+
g_signal_connect_data (item, "activate",
G_CALLBACK (gsm_menu_item_activate),
info,
(GClosureNotify) gsm_menu_item_info_destroy, 0);
}
- g_slist_free (connections);
-
- gtk_check_menu_item_set_draw_as_radio (item, TRUE);
- gtk_check_menu_item_set_active (item, nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
- gtk_widget_show (GTK_WIDGET (item));
-
- info = g_slice_new (GSMMenuItemInfo);
- info->applet = applet;
- info->device = device;
- info->connection = NULL; // FIXME
-
- g_signal_connect_data (item, "activate",
- G_CALLBACK (gsm_menu_item_activate),
- info,
- (GClosureNotify) gsm_menu_item_info_destroy, 0);
+ gtk_widget_show (item);
+ g_slist_free (connections);
}
static void
Modified: trunk/src/applet-device-wired.c
==============================================================================
--- trunk/src/applet-device-wired.c (original)
+++ trunk/src/applet-device-wired.c Sat Jan 19 17:24:59 2008
@@ -92,15 +92,58 @@
}
static void
+add_connection_items (NMDevice *device,
+ GSList *connections,
+ gboolean disabled,
+ NMConnection *active,
+ GtkWidget *menu,
+ NMApplet *applet)
+{
+ GSList *iter;
+ WiredMenuItemInfo *info;
+
+ for (iter = connections; iter; iter = g_slist_next (iter)) {
+ NMConnection *connection = NM_CONNECTION (iter->data);
+ NMSettingConnection *s_con;
+ GtkWidget *item;
+
+ s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
+ item = gtk_check_menu_item_new_with_label (s_con->id);
+ gtk_widget_set_sensitive (GTK_WIDGET (item), !disabled);
+ gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+ if (connection == active)
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
+
+ info = g_slice_new0 (WiredMenuItemInfo);
+ info->applet = applet;
+ info->device = g_object_ref (G_OBJECT (device));
+ info->connection = g_object_ref (connection);
+
+ g_signal_connect_data (item, "activate",
+ G_CALLBACK (wired_menu_item_activate),
+ info,
+ (GClosureNotify) wired_menu_item_info_destroy, 0);
+
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ }
+}
+
+static void
wired_add_menu_item (NMDevice *device,
guint32 n_devices,
+ NMConnection *active,
GtkWidget *menu,
NMApplet *applet)
{
char *text;
- GtkCheckMenuItem *item;
- GSList *connections, *all, *iter;
- WiredMenuItemInfo *info;
+ GtkWidget *item;
+ GSList *connections, *all;
+ gboolean disabled = FALSE;
+
+ all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
+ connections = utils_filter_connections_for_device (device, all);
+ g_slist_free (all);
if (n_devices > 1) {
const char *desc;
@@ -112,48 +155,53 @@
if (!dev_name)
dev_name = nm_device_get_iface (device);
g_assert (dev_name);
- text = g_strdup_printf (_("Wired Network (%s)"), dev_name);
- g_free (dev_name);
- } else
- text = g_strdup (_("_Wired Network"));
- item = GTK_CHECK_MENU_ITEM (gtk_check_menu_item_new_with_mnemonic (text));
- g_free (text);
-
- all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
- connections = utils_filter_connections_for_device (device, all);
- g_slist_free (all);
+ if (g_slist_length (connections) > 1)
+ text = g_strdup_printf (_("Wired Networks (%s)"), dev_name);
+ else
+ text = g_strdup_printf (_("Wired Network (%s)"), dev_name);
+ g_free (dev_name);
+ } else {
+ if (g_slist_length (connections) > 1)
+ text = g_strdup (_("Wired Networks"));
+ else
+ text = g_strdup (_("_Wired Network"));
+ }
- /* If there's only one connection, don't show the submenu */
if (g_slist_length (connections) > 1) {
- GtkWidget *submenu;
-
- submenu = gtk_menu_new ();
+ item = gtk_menu_item_new_with_label (text);
+ } else {
+ item = gtk_check_menu_item_new_with_mnemonic (text);
+ gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (item), TRUE);
+ }
+ g_free (text);
- for (iter = connections; iter; iter = g_slist_next (iter)) {
- NMConnection *connection = NM_CONNECTION (iter->data);
- NMSettingConnection *s_con;
- GtkWidget *subitem;
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- s_con = NM_SETTING_CONNECTION (nm_connection_get_setting (connection, NM_TYPE_SETTING_CONNECTION));
- subitem = gtk_menu_item_new_with_label (s_con->id);
+ /* Only dim the item if the device supports carrier detection AND
+ * we know it doesn't have a link.
+ */
+ if (nm_device_get_capabilities (device) & NM_DEVICE_CAP_CARRIER_DETECT) {
+ disabled = nm_device_get_carrier (device) ? FALSE : TRUE;
+ gtk_widget_set_sensitive (GTK_WIDGET (item), disabled);
+ }
- info = g_slice_new0 (WiredMenuItemInfo);
- info->applet = applet;
- info->device = g_object_ref (G_OBJECT (device));
- info->connection = g_object_ref (connection);
+ if (g_slist_length (connections) > 1) {
+ GtkWidget *label;
+ char *bold_text;
- g_signal_connect_data (subitem, "activate",
- G_CALLBACK (wired_menu_item_activate),
- info,
- (GClosureNotify) wired_menu_item_info_destroy, 0);
+ label = gtk_bin_get_child (GTK_BIN (item));
+ bold_text = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
+ gtk_label_get_text (GTK_LABEL (label)));
+ gtk_label_set_markup (GTK_LABEL (label), bold_text);
+ g_free (bold_text);
- gtk_menu_shell_append (GTK_MENU_SHELL (submenu), GTK_WIDGET (subitem));
- }
+ gtk_widget_set_sensitive (item, FALSE);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), submenu);
+ add_connection_items (device, connections, disabled, active, menu, applet);
} else {
NMConnection *connection;
+ WiredMenuItemInfo *info;
info = g_slice_new0 (WiredMenuItemInfo);
info->applet = applet;
@@ -164,31 +212,18 @@
info->connection = g_object_ref (G_OBJECT (connection));
}
+ if ( (nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED)
+ || (info->connection && info->connection == active))
+ gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), TRUE);
+
g_signal_connect_data (item, "activate",
G_CALLBACK (wired_menu_item_activate),
info,
(GClosureNotify) wired_menu_item_info_destroy, 0);
}
- g_slist_free (connections);
-
- gtk_check_menu_item_set_draw_as_radio (item, TRUE);
-
- g_signal_handlers_block_matched (item, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
- G_CALLBACK (wired_menu_item_activate), NULL);
-
- gtk_check_menu_item_set_active (item, nm_device_get_state (device) == NM_DEVICE_STATE_ACTIVATED);
- g_signal_handlers_unblock_matched (item, G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
- G_CALLBACK (wired_menu_item_activate), NULL);
-
- /* Only dim the item if the device supports carrier detection AND
- * we know it doesn't have a link.
- */
- if (nm_device_get_capabilities (device) & NM_DEVICE_CAP_CARRIER_DETECT)
- gtk_widget_set_sensitive (GTK_WIDGET (item), nm_device_get_carrier (device));
-
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
- gtk_widget_show (GTK_WIDGET (item));
+ gtk_widget_show (item);
+ g_slist_free (connections);
}
static void
Modified: trunk/src/applet-device-wireless.c
==============================================================================
--- trunk/src/applet-device-wireless.c (original)
+++ trunk/src/applet-device-wireless.c Sat Jan 19 17:24:59 2008
@@ -414,6 +414,7 @@
NMAccessPoint *ap,
struct dup_data *dup_data,
NMAccessPoint *active_ap,
+ NMConnection *active,
GSList *connections,
GtkWidget *menu,
NMApplet *applet)
@@ -488,7 +489,7 @@
info->ap = g_object_ref (G_OBJECT (ap));
if (g_slist_length (ap_connections) == 1) {
- connection = NM_CONNECTION (g_slist_nth_data (connections, 0));
+ connection = NM_CONNECTION (g_slist_nth_data (ap_connections, 0));
info->connection = g_object_ref (G_OBJECT (connection));
}
@@ -511,6 +512,7 @@
NMAccessPoint *ap,
GSList *connections,
NMAccessPoint *active_ap,
+ NMConnection *active,
GtkWidget *menu,
NMApplet *applet)
{
@@ -544,7 +546,7 @@
nm_network_menu_item_add_dupe (item, ap);
} else {
- item = add_new_ap_item (device, ap, &dup_data, active_ap, connections, menu, applet);
+ item = add_new_ap_item (device, ap, &dup_data, active_ap, active, connections, menu, applet);
}
if (!active_ap)
@@ -611,32 +613,30 @@
return 0;
}
-static gboolean
-label_expose (GtkWidget *widget)
-{
- /* Bad hack to make the label draw normally, instead of insensitive. */
- widget->state = GTK_STATE_NORMAL;
-
- return FALSE;
-}
-
static void
wireless_add_menu_item (NMDevice *device,
guint32 n_devices,
+ NMConnection *active,
GtkWidget *menu,
NMApplet *applet)
{
NMDevice80211Wireless *wdev;
char *text;
- GtkMenuItem *item;
+ GtkWidget *item;
GSList *aps;
GSList *iter;
NMAccessPoint *active_ap = NULL;
GSList *connections = NULL, *all;
+ GtkWidget *label;
+ char *bold_text;
wdev = NM_DEVICE_802_11_WIRELESS (device);
aps = nm_device_802_11_wireless_get_access_points (wdev);
+ all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
+ connections = utils_filter_connections_for_device (device, all);
+ g_slist_free (all);
+
if (n_devices > 1) {
const char *desc;
char *dev_name = NULL;
@@ -646,35 +646,40 @@
dev_name = g_strdup (desc);
if (!dev_name)
dev_name = nm_device_get_iface (device);
- text = g_strdup_printf (ngettext ("Wireless Network (%s)", "Wireless Networks (%s)",
- g_slist_length (aps)), dev_name);
+ g_assert (dev_name);
+
+ if (g_slist_length (aps) > 1)
+ text = g_strdup_printf (_("Wireless Networks (%s)"), dev_name);
+ else
+ text = g_strdup_printf (_("Wireless Network (%s)"), dev_name);
g_free (dev_name);
} else
text = g_strdup (ngettext ("Wireless Network", "Wireless Networks", g_slist_length (aps)));
- item = GTK_MENU_ITEM (gtk_menu_item_new_with_mnemonic (text));
+ item = gtk_menu_item_new_with_mnemonic (text);
g_free (text);
- g_signal_connect (item, "expose-event", G_CALLBACK (label_expose), NULL);
- gtk_widget_set_sensitive (GTK_WIDGET (item), FALSE);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), GTK_WIDGET (item));
- gtk_widget_show (GTK_WIDGET (item));
+ label = gtk_bin_get_child (GTK_BIN (item));
+ bold_text = g_markup_printf_escaped ("<span weight=\"bold\">%s</span>",
+ gtk_label_get_text (GTK_LABEL (label)));
+ gtk_label_set_markup (GTK_LABEL (label), bold_text);
+ g_free (bold_text);
+
+ gtk_widget_set_sensitive (item, FALSE);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
/* Don't display APs when wireless is disabled */
if (!nm_client_wireless_get_enabled (applet->nm_client))
goto out;
- all = applet_dbus_settings_get_all_connections (APPLET_DBUS_SETTINGS (applet->settings));
- connections = utils_filter_connections_for_device (device, all);
- g_slist_free (all);
-
aps = nm_device_802_11_wireless_get_access_points (wdev);
active_ap = nm_device_802_11_wireless_get_active_access_point (wdev);
/* Add all networks in our network list to the menu */
aps = g_slist_sort (aps, sort_wireless_networks);
for (iter = aps; iter; iter = g_slist_next (iter))
- add_one_ap_menu_item (wdev, NM_ACCESS_POINT (iter->data), connections, active_ap, menu, applet);
+ add_one_ap_menu_item (wdev, NM_ACCESS_POINT (iter->data), connections, active_ap, active, menu, applet);
out:
g_slist_free (connections);
Modified: trunk/src/applet.c
==============================================================================
--- trunk/src/applet.c (original)
+++ trunk/src/applet.c Sat Jan 19 17:24:59 2008
@@ -489,6 +489,37 @@
return 0;
}
+static NMConnection *
+find_active_connection_for_device (NMDevice *device, NMApplet *applet)
+{
+ NMConnection *connection = NULL;
+ GSList *iter;
+
+ g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
+ g_return_val_if_fail (NM_IS_APPLET (applet), NULL);
+
+ for (iter = applet->active_connections; iter; iter = g_slist_next (iter)) {
+ NMClientActiveConnection *con = (NMClientActiveConnection *) iter->data;
+
+ if (!g_slist_find (con->devices, device))
+ continue;
+
+ if (!strcmp (con->service_name, NM_DBUS_SERVICE_SYSTEM_SETTINGS)) {
+ connection = applet_dbus_settings_system_get_by_dbus_path (APPLET_DBUS_SETTINGS (applet->settings), con->connection_path);
+ } else if (!strcmp (con->service_name, NM_DBUS_SERVICE_USER_SETTINGS)) {
+ AppletDbusConnectionSettings *tmp;
+
+ tmp = applet_dbus_settings_user_get_by_dbus_path (APPLET_DBUS_SETTINGS (applet->settings), con->connection_path);
+ if (tmp) {
+ connection = applet_dbus_connection_settings_get_connection (NM_CONNECTION_SETTINGS (tmp));
+ break;
+ }
+ }
+ }
+
+ return connection;
+}
+
static void
nma_menu_add_devices (GtkWidget *menu, NMApplet *applet)
{
@@ -526,6 +557,7 @@
NMDevice *device = NM_DEVICE (iter->data);
gint n_devices = 0;
NMADeviceClass *dclass;
+ NMConnection *active;
/* Ignore unsupported devices */
if (!(nm_device_get_capabilities (device) & NM_DEVICE_CAP_NM_SUPPORTED))
@@ -536,9 +568,11 @@
else if (NM_IS_DEVICE_802_3_ETHERNET (device))
n_devices = n_wired_interfaces++;
+ active = find_active_connection_for_device (device, applet);
+
dclass = get_device_class (device, applet);
g_assert (dclass);
- dclass->add_menu_item (device, n_devices, menu, applet);
+ dclass->add_menu_item (device, n_devices, active, menu, applet);
}
if (n_wireless_interfaces > 0 && nm_client_wireless_get_enabled (applet->nm_client)) {
Modified: trunk/src/applet.h
==============================================================================
--- trunk/src/applet.h (original)
+++ trunk/src/applet.h Sat Jan 19 17:24:59 2008
@@ -149,7 +149,7 @@
struct NMADeviceClass {
NMConnection * (*new_auto_connection) (NMDevice *device, NMApplet *applet, gpointer user_data);
- void (*add_menu_item) (NMDevice *device, guint32 num_devices, GtkWidget *menu, NMApplet *applet);
+ void (*add_menu_item) (NMDevice *device, guint32 num_devices, NMConnection *active, GtkWidget *menu, NMApplet *applet);
void (*device_added) (NMDevice *device, NMApplet *applet);
void (*device_state_changed) (NMDevice *device, NMDeviceState state, NMApplet *applet);
GdkPixbuf * (*get_icon) (NMDevice *device, NMDeviceState state, char **tip, NMApplet *applet);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]