[Banshee-List] Add Artist/Album to playlist
- From: Markus Jonsson <marjo691 student liu se>
- To: banshee-list gnome org
- Subject: [Banshee-List] Add Artist/Album to playlist
- Date: Sun, 13 Nov 2005 23:21:42 +0100
Hello People
I created a little something that adds two entries to the track context
menu. The first is "Add Artist To Playlist" which is adds all tracks
with a specified artist to the specified playlist. And the other one is
"Add Album To Playlist" which does dito for albums.
Take a look at it and say what you think.
Find an attached patch.
Cheers
--Markus, aka m6
Index: banshee/data/glade/player.glade
===================================================================
RCS file: /cvs/gnome/banshee/data/glade/player.glade,v
retrieving revision 1.31
diff -u -p -r1.31 player.glade
--- banshee/data/glade/player.glade 11 Nov 2005 19:23:13 -0000 1.31
+++ banshee/data/glade/player.glade 13 Nov 2005 22:03:04 -0000
@@ -1273,6 +1273,22 @@
</child>
<child>
+ <widget class="GtkMenuItem" id="ItemAddArtistToPlaylist">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Add Artist To Playlist</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="ItemAddAlbumToPlaylist">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Add Album To Playlist</property>
+ <property name="use_underline">True</property>
+ </widget>
+ </child>
+
+ <child>
<widget class="GtkMenuItem" id="ItemRating">
<property name="visible">True</property>
<property name="label" translatable="yes">Rating</property>
Index: banshee/src/PlayerInterface.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/PlayerInterface.cs,v
retrieving revision 1.97
diff -u -p -r1.97 PlayerInterface.cs
--- banshee/src/PlayerInterface.cs 13 Nov 2005 15:30:52 -0000 1.97
+++ banshee/src/PlayerInterface.cs 13 Nov 2005 22:04:56 -0000
@@ -2039,6 +2039,18 @@ namespace Banshee
newPlItem.Activated += OnNewPlaylistFromSelectionActivated;
plMenu.Append(newPlItem);
+ Menu artistToPlMenu = new Menu();
+ newPlItem = new ImageMenuItem(Catalog.GetString("New Playlist"));
+ newPlItem.Image = new Gtk.Image("gtk-new", IconSize.Menu);
+ newPlItem.Activated += OnNewPlaylistFromArtistActivated;
+ artistToPlMenu.Append(newPlItem);
+
+ Menu albumToPlMenu = new Menu();
+ newPlItem = new ImageMenuItem(Catalog.GetString("New Playlist"));
+ newPlItem.Image = new Gtk.Image("gtk-new", IconSize.Menu);
+ newPlItem.Activated += OnNewPlaylistFromAlbumActivated;
+ albumToPlMenu.Append(newPlItem);
+
string [] names = Playlist.ListAll();
if(names.Length > 0) {
@@ -2053,6 +2065,24 @@ namespace Banshee
item.Activated += OnItemAddToPlaylistActivated;
plMenu.Append(item);
+
+ item = new ImageMenuItem(plName);
+ item.Image = new Gtk.Image(
+ Pixbuf.LoadFromResource("source-playlist.png"));
+
+ playlistMenuMap[item] = plName;
+ item.Activated += OnItemAddArtistToPlaylistActivated;
+
+ artistToPlMenu.Append(item);
+
+ item = new ImageMenuItem(plName);
+ item.Image = new Gtk.Image(
+ Pixbuf.LoadFromResource("source-playlist.png"));
+
+ playlistMenuMap[item] = plName;
+ item.Activated += OnItemAddAlbumToPlaylistActivated;
+
+ albumToPlMenu.Append(item);
}
}
@@ -2079,13 +2109,21 @@ namespace Banshee
}
(gxmlPlaylistMenu["ItemAddToPlaylist"] as MenuItem).Submenu = plMenu;
+ (gxmlPlaylistMenu["ItemAddArtistToPlaylist"] as MenuItem).Submenu = artistToPlMenu;
+ (gxmlPlaylistMenu["ItemAddAlbumToPlaylist"] as MenuItem).Submenu = albumToPlMenu;
(gxmlPlaylistMenu["ItemRating"] as MenuItem).Submenu = ratingMenu;
}
menu.ShowAll();
gxmlPlaylistMenu["ItemAddToPlaylist"].Visible = sensitive
- && playlistModel.Source.Type != SourceType.AudioCd;;
+ && playlistModel.Source.Type != SourceType.AudioCd;
+ gxmlPlaylistMenu["ItemAddArtistToPlaylist"].Visible =
+ playlistView.Selection.CountSelectedRows() == 1
+ && playlistModel.Source.Type != SourceType.AudioCd;
+ gxmlPlaylistMenu["ItemAddAlbumToPlaylist"].Visible =
+ playlistView.Selection.CountSelectedRows() == 1
+ && playlistModel.Source.Type != SourceType.AudioCd;
gxmlPlaylistMenu["ItemRating"].Visible = sensitive
&& playlistModel.Source.Type != SourceType.AudioCd;
gxmlPlaylistMenu["ItemSep"].Visible = sensitive;
@@ -2100,7 +2138,100 @@ namespace Banshee
return false;
}
-
+
+ private void OnItemAddArtistToPlaylistActivated(object o, EventArgs args)
+ {
+ string plName = playlistMenuMap[o] as string;
+ ArrayList tracks_to_add = new ArrayList();
+ Statement track_query_sql = new Select("Tracks");
+
+ foreach(TreePath path in playlistView.Selection.GetSelectedRows()) {
+ TrackInfo ti = playlistModel.PathTrackInfo(path);
+ track_query_sql += new Where(new Compare("Artist","=",ti.Artist));
+ }
+
+ IDataReader track_query_result = Core.Library.Db.Query(track_query_sql);
+
+ while(track_query_result.Read())
+ {
+ TrackInfo ti = Core.Library.Tracks[track_query_result.GetInt32(0)] as TrackInfo;
+ tracks_to_add.Add(ti);
+ }
+
+ playlistView.AddTracksToPlayList(tracks_to_add, plName);
+ }
+
+ private void OnNewPlaylistFromArtistActivated(object o, EventArgs args)
+ {
+ ArrayList tracks_to_add = new ArrayList();
+ Statement track_query_sql = new Select("Tracks");
+
+ foreach(TreePath path in playlistView.Selection.GetSelectedRows()) {
+ TrackInfo ti = playlistModel.PathTrackInfo(path);
+ track_query_sql += new Where(new Compare("Artist","=",ti.Artist));
+ }
+
+ IDataReader track_query_result = Core.Library.Db.Query(track_query_sql);
+
+ while(track_query_result.Read())
+ {
+ TrackInfo ti = Core.Library.Tracks[track_query_result.GetInt32(0)] as TrackInfo;
+ tracks_to_add.Add(ti);
+ }
+
+ Playlist pl = new Playlist(Playlist.GoodUniqueName(tracks_to_add));
+ pl.Append(tracks_to_add);
+ pl.Save();
+ pl.Saved += OnPlaylistSaved;
+ }
+
+ private void OnItemAddAlbumToPlaylistActivated(object o, EventArgs args)
+ {
+ string plName = playlistMenuMap[o] as string;
+
+ ArrayList tracks_to_add = new ArrayList();
+ Statement track_query_sql = new Select("Tracks");
+
+ foreach(TreePath path in playlistView.Selection.GetSelectedRows()) {
+ TrackInfo ti = playlistModel.PathTrackInfo(path);
+ track_query_sql += new Where(new Compare("AlbumTitle","=",ti.Album));
+ }
+
+ IDataReader track_query_result = Core.Library.Db.Query(track_query_sql);
+
+ while(track_query_result.Read())
+ {
+ TrackInfo ti = Core.Library.Tracks[track_query_result.GetInt32(0)] as TrackInfo;
+ tracks_to_add.Add(ti);
+ }
+
+ playlistView.AddTracksToPlayList(tracks_to_add, plName);
+ }
+
+ private void OnNewPlaylistFromAlbumActivated(object o, EventArgs args)
+ {
+ ArrayList tracks_to_add = new ArrayList();
+ Statement track_query_sql = new Select("Tracks");
+
+ foreach(TreePath path in playlistView.Selection.GetSelectedRows()) {
+ TrackInfo ti = playlistModel.PathTrackInfo(path);
+ track_query_sql += new Where(new Compare("AlbumTitle","=",ti.Album));
+ }
+
+ IDataReader track_query_result = Core.Library.Db.Query(track_query_sql);
+
+ while(track_query_result.Read())
+ {
+ TrackInfo ti = Core.Library.Tracks[track_query_result.GetInt32(0)] as TrackInfo;
+ tracks_to_add.Add(ti);
+ }
+
+ Playlist pl = new Playlist(Playlist.GoodUniqueName(tracks_to_add));
+ pl.Append(tracks_to_add);
+ pl.Save();
+ pl.Saved += OnPlaylistSaved;
+ }
+
private void OnItemAddToPlaylistActivated(object o, EventArgs args)
{
string name = playlistMenuMap[o] as string;
Index: banshee/src/PlaylistView.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/PlaylistView.cs,v
retrieving revision 1.27
diff -u -p -r1.27 PlaylistView.cs
--- banshee/src/PlaylistView.cs 25 Oct 2005 01:26:10 -0000 1.27
+++ banshee/src/PlaylistView.cs 13 Nov 2005 22:04:57 -0000
@@ -695,6 +695,18 @@ namespace Banshee
pl.Save();
}
+ public void AddTracksToPlayList(ArrayList tracks, string name) {
+ Playlist pl = new Playlist(name);
+ pl.Load();
+
+ foreach(TrackInfo track in tracks) {
+ if(track == null)
+ continue;
+ pl.Append(track);
+ }
+ pl.Save();
+ }
+
public TrackInfo SelectedTrackInfo {
get {
TreePath [] paths = Selection.GetSelectedRows();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]