[telepathy-qt4/master] OptionalInterfaceFactory: Added optionalInterface method.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Sun Jun 21 21:23:11 PDT 2009


Moved optionalInterface method to OptionalInterfaceFactory removing
duplicated code.
---
 TelepathyQt4/account.h                    |   14 --------------
 TelepathyQt4/channel-dispatch-operation.h |   13 -------------
 TelepathyQt4/channel-request.h            |   13 -------------
 TelepathyQt4/channel.h                    |   13 -------------
 TelepathyQt4/connection.h                 |   14 --------------
 TelepathyQt4/optional-interface-factory.h |   14 ++++++++++++++
 6 files changed, 14 insertions(+), 67 deletions(-)

diff --git a/TelepathyQt4/account.h b/TelepathyQt4/account.h
index d20c037..19c167d 100644
--- a/TelepathyQt4/account.h
+++ b/TelepathyQt4/account.h
@@ -169,20 +169,6 @@ public:
             QDateTime userActionTime = QDateTime::currentDateTime(),
             const QString &preferredHandler = QString());
 
-    template <class Interface>
-    inline Interface *optionalInterface(
-            InterfaceSupportedChecking check = CheckInterfaceSupported) const
-    {
-        // Check for the remote object supporting the interface
-        QString name(Interface::staticInterfaceName());
-        if (check == CheckInterfaceSupported && !interfaces().contains(name)) {
-            return 0;
-        }
-
-        // If present or forced, delegate to OptionalInterfaceFactory
-        return OptionalInterfaceFactory<Account>::interface<Interface>();
-    }
-
     inline Client::DBus::PropertiesInterface *propertiesInterface() const
     {
         return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
diff --git a/TelepathyQt4/channel-dispatch-operation.h b/TelepathyQt4/channel-dispatch-operation.h
index c2622fc..7dc9617 100644
--- a/TelepathyQt4/channel-dispatch-operation.h
+++ b/TelepathyQt4/channel-dispatch-operation.h
@@ -77,19 +77,6 @@ public:
 
     PendingOperation *claim();
 
-    template <class Interface>
-    inline Interface *optionalInterface(
-            InterfaceSupportedChecking check = CheckInterfaceSupported) const
-    {
-        // Check for the remote object supporting the interface
-        QString name(Interface::staticInterfaceName());
-        if (check == CheckInterfaceSupported && !interfaces().contains(name))
-            return 0;
-
-        // If present or forced, delegate to OptionalInterfaceFactory
-        return OptionalInterfaceFactory<ChannelDispatchOperation>::interface<Interface>();
-    }
-
     inline Client::DBus::PropertiesInterface *propertiesInterface() const
     {
         return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
diff --git a/TelepathyQt4/channel-request.h b/TelepathyQt4/channel-request.h
index 57941f8..b74a1ea 100644
--- a/TelepathyQt4/channel-request.h
+++ b/TelepathyQt4/channel-request.h
@@ -75,19 +75,6 @@ public:
 
     PendingOperation *cancel();
 
-    template <class Interface>
-    inline Interface *optionalInterface(
-            InterfaceSupportedChecking check = CheckInterfaceSupported) const
-    {
-        // Check for the remote object supporting the interface
-        QString name(Interface::staticInterfaceName());
-        if (check == CheckInterfaceSupported && !interfaces().contains(name))
-            return 0;
-
-        // If present or forced, delegate to OptionalInterfaceFactory
-        return OptionalInterfaceFactory<ChannelRequest>::interface<Interface>();
-    }
-
     inline Client::DBus::PropertiesInterface *propertiesInterface() const
     {
         return optionalInterface<Client::DBus::PropertiesInterface>(BypassInterfaceCheck);
diff --git a/TelepathyQt4/channel.h b/TelepathyQt4/channel.h
index 63c5459..bfa275f 100644
--- a/TelepathyQt4/channel.h
+++ b/TelepathyQt4/channel.h
@@ -170,19 +170,6 @@ protected Q_SLOTS:
     PendingOperation *groupAddSelfHandle();
 
 public:
-    template <class Interface>
-    inline Interface *optionalInterface(
-            InterfaceSupportedChecking check = CheckInterfaceSupported) const
-    {
-        // Check for the remote object supporting the interface
-        QString name(Interface::staticInterfaceName());
-        if (check == CheckInterfaceSupported && !interfaces().contains(name))
-            return 0;
-
-        // If present or forced, delegate to OptionalInterfaceFactory
-        return OptionalInterfaceFactory<Channel>::interface<Interface>();
-    }
-
     inline Client::ChannelInterfaceCallStateInterface *callStateInterface(
             InterfaceSupportedChecking check = CheckInterfaceSupported) const
     {
diff --git a/TelepathyQt4/connection.h b/TelepathyQt4/connection.h
index 50e5afd..3b83b44 100644
--- a/TelepathyQt4/connection.h
+++ b/TelepathyQt4/connection.h
@@ -95,20 +95,6 @@ public:
 
     ContactPtr selfContact() const;
 
-    template <class Interface>
-    inline Interface *optionalInterface(
-            InterfaceSupportedChecking check = CheckInterfaceSupported) const
-    {
-        // Check for the remote object supporting the interface
-        QString name(Interface::staticInterfaceName());
-        if (check == CheckInterfaceSupported && !interfaces().contains(name)) {
-            return 0;
-        }
-
-        // If present or forced, delegate to OptionalInterfaceFactory
-        return OptionalInterfaceFactory<Connection>::interface<Interface>();
-    }
-
     inline Client::ConnectionInterfaceAliasingInterface *aliasingInterface(
             InterfaceSupportedChecking check = CheckInterfaceSupported) const
     {
diff --git a/TelepathyQt4/optional-interface-factory.h b/TelepathyQt4/optional-interface-factory.h
index aa8544d..8fd3e84 100644
--- a/TelepathyQt4/optional-interface-factory.h
+++ b/TelepathyQt4/optional-interface-factory.h
@@ -75,6 +75,20 @@ public:
 
     inline QStringList interfaces() const { return mInterfaces; }
 
+    template <class Interface>
+    inline Interface *optionalInterface(
+            InterfaceSupportedChecking check = CheckInterfaceSupported) const
+    {
+        // Check for the remote object supporting the interface
+        QString name(Interface::staticInterfaceName());
+        if (check == CheckInterfaceSupported && !mInterfaces.contains(name)) {
+            return 0;
+        }
+
+        // If present or forced, delegate to OptionalInterfaceFactory
+        return interface<Interface>();
+    }
+
     template <typename Interface>
     inline Interface *interface() const
     {
-- 
1.5.6.5




More information about the telepathy-commits mailing list