2 # -*- coding: utf-8 -*-
5 @todo backgrounds need some resizing
6 @bug For some reason, the back/close button doesn't work when I nest multiple levels
7 @todo Need to confirm id's are persistent (not just for todos but broken behavior on transition)
12 @todo Reverse order option. Toggle between playing ascending/descending chronological order
13 @todo Podcast integration
16 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 currentPath = os.path.abspath(__file__)
52 storePath = os.path.join(os.path.split(os.path.dirname(currentPath))[0], "data")
53 self._store = imagestore.ImageStore(storePath, constants._cache_path_)
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.source.SourceSelector(self, self._player, self._store, self._index)
73 self._sourceSelector.window.connect("destroy", self._on_destroy)
74 self._sourceSelector.window.set_default_size(400, 800)
75 self._sourceSelector.show()
82 def _save_settings(self):
83 config = ConfigParser.SafeConfigParser()
85 self._sourceSelector.save_settings(config, "Windows")
87 with open(constants._user_settings_, "wb") as configFile:
88 config.write(configFile)
90 def _load_settings(self):
91 config = ConfigParser.SafeConfigParser()
92 config.read(constants._user_settings_)
94 self._sourceSelector.load_settings(config, "Windows")
96 @misc_utils.log_exception(_moduleLogger)
97 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
99 For system_inactivity, we have no background tasks to pause
101 @note Hildon specific
106 if save_unsaved_data or shutdown:
107 self._save_settings()
109 @misc_utils.log_exception(_moduleLogger)
110 def _on_destroy(self, widget = None, data = None):
115 self._save_settings()
121 self._deviceState.close()
122 except AttributeError:
123 pass # Either None or close was removed (in Fremantle)
126 except AttributeError:
127 pass # Either None or close was removed (in Fremantle)
131 @misc_utils.log_exception(_moduleLogger)
132 def _on_show_about(self, widget = None, data = None):
133 dialog = gtk.AboutDialog()
134 dialog.set_position(gtk.WIN_POS_CENTER)
135 dialog.set_name(constants.__pretty_app_name__)
136 dialog.set_version(constants.__version__)
137 dialog.set_copyright("")
138 dialog.set_website("")
139 comments = "Mormon Radio and Audiobook Player"
140 dialog.set_comments(comments)
141 dialog.set_authors(["Ed Page <eopage@byu.net>"])
147 gobject.threads_init()
148 gtk.gdk.threads_init()
149 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
151 hildonize.set_application_title(constants.__pretty_app_name__)
152 app = MormonChannelProgram()
153 if not PROFILE_STARTUP:
156 except KeyboardInterrupt:
161 if __name__ == "__main__":
162 logging.basicConfig(level=logging.DEBUG)