cheese r1001 - in trunk: . src



Author: dgsiegel
Date: Mon Sep  8 22:37:51 2008
New Revision: 1001
URL: http://svn.gnome.org/viewvc/cheese?rev=1001&view=rev

Log:
old photos and videos (before 2.24) are now available in cheese 2.24, fixes bug #547290


Modified:
   trunk/ChangeLog
   trunk/src/cheese-fileutil.c
   trunk/src/cheese-fileutil.h
   trunk/src/cheese.c

Modified: trunk/src/cheese-fileutil.c
==============================================================================
--- trunk/src/cheese-fileutil.c	(original)
+++ trunk/src/cheese-fileutil.c	Mon Sep  8 22:37:51 2008
@@ -79,6 +79,12 @@
 }
 
 gchar *
+cheese_fileutil_get_path_before_224 (CheeseFileUtil *fileutil)
+{
+  return g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", "media", NULL);
+}
+
+gchar *
 cheese_fileutil_get_log_path (CheeseFileUtil *fileutil)
 {
   CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
@@ -177,41 +183,37 @@
   CheeseFileUtilPrivate *priv = CHEESE_FILEUTIL_GET_PRIVATE (fileutil);
 
   CheeseGConf *gconf;
-  gchar       *v_path, *p_path;
 
   gconf = cheese_gconf_new ();
 
-  /* get the path from gconf, xdg or hardcoded */
-  g_object_get (gconf, "gconf_prop_video_path", &v_path, NULL);
+  g_object_get (gconf, "gconf_prop_video_path", &priv->video_path, NULL);
+  g_object_get (gconf, "gconf_prop_photo_path", &priv->photo_path, NULL);
 
-  if (!v_path || strcmp (v_path, "") == 0)
+  /* get the video path from gconf, xdg or hardcoded */
+  if (!priv->video_path || strcmp (priv->video_path, "") == 0)
   {
     /* get xdg */
-    v_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS), "Webcam", NULL);
-    if (strcmp (v_path, "") == 0)
+    priv->video_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS), "Webcam", NULL);
+    if (strcmp (priv->video_path, "") == 0)
     {
       /* get "~/.gnome2/cheese/media" */
-
-      v_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", "media", NULL);
+      priv->video_path = cheese_fileutil_get_path_before_224 (fileutil);
     }
   }
-  priv->video_path = v_path;
-
-  /* get the path from gconf, xdg or hardcoded */
-  g_object_get (gconf, "gconf_prop_photo_path", &p_path, NULL);
 
-  if (!p_path || strcmp (p_path, "") == 0)
+  /* get the photo path from gconf, xdg or hardcoded */
+  if (!priv->photo_path || strcmp (priv->photo_path, "") == 0)
   {
     /* get xdg */
-    p_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES), "Webcam", NULL);
-    if (strcmp (p_path, "") == 0)
+    priv->photo_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_user_special_dir (G_USER_DIRECTORY_PICTURES), "Webcam", NULL);
+    if (strcmp (priv->photo_path, "") == 0)
     {
       /* get "~/.gnome2/cheese/media" */
-      p_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", "media", NULL);
+      priv->photo_path = cheese_fileutil_get_path_before_224 (fileutil);
     }
   }
-  priv->photo_path = p_path;
 
+  /* FIXME: use the xdg log path */
   priv->log_path = g_strjoin (G_DIR_SEPARATOR_S, g_get_home_dir (), ".gnome2", "cheese", NULL);
 
   g_object_unref (gconf);

Modified: trunk/src/cheese-fileutil.h
==============================================================================
--- trunk/src/cheese-fileutil.h	(original)
+++ trunk/src/cheese-fileutil.h	Mon Sep  8 22:37:51 2008
@@ -58,6 +58,7 @@
 
 gchar *cheese_fileutil_get_video_path (CheeseFileUtil *fileutil);
 gchar *cheese_fileutil_get_photo_path (CheeseFileUtil *fileutil);
+gchar *cheese_fileutil_get_path_before_224 (CheeseFileUtil *fileutil);
 gchar *cheese_fileutil_get_log_path (CheeseFileUtil *fileutil);
 gchar *cheese_fileutil_get_new_media_filename (CheeseFileUtil *fileutil, CheeseMediaMode mode);
 

