2 # -*- coding: utf-8 -*-
5 @todo Restructure so there is a windows/ folder with a file per source
6 @todo Add additional sources
7 @todo Need to confirm id's are persistent (not just for todos but broken behavior on transition)
12 @todo Reverse order option. Toggle between playing ascending/descending chronological order
13 @todo Podcast integration
16 from __future__ import with_statement
24 import dbus.mainloop.glib
34 import util.misc as misc_utils
42 _moduleLogger = logging.getLogger(__name__)
43 PROFILE_STARTUP = False
46 class MormonChannelProgram(hildonize.get_app_class()):
49 super(MormonChannelProgram, self).__init__()
50 self._store = imagestore.ImageStore("../data", "../data")
51 self._index = stream_index.AudioIndex()
52 self._player = player.Player(self._index)
56 if not hildonize.IS_HILDON_SUPPORTED:
57 _moduleLogger.info("No hildonization support")
60 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
61 self._deviceState = osso.DeviceState(self._osso_c)
62 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
64 _moduleLogger.info("No osso support")
66 self._deviceState = None
68 self._sourceSelector = windows.SourceSelector(self._player, self._store, self._index)
69 self._sourceSelector.window.connect("destroy", self._on_destroy)
70 self._sourceSelector.show()
76 def _save_settings(self):
77 config = ConfigParser.SafeConfigParser()
79 self._sourceSelector.save_settings(config, "Windows")
81 with open(constants._user_settings_, "wb") as configFile:
82 config.write(configFile)
84 def _load_settings(self):
85 config = ConfigParser.SafeConfigParser()
86 config.read(constants._user_settings_)
88 self._sourceSelector.load_settings(config, "Windows")
90 @misc_utils.log_exception(_moduleLogger)
91 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
93 For system_inactivity, we have no background tasks to pause
100 if save_unsaved_data or shutdown:
101 self._save_settings()
103 @misc_utils.log_exception(_moduleLogger)
104 def _on_destroy(self, widget = None, data = None):
109 self._save_settings()
114 self._deviceState.close()
115 except AttributeError:
116 pass # Either None or close was removed (in Fremantle)
119 except AttributeError:
120 pass # Either None or close was removed (in Fremantle)
124 @misc_utils.log_exception(_moduleLogger)
125 def _on_show_about(self, widget = None, data = None):
126 dialog = gtk.AboutDialog()
127 dialog.set_position(gtk.WIN_POS_CENTER)
128 dialog.set_name(constants.__pretty_app_name__)
129 dialog.set_version(constants.__version__)
130 dialog.set_copyright("")
131 dialog.set_website("")
132 comments = "Mormon Radio and Audiobook Player"
133 dialog.set_comments(comments)
134 dialog.set_authors(["Ed Page <eopage@byu.net>"])
140 gobject.threads_init()
141 gtk.gdk.threads_init()
142 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
144 hildonize.set_application_title(constants.__pretty_app_name__)
145 app = MormonChannelProgram()
146 if not PROFILE_STARTUP:
149 except KeyboardInterrupt:
154 if __name__ == "__main__":
155 logging.basicConfig(level=logging.DEBUG)