Adding indentation to traces
[theonering] / src / autogv.py
index 7999ed4..d18b28b 100644 (file)
@@ -9,6 +9,12 @@ try:
 except (ImportError, OSError):
        conic = None
 
+try:
+       import osso as _osso
+       osso = _osso
+except (ImportError, OSError):
+       osso = None
+
 import constants
 import util.coroutines as coroutines
 import util.go_utils as gobject_utils
@@ -39,6 +45,9 @@ class NewGVConversations(object):
                )
 
        def stop(self):
+               if self.__callback is None:
+                       _moduleLogger.info("New conversation monitor stopped without starting")
+                       return
                self._connRef().session.voicemails.updateSignalHandler.unregister_sink(
                        self.__callback
                )
@@ -77,11 +86,16 @@ class RefreshVoicemail(object):
                self._connRef = connRef
                self._newChannelSignaller = telepathy_utils.NewChannelSignaller(self._on_new_channel)
                self._outstandingRequests = []
+               self._isStarted = False
 
        def start(self):
                self._newChannelSignaller.start()
+               self._isStarted = True
 
        def stop(self):
+               if not self._isStarted:
+                       _moduleLogger.info("voicemail monitor stopped without starting")
+                       return
                _moduleLogger.info("Stopping voicemail refresh")
                self._newChannelSignaller.stop()
 
@@ -92,6 +106,8 @@ class RefreshVoicemail(object):
                for request in localRequests:
                        localRequests.cancel()
 
+               self._isStarted = False
+
        @gtk_toolbox.log_exception(_moduleLogger)
        def _on_new_channel(self, bus, serviceName, connObjectPath, channelObjectPath, channelType):
                if channelType != telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA:
@@ -173,14 +189,52 @@ class AutoDisconnect(object):
                if not self.session.is_logged_in():
                        _moduleLogger.info("Received connection change event when not logged in")
                        return
-               self._connRef().StatusChanged(
-                       telepathy.CONNECTION_STATUS_DISCONNECTED,
-                       telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR
-               )
                try:
-                       self._connRef().disconnect()
+                       self._connRef().disconnect(telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR)
                except Exception:
                        _moduleLogger.exception("Error durring disconnect")
                self.__delayedDisconnectEventId = None
                return False
 
+
+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
+
+       @gtk_toolbox.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_REQUEST)
+               except Exception:
+                       _moduleLogger.exception("Error durring disconnect")