cheese r708 - in trunk: . src



Author: dgsiegel
Date: Fri May  2 16:48:30 2008
New Revision: 708
URL: http://svn.gnome.org/viewvc/cheese?rev=708&view=rev

Log:
store photos and videos in xdg directories, fixes bug #509475, courtesy of Felix Kaser


Modified:
   trunk/AUTHORS
   trunk/ChangeLog
   trunk/src/cheese-fileutil.c
   trunk/src/cheese-fileutil.h
   trunk/src/cheese-thumb-view.c
   trunk/src/cheese-window.c
   trunk/src/cheese.c

Modified: trunk/AUTHORS
==============================================================================
--- trunk/AUTHORS	(original)
+++ trunk/AUTHORS	Fri May  2 16:48:30 2008
@@ -5,6 +5,7 @@
   - Baptiste Mille-Mathias <bmm80 free fr>
   - Cosimo Cecchi <anarki lilik it>
   - Diego Escalante Urrelo <dieguito gmail com>
+  - Felix Kaser <f kaser gmx net>
   - Gintautas Miliauskas <gintas akl lt>
   - James Liggett <jrliggett cox net>
   - Luca Ferretti <elle uca libero it>

Modified: trunk/src/cheese-fileutil.c
==============================================================================
--- trunk/src/cheese-fileutil.c	(original)
+++ trunk/src/cheese-fileutil.c	Fri May  2 16:48:30 2008
@@ -29,30 +29,54 @@
 #include "cheese-fileutil.h"
 
 char *
-cheese_fileutil_get_path ()
+cheese_fileutil_get_photo_path ()
 {
   char *path;
+  
 #ifdef HILDON
+  // TODO change HILDON to xdg as well?
   path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir(), "Mydocs", ".images", NULL);
 #else
-  path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir(), ".gnome2", "cheese", NULL);
+  path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES), "Webcam", NULL);
 #endif
+
   return path;
 }
 
 char *
-cheese_fileutil_get_media_path ()
+cheese_fileutil_get_video_path ()
 {
   char *path;
-  char *cheese_path;
+  
+#ifdef HILDON
+  // TODO change HILDON to xdg as well?
+  path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), "Mydocs", "videos", NULL);
+#else
+  path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS), "Webcam", NULL);
+#endif
+
+  return path;
 
-  cheese_path = cheese_fileutil_get_path ();
-  path = g_strjoin (G_DIR_SEPARATOR_S, cheese_path, "media", NULL);
-  g_free (cheese_path);
+}
+
+char *
+cheese_fileutil_get_log_path ()
+{
+  char *path;
+  
+#ifdef HILDON
+  // TODO change HILDON to xdg as well?
+  path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), "Mydocs", "cheese-log", NULL);
+#else
+  //path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_cache_dir(), NULL);
+  path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", NULL);
+#endif
 
   return path;
+
 }
 
+
 char *
 cheese_fileutil_get_new_media_filename (CheeseMediaMode mode)
 {
@@ -68,8 +92,11 @@
   ptr = localtime (&tm);
   strftime (date, 20, "%F-%H%M%S", ptr);
 
-  path = cheese_fileutil_get_media_path ();
-
+  if (mode == CHEESE_MEDIA_MODE_PHOTO)
+    path = cheese_fileutil_get_photo_path ();
+  else
+    path = cheese_fileutil_get_video_path ();
+    
   if (mode == CHEESE_MEDIA_MODE_PHOTO)
     filename = g_strdup_printf ("%s%s%s%s", path, G_DIR_SEPARATOR_S, date, PHOTO_NAME_SUFFIX);
   else

Modified: trunk/src/cheese-fileutil.h
==============================================================================
--- trunk/src/cheese-fileutil.h	(original)
+++ trunk/src/cheese-fileutil.h	Fri May  2 16:48:30 2008
@@ -30,8 +30,9 @@
   CHEESE_MEDIA_MODE_VIDEO
 } CheeseMediaMode;
 
-char *cheese_fileutil_get_path(void);
-char *cheese_fileutil_get_media_path (void);
+char *cheese_fileutil_get_photo_path (void);
+char *cheese_fileutil_get_video_path (void);
+char *cheese_fileutil_get_log_path (void);
 char *cheese_fileutil_get_new_media_filename (CheeseMediaMode mode);
 
 #endif /* __CHEESE_FILE_UTIL_H__ */

