2 # -*- coding: utf-8 -*-
5 @bug For some reason, the back/close button doesn't work when I nest multiple levels
6 @todo Need to confirm id's are persistent (not just for todos but broken behavior on transition)
11 @todo Reverse order option. Toggle between playing ascending/descending chronological order
12 @todo Podcast integration
15 from __future__ import with_statement
24 import dbus.mainloop.glib
34 import util.misc as misc_utils
42 _moduleLogger = logging.getLogger(__name__)
43 PROFILE_STARTUP = False
46 class MormonChannelProgram(hildonize.get_app_class()):
49 super(MormonChannelProgram, self).__init__()
50 currentPath = os.path.abspath(__file__)
51 storePath = os.path.join(os.path.split(os.path.dirname(currentPath))[0], "data")
52 self._store = imagestore.ImageStore(storePath, constants._cache_path_)
53 self._index = stream_index.AudioIndex()
54 self._player = player.Player(self._index)
59 if not hildonize.IS_HILDON_SUPPORTED:
60 _moduleLogger.info("No hildonization support")
63 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
64 self._deviceState = osso.DeviceState(self._osso_c)
65 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
67 _moduleLogger.info("No osso support")
69 self._deviceState = None
71 self._sourceSelector = windows.source.SourceSelector(self, self._player, self._store, self._index)
72 self._sourceSelector.window.connect("destroy", self._on_destroy)
73 self._sourceSelector.window.set_default_size(400, 800)
74 self._sourceSelector.show()
81 def _save_settings(self):
82 config = ConfigParser.SafeConfigParser()
84 self._sourceSelector.save_settings(config, "Windows")
86 with open(constants._user_settings_, "wb") as configFile:
87 config.write(configFile)
89 def _load_settings(self):
90 config = ConfigParser.SafeConfigParser()
91 config.read(constants._user_settings_)
93 self._sourceSelector.load_settings(config, "Windows")
95 @misc_utils.log_exception(_moduleLogger)
96 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
98 For system_inactivity, we have no background tasks to pause
100 @note Hildon specific
105 if save_unsaved_data or shutdown:
106 self._save_settings()
108 @misc_utils.log_exception(_moduleLogger)
109 def _on_destroy(self, widget = None, data = None):
114 self._save_settings()
120 self._deviceState.close()
121 except AttributeError:
122 pass # Either None or close was removed (in Fremantle)
125 except AttributeError:
126 pass # Either None or close was removed (in Fremantle)
130 @misc_utils.log_exception(_moduleLogger)
131 def _on_show_about(self, widget = None, data = None):
132 dialog = gtk.AboutDialog()
133 dialog.set_position(gtk.WIN_POS_CENTER)
134 dialog.set_name(constants.__pretty_app_name__)
135 dialog.set_version(constants.__version__)
136 dialog.set_copyright("")
137 dialog.set_website("")
138 comments = "Mormon Radio and Audiobook Player"
139 dialog.set_comments(comments)
140 dialog.set_authors(["Ed Page <eopage@byu.net>"])
146 gobject.threads_init()
147 gtk.gdk.threads_init()
148 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
150 hildonize.set_application_title(constants.__pretty_app_name__)
151 app = MormonChannelProgram()
152 if not PROFILE_STARTUP:
155 except KeyboardInterrupt:
160 if __name__ == "__main__":
161 logging.basicConfig(level=logging.DEBUG)