brasero r721 - in trunk: . data src



Author: philippr
Date: Wed Apr 16 13:22:26 2008
New Revision: 721
URL: http://svn.gnome.org/viewvc/brasero?rev=721&view=rev

Log:
	Fix #516687 â Handle audio playlists
	Added possibility to save audio project as a playlist and open playlists as audio projects
	Fixed problems with building without totem-pl-parser

	* data/brasero.desktop.in.in:
	* src/brasero-audio-disc.c (brasero_audio_disc_new_row_cb):
	* src/brasero-io.c (brasero_io_get_file_count_process_file),
	(brasero_io_load_directory_thread):
	* src/brasero-project-manager.c
	(brasero_project_manager_open_project),
	(brasero_project_manager_open_playlist),
	(brasero_project_manager_open_by_mime),
	(brasero_project_manager_open_uri),
	(brasero_project_manager_open_cb),
	(brasero_project_manager_recent_clicked_cb),
	(brasero_project_manager_init):
	* src/brasero-project-manager.h:
	* src/brasero-project-type-chooser.c
	(brasero_project_type_chooser_recent_clicked_cb),
	(brasero_project_type_chooser_build_recent),
	(brasero_project_type_chooser_class_init):
	* src/brasero-project-type-chooser.h:
	* src/brasero-project.c (brasero_project_add_to_recents),
	(brasero_project_set_uri), (brasero_project_open_project),
	(brasero_project_playlist_entry_parsed),
	(brasero_project_open_audio_playlist_project),
	(brasero_project_open_playlist),
	(brasero_project_save_audio_playlist_entry),
	(brasero_project_save_audio_project_playlist),
	(brasero_project_save_project_real),
	(brasero_project_save_project_ask_for_path):
	* src/brasero-project.h:
	* src/main.c (brasero_app_recent_open), (brasero_app_add_recent),
	(brasero_app_parse_options), (main):

Modified:
   trunk/ChangeLog
   trunk/data/brasero.desktop.in.in
   trunk/src/brasero-audio-disc.c
   trunk/src/brasero-io.c
   trunk/src/brasero-project-manager.c
   trunk/src/brasero-project-manager.h
   trunk/src/brasero-project-type-chooser.c
   trunk/src/brasero-project-type-chooser.h
   trunk/src/brasero-project.c
   trunk/src/brasero-project.h
   trunk/src/main.c

Modified: trunk/data/brasero.desktop.in.in
==============================================================================
--- trunk/data/brasero.desktop.in.in	(original)
+++ trunk/data/brasero.desktop.in.in	Wed Apr 16 13:22:26 2008
@@ -6,7 +6,7 @@
 Encoding=UTF-8
 Exec=brasero %U
 Icon=brasero
-MimeType=application/x-cd-image;application/x-cdrdao-toc;application/x-toc;application/x-cue;application/x-brasero;
+MimeType=application/x-cd-image;application/x-cdrdao-toc;application/x-toc;application/x-cue;application/x-brasero;audio/x-scpls;audio/x-ms-asx;audio/x-mp3-playlist;audio/x-mpegurl;
 StartupNotify=true
 Terminal=false
 Type=Application
@@ -29,3 +29,8 @@
 Exec=brasero -p %u
 _Name=Open project
 
+[Desktop Action OpenPlaylist]
+Icon=brasero
+MimeType=audio/x-scpls;audio/x-ms-asx;audio/x-mp3-playlist;audio/x-mpegurl;
+Exec=brasero -l %u
+_Name=Open project

Modified: trunk/src/brasero-audio-disc.c
==============================================================================
--- trunk/src/brasero-audio-disc.c	(original)
+++ trunk/src/brasero-audio-disc.c	Wed Apr 16 13:22:26 2008
@@ -1498,7 +1498,6 @@
 			       gpointer user_data)
 {
 	GtkTreeIter iter;
-	const gchar *mime;
 	GtkTreeModel *model;
 	GtkTreeIter gap_iter;
 	GtkTreePath *treepath;
@@ -1537,6 +1536,8 @@
 
 #if BUILD_PLAYLIST
 
+	const gchar *mime;
+
 	/* see if it a playlist */
 	mime = g_file_info_get_content_type (info);
 	if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR

Modified: trunk/src/brasero-io.c
==============================================================================
--- trunk/src/brasero-io.c	(original)
+++ trunk/src/brasero-io.c	Wed Apr 16 13:22:26 2008
@@ -1042,6 +1042,8 @@
 	brasero_io_job_free (callback_data);
 }
 
+#ifdef BUILD_PLAYLIST
+
 static gboolean
 brasero_io_get_file_count_process_playlist (BraseroIO *self,
 					    GCancellable *cancel,
@@ -1084,6 +1086,8 @@
 	return TRUE;
 }
 
