2 # -*- coding: utf-8 -*-
5 @bug For some reason, the back/close button doesn't work when I nest multiple levels
6 @bug When switching from conference to magazines, it randomly jumps around and duplicates windows
7 @bug fullscreen does not propgate
9 @todo Re-use windows for better performance
10 @todo Make radio program updates only happen when the app has focus to reduce CPU wakes
11 @todo Need to confirm id's are persistent (not just for todos but broken behavior on transition)
16 @todo Reverse order option. Toggle between playing ascending/descending chronological order
17 @todo Podcast integration
18 @todo Default with BYU Devotionals, http://speeches.byu.edu/?act=help&page=podcast
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):
122 self._save_settings()
129 self._deviceState.close()
130 except AttributeError:
131 pass # Either None or close was removed (in Fremantle)
134 except AttributeError:
135 pass # Either None or close was removed (in Fremantle)
137 @misc_utils.log_exception(_moduleLogger)
138 def _on_show_about(self, widget = None, data = None):
139 dialog = gtk.AboutDialog()
140 dialog.set_position(gtk.WIN_POS_CENTER)
141 dialog.set_name(constants.__pretty_app_name__)
142 dialog.set_version(constants.__version__)
143 dialog.set_copyright("")
144 dialog.set_website("")
145 comments = "Mormon Radio and Audiobook Player"
146 dialog.set_comments(comments)
147 dialog.set_authors(["Ed Page <eopage@byu.net>"])
153 gobject.threads_init()
154 gtk.gdk.threads_init()
155 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
157 hildonize.set_application_name("FMRadio") # Playback while silent on Maemo 5
158 app = MormonChannelProgram()
159 if not PROFILE_STARTUP:
162 except KeyboardInterrupt:
169 if __name__ == "__main__":
170 logging.basicConfig(level=logging.DEBUG)