2 # -*- coding: utf-8 -*-
4 from __future__ import with_statement
21 import util.misc as misc_utils
24 _moduleLogger = logging.getLogger(__name__)
25 PROFILE_STARTUP = False
28 class REPLACEMElProgram(hildonize.get_app_class()):
31 super(REPLACEMElProgram, self).__init__()
33 if not hildonize.IS_HILDON_SUPPORTED:
34 _moduleLogger.info("No hildonization support")
37 self._osso_c = osso.Context(constants.__app_name__, constants.__version__, False)
38 self._deviceState = osso.DeviceState(self._osso_c)
39 self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
41 _moduleLogger.info("No osso support")
43 self._deviceState = None
45 def _save_settings(self):
46 config = ConfigParser.SafeConfigParser()
48 self._REPLACEME.save_settings(config, "Windows")
50 with open(constants._user_settings_, "wb") as configFile:
51 config.write(configFile)
53 def _load_settings(self):
54 config = ConfigParser.SafeConfigParser()
55 config.read(constants._user_settings_)
57 self._REPLACEME.load_settings(config, "Windows")
59 @misc_utils.log_exception(_moduleLogger)
60 def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
62 For system_inactivity, we have no background tasks to pause
69 if save_unsaved_data or shutdown:
72 @misc_utils.log_exception(_moduleLogger)
73 def _on_destroy(self, widget = None, data = None):
83 _moduleLogger.exception("Error saving settigns")
86 self._deviceState.close()
87 except AttributeError:
88 pass # Either None or close was removed (in Fremantle)
90 _moduleLogger.exception("Error closing device state")
93 except AttributeError:
94 pass # Either None or close was removed (in Fremantle)
96 _moduleLogger.exception("Error closing osso state")
100 gobject.threads_init()
101 gtk.gdk.threads_init()
102 l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
104 # HACK Playback while silent on Maemo 5
105 hildonize.set_application_name("FMRadio")
107 app = REPLACEMElProgram()
108 if not PROFILE_STARTUP:
111 except KeyboardInterrupt:
118 if __name__ == "__main__":
119 logging.basicConfig(level=logging.DEBUG)