Added 'helldon' to transparently port the thing to the desktop :P
[jamaendo] / jamaui / ui.py
index 8fc1997..dda0ecc 100644 (file)
@@ -38,7 +38,7 @@ gobject.threads_init()
 
 log = logging.getLogger(__name__)
 
-VERSION = '0.1'
+VERSION = '0.2'
 
 try:
     import hildon
@@ -47,8 +47,8 @@ except:
         log.critical('Using GTK widgets, install "python2.5-hildon" '
             'for this to work properly.')
     else:
-        log.critical('This ui only works in maemo')
-        sys.exit(1)
+        log.critical('This ui (probably) only works in maemo')
+        import helldon as hildon
 
 from dbus.mainloop.glib import DBusGMainLoop
 
@@ -62,16 +62,8 @@ from search import SearchWindow
 from featured import FeaturedWindow
 from radios import RadiosWindow
 from favorites import FavoritesWindow
-
-class PlaylistsWindow(hildon.StackableWindow):
-    def __init__(self):
-        hildon.StackableWindow.__init__(self)
-        self.set_title("Playlists")
-
-        label = gtk.Label("Playlists")
-        vbox = gtk.VBox(False, 0)
-        vbox.pack_start(label, True, True, 0)
-        self.add(vbox)
+from playlists import PlaylistsWindow
+from listbox import ButtonListDialog
 
 class Jamaui(object):
     def __init__(self):
@@ -80,12 +72,13 @@ class Jamaui(object):
         self.window = None
 
     def create_window(self):
+        log.debug("Creating main window...")
         self.app = hildon.Program()
         self.window = hildon.StackableWindow()
         self.app.add_window(self.window)
 
         self.window.set_title("jamaendo")
-        self.window.set_icon('jamaendo')
+
         self.window.connect("destroy", self.destroy)
 
         self.CONFDIR = os.path.expanduser('~/MyDocs/.jamaendo')
@@ -93,10 +86,9 @@ class Jamaui(object):
         settings.set_filename(os.path.join(self.CONFDIR, 'ui_settings'))
         settings.load()
 
-        postoffice.connect('request-album-cover', self.on_request_cover)
-
-    def save_settings(self):
-        settings.save()
+        postoffice.connect('request-album-cover', self, self.on_request_cover)
+        postoffice.connect('request-images', self, self.on_request_images)
+        log.debug("Created main window.")
 
     def create_menu(self):
         self.menu = hildon.AppMenu()
@@ -106,20 +98,20 @@ class Jamaui(object):
         #search.connect("clicked", self.on_search)
         #self.menu.append(search)
 
-        #player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        #player.set_label("Open player")
-        #player.connect("clicked", self.on_player)
-        #self.menu.append(player)
+        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        player.set_label("Open player")
+        player.connect("clicked", self.on_player)
+        self.menu.append(player)
 
         player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
         player.set_label("Favorites")
         player.connect("clicked", self.on_favorites)
         self.menu.append(player)
 
-        #player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
-        #player.set_label("Playlists")
-        #player.connect("clicked", self.on_playlists)
-        #self.menu.append(player)
+        player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
+        player.set_label("Playlists")
+        player.connect("clicked", self.on_playlists)
+        self.menu.append(player)
 
         player = hildon.GtkButton(gtk.HILDON_SIZE_AUTO)
         player.set_label("Settings")
@@ -174,9 +166,15 @@ class Jamaui(object):
     def on_request_cover(self, albumid, size):
         jamaendo.get_album_cover_async(self.got_album_cover, int(albumid), size)
 
+    def on_request_images(self, urls):
+        jamaendo.get_images_async(self.got_images, urls)
+
     def got_album_cover(self, albumid, size, cover):
         postoffice.notify('album-cover', albumid, size, cover)
 
+    def got_images(self, images):
+        postoffice.notify('images', images)
+
     #def add_featured_button(self):
     #    self.featured_sel = hildon.TouchSelector(text=True)
     #    self.featured_sel.append_text("Albums of the week")
@@ -191,14 +189,18 @@ class Jamaui(object):
     #    self.bbox.add(btn)
 
     def destroy(self, widget):
-        postoffice.disconnect('request-album-cover', self.on_request_cover)
+        postoffice.disconnect(['request-album-cover', 'request-images'], self)
+        settings.save()
+        from player import the_player
+        if the_player:
+            the_player.stop()
         gtk.main_quit()
 
     def show_about(self, w, win):
         dialog = gtk.AboutDialog()
         dialog.set_program_name("jamaendo")
-        dialog.set_website("http://github.com/krig")
-        dialog.set_website_label("http://github.com/krig")
+        dialog.set_website("http://jamaendo.garage.maemo.org/")
+        dialog.set_website_label("http://jamaendo.garage.maemo.org/")
         dialog.set_version(VERSION)
         dialog.set_license("""Copyright (c) 2010, Kristoffer Gronlund
 All rights reserved.
@@ -254,16 +256,15 @@ JAMENDO is an online platform that distributes musical works under Creative Comm
     #    dialog.hide()
 
     def on_featured(self, button):
-        dialog = hildon.PickerDialog(self.window)
-        sel = hildon.TouchSelector(text=True)
-        for feature, _ in FeaturedWindow.features:
-            sel.append_text(feature)
-        dialog.set_selector(sel)
-        dialog.set_title("Featured")
-        if dialog.run() == gtk.RESPONSE_OK:
-            txt = sel.get_current_text()
-            self.featuredwnd = FeaturedWindow(txt)
+        dialog = ButtonListDialog('Featured', self.window)
+        def fn(btn, feature):
+            self.featuredwnd = FeaturedWindow(feature)
             self.featuredwnd.show_all()
+            dialog.response(gtk.RESPONSE_OK)
+        for feature, _ in FeaturedWindow.features:
+            dialog.add_button(feature, fn, feature)
+        dialog.show_all()
+        dialog.run()
         dialog.destroy()
 
     def on_radios(self, button):
@@ -299,7 +300,7 @@ JAMENDO is an online platform that distributes musical works under Creative Comm
         if val and result == gtk.RESPONSE_OK:
             #print "new user name:", val
             settings.user = val
-            self.save_settings()
+            settings.save()
 
 
     def on_favorites(self, button):
@@ -307,7 +308,7 @@ JAMENDO is an online platform that distributes musical works under Creative Comm
         self.favoriteswnd.show_all()
 
     def on_player(self, button):
-        open_playerwindow([])
+        open_playerwindow()
 
     '''
     def on_search(self, button):