Commit c064fab6 authored by Philip Withnall's avatar Philip Withnall Committed by Philip Withnall

thumbnailer: Add missing cases to switch statement

This shuts up a gcc warning by adding support for thumbnail directories being
unmounted or moved.

https://bugzilla.gnome.org/show_bug.cgi?id=709819
parent b778fb5e
......@@ -47,6 +47,13 @@
#define SECONDS_BETWEEN_STATS 10
static void
thumbnailers_directory_changed (GFileMonitor *monitor,
GFile *file,
GFile *other_file,
GFileMonitorEvent event_type,
GnomeDesktopThumbnailFactory *factory);
struct _GnomeDesktopThumbnailFactoryPrivate {
GnomeDesktopThumbnailSize size;
......@@ -648,6 +655,88 @@ remove_thumbnailer (GnomeDesktopThumbnailFactory *factory,
g_mutex_unlock (&priv->lock);
}
static void
remove_thumbnailers_for_dir (GnomeDesktopThumbnailFactory *factory,
const gchar *thumbnailer_dir,
GFileMonitor *monitor)
{
GnomeDesktopThumbnailFactoryPrivate *priv = factory->priv;
GList *l;
Thumbnailer *thumb;
g_mutex_lock (&priv->lock);
/* Remove all the thumbnailers inside this @thumbnailer_dir. */
for (l = priv->thumbnailers; l; l = g_list_next (l))
{
thumb = (Thumbnailer *)l->data;
if (g_str_has_prefix (thumb->path, thumbnailer_dir) == TRUE)
{
priv->thumbnailers = g_list_delete_link (priv->thumbnailers, l);
g_hash_table_foreach_remove (priv->mime_types_map,
(GHRFunc)remove_thumbnailer_from_mime_type_map,
(gpointer)thumb->path);
thumbnailer_unref (thumb);
break;
}
}
/* Remove the monitor for @thumbnailer_dir. */
priv->monitors = g_list_remove (priv->monitors, monitor);
g_signal_handlers_disconnect_by_func (monitor, thumbnailers_directory_changed, factory);
g_mutex_unlock (&priv->lock);
}
static void
gnome_desktop_thumbnail_factory_load_thumbnailers_for_dir (GnomeDesktopThumbnailFactory *factory,
const gchar *path)
{
GnomeDesktopThumbnailFactoryPrivate *priv = factory->priv;
GDir *dir;
GFile *dir_file;
GFileMonitor *monitor;
const gchar *dirent;
dir = g_dir_open (path, 0, NULL);
if (!dir)
return;
/* Monitor dir */
dir_file = g_file_new_for_path (path);
monitor = g_file_monitor_directory (dir_file,
G_FILE_MONITOR_NONE,
NULL, NULL);
if (monitor)
{
g_signal_connect (monitor, "changed",
G_CALLBACK (thumbnailers_directory_changed),
factory);
priv->monitors = g_list_prepend (priv->monitors, monitor);
}
g_object_unref (dir_file);
while ((dirent = g_dir_read_name (dir)))
{
Thumbnailer *thumb;
gchar *filename;
if (!g_str_has_suffix (dirent, THUMBNAILER_EXTENSION))
continue;
filename = g_build_filename (path, dirent, NULL);
thumb = thumbnailer_new (filename);
g_free (filename);
if (thumb)
gnome_desktop_thumbnail_factory_add_thumbnailer (factory, thumb);
}
g_dir_close (dir);
}
static void
thumbnailers_directory_changed (GFileMonitor *monitor,
GFile *file,
......@@ -676,6 +765,19 @@ thumbnailers_directory_changed (GFileMonitor *monitor,
g_free (path);
break;
case G_FILE_MONITOR_EVENT_UNMOUNTED:
case G_FILE_MONITOR_EVENT_MOVED:
path = g_file_get_path (file);
remove_thumbnailers_for_dir (factory, path, monitor);
if (event_type == G_FILE_MONITOR_EVENT_MOVED)
gnome_desktop_thumbnail_factory_load_thumbnailers_for_dir (factory, path);
g_free (path);
break;
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
default:
break;
}
......@@ -694,47 +796,7 @@ gnome_desktop_thumbnail_factory_load_thumbnailers (GnomeDesktopThumbnailFactory
dirs = get_thumbnailers_dirs ();
for (i = 0; dirs[i]; i++)
{
const gchar *path = dirs[i];
GDir *dir;
GFile *dir_file;
GFileMonitor *monitor;
const gchar *dirent;
dir = g_dir_open (path, 0, NULL);
if (!dir)
continue;
/* Monitor dir */
dir_file = g_file_new_for_path (path);
monitor = g_file_monitor_directory (dir_file,
G_FILE_MONITOR_NONE,
NULL, NULL);
if (monitor)
{
g_signal_connect (monitor, "changed",
G_CALLBACK (thumbnailers_directory_changed),
factory);
priv->monitors = g_list_prepend (priv->monitors, monitor);
}
g_object_unref (dir_file);
while ((dirent = g_dir_read_name (dir)))
{
Thumbnailer *thumb;
gchar *filename;
if (!g_str_has_suffix (dirent, THUMBNAILER_EXTENSION))
continue;
filename = g_build_filename (path, dirent, NULL);
thumb = thumbnailer_new (filename);
g_free (filename);
if (thumb)
gnome_desktop_thumbnail_factory_add_thumbnailer (factory, thumb);
}
g_dir_close (dir);
gnome_desktop_thumbnail_factory_load_thumbnailers_for_dir (factory, dirs[i]);
}
priv->loaded = TRUE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment