rhythmbox r6152 - in trunk: . bindings/python lib plugins plugins/artdisplay/artdisplay plugins/audioscrobbler shell tests



Author: jmatthew
Date: Mon Feb 16 08:54:47 2009
New Revision: 6152
URL: http://svn.gnome.org/viewvc/rhythmbox?rev=6152&view=rev

Log:
2009-02-16  Jonathan Matthew  <jonathan d14n org>

	based on a patch by: John Daiker  <daikerjohn gmail com>

	* lib/rb-file-helpers.c: (rb_dot_dir), (rb_user_data_dir),
	(rb_user_cache_dir), (rb_find_user_data_file),
	(rb_file_helpers_shutdown):
	* lib/rb-file-helpers.h:
	Add helpers to get our user data and cache directories, and for
	handling the migration of files from ~/.gnome2/rhythmbox/
	intelligently.
	
	* shell/rb-shell.c: (rb_shell_init), (rb_shell_new),
	(construct_db), (construct_sources):
	Use rb_find_user_data_file to migrate rhythmdb.xml and playlists.xml
	to the user data directory.

	* lib/rb-stock-icons.c: (rb_stock_icons_init):
	* plugins/rb-plugin.c: (rb_get_plugin_paths):
	Add user data dir search paths for icons and plugins

	* plugins/audioscrobbler/rb-audioscrobbler.c:
	(rb_audioscrobbler_load_queue), (rb_audioscrobbler_save_queue):
	Store audioscrobbler cache in user data dir.

	* tests/bench-rhythmdb-load.c: (main):
	Use rb_user_data_dir to find rhythmdb.xml
	
	* bindings/python/Makefile.am:
	* bindings/python/rb.defs:
	Add bindings for rb_user_data_dir and rb_user_cache_dir
	
	* plugins/artdisplay/artdisplay/CoverArtDatabase.py:
	Use rb_user_cache_dir to find the cover cache path.

	Fixes #518589 and #560824.


Modified:
   trunk/ChangeLog
   trunk/bindings/python/Makefile.am
   trunk/bindings/python/rb.defs
   trunk/lib/rb-file-helpers.c
   trunk/lib/rb-file-helpers.h
   trunk/lib/rb-stock-icons.c
   trunk/plugins/artdisplay/artdisplay/CoverArtDatabase.py
   trunk/plugins/audioscrobbler/rb-audioscrobbler.c
   trunk/plugins/rb-plugin.c
   trunk/shell/rb-shell.c
   trunk/tests/bench-rhythmdb-load.c

Modified: trunk/bindings/python/Makefile.am
==============================================================================
--- trunk/bindings/python/Makefile.am	(original)
+++ trunk/bindings/python/Makefile.am	Mon Feb 16 08:54:47 2009
@@ -54,6 +54,7 @@
 	plugins/rb-plugin.h			\
 	lib/rb-string-value-map.h		\
 	lib/rb-cut-and-paste-code.h		\
+	lib/rb-file-helpers.h			\
 	rhythmdb/rhythmdb.h			\
 	rhythmdb/rhythmdb-property-model.h	\
 	rhythmdb/rhythmdb-query-model.h		\

Modified: trunk/bindings/python/rb.defs
==============================================================================
--- trunk/bindings/python/rb.defs	(original)
+++ trunk/bindings/python/rb.defs	Mon Feb 16 08:54:47 2009
@@ -2428,3 +2428,18 @@
   )
 )
 
+;; From rb-file-helpers.h
+
+(define-function user_data_dir
+  (in-module "rb")
+  (c-name "rb_user_data_dir")
+  (return-type "const-char*")
+)
+
+(define-function user_cache_dir
+  (in-module "rb")
+  (c-name "rb_user_cache_dir")
+  (return-type "const-char*")
+)
+
+

Modified: trunk/lib/rb-file-helpers.c
==============================================================================
--- trunk/lib/rb-file-helpers.c	(original)
+++ trunk/lib/rb-file-helpers.c	Mon Feb 16 08:54:47 2009
@@ -46,6 +46,8 @@
 static GHashTable *files = NULL;
 
 static char *dot_dir = NULL;
+static char *user_data_dir = NULL;
+static char *user_cache_dir = NULL;
 
 const char *
 rb_file (const char *filename)
@@ -91,13 +93,63 @@
 					    GNOME_DOT_GNOME,
 					    "rhythmbox",
 					    NULL);
-		if (g_mkdir (dot_dir, 0750) == -1)
-			rb_debug ("unable to create Rhythmbox's dot dir");
+
+		/* since we don't write any new files in this directory, we shouldn't
+		 * create it if it doesn't already exist.
+		 */
 	}
 	
 	return dot_dir;
 }
 
