Re: [Banshee-List] Add Artist/Album to playlist
- From: Markus Jonsson <marjo691 student liu se>
- To: banshee-list gnome org
- Subject: Re: [Banshee-List] Add Artist/Album to playlist
- Date: Mon, 14 Nov 2005 23:07:14 +0100
Here is the new patch. I regret even sending the other one, really
embarrassing stuff there.
Regards
--Markus
s�005-11-13 klockan 23:21 +0100 skrev Markus Jonsson:
> 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
> _______________________________________________
> Banshee-list mailing list
> Banshee-list gnome org
> http://mail.gnome.org/mailman/listinfo/banshee-list
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 14 Nov 2005 21:51:37 -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/Library.cs
===================================================================
RCS file: /cvs/gnome/banshee/src/Library.cs,v
retrieving revision 1.28
diff -u -p -r1.28 Library.cs
--- banshee/src/Library.cs 13 Nov 2005 20:13:47 -0000 1.28
+++ banshee/src/Library.cs 14 Nov 2005 21:51:39 -0000
@@ -583,7 +583,7 @@ namespace Banshee
return GetId(name) > 0;
}
- private static string PostfixDuplicate(string prefix)
+ public static string PostfixDuplicate(string prefix)
{
string name = prefix;
for(int i = 1; true; i++) {
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 14 Nov 2005 21:51:41 -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;
@@ -2109,6 +2147,79 @@ namespace Banshee
return;
playlistView.AddSelectedToPlayList(name);
+ }
+
+ private ArrayList GetTracksByField(string Artist, string Album)
+ {
+ Console.WriteLine(Artist + " " + Album);
+ ArrayList tracks = new ArrayList();
+ string track_query_sql = String.Format("SELECT * FROM Tracks"+
+ " WHERE Artist = '{0}'",Artist);
+
+ if (Album != null)
+ track_query_sql += String.Format(" AND AlbumTitle = '{0}'",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.Add(ti);
+ }
+
+ return tracks;
+ }
+
+ private void OnNewPlaylistFromArtistActivated(object o, EventArgs args)
+ {
+ string plName = playlistMenuMap[o] as string;
+ TreePath path = playlistView.Selection.GetSelectedRows()[0];
+ TrackInfo ti = playlistModel.PathTrackInfo(path);
+ ArrayList tracks_to_add = GetTracksByField(ti.Artist, null);
+
+ Playlist pl = new Playlist(Playlist.PostfixDuplicate(ti.Artist));
+ pl.Append(tracks_to_add);
+ pl.Save();
+ pl.Saved += OnPlaylistSaved;
+ }
+
+ private void OnItemAddArtistToPlaylistActivated(object o, EventArgs args)
+ {
+ string plName = playlistMenuMap[o] as string;
+ TreePath path = playlistView.Selection.GetSelectedRows()[0];
+ TrackInfo ti = playlistModel.PathTrackInfo(path);
+ ArrayList tracks_to_add = GetTracksByField(ti.Artist, null);
+
+ Playlist pl = new Playlist(plName);
+ pl.Load();
+ pl.Append(tracks_to_add);
+ pl.Save();
+ }
+
+ private void OnNewPlaylistFromAlbumActivated(object o, EventArgs args)
+ {
+ string plName = playlistMenuMap[o] as string;
+ TreePath path = playlistView.Selection.GetSelectedRows()[0];
+ TrackInfo ti = playlistModel.PathTrackInfo(path);
+ ArrayList tracks_to_add = GetTracksByField(ti.Artist, ti.Album);
+
+ Playlist pl = new Playlist(Playlist.PostfixDuplicate(ti.Artist + " - " + ti.Album));
+ pl.Append(tracks_to_add);
+ pl.Save();
+ pl.Saved += OnPlaylistSaved;
+ }
+
+ private void OnItemAddAlbumToPlaylistActivated(object o, EventArgs args)
+ {
+ string plName = playlistMenuMap[o] as string;
+ TreePath path = playlistView.Selection.GetSelectedRows()[0];
+ TrackInfo ti = playlistModel.PathTrackInfo(path);
+ ArrayList tracks_to_add = GetTracksByField(ti.Artist, ti.Album);
+
+ Playlist pl = new Playlist(plName);
+ pl.Load();
+ pl.Append(tracks_to_add);
+ pl.Save();
}
private void OnItemRatingActivated(object o, EventArgs args)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]