2 # -*- coding: utf-8 -*-
5 @todo Implement Jump TO
6 @todo Implement highlighting of current track
7 @todo Restructure so there is a windows/ folder with a file per source
8 @todo Add additional sources
9 @bug All connect's need disconnects or else we will leak a bunch of objects
11 @todo Reverse order option. Toggle between playing ascending/descending chronological order
14 from __future__ import with_statement
30 import util.misc as misc_utils
38 _moduleLogger = logging.getLogger(__name__)
39 PROFILE_STARTUP = False
42 class MormonChannelProgram(hildonize.get_app_class()):
45 super(MormonChannelProgram, self).__init__()
46 self._store = imagestore.ImageStore("../data", "../data")
47 self._index = index.AudioIndex()
48 self._player = player.Player(self._index)
53 if not hildonize.IS_HILDON_SUPPORTED:
54 _moduleLogger.info("No hildonization support")
57 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
58 self._deviceState = osso.DeviceState(self._osso_c)
59 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
61 _moduleLogger.info("No osso support")
63 self._deviceState = None
65 self._sourceSelector = windows.SourceSelector(self._player, self._store, self._index)
66 self._sourceSelector.window.connect("destroy", self._on_destroy)
67 self._sourceSelector.show()
73 def _save_settings(self):
74 config = ConfigParser.SafeConfigParser()
76 self._sourceSelector.save_settings(config, "Windows")
78 with open(constants._user_settings_, "wb") as configFile:
79 config.write(configFile)
81 def _load_settings(self):
82 config = ConfigParser.SafeConfigParser()
83 config.read(constants._user_settings_)
85 self._sourceSelector.load_settings(config, "Windows")
87 @misc_utils.log_exception(_moduleLogger)
88 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
90 For system_inactivity, we have no background tasks to pause
97 if save_unsaved_data or shutdown:
100 @misc_utils.log_exception(_moduleLogger)
101 def _on_destroy(self, widget = None, data = None):
106 self._save_settings()
111 self._deviceState.close()
112 except AttributeError:
113 pass # Either None or close was removed (in Fremantle)
116 except AttributeError:
117 pass # Either None or close was removed (in Fremantle)
121 @misc_utils.log_exception(_moduleLogger)
122 def _on_show_about(self, widget = None, data = None):
123 dialog = gtk.AboutDialog()
124 dialog.set_position(gtk.WIN_POS_CENTER)
125 dialog.set_name(constants.__pretty_app_name__)
126 dialog.set_version(constants.__version__)
127 dialog.set_copyright("")
128 dialog.set_website("")
129 comments = "Mormon Radio and Audiobook Player"
130 dialog.set_comments(comments)
131 dialog.set_authors(["Ed Page <eopage@byu.net>"])
137 gobject.threads_init()
138 gtk.gdk.threads_init()
140 hildonize.set_application_title(constants.__pretty_app_name__)
141 app = MormonChannelProgram()
142 if not PROFILE_STARTUP:
145 except KeyboardInterrupt:
150 if __name__ == "__main__":
151 logging.basicConfig(level=logging.DEBUG)