After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 693329 - Add items when files added to Pictures/cache directory
Add items when files added to Pictures/cache directory
Status: RESOLVED FIXED
Product: gnome-control-center
Classification: Core
Component: Background
3.7.x
Other Linux
: Normal normal
: ---
Assigned To: Control-Center Maintainers
Control-Center Maintainers
Depends on:
Blocks:
 
 
Reported: 2013-02-07 14:24 UTC by Michael Wood
Modified: 2013-03-01 11:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add items when added to pictures/cache (6.80 KB, patch)
2013-02-07 14:24 UTC, Michael Wood
needs-work Details | Review
background: Monitor the Pictures and cache directory for new files (6.88 KB, patch)
2013-02-11 12:04 UTC, Michael Wood
needs-work Details | Review
background: Monitor the Pictures and cache directory for new files (8.74 KB, patch)
2013-02-12 18:46 UTC, Michael Wood
reviewed Details | Review
background: Monitor the Pictures and cache directory for new files (8.73 KB, patch)
2013-02-19 15:03 UTC, Michael Wood
reviewed Details | Review
background: Monitor the Pictures and cache directory for new files (8.64 KB, patch)
2013-02-26 14:50 UTC, Michael Wood
committed Details | Review

Description Michael Wood 2013-02-07 14:24:55 UTC
Created attachment 235403 [details] [review]
Add items when added to pictures/cache

Monitor the pictures directory and cache directory for any new files added or removed. Re-purposes the add/remove api that was no longer used.
Comment 1 Thomas Wood 2013-02-08 16:24:56 UTC
Review of attachment 235403 [details] [review]:

::: panels/background/bg-pictures-source.c
@@ +127,3 @@
+    {
+      g_object_unref (bg_source->priv->picture_dir_monitor);
+      bg_source->priv->picture_dir_monitor = NULL;

Use g_clear_object to clear the reference.

@@ +133,3 @@
+    {
+      g_object_unref (bg_source->priv->cache_dir_monitor);
+      bg_source->priv->cache_dir_monitor = NULL;

Same as above.

@@ +382,3 @@
 gboolean
 bg_pictures_source_remove (BgPicturesSource *bg_source,
+                          const char       *uri)

Alignment is slightly wrong here.

@@ +568,3 @@
+            BgPicturesSource *self)
+{
+  if (!bg_pictures_source_is_known (self, g_file_get_uri (file)))

The return value of g_file_get_uri needs to be freed.

@@ +571,3 @@
+    {
+      /* sync up the ref count so we can re-use the add_single_item code path */
+      g_object_ref (file);

Probably best to move this and the explanation up to to where add_single_item is called.

@@ +636,3 @@
+                                                        G_FILE_MONITOR_NONE,
+                                                        NULL,
+                                                        NULL);

g_file_monitor_directory can return NULL on error, so this should be checked before attempting to connect the signal.

@@ +656,3 @@
+                                                      G_FILE_MONITOR_NONE,
+                                                      NULL,
+                                                      NULL);

Same as above.
Comment 2 Michael Wood 2013-02-11 12:04:13 UTC
Created attachment 235695 [details] [review]
background: Monitor the Pictures and cache directory for new files

Updated patch
Comment 3 Bastien Nocera 2013-02-11 13:01:55 UTC
Review of attachment 235695 [details] [review]:

::: panels/background/bg-pictures-source.c
@@ +595,3 @@
+  switch (event_type)
+    {
+      case G_FILE_MONITOR_EVENT_CREATED:

You don't want to use created here. New files might get opened before they're done writing, and you don't check for changed.
You likely want G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT
Comment 4 Michael Wood 2013-02-11 16:33:59 UTC
G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT fires three times if a file is overwritten.

I am checking before add_single_file to see if the file exists in the "known_items" hash table, but it seems there isn't anything ever being added to that in the first place.. I could fix the inserting as well but not sure what the side effects are.
Comment 5 Michael Wood 2013-02-12 18:46:10 UTC
Created attachment 235810 [details] [review]
background: Monitor the Pictures and cache directory for new files

Change to using G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT. This required the known_items table to be re-instated. 

There is a bit of clean up to do in bg-pictures-source which I'll open a separate bug/patch about, would be good to do this on top of this patch and #691800
Comment 6 Bastien Nocera 2013-02-18 15:50:26 UTC
Review of attachment 235810 [details] [review]:

Looks good other than that.

::: panels/background/bg-pictures-source.c
@@ +553,3 @@
+                               G_FILE_QUERY_INFO_NONE,
+                               G_PRIORITY_LOW,
+                               NULL,

Needs to use a GCancellable here, so we can cancel any queries when exiting the panel.
Comment 7 Michael Wood 2013-02-19 15:03:04 UTC
Created attachment 236771 [details] [review]
background: Monitor the Pictures and cache directory for new files

Added cancellable to file monitors
Comment 8 Bastien Nocera 2013-02-26 13:54:26 UTC
Review of attachment 236771 [details] [review]:

Feel free to commit after making those changes.

::: panels/background/bg-pictures-source.c
@@ +125,3 @@
     }
 
+  if (bg_source->priv->picture_dir_monitor)

You don't need to do "if..." with g_clear_object.

@@ +128,3 @@
+      g_clear_object (&bg_source->priv->picture_dir_monitor);
+
+  if (bg_source->priv->cache_dir_monitor)

Ditto.
Comment 9 Michael Wood 2013-02-26 14:50:22 UTC
Created attachment 237445 [details] [review]
background: Monitor the Pictures and cache directory for new files

fix up patch
Comment 10 Thomas Wood 2013-03-01 11:32:18 UTC
Attachment 237445 [details] pushed as ce409d4 - background: Monitor the Pictures and cache directory for new files