2 # -*- coding: utf-8 -*-
5 @todo Need to confirm id's are persistent (not just for todos but broken behavior on transition)
10 @todo Reverse order option. Toggle between playing ascending/descending chronological order
11 @todo Podcast integration
14 from __future__ import with_statement
22 import dbus.mainloop.glib
32 import util.misc as misc_utils
40 _moduleLogger = logging.getLogger(__name__)
41 PROFILE_STARTUP = False
44 class MormonChannelProgram(hildonize.get_app_class()):
47 super(MormonChannelProgram, self).__init__()
48 self._store = imagestore.ImageStore("../data", "../data")
49 self._index = stream_index.AudioIndex()
50 self._player = player.Player(self._index)
54 if not hildonize.IS_HILDON_SUPPORTED:
55 _moduleLogger.info("No hildonization support")
58 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
59 self._deviceState = osso.DeviceState(self._osso_c)
60 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
62 _moduleLogger.info("No osso support")
64 self._deviceState = None
66 self._sourceSelector = windows.source.SourceSelector(self._player, self._store, self._index)
67 self._sourceSelector.window.connect("destroy", self._on_destroy)
68 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):
107 self._save_settings()
112 self._deviceState.close()
113 except AttributeError:
114 pass # Either None or close was removed (in Fremantle)
117 except AttributeError:
118 pass # Either None or close was removed (in Fremantle)
122 @misc_utils.log_exception(_moduleLogger)
123 def _on_show_about(self, widget = None, data = None):
124 dialog = gtk.AboutDialog()
125 dialog.set_position(gtk.WIN_POS_CENTER)
126 dialog.set_name(constants.__pretty_app_name__)
127 dialog.set_version(constants.__version__)
128 dialog.set_copyright("")
129 dialog.set_website("")
130 comments = "Mormon Radio and Audiobook Player"
131 dialog.set_comments(comments)
132 dialog.set_authors(["Ed Page <eopage@byu.net>"])
138 gobject.threads_init()
139 gtk.gdk.threads_init()
140 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
142 hildonize.set_application_title(constants.__pretty_app_name__)
143 app = MormonChannelProgram()
144 if not PROFILE_STARTUP:
147 except KeyboardInterrupt:
152 if __name__ == "__main__":
153 logging.basicConfig(level=logging.DEBUG)