2 # -*- coding: utf-8 -*-
5 @todo Reverse order option. Toggle between playing ascending/descending chronological order
8 from __future__ import with_statement
17 import dbus.mainloop.glib
28 import util.misc as misc_utils
36 _moduleLogger = logging.getLogger(__name__)
37 PROFILE_STARTUP = False
40 class WatersOfShiloahProgram(hildonize.get_app_class()):
43 super(WatersOfShiloahProgram, self).__init__()
44 currentPath = os.path.abspath(__file__)
45 for dirName in ["share", "data"]:
46 storePath = os.path.join(os.path.split(os.path.dirname(currentPath))[0], dirName)
47 if os.path.isdir(storePath):
49 self._store = imagestore.ImageStore(storePath, constants._cache_path_)
50 self._index = stream_index.AudioIndex()
51 self._player = player.Player(self._index)
56 if not hildonize.IS_HILDON_SUPPORTED:
57 _moduleLogger.info("No hildonization support")
60 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
61 self._deviceState = osso.DeviceState(self._osso_c)
62 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
64 _moduleLogger.info("No osso support")
66 self._deviceState = None
68 self._sourceSelector = windows.source.SourceSelector(self, self._player, self._store, self._index)
69 self._sourceSelector.window.connect("destroy", self._on_destroy)
70 self._sourceSelector.window.set_default_size(400, 800)
71 self._sourceSelector.show()
78 def _save_settings(self):
79 config = ConfigParser.SafeConfigParser()
81 self._sourceSelector.save_settings(config, "Windows")
83 with open(constants._user_settings_, "wb") as configFile:
84 config.write(configFile)
86 def _load_settings(self):
87 config = ConfigParser.SafeConfigParser()
88 config.read(constants._user_settings_)
90 self._sourceSelector.load_settings(config, "Windows")
92 @misc_utils.log_exception(_moduleLogger)
93 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
95 For system_inactivity, we have no background tasks to pause
102 if save_unsaved_data or shutdown:
103 self._save_settings()
105 @misc_utils.log_exception(_moduleLogger)
106 def _on_destroy(self, widget = None, data = None):
114 self._save_settings()
116 _moduleLogger.exception("Error saving settigns")
121 _moduleLogger.exception("Error stopping player")
125 _moduleLogger.exception("Error stopping index")
129 _moduleLogger.exception("Error stopping store")
132 self._deviceState.close()
133 except AttributeError:
134 pass # Either None or close was removed (in Fremantle)
136 _moduleLogger.exception("Error closing device state")
139 except AttributeError:
140 pass # Either None or close was removed (in Fremantle)
142 _moduleLogger.exception("Error closing osso state")
146 gobject.threads_init()
147 gtk.gdk.threads_init()
148 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
150 # HACK Playback while silent on Maemo 5
151 hildonize.set_application_name("FMRadio")
153 app = WatersOfShiloahProgram()
154 if not PROFILE_STARTUP:
157 except KeyboardInterrupt:
164 if __name__ == "__main__":
165 logging.basicConfig(level=logging.DEBUG)