2 # -*- coding: utf-8 -*-
5 @todo Add python-support support, http://svn.debian.org/viewsvn/collab-maint/deb-maint/python-support/trunk/README
7 @todo Need to confirm id's are persistent (not just for todos but broken behavior on transition)
12 @todo Podcast integration
13 @todo Default with BYU Devotionals, http://speeches.byu.edu/?act=help&page=podcast
15 @todo Reverse order option. Toggle between playing ascending/descending chronological order
18 @todo Re-use windows for better performance
19 @todo Make radio program updates only happen when the app has focus to reduce CPU wakes
22 from __future__ import with_statement
31 import dbus.mainloop.glib
41 import util.misc as misc_utils
49 _moduleLogger = logging.getLogger(__name__)
50 PROFILE_STARTUP = False
53 class MormonChannelProgram(hildonize.get_app_class()):
56 super(MormonChannelProgram, self).__init__()
57 currentPath = os.path.abspath(__file__)
58 storePath = os.path.join(os.path.split(os.path.dirname(currentPath))[0], "data")
59 self._store = imagestore.ImageStore(storePath, constants._cache_path_)
60 self._index = stream_index.AudioIndex()
61 self._player = player.Player(self._index)
66 if not hildonize.IS_HILDON_SUPPORTED:
67 _moduleLogger.info("No hildonization support")
70 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
71 self._deviceState = osso.DeviceState(self._osso_c)
72 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
74 _moduleLogger.info("No osso support")
76 self._deviceState = None
78 self._sourceSelector = windows.source.SourceSelector(self, self._player, self._store, self._index)
79 self._sourceSelector.window.connect("destroy", self._on_destroy)
80 self._sourceSelector.window.set_default_size(400, 800)
81 self._sourceSelector.show()
88 def _save_settings(self):
89 config = ConfigParser.SafeConfigParser()
91 self._sourceSelector.save_settings(config, "Windows")
93 with open(constants._user_settings_, "wb") as configFile:
94 config.write(configFile)
96 def _load_settings(self):
97 config = ConfigParser.SafeConfigParser()
98 config.read(constants._user_settings_)
100 self._sourceSelector.load_settings(config, "Windows")
102 @misc_utils.log_exception(_moduleLogger)
103 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
105 For system_inactivity, we have no background tasks to pause
107 @note Hildon specific
112 if save_unsaved_data or shutdown:
113 self._save_settings()
115 @misc_utils.log_exception(_moduleLogger)
116 def _on_destroy(self, widget = None, data = None):
124 self._save_settings()
126 _moduleLogger.exception("Error saving settigns")
131 _moduleLogger.exception("Error stopping player")
135 _moduleLogger.exception("Error stopping index")
139 _moduleLogger.exception("Error stopping store")
142 self._deviceState.close()
143 except AttributeError:
144 pass # Either None or close was removed (in Fremantle)
146 _moduleLogger.exception("Error closing device state")
149 except AttributeError:
150 pass # Either None or close was removed (in Fremantle)
152 _moduleLogger.exception("Error closing osso state")
156 gobject.threads_init()
157 gtk.gdk.threads_init()
158 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
160 # HACK Playback while silent on Maemo 5
161 hildonize.set_application_name("FMRadio")
163 app = MormonChannelProgram()
164 if not PROFILE_STARTUP:
167 except KeyboardInterrupt:
174 if __name__ == "__main__":
175 logging.basicConfig(level=logging.DEBUG)