2 # -*- coding: utf-8 -*-
5 @todo backgrounds need some resizing
6 @todo Re-use windows for better performance
7 @bug For some reason, the back/close button doesn't work when I nest multiple levels
8 @todo Need to confirm id's are persistent (not just for todos but broken behavior on transition)
13 @todo Reverse order option. Toggle between playing ascending/descending chronological order
14 @todo Podcast integration
17 from __future__ import with_statement
26 import dbus.mainloop.glib
36 import util.misc as misc_utils
44 _moduleLogger = logging.getLogger(__name__)
45 PROFILE_STARTUP = False
48 class MormonChannelProgram(hildonize.get_app_class()):
51 super(MormonChannelProgram, self).__init__()
52 currentPath = os.path.abspath(__file__)
53 storePath = os.path.join(os.path.split(os.path.dirname(currentPath))[0], "data")
54 self._store = imagestore.ImageStore(storePath, constants._cache_path_)
55 self._index = stream_index.AudioIndex()
56 self._player = player.Player(self._index)
61 if not hildonize.IS_HILDON_SUPPORTED:
62 _moduleLogger.info("No hildonization support")
65 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
66 self._deviceState = osso.DeviceState(self._osso_c)
67 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
69 _moduleLogger.info("No osso support")
71 self._deviceState = None
73 self._sourceSelector = windows.source.SourceSelector(self, self._player, self._store, self._index)
74 self._sourceSelector.window.connect("destroy", self._on_destroy)
75 self._sourceSelector.window.set_default_size(400, 800)
76 self._sourceSelector.show()
83 def _save_settings(self):
84 config = ConfigParser.SafeConfigParser()
86 self._sourceSelector.save_settings(config, "Windows")
88 with open(constants._user_settings_, "wb") as configFile:
89 config.write(configFile)
91 def _load_settings(self):
92 config = ConfigParser.SafeConfigParser()
93 config.read(constants._user_settings_)
95 self._sourceSelector.load_settings(config, "Windows")
97 @misc_utils.log_exception(_moduleLogger)
98 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
100 For system_inactivity, we have no background tasks to pause
102 @note Hildon specific
107 if save_unsaved_data or shutdown:
108 self._save_settings()
110 @misc_utils.log_exception(_moduleLogger)
111 def _on_destroy(self, widget = None, data = None):
118 self._save_settings()
125 self._deviceState.close()
126 except AttributeError:
127 pass # Either None or close was removed (in Fremantle)
130 except AttributeError:
131 pass # Either None or close was removed (in Fremantle)
133 @misc_utils.log_exception(_moduleLogger)
134 def _on_show_about(self, widget = None, data = None):
135 dialog = gtk.AboutDialog()
136 dialog.set_position(gtk.WIN_POS_CENTER)
137 dialog.set_name(constants.__pretty_app_name__)
138 dialog.set_version(constants.__version__)
139 dialog.set_copyright("")
140 dialog.set_website("")
141 comments = "Mormon Radio and Audiobook Player"
142 dialog.set_comments(comments)
143 dialog.set_authors(["Ed Page <eopage@byu.net>"])
149 gobject.threads_init()
150 gtk.gdk.threads_init()
151 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
153 hildonize.set_application_name("FMRadio") # Playback while silent on Maemo 5
154 app = MormonChannelProgram()
155 if not PROFILE_STARTUP:
158 except KeyboardInterrupt:
165 if __name__ == "__main__":
166 logging.basicConfig(level=logging.DEBUG)