Rhythmbox library update & Album renderer
- From: Lee Willis <lee leewillis co uk>
- To: dashboard-hackers gnome org
- Subject: Rhythmbox library update & Album renderer
- Date: Wed, 25 Feb 2004 21:27:03 +0000
Find attached a first-pass at bringing the rhythmbox backend up to date,
together with putting in place a renderer for Album matches.
The code is less than clean in places (I don't like the way we pass the
list of songs) and hasn't seen much testing yet. I also suspect that
someone more aesthetic than me can tidy up the renderer output
The major change hidden in all of this is that the backend will now
listen to all cluetypes, not just "artist".
Note also that the patch removes GaimLogBackend from the Makefile since
it doesn't build for me here [and I don't have time to debug right now
:(] - you may want to ignore that bit of the patch.
Feedback appreciated.
Thanks
PS. Nat - not sure you got my previous mail - I think it went straight
to you and not to the list, but I'm happy for this, or any other code of
mine to go under a GPL.
Index: backends/Makefile.am
===================================================================
RCS file: /cvs/gnome/dashboard/backends/Makefile.am,v
retrieving revision 1.65
diff -u -u -r1.65 Makefile.am
--- backends/Makefile.am 25 Feb 2004 07:43:10 -0000 1.65
+++ backends/Makefile.am 25 Feb 2004 21:22:37 -0000
@@ -10,13 +10,13 @@
EpiphanyBookmarksBackend.dll \
EpiphanyHistoryBackend.dll \
EvolutionMailBackend.dll \
- GaimLogBackend.dll \
GaleonBookmarksBackend.dll \
GoogleBackend.dll \
GeoSitesBackend.dll \
ManPagesBackend.dll \
MozillaBookmarksBackend.dll \
RSSBackend.dll \
+ RhythmboxLibraryBackend.dll \
TextChainerBackend.dll
# These backends may work fine, but we have consciously decided not to
@@ -32,7 +32,6 @@
DocumentIndexBackend.dll \
EvolutionAddressbookBackend.dll \
HTTPBridgeBackend.dll \
- RhythmboxLibraryBackend.dll \
RegexpChainerBackend.dll \
HTMLIndexBackend.dll \
HTMLChainerBackend.dll \
@@ -47,7 +46,6 @@
$(srcdir)/EvolutionAddressbookBackend.cs \
$(srcdir)/EvolutionMailBackend.cs \
$(srcdir)/FoafFileBackend.cs \
- $(srcdir)/GaimLogBackend.cs \
$(srcdir)/GaleonBookmarksBackend.cs \
$(srcdir)/GeoSitesBackend.cs \
$(srcdir)/GoogleBackend.cs \
@@ -89,8 +87,8 @@
GoogleBackend.dll: GoogleBackend.cs $(dashboard_exe)
$(CSC) $(LIBFLAGS) -out:GoogleBackend.dll $(srcdir)/GoogleBackend.cs -r:../util/webservices/GoogleSearchService.dll
-RhythmboxLibraryBackend: backend-rhythmboxlibrary.cs $(dashboard_exe)
- $(CSC) $(LIBFLAGS) -out:backend-rhythmboxlibrary.dll $(srcdir)/backend-rhythmboxlibrary.cs -r:../util/webservices/AmazonSearchService.dll
+RhythmboxLibraryBackend.dll: RhythmboxLibraryBackend.cs $(dashboard_exe)
+ $(CSC) $(LIBFLAGS) -out:RhythmboxLibraryBackend.dll $(srcdir)/RhythmboxLibraryBackend.cs -r:../util/webservices/AmazonSearchService.dll
clean:
Index: backends/RhythmboxLibraryBackend.cs
===================================================================
RCS file: /cvs/gnome/dashboard/backends/RhythmboxLibraryBackend.cs,v
retrieving revision 1.10
diff -u -u -r1.10 RhythmboxLibraryBackend.cs
--- backends/RhythmboxLibraryBackend.cs 14 Feb 2004 06:03:35 -0000 1.10
+++ backends/RhythmboxLibraryBackend.cs 25 Feb 2004 21:22:37 -0000
@@ -19,7 +19,7 @@
namespace Dashboard {
- class SongMatch {
+ class SongInfo {
public string title;
public string album;
public string track_number;
@@ -43,7 +43,7 @@
public override bool Startup ()
{
- Name = "Rhythmbox Library";
+ this.Name = "Rhythmbox Library";
string home_dir = Environment.GetEnvironmentVariable ("HOME");
string path;
@@ -60,9 +60,6 @@
songs = doc.SelectNodes ("/rhythmdb[ version=\"1.0\"]/entry");
- // Subscribe to artist clues
- this.SubscribeToClues ("artist");
-
this.Initialized = true;
return true;
@@ -84,42 +81,39 @@
SortedList AlbumArray = new SortedList();
string clue_text = clue.Text.ToLower ();
- if (clue.Type == "artist") {
-
- // Find matching songs
- XmlNodeList ArtistMatches = doc.SelectNodes (String.Format("//entry[artist=\"{0}\"]",clue.Text));
+ // Find matching songs
+ XmlNodeList ArtistMatches = doc.SelectNodes (String.Format("//entry[artist=\"{0}\"]",clue.Text));
- if (ArtistMatches.Count > 0) {
+ if (ArtistMatches.Count > 0) {
- foreach (XmlNode Song in ArtistMatches) {
+ foreach (XmlNode Song in ArtistMatches) {
- AlbumMatch thisAlbum;
- SongMatch thisMatch = new SongMatch();
-
- thisMatch.artist = clue.Text;
- thisMatch.album = Song["album"].InnerText;
- thisMatch.title = Song["title"].InnerText;
- thisMatch.track_number = Song["track-number"].InnerText;
-
- // See if there is an entry in AlbumArray for this album
- if (AlbumArray.ContainsKey(thisMatch.album)) {
- // If so then grab the AlbumMatch entry
- thisAlbum = (AlbumMatch)AlbumArray[thisMatch.album];
- } else {
- // Create a blank AlbumMatch entry
- thisAlbum = new AlbumMatch();
- thisAlbum.artist = thisMatch.artist;
- thisAlbum.title = thisMatch.album;
- thisAlbum.songs = new SortedList();
- AlbumArray.Add (thisAlbum.title, thisAlbum);
- }
-
- // Add the song to the AlbumMatch entry
- // FIXME This breaks if you have two tracks on the same album, claiming the same track number :(
- thisAlbum.songs.Add(Convert.ToInt32(thisMatch.track_number), thisMatch);
+ AlbumMatch thisAlbum;
+ SongInfo thisMatch = new SongInfo();
+
+ thisMatch.artist = clue.Text;
+ thisMatch.album = Song["album"].InnerText;
+ thisMatch.title = Song["title"].InnerText;
+ thisMatch.track_number = Song["track-number"].InnerText;
+
+ // See if there is an entry in AlbumArray for this album
+ if (AlbumArray.ContainsKey(thisMatch.album)) {
+ // If so then grab the AlbumMatch entry
+ thisAlbum = (AlbumMatch)AlbumArray[thisMatch.album];
+ } else {
+ // Create a blank AlbumMatch entry
+ thisAlbum = new AlbumMatch();
+ thisAlbum.artist = thisMatch.artist;
+ thisAlbum.title = thisMatch.album;
+ thisAlbum.songs = new SortedList();
+ AlbumArray.Add (thisAlbum.title, thisAlbum);
}
+ // Add the song to the AlbumMatch entry
+ // FIXME This breaks if you have two tracks on the same album, claiming the same track number :(
+ thisAlbum.songs.Add(Convert.ToInt32(thisMatch.track_number), thisMatch);
}
+
}
// Now we have a nicely sorted dataset we can create the match sets
@@ -127,32 +121,33 @@
AlbumMatch thisAlbum = (AlbumMatch)AlbumArray.GetByIndex(i);
// Create a backendmatch
- Match AlbumMatch = new Match ("Song");
+ Match AlbumMatch = new Match ("Album",clue);
AlbumWebInfo albumwebinfo = GetAlbumArtURLFromAlbumDetails(thisAlbum.artist, thisAlbum.title);
if (albumwebinfo != null) {
- AlbumMatch.AddItem(new MatchItem("Icon", albumwebinfo.art_url, "image", "plain", albumwebinfo.album_url));
+ AlbumMatch ["album_art_url"] = albumwebinfo.art_url;
}
- AlbumMatch.AddItem(new MatchItem("AlbumTitle", thisAlbum.title, "text", "plain"));
+ AlbumMatch ["artist"] = thisAlbum.artist;
+ AlbumMatch ["title"] = thisAlbum.title;
+ ArrayList track_number_array = new ArrayList();
+ ArrayList title_array = new ArrayList();
+
// For each song on album
for (int j=0; j < thisAlbum.songs.Count; j++) {
- // Create a backend sub match
- Match songMatch = new Match ("Song");
+ SongInfo thisSong = (SongInfo)thisAlbum.songs.GetByIndex(j);
+ track_number_array.Add (thisSong.track_number);
+ title_array.Add (thisSong.title);
- SongMatch thisSong = (SongMatch)thisAlbum.songs.GetByIndex(j);
-
- songMatch.AddItem(new MatchItem("TrackNumber", thisSong.track_number, "number", "plain"));
- songMatch.AddItem(new MatchItem("TrackTitle", thisSong.title, "text", "plain"));
-
- // Add it the album match
- AlbumMatch.AddSubMatch(songMatch);
}
+ AlbumMatch ["song_track_numbers"] = track_number_array;
+ AlbumMatch ["song_titles"] = title_array;
+
// Add the album match to the match set
- matches.Add(AlbumMatch);
+ matches.Add(AlbumMatch);
}
if (matches.Count > 0) {
Index: renderers/AlbumMatchRenderer.cs
===================================================================
RCS file: renderers/AlbumMatchRenderer.cs
diff -N renderers/AlbumMatchRenderer.cs
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ renderers/AlbumMatchRenderer.cs 25 Feb 2004 21:22:37 -0000
@@ -0,0 +1,99 @@
+//
+// GNOME Dashboard
+//
+// AlbumMatchRenderer.cs: Knows how to render Album matches.
+//
+// Author:
+// Lee Willis <lee leewillis co uk>
+//
+
+using Gdk;
+using System;
+using System.IO;
+using System.Collections;
+
+namespace Dashboard {
+
+ class AlbumMatchRenderer : MatchRenderer {
+
+ public override void Startup ()
+ {
+ Type = "Album";
+ }
+
+ public override string HTMLRenderMatches (ArrayList matches)
+ {
+ string html = "";
+
+ html += "<u>Albums</u> <blockquote> <table border=0 cellpadding=0 cellspacing=0>";
+
+ foreach (Match m in matches)
+ html += HTMLRenderSingleAlbum (m);
+
+ html += "</table> </blockquote>\n\n";
+
+ return html;
+ }
+
+ private string HTMLRenderSingleAlbum (Match m)
+ {
+ string html;
+ string icon;
+
+ // Allow the caller to overwide the icon by passing
+ // in an album art URL
+ if (m ["album_art_url"] != null) {
+ icon = (string)m ["album_art_url"];
+ } else {
+ icon = "internal:music.png";
+ }
+
+
+ html = String.Format
+ ("<tr>" +
+ " <td colspan=\"2\" valign=top>" +
+ " <img src=\"{2}\" width=\"32\" height=\"32\" border=0 align=\"left\">" +
+ " {0}<br>" +
+ " <font size=-1 color=#666666>{1}</font>" +
+ " </td>" +
+ "</tr>" +
+ "<tr>" +
+ " <td colspan=\"2\"><hr width=\"100%\"></td>" +
+ "</tr>",
+
+ m ["artist"],
+ m ["title"],
+ icon);
+
+ ArrayList track_numbers = (ArrayList) m ["song_track_numbers"];
+ ArrayList song_titles = (ArrayList) m ["song_titles"];
+ bool is_odd = true;
+
+ for (int j=0; j < song_titles.Count; j++) {
+
+ if (is_odd)
+ html += "<tr>";
+
+ html += String.Format
+ ("<td width=\"50%\">" +
+ "<font size=-1 color=#666666>{0} - {1}</font>" +
+ "</td>",
+
+ track_numbers[j],
+ song_titles[j]);
+
+ if (!is_odd)
+ html += "</tr>";
+
+ if (is_odd)
+ is_odd = false;
+ else
+ is_odd = true;
+ }
+
+ return html;
+ }
+
+ }
+}
+
Index: renderers/Makefile.am
===================================================================
RCS file: /cvs/gnome/dashboard/renderers/Makefile.am,v
retrieving revision 1.5
diff -u -u -r1.5 Makefile.am
--- renderers/Makefile.am 25 Feb 2004 07:43:11 -0000 1.5
+++ renderers/Makefile.am 25 Feb 2004 21:22:37 -0000
@@ -10,6 +10,7 @@
IMLogMatchRenderer.dll \
MailMessageMatchRenderer.dll \
BugzillaBugMatchRenderer.dll \
+ AlbumMatchRenderer.dll \
DefaultMatchRenderer.dll
# These do not work.
@@ -20,6 +21,7 @@
$(srcdir)/IMLogMatchRenderer.cs \
$(srcdir)/MailMessageMatchRenderer.cs \
$(srcdir)/BugzillaBugMatchRenderer.cs \
+ $(srcdir)/AlbumMatchRenderer.cs \
$(srcdir)/DefaultMatchRenderer.cs
all: $(renderers)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]