[gnome-control-center] background: refactor code into separate function



commit a630474cc1183beec8efdfe4c67daf234f686737
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Apr 2 10:10:46 2016 -0700

    background: refactor code into separate function
    
    Split out the creation of a file monitor in a separate function.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764504

 panels/background/bg-pictures-source.c |   76 ++++++++++++++-----------------
 1 files changed, 34 insertions(+), 42 deletions(-)
---
diff --git a/panels/background/bg-pictures-source.c b/panels/background/bg-pictures-source.c
index de5f189..a33cee7 100644
--- a/panels/background/bg-pictures-source.c
+++ b/panels/background/bg-pictures-source.c
@@ -891,6 +891,38 @@ files_changed_cb (GFileMonitor      *monitor,
     }
 }
 
+static GFileMonitor *
+monitor_path (BgPicturesSource *self,
+              const char       *path)
+{
+  GFileMonitor *monitor;
+  GFile *dir;
+
+  g_mkdir_with_parents (path, USER_DIR_MODE);
+
+  dir = g_file_new_for_path (path);
+  g_file_enumerate_children_async (dir,
+                                   ATTRIBUTES,
+                                   G_FILE_QUERY_INFO_NONE,
+                                   G_PRIORITY_LOW, self->priv->cancellable,
+                                   dir_enum_async_ready, self);
+
+  monitor = g_file_monitor_directory (dir,
+                                      G_FILE_MONITOR_NONE,
+                                      self->priv->cancellable,
+                                      NULL);
+
+  if (monitor)
+    g_signal_connect (monitor,
+                      "changed",
+                      G_CALLBACK (files_changed_cb),
+                      self);
+
+  g_object_unref (dir);
+
+  return monitor;
+}
+
 static void
 media_found_cb (BgPicturesSource *self, GrlMedia *media)
 {
@@ -908,7 +940,6 @@ bg_pictures_source_init (BgPicturesSource *self)
 {
   const gchar *pictures_path;
   BgPicturesSourcePrivate *priv;
-  GFile *dir;
   char *cache_path;
   GtkListStore *store;
 
@@ -924,51 +955,12 @@ bg_pictures_source_init (BgPicturesSource *self)
   if (pictures_path == NULL)
     pictures_path = g_get_home_dir ();
 
-  g_mkdir_with_parents (pictures_path, USER_DIR_MODE);
-
-  dir = g_file_new_for_path (pictures_path);
-  g_file_enumerate_children_async (dir,
-                                  ATTRIBUTES,
-                                   G_FILE_QUERY_INFO_NONE,
-                                   G_PRIORITY_LOW, priv->cancellable,
-                                   dir_enum_async_ready, self);
-
-  priv->picture_dir_monitor = g_file_monitor_directory (dir,
-                                                        G_FILE_MONITOR_NONE,
-                                                        priv->cancellable,
-                                                        NULL);
-
-  if (priv->picture_dir_monitor)
-    g_signal_connect (priv->picture_dir_monitor,
-                      "changed",
-                      G_CALLBACK (files_changed_cb),
-                      self);
-
-  g_object_unref (dir);
+  priv->picture_dir_monitor = monitor_path (self, pictures_path);
 
   cache_path = bg_pictures_source_get_cache_path ();
-  g_mkdir_with_parents (cache_path, USER_DIR_MODE);
-
-  dir = g_file_new_for_path (cache_path);
-  g_file_enumerate_children_async (dir,
-                                  ATTRIBUTES,
-                                   G_FILE_QUERY_INFO_NONE,
-                                   G_PRIORITY_LOW, priv->cancellable,
-                                   dir_enum_async_ready, self);
+  priv->cache_dir_monitor = monitor_path (self, cache_path);
   g_free (cache_path);
 
-  priv->cache_dir_monitor = g_file_monitor_directory (dir,
-                                                      G_FILE_MONITOR_NONE,
-                                                      priv->cancellable,
-                                                      NULL);
-  if (priv->cache_dir_monitor)
-    g_signal_connect (priv->cache_dir_monitor,
-                      "changed",
-                      G_CALLBACK (files_changed_cb),
-                      self);
-
-  g_object_unref (dir);
-
   priv->grl_miner = cc_background_grilo_miner_new ();
   g_signal_connect_swapped (priv->grl_miner, "media-found", G_CALLBACK (media_found_cb), self);
   cc_background_grilo_miner_start (priv->grl_miner);


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