diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-11-30 16:29:54 +0000 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2011-11-30 16:29:54 +0000 |
commit | 92d7ce512fa88d6e3ffb4c4da4aebeb7e529035a (patch) | |
tree | 0e99a3e46337b152a92f8a565f0c10591e85fb91 /qt4/examples/protocols | |
parent | 18746bafae9ac426a512f15c780b5911a8c7eaed (diff) | |
parent | 83ab35a5d0568717451cfd328f60fc15995a9f7d (diff) |
Merge remote-tracking branch 'qt4/testing'
Diffstat (limited to 'qt4/examples/protocols')
-rw-r--r-- | qt4/examples/protocols/CMakeLists.txt | 18 | ||||
-rw-r--r-- | qt4/examples/protocols/cm-wrapper.cpp | 65 | ||||
-rw-r--r-- | qt4/examples/protocols/cm-wrapper.h | 59 | ||||
-rw-r--r-- | qt4/examples/protocols/main.cpp | 21 | ||||
-rw-r--r-- | qt4/examples/protocols/protocols.cpp | 73 | ||||
-rw-r--r-- | qt4/examples/protocols/protocols.h | 57 |
6 files changed, 293 insertions, 0 deletions
diff --git a/qt4/examples/protocols/CMakeLists.txt b/qt4/examples/protocols/CMakeLists.txt new file mode 100644 index 000000000..a3c348ad9 --- /dev/null +++ b/qt4/examples/protocols/CMakeLists.txt @@ -0,0 +1,18 @@ +set(protocols_SRCS + main.cpp + cm-wrapper.cpp + protocols.cpp) + +set(protocols_MOC_SRCS + cm-wrapper.h + protocols.h) + +tpqt4_generate_mocs(${protocols_MOC_SRCS}) + +add_executable(protocols ${protocols_SRCS} ${protocols_MOC_SRCS}) +target_link_libraries(protocols + ${QT_QTDBUS_LIBRARY} + ${QT_QTGUI_LIBRARY} + ${QT_QTXML_LIBRARY} + ${QT_QTCORE_LIBRARY} + telepathy-qt4) diff --git a/qt4/examples/protocols/cm-wrapper.cpp b/qt4/examples/protocols/cm-wrapper.cpp new file mode 100644 index 000000000..b8122b53a --- /dev/null +++ b/qt4/examples/protocols/cm-wrapper.cpp @@ -0,0 +1,65 @@ +/** + * This file is part of TelepathyQt4 + * + * @copyright Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> + * @copyright Copyright (C) 2010 Nokia Corporation + * @license LGPL 2.1 + * + * 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 "cm-wrapper.h" +#include "_gen/cm-wrapper.moc.hpp" + +#include <TelepathyQt4/Debug> +#include <TelepathyQt4/ConnectionManager> +#include <TelepathyQt4/PendingReady> + +#include <QDebug> + +CMWrapper::CMWrapper(const QString &cmName, QObject *parent) + : QObject(parent), + mCM(ConnectionManager::create(cmName)) +{ + connect(mCM->becomeReady(), + SIGNAL(finished(Tp::PendingOperation *)), + SLOT(onCMReady(Tp::PendingOperation *))); +} + +CMWrapper::~CMWrapper() +{ +} + +ConnectionManagerPtr CMWrapper::cm() const +{ + return mCM; +} + +void CMWrapper::onCMReady(PendingOperation *op) +{ + if (op->isError()) { + qWarning() << "CM" << mCM->name() << "cannot become ready -" << + op->errorName() << ": " << op->errorMessage(); + return; + } + + qDebug() << "CM" << mCM->name() << "ready!"; + qDebug() << "Supported protocols:"; + foreach (const QString &protocol, mCM->supportedProtocols()) { + qDebug() << "\t" << protocol; + } + + emit finished(); +} diff --git a/qt4/examples/protocols/cm-wrapper.h b/qt4/examples/protocols/cm-wrapper.h new file mode 100644 index 000000000..a95778fed --- /dev/null +++ b/qt4/examples/protocols/cm-wrapper.h @@ -0,0 +1,59 @@ +/** + * This file is part of TelepathyQt4 + * + * @copyright Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> + * @copyright Copyright (C) 2010 Nokia Corporation + * @license LGPL 2.1 + * + * 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_examples_protocols_cm_wrapper_h_HEADER_GUARD_ +#define _TelepathyQt4_examples_protocols_cm_wrapper_h_HEADER_GUARD_ + +#include <TelepathyQt4/Types> + +#include <QObject> +#include <QString> + +using namespace Tp; + +namespace Tp +{ +class ConnectionManager; +class PendingOperation; +} + +class CMWrapper : public QObject +{ + Q_OBJECT + +public: + CMWrapper(const QString &cmName, QObject *parent = 0); + ~CMWrapper(); + + ConnectionManagerPtr cm() const; + +Q_SIGNALS: + void finished(); + +private Q_SLOTS: + void onCMReady(Tp::PendingOperation *op); + +private: + ConnectionManagerPtr mCM; +}; + +#endif diff --git a/qt4/examples/protocols/main.cpp b/qt4/examples/protocols/main.cpp new file mode 100644 index 000000000..eed72c236 --- /dev/null +++ b/qt4/examples/protocols/main.cpp @@ -0,0 +1,21 @@ +#include <TelepathyQt4/Debug> +#include <TelepathyQt4/Constants> +#include <TelepathyQt4/Types> + +#include <QDebug> +#include <QtCore> + +#include "protocols.h" + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + + Tp::registerTypes(); + Tp::enableDebug(false); + Tp::enableWarnings(false); + + Protocols protocols; + + return app.exec(); +} diff --git a/qt4/examples/protocols/protocols.cpp b/qt4/examples/protocols/protocols.cpp new file mode 100644 index 000000000..1ccffe224 --- /dev/null +++ b/qt4/examples/protocols/protocols.cpp @@ -0,0 +1,73 @@ +/** + * This file is part of TelepathyQt4 + * + * @copyright Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> + * @copyright Copyright (C) 2010 Nokia Corporation + * @license LGPL 2.1 + * + * 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 "protocols.h" +#include "_gen/protocols.moc.hpp" + +#include <TelepathyQt4/Debug> +#include <TelepathyQt4/ConnectionManager> +#include <TelepathyQt4/PendingStringList> + +#include <QCoreApplication> +#include <QDebug> + +Protocols::Protocols() + : cmWrappersFinished(0) +{ + qDebug() << "Listing names"; + connect(ConnectionManager::listNames(), + SIGNAL(finished(Tp::PendingOperation *)), + SLOT(onListNamesFinished(Tp::PendingOperation *))); +} + +Protocols::~Protocols() +{ +} + +void Protocols::onListNamesFinished(PendingOperation *op) +{ + if (op->isError()) { + qWarning() << "Error listing connection manager names -" << + op->errorName() << ": " << op->errorMessage(); + return; + } + + PendingStringList *ps = qobject_cast<PendingStringList *>(op); + + qDebug() << "Supported CMs:" << ps->result(); + + foreach (const QString &cmName, ps->result()) { + CMWrapper *cmWrapper = new CMWrapper(cmName, this); + mCMWrappers.append(cmWrapper); + connect(cmWrapper, + SIGNAL(finished()), + SLOT(onCMWrapperFinished())); + } +} + +void Protocols::onCMWrapperFinished() +{ + if (++cmWrappersFinished == mCMWrappers.size()) { + QCoreApplication::quit(); + } +} + diff --git a/qt4/examples/protocols/protocols.h b/qt4/examples/protocols/protocols.h new file mode 100644 index 000000000..896fe17a0 --- /dev/null +++ b/qt4/examples/protocols/protocols.h @@ -0,0 +1,57 @@ +/** + * This file is part of TelepathyQt4 + * + * @copyright Copyright (C) 2010 Collabora Ltd. <http://www.collabora.co.uk/> + * @copyright Copyright (C) 2010 Nokia Corporation + * @license LGPL 2.1 + * + * 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_examples_protocols_protocols_h_HEADER_GUARD_ +#define _TelepathyQt4_examples_protocols_protocols_h_HEADER_GUARD_ + +#include <TelepathyQt4/Types> + +#include "cm-wrapper.h" + +#include <QList> +#include <QObject> + +using namespace Tp; + +namespace Tp +{ +class PendingOperation; +} + +class Protocols : public QObject +{ + Q_OBJECT + +public: + Protocols(); + ~Protocols(); + +private Q_SLOTS: + void onListNamesFinished(Tp::PendingOperation *op); + void onCMWrapperFinished(); + +private: + QList<CMWrapper *> mCMWrappers; + int cmWrappersFinished; +}; + +#endif |