[brasero] Code refactoring for next fix



commit f0f36d4a99064d0b67b8875720c7933367bf34b3
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Wed Aug 26 13:23:48 2009 +0200

    Code refactoring for next fix

 src/brasero-app.c             |  147 ++++++++++++++++++++++++++++++++++++++++-
 src/brasero-app.h             |    4 +
 src/brasero-project-manager.c |  141 +--------------------------------------
 src/brasero-project-manager.h |    9 ---
 src/main.c                    |    6 +--
 5 files changed, 151 insertions(+), 156 deletions(-)
---
diff --git a/src/brasero-app.c b/src/brasero-app.c
index d480a2a..d8de171 100644
--- a/src/brasero-app.c
+++ b/src/brasero-app.c
@@ -1127,6 +1127,147 @@ on_configure_event_cb (GtkWidget *widget,
 	return FALSE;
 }
 
+static gboolean
+brasero_app_open_by_mime (BraseroApp *app,
+                          const gchar *uri,
+                          const gchar *mime)
+{
+	BraseroAppPrivate *priv;
+
+	priv = BRASERO_APP_PRIVATE (app);
+
+	if (!mime) {
+		/* that can happen when the URI could not be identified */
+		return FALSE;
+	}
+
+	/* When our files/description of x-brasero mime type is not properly 
+	 * installed, it's returned as application/xml, so check that too. */
+	if (!strcmp (mime, "application/x-brasero")
+	||  !strcmp (mime, "application/xml"))
+		return (brasero_project_manager_open_project (BRASERO_PROJECT_MANAGER (priv->projects), uri, FALSE, FALSE) != BRASERO_PROJECT_TYPE_INVALID);
+
+#ifdef BUILD_PLAYLIST
+
+	else if (!strcmp (mime, "audio/x-scpls")
+	     ||  !strcmp (mime, "audio/x-ms-asx")
+	     ||  !strcmp (mime, "audio/x-mp3-playlist")
+	     ||  !strcmp (mime, "audio/x-mpegurl"))
+		return (brasero_project_manager_open_project (BRASERO_PROJECT_MANAGER (priv->projects), uri, TRUE, FALSE) != BRASERO_PROJECT_TYPE_INVALID);
+
+
+#endif
+
+	else if (!strcmp (mime, "application/x-cd-image")
+	     ||  !strcmp (mime, "application/x-cdrdao-toc")
+	     ||  !strcmp (mime, "application/x-toc")
+	     ||  !strcmp (mime, "application/x-cue")) {
+		brasero_project_manager_iso (BRASERO_PROJECT_MANAGER (priv->projects), uri);
+		return TRUE;
+	}
+
+	return FALSE;
+}
+
+gboolean
+brasero_app_open_uri (BraseroApp *app,
+                      const gchar *uri_arg)
+{
+	gchar *uri;
+	GFile *file;
+	GFileInfo *info;
+	BraseroProjectType type;
+
+	/* FIXME: make that asynchronous */
+	/* NOTE: don't follow symlink because we want to identify them */
+	file = g_file_new_for_commandline_arg (uri_arg);
+	if (!file)
+		return BRASERO_PROJECT_TYPE_INVALID;
+
+	info = g_file_query_info (file,
+				  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+				  G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK ","
+				  G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
+				  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+				  NULL,
+				  NULL);
+
+	if (!info) {
+		g_object_unref (file);
+		return BRASERO_PROJECT_TYPE_INVALID;
+	}
+
+	/* if that's a symlink, redo it on its target to get the real mime type
+	 * that usually also depends on the extension of the target:
+	 * ex: an iso file with the extension .iso will be seen as octet-stream
+	 * if the symlink hasn't got any extention at all */
+	while (g_file_info_get_is_symlink (info)) {
+		const gchar *target;
+		GFileInfo *tmp_info;
+		GFile *tmp_file;
+		GError *error = NULL;
+
+		target = g_file_info_get_symlink_target (info);
+		if (!g_path_is_absolute (target)) {
+			gchar *parent;
+			gchar *tmp;
+
+			tmp = g_file_get_path (file);
+			parent = g_path_get_dirname (tmp);
+			g_free (tmp);
+
+			target = g_build_filename (parent, target, NULL);
+			g_free (parent);
+		}
+
+		tmp_file = g_file_new_for_commandline_arg (target);
+		tmp_info = g_file_query_info (tmp_file,
+					      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
+					      G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK ","
+					      G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
+					      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+					      NULL,
+					      &error);
+		if (!tmp_info) {
+			g_object_unref (tmp_file);
+			break;
+		}
+
+		g_object_unref (info);
+		g_object_unref (file);
+
+		info = tmp_info;
+		file = tmp_file;
+	}
+
+	uri = g_file_get_uri (file);
+	if (g_file_query_exists (file, NULL)
+	&& g_file_info_get_content_type (info)) {
+		const gchar *mime;
+
+		mime = g_file_info_get_content_type (info);
+	  	type = brasero_app_open_by_mime (app, uri, mime);
+        } 
+	else {
+		gchar *string;
+
+		string = g_strdup_printf (_("The project \"%s\" does not exist"), uri);
+		brasero_app_alert (app,
+				   _("Error while loading the project"),
+				   string,
+				   GTK_MESSAGE_ERROR);
+		g_free (string);
+
+		type = BRASERO_PROJECT_TYPE_INVALID;
+	}
+
+	g_free (uri);
+	g_object_unref (file);
+	g_object_unref (info);
+
+	return type;
+}
+
 static void
 brasero_app_recent_open (GtkRecentChooser *chooser,
 			 BraseroApp *app)