+#endif 
+
 static void
 brasero_io_get_file_count_process_file (BraseroIO *self,
 					GCancellable *cancel,
@@ -1106,6 +1110,9 @@
 
 		if (result)
 			data->total_b += metadata.len;
+
+#ifdef BUILD_PLAYLIST
+
 		/* see if that's a playlist (and if we have recursive on). */
 		else if (data->job.options & BRASERO_IO_INFO_RECURSIVE) {
 			const gchar *mime;
@@ -1122,6 +1129,9 @@
 
 			data->files_invalid ++;
 		}
+
+#endif
+
 		else
 			data->files_invalid ++;
 
@@ -1351,6 +1361,8 @@
 	brasero_io_job_free (BRASERO_IO_JOB (data));
 }
 
+#ifdef BUILD_PLAYLIST
+
 static gboolean
 brasero_io_load_directory_playlist (BraseroIO *self,
 				    GCancellable *cancel,
@@ -1412,6 +1424,8 @@
 	return TRUE;
 }
 
+#endif
+
 static BraseroAsyncTaskResult
 brasero_io_load_directory_thread (BraseroAsyncTaskManager *manager,
 				  GCancellable *cancel,
@@ -1544,6 +1558,9 @@
 
 			if (result)
 				brasero_io_set_metadata_attributes (info, &metadata);
+
+#ifdef BUILD_PLAYLIST
+
 			else if (data->job.options & BRASERO_IO_INFO_RECURSIVE) {
 				const gchar *mime;
 
@@ -1560,6 +1577,8 @@
 									    attributes);
 			}
 
+#endif
+
 			brasero_metadata_info_clear (&metadata);
 		}
 

Modified: trunk/src/brasero-project-manager.c
==============================================================================
--- trunk/src/brasero-project-manager.c	(original)
+++ trunk/src/brasero-project-manager.c	Wed Apr 16 13:22:26 2008
@@ -628,27 +628,6 @@
 	brasero_project_manager_switch (manager, BRASERO_PROJECT_TYPE_ISO, NULL, NULL, TRUE);
 }
 
-static void
-brasero_project_manager_open_cb (GtkAction *action, BraseroProjectManager *manager)
-{
-	BraseroProjectType type;
-
-	type = brasero_project_open_project (BRASERO_PROJECT (manager->priv->project), NULL);
-	if (type == BRASERO_PROJECT_TYPE_INVALID)
-		return;
-
-	manager->priv->type = type;
-
-	if (type == BRASERO_PROJECT_TYPE_DATA)
-		brasero_layout_load (BRASERO_LAYOUT (manager->priv->layout), BRASERO_LAYOUT_DATA);
-	else
-		brasero_layout_load (BRASERO_LAYOUT (manager->priv->layout), BRASERO_LAYOUT_AUDIO);
-	gtk_notebook_set_current_page (GTK_NOTEBOOK (manager), 1);
-
-	action = gtk_action_group_get_action (manager->priv->action_group, "NewChoose");
-	gtk_action_set_sensitive (action, TRUE);
-}
-
 void
 brasero_project_manager_audio (BraseroProjectManager *manager, GSList *uris)
 {
@@ -681,16 +660,9 @@
 	brasero_project_manager_switch (manager, BRASERO_PROJECT_TYPE_ISO, NULL, uri, TRUE);
 }
 
-static void
-brasero_project_manager_uri_clicked_cb (BraseroProjectTypeChooser *chooser,
-					const gchar *uri,
-					BraseroProjectManager *manager)
-{
-	brasero_project_manager_switch (manager, BRASERO_PROJECT_TYPE_ISO, NULL, uri, TRUE);
-}
-
-void
-brasero_project_manager_open (BraseroProjectManager *manager, const gchar *uri)
+BraseroProjectType
+brasero_project_manager_open_project (BraseroProjectManager *manager,
+				      const gchar *uri)
 {
 	BraseroProjectType type;
 	GtkAction *action;
@@ -703,7 +675,7 @@
 
     	if (type == BRASERO_PROJECT_TYPE_INVALID) {
 		brasero_project_manager_switch (manager, BRASERO_PROJECT_TYPE_INVALID, NULL, NULL, TRUE);
-		return;
+		return BRASERO_PROJECT_TYPE_INVALID;
 	}
 
 	if (type == BRASERO_PROJECT_TYPE_DATA)
@@ -713,14 +685,136 @@
 
 	action = gtk_action_group_get_action (manager->priv->action_group, "NewChoose");
 	gtk_action_set_sensitive (action, TRUE);
+
+	return type;
+}
+
+#ifdef BUILD_PLAYLIST
+
+BraseroProjectType
+brasero_project_manager_open_playlist (BraseroProjectManager *manager,
+				       const gchar *uri)
+{
+	BraseroProjectType type;
+	GtkAction *action;
+
+    	gtk_widget_show (manager->priv->layout);
+	gtk_notebook_set_current_page (GTK_NOTEBOOK (manager), 1);
+	type = brasero_project_open_playlist (BRASERO_PROJECT (manager->priv->project), uri);
+	manager->priv->type = type;
+
+    	if (type == BRASERO_PROJECT_TYPE_INVALID) {
+		brasero_project_manager_switch (manager, BRASERO_PROJECT_TYPE_INVALID, NULL, NULL, TRUE);
+		return BRASERO_PROJECT_TYPE_INVALID;
+	}
+
+	brasero_layout_load (BRASERO_LAYOUT (manager->priv->layout), BRASERO_LAYOUT_AUDIO);
+	action = gtk_action_group_get_action (manager->priv->action_group, "NewChoose");
+	gtk_action_set_sensitive (action, TRUE);
+
+	return BRASERO_PROJECT_TYPE_AUDIO;
+}
+
+#endif
+
+BraseroProjectType
+brasero_project_manager_open_by_mime (BraseroProjectManager *manager,
+				      const gchar *uri,
+				      const gchar *mime)
+{
+	if (!strcmp (mime, "application/x-brasero"))
+		return brasero_project_manager_open_project (manager, uri);
+
+#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_playlist (manager, uri);
+#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;
+	const gchar *mime;
+	BraseroProjectType type;
+
+	/* FIXME: make that asynchronous */
+	file = g_file_new_for_commandline_arg (uri_arg);
+	info = g_file_query_info (file,
+				  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
+				  G_FILE_QUERY_INFO_NONE,
+				  NULL,
+				  NULL);
+
+	uri = g_file_get_uri (file);
+	mime = g_file_info_get_content_type (info);
+
+	type = brasero_project_manager_open_by_mime (manager, uri, mime);
+
+	g_free (uri);
+	g_object_unref (file);
+	g_object_unref (info);
+
+	return type;
 }
 
 static void
