Fri Aug 28 2004 Dan Williams <dcbw@redhat.com>

* panel-applet/NMWirelessApplet.c
		- Make current device bold
		- Show more user-friendly device name if we got one from hal

	* panel-applet/NMWirelessAppletDbus.c
		- Grab "info.product" key from hal for network devices
		- Cache the current active device


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@92 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
Dan Williams 2004-08-27 19:42:47 +00:00
parent 9dccb3c351
commit 7fd3e529b4
5 changed files with 162 additions and 13 deletions

View file

@ -1,3 +1,13 @@
Fri Aug 28 2004 Dan Williams <dcbw@redhat.com>
* panel-applet/NMWirelessApplet.c
- Make current device bold
- Show more user-friendly device name if we got one from hal
* panel-applet/NMWirelessAppletDbus.c
- Grab "info.product" key from hal for network devices
- Cache the current active device
2004-08-27 Adam Weinberger <adamw@gnome.org>
* configure.in: Added en_CA to ALL_LINGUAS.

View file

@ -500,7 +500,7 @@ void nmwa_menu_add_text_item (GtkWidget *menu, char *text)
* Add a network device to the menu
*
*/
void nmwa_menu_add_device_item (GtkWidget *menu, GdkPixbuf *icon, char *name, char *nm_device, gpointer user_data)
void nmwa_menu_add_device_item (GtkWidget *menu, GdkPixbuf *icon, char *name, char *nm_device, gboolean current, gpointer user_data)
{
GtkWidget *menu_item;
GtkWidget *label;
@ -524,6 +524,12 @@ void nmwa_menu_add_device_item (GtkWidget *menu, GdkPixbuf *icon, char *name, ch
}
label = gtk_label_new (name);
if (current)
{
char *markup = g_strdup_printf ("<span weight=\"bold\">%s</span>", name);
gtk_label_set_markup (GTK_LABEL (label), markup);
g_free (markup);
}
gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 2);
gtk_widget_show (label);
@ -561,7 +567,12 @@ void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet)
if (dev && ((dev->type == DEVICE_TYPE_WIRED_ETHERNET) || (dev->type == DEVICE_TYPE_WIRELESS_ETHERNET)))
{
GdkPixbuf *icon = (dev->type == DEVICE_TYPE_WIRED_ETHERNET) ? applet->wired_icon : applet->wireless_icon;
nmwa_menu_add_device_item (menu, icon, dev->name, dev->nm_device, applet);
char *name_string;
gboolean current = applet->active_device ? (strcmp (applet->active_device, dev->nm_device) == 0) : FALSE;
name_string = g_strdup_printf ("%s (%s)", (dev->hal_name ? dev->hal_name : dev->nm_name),
(dev->type == DEVICE_TYPE_WIRED_ETHERNET) ? "wired" : "wireless");
nmwa_menu_add_device_item (menu, icon, name_string, dev->nm_device, current, applet);
}
element = g_slist_next (element);
@ -648,6 +659,8 @@ void nmwa_menu_add_networks (GtkWidget *menu, NMWirelessApplet *applet)
nmwa_menu_add_text_item (menu, _("There are no wireless networks..."));
else
{
nmwa_menu_add_text_item (menu, _("Wireless Networks"));
/* Add all networks in our network list to the menu */
while (element)
{
@ -721,6 +734,7 @@ GtkWidget * nmwa_populate_menu (NMWirelessApplet *applet)
return;
}
nmwa_menu_add_text_item (menu, _("Network Connections"));
nmwa_menu_add_devices (menu, applet);
nmwa_menu_add_separator_item (menu);
@ -877,12 +891,15 @@ static GtkWidget * nmwa_new (NMWirelessApplet *applet)
applet->ui_resources = glade_xml_new(glade_file, NULL, NULL);
if (!applet->ui_resources)
{
fprintf (stderr, "Could not get our UI resources from the glade file\n");
show_warning_dialog (TRUE, _("The NetworkManager Applet could not find some required resources (the glade file was not found)."));
g_object_unref (G_OBJECT (applet->gconf_client));
return (NULL);
}
applet->applet_state = APPLET_STATE_NO_NM;
applet->networks = NULL;
applet->devices = NULL;
applet->active_device = NULL;
/* Start our dbus thread */
if (!(applet->data_mutex = g_mutex_new ()))

View file

@ -84,6 +84,7 @@ typedef struct
GMutex *data_mutex;
GSList *devices;
GSList *networks;
char *active_device;
AppletState applet_state;
/* Direct UI elements */
@ -115,7 +116,8 @@ typedef struct
{
char *nm_device;
int type;
char *name;
char *nm_name;
char *hal_name;
char *udi;
} NetworkDevice;

View file

@ -358,7 +358,8 @@ char * nmwa_dbus_get_active_device (NMWirelessApplet *applet, AppletState failur
break;
case (RETURN_FAILURE):
applet->applet_state = failure_state;
if (failure_state != APPLET_STATE_IGNORE)
applet->applet_state = failure_state;
break;
default:
@ -607,6 +608,98 @@ char **nmwa_dbus_get_device_networks (NMWirelessApplet *applet, char *path, int
}
/*
* nmwa_dbus_get_hal_device_string_property
*
* Get a string property from a device
*
*/
char *nmwa_dbus_get_hal_device_string_property (DBusConnection *connection, const char *udi, const char *property_name)
{
DBusError error;
DBusMessage *message;
DBusMessage *reply;
char *property = NULL;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (udi != NULL, NULL);
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", "GetPropertyString");
if (!message)
return (NULL);
dbus_error_init (&error);
dbus_message_append_args (message, DBUS_TYPE_STRING, property_name, DBUS_TYPE_INVALID);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
dbus_message_unref (message);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "nmwa_dbus_get_hal_device_string_property(): %s raised:\n %s\n\n", error.name, error.message);
return (NULL);
}
if (reply == NULL)
{
fprintf( stderr, "nmwa_dbus_get_hal_device_string_property(): dbus reply message was NULL\n" );
return (NULL);
}
dbus_error_init (&error);
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &property, DBUS_TYPE_INVALID))
property = NULL;
dbus_message_unref (reply);
return (property);
}
/*
* nmwa_dbus_get_hal_device_info
*
* Grab the info.product tag from hal for a specific UDI
*
*/
char *nmwa_dbus_get_hal_device_info (DBusConnection *connection, const char *udi)
{
DBusError error;
DBusMessage *message;
DBusMessage *reply;
gboolean exists = FALSE;
char *info = NULL;
g_return_val_if_fail (connection != NULL, NULL);
g_return_val_if_fail (udi != NULL, NULL);
message = dbus_message_new_method_call ("org.freedesktop.Hal", udi, "org.freedesktop.Hal.Device", "PropertyExists");
if (!message)
return (NULL);
dbus_error_init (&error);
dbus_message_append_args (message, DBUS_TYPE_STRING, "info.product", DBUS_TYPE_INVALID);
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
dbus_message_unref (message);
if (dbus_error_is_set (&error))
{
fprintf (stderr, "nmwa_dbus_get_hal_device_info(): %s raised:\n %s\n\n", error.name, error.message);
return (NULL);
}
if (reply == NULL)
{
fprintf( stderr, "nmwa_dbus_get_hal_device_info(): dbus reply message was NULL\n" );
return (NULL);
}
dbus_error_init (&error);
if (dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN, &exists, DBUS_TYPE_INVALID))
info = nmwa_dbus_get_hal_device_string_property (connection, udi, "info.product");
dbus_message_unref (reply);
return (info);
}
/*
* nmwa_dbus_set_network
*
@ -836,13 +929,32 @@ static void network_device_free (void *element, void *user_data)
if (dev)
{
g_free (dev->nm_device);
g_free (dev->name);
g_free (dev->udi);
g_free (dev->nm_name);
dbus_free (dev->udi);
dbus_free (dev->hal_name);
}
g_free (dev);
}
/*
* nmwa_dbus_update_active_device
*
* Get the active device from NetworkManager
*
*/
void nmwa_dbus_update_active_device (NMWirelessApplet *applet)
{
g_return_if_fail (applet != NULL);
g_mutex_lock (applet->data_mutex);
if (applet->active_device)
dbus_free (applet->active_device);
applet->active_device = nmwa_dbus_get_active_device (applet, APPLET_STATE_IGNORE);
g_mutex_unlock (applet->data_mutex);
}
/*
* nmwa_dbus_update_devices
*
@ -888,16 +1000,17 @@ void nmwa_dbus_update_devices (NMWirelessApplet *applet)
{
dev->nm_device = g_strdup (devices[i]);
dev->type = nmwa_dbus_get_device_type (applet, devices[i], APPLET_STATE_NO_CONNECTION);
dev->name = g_strdup (name);
dev->nm_name = g_strdup (name);
dev->udi = nmwa_dbus_get_device_udi (applet, devices[i]);
dev->hal_name = nmwa_dbus_get_hal_device_info (applet->connection, dev->udi);
/* Ensure valid device information */
if (!dev->nm_device || !dev->name || !dev->udi || (dev->type == -1))
if (!dev->nm_device || !dev->nm_name || !dev->udi || (dev->type == -1))
network_device_free (dev, NULL);
else
{
applet->devices = g_slist_append (applet->devices, dev);
fprintf( stderr, "Got device '%s', udi '%s'\n", dev->name, dev->udi);
fprintf( stderr, "Got device '%s', udi '%s'\n", dev->nm_name, dev->udi);
}
}
}
@ -952,9 +1065,13 @@ static DBusHandlerResult nmwa_dbus_filter (DBusConnection *connection, DBusMessa
|| dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DeviceActivating"))
{
nmwa_dbus_update_network_state (applet);
nmwa_dbus_update_active_device (applet);
}
else if (dbus_message_is_signal (message, NM_DBUS_INTERFACE, "DevicesChanged"))
{
nmwa_dbus_update_devices (applet);
nmwa_dbus_update_active_device (applet);
}
else
handled = FALSE;
@ -1085,6 +1202,7 @@ gpointer nmwa_dbus_worker (gpointer user_data)
if ((applet->applet_state == APPLET_STATE_WIRELESS) || (applet->applet_state == APPLET_STATE_WIRELESS_CONNECTING))
nmwa_dbus_update_wireless_network_list (applet);
nmwa_dbus_update_devices (applet);
nmwa_dbus_update_active_device (applet);
}
else
applet->applet_state = APPLET_STATE_NO_NM;

View file

@ -42,10 +42,12 @@ enum
DEVICE_TYPE_WIRELESS_ETHERNET
};
gpointer nmwa_dbus_worker (gpointer user_data);
gpointer nmwa_dbus_worker (gpointer user_data);
void nmwa_dbus_set_network (DBusConnection *connection, char *network);
void nmwa_dbus_set_network (DBusConnection *connection, char *network);
void nmwa_dbus_set_device (DBusConnection *connection, char *device);
void nmwa_dbus_set_device (DBusConnection *connection, char *device);
char * nmwa_dbus_get_active_device (NMWirelessApplet *applet, AppletState failure_state);
#endif