2 # -*- coding: utf-8 -*-
5 @todo Restructure so there is a windows/ folder with a file per source
6 @todo Add additional sources
7 @bug All connect's need disconnects or else we will leak a bunch of objects
9 @todo Reverse order option. Toggle between playing ascending/descending chronological order
12 from __future__ import with_statement
28 import util.misc as misc_utils
36 _moduleLogger = logging.getLogger(__name__)
37 PROFILE_STARTUP = False
40 class MormonChannelProgram(hildonize.get_app_class()):
43 super(MormonChannelProgram, self).__init__()
44 self._store = imagestore.ImageStore("../data", "../data")
45 self._index = stream_index.AudioIndex()
46 self._player = player.Player(self._index)
51 if not hildonize.IS_HILDON_SUPPORTED:
52 _moduleLogger.info("No hildonization support")
55 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
56 self._deviceState = osso.DeviceState(self._osso_c)
57 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
59 _moduleLogger.info("No osso support")
61 self._deviceState = None
63 self._sourceSelector = windows.SourceSelector(self._player, self._store, self._index)
64 self._sourceSelector.window.connect("destroy", self._on_destroy)
65 self._sourceSelector.show()
71 def _save_settings(self):
72 config = ConfigParser.SafeConfigParser()
74 self._sourceSelector.save_settings(config, "Windows")
76 with open(constants._user_settings_, "wb") as configFile:
77 config.write(configFile)
79 def _load_settings(self):
80 config = ConfigParser.SafeConfigParser()
81 config.read(constants._user_settings_)
83 self._sourceSelector.load_settings(config, "Windows")
85 @misc_utils.log_exception(_moduleLogger)
86 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
88 For system_inactivity, we have no background tasks to pause
95 if save_unsaved_data or shutdown:
98 @misc_utils.log_exception(_moduleLogger)
99 def _on_destroy(self, widget = None, data = None):
104 self._save_settings()
109 self._deviceState.close()
110 except AttributeError:
111 pass # Either None or close was removed (in Fremantle)
114 except AttributeError:
115 pass # Either None or close was removed (in Fremantle)
119 @misc_utils.log_exception(_moduleLogger)
120 def _on_show_about(self, widget = None, data = None):
121 dialog = gtk.AboutDialog()
122 dialog.set_position(gtk.WIN_POS_CENTER)
123 dialog.set_name(constants.__pretty_app_name__)
124 dialog.set_version(constants.__version__)
125 dialog.set_copyright("")
126 dialog.set_website("")
127 comments = "Mormon Radio and Audiobook Player"
128 dialog.set_comments(comments)
129 dialog.set_authors(["Ed Page <eopage@byu.net>"])
135 gobject.threads_init()
136 gtk.gdk.threads_init()
138 hildonize.set_application_title(constants.__pretty_app_name__)
139 app = MormonChannelProgram()
140 if not PROFILE_STARTUP:
143 except KeyboardInterrupt:
148 if __name__ == "__main__":
149 logging.basicConfig(level=logging.DEBUG)