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
23 import dbus.mainloop.glib
33 import util.misc as misc_utils
41 _moduleLogger = logging.getLogger(__name__)
42 PROFILE_STARTUP = False
45 class MormonChannelProgram(hildonize.get_app_class()):
48 super(MormonChannelProgram, self).__init__()
49 currentPath = os.path.abspath(__file__)
50 storePath = os.path.join(os.path.split(os.path.dirname(currentPath))[0], "data")
51 self._store = imagestore.ImageStore(storePath, constants._cache_path_)
52 self._index = stream_index.AudioIndex()
53 self._player = player.Player(self._index)
58 if not hildonize.IS_HILDON_SUPPORTED:
59 _moduleLogger.info("No hildonization support")
62 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
63 self._deviceState = osso.DeviceState(self._osso_c)
64 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
66 _moduleLogger.info("No osso support")
68 self._deviceState = None
70 self._sourceSelector = windows.source.SourceSelector(self._player, self._store, self._index)
71 self._sourceSelector.window.connect("destroy", self._on_destroy)
72 self._sourceSelector.show()
79 def _save_settings(self):
80 config = ConfigParser.SafeConfigParser()
82 self._sourceSelector.save_settings(config, "Windows")
84 with open(constants._user_settings_, "wb") as configFile:
85 config.write(configFile)
87 def _load_settings(self):
88 config = ConfigParser.SafeConfigParser()
89 config.read(constants._user_settings_)
91 self._sourceSelector.load_settings(config, "Windows")
93 @misc_utils.log_exception(_moduleLogger)
94 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
96 For system_inactivity, we have no background tasks to pause
103 if save_unsaved_data or shutdown:
104 self._save_settings()
106 @misc_utils.log_exception(_moduleLogger)
107 def _on_destroy(self, widget = None, data = None):
112 self._save_settings()
118 self._deviceState.close()
119 except AttributeError:
120 pass # Either None or close was removed (in Fremantle)
123 except AttributeError:
124 pass # Either None or close was removed (in Fremantle)
128 @misc_utils.log_exception(_moduleLogger)
129 def _on_show_about(self, widget = None, data = None):
130 dialog = gtk.AboutDialog()
131 dialog.set_position(gtk.WIN_POS_CENTER)
132 dialog.set_name(constants.__pretty_app_name__)
133 dialog.set_version(constants.__version__)
134 dialog.set_copyright("")
135 dialog.set_website("")
136 comments = "Mormon Radio and Audiobook Player"
137 dialog.set_comments(comments)
138 dialog.set_authors(["Ed Page <eopage@byu.net>"])
144 gobject.threads_init()
145 gtk.gdk.threads_init()
146 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
148 hildonize.set_application_title(constants.__pretty_app_name__)
149 app = MormonChannelProgram()
150 if not PROFILE_STARTUP:
153 except KeyboardInterrupt:
158 if __name__ == "__main__":
159 logging.basicConfig(level=logging.DEBUG)