@@ -1166,9 +1307,9 @@ brasero_app_recent_open (GtkRecentChooser *chooser,
 	}
 
 	/* Make sure it is no longer one shot */
-	brasero_project_manager_open_by_mime (BRASERO_PROJECT_MANAGER (priv->projects),
-					      uri,
-					      mime);
+	brasero_app_open_by_mime (app,
+	                          uri,
+	                          mime);
 	gtk_recent_info_unref (item);
 	g_free (uri);
 }
diff --git a/src/brasero-app.h b/src/brasero-app.h
index 254488b..4ff5125 100644
--- a/src/brasero-app.h
+++ b/src/brasero-app.h
@@ -111,6 +111,10 @@ void
 brasero_app_check (BraseroApp *app,
 		   const gchar *device);
 
+gboolean
+brasero_app_open_uri (BraseroApp *app,
+                      const gchar *uri_arg);
+
 GtkWidget *
 brasero_app_get_statusbar1 (BraseroApp *app);
 
diff --git a/src/brasero-project-manager.c b/src/brasero-project-manager.c
index 1198ca9..0a04af8 100644
--- a/src/brasero-project-manager.c
+++ b/src/brasero-project-manager.c
@@ -782,143 +782,6 @@ brasero_project_manager_open_project (BraseroProjectManager *manager,
 	return type;
 }
 
