Auto-enabled system contacts for all contacts
authorEd Page <eopage@byu.net>
Sat, 13 Mar 2010 04:06:22 +0000 (22:06 -0600)
committerEd Page <eopage@byu.net>
Sat, 13 Mar 2010 04:06:22 +0000 (22:06 -0600)
src/autogv.py
src/connection.py
src/util/tp_utils.py

index 9a946e9..9a0f61e 100644 (file)
@@ -108,6 +108,7 @@ class RefreshVoicemail(object):
 
                self._isStarted = False
 
 
                self._isStarted = False
 
+       @misc_utils.log_exception(_moduleLogger)
        def _on_new_channel(self, bus, serviceName, connObjectPath, channelObjectPath, channelType):
                if channelType != telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA:
                        return
        def _on_new_channel(self, bus, serviceName, connObjectPath, channelObjectPath, channelType):
                if channelType != telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA:
                        return
@@ -152,6 +153,7 @@ class TimedDisconnect(object):
        def stop(self):
                self.__delayedDisconnect.cancel()
 
        def stop(self):
                self.__delayedDisconnect.cancel()
 
+       @misc_utils.log_exception(_moduleLogger)
        def _on_delayed_disconnect(self):
                _moduleLogger.info("Timed disconnect occurred")
                self._connRef().disconnect(telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR)
        def _on_delayed_disconnect(self):
                _moduleLogger.info("Timed disconnect occurred")
                self._connRef().disconnect(telepathy.CONNECTION_STATUS_REASON_NETWORK_ERROR)
@@ -195,6 +197,7 @@ class AutoDisconnect(object):
                else:
                        _moduleLogger.info("Other status: %r" % (status, ))
 
                else:
                        _moduleLogger.info("Other status: %r" % (status, ))
 
+       @misc_utils.log_exception(_moduleLogger)
        def _cancel_delayed_disconnect(self):
                _moduleLogger.info("Cancelling auto-log off")
                self.__delayedDisconnect.cancel()
        def _cancel_delayed_disconnect(self):
                _moduleLogger.info("Cancelling auto-log off")
                self.__delayedDisconnect.cancel()
@@ -251,3 +254,22 @@ class DisconnectOnShutdown(object):
                        self._connRef().disconnect(telepathy.CONNECTION_STATUS_REASON_REQUESTED)
                except Exception:
                        _moduleLogger.exception("Error durring disconnect")
                        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()
index a5dec2e..933c372 100644 (file)
@@ -138,6 +138,7 @@ class TheOneRingConnection(
                        autogv.NewGVConversations(weakref.ref(self)),
                        autogv.RefreshVoicemail(weakref.ref(self)),
                        autogv.AutoDisconnect(weakref.ref(self)),
                        autogv.NewGVConversations(weakref.ref(self)),
                        autogv.RefreshVoicemail(weakref.ref(self)),
                        autogv.AutoDisconnect(weakref.ref(self)),
+                       autogv.DelayEnableContactIntegration(constants._telepathy_implementation_name_),
                ]
                self._delayedConnect = gobject_utils.Async(self._delayed_connect)
 
                ]
                self._delayedConnect = gobject_utils.Async(self._delayed_connect)
 
index addae92..042a88a 100644 (file)
@@ -136,6 +136,66 @@ class NewChannelSignaller(object):
                        _moduleLogger.exception("Blocking exception from being passed up")
 
 
                        _moduleLogger.exception("Blocking exception from being passed up")
 
 
+class EnableSystemContactIntegration(object):
+
+       ACCOUNT_MGR_NAME = "org.freedesktop.Telepathy.AccountManager"
+       ACCOUNT_MGR_PATH = "/org/freedesktop/Telepathy/AccountManager"
+       ACCOUNT_MGR_IFACE_QUERY = "com.nokia.AccountManager.Interface.Query"
+       ACCOUNT_IFACE_COMPAT = "com.nokia.Account.Interface.Compat"
+       ACCOUNT_IFACE_COMPAT_PROFILE = "com.nokia.Account.Interface.Compat.Profile"
+       DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
+
+       def __init__(self, profileName):
+               self._bus = dbus.SessionBus()
+               self._profileName = profileName
+
+       def start(self):
+               self._accountManager = self._bus.get_object(
+                       self.ACCOUNT_MGR_NAME,
+                       self.ACCOUNT_MGR_PATH,
+               )
+               self._accountManagerQuery = dbus.Interface(
+                       self._accountManager,
+                       dbus_interface=self.ACCOUNT_MGR_IFACE_QUERY,
+               )
+
+               self._accountManagerQuery.FindAccounts(
+                       {
+                               self.ACCOUNT_IFACE_COMPAT_PROFILE: self._profileName,
+                       },
+                       reply_handler = self._on_found_accounts_reply,
+                       error_handler = self._on_error,
+               )
+
+       @misc.log_exception(_moduleLogger)
+       def _on_found_accounts_reply(self, accountObjectPaths):
+               for accountObjectPath in accountObjectPaths:
+                       print accountObjectPath
+                       account = self._bus.get_object(
+                               self.ACCOUNT_MGR_NAME,
+                               accountObjectPath,
+                       )
+                       accountProperties = dbus.Interface(
+                               account,
+                               self.DBUS_PROPERTIES,
+                       )
+                       accountProperties.Set(
+                               self.ACCOUNT_IFACE_COMPAT,
+                               "SecondaryVCardFields",
+                               ["TEL"],
+                               reply_handler = self._on_field_set,
+                               error_handler = self._on_error,
+                       )
+
+       @misc.log_exception(_moduleLogger)
+       def _on_field_set(self):
+               _moduleLogger.info("SecondaryVCardFields Set")
+
+       @misc.log_exception(_moduleLogger)
+       def _on_error(self, error):
+               _moduleLogger.error("%r" % (error, ))
+
+
 def channel_path_to_conn_path(channelObjectPath):
        """
        >>> channel_path_to_conn_path("/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME/Channel1")
 def channel_path_to_conn_path(channelObjectPath):
        """
        >>> channel_path_to_conn_path("/org/freedesktop/Telepathy/ConnectionManager/theonering/gv/USERNAME/Channel1")