2 # -*- coding: utf-8 -*-
5 @todo Reverse order option. Toggle between playing ascending/descending chronological order
7 @bug All connect's need disconnects or else we will leak a bunch of objects
10 from __future__ import with_statement
26 import util.misc as misc_utils
34 _moduleLogger = logging.getLogger(__name__)
35 PROFILE_STARTUP = False
38 class MormonChannelProgram(hildonize.get_app_class()):
41 super(MormonChannelProgram, self).__init__()
42 self._store = imagestore.ImageStore("../data", "../data")
43 self._index = index.AudioIndex()
44 self._player = player.Player(self._index)
49 if not hildonize.IS_HILDON_SUPPORTED:
50 _moduleLogger.info("No hildonization support")
53 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
54 self._deviceState = osso.DeviceState(self._osso_c)
55 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
57 _moduleLogger.info("No osso support")
59 self._deviceState = None
61 self._sourceSelector = windows.SourceSelector(self._player, self._store, self._index)
62 self._sourceSelector.window.connect("destroy", self._on_destroy)
63 self._sourceSelector.show()
69 def _save_settings(self):
70 config = ConfigParser.SafeConfigParser()
72 self._sourceSelector.save_settings(config, "Windows")
74 with open(constants._user_settings_, "wb") as configFile:
75 config.write(configFile)
77 def _load_settings(self):
78 config = ConfigParser.SafeConfigParser()
79 config.read(constants._user_settings_)
81 self._sourceSelector.load_settings(config, "Windows")
83 @misc_utils.log_exception(_moduleLogger)
84 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
86 For system_inactivity, we have no background tasks to pause
93 if save_unsaved_data or shutdown:
96 @misc_utils.log_exception(_moduleLogger)
97 def _on_destroy(self, widget = None, data = None):
102 self._save_settings()
107 self._deviceState.close()
108 except AttributeError:
109 pass # Either None or close was removed (in Fremantle)
112 except AttributeError:
113 pass # Either None or close was removed (in Fremantle)
117 @misc_utils.log_exception(_moduleLogger)
118 def _on_show_about(self, widget = None, data = None):
119 dialog = gtk.AboutDialog()
120 dialog.set_position(gtk.WIN_POS_CENTER)
121 dialog.set_name(constants.__pretty_app_name__)
122 dialog.set_version(constants.__version__)
123 dialog.set_copyright("")
124 dialog.set_website("")
125 comments = "Mormon Radio and Audiobook Player"
126 dialog.set_comments(comments)
127 dialog.set_authors(["Ed Page <eopage@byu.net>"])
133 gobject.threads_init()
134 gtk.gdk.threads_init()
136 hildonize.set_application_title(constants.__pretty_app_name__)
137 app = MormonChannelProgram()
138 if not PROFILE_STARTUP:
141 except KeyboardInterrupt:
146 if __name__ == "__main__":
147 logging.basicConfig(level=logging.DEBUG)