Added ossohelper from panucci'
authorKristoffer Grönlund <kristoffer.gronlund@purplescout.se>
Wed, 30 Dec 2009 11:32:31 +0000 (12:32 +0100)
committerKristoffer Grönlund <kristoffer.gronlund@purplescout.se>
Sat, 2 Jan 2010 23:37:44 +0000 (00:37 +0100)
jamaui/ossohelper.py [new file with mode: 0644]
jamaui/player.py
jamaui/ui.py

diff --git a/jamaui/ossohelper.py b/jamaui/ossohelper.py
new file mode 100644 (file)
index 0000000..00306fb
--- /dev/null
@@ -0,0 +1,139 @@
+# ossohelper.py - Helper to osso functions
+#
+#  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
+#
+#  This file is part of carman-python.
+#  Modified for inclusion in Panucci (June 2009).
+#
+#  carman-python 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.
+#
+#  carman-python 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 this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import logging
+
+__log = logging.getLogger('panucci.ossohelper')
+
+try:
+    import osso
+    __osso_imported__ = True
+except ImportError:
+    __log.warning('osso module not found - are you running on a desktop?')
+    __osso_imported__ = False
+
+DEVICE_STATE_NORMAL     = "normal"
+OSSO_DEVSTATE_MODE_FILE = "/tmp/.libosso_device_mode_cache"
+
+__osso_context__ = None
+__osso_application__ = None
+__osso_device_state__ = None
+
+def application_init(app_name, app_version):
+    """
+    Osso application init.
+    """
+
+    global __osso_context__, __osso_device_state__, __osso_application__
+
+    if __osso_imported__:
+        if has_osso():
+            __log.warning('osso application was already called. Ignoring...')
+            return
+        try:
+            __osso_context__ = osso.Context(app_name, app_version, False)
+        except Exception, err:
+            __log.warning('osso module found but could not be initialized: %s',
+                          err)
+            __osso_context__ = None
+            return
+
+        try:
+            __osso_application__ = osso.Application(__osso_context__)
+        except Exception, err:
+            __log.warning('error creating osso application: %s' % err)
+            __osso_application__ = None
+
+        __log.info( 'osso application init sent - %s v%s', app_name,
+                    app_version)
+        __osso_device_state__ = osso.DeviceState(__osso_context__)
+# application_init
+
+def application_exit():
+    """
+    Osso application exit.
+    """
+    if __osso_application__ is not None and __osso_context__ is not None:
+        try:
+            __osso_application__.close()
+            __osso_context__.close()
+        except Exception, err:
+            __log.warning('application end could not be sent: %s' % err)
+        __log.info('osso application end sent')
+# application_exit
+
+def application_top(app_name):
+    """
+    Osso application top.
+    """
+    if __osso_imported__ and __osso_application__:
+        try:
+            __osso_application__.application_top(app_name)
+        except Exception, err:
+            __log.warning( "Error calling application top for %s: %s",
+                           app_name, err)
+        __log.info('osso application top for %s sent', app_name)
+
+# application_top
+
+def has_osso():
+    """
+    Return if the osso module was initialized and all objects were created
+    without any problem
+    """
+    return __osso_imported__ and not None in ( __osso_context__, 
+                                               __osso_device_state__, 
+                                               __osso_application__ )
+# has_osso
+
+def display_on():
+    """
+    Turn on the display
+    """
+    if __osso_device_state__ is not None:
+        __osso_device_state__.display_state_on()
+        __osso_device_state__.display_blanking_pause()
+        __log.info('osso display on')
+# display_on
+
+def display_blanking_pause():
+    """
+    Keep the backlight on. Should be called every 45 seconds.
+    """
+    if __osso_device_state__ is not None:
+        __osso_device_state__.display_blanking_pause()
+        __log.debug('osso blanking screen')
+#display_blanking_pause
+
+def get_device_state():
+    if __osso_device_state__ is not None:
+        cache_file_name = OSSO_DEVSTATE_MODE_FILE + "-" + str(os.getuid())
+        try:
+            state = os.readlink(cache_file_name)
+        except:
+            state = None
+        if not state:
+            __log.debug( "Failure to read device state from %s",
+                         cache_file_name)
+            state = DEVICE_STATE_NORMAL
+        return state
+    else:
+        return DEVICE_STATE_NORMAL
index 1ada454..563484d 100644 (file)
@@ -277,14 +277,14 @@ if util.platform == 'maemo':
             }
 
             # Connect status signals
-            self.audio_proxy.connect_to_signal( "state_changed",
+            self._audio.connect_to_signal( "state_changed",
                                                 self._on_state_changed )
-            self.audio_proxy.connect_to_signal( "end_of_stream",
+            self._audio.connect_to_signal( "end_of_stream",
                                                 lambda x: self._call_eos() )
 
             # Connect error signals
             for error, msg in error_signals.iteritems():
-                self.audio_proxy.connect_to_signal(error, lambda *x: self._error(msg))
+                self._audio.connect_to_signal(error, lambda *x: self._error(msg))
 
         def _error(self, msg):
             log.error(msg)
index 17cf158..efbd2b2 100644 (file)
@@ -14,6 +14,8 @@ import gobject
 from jamaendo.api import LocalDB, Query, Queries, refresh_dump
 from jamaui.player import Player, Playlist
 
+import ossohelper
+
 gobject.threads_init()
 
 log = logging.getLogger(__name__)
@@ -28,6 +30,10 @@ except:
         log.critical('This ui only works in maemo')
         sys.exit(1)
 
+from dbus.mainloop.glib import DBusGMainLoop
+
+DBusGMainLoop(set_as_default=True)
+
 class RefreshDialog(object):
     def __init__(self):
         self.notebook = gtk.Notebook()
@@ -178,11 +184,19 @@ class SearchWindow(hildon.StackableWindow):
         hbox.pack_start(self.entry, True, True, 0)
         hbox.pack_start(btn, False)
 
+        btnbox = gtk.HBox()
+        playbtn = hildon.GtkButton(gtk.HILDON_SIZE_FINGER_HEIGHT)
+        playbtn.set_label("Play selected")
+        playbtn.connect('clicked', self.play_selected)
+        btnbox.pack_start(playbtn, False)
+
         self.results = hildon.TouchSelector(text=True)
         self.results.connect("changed", self.selection_changed)
+        self.results.set_column_selection_mode(hildon.TOUCH_SELECTOR_SELECTION_MODE_SINGLE)
 
         vbox.pack_start(hbox, False)
         vbox.pack_start(self.results, True, True, 0)
+        vbox.pack_start(btnbox, False)
 
         self.add(vbox)
 
@@ -202,7 +216,10 @@ class SearchWindow(hildon.StackableWindow):
             self.results.append_text(title)
 
     def selection_changed(self, results, userdata):
-        current_selection = results.get_current_text()
+        pass
+
+    def play_selected(self, btn):
+        current_selection = self.results.get_current_text()
 
         album = self.idmap[current_selection]
         selected = [int(album['id'])]
@@ -371,11 +388,13 @@ class Jamaui(object):
     '''
 
     def run(self):
+        ossohelper.application_init('org.jamaendo', '0.1')
         self.create_window()
         self.create_menu()
         self.setup_widgets()
         self.window.show_all()
         gtk.main()
+        ossohelper.application_exit()
 
 if __name__=="__main__":
     ui = Jamaui()