Modified: trunk/src/cheese-thumb-view.c
==============================================================================
--- trunk/src/cheese-thumb-view.c	(original)
+++ trunk/src/cheese-thumb-view.c	Fri May  2 16:48:30 2008
@@ -42,7 +42,8 @@
 typedef struct
 {
   GtkListStore *store;
-  GFileMonitor *file_monitor;
+  GFileMonitor *photo_file_monitor;
+  GFileMonitor *video_file_monitor;
 } CheeseThumbViewPrivate;
 
 enum
@@ -296,33 +297,52 @@
 cheese_thumb_view_fill (CheeseThumbView *thumb_view)
 {
   CheeseThumbViewPrivate* priv = CHEESE_THUMB_VIEW_GET_PRIVATE (thumb_view);
-  GDir *dir;
-  char *path;
+  GDir *dir_videos, *dir_photos;
+  char *path_videos, *path_photos;
   const char *name;
   char *filename;
   GFile *file;
 
   gtk_list_store_clear (priv->store);
 
-  path = cheese_fileutil_get_media_path ();
-  dir = g_dir_open (path, 0, NULL);
-  if (!dir)
+  path_videos = cheese_fileutil_get_video_path ();
+  path_photos = cheese_fileutil_get_photo_path ();
+  
+  dir_videos = g_dir_open (path_videos, 0, NULL);
+  dir_photos = g_dir_open (path_photos, 0, NULL);
+  
+  if (!dir_videos && !dir_photos)
     return;
 
-  while ((name = g_dir_read_name (dir)))
+  //read videos from the vid directory
+  while (name = g_dir_read_name (dir_videos))
   {
-    if (!(g_str_has_suffix (name, PHOTO_NAME_SUFFIX) || g_str_has_suffix (name, VIDEO_NAME_SUFFIX)))
+    if (!(g_str_has_suffix (name, VIDEO_NAME_SUFFIX)))
       continue;
-
-    filename = g_build_filename (path, name, NULL);
+    
+    filename = g_build_filename (path_videos, name, NULL);
     file = g_file_new_for_path (filename);
     cheese_thumb_view_append_item (thumb_view, file);
     g_free (filename);
     g_object_unref (file);
   }
+  g_free (path_videos);
+  g_dir_close (dir_videos);
+  
+  //read photos from the photo directory
+  while (name = g_dir_read_name (dir_photos))
+  {
+    if (!(g_str_has_suffix (name, PHOTO_NAME_SUFFIX)))
+      continue;
 
-  g_free (path);
-  g_dir_close (dir);
+    filename = g_build_filename (path_photos, name, NULL);
+    file = g_file_new_for_path (filename);
+    cheese_thumb_view_append_item (thumb_view, file);
+    g_free (filename);
+    g_object_unref (file);
+  }
+  g_free (path_photos);
+  g_dir_close (dir_photos);
 }
 
 static void
@@ -334,7 +354,8 @@
   CheeseThumbViewPrivate *priv = CHEESE_THUMB_VIEW_GET_PRIVATE (thumb_view);  
 
   g_object_unref (priv->store);
-  g_file_monitor_cancel (priv->file_monitor);
+  g_file_monitor_cancel (priv->photo_file_monitor);
+  g_file_monitor_cancel (priv->video_file_monitor);
 
   G_OBJECT_CLASS (cheese_thumb_view_parent_class)->finalize (object);
 }
@@ -353,7 +374,8 @@
 cheese_thumb_view_init (CheeseThumbView *thumb_view)
 {
   CheeseThumbViewPrivate* priv = CHEESE_THUMB_VIEW_GET_PRIVATE (thumb_view);
-  char *path = NULL;
+  char *path_videos = NULL, *path_photos = NULL;
+  
   GFile *file;  
   const int THUMB_VIEW_HEIGHT = 120;
 
@@ -365,15 +387,24 @@
 
   gtk_widget_set_size_request (GTK_WIDGET (thumb_view), -1, THUMB_VIEW_HEIGHT);
 
-  path = cheese_fileutil_get_media_path ();
+  path_videos = cheese_fileutil_get_video_path ();
+  path_photos = cheese_fileutil_get_photo_path ();
+  
+  g_mkdir_with_parents (path_videos, 0775);
+  g_mkdir_with_parents (path_photos, 0775);
+
+  //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);
+  g_signal_connect (priv->video_file_monitor, "changed", G_CALLBACK (cheese_thumb_view_monitor_cb), thumb_view);
+  
+  //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);
+  g_signal_connect (priv->photo_file_monitor, "changed", G_CALLBACK (cheese_thumb_view_monitor_cb), thumb_view);
 
-  g_mkdir_with_parents (path, 0775);
-
-  file = g_file_new_for_path (path);
-  priv->file_monitor = g_file_monitor_directory (file, 0, NULL, NULL);
-  g_signal_connect (priv->file_monitor, "changed", G_CALLBACK (cheese_thumb_view_monitor_cb), thumb_view);
-
-  g_free (path);
+  g_free (path_videos);
+  g_free (path_photos);
 
   gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (thumb_view), 0);
 #ifdef HILDON
