gnome-mount r199 - in trunk: . src



Author: matthiasc
Date: Tue Nov 11 03:43:40 2008
New Revision: 199
URL: http://svn.gnome.org/viewvc/gnome-mount?rev=199&view=rev

Log:
2008-11-10  Matthias Clasen  <mclasen redhat com>

        Bug 549974 â fix icon in notification

        * src/gnome-mount.c: Use proper icon names. Patch by Pierre Ossman



Modified:
   trunk/ChangeLog
   trunk/src/gnome-mount.c

Modified: trunk/src/gnome-mount.c
==============================================================================
--- trunk/src/gnome-mount.c	(original)
+++ trunk/src/gnome-mount.c	Tue Nov 11 03:43:40 2008
@@ -3,6 +3,7 @@
  * gnome-mount.c : GNOME mount, unmount and eject wrappers using HAL
  *
  * Copyright (C) 2006 David Zeuthen, <david fubar dk>
+ * Copyright 2008 Pierre Ossman
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1557,6 +1558,7 @@
 
 static gboolean unmount_note_is_eject = FALSE;
 static char *unmount_note_drive_name = NULL;
+static char *unmount_note_icon_name = NULL;
 
 #ifdef ENABLE_NOTIFY
 static void
@@ -1570,8 +1572,6 @@
 static gboolean
 unmount_cache_timeout_func (gpointer data)
 {
-	char *drive_name = data;
-
 #ifdef ENABLE_NOTIFY
 	if (!opt_noui) {
 		char *summary;
@@ -1583,7 +1583,7 @@
 		message = g_strdup_printf (_("There is data that needs to be written to the device %s before it can be removed. Please do not remove the media or disconnect the drive."), unmount_note_drive_name);
 		unmount_note = notify_notification_new (summary,
 							message,
-							"gnome-dev-harddisk", /* TODO: use appropriate icon */
+							unmount_note_icon_name,
 							NULL);
 		if (unmount_note == NULL) {
 			g_warning ("Cannot create note for unmount cache sync");
@@ -1601,11 +1601,16 @@
 }
 
 static void
-unmount_cache_timeout_start (char *drive_name, gboolean is_eject)
+unmount_cache_timeout_start (char *drive_name, char *icon_name, gboolean is_eject)
 {
 	unmount_note_is_eject = is_eject;
 	unmount_note_drive_name = g_strdup (drive_name);
+	if (icon_name)
+		unmount_note_icon_name = g_strdup (icon_name);
+	else
+		unmount_note_icon_name = g_strdup ("drive-harddisk");
 	g_strchug (unmount_note_drive_name);
+	g_debug("Icon %s\n", unmount_note_icon_name);
 	g_debug ("Setting up 750ms timer for Flushing Cache dialog");
 	unmount_cache_timeout_id = g_timeout_add (750, unmount_cache_timeout_func, NULL);
 #ifdef ENABLE_NOTIFY
@@ -1628,10 +1633,11 @@
 			summary = _("Device is now safe to remove");
 			message = g_strdup_printf (_("The device %s is now safe to remove."), 
 						   unmount_note_drive_name);
+			notify_notification_close (unmount_note, NULL);
 			notify_notification_update (unmount_note, 
 						    summary, 
 						    message, 
-						    "gnome-dev-harddisk"); /* TODO: use appropriate icon */
+						    unmount_note_icon_name);
 			g_free (message);
 			notify_notification_set_timeout (unmount_note, NOTIFY_EXPIRES_DEFAULT);
 			notify_notification_show (unmount_note, NULL);
@@ -1655,7 +1661,81 @@
 	dbus_pending_call_unref (pending_call);
 }
 
+static char *
+volume_icon(const char *udi)
+{
+	GVolumeMonitor *monitor;
+	GList *volumes, *tmp;
+
+	char *vol_udi;
+	GVolume *volume;
+	GMount *mount;
+	GIcon *icon;
+	const char * const * names;
+
+	char *icon_name;
+
+	g_assert (udi);
+
+	monitor = g_volume_monitor_get ();
+	if (!monitor)
+		return NULL;
+
+	icon_name = NULL;
+
+	volumes = g_volume_monitor_get_volumes (monitor);
+
+	/* Find it... */
+	for (tmp = volumes; tmp != NULL; tmp = tmp->next) {
+		volume = tmp->data;
+
+		vol_udi = g_volume_get_identifier (volume,
+						   G_VOLUME_IDENTIFIER_KIND_HAL_UDI);
+		if (vol_udi) {
+			if (strcmp (udi, vol_udi) == 0) {
+				g_free (vol_udi);
+				break;
+			}
+			g_free (vol_udi);
+		}
+
+		g_object_unref (volume);
+	}
+
+	/* Figure out its icon... */
+	if (tmp) {
+		mount = g_volume_get_mount (volume);
+		if (mount) {
+			icon = g_mount_get_icon (mount);
+			g_object_unref (mount);
+		} else {
+			icon = g_volume_get_icon (volume);
+		}
+
+		g_object_unref (volume);
+
+		if (icon) {
+			if (G_IS_THEMED_ICON (icon)) {
+				names = g_themed_icon_get_names (G_THEMED_ICON(icon));
+				if (names[0])
+					icon_name = g_strdup (names[0]);
+			}
+			g_object_unref (icon);
+		}
+	}
+
+	/* Cleanup... */
+	for (; tmp != NULL; tmp = tmp->next) {
+		volume = tmp->data;
+		g_object_unref (volume);
+	}
+
+	g_list_free (volumes);
 
+	g_object_unref (monitor);
+
+	return icon_name;
+}
 
 static gboolean
 volume_unmount (const char *udi, LibHalVolume *volume, LibHalDrive *drive)
@@ -1670,6 +1750,7 @@
 	const char *device_file;
 	const char *label;
 	const char *uuid;
+	char *icon_name;
 	char *model;
 	char *vendor;
 	char *drive_name;
@@ -1708,6 +1789,8 @@
 		}
 	}
 
