2 # -*- coding: utf-8 -*-
5 @todo Restructure so there is a windows/ folder with a file per source
6 @todo Add additional sources
8 @todo Sequential playback
13 @todo Reverse order option. Toggle between playing ascending/descending chronological order
14 @todo Podcast integration
17 from __future__ import with_statement
25 import dbus.mainloop.glib
35 import util.misc as misc_utils
43 _moduleLogger = logging.getLogger(__name__)
44 PROFILE_STARTUP = False
47 class MormonChannelProgram(hildonize.get_app_class()):
50 super(MormonChannelProgram, self).__init__()
51 self._store = imagestore.ImageStore("../data", "../data")
52 self._index = stream_index.AudioIndex()
53 self._player = player.Player(self._index)
57 if not hildonize.IS_HILDON_SUPPORTED:
58 _moduleLogger.info("No hildonization support")
61 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
62 self._deviceState = osso.DeviceState(self._osso_c)
63 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
65 _moduleLogger.info("No osso support")
67 self._deviceState = None
69 self._sourceSelector = windows.SourceSelector(self._player, self._store, self._index)
70 self._sourceSelector.window.connect("destroy", self._on_destroy)
71 self._sourceSelector.show()
77 def _save_settings(self):
78 config = ConfigParser.SafeConfigParser()
80 self._sourceSelector.save_settings(config, "Windows")
82 with open(constants._user_settings_, "wb") as configFile:
83 config.write(configFile)
85 def _load_settings(self):
86 config = ConfigParser.SafeConfigParser()
87 config.read(constants._user_settings_)
89 self._sourceSelector.load_settings(config, "Windows")
91 @misc_utils.log_exception(_moduleLogger)
92 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
94 For system_inactivity, we have no background tasks to pause
101 if save_unsaved_data or shutdown:
102 self._save_settings()
104 @misc_utils.log_exception(_moduleLogger)
105 def _on_destroy(self, widget = None, data = None):
110 self._save_settings()
115 self._deviceState.close()
116 except AttributeError:
117 pass # Either None or close was removed (in Fremantle)
120 except AttributeError:
121 pass # Either None or close was removed (in Fremantle)
125 @misc_utils.log_exception(_moduleLogger)
126 def _on_show_about(self, widget = None, data = None):
127 dialog = gtk.AboutDialog()
128 dialog.set_position(gtk.WIN_POS_CENTER)
129 dialog.set_name(constants.__pretty_app_name__)
130 dialog.set_version(constants.__version__)
131 dialog.set_copyright("")
132 dialog.set_website("")
133 comments = "Mormon Radio and Audiobook Player"
134 dialog.set_comments(comments)
135 dialog.set_authors(["Ed Page <eopage@byu.net>"])
141 gobject.threads_init()
142 gtk.gdk.threads_init()
143 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
145 hildonize.set_application_title(constants.__pretty_app_name__)
146 app = MormonChannelProgram()
147 if not PROFILE_STARTUP:
150 except KeyboardInterrupt:
155 if __name__ == "__main__":
156 logging.basicConfig(level=logging.DEBUG)