2 # -*- coding: utf-8 -*-
5 @todo Add python-support support, http://svn.debian.org/viewsvn/collab-maint/deb-maint/python-support/trunk/README
6 @todo Need to confirm id's are persistent (not just for todos but broken behavior on transition)
11 @todo Podcast integration
12 @todo Default with BYU Devotionals, http://speeches.byu.edu/?act=help&page=podcast
14 @todo Reverse order option. Toggle between playing ascending/descending chronological order
17 @todo Re-use windows for better performance
18 @todo Make radio program updates only happen when the app has focus to reduce CPU wakes
21 from __future__ import with_statement
30 import dbus.mainloop.glib
40 import util.misc as misc_utils
48 _moduleLogger = logging.getLogger(__name__)
49 PROFILE_STARTUP = False
52 class MormonChannelProgram(hildonize.get_app_class()):
55 super(MormonChannelProgram, self).__init__()
56 currentPath = os.path.abspath(__file__)
57 storePath = os.path.join(os.path.split(os.path.dirname(currentPath))[0], "data")
58 self._store = imagestore.ImageStore(storePath, constants._cache_path_)
59 self._index = stream_index.AudioIndex()
60 self._player = player.Player(self._index)
65 if not hildonize.IS_HILDON_SUPPORTED:
66 _moduleLogger.info("No hildonization support")
69 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
70 self._deviceState = osso.DeviceState(self._osso_c)
71 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
73 _moduleLogger.info("No osso support")
75 self._deviceState = None
77 self._sourceSelector = windows.source.SourceSelector(self, self._player, self._store, self._index)
78 self._sourceSelector.window.connect("destroy", self._on_destroy)
79 self._sourceSelector.window.set_default_size(400, 800)
80 self._sourceSelector.show()
87 def _save_settings(self):
88 config = ConfigParser.SafeConfigParser()
90 self._sourceSelector.save_settings(config, "Windows")
92 with open(constants._user_settings_, "wb") as configFile:
93 config.write(configFile)
95 def _load_settings(self):
96 config = ConfigParser.SafeConfigParser()
97 config.read(constants._user_settings_)
99 self._sourceSelector.load_settings(config, "Windows")
101 @misc_utils.log_exception(_moduleLogger)
102 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
104 For system_inactivity, we have no background tasks to pause
106 @note Hildon specific
111 if save_unsaved_data or shutdown:
112 self._save_settings()
114 @misc_utils.log_exception(_moduleLogger)
115 def _on_destroy(self, widget = None, data = None):
123 self._save_settings()
125 _moduleLogger.exception("Error saving settigns")
130 _moduleLogger.exception("Error stopping player")
134 _moduleLogger.exception("Error stopping index")
138 _moduleLogger.exception("Error stopping store")
141 self._deviceState.close()
142 except AttributeError:
143 pass # Either None or close was removed (in Fremantle)
145 _moduleLogger.exception("Error closing device state")
148 except AttributeError:
149 pass # Either None or close was removed (in Fremantle)
151 _moduleLogger.exception("Error closing osso state")
155 gobject.threads_init()
156 gtk.gdk.threads_init()
157 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
159 # HACK Playback while silent on Maemo 5
160 hildonize.set_application_name("FMRadio")
162 app = MormonChannelProgram()
163 if not PROFILE_STARTUP:
166 except KeyboardInterrupt:
173 if __name__ == "__main__":
174 logging.basicConfig(level=logging.DEBUG)