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()
48 if not hildonize.IS_HILDON_SUPPORTED:
49 _moduleLogger.info("No hildonization support")
52 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
53 self._deviceState = osso.DeviceState(self._osso_c)
54 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
56 _moduleLogger.info("No osso support")
58 self._deviceState = None
60 self._sourceSelector = windows.SourceSelector(self._player, self._store, self._index)
61 self._sourceSelector.window.connect("destroy", self._on_destroy)
67 def _save_settings(self):
68 config = ConfigParser.SafeConfigParser()
70 self._sourceSelector.save_settings(config, "Windows")
72 with open(constants._user_settings_, "wb") as configFile:
73 config.write(configFile)
75 def _load_settings(self):
76 config = ConfigParser.SafeConfigParser()
77 config.read(constants._user_settings_)
79 self._sourceSelector.load_settings(config, "Windows")
81 @misc_utils.log_exception(_moduleLogger)
82 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
84 For system_inactivity, we have no background tasks to pause
91 if save_unsaved_data or shutdown:
94 @misc_utils.log_exception(_moduleLogger)
95 def _on_destroy(self, widget = None, data = None):
100 self._save_settings()
105 self._deviceState.close()
106 except AttributeError:
107 pass # Either None or close was removed (in Fremantle)
110 except AttributeError:
111 pass # Either None or close was removed (in Fremantle)
115 @misc_utils.log_exception(_moduleLogger)
116 def _on_show_about(self, widget = None, data = None):
117 dialog = gtk.AboutDialog()
118 dialog.set_position(gtk.WIN_POS_CENTER)
119 dialog.set_name(constants.__pretty_app_name__)
120 dialog.set_version(constants.__version__)
121 dialog.set_copyright("")
122 dialog.set_website("")
123 comments = "Mormon Radio and Audiobook Player"
124 dialog.set_comments(comments)
125 dialog.set_authors(["Ed Page <eopage@byu.net>"])
131 gobject.threads_init()
132 gtk.gdk.threads_init()
134 hildonize.set_application_title(constants.__pretty_app_name__)
135 app = MormonChannelProgram()
136 if not PROFILE_STARTUP:
139 except KeyboardInterrupt:
144 if __name__ == "__main__":
145 logging.basicConfig(level=logging.DEBUG)