2 # -*- coding: utf-8 -*-
5 @bug presenter while playing and active, drag up, it shows play rather than pause, same with play control
6 @todo Restructure so there is a windows/ folder with a file per source
7 @todo Add additional sources
9 @todo Sequential playback
14 @todo Reverse order option. Toggle between playing ascending/descending chronological order
15 @todo Podcast integration
18 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 self._store = imagestore.ImageStore("../data", "../data")
53 self._index = stream_index.AudioIndex()
54 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.SourceSelector(self._player, self._store, self._index)
71 self._sourceSelector.window.connect("destroy", self._on_destroy)
72 self._sourceSelector.show()
78 def _save_settings(self):
79 config = ConfigParser.SafeConfigParser()
81 self._sourceSelector.save_settings(config, "Windows")
83 with open(constants._user_settings_, "wb") as configFile:
84 config.write(configFile)
86 def _load_settings(self):
87 config = ConfigParser.SafeConfigParser()
88 config.read(constants._user_settings_)
90 self._sourceSelector.load_settings(config, "Windows")
92 @misc_utils.log_exception(_moduleLogger)
93 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
95 For system_inactivity, we have no background tasks to pause
102 if save_unsaved_data or shutdown:
103 self._save_settings()
105 @misc_utils.log_exception(_moduleLogger)
106 def _on_destroy(self, widget = None, data = None):
111 self._save_settings()
116 self._deviceState.close()
117 except AttributeError:
118 pass # Either None or close was removed (in Fremantle)
121 except AttributeError:
122 pass # Either None or close was removed (in Fremantle)
126 @misc_utils.log_exception(_moduleLogger)
127 def _on_show_about(self, widget = None, data = None):
128 dialog = gtk.AboutDialog()
129 dialog.set_position(gtk.WIN_POS_CENTER)
130 dialog.set_name(constants.__pretty_app_name__)
131 dialog.set_version(constants.__version__)
132 dialog.set_copyright("")
133 dialog.set_website("")
134 comments = "Mormon Radio and Audiobook Player"
135 dialog.set_comments(comments)
136 dialog.set_authors(["Ed Page <eopage@byu.net>"])
142 gobject.threads_init()
143 gtk.gdk.threads_init()
144 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
146 hildonize.set_application_title(constants.__pretty_app_name__)
147 app = MormonChannelProgram()
148 if not PROFILE_STARTUP:
151 except KeyboardInterrupt:
156 if __name__ == "__main__":
157 logging.basicConfig(level=logging.DEBUG)