Modified: trunk/src/cheese.c
==============================================================================
--- trunk/src/cheese.c	(original)
+++ trunk/src/cheese.c	Mon Sep  8 22:37:51 2008
@@ -49,7 +49,6 @@
 
   CheeseFileUtil *fileutil = cheese_fileutil_new ();
 
-
   if (fp == NULL)
   {
     path = cheese_fileutil_get_log_path (fileutil);
@@ -60,13 +59,13 @@
       return;
     }
 
-    // remove the old logfile if it exists
+    /* remove the old logfile if it exists */
     filename = g_build_filename (path, "log", NULL);
     if (g_file_test (filename, G_FILE_TEST_EXISTS))
     {
       GFile *old = g_file_new_for_path (filename);
       g_file_delete (old, NULL, NULL);
-      g_object_unref(old);
+      g_object_unref (old);
     }
     g_free (filename);
 
@@ -85,6 +84,72 @@
     fprintf (stdout, "%s", string);
 }
 
+void
+cheese_handle_files_from_before_224 (void)
+{
+  CheeseFileUtil *fileutil             = cheese_fileutil_new ();
+  gchar          *photo_path           = cheese_fileutil_get_photo_path (fileutil);
+  gchar          *video_path           = cheese_fileutil_get_video_path (fileutil);
+  gchar          *path_from_before_224 = cheese_fileutil_get_path_before_224 (fileutil);
+  GDir           *dir_from_before_224;
+  gchar          *source_filename, *target_filename;
+  const char     *name;
+  GFile          *source, *target, *dir;
+
+  if (g_file_test (path_from_before_224, G_FILE_TEST_IS_DIR) &&
+      (g_strcmp0 (video_path, path_from_before_224) != 0) &&
+      (g_strcmp0 (photo_path, path_from_before_224) != 0))
+  {
+    dir_from_before_224 = g_dir_open (path_from_before_224, 0, NULL);
+
+    while ((name = g_dir_read_name (dir_from_before_224)))
+    {
+      /* the filenames from before 2.24 have different namings than the > 2.24
+       * files (0042.jpg/ogg vs. 2008-09-09-015555.jpg/ogv) so we just copy and
+       * rename the ogg files to ogv
+       */
+      if (g_str_has_suffix (name, VIDEO_NAME_SUFFIX))
+      {
+        target_filename = g_build_filename (video_path, name, NULL);
+      }
+      else if (g_str_has_suffix (name, ".ogg"))
+      {
+        gchar *filename  = g_strdup (name);
+        gchar *extension = g_strrstr (filename, ".ogg");
+        extension[3]    = 'v';
+        target_filename = g_build_filename (video_path, filename, NULL);
+        g_free (filename);
+      }
+      else if (g_str_has_suffix (name, PHOTO_NAME_SUFFIX))
+      {
+        target_filename = g_build_filename (photo_path, name, NULL);
+      }
+      else
+      {
+        continue;
+      }
+
+      source_filename = g_build_filename (path_from_before_224, name, NULL);
+      source          = g_file_new_for_path (source_filename);
+      target          = g_file_new_for_path (target_filename);
+      printf ("copying %s to %s\n", source_filename, target_filename);
+      g_file_move (source, target, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, NULL);
+      g_free (source_filename);
+      g_free (target_filename);
+      g_object_unref (source);
+      g_object_unref (target);
+    }
+
+    g_dir_close (dir_from_before_224);
+
+    dir = g_file_new_for_path (path_from_before_224);
+    g_file_delete (dir, NULL, NULL);
+    g_object_unref (dir);
+  }
+  g_free (path_from_before_224);
+  g_object_unref (fileutil);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -133,6 +198,7 @@
   gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
                                      APPNAME_DATA_DIR G_DIR_SEPARATOR_S "icons");
 
+  cheese_handle_files_from_before_224 ();
   cheese_window_init (CheeseOptions.hal_device_id, dbus_server);
 
   gdk_threads_enter ();



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