-brasero_project_manager_project_clicked_cb (BraseroProjectTypeChooser *chooser,
-					    const gchar *uri,
-					    BraseroProjectManager *manager)
+brasero_project_manager_open_cb (GtkAction *action, BraseroProjectManager *manager)
 {
-	brasero_project_manager_open (manager, uri);
+	gchar *uri;
+	gint answer;
+	GtkWidget *chooser;
+	GtkWidget *toplevel;
+	BraseroProjectType type;
+
+	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (manager));
+	chooser = gtk_file_chooser_dialog_new (_("Open a project"),
+					      GTK_WINDOW (toplevel),
+					      GTK_FILE_CHOOSER_ACTION_OPEN,
+					      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+					      GTK_STOCK_OPEN, GTK_RESPONSE_OK,
+					      NULL);
+	gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), TRUE);
+	gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
+					     g_get_home_dir ());
+	
+	gtk_widget_show (chooser);
+	answer = gtk_dialog_run (GTK_DIALOG (chooser));
+	if (answer != GTK_RESPONSE_OK) {
+		gtk_widget_destroy (chooser);
+		return;
+	}
+
+	uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
+	gtk_widget_destroy (chooser);
+
+	type = brasero_project_manager_open_uri (manager, uri);
+	g_free (uri);
+}
+
+static void
+brasero_project_manager_recent_clicked_cb (BraseroProjectTypeChooser *chooser,
+					   const gchar *uri,
+					   BraseroProjectManager *manager)
+{
+	brasero_project_manager_open_uri (manager, uri);
 }
 
 void
@@ -806,12 +900,8 @@
 			  G_CALLBACK (brasero_project_manager_type_changed_cb),
 			  obj);
 	g_signal_connect (type,
-			  "uri-clicked",
-			  G_CALLBACK (brasero_project_manager_uri_clicked_cb),
-			  obj);
-	g_signal_connect (type,
-			  "project-clicked",
-			  G_CALLBACK (brasero_project_manager_project_clicked_cb),
+			  "recent-clicked",
+			  G_CALLBACK (brasero_project_manager_recent_clicked_cb),
 			  obj);
 	gtk_notebook_prepend_page (GTK_NOTEBOOK (obj), type, NULL);
 

Modified: trunk/src/brasero-project-manager.h
==============================================================================
--- trunk/src/brasero-project-manager.h	(original)
+++ trunk/src/brasero-project-manager.h	Wed Apr 16 13:22:26 2008
@@ -31,6 +31,8 @@
 #include <gtk/gtknotebook.h>
 #include <gtk/gtkuimanager.h>
 
+#include "brasero-project-type-chooser.h"
+
 G_BEGIN_DECLS
 
 #define BRASERO_TYPE_PROJECT_MANAGER         (brasero_project_manager_get_type ())
@@ -54,7 +56,6 @@
 GType brasero_project_manager_get_type ();
 GtkWidget *brasero_project_manager_new ();
 
-
 void
 brasero_project_manager_audio (BraseroProjectManager *manager, GSList *uris);
 void
@@ -63,8 +64,22 @@
 brasero_project_manager_copy (BraseroProjectManager *manager);
 void
 brasero_project_manager_iso (BraseroProjectManager *manager, const gchar *uri);
-void
-brasero_project_manager_open (BraseroProjectManager *manager, const gchar *uri);
+
+BraseroProjectType
+brasero_project_manager_open_playlist (BraseroProjectManager *manager, const gchar *uri);
+
+BraseroProjectType
+brasero_project_manager_open_project (BraseroProjectManager *manager, const gchar *uri);
+
+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);
 

