2 # -*- coding: utf-8 -*-
5 @todo Reverse order option. Toggle between playing ascending/descending chronological order
9 from __future__ import with_statement
25 import util.misc as misc_utils
33 _moduleLogger = logging.getLogger(__name__)
34 PROFILE_STARTUP = False
37 class MormonChannelProgram(hildonize.get_app_class()):
40 super(MormonChannelProgram, self).__init__()
41 self._store = imagestore.ImageStore("../data", "../data")
42 self._index = index.AudioIndex()
43 self._player = player.Player()
47 if not hildonize.IS_HILDON_SUPPORTED:
48 _moduleLogger.info("No hildonization support")
51 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
52 self._deviceState = osso.DeviceState(self._osso_c)
53 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
55 _moduleLogger.info("No osso support")
57 self._deviceState = None
59 self._sourceSelector = windows.SourceSelector(self._player, self._store, self._index)
60 self._sourceSelector.window.connect("destroy", self._on_destroy)
63 def _save_settings(self):
64 config = ConfigParser.SafeConfigParser()
66 self._sourceSelector.save_settings(config, "Windows")
68 with open(constants._user_settings_, "wb") as configFile:
69 config.write(configFile)
71 def _load_settings(self):
72 config = ConfigParser.SafeConfigParser()
73 config.read(constants._user_settings_)
75 self._sourceSelector.load_settings(config, "Windows")
77 @misc_utils.log_exception(_moduleLogger)
78 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
80 For system_inactivity, we have no background tasks to pause
87 if save_unsaved_data or shutdown:
90 @misc_utils.log_exception(_moduleLogger)
91 def _on_destroy(self, widget = None, data = None):
101 self._deviceState.close()
102 except AttributeError:
103 pass # Either None or close was removed (in Fremantle)
106 except AttributeError:
107 pass # Either None or close was removed (in Fremantle)
111 @misc_utils.log_exception(_moduleLogger)
112 def _on_show_about(self, widget = None, data = None):
113 dialog = gtk.AboutDialog()
114 dialog.set_position(gtk.WIN_POS_CENTER)
115 dialog.set_name(constants.__pretty_app_name__)
116 dialog.set_version(constants.__version__)
117 dialog.set_copyright("")
118 dialog.set_website("")
119 comments = "Mormon Radio and Audiobook Player"
120 dialog.set_comments(comments)
121 dialog.set_authors(["Ed Page <eopage@byu.net>"])
127 gobject.threads_init()
128 gtk.gdk.threads_init()
130 hildonize.set_application_title(constants.__pretty_app_name__)
131 app = MormonChannelProgram()
132 if not PROFILE_STARTUP:
135 except KeyboardInterrupt:
140 if __name__ == "__main__":
141 logging.basicConfig(level=logging.DEBUG)