[telepathy-qt4/master] Added ChannelFactory, internal class to create channels based on their types.

Andre Moreira Magalhaes (andrunko) andre.magalhaes at collabora.co.uk
Wed May 27 07:36:45 PDT 2009


---
 TelepathyQt4/Makefile.am         |    2 +
 TelepathyQt4/channel-factory.cpp |   67 ++++++++++++++++++++++++++++++++++++++
 TelepathyQt4/channel-factory.h   |   42 +++++++++++++++++++++++
 3 files changed, 111 insertions(+), 0 deletions(-)
 create mode 100644 TelepathyQt4/channel-factory.cpp
 create mode 100644 TelepathyQt4/channel-factory.h

diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index 53abe3b..b66ff4a 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -51,6 +51,8 @@ libtelepathy_qt4_la_SOURCES = \
     account.cpp \
     account-manager.cpp \
     channel.cpp \
+    channel-factory.cpp \
+    channel-factory.h \
     channel-request.cpp \
     client.cpp \
     client-registrar.cpp \
diff --git a/TelepathyQt4/channel-factory.cpp b/TelepathyQt4/channel-factory.cpp
new file mode 100644
index 0000000..6b831d2
--- /dev/null
+++ b/TelepathyQt4/channel-factory.cpp
@@ -0,0 +1,67 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "TelepathyQt4/channel-factory.h"
+
+#include <TelepathyQt4/Channel>
+#include <TelepathyQt4/Connection>
+#include <TelepathyQt4/Constants>
+#include <TelepathyQt4/FileTransfer>
+#include <TelepathyQt4/RoomList>
+#include <TelepathyQt4/StreamedMediaChannel>
+#include <TelepathyQt4/TextChannel>
+
+namespace Tp
+{
+
+ChannelPtr ChannelFactory::create(const ConnectionPtr &connection,
+        const QString &channelPath, const QVariantMap &immutableProperties)
+{
+    QString channelType = immutableProperties.value(QLatin1String(
+                TELEPATHY_INTERFACE_CHANNEL ".ChannelType")).toString();
+    if (channelType == TELEPATHY_INTERFACE_CHANNEL_TYPE_TEXT) {
+        return ChannelPtr(dynamic_cast<Channel*>(
+                    TextChannel::create(connection,
+                        channelPath, immutableProperties).data()));
+    }
+    else if (channelType == TELEPATHY_INTERFACE_CHANNEL_TYPE_STREAMED_MEDIA) {
+        return ChannelPtr(dynamic_cast<Channel*>(
+                    StreamedMediaChannel::create(connection,
+                        channelPath, immutableProperties).data()));
+    }
+    else if (channelType == TELEPATHY_INTERFACE_CHANNEL_TYPE_ROOM_LIST) {
+        return ChannelPtr(dynamic_cast<Channel*>(
+                    RoomList::create(connection,
+                        channelPath, immutableProperties).data()));
+    }
+    // FIXME: update spec so we can do this properly
+    else if (channelType == "org.freedesktop.Telepathy.Channel.Type.FileTransfer") {
+        return ChannelPtr(dynamic_cast<Channel*>(
+                    FileTransfer::create(connection,
+                        channelPath, immutableProperties).data()));
+    }
+
+    // ContactList, old-style Tubes, or a future channel type
+    return Channel::create(connection,
+            channelPath, immutableProperties);
+}
+
+} // Tp
diff --git a/TelepathyQt4/channel-factory.h b/TelepathyQt4/channel-factory.h
new file mode 100644
index 0000000..6b4604d
--- /dev/null
+++ b/TelepathyQt4/channel-factory.h
@@ -0,0 +1,42 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2009 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2009 Nokia Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef _TelepathyQt4_cli_channel_factory_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_channel_factory_h_HEADER_GUARD_
+
+#include <TelepathyQt4/Types>
+
+#include <QString>
+#include <QVariantMap>
+
+namespace Tp
+{
+
+class ChannelFactory
+{
+public:
+    static ChannelPtr create(const ConnectionPtr &connection,
+        const QString &channelPath, const QVariantMap &immutableProperties);
+};
+
+} // Tp
+
+#endif
-- 
1.5.6.5




More information about the telepathy-commits mailing list