Modified: trunk/src/brasero-project-type-chooser.c
==============================================================================
--- trunk/src/brasero-project-type-chooser.c	(original)
+++ trunk/src/brasero-project-type-chooser.c	Wed Apr 16 13:22:26 2008
@@ -46,8 +46,7 @@
 G_DEFINE_TYPE (BraseroProjectTypeChooser, brasero_project_type_chooser, GTK_TYPE_EVENT_BOX);
 
 typedef enum {
-	PROJECT_CLICKED_SIGNAL,
-	URI_CLICKED_SIGNAL,
+	RECENT_CLICKED_SIGNAL,
 	CHOSEN_SIGNAL,
 	LAST_SIGNAL
 } BraseroProjectTypeChooserSignalType;
@@ -170,27 +169,14 @@
 }
 
 static void
-brasero_project_type_chooser_uri_clicked_cb (GtkButton *button,
-					     BraseroProjectTypeChooser *self)
-{
-	const gchar *uri;
-
-	uri = gtk_link_button_get_uri (GTK_LINK_BUTTON (button));
-	g_signal_emit (self,
-		       brasero_project_type_chooser_signals [URI_CLICKED_SIGNAL],
-		       0,
-		       uri);
-}
-
-static void
-brasero_project_type_chooser_project_clicked_cb (GtkButton *button,
-						 BraseroProjectTypeChooser *self)
+brasero_project_type_chooser_recent_clicked_cb (GtkButton *button,
+						BraseroProjectTypeChooser *self)
 {
 	const gchar *uri;
 
 	uri = gtk_link_button_get_uri (GTK_LINK_BUTTON (button));
 	g_signal_emit (self,
-		       brasero_project_type_chooser_signals [PROJECT_CLICKED_SIGNAL],
+		       brasero_project_type_chooser_signals [RECENT_CLICKED_SIGNAL],
 		       0,
 		       uri);
 }
@@ -236,7 +222,11 @@
 		&&  strcmp (mime, "application/x-cd-image")
 		&&  strcmp (mime, "application/x-cdrdao-toc")
 		&&  strcmp (mime, "application/x-toc")
-		&&  strcmp (mime, "application/x-cue"))
+		&&  strcmp (mime, "application/x-cue")
+		&&  strcmp (mime, "audio/x-scpls")
+		&&  strcmp (mime, "audio/x-ms-asx")
+		&&  strcmp (mime, "audio/x-mp3-playlist")
+		&&  strcmp (mime, "audio/x-mpegurl"))
 			continue;
 
 		/* sort */
@@ -282,16 +272,10 @@
 		link = gtk_link_button_new_with_label (uri, name);
 		gtk_button_set_focus_on_click (GTK_BUTTON (link), FALSE);
 		gtk_button_set_image (GTK_BUTTON (link), image);
-		if (strcmp (gtk_recent_info_get_mime_type (info), "application/x-brasero"))
-			g_signal_connect (link,
-					  "clicked",
-					  G_CALLBACK (brasero_project_type_chooser_uri_clicked_cb),
-					  self);
-		else
-			g_signal_connect (link,
-					  "clicked",
-					  G_CALLBACK (brasero_project_type_chooser_project_clicked_cb),
-					  self);
+		g_signal_connect (link,
+				  "clicked",
+				  G_CALLBACK (brasero_project_type_chooser_recent_clicked_cb),
+				  self);
 
 		gtk_widget_show (link);
 		gtk_widget_set_tooltip_text (link, tooltip);
@@ -496,19 +480,10 @@
 			  G_TYPE_NONE,
 			  1,
 			  G_TYPE_UINT);
