From beabd1d936e0095e5162a0551fc024cd21bb4e86 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Fri, 5 Apr 2013 15:24:14 +0200 Subject: [PATCH] Add Account Storage Info --- TelepathyQt/CMakeLists.txt | 3 ++ TelepathyQt/StorageInfo | 13 ++++++ TelepathyQt/account.cpp | 58 +++++++++++++++++++++++ TelepathyQt/account.h | 5 ++ TelepathyQt/storage-info.cpp | 104 ++++++++++++++++++++++++++++++++++++++++++ TelepathyQt/storage-info.h | 72 +++++++++++++++++++++++++++++ 6 files changed, 255 insertions(+) create mode 100644 TelepathyQt/StorageInfo create mode 100644 TelepathyQt/storage-info.cpp create mode 100644 TelepathyQt/storage-info.h diff --git a/TelepathyQt/CMakeLists.txt b/TelepathyQt/CMakeLists.txt index 7577be9..f2b2c65 100644 --- a/TelepathyQt/CMakeLists.txt +++ b/TelepathyQt/CMakeLists.txt @@ -125,6 +125,7 @@ set(telepathy_qt_SRCS simple-stream-tube-handler.cpp simple-text-observer.cpp simple-text-observer-internal.h + storage-info.cpp stream-tube-channel.cpp stream-tube-client.cpp stream-tube-client-internal.h @@ -476,6 +477,8 @@ set(telepathy_qt_HEADERS simple-text-observer.h StatefulDBusProxy StatelessDBusProxy + storage-info.h + StorageInfo StreamTubeChannel StreamTubeClient StreamTubeServer diff --git a/TelepathyQt/StorageInfo b/TelepathyQt/StorageInfo new file mode 100644 index 0000000..b4daee1 --- /dev/null +++ b/TelepathyQt/StorageInfo @@ -0,0 +1,13 @@ +#ifndef _TelepathyQt_StorageInfo_HEADER_GUARD_ +#define _TelepathyQt_StorageInfo_HEADER_GUARD_ + +#ifndef IN_TP_QT_HEADER +#define IN_TP_QT_HEADER +#endif + +#include + +#undef IN_TP_QT_HEADER + +#endif +// vim:set ft=cpp: diff --git a/TelepathyQt/account.cpp b/TelepathyQt/account.cpp index c2ad581..9f4e52c 100644 --- a/TelepathyQt/account.cpp +++ b/TelepathyQt/account.cpp @@ -42,11 +42,13 @@ #include #include #include +#include #include #include #include #include #include +#include #include #include @@ -570,6 +572,7 @@ struct TP_QT_NO_EXPORT Account::Private static void introspectMain(Private *self); static void introspectAvatar(Private *self); static void introspectProtocolInfo(Private *self); + static void introspectStorageInfo(Private *self); static void introspectCapabilities(Private *self); void updateProperties(const QVariantMap &props); @@ -594,6 +597,8 @@ struct TP_QT_NO_EXPORT Account::Private // Mandatory properties interface proxy Client::DBus::PropertiesInterface *properties; + Client::AccountInterfaceStorageInterface *storageInterface; + ReadinessHelper *readinessHelper; // Introspection @@ -606,6 +611,7 @@ struct TP_QT_NO_EXPORT Account::Private QString cmName; QString protocolName; QString serviceName; + StorageInfo storageInfo; ProfilePtr profile; QString displayName; QString nickname; @@ -663,6 +669,7 @@ Account::Private::Private(Account *parent, const ConnectionFactoryConstPtr &conn contactFactory(contactFactory), baseInterface(new Client::AccountInterface(parent)), properties(parent->interface()), + storageInterface(parent->interface()), readinessHelper(parent->readinessHelper()), valid(false), enabled(false), @@ -732,6 +739,14 @@ Account::Private::Private(Account *parent, const ConnectionFactoryConstPtr &conn this); introspectables[FeatureProtocolInfo] = introspectableProtocolInfo; + ReadinessHelper::Introspectable introspectableStorageInfo( + QSet() << 0, + Features() << FeatureCore, + QStringList(), + (ReadinessHelper::IntrospectFunc) &Private::introspectStorageInfo, + this); + introspectables[FeatureStorageInfo] = introspectableStorageInfo; + ReadinessHelper::Introspectable introspectableCapabilities( QSet() << 0, // makesSenseForStatuses Features() << FeatureCore << FeatureProtocolInfo << FeatureProfile, // dependsOnFeatures @@ -972,6 +987,8 @@ const Feature Account::FeatureProfile = FeatureProtocolInfo; // the protocol info, cm name and protocol name to build a fake profile. Make it // a full-featured feature if needed later. +const Feature Account::FeatureStorageInfo = Feature(QLatin1String(Account::staticMetaObject.className()), 4);; + /** * Create a new Account object using QDBusConnection::sessionBus() and the given factories. * @@ -1555,6 +1572,25 @@ ProtocolInfo Account::protocolInfo() const } /** + * Return the storage info of this account. + * + * This method requires Account::FeatureStorageInfo to be ready. + * + * \return The storage info for this account. + */ +StorageInfo Account::storageInfo() const +{ + if (!isReady(Features() << FeatureStorageInfo)) { + warning() << "Trying to retrieve protocol info from account, but " + "protocol info is not supported or was not requested. " + "Use becomeReady(FeatureStorageInfo)"; + return StorageInfo(); + } + + return mPriv->storageInfo; +} + +/** * Return the capabilities for this account. * * Note that this method will return the connection() capabilities if the @@ -4162,6 +4198,13 @@ void Account::Private::introspectProtocolInfo(Account::Private *self) SLOT(onConnectionManagerReady(Tp::PendingOperation*))); } +void Account::Private::introspectStorageInfo(Account::Private* self) +{ + self->parent->connect(self->storageInterface->requestAllProperties(), + SIGNAL(finished(Tp::PendingOperation*)), + SLOT(onStorageIntrospected(Tp::PendingOperation*))); +} + void Account::Private::introspectCapabilities(Account::Private *self) { if (!self->connection) { @@ -4686,6 +4729,21 @@ void Account::onConnectionBuilt(PendingOperation *op) } } +void Account::onStorageIntrospected(PendingOperation* op) +{ + PendingVariantMap *pendingMap = qobject_cast(op); + Q_ASSERT(pendingMap != NULL); + + if (pendingMap->isError()) { + warning() << "Introspect StorageInfo " << mPriv->displayName << "failed with" << + op->errorName() << "-" << op->errorMessage(); + } + + mPriv->storageInfo.updateData(pendingMap->result()); + mPriv->readinessHelper->setIntrospectCompleted(FeatureStorageInfo, true); +} + + /** * \fn void Account::removed() * diff --git a/TelepathyQt/account.h b/TelepathyQt/account.h index 72f858f..5278cfc 100644 --- a/TelepathyQt/account.h +++ b/TelepathyQt/account.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +106,7 @@ public: static const Feature FeatureProtocolInfo; static const Feature FeatureCapabilities; static const Feature FeatureProfile; + static const Feature FeatureStorageInfo; static AccountPtr create(const QString &busName, const QString &objectPath, const ConnectionFactoryConstPtr &connectionFactory = @@ -161,6 +163,8 @@ public: ProtocolInfo protocolInfo() const; + StorageInfo storageInfo() const; + ConnectionCapabilities capabilities() const; bool connectsAutomatically() const; @@ -573,6 +577,7 @@ private Q_SLOTS: TP_QT_NO_EXPORT void onPropertyChanged(const QVariantMap &delta); TP_QT_NO_EXPORT void onRemoved(); TP_QT_NO_EXPORT void onConnectionBuilt(Tp::PendingOperation *); + TP_QT_NO_EXPORT void onStorageIntrospected(Tp::PendingOperation *); private: struct Private; diff --git a/TelepathyQt/storage-info.cpp b/TelepathyQt/storage-info.cpp new file mode 100644 index 0000000..37ef28c --- /dev/null +++ b/TelepathyQt/storage-info.cpp @@ -0,0 +1,104 @@ +/** + * This file is part of TelepathyQt + * + * @copyright Copyright (C) 2013 David Edmundson + * @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 + +#include + +namespace Tp +{ + +struct TP_QT_NO_EXPORT StorageInfo::Private : public QSharedData +{ + QVariantMap storage; +}; + +/** + * \class StorageInfo + * \ingroup clientconn + * \headerfile TelepathyQt/location-info.h + * + * \brief The StorageInfo class represents the location of a + * Telepathy Contact. + */ + +/** + * Construct a new StorageInfo object. + */ +StorageInfo::StorageInfo() + : mPriv(new Private) +{ +} + +StorageInfo::StorageInfo(const QVariantMap &storage) + : mPriv(new Private) +{ + mPriv->storage = storage; +} + +StorageInfo::StorageInfo(const StorageInfo &other) + : mPriv(other.mPriv) +{ +} + +/** + * Class destructor. + */ +StorageInfo::~StorageInfo() +{ +} + +StorageInfo &StorageInfo::operator=(const StorageInfo &other) +{ + this->mPriv = other.mPriv; + return *this; +} + +void StorageInfo::updateData(const QVariantMap &storage) +{ + if (!isValid()) { + mPriv = new Private; + } + + mPriv->storage = storage; +} + +QString StorageInfo::storageProvider() const +{ + return mPriv->storage[QLatin1String("StorageProvider")].toString(); +} + +QVariant StorageInfo::storageIdentifider() const +{ + return mPriv->storage[QLatin1String("StorageIdentifier")].value().variant(); +} + +StorageRestrictionFlag StorageInfo::storageRestrictions() const +{ + return (StorageRestrictionFlag)mPriv->storage[QLatin1String("StorageRestrictions")].toUInt(); +} + +QVariantMap StorageInfo::storageSpecificInformation() const +{ + return mPriv->storage[QLatin1String("StorageSpecificInformation")].toMap(); +} + +} // Tp diff --git a/TelepathyQt/storage-info.h b/TelepathyQt/storage-info.h new file mode 100644 index 0000000..6944bef --- /dev/null +++ b/TelepathyQt/storage-info.h @@ -0,0 +1,72 @@ +/** + * This file is part of TelepathyQt + * + * @copyright Copyright (C) 2013 David Edmundson + * @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 _TelepathyQt_location_info_h_HEADER_GUARD_ +#define _TelepathyQt_location_info_h_HEADER_GUARD_ + +#ifndef IN_TP_QT_HEADER +#error IN_TP_QT_HEADER +#endif + +#include + +#include +#include +#include +#include + +#include + +namespace Tp +{ + +class TP_QT_EXPORT StorageInfo +{ +public: + StorageInfo(); + StorageInfo(const QVariantMap &location); + StorageInfo(const StorageInfo &other); + virtual ~StorageInfo(); + + bool isValid() const { return mPriv.constData() != 0; } + + StorageInfo &operator=(const StorageInfo &other); + + QString storageProvider() const; + QVariant storageIdentifider() const; + QVariantMap storageSpecificInformation() const; + StorageRestrictionFlag storageRestrictions() const; + +private: + friend class Account; + + TP_QT_NO_EXPORT void updateData(const QVariantMap &storage); + + struct Private; + friend struct Private; + QSharedDataPointer mPriv; +}; + +} // Tp + +Q_DECLARE_METATYPE(Tp::StorageInfo); + +#endif -- 1.7.10.4