A thousand cuts..
[jamaendo] / jamaui / ui.py
index be4da53..329963b 100644 (file)
@@ -1,3 +1,30 @@
+#!/usr/bin/env python
+#
+# This file is part of Jamaendo.
+# Copyright (c) 2010 Kristoffer Gronlund
+#
+# Jamaendo is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Jamaendo is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Jamaendo.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Player code heavily based on http://thpinfo.com/2008/panucci/:
+#  A resuming media player for Podcasts and Audiobooks
+#  Copyright (c) 2008-05-26 Thomas Perl <thpinfo.com>
+#  (based on http://pygstdocs.berlios.de/pygst-tutorial/seeking.html)
+#
+# Jamaendo jamendo.com API wrapper licensed under the New BSD License;
+# see module for details.
+#
+
 import os, sys
 import gtk
 import gobject
@@ -11,7 +38,7 @@ gobject.threads_init()
 
 log = logging.getLogger(__name__)
 
-VERSION = '1'
+VERSION = '0.1'
 
 try:
     import hildon
@@ -29,6 +56,7 @@ DBusGMainLoop(set_as_default=True)
 
 import jamaendo
 
+from postoffice import postoffice
 from playerwindow import open_playerwindow
 from search import SearchWindow
 from featured import FeaturedWindow
@@ -52,11 +80,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.connect("destroy", self.destroy)
 
         self.CONFDIR = os.path.expanduser('~/MyDocs/.jamaendo')
@@ -64,6 +94,9 @@ class Jamaui(object):
         settings.set_filename(os.path.join(self.CONFDIR, 'ui_settings'))
         settings.load()
 
+        postoffice.connect('request-album-cover', self, self.on_request_cover)
+        log.debug("Created main window.")
+
     def save_settings(self):
         settings.save()
 
@@ -75,10 +108,10 @@ 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")
@@ -140,6 +173,12 @@ class Jamaui(object):
         btn.connect('clicked', callback)
         self.bbox.add(btn)
 
+    def on_request_cover(self, albumid, size):
+        jamaendo.get_album_cover_async(self.got_album_cover, int(albumid), size)
+
+    def got_album_cover(self, albumid, size, cover):
+        postoffice.notify('album-cover', albumid, size, cover)
+
     #def add_featured_button(self):
     #    self.featured_sel = hildon.TouchSelector(text=True)
     #    self.featured_sel.append_text("Albums of the week")
@@ -154,6 +193,7 @@ class Jamaui(object):
     #    self.bbox.add(btn)
 
     def destroy(self, widget):
+        postoffice.disconnect('request-album-cover', self)
         gtk.main_quit()
 
     def show_about(self, w, win):
@@ -162,7 +202,33 @@ class Jamaui(object):
         dialog.set_website("http://github.com/krig")
         dialog.set_website_label("http://github.com/krig")
         dialog.set_version(VERSION)
-        dialog.set_authors(("Kristoffer Gronlund <kristoffer.gronlund@purplescout.se>",))
+        dialog.set_license("""Copyright (c) 2010, Kristoffer Gronlund
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+     * Redistributions of source code must retain the above copyright
+       notice, this list of conditions and the following disclaimer.
+     * Redistributions in binary form must reproduce the above copyright
+       notice, this list of conditions and the following disclaimer in the
+       documentation and/or other materials provided with the distribution.
+     * Neither the name of Jamaendo nor the
+       names of its contributors may be used to endorse or promote products
+       derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+""")
+        dialog.set_authors(("Kristoffer Gronlund <kristoffer.gronlund@purplescout.se>",
+                            "Based on Panucci, written by Thomas Perl <thpinfo.com>"))
         dialog.set_comments("""Jamaendo plays music from the music catalog of JAMENDO.
 
 JAMENDO is an online platform that distributes musical works under Creative Commons licenses.""")
@@ -178,7 +244,7 @@ JAMENDO is an online platform that distributes musical works under Creative Comm
         dialog.destroy()
 
     def open_link(self, d, url, data):
-        print "url: %s" % (url)
+        #print "url: %s" % (url)
         import webbrowser
         webbrowser.open_new(url)
 
@@ -231,9 +297,9 @@ JAMENDO is an online platform that distributes musical works under Creative Comm
         result = dialog.run()
         val = entry.get_text()
         dialog.destroy()
-        print val, result
+        #print val, result
         if val and result == gtk.RESPONSE_OK:
-            print "new user name:", val
+            #print "new user name:", val
             settings.user = val
             self.save_settings()
 
@@ -243,7 +309,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):