-	brasero_project_type_chooser_signals[URI_CLICKED_SIGNAL] =
-	    g_signal_new ("uri_clicked", G_OBJECT_CLASS_TYPE (object_class),
-			  G_SIGNAL_ACTION | G_SIGNAL_RUN_FIRST,
-			  G_STRUCT_OFFSET (BraseroProjectTypeChooserClass, uri_clicked),
-			  NULL, NULL,
-			  g_cclosure_marshal_VOID__STRING,
-			  G_TYPE_NONE,
-			  1,
-			  G_TYPE_STRING);
-	brasero_project_type_chooser_signals[PROJECT_CLICKED_SIGNAL] =
-	    g_signal_new ("project_clicked", G_OBJECT_CLASS_TYPE (object_class),
+	brasero_project_type_chooser_signals[RECENT_CLICKED_SIGNAL] =
+	    g_signal_new ("recent_clicked", G_OBJECT_CLASS_TYPE (object_class),
 			  G_SIGNAL_ACTION | G_SIGNAL_RUN_FIRST,
-			  G_STRUCT_OFFSET (BraseroProjectTypeChooserClass, project_clicked),
+			  G_STRUCT_OFFSET (BraseroProjectTypeChooserClass, recent_clicked),
 			  NULL, NULL,
 			  g_cclosure_marshal_VOID__STRING,
 			  G_TYPE_NONE,

Modified: trunk/src/brasero-project-type-chooser.h
==============================================================================
--- trunk/src/brasero-project-type-chooser.h	(original)
+++ trunk/src/brasero-project-type-chooser.h	Wed Apr 16 13:22:26 2008
@@ -56,9 +56,7 @@
 typedef struct {
 	GtkEventBoxClass parent_class;
 
-	void	(*project_clicked)	(BraseroProjectTypeChooser *chooser,
-					 const gchar *uri);
-	void	(*uri_clicked)		(BraseroProjectTypeChooser *chooser,
+	void	(*recent_clicked)	(BraseroProjectTypeChooser *chooser,
 					 const gchar *uri);
 	void	(*chosen)		(BraseroProjectTypeChooser *chooser,
 					 BraseroProjectType type);

Modified: trunk/src/brasero-project.c
==============================================================================
--- trunk/src/brasero-project.c	(original)
+++ trunk/src/brasero-project.c	Wed Apr 16 13:22:26 2008
@@ -32,6 +32,8 @@
 #include <glib/gstdio.h>
 #include <glib/gi18n.h>
 
+#include <gio/gio.h>
+
 #include <gtk/gtknotebook.h>
 #include <gtk/gtkscrolledwindow.h>
 #include <gtk/gtkfilechooser.h>
@@ -51,6 +53,10 @@
 
 #include <gconf/gconf-client.h>
 
+#ifdef BUILD_PLAYLIST
+#include <totem-pl-parser.h>
+#endif
+
 #include "burn-debug.h"
 #include "burn-session.h"
 #include "brasero-project.h"
@@ -130,8 +136,12 @@
 				gint *footer);
 
 typedef enum {
-	BRASERO_PROJECT_SAVE_XML	= 0,
-	BRASERO_PROJECT_SAVE_PLAIN	= 1
+	BRASERO_PROJECT_SAVE_XML			= 0,
+	BRASERO_PROJECT_SAVE_PLAIN			= 1,
+	BRASERO_PROJECT_SAVE_PLAYLIST_PLS		= 2,
+	BRASERO_PROJECT_SAVE_PLAYLIST_M3U		= 3,
+	BRASERO_PROJECT_SAVE_PLAYLIST_XSPF		= 4,
+	BRASERO_PROJECT_SAVE_PLAYLIST_IRIVER_PLA	= 5
 } BraseroProjectSave;
 
 struct BraseroProjectPrivate {
@@ -1575,27 +1585,41 @@
 }
 
 /******************************* common to save/open ***************************/
+
 static void
-brasero_project_set_uri (BraseroProject *project,
-			 const gchar *uri,
-			 BraseroProjectType type)
+brasero_project_add_to_recents (BraseroProject *project,
+				const gchar *uri,
+				gboolean is_project)
 {
-     	gchar *name;
-	gchar *title;
-	gchar *groups [] = { "brasero", NULL };
-	GtkAction *action;
-	GtkWidget *toplevel;
    	GtkRecentManager *recent;
+	gchar *groups [] = { "brasero", NULL };
+	gchar *open_playlist = "brasero -l %u";
 	GtkRecentData recent_data = { NULL,
 				      NULL,
-
 				      "application/x-brasero",
-
 				      "brasero",
 				      "brasero -p %u",
 				      groups,
 				      FALSE };
 
+    	recent = gtk_recent_manager_get_default ();
+
+	if (is_project)
+		recent_data.app_exec = open_playlist;
+
+    	gtk_recent_manager_add_full (recent, uri, &recent_data);
+}
+
+static void
+brasero_project_set_uri (BraseroProject *project,
+			 const gchar *uri,
+			 BraseroProjectType type)
+{
+     	gchar *name;
+	gchar *title;
+	GtkAction *action;
+	GtkWidget *toplevel;
+
 	/* possibly reset the name of the project */
 	if (uri) {
 		if (project->priv->project)
@@ -1607,8 +1631,7 @@
 	uri = uri ? uri : project->priv->project;
 
     	/* add it to recent manager */
-    	recent = gtk_recent_manager_get_default ();
-    	gtk_recent_manager_add_full (recent, uri, &recent_data);
+    	brasero_project_add_to_recents (project, uri, TRUE);
 
 	/* update the name of the main window */
     	BRASERO_GET_BASENAME_FOR_DISPLAY (uri, name);
@@ -1986,48 +2009,17 @@
 
 BraseroProjectType
 brasero_project_open_project (BraseroProject *project,
-			      const gchar *escaped_uri)
+			      const gchar *uri)	/* escaped */
 {
 	BraseroDiscTrack *track = NULL;
 	BraseroProjectType type;
-	GtkWidget *toplevel;
-    	gchar *uri;
 
-	if (!escaped_uri) {
-		GtkWidget *chooser;
-		gint answer;
-
-		toplevel = gtk_widget_get_toplevel (GTK_WIDGET (project));
-		chooser = gtk_file_chooser_dialog_new (_("Open a project"),
-						      GTK_WINDOW (toplevel),
-						      GTK_FILE_CHOOSER_ACTION_OPEN,
-						      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
-						      GTK_STOCK_OPEN, GTK_RESPONSE_OK,
-						      NULL);
-		gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser), TRUE);
-		gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (chooser),
-						     g_get_home_dir ());
-	
-		gtk_widget_show (chooser);
-		answer = gtk_dialog_run (GTK_DIALOG (chooser));
-	
-		if (answer == GTK_RESPONSE_OK)
-			uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (chooser));
-		else
-			uri = NULL;
-	
-		gtk_widget_destroy (chooser);
-	}
-	else
-		uri = g_strdup (escaped_uri);
 
 	if (!uri || *uri =='\0')
 		return BRASERO_PROJECT_TYPE_INVALID;
- 
-	if (!brasero_project_open_project_xml (project, uri, &track, TRUE)) {
-		g_free (uri);
+
+	if (!brasero_project_open_project_xml (project, uri, &track, TRUE))
 		return BRASERO_PROJECT_TYPE_INVALID;
-	}
 
 	brasero_project_size_set_sectors (BRASERO_PROJECT_SIZE (project->priv->size_display),
 					  0);
@@ -2041,7 +2033,6 @@
 		type = BRASERO_PROJECT_TYPE_DATA;
 	}
 	else {
-	    	g_free (uri);
 		brasero_track_free (track);
 		return BRASERO_PROJECT_TYPE_INVALID;
 	}
