Added 'helldon' to transparently port the thing to the desktop :P
[jamaendo] / jamaui / featured.py
index a012993..2eef82d 100644 (file)
 #  (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
 #
 import gtk
 #  (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
 #
 import gtk
-import hildon
+try:
+    import hildon
+except:
+    import helldon as hildon
 import jamaendo
 from playerwindow import open_playerwindow
 from showartist import ShowArtist
 from showalbum import ShowAlbum
 import jamaendo
 from playerwindow import open_playerwindow
 from showartist import ShowArtist
 from showalbum import ShowAlbum
+from albumlist import MusicList
+from player import Playlist
 
 def _alist(l, match):
     for key, value in l:
 
 def _alist(l, match):
     for key, value in l:
@@ -35,67 +40,55 @@ def _alist(l, match):
     return None
 
 class FeaturedWindow(hildon.StackableWindow):
     return None
 
 class FeaturedWindow(hildon.StackableWindow):
-    features = (("Albums of the week",jamaendo.albums_of_the_week),
-                ("Tracks of the week",jamaendo.tracks_of_the_week),
-                ("New releases",jamaendo.new_releases)
-                )
+    features = (
+        ("New releases",jamaendo.new_releases),
+        ("Top albums today", lambda: jamaendo.top_albums(order='ratingday_desc')),
+        ("Top tracks today", lambda: jamaendo.top_tracks(order='ratingday_desc')),
+        ("Albums of the week",jamaendo.albums_of_the_week),
+        ("Tracks of the week",jamaendo.tracks_of_the_week),
+        ("Top 50 tags", lambda: jamaendo.top_tags(count=50)),
+        ("Top 50 artists", lambda: jamaendo.top_artists(count=50)),
+        ("Top 50 albums", lambda: jamaendo.top_albums(count=50)),
+        ("Top 50 tracks", lambda: jamaendo.top_tracks(count=50)),
+        )
 
     def __init__(self, feature):
         hildon.StackableWindow.__init__(self)
 
     def __init__(self, feature):
         hildon.StackableWindow.__init__(self)
-        self.set_title("Featured")
+        self.set_title(feature)
 
         self.featurefn = _alist(self.features, feature)
 
         # Results list
         self.panarea = hildon.PannableArea()
 
         self.featurefn = _alist(self.features, feature)
 
         # Results list
         self.panarea = hildon.PannableArea()
-        self.result_store = gtk.ListStore(str, int)
-        #self.result_store.append(['red'])
-        self.result_view = gtk.TreeView(self.result_store)
-        col = gtk.TreeViewColumn('Name')
-        self.result_view.append_column(col)
-        cell = gtk.CellRendererText()
-        col.pack_start(cell, True)
-        col.add_attribute(cell, 'text', 0)
-        self.result_view.set_search_column(0)
-        col.set_sort_column_id(0)
-        self.result_view.connect('row-activated', self.row_activated)
-
-        self.panarea.add(self.result_view)
+        self.musiclist = MusicList()
+        self.musiclist.connect('row-activated', self.row_activated)
+        self.panarea.add(self.musiclist)
 
         self.idmap = {}
 
         self.idmap = {}
-        for item in self.featurefn():
+        self.items = self.featurefn()
+        for item in self.items:
             self.idmap[item.ID] = item
             self.idmap[item.ID] = item
-            self.result_store.append([self.get_item_text(item), item.ID])
+        self.musiclist.add_items(self.items)
 
         self.add(self.panarea)
 
 
         self.add(self.panarea)
 
-    def get_item_text(self, item):
-        if isinstance(item, jamaendo.Album):
-            return "%s - %s" % (item.artist_name, item.name)
-        elif isinstance(item, jamaendo.Track):
-            return "%s - %s" % (item.artist_name, item.name)
-        else:
-            return item.name
-
-    def make_button(self, text, subtext, callback):
-        button = hildon.Button(gtk.HILDON_SIZE_FINGER_HEIGHT,
-                               hildon.BUTTON_ARRANGEMENT_VERTICAL)
-        button.set_text(text, subtext)
+        self.create_menu()
 
 
-        if callback:
-            button.connect('clicked', callback)
-
-        #image = gtk.image_new_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_BUTTON)
-        #button.set_image(image)
-        #button.set_image_position(gtk.POS_RIGHT)
-
-        return button
+    def create_menu(self):
+        def on_player(*args):
+            from playerwindow import open_playerwindow
+            open_playerwindow()
+        self.menu = hildon.AppMenu()
+        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        player.set_label("Open player")
+        player.connect("clicked", on_player)
+        self.menu.append(player)
+        self.menu.show_all()
+        self.set_app_menu(self.menu)
 
     def row_activated(self, treeview, path, view_column):
 
     def row_activated(self, treeview, path, view_column):
-        treeiter = self.result_store.get_iter(path)
-        title, _id = self.result_store.get(treeiter, 0, 1)
+        _id = self.musiclist.get_item_id(path)
         item = self.idmap[_id]
         item = self.idmap[_id]
-        print _id, item
         self.open_item(item)
 
     def open_item(self, item):
         self.open_item(item)
 
     def open_item(self, item):
@@ -106,5 +99,10 @@ class FeaturedWindow(hildon.StackableWindow):
             wnd = ShowArtist(item)
             wnd.show_all()
         elif isinstance(item, jamaendo.Track):
             wnd = ShowArtist(item)
             wnd.show_all()
         elif isinstance(item, jamaendo.Track):
+            playlist = Playlist(self.items)
+            playlist.jump_to(item.ID)
+            wnd = open_playerwindow()
+            wnd.play_tracks(playlist)
+        elif isinstance(item, jamaendo.Tag):
             wnd = open_playerwindow()
             wnd = open_playerwindow()
-            wnd.play_tracks([item])
+            wnd.play_tracks(jamaendo.get_tag_tracks(item.ID))