-BraseroProjectType
-brasero_project_manager_open_by_mime (BraseroProjectManager *manager,
-				      const gchar *uri,
-				      const gchar *mime)
-{
-	if (!mime) {
-		/* that can happen when the URI could not be identified */
-		return BRASERO_PROJECT_TYPE_INVALID;
-	}
-
-	/* When our files/description of x-brasero mime type is not properly 
-	 * installed, it's returned as application/xml, so check that too. */
-	if (!strcmp (mime, "application/x-brasero")
-	||  !strcmp (mime, "application/xml"))
-		return brasero_project_manager_open_project (manager, uri, FALSE, FALSE);
-
-#ifdef BUILD_PLAYLIST
-
-	else if (!strcmp (mime, "audio/x-scpls")
-	     ||  !strcmp (mime, "audio/x-ms-asx")
-	     ||  !strcmp (mime, "audio/x-mp3-playlist")
-	     ||  !strcmp (mime, "audio/x-mpegurl"))
-		return brasero_project_manager_open_project (manager, uri, TRUE, FALSE);
-
-
-#endif
-
-	else if (!strcmp (mime, "application/x-cd-image")
-	     ||  !strcmp (mime, "application/x-cdrdao-toc")
-	     ||  !strcmp (mime, "application/x-toc")
-	     ||  !strcmp (mime, "application/x-cue")) {
-		brasero_project_manager_iso (manager, uri);
-		return BRASERO_PROJECT_TYPE_ISO;
-	}
-
-	return BRASERO_PROJECT_TYPE_INVALID;
-}
-
-BraseroProjectType
-brasero_project_manager_open_uri (BraseroProjectManager *manager,
-				  const gchar *uri_arg)
-{
-	gchar *uri;
-	GFile *file;
-	GFileInfo *info;
-	BraseroProjectType type;
-
-	/* FIXME: make that asynchronous */
-	/* NOTE: don't follow symlink because we want to identify them */
-	file = g_file_new_for_commandline_arg (uri_arg);
-	if (!file)
-		return BRASERO_PROJECT_TYPE_INVALID;
-
-	info = g_file_query_info (file,
-				  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
-				  G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK ","
-				  G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
-				  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-				  NULL,
-				  NULL);
-
-	if (!info) {
-		g_object_unref (file);
-		return BRASERO_PROJECT_TYPE_INVALID;
-	}
-
-	/* if that's a symlink, redo it on its target to get the real mime type
-	 * that usually also depends on the extension of the target:
-	 * ex: an iso file with the extension .iso will be seen as octet-stream
-	 * if the symlink hasn't got any extention at all */
-	while (g_file_info_get_is_symlink (info)) {
-		const gchar *target;
-		GFileInfo *tmp_info;
-		GFile *tmp_file;
-		GError *error = NULL;
-
-		target = g_file_info_get_symlink_target (info);
-		if (!g_path_is_absolute (target)) {
-			gchar *parent;
-			gchar *tmp;
-
-			tmp = g_file_get_path (file);
-			parent = g_path_get_dirname (tmp);
-			g_free (tmp);
-
-			target = g_build_filename (parent, target, NULL);
-			g_free (parent);
-		}
-
-		tmp_file = g_file_new_for_commandline_arg (target);
-		tmp_info = g_file_query_info (tmp_file,
-					      G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
-					      G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK ","
-					      G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET,
-					      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
-					      NULL,
-					      &error);
-		if (!tmp_info) {
-			g_object_unref (tmp_file);
-			break;
-		}
-
-		g_object_unref (info);
-		g_object_unref (file);
-
-		info = tmp_info;
-		file = tmp_file;
-	}
-
-	uri = g_file_get_uri (file);
-	if (g_file_query_exists (file, NULL)
-	&& g_file_info_get_content_type (info)) {
-		const gchar *mime;
-
-		mime = g_file_info_get_content_type (info);
-	  	type = brasero_project_manager_open_by_mime (manager, uri, mime);
-        } 
-	else {
-		gchar *string;
-
-		string = g_strdup_printf (_("The project \"%s\" does not exist"), uri);
-		brasero_app_alert (brasero_app_get_default (),
-				   _("Error while loading the project"),
-				   string,
-				   GTK_MESSAGE_ERROR);
-		g_free (string);
-
-		type = BRASERO_PROJECT_TYPE_INVALID;
-	}
-
-	g_free (uri);
-	g_object_unref (file);
-	g_object_unref (info);
-
-	return type;
-}
-
 static void
 brasero_project_manager_open_cb (GtkAction *action, BraseroProjectManager *manager)
 {
@@ -948,7 +811,7 @@ brasero_project_manager_open_cb (GtkAction *action, BraseroProjectManager *manag
 	uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
 	gtk_widget_destroy (chooser);
 
-	brasero_project_manager_open_uri (manager, uri);
+	brasero_app_open_uri (brasero_app_get_default (), uri);
 	g_free (uri);
 }
 
@@ -957,7 +820,7 @@ brasero_project_manager_recent_clicked_cb (BraseroProjectTypeChooser *chooser,
 					   const gchar *uri,
 					   BraseroProjectManager *manager)
 {
-	brasero_project_manager_open_uri (manager, uri);
+	brasero_app_open_uri (brasero_app_get_default (), uri);
 }
 
 void
diff --git a/src/brasero-project-manager.h b/src/brasero-project-manager.h
index 4b8c05d..0ecd8df 100644
--- a/src/brasero-project-manager.h
+++ b/src/brasero-project-manager.h
@@ -86,15 +86,6 @@ brasero_project_manager_open_project (BraseroProjectManager *manager,
 				      gboolean playlist,
 				      gboolean burn);
 
-BraseroProjectType
-brasero_project_manager_open_by_mime (BraseroProjectManager *manager,
-				      const gchar *uri,
-				      const gchar *mime);
-
-BraseroProjectType
-brasero_project_manager_open_uri (BraseroProjectManager *manager,
-				  const gchar *uri_arg);
-
 void
 brasero_project_manager_empty (BraseroProjectManager *manager);
 
diff --git a/src/main.c b/src/main.c
index b945683..66d0a24 100644
--- a/src/main.c
+++ b/src/main.c
@@ -434,12 +434,8 @@ brasero_app_parse_options (BraseroApp *app)
 		manager = brasero_app_get_project_manager (app);
 
 		if (g_strv_length (files) == 1) {
-			BraseroProjectType type;
-
-			type = brasero_project_manager_open_uri (BRASERO_PROJECT_MANAGER (manager), files [0]);
-
 			/* Fallback if it hasn't got a suitable URI */
-			if (type == BRASERO_PROJECT_TYPE_INVALID) {
+			if (!brasero_app_open_uri (app, files [0])) {
 				BRASERO_PROJECT_OPEN_LIST (manager, brasero_project_manager_data, files, FALSE);
 			}
 		}



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