Re: [Rhythmbox-devel] Create playlist from library selection



On Thu, 2005-07-28 at 22:18 +0100, Ed Mack wrote:
> Getting the crasher bug removed is important though - I'm not fully
> aware of what to edit for that.

Attached is a slightly updated patch, which contains some fixes, so that
attempting to edit (some) uneditable playlists displays an error rather
than crashing. It doesn't handle unexpected properties/criteria yet -
but that doesn't matter for the purposes of creating playlists frm the
library selection. It could with a better error message though.

Also changed:
* the menu item uses RB_STOCK_AUTOMATIC_PLAYLIST, rather than
GTK_STOCK_NEW. The latter gives it a Ctrl-N shortcut, which is already
in use (by new playlist).
* the menu item is only enabled when you are viewing the library

> > Why not go the GtkFileChooser route - i.e. have a simple dialog with
> > perhaps a UI for a single filter, with an 'advanced' option to expand
> > the dialog into a more complex UI.
> 
> Here-here :)

Well, we still need to design a decent "advanced" UI.


Cheers,

James "Doc" Livingston 
-- 
If you treat the people around you with respect, they will never guess
that you're trying to stab them in the back
Index: data/ui/rhythmbox-ui.xml
===================================================================
RCS file: /cvs/gnome/rhythmbox/data/ui/rhythmbox-ui.xml,v
retrieving revision 1.20
diff -u -r1.20 rhythmbox-ui.xml
--- data/ui/rhythmbox-ui.xml	26 Jul 2005 14:07:28 -0000	1.20
+++ data/ui/rhythmbox-ui.xml	2 Aug 2005 16:37:53 -0000
@@ -7,6 +7,7 @@
       <separator/>
       <menu name="PlaylistMenu" action="Playlist">
 	<menuitem name="MusicPlaylistNewPlaylistMenu" action="MusicPlaylistNewPlaylist"/>
+	<menuitem name="MusicPlaylistNewReflectionPlaylistMenu" action="MusicPlaylistNewReflectionPlaylist"/>
 	<menuitem name="MusicPlaylistNewAutomaticPlaylistMenu" action="MusicPlaylistNewAutomaticPlaylist"/>
 	<menuitem name="MusicPlaylistLoadPlaylistMenu" action="MusicPlaylistLoadPlaylist"/>
 	<menuitem name="MusicPlaylistSavePlaylistMenu" action="MusicPlaylistSavePlaylist"/>
Index: shell/rb-playlist-manager.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/shell/rb-playlist-manager.c,v
retrieving revision 1.48
diff -u -r1.48 rb-playlist-manager.c
--- shell/rb-playlist-manager.c	19 Jun 2005 16:38:12 -0000	1.48
+++ shell/rb-playlist-manager.c	2 Aug 2005 16:38:00 -0000
@@ -70,6 +70,8 @@
 						  RBPlaylistManager *mgr);
 static void rb_playlist_manager_cmd_new_automatic_playlist (GtkAction *action,
 							    RBPlaylistManager *mgr);