@@ -2052,10 +2043,96 @@
 	project->priv->modified = 0;
 
 	brasero_project_set_uri (project, uri, type);
-    	g_free (uri);
 	return type;
 }
 
+#ifdef BUILD_PLAYLIST
+
+static void
+brasero_project_playlist_entry_parsed (TotemPlParser *parser,
+				       const gchar *uri,
+				       GHashTable *metadata,
+				       gpointer user_data)
+{
+	BraseroDiscTrack *track = user_data;
+	BraseroDiscSong *song;
+
+	song = g_new0 (BraseroDiscSong, 1);
+	song->uri = g_strdup (uri);
+
+	/* to know if this info was set or not */
+	song->start = -1;
+	song->end = -1;
+	track->contents.tracks = g_slist_prepend (track->contents.tracks, song);
+}
+
+static gboolean
+brasero_project_open_audio_playlist_project (BraseroProject *proj,
+					     const gchar *uri,
+					     BraseroDiscTrack **track,
+					     gboolean warn_user)
+{
+	TotemPlParser *parser;
+	TotemPlParserResult result;
+	BraseroDiscTrack *new_track;
+
+	new_track = g_new0 (BraseroDiscTrack, 1);
+	new_track->type = BRASERO_DISC_TRACK_AUDIO;
+
+	parser = totem_pl_parser_new ();
+	g_object_set (parser,
+		      "recurse", FALSE,
+		      "disable-unsafe", TRUE,
+		      NULL);
+
+	g_signal_connect (parser,
+			  "entry-parsed",
+			  G_CALLBACK (brasero_project_playlist_entry_parsed),
+			  new_track);
+
+	result = totem_pl_parser_parse (parser, uri, FALSE);
+	if (result != TOTEM_PL_PARSER_RESULT_SUCCESS) {
+		if (warn_user)
+			brasero_project_invalid_project_dialog (proj, _("it doesn't seem to be a valid brasero project."));
+
+		brasero_track_free (new_track);
+	}
+	else
+		*track = new_track;
+
+	g_object_unref (parser);
+
+	return (result == TOTEM_PL_PARSER_RESULT_SUCCESS);
+}
+
+BraseroProjectType
+brasero_project_open_playlist (BraseroProject *project,
+			       const gchar *uri) /* escaped */
+{
+	BraseroDiscTrack *track = NULL;
+	BraseroProjectType type;
+
+	if (!uri || *uri =='\0')
+		return BRASERO_PROJECT_TYPE_INVALID;
+
+	if (!brasero_project_open_audio_playlist_project (project, uri, &track, TRUE))
+		return BRASERO_PROJECT_TYPE_INVALID;
+
+	brasero_project_size_set_sectors (BRASERO_PROJECT_SIZE (project->priv->size_display), 0);
+	brasero_project_switch (project, TRUE);
+	type = BRASERO_PROJECT_TYPE_AUDIO;
+
+	brasero_disc_load_track (project->priv->current, track);
+	brasero_track_free (track);
+
+	brasero_project_add_to_recents (project, uri, FALSE);
+	project->priv->modified = 0;
+
+	return type;
+}
+
+#endif
+
 BraseroProjectType
 brasero_project_load_session (BraseroProject *project, const gchar *uri)
 {
@@ -2485,6 +2562,100 @@
 	return FALSE;
 }
 
