+
+class DisconnectOnShutdown(object):
+ """
+ I'm unsure when I get notified of shutdown or if I have enough time to do
+ anything about it, but thought this might help
+ """
+
+ def __init__(self, connRef):
+ self._connRef = connRef
+
+ self._osso = None
+ self._deviceState = None
+
+ def start(self):
+ if osso is not None:
+ self._osso = osso.Context(constants.__app_name__, constants.__version__, False)
+ self._deviceState = osso.DeviceState(self._osso)
+ self._deviceState.set_device_state_callback(self._on_device_state_change, 0)
+ else:
+ _moduleLogger.warning("No device state support")
+
+ def stop(self):
+ try:
+ self._deviceState.close()
+ except AttributeError:
+ pass # Either None or close was removed (in Fremantle)
+ self._deviceState = None
+ try:
+ self._osso.close()
+ except AttributeError:
+ pass # Either None or close was removed (in Fremantle)
+ self._osso = None
+
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_device_state_change(self, shutdown, save_unsaved_data, memory_low, system_inactivity, message, userData):
+ """
+ @note Hildon specific
+ """
+ try:
+ self._connRef().disconnect(telepathy.CONNECTION_STATUS_REASON_REQUESTED)
+ except Exception:
+ _moduleLogger.exception("Error durring disconnect")
+
+
+class DelayEnableContactIntegration(object):
+
+ def __init__(self, protocolName):
+ self.__enableSystemContactSupport = telepathy_utils.EnableSystemContactIntegration(
+ protocolName
+ )
+ self.__delayedEnable = gobject_utils.Async(self._on_delayed_enable)
+
+ def start(self):
+ self.__delayedEnable.start()
+
+ def stop(self):
+ self.__delayedEnable.cancel()
+
+ @misc_utils.log_exception(_moduleLogger)
+ def _on_delayed_enable(self):
+ self.__enableSystemContactSupport.start()