summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2012-07-13 12:56:18 -0400
committerCosimo Cecchi <cosimoc@gnome.org>2012-07-13 12:56:18 -0400
commit7c72858b6505f59538b5d196ae318d2f826e2f94 (patch)
treeecbd239fc4517efc3ec9e615113ddf538399ca2c
parentbd3a0214c0f2638e38055350e6cd07c7474beb0e (diff)
downloadnautilus-7c72858b6505f59538b5d196ae318d2f826e2f94.tar.gz
trash-monitor: make sure to use our icon names for trash
-rw-r--r--libnautilus-private/nautilus-trash-monitor.c111
1 files changed, 66 insertions, 45 deletions
diff --git a/libnautilus-private/nautilus-trash-monitor.c b/libnautilus-private/nautilus-trash-monitor.c
index 98aacdf27..433d6a54c 100644
--- a/libnautilus-private/nautilus-trash-monitor.c
+++ b/libnautilus-private/nautilus-trash-monitor.c
@@ -90,64 +90,85 @@ nautilus_trash_monitor_class_init (NautilusTrashMonitorClass *klass)
}
static void
-update_info_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+update_icon (NautilusTrashMonitor *trash_monitor)
{
- NautilusTrashMonitor *trash_monitor;
- GFileInfo *info;
- GIcon *icon;
- const char * const *names;
- gboolean empty;
- int i;
+ g_clear_object (&trash_monitor->details->icon);
- trash_monitor = NAUTILUS_TRASH_MONITOR (user_data);
+ if (trash_monitor->details->empty) {
+ trash_monitor->details->icon = g_themed_icon_new (NAUTILUS_ICON_TRASH);
+ } else {
+ trash_monitor->details->icon = g_themed_icon_new (NAUTILUS_ICON_TRASH_FULL);
+ }
+}
+
+static void
+update_empty_info (NautilusTrashMonitor *trash_monitor,
+ gboolean is_empty)
+{
+ if (trash_monitor->details->empty == is_empty) {
+ return;
+ }
- info = g_file_query_info_finish (G_FILE (source_object),
- res, NULL);
-
- if (info != NULL) {
- icon = g_file_info_get_icon (info);
-
- if (icon) {
- g_object_unref (trash_monitor->details->icon);
- trash_monitor->details->icon = g_object_ref (icon);
- empty = TRUE;
- if (G_IS_THEMED_ICON (icon)) {
- names = g_themed_icon_get_names (G_THEMED_ICON (icon));
- for (i = 0; names[i] != NULL; i++) {
- if (strcmp (names[i], NAUTILUS_ICON_TRASH_FULL) == 0) {
- empty = FALSE;
- break;
- }
- }
- }
- if (trash_monitor->details->empty != empty) {
- trash_monitor->details->empty = empty;
-
- /* trash got empty or full, notify everyone who cares */
- g_signal_emit (trash_monitor,
- signals[TRASH_STATE_CHANGED], 0,
- trash_monitor->details->empty);
- }
- }
- g_object_unref (info);
+ trash_monitor->details->empty = is_empty;
+ update_icon (trash_monitor);
+
+ /* trash got empty or full, notify everyone who cares */
+ g_signal_emit (trash_monitor,
+ signals[TRASH_STATE_CHANGED], 0,
+ trash_monitor->details->empty);
+}
+
+static void
+enumerate_next_files_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ NautilusTrashMonitor *trash_monitor = user_data;
+ GList *infos;
+
+ infos = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source), res, NULL);
+ if (!infos) {
+ update_empty_info (trash_monitor, TRUE);
+ } else {
+ update_empty_info (trash_monitor, FALSE);
+ g_list_free_full (infos, g_object_unref);
}
g_object_unref (trash_monitor);
}
static void
+enumerate_children_cb (GObject *source,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ GFileEnumerator *enumerator;
+ NautilusTrashMonitor *trash_monitor = user_data;
+
+ enumerator = g_file_enumerate_children_finish (G_FILE (source), res, NULL);
+ if (!enumerator) {
+ update_empty_info (trash_monitor, TRUE);
+ g_object_unref (trash_monitor);
+ return;
+ }
+
+ g_file_enumerator_next_files_async (enumerator, 1,
+ G_PRIORITY_DEFAULT, NULL,
+ enumerate_next_files_cb, trash_monitor);
+ g_object_unref (enumerator);
+}
+
+static void
schedule_update_info (NautilusTrashMonitor *trash_monitor)
{
GFile *location;
location = g_file_new_for_uri ("trash:///");
-
- g_file_query_info_async (location,
- G_FILE_ATTRIBUTE_STANDARD_ICON,
- 0, 0, NULL,
- update_info_cb, g_object_ref (trash_monitor));
+ g_file_enumerate_children_async (location,
+ G_FILE_ATTRIBUTE_STANDARD_TYPE,
+ G_FILE_QUERY_INFO_NONE,
+ G_PRIORITY_DEFAULT, NULL,
+ enumerate_children_cb, g_object_ref (trash_monitor));
g_object_unref (location);
}
@@ -176,7 +197,7 @@ nautilus_trash_monitor_init (NautilusTrashMonitor *trash_monitor)
NautilusTrashMonitorDetails);
trash_monitor->details->empty = TRUE;
- trash_monitor->details->icon = g_themed_icon_new (NAUTILUS_ICON_TRASH);
+ update_icon (trash_monitor);
location = g_file_new_for_uri ("trash:///");