+	icon_name = volume_icon (udi);
+
 	if (vendor != NULL && model != NULL)
 		drive_name = g_strdup_printf (" %s %s", vendor, model);
 	else if (vendor != NULL)
@@ -1813,7 +1896,7 @@
 	 * the cache.
 	 */
 	if (!is_ro) {
-		unmount_cache_timeout_start (drive_name, FALSE);
+		unmount_cache_timeout_start (drive_name, icon_name, FALSE);
 	}
 
 	/* it also means we can't use dbus_connection_send_with_reply_and_block() as
@@ -1871,6 +1954,8 @@
 		dbus_message_unref (msg);
 	if (reply != NULL)
 		dbus_message_unref (reply);
+	if (icon_name != NULL)
+		g_free (icon_name);
 
 	g_free (drive_name);
 
@@ -1890,6 +1975,7 @@
 	const char *device_file;
 	const char *label;
 	const char *uuid;
+	char *icon_name;
 	char *model;
 	char *vendor;
 	char *drive_name;
@@ -1928,6 +2014,8 @@
 		}
 	}
 
+	icon_name = volume_icon (udi);
+
 	if (vendor != NULL && model != NULL)
 		drive_name = g_strdup_printf (" %s %s", vendor, model);
 	else if (vendor != NULL)
@@ -2032,7 +2120,7 @@
 	 * the cache.
 	 */
 	if (!is_ro) {
-		unmount_cache_timeout_start (drive_name, TRUE);
+		unmount_cache_timeout_start (drive_name, icon_name, TRUE);
 	}
 
 	/* it also means we can't use dbus_connection_send_with_reply_and_block() as
@@ -2091,6 +2179,8 @@
 		dbus_message_unref (msg);
 	if (reply != NULL)
 		dbus_message_unref (reply);
+	if (icon_name != NULL)
+		g_free (icon_name);
 
 	g_free (drive_name);
 



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