[rhythmbox] context: add links to the data provider (last.fm in this case)



commit d03ba2ec0c9088209056f00d978a23e4b842db02
Author: Jonathan Matthew <jonathan fibula d14n org>
Date:   Sun Nov 1 10:26:02 2009 +1000

    context: add links to the data provider (last.fm in this case)
    
    Since we're not a web browser, handle navigation requests by opening
    the target URI in the default browser.

 plugins/context/Makefile.am            |    1 +
 plugins/context/context/AlbumTab.py    |    1 +
 plugins/context/context/ArtistTab.py   |    1 +
 plugins/context/context/ContextView.py |   10 ++++++++++
 plugins/context/context/LastFM.py      |    6 ++++--
 plugins/context/img/lastfm.png         |  Bin 0 -> 1929 bytes
 plugins/context/tmpl/album-tmpl.html   |    1 +
 plugins/context/tmpl/artist-tmpl.html  |    1 +
 8 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/plugins/context/Makefile.am b/plugins/context/Makefile.am
index 5dfa789..db3cd7e 100644
--- a/plugins/context/Makefile.am
+++ b/plugins/context/Makefile.am
@@ -19,6 +19,7 @@ tmpl_DATA = \
 
 imgdir = $(plugindir)/img
 img_DATA = \
+	img/lastfm.png			\
 	img/spinner.gif
 
 EXTRA_DIST = $(plugin_in_files) $(tmpl_DATA) $(img_DATA)
diff --git a/plugins/context/context/AlbumTab.py b/plugins/context/context/AlbumTab.py
index c529946..8de000b 100644
--- a/plugins/context/context/AlbumTab.py
+++ b/plugins/context/context/AlbumTab.py
@@ -126,6 +126,7 @@ class AlbumView (gobject.GObject):
         self.file = self.album_template.render (error = ds.get_error(), 
                                                 list = ds.get_top_albums(), 
                                                 artist = ds.get_artist(),
+                                                datasource = LastFM.datasource_link (self.basepath),
                                                 stylesheet = self.styles)
         self.load_view ()
 
diff --git a/plugins/context/context/ArtistTab.py b/plugins/context/context/ArtistTab.py
index 3677ac6..e4e0a66 100644
--- a/plugins/context/context/ArtistTab.py
+++ b/plugins/context/context/ArtistTab.py
@@ -133,6 +133,7 @@ class ArtistView (gobject.GObject):
                                               image      = med,
                                               fullbio    = full_bio,
                                               shortbio   = summary,
+                                              datasource = LastFM.datasource_link (self.basepath),
                                               stylesheet = self.styles )
             self.load_view ()
         except Exception, e:
diff --git a/plugins/context/context/ContextView.py b/plugins/context/context/ContextView.py
index 5848665..003b739 100644
--- a/plugins/context/context/ContextView.py
+++ b/plugins/context/context/ContextView.py
@@ -187,6 +187,15 @@ class ContextView (gobject.GObject):
 
         self.tab[self.current].reload()
 
+    def navigation_request_cb(self, view, frame, request):
+        # open HTTP URIs externally.  this isn't a web browser.
+        if request.get_uri().startswith('http'):
+            print "opening uri %s" % request.get_uri()
+            rb.show_uri(request.get_uri())
+            return 1        # WEBKIT_NAVIGATION_RESPONSE_IGNORE
+        else:
+            return 0	# WEBKIT_NAVIGATION_RESPONSE_ACCEPT
+
     def init_gui(self):
         self.vbox = gtk.VBox()
         self.frame = gtk.Frame()
@@ -220,6 +229,7 @@ class ContextView (gobject.GObject):
 
         #---- set up webkit pane -----#
         self.webview = webkit.WebView()
+        self.webview.connect("navigation-requested", self.navigation_request_cb)
         self.scroll = gtk.ScrolledWindow()
         self.scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
         self.scroll.set_shadow_type(gtk.SHADOW_IN)
diff --git a/plugins/context/context/LastFM.py b/plugins/context/context/LastFM.py
index e8ea9e1..2ca4966 100644
--- a/plugins/context/context/LastFM.py
+++ b/plugins/context/context/LastFM.py
@@ -41,7 +41,9 @@ NO_ACCOUNT_ERROR = _("This information is only available to last.fm users. Pleas
 USERNAME_GCONF_KEY = "/apps/rhythmbox/audioscrobbler/username"
 
 def user_has_account():
-        username = gconf.client_get_default().get_string(USERNAME_GCONF_KEY)
-        return (username is not None and username != "")
+    username = gconf.client_get_default().get_string(USERNAME_GCONF_KEY)
+    return (username is not None and username != "")
 
+def datasource_link(path):
+    return "<a href='http://last.fm/'><img src='%s/img/lastfm.png'></a>" % self.basepath
 
diff --git a/plugins/context/img/lastfm.png b/plugins/context/img/lastfm.png
new file mode 100644
index 0000000..6e9a88d
Binary files /dev/null and b/plugins/context/img/lastfm.png differ
diff --git a/plugins/context/tmpl/album-tmpl.html b/plugins/context/tmpl/album-tmpl.html
index 9e73068..95e12f7 100644
--- a/plugins/context/tmpl/album-tmpl.html
+++ b/plugins/context/tmpl/album-tmpl.html
@@ -76,6 +76,7 @@
     %endif
     </div>
 %endfor
+    <p>${datasource}</p>
 %else:
     <h1>${ _("Unable to retrieve album information:") }</h1>
     <p class="error">${error}</p>
diff --git a/plugins/context/tmpl/artist-tmpl.html b/plugins/context/tmpl/artist-tmpl.html
index 64ff139..f4a2d1c 100644
--- a/plugins/context/tmpl/artist-tmpl.html
+++ b/plugins/context/tmpl/artist-tmpl.html
@@ -42,6 +42,7 @@ ${ _("Read less") }
 ${ _("Read less") }
 </button>
 </div>
+<p>${datasource}</p>
 %else:
 <h1>${ _("Unable to retrieve artist information:") }</h1>
 <p class="error">${error}</p>



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