+static void rb_playlist_manager_cmd_new_reflection_playlist (GtkAction *action,
+							     RBPlaylistManager *mgr);
 static void rb_playlist_manager_cmd_rename_playlist (GtkAction *action,
 						     RBPlaylistManager *mgr);
 static void rb_playlist_manager_cmd_delete_playlist (GtkAction *action,
@@ -143,6 +145,9 @@
 	{ "MusicPlaylistNewPlaylist", GTK_STOCK_NEW, N_("_New Playlist..."), "<control>N",
 	  N_("Create a new playlist"),
 	  G_CALLBACK (rb_playlist_manager_cmd_new_playlist) },
+	{ "MusicPlaylistNewReflectionPlaylist", RB_STOCK_AUTOMATIC_PLAYLIST, N_("New Automatic Playlist from _Selected Categories"), NULL,
+	  N_("Create a new automatic playlist from the selected categories"),
+	  G_CALLBACK (rb_playlist_manager_cmd_new_reflection_playlist) },
 	{ "MusicPlaylistNewAutomaticPlaylist", RB_STOCK_AUTOMATIC_PLAYLIST, N_("New _Automatic Playlist..."), NULL,
 	  N_("Create a new automatically updating playlist"),
 	  G_CALLBACK (rb_playlist_manager_cmd_new_automatic_playlist) },
@@ -475,6 +480,9 @@
 void
 rb_playlist_manager_set_source (RBPlaylistManager *mgr, RBSource *source)
 {
+	GtkAction *reflection_action = gtk_action_group_get_action (mgr->priv->actiongroup, "MusicPlaylistNewReflectionPlaylist");
+	gtk_action_set_sensitive (reflection_action, (source == RB_SOURCE (mgr->priv->libsource)));
+
 	g_return_if_fail (RB_IS_PLAYLIST_MANAGER (mgr));
 	g_return_if_fail (RB_IS_SOURCE (source));
 
@@ -735,6 +743,22 @@
 }
 
 static void
+rb_playlist_manager_cmd_new_reflection_playlist (GtkAction *action,
+						RBPlaylistManager *mgr)
+{
+	RBLibrarySource *source;
+	RBSource *playlist;
+	
+	playlist = rb_playlist_manager_new_playlist (mgr, NULL, TRUE);
+	
+	rb_playlist_source_set_query (RB_PLAYLIST_SOURCE (playlist),
+				                     rb_library_get_query (mgr->priv->libsource),
+				                     0, 0);
+
+	rb_playlist_manager_set_dirty (mgr);
+}
+
+static void
 rb_playlist_manager_cmd_new_automatic_playlist (GtkAction *action,
 						RBPlaylistManager *mgr)
 {
@@ -775,11 +799,19 @@
 								     query,
 								     limit_count,
 								     limit_size));	
+	if (creator != NULL) {
+		gtk_dialog_run (GTK_DIALOG (creator));
 
-	gtk_dialog_run (GTK_DIALOG (creator));
-
-	rb_playlist_manager_set_automatic_playlist (mgr, playlist, creator);
-	gtk_widget_destroy (GTK_WIDGET (creator));	
+		rb_playlist_manager_set_automatic_playlist (mgr, playlist, creator);
+		gtk_widget_destroy (GTK_WIDGET (creator));
+	} else {
+		/*
+		 * the query creator could not be started. this means that the
+		 * RB cannot edit this playlist
+		 */
+		rb_error_dialog (NULL, _("Cannot edit playlist"),
+				 _("This playlist cannot be edited in this version of Rhythmbox"));
+	}
 }
 
 static void
Index: sources/rb-library-source.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-library-source.c,v
retrieving revision 1.108
diff -u -r1.108 rb-library-source.c
--- sources/rb-library-source.c	23 Jul 2005 12:41:07 -0000	1.108
+++ sources/rb-library-source.c	2 Aug 2005 16:38:27 -0000
@@ -1458,6 +1458,11 @@
 	return query;
 }
 