@@ -388,7 +419,7 @@
   g_signal_connect (G_OBJECT (thumb_view), "drag-data-get",
                     G_CALLBACK (cheese_thumb_view_on_drag_data_get_cb), NULL);
 
-  gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(priv->store),
+  gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE (priv->store),
                                        THUMBNAIL_URL_COLUMN, GTK_SORT_ASCENDING);
 
   cheese_thumb_view_fill (thumb_view);

Modified: trunk/src/cheese-window.c
==============================================================================
--- trunk/src/cheese-window.c	(original)
+++ trunk/src/cheese-window.c	Fri May  2 16:48:30 2008
@@ -383,8 +383,8 @@
   char *filename;
   GFile *file;
   GList *files_list = NULL;
-  GDir *dir;
-  char *path;
+  GDir *dir_videos, *dir_photos;
+  char *path_videos, *path_photos;
   const char *name;
 
   prompt = g_strdup_printf (_("Really move all photos and videos to the trash?"));
@@ -406,14 +406,32 @@
   if (response !=  GTK_RESPONSE_OK)
     return;
 
-  path = cheese_fileutil_get_media_path ();
-  dir = g_dir_open (path, 0, NULL);
-  while ((name = g_dir_read_name (dir)) != NULL)
+  //delete all videos
+  path_videos = cheese_fileutil_get_video_path ();
+  dir_videos = g_dir_open (path_videos, 0, NULL);
+  while ((name = g_dir_read_name (dir_videos)) != NULL)
+  {
+    if (g_str_has_suffix (name, VIDEO_NAME_SUFFIX))
+    {
+      filename = g_strjoin (G_DIR_SEPARATOR_S, path_videos, name, NULL);
+      file = g_file_new_for_path (filename);
+
+      files_list = g_list_append (files_list, file);
+      g_free (filename);
+    }
+  }
+  cheese_window_cmd_move_file_to_trash (cheese_window, files_list);
+  g_list_free (files_list);
+  g_dir_close (dir_videos);
+  
+  //delete all videos
+  path_photos = cheese_fileutil_get_photo_path ();
+  dir_photos = g_dir_open (path_photos, 0, NULL);
+  while ((name = g_dir_read_name (dir_photos)) != NULL)
   {
-    if (g_str_has_suffix (name, PHOTO_NAME_SUFFIX) || 
-        g_str_has_suffix (name, VIDEO_NAME_SUFFIX))
+    if (g_str_has_suffix (name, PHOTO_NAME_SUFFIX))
     {
-      filename = g_strjoin (G_DIR_SEPARATOR_S, path, name, NULL);
+      filename = g_strjoin (G_DIR_SEPARATOR_S, path_photos, name, NULL);
       file = g_file_new_for_path (filename);
 
       files_list = g_list_append (files_list, file);
@@ -422,7 +440,7 @@
   }
   cheese_window_cmd_move_file_to_trash (cheese_window, files_list);
   g_list_free (files_list);
-  g_dir_close(dir);
+  g_dir_close (dir_photos);
 }
 
 static void
@@ -440,7 +458,7 @@
     return;
 
   file = g_file_new_for_path (filename);
-  g_free(filename);
+  g_free (filename);
 
   files_list = g_list_append (files_list, file);
   cheese_window_cmd_move_file_to_trash (cheese_window, files_list);
@@ -506,7 +524,7 @@
       }
       g_free (*data);
     }
-    g_free(filename);
+    g_free (filename);
     g_object_unref (pixbuf);
   }
 }
@@ -574,9 +592,9 @@
                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                 GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, 
                                 _("Unable to open help file for Cheese"));
-    gtk_dialog_run(GTK_DIALOG(d));
-    gtk_widget_destroy(d);
-    g_error_free(error);
+    gtk_dialog_run (GTK_DIALOG (d));
+    gtk_widget_destroy (d);
+    g_error_free (error);
   }
 }
 

Modified: trunk/src/cheese.c
==============================================================================
--- trunk/src/cheese.c	(original)
+++ trunk/src/cheese.c	Fri May  2 16:48:30 2008
@@ -46,7 +46,7 @@
 
   if (fp == NULL)
   {
-    path = cheese_fileutil_get_path ();
+    path = cheese_fileutil_get_log_path ();
     dir = g_dir_open (path, 0, NULL);
     if (!dir)
       return;



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