+/**
+ * rb_user_data_dir:
+ *
+ * This will create the rhythmbox user data directory, using the XDG Base
+ * Directory specification.  If none of the XDG environment variables are
+ * set, this will be ~/.local/share/rhythmbox.
+ *
+ * Returns: string holding the path to the rhythmbox user data directory, or
+ * NULL if the directory does not exist and cannot be created.
+ */
+const char *
+rb_user_data_dir (void)
+{
+	if (user_data_dir == NULL) {
+		user_data_dir = g_build_filename (g_get_user_data_dir (),
+						  "rhythmbox",
+						  NULL);
+		if (g_mkdir_with_parents (user_data_dir, 0700) == -1)
+			rb_debug ("unable to create Rhythmbox's user data dir, %s", user_data_dir);
+	}
+	
+	return user_data_dir;
+}
+
+/**
+ * rb_user_cache_dir:
+ *
+ * This will create the rhythmbox user cache directory, using the XDG
+ * Base Directory specification.  If none of the XDG environment
+ * variables are set, this will be ~/.cache/rhythmbox.
+ *
+ * Returns: string holding the path to the rhythmbox user cache directory, or
+ * NULL if the directory does not exist and could not be created.
+ */
+const char *
+rb_user_cache_dir (void)
+{
+	if (user_cache_dir == NULL) {
+		user_cache_dir = g_build_filename (g_get_user_cache_dir (),
+						   "rhythmbox",
+						   NULL);
+		if (g_mkdir_with_parents (user_cache_dir, 0700) == -1)
+			rb_debug ("unable to create Rhythmbox's user cache dir, %s", user_cache_dir);
+	}
+
+	return user_cache_dir;
+}
+
 
 const char *
 rb_music_dir (void)
@@ -114,6 +166,77 @@
 	return dir;
 }
 
