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
27 import util.misc as misc_utils
35 _moduleLogger = logging.getLogger(__name__)
36 PROFILE_STARTUP = False
39 class WatersOfShiloahProgram(hildonize.get_app_class()):
42 super(WatersOfShiloahProgram, self).__init__()
43 currentPath = os.path.abspath(__file__)
44 storePath = os.path.join(os.path.split(os.path.dirname(currentPath))[0], "data")
45 self._store = imagestore.ImageStore(storePath, constants._cache_path_)
46 self._index = stream_index.AudioIndex()
47 self._player = player.Player(self._index)
52 if not hildonize.IS_HILDON_SUPPORTED:
53 _moduleLogger.info("No hildonization support")
56 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
57 self._deviceState = osso.DeviceState(self._osso_c)
58 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
60 _moduleLogger.info("No osso support")
62 self._deviceState = None
64 self._sourceSelector = windows.source.SourceSelector(self, self._player, self._store, self._index)
65 self._sourceSelector.window.connect("destroy", self._on_destroy)
66 self._sourceSelector.window.set_default_size(400, 800)
67 self._sourceSelector.show()
74 def _save_settings(self):
75 config = ConfigParser.SafeConfigParser()
77 self._sourceSelector.save_settings(config, "Windows")
79 with open(constants._user_settings_, "wb") as configFile:
80 config.write(configFile)
82 def _load_settings(self):
83 config = ConfigParser.SafeConfigParser()
84 config.read(constants._user_settings_)
86 self._sourceSelector.load_settings(config, "Windows")
88 @misc_utils.log_exception(_moduleLogger)
89 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
91 For system_inactivity, we have no background tasks to pause
98 if save_unsaved_data or shutdown:
101 @misc_utils.log_exception(_moduleLogger)
102 def _on_destroy(self, widget = None, data = None):
110 self._save_settings()
112 _moduleLogger.exception("Error saving settigns")
117 _moduleLogger.exception("Error stopping player")
121 _moduleLogger.exception("Error stopping index")
125 _moduleLogger.exception("Error stopping store")
128 self._deviceState.close()
129 except AttributeError:
130 pass # Either None or close was removed (in Fremantle)
132 _moduleLogger.exception("Error closing device state")
135 except AttributeError:
136 pass # Either None or close was removed (in Fremantle)
138 _moduleLogger.exception("Error closing osso state")
142 gobject.threads_init()
143 gtk.gdk.threads_init()
144 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
146 # HACK Playback while silent on Maemo 5
147 hildonize.set_application_name("FMRadio")
149 app = WatersOfShiloahProgram()
150 if not PROFILE_STARTUP:
153 except KeyboardInterrupt:
160 if __name__ == "__main__":
161 logging.basicConfig(level=logging.DEBUG)