[cheese/camerabin2-format: 10/27] thumb-view: handle photo/video moved to monitored directories



commit 8d25c1278f60b10aa6989202350af5a9d96c4aec
Author: Raluca Elena Podiuc <ralucaelena1985 gmail com>
Date:   Wed Jul 13 14:21:27 2011 +0300

    thumb-view: handle photo/video moved to monitored directories
    
    Camerabin2 creates a temporary file, writes data to it and in the end
    it moves it to the destination path.
    
    Without G_FILE_MONITOR_SEND_MOVED to g_file_monitor_directory, moves
    would be sent as DELETE + CREATE.
    
    Unfortunately, we would also get CREATE events when the temporary file
    was created. We cannot listen for CREATE events as temporary files
    would be CREATEd and then CHANGEd and the thumb-view creation code
    would work with bad data.
    
    By using G_FILE_MONITOR_SEND_MOVED we get a single event when the file
    is moved. As the file monitor ignores files with unknown extensions
    (as is the case for the temporary files created by camerabin2) we
    could only just append the new file. But because the user might also
    move a picture/video manually from the Pictures/Webcam or
    Videos/Webcam directories, removing the old file from the thumb-view
    keeps it up-to-date with the state of the file system.
    
    If camerabin2 switches away from the create-temp+move approach, to the
    camerabin one (create the destination file directly), we're prepared
    to handle that code with G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT.

 src/thumbview/cheese-thumb-view.c |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
---
diff --git a/src/thumbview/cheese-thumb-view.c b/src/thumbview/cheese-thumb-view.c
index 5c06ff3..97dadcf 100644
--- a/src/thumbview/cheese-thumb-view.c
+++ b/src/thumbview/cheese-thumb-view.c
@@ -356,9 +356,16 @@ cheese_thumb_view_monitor_cb (GFileMonitor     *file_monitor,
     case G_FILE_MONITOR_EVENT_DELETED:
       cheese_thumb_view_remove_item (thumb_view, file);
       break;
+
+    case G_FILE_MONITOR_EVENT_MOVED:
+      cheese_thumb_view_remove_item (thumb_view, file);
+      cheese_thumb_view_append_item (thumb_view, other_file);
+      break;
+
     case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
       cheese_thumb_view_append_item (thumb_view, file);
       break;
+
     default:
       break;
   }
@@ -697,7 +704,7 @@ cheese_thumb_view_start_monitoring_photo_path (CheeseThumbView *thumb_view, cons
 
   /* connect signal to photo path */
   file                     = g_file_new_for_path (path_photos);
-  priv->photo_file_monitor = g_file_monitor_directory (file, 0, NULL, NULL);
+  priv->photo_file_monitor = g_file_monitor_directory (file, G_FILE_MONITOR_SEND_MOVED, NULL, NULL);
   g_signal_connect (priv->photo_file_monitor, "changed", G_CALLBACK (cheese_thumb_view_monitor_cb), thumb_view);
 
   g_object_unref (file);
@@ -716,7 +723,7 @@ cheese_thumb_view_start_monitoring_video_path (CheeseThumbView *thumb_view, cons
 
   /* connect signal to video path */
   file                     = g_file_new_for_path (path_videos);
-  priv->video_file_monitor = g_file_monitor_directory (file, 0, NULL, NULL);
+  priv->video_file_monitor = g_file_monitor_directory (file, G_FILE_MONITOR_SEND_MOVED, NULL, NULL);
   g_signal_connect (priv->video_file_monitor, "changed", G_CALLBACK (cheese_thumb_view_monitor_cb), thumb_view);
 
   g_object_unref (file);



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