+GPtrArray * rb_library_get_query (RBLibrarySource *source)
+{
+	return construct_query_from_selection (source);
+}
+
 static void
 rb_library_source_do_query (RBLibrarySource *source, RBLibraryQueryType qtype)
 {
Index: sources/rb-library-source.h
===================================================================
RCS file: /cvs/gnome/rhythmbox/sources/rb-library-source.h,v
retrieving revision 1.12
diff -u -r1.12 rb-library-source.h
--- sources/rb-library-source.h	10 Sep 2004 05:12:59 -0000	1.12
+++ sources/rb-library-source.h	2 Aug 2005 16:38:27 -0000
@@ -64,6 +64,8 @@
 void            rb_library_source_class_add_actions (RBShell *shell, 
 						     GtkActionGroup *uimgr);
 
+GPtrArray * rb_library_get_query (RBLibrarySource *source);
+
 G_END_DECLS
 
 #endif /* __RB_LIBRARY_SOURCE_H */
Index: widgets/rb-query-creator.c
===================================================================
RCS file: /cvs/gnome/rhythmbox/widgets/rb-query-creator.c,v
retrieving revision 1.29
diff -u -r1.29 rb-query-creator.c
--- widgets/rb-query-creator.c	25 Jul 2005 16:30:58 -0000	1.29
+++ widgets/rb-query-creator.c	2 Aug 2005 16:38:35 -0000
@@ -266,7 +266,6 @@
 
 	mainbox = glade_xml_get_widget (xml, "main_vbox");
 	gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dlg)->vbox), mainbox, FALSE, FALSE, 0);
-	gtk_widget_show_all (GTK_WIDGET (dlg));
 
 	return G_OBJECT (dlg);
 }
@@ -352,7 +351,7 @@
 	return g_object_new (RB_TYPE_QUERY_CREATOR, "db", db, NULL);
 }
 
-static void
+static gboolean
 rb_query_creator_load_query (RBQueryCreator *creator, GPtrArray *query,
 			     int limit_count, int limit_size)
 {
@@ -362,20 +361,15 @@
 	RhythmDBQueryData *qdata;
 	GPtrArray *subquery;
 
-	g_assert (query->len == 2);
+	/* the query creator can only edit querys of the form {type=SONG, subquery{...}} */
+	if (query->len != 2)
+		return FALSE;
 
 	qdata = g_ptr_array_index (query, 1);
-	g_assert (qdata->type == RHYTHMDB_QUERY_SUBQUERY);
+	if (qdata->type != RHYTHMDB_QUERY_SUBQUERY)
+		return FALSE;
 
 	subquery = qdata->subquery;
-
-	if (subquery->len > 0)
-		for (i = 0; i < subquery->len - 1; i++) {
-			RhythmDBQueryData *data = g_ptr_array_index (subquery, i);
-			if (data->type != RHYTHMDB_QUERY_DISJUNCTION)
-				append_row (creator);
-		}
-	
 	rows = creator->priv->rows;
 
 	for (i = 0; i < subquery->len; i++) {
@@ -387,15 +381,14 @@
 			disjunction = TRUE;
 			continue;
 		}
+		append_row (creator);
 
 		propmenu = GTK_OPTION_MENU (get_box_widget_at_pos (GTK_BOX (rows->data), 0));
-		
 		select_property_from_value (GTK_WIDGET (propmenu), property_options,
 					    G_N_ELEMENTS (property_options), data->propid);
 
 		criteria_menu = GTK_OPTION_MENU (get_box_widget_at_pos (GTK_BOX (rows->data),
 									1));
-
 		select_criteria_from_value (creator,
 					    GTK_WIDGET (criteria_menu), data->propid,
 					    data->type);
@@ -427,6 +420,8 @@
 		gtk_option_menu_set_history (GTK_OPTION_MENU (creator->priv->limit_option), 2);
 		gtk_spin_button_set_value (GTK_SPIN_BUTTON (creator->priv->limit_entry), limit_size / 1000);
 	}
+
+	return TRUE;
 }
 
 GtkWidget *
@@ -438,8 +433,13 @@
 	if (!creator)
 		return NULL;
 
-	rb_query_creator_load_query (creator, query, limit_count, limit_size);
-	return GTK_WIDGET (creator);
+	if (rb_query_creator_load_query (creator, query, limit_count, limit_size)) {
+		gtk_widget_show (GTK_WIDGET (creator));
+		return GTK_WIDGET (creator);
+	} else {
+		gtk_widget_destroy (GTK_WIDGET (creator));
+		return NULL;
+	}
 }
 
 static GtkWidget *

Attachment: signature.asc
Description: This is a digitally signed message part



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