+#ifdef BUILD_PLAYLIST
+
+static void
+brasero_project_save_audio_playlist_entry (GtkTreeModel *model,
+					   GtkTreeIter *iter,
+					   gchar **uri,
+					   gchar **title,
+					   gboolean *custom_title,
+					   gpointer user_data)
+{
+	gtk_tree_model_get (model, iter,
+			    0, uri,
+			    1, title,
+			    2, custom_title,
+			    -1);
+}
+
+static gboolean
+brasero_project_save_audio_project_playlist (BraseroProject *proj,
+					     const gchar *uri,
+					     BraseroProjectSave type,
+					     BraseroDiscTrack *track,
+					     gboolean use_dialog)
+{
+	TotemPlParserType pl_type;
+	TotemPlParser *parser;
+	GtkListStore *model;
+	GtkTreeIter t_iter;
+	gboolean result;
+	GSList *iter;
+	gchar *path;
+
+    	path = g_filename_from_uri (uri, NULL, NULL);
+    	if (!path)
+		return FALSE;
+
+	parser = totem_pl_parser_new ();
+
+	/* create and populate treemodel */
+	model = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN);
+	for (iter = track->contents.tracks; iter; iter = iter->next) {
+		BraseroDiscSong *song;
+		BraseroSongInfo *info;
+
+		song = iter->data;
+		info = song->info;
+
+		gtk_list_store_append (model, &t_iter);
+		gtk_list_store_set (model, &t_iter,
+				    0, song->uri,
+				    1, info->title,
+				    2, TRUE,
+				    -1);
+	}
+
+	switch (type) {
+		case BRASERO_PROJECT_SAVE_PLAYLIST_M3U:
+			pl_type = TOTEM_PL_PARSER_M3U;
+			break;
+		case BRASERO_PROJECT_SAVE_PLAYLIST_XSPF:
+			pl_type = TOTEM_PL_PARSER_XSPF;
+			break;
+		case BRASERO_PROJECT_SAVE_PLAYLIST_IRIVER_PLA:
+			pl_type = TOTEM_PL_PARSER_IRIVER_PLA;
+			break;
+
+		case BRASERO_PROJECT_SAVE_PLAYLIST_PLS:
+		default:
+			pl_type = TOTEM_PL_PARSER_PLS;
+			break;
+	}
+
+	result = totem_pl_parser_write (parser,
+					GTK_TREE_MODEL (model),
+					brasero_project_save_audio_playlist_entry,
+					path,
+					pl_type,
+					NULL,
+					NULL);
+	if (!result && use_dialog)
+		brasero_project_not_saved_dialog (proj);
+
+	if (result)
+		brasero_project_add_to_recents (proj, uri, FALSE);
+
+	g_object_unref (model);
+	g_object_unref (parser);
+	g_free (path);
+
+	return result;
+}
+
+#endif
+
 static gboolean
 brasero_project_save_project_real (BraseroProject *project,
 				   const gchar *uri,
@@ -2525,7 +2696,6 @@
 		project->priv->modified = 0;
 	}
 	else if (save_type == BRASERO_PROJECT_SAVE_PLAIN) {
-		brasero_project_set_uri (project, uri, track.type);
 		if (!brasero_project_save_audio_project_plain_text (project,
 								    uri,
 								    &track,
@@ -2533,6 +2703,19 @@
 			return FALSE;
 	}
 
+#ifdef BUILD_PLAYLIST
+
+	else {
+		if (!brasero_project_save_audio_project_playlist (project,
+								  uri,
+								  save_type,
+								  &track,
+								  TRUE))
+			return FALSE;
+	}
+
+#endif
+
 	brasero_track_clear (&track);
 	return TRUE;
 }
@@ -2568,8 +2751,17 @@
 
 		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as brasero audio project"));
 		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as a plain text list"));
-		gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
 
+#ifdef BUILD_PLAYLIST
+
+		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as a PLS playlist"));
+		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as an M3U playlist"));
+		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as a XSPF playlist"));
+		gtk_combo_box_append_text (GTK_COMBO_BOX (combo), _("Save project as an IRIVER playlist"));
+
+#endif
+
+		gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
 		gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (chooser), combo);
 	}
 

Modified: trunk/src/brasero-project.h
==============================================================================
--- trunk/src/brasero-project.h	(original)
+++ trunk/src/brasero-project.h	Wed Apr 16 13:22:26 2008
@@ -77,7 +77,13 @@
 			    BraseroURIContainer *source);
 
 BraseroProjectType
-brasero_project_open_project (BraseroProject *project, const gchar *uri);
+brasero_project_open_playlist (BraseroProject *project,
+			       const gchar *uri);
+
+BraseroProjectType
+brasero_project_open_project (BraseroProject *project,
+			      const gchar *uri);
+
 gboolean
 brasero_project_save_project (BraseroProject *project);
 gboolean

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	(original)
+++ trunk/src/main.c	Wed Apr 16 13:22:26 2008
@@ -62,6 +62,7 @@
 
 static GConfClient *client;
 gchar *project_uri;
+gchar *playlist_uri;
 gchar *iso_uri;
 gchar **files;
 gchar **audio_project;
