2 # -*- coding: utf-8 -*-
5 @todo Restructure so there is a windows/ folder with a file per source
6 @todo Add additional sources
7 @todo Switch home icon color
8 @todo Switch from swappping icons on press to the pressed version of icons
9 @bug Fix presenter display
10 @bug All connect's need disconnects or else we will leak a bunch of objects
13 @todo Sequential playback
14 @todo Enable Call Monitor
17 @todo Reverse order option. Toggle between playing ascending/descending chronological order
18 @todo Podcast integration
21 from __future__ import with_statement
37 import util.misc as misc_utils
45 _moduleLogger = logging.getLogger(__name__)
46 PROFILE_STARTUP = False
49 class MormonChannelProgram(hildonize.get_app_class()):
52 super(MormonChannelProgram, self).__init__()
53 self._store = imagestore.ImageStore("../data", "../data")
54 self._index = stream_index.AudioIndex()
55 self._player = player.Player(self._index)
60 if not hildonize.IS_HILDON_SUPPORTED:
61 _moduleLogger.info("No hildonization support")
64 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
65 self._deviceState = osso.DeviceState(self._osso_c)
66 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
68 _moduleLogger.info("No osso support")
70 self._deviceState = None
72 self._sourceSelector = windows.SourceSelector(self._player, self._store, self._index)
73 self._sourceSelector.window.connect("destroy", self._on_destroy)
74 self._sourceSelector.show()
80 def _save_settings(self):
81 config = ConfigParser.SafeConfigParser()
83 self._sourceSelector.save_settings(config, "Windows")
85 with open(constants._user_settings_, "wb") as configFile:
86 config.write(configFile)
88 def _load_settings(self):
89 config = ConfigParser.SafeConfigParser()
90 config.read(constants._user_settings_)
92 self._sourceSelector.load_settings(config, "Windows")
94 @misc_utils.log_exception(_moduleLogger)
95 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
97 For system_inactivity, we have no background tasks to pause
104 if save_unsaved_data or shutdown:
105 self._save_settings()
107 @misc_utils.log_exception(_moduleLogger)
108 def _on_destroy(self, widget = None, data = None):
113 self._save_settings()
118 self._deviceState.close()
119 except AttributeError:
120 pass # Either None or close was removed (in Fremantle)
123 except AttributeError:
124 pass # Either None or close was removed (in Fremantle)
128 @misc_utils.log_exception(_moduleLogger)
129 def _on_show_about(self, widget = None, data = None):
130 dialog = gtk.AboutDialog()
131 dialog.set_position(gtk.WIN_POS_CENTER)
132 dialog.set_name(constants.__pretty_app_name__)
133 dialog.set_version(constants.__version__)
134 dialog.set_copyright("")
135 dialog.set_website("")
136 comments = "Mormon Radio and Audiobook Player"
137 dialog.set_comments(comments)
138 dialog.set_authors(["Ed Page <eopage@byu.net>"])
144 gobject.threads_init()
145 gtk.gdk.threads_init()
147 hildonize.set_application_title(constants.__pretty_app_name__)
148 app = MormonChannelProgram()
149 if not PROFILE_STARTUP:
152 except KeyboardInterrupt:
157 if __name__ == "__main__":
158 logging.basicConfig(level=logging.DEBUG)