+/**
+ * rb_find_user_data_file:
+ * @name: name of file to find
+ * @error: returns error information
+ *
+ * Determines the full path to use for user-specific files, such as rhythmdb.xml.
+ * This first checks in the user data directory (see @rb_user_data_dir).
+ * If the file does not exist in the user data directory, it then checks the
+ * old .gnome2 directory, moving the file to the user data directory if found there.
+ * If an error occurs while moving the file, this will be reported through @error 
+ * and the .gnome2 path will be returned.
+ *
+ * Returns: allocated string containing the location of the file to use, even if
+ *  an error occurred.
+ */
+char *
+rb_find_user_data_file (const char *name,
+			GError **error)
+{
+	GError *temp_err = NULL;
+	char *srcpath;
+	char *destpath;
+	GFile *src;
+	GFile *dest;
+	char *use_path;
+
+	/* if the file exists in the user data dir, return the path */
+	destpath = g_build_filename (rb_user_data_dir (), name, NULL);
+	dest = g_file_new_for_path (destpath);
+	if (g_file_query_exists (dest, NULL) == TRUE) {
+		g_object_unref (dest);
+		rb_debug ("found user data dir path for '%s': %s", name, destpath);
+		return destpath;
+	}
+
+	/* doesn't exist in the user data dir, so try to move it from the .gnome2 dir */
+	srcpath = g_build_filename (rb_dot_dir (), name, NULL);
+	src = g_file_new_for_path (srcpath);
+
+	if (g_file_query_exists (src, NULL)) {
+		g_file_move (src, dest, G_FILE_COPY_NONE, NULL, NULL, NULL, &temp_err);
+		if (temp_err != NULL) {
+			rb_debug ("failed to move user data file '%s' from .gnome2 dir, returning .gnome2 path %s: %s",
+				  name, srcpath, temp_err->message);
+
+			use_path = g_file_get_path (src);
+			g_set_error (error,
+				     temp_err->domain,
+				     temp_err->code,
+				     _("Unable to move %s to %s: %s"),
+				     srcpath, destpath, temp_err->message);
+			g_error_free (temp_err);
+		} else {
+			rb_debug ("moved user data file '%s' from .gnome2 dir, returning user data dir path %s",
+				  name, destpath);
+			use_path = g_file_get_path (dest);
+		}
+	} else {
+		rb_debug ("no existing file for '%s', returning user data dir path %s", name, destpath);
+		use_path = g_file_get_path (dest);
+	}
+
+	g_free (srcpath);
+	g_free (destpath);
+
+	g_object_unref (src);
+	g_object_unref (dest);
+
+	return use_path;
+}
+
 void
 rb_file_helpers_init (void)
 {
@@ -128,6 +251,8 @@
 {
 	g_hash_table_destroy (files);
 	g_free (dot_dir);
+	g_free (user_data_dir);
+	g_free (user_cache_dir);
 }
 
 #define MAX_LINK_LEVEL 5

Modified: trunk/lib/rb-file-helpers.h
==============================================================================
--- trunk/lib/rb-file-helpers.h	(original)
+++ trunk/lib/rb-file-helpers.h	Mon Feb 16 08:54:47 2009
@@ -37,8 +37,13 @@
 
 const char *	rb_file			(const char *filename);
 const char *	rb_dot_dir		(void);
+const char *	rb_user_data_dir	(void);
+const char *	rb_user_cache_dir	(void);
 const char *	rb_music_dir		(void);
 
+char *		rb_find_user_data_file	(const char *name,
+					 GError **error);
+
 char *		rb_canonicalise_uri	(const char *uri);
 
 gboolean	rb_uri_mkstemp		(const char *prefix, char **uri,

Modified: trunk/lib/rb-stock-icons.c
==============================================================================
--- trunk/lib/rb-stock-icons.c	(original)
+++ trunk/lib/rb-stock-icons.c	Mon Feb 16 08:54:47 2009
@@ -80,8 +80,11 @@
 	int icon_size;
 	char *dot_icon_dir;
 
-	/* add our icon search paths */
+	/* add our icon search paths.  the rb_dot_dir() path is deprecated
+	 * and should be removed at some point.
+	 */
 	dot_icon_dir = g_build_filename (rb_dot_dir (), "icons", NULL);
+	dot_icon_dir = g_build_filename (rb_user_data_dir (), "icons", NULL);
 	gtk_icon_theme_append_search_path (theme, dot_icon_dir);
 	g_free (dot_icon_dir);
 

Modified: trunk/plugins/artdisplay/artdisplay/CoverArtDatabase.py
==============================================================================
--- trunk/plugins/artdisplay/artdisplay/CoverArtDatabase.py	(original)
+++ trunk/plugins/artdisplay/artdisplay/CoverArtDatabase.py	Mon Feb 16 08:54:47 2009
@@ -40,11 +40,8 @@
 ART_SEARCHES_LOCAL = [LocalCoverArtSearch]
 ART_SEARCHES_REMOTE = [PodcastCoverArtSearch, AmazonCoverArtSearch]
 OLD_ART_FOLDER = '~/.gnome2/rhythmbox/covers'
-# complicated way of saying ~/.cache/rhythmbox/covers
-ART_FOLDER = os.path.join(os.environ.get('XDG_CACHE_HOME',
-		os.path.join(os.environ.get('XDG_HOME_DIR',
-				os.environ.get('HOME','~')),
-				'.cache')), 'rhythmbox/covers')
+
+ART_FOLDER = os.path.join(rb.user_cache_dir(), 'covers')
 ART_CACHE_EXTENSION_JPG = 'jpg'
 ART_CACHE_EXTENSION_PNG = 'png'
 ART_CACHE_FORMAT_JPG = 'jpeg'

Modified: trunk/plugins/audioscrobbler/rb-audioscrobbler.c
==============================================================================
--- trunk/plugins/audioscrobbler/rb-audioscrobbler.c	(original)
+++ trunk/plugins/audioscrobbler/rb-audioscrobbler.c	Mon Feb 16 08:54:47 2009
@@ -1357,7 +1357,8 @@
 	char *end;
 	gsize size;
 
-	pathname = g_build_filename (rb_dot_dir (), "audioscrobbler.queue", NULL);
+	/* we don't really care about errors enough to report them here */
+	pathname = rb_find_user_data_file ("audioscrobbler.queue", NULL);
 	file = g_file_new_for_path (pathname);
 	rb_debug ("loading Audioscrobbler queue from \"%s\"", pathname);
 	g_free (pathname);
@@ -1413,7 +1414,8 @@
 		rb_audioscrobbler_entry_save_to_string (str, entry);
 	}
 
-	pathname = g_build_filename (rb_dot_dir (), "audioscrobbler.queue", NULL);
+	/* we don't really care about errors enough to report them here */
+	pathname = rb_find_user_data_file ("audioscrobbler.queue", NULL);
 	rb_debug ("Saving Audioscrobbler queue to \"%s\"", pathname);
 
 	file = g_file_new_for_path (pathname);

Modified: trunk/plugins/rb-plugin.c
==============================================================================
--- trunk/plugins/rb-plugin.c	(original)
+++ trunk/plugins/rb-plugin.c	Mon Feb 16 08:54:47 2009
@@ -202,8 +202,12 @@
 	paths = NULL;
 
 	if (!eel_gconf_get_boolean (CONF_PLUGIN_DISABLE_USER)) {
+		/* deprecated path, should be removed some time in the future */
 		path = g_build_filename (rb_dot_dir (), "plugins", NULL);
 		paths = g_list_prepend (paths, path);
+
+		path = g_build_filename (rb_user_data_dir (), "plugins", NULL);
+		paths = g_list_prepend (paths, path);
 	}
 
 #ifdef SHARE_UNINSTALLED_DIR

Modified: trunk/shell/rb-shell.c
==============================================================================
--- trunk/shell/rb-shell.c	(original)
+++ trunk/shell/rb-shell.c	Mon Feb 16 08:54:47 2009
@@ -678,7 +678,7 @@
 {
 	shell->priv = RB_SHELL_GET_PRIVATE (shell);
 
-	rb_dot_dir ();
+	rb_user_data_dir ();
 
         rb_shell_session_init (shell);
 
@@ -953,23 +953,11 @@
 	      char *rhythmdb,
 	      char *playlists)
 {
-	RBShell *s;
-	char *pathname;
-
-	/* set default playlist name, if none supplied */
-	if (playlists) 
-		pathname = g_strdup (playlists);
-	else 
-		pathname = g_build_filename (rb_dot_dir (), "playlists.xml", NULL); 
-	
-	s = g_object_new (RB_TYPE_SHELL,
+	return g_object_new (RB_TYPE_SHELL,
 			  "no-registration", no_registration,
 			  "no-update", no_update,
 			  "dry-run", dry_run, "rhythmdb-file", rhythmdb, 
-			  "playlists-file", pathname, NULL);
-
-	g_free (pathname);
-	return s;
+			  "playlists-file", playlists, NULL);
 }
 
 static GMountOperation *
@@ -986,16 +974,24 @@
 static void
 construct_db (RBShell *shell)
 {
+	GError *error = NULL;
 	char *pathname;
 
 	/* Initialize the database */
 	rb_debug ("creating database object");
 	rb_profile_start ("creating database object");
 
-	if (shell->priv->rhythmdb_file)
+	if (shell->priv->rhythmdb_file) {
 		pathname = g_strdup (shell->priv->rhythmdb_file);
-	else
-		pathname = g_build_filename (rb_dot_dir (), "rhythmdb.xml", NULL);
+	} else {
+		pathname = rb_find_user_data_file ("rhythmdb.xml", &error);
+		if (error != NULL) {
+			rb_error_dialog (GTK_WINDOW (shell->priv->window),
+					 _("Unable to move user data files"),
+					 "%s", error->message);
+			g_error_free (error);
+		}
+	}
 
 #ifdef WITH_RHYTHMDB_TREE
 	shell->priv->db = rhythmdb_tree_new (pathname);
@@ -1183,6 +1179,9 @@
 static void
 construct_sources (RBShell *shell)
 {
+	GError *error = NULL;
+	char *pathname;
+
 	rb_profile_start ("constructing sources");
 
 	shell->priv->library_source = RB_LIBRARY_SOURCE (rb_library_source_new (shell));
@@ -1194,10 +1193,23 @@
 	shell->priv->import_errors_source = rb_import_errors_source_new (shell, RHYTHMDB_ENTRY_TYPE_IMPORT_ERROR);
 	rb_shell_append_source (shell, shell->priv->import_errors_source, NULL);
 
+	/* Find the playlist name if none supplied */
+	if (shell->priv->playlists_file) {
+		pathname = g_strdup (shell->priv->playlists_file);
+	} else {
+		pathname = rb_find_user_data_file ("playlists.xml", &error);
+		if (error != NULL) {
+			rb_error_dialog (GTK_WINDOW (shell->priv->window),
+					 _("Unable to move user data files"),
+					 "%s", error->message);
+			g_error_free (error);
+		}
+	}
+
 	/* Initialize playlist manager */
 	rb_debug ("shell: creating playlist manager");
 	shell->priv->playlist_manager = rb_playlist_manager_new (shell,
-								 RB_SOURCELIST (shell->priv->sourcelist), shell->priv->playlists_file);
+								 RB_SOURCELIST (shell->priv->sourcelist), pathname);
 
 	g_object_set (G_OBJECT(shell->priv->clipboard_shell), "playlist-manager", shell->priv->playlist_manager, NULL);
 
@@ -1215,6 +1227,8 @@
 	g_signal_connect_object (G_OBJECT (shell->priv->removable_media_manager), "transfer-progress",
 				 G_CALLBACK (rb_shell_transfer_progress_cb), shell, 0);
 
+	g_free (pathname);
+
 	rb_profile_end ("constructing sources");
 }
 

Modified: trunk/tests/bench-rhythmdb-load.c
==============================================================================
--- trunk/tests/bench-rhythmdb-load.c	(original)
+++ trunk/tests/bench-rhythmdb-load.c	Mon Feb 16 08:54:47 2009
@@ -89,8 +89,8 @@
 	int i;
 
 	if (argc < 2) {
-		g_print ("using ~/.gnome2/rhythmbox/rhythmdb.xml\n");
-		name = g_strdup_printf ("%s/rhythmdb.xml", rb_dot_dir ());
+		name = g_build_filename (rb_user_data_dir(), "rhythmdb.xml", NULL);
+		g_print ("using %s\n", name);
 	} else {
 		name = g_strdup (argv[1]);
 	}



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