@@ -78,6 +79,14 @@
 	  N_("Open the specified project"),
 	  N_("PROJECT") },
 
+#ifdef BUILD_PLAYLIST
+
+	 { "playlist", 'l', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_STRING, &playlist_uri,
+	  N_("Open the specified playlist as an audio project"),
+	  N_("PLAYLIST") },
+
+#endif
+
 	{ "audio", 'a', 0, G_OPTION_ARG_NONE, &audio_project,
 	  N_("Open an audio project adding the URIs given on the command line"),
 	  NULL },
@@ -366,22 +375,7 @@
 		return;
 	}
 
-	if (!strcmp (mime, "application/x-brasero")) {
-		BRASERO_PROJECT_OPEN_URI (app,
-					  brasero_project_manager_open,
-					  gtk_recent_info_get_uri (item));
-	}
-    	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_OPEN_URI (app,
-					  brasero_project_manager_iso,
-					  gtk_recent_info_get_uri (item));
-	}
-	else
-		g_warning ("Unknown type of file can't open");
-
+	brasero_project_manager_open_by_mime (BRASERO_PROJECT_MANAGER (app->contents), uri, mime);
 	gtk_recent_info_unref (item);
 }
 
@@ -407,6 +401,11 @@
 	gtk_recent_filter_add_mime_type (filter, "application/x-cdrdao-toc");
 	gtk_recent_filter_add_mime_type (filter, "application/x-toc");
 	gtk_recent_filter_add_mime_type (filter, "application/x-cue");
+	gtk_recent_filter_add_mime_type (filter, "audio/x-scpls");
+	gtk_recent_filter_add_mime_type (filter, "audio/x-ms-asx");
+	gtk_recent_filter_add_mime_type (filter, "audio/x-mp3-playlist");
+	gtk_recent_filter_add_mime_type (filter, "audio/x-mpegurl");
+
 	gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (action), filter);
 	gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (action), filter);
 
@@ -599,6 +598,8 @@
 		nb ++;
 	if (project_uri)
 		nb ++;
+	if (playlist_uri)
+		nb ++;
 	if (audio_project)
 		nb ++;
 	if (data_project)
@@ -635,8 +636,17 @@
 		BRASERO_PROJECT_OPEN_URI (app, brasero_project_manager_iso, iso_uri);
 	}
 	else if (project_uri) {
-		BRASERO_PROJECT_OPEN_URI (app, brasero_project_manager_open, project_uri);
+		BRASERO_PROJECT_OPEN_URI (app, brasero_project_manager_open_project, project_uri);
+	}
+
+#ifdef BUILD_PLAYLIST
+
+	else if (playlist_uri) {
+		BRASERO_PROJECT_OPEN_URI (app, brasero_project_manager_open_playlist, playlist_uri);
 	}
+
+#endif
+
 	else if (audio_project) {
 		BRASERO_PROJECT_OPEN_LIST (app, brasero_project_manager_audio, files);
 	}
@@ -668,42 +678,13 @@
 		g_slist_free (list);
 	}
 	else if (files) {
-		const gchar *mime;
-		GFileInfo *info;
-		GFile *file;
+		BraseroProjectType type;
 
 	    	if (g_strv_length (files) > 1)
 			BRASERO_PROJECT_OPEN_LIST (app, brasero_project_manager_data, files);
 
-		/* we need to determine what type of file it is */
-		file = g_file_new_for_commandline_arg (files [0]);
-		info = g_file_query_info (file,
-					  G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
-					  G_FILE_QUERY_INFO_NONE,
-					  NULL,
-					  NULL);
-		g_object_unref (file);
-
-		mime = g_file_info_get_content_type (info);
-	    	g_object_unref (info);
-
-		if (mime) {
-			if (!strcmp (mime, "application/x-brasero")) {
-				BRASERO_PROJECT_OPEN_URI (app, brasero_project_manager_open, files [0]);
-			}
-			else if (!strcmp (mime, "application/x-cue")
-			     ||  !strcmp (mime, "application/x-toc")
-			     ||  !strcmp (mime, "application/x-cdrdao-toc")
-			     ||  !strcmp (mime, "application/x-cd-image")
-			     ||  !strcmp (mime, "application/octet-stream")) {
-				BRASERO_PROJECT_OPEN_URI (app, brasero_project_manager_iso, files [0]);
-			}
-			else {
-				/* open it in a data project */
-				BRASERO_PROJECT_OPEN_LIST (app, brasero_project_manager_data, files);
-			}
-		}
-		else
+		type = brasero_project_manager_open_uri (BRASERO_PROJECT_MANAGER (app->contents), files [0]);
+		if (type == BRASERO_PROJECT_TYPE_INVALID)
 			BRASERO_PROJECT_OPEN_LIST (app, brasero_project_manager_data, files);
 	}
 	else {
@@ -765,7 +746,6 @@
 
 	gtk_widget_show (app->mainwin);
 
-	/* debug */
 	gtk_main ();
 
 	brasero_burn_library_shutdown ();



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