[Telepathy-commits] [telepathy-qt4/master] Added AccountManager::createAccount support.
Andre Moreira Magalhaes (andrunko)
andre.magalhaes at collabora.co.uk
Fri Jan 9 12:45:44 PST 2009
---
TelepathyQt4/Client/PendingAccount | 13 +++
TelepathyQt4/Client/account-manager.cpp | 8 +-
TelepathyQt4/Client/account-manager.h | 1 +
TelepathyQt4/Client/pending-account.cpp | 151 +++++++++++++++++++++++++++++++
TelepathyQt4/Client/pending-account.h | 72 +++++++++++++++
TelepathyQt4/Makefile.am | 3 +
6 files changed, 245 insertions(+), 3 deletions(-)
create mode 100644 TelepathyQt4/Client/PendingAccount
create mode 100644 TelepathyQt4/Client/pending-account.cpp
create mode 100644 TelepathyQt4/Client/pending-account.h
diff --git a/TelepathyQt4/Client/PendingAccount b/TelepathyQt4/Client/PendingAccount
new file mode 100644
index 0000000..d004255
--- /dev/null
+++ b/TelepathyQt4/Client/PendingAccount
@@ -0,0 +1,13 @@
+#ifndef _TelepathyQt4_Client_PendingAccount_HEADER_GUARD_
+#define _TelepathyQt4_Client_PendingAccount_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#define IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/Client/pending-account.h>
+
+#undef IN_TELEPATHY_QT4_HEADER
+
+#endif
+// vim:set ft=cpp:
diff --git a/TelepathyQt4/Client/account-manager.cpp b/TelepathyQt4/Client/account-manager.cpp
index 0bf9b9b..1f7dd4f 100644
--- a/TelepathyQt4/Client/account-manager.cpp
+++ b/TelepathyQt4/Client/account-manager.cpp
@@ -30,6 +30,7 @@
#include "TelepathyQt4/debug-internal.h"
#include <TelepathyQt4/Client/Account>
+#include <TelepathyQt4/Client/PendingAccount>
#include <TelepathyQt4/Client/PendingSuccess>
#include <TelepathyQt4/Constants>
@@ -159,6 +160,8 @@ void AccountManager::Private::onGetAllAccountManagerReturn(
}
continueIntrospection();
+
+ watcher->deleteLater();
}
void AccountManager::Private::onAccountValidityChanged(const QDBusObjectPath &path,
@@ -394,7 +397,6 @@ QList<Account *> AccountManager::accountsForPaths(const QList<QDBusObjectPath> &
return result;
}
-#if 0
/**
* Create an Account with the given parameters.
*
@@ -412,9 +414,9 @@ PendingAccount *AccountManager::createAccount(const QString &connectionManager,
const QString &protocol, const QString &displayName,
const QVariantMap ¶meters)
{
- return 0;
+ return new PendingAccount(this, connectionManager,
+ protocol, displayName, parameters);
}
-#endif
/**
* Return whether this object has finished its initial setup.
diff --git a/TelepathyQt4/Client/account-manager.h b/TelepathyQt4/Client/account-manager.h
index 637e1f9..2a7c014 100644
--- a/TelepathyQt4/Client/account-manager.h
+++ b/TelepathyQt4/Client/account-manager.h
@@ -104,6 +104,7 @@ private:
class Private;
friend class Private;
+ friend class PendingAccount;
Private *mPriv;
};
diff --git a/TelepathyQt4/Client/pending-account.cpp b/TelepathyQt4/Client/pending-account.cpp
new file mode 100644
index 0000000..6bcfeff
--- /dev/null
+++ b/TelepathyQt4/Client/pending-account.cpp
@@ -0,0 +1,151 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 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/Client/PendingAccount>
+
+#include "TelepathyQt4/Client/_gen/pending-account.moc.hpp"
+
+#include "TelepathyQt4/debug-internal.h"
+
+#include <TelepathyQt4/Client/AccountManager>
+#include <TelepathyQt4/Client/Account>
+
+#include <QDBusObjectPath>
+#include <QDBusPendingCallWatcher>
+#include <QDBusPendingReply>
+
+/**
+ * \addtogroup clientsideproxies Client-side proxies
+ *
+ * Proxy objects representing remote service objects accessed via D-Bus.
+ *
+ * In addition to providing direct access to methods, signals and properties
+ * exported by the remote objects, some of these proxies offer features like
+ * automatic inspection of remote object capabilities, property tracking,
+ * backwards compatibility helpers for older services and other utilities.
+ */
+
+namespace Telepathy
+{
+namespace Client
+{
+
+struct PendingAccount::Private
+{
+ Private(AccountManager *manager) :
+ manager(manager),
+ account(0)
+ {
+ }
+
+ AccountManager *manager;
+ Account *account;
+};
+
+/**
+ * \class PendingAccount
+ * \ingroup clientaccount
+ * \headerfile <TelepathyQt4/Client/pending-account.h> <TelepathyQt4/Client/PendingAccount>
+ *
+ * Class containing the parameters of and the reply to an asynchronous account
+ * request. Instances of this class cannot be constructed directly; the only
+ * way to get one is via AccountManager.
+ */
+
+/**
+ * Construct a PendingAccount object.
+ *
+ * \param manager AccountManager to use.
+ * \param connectionManager Name of the connection manager to create the account for.
+ * \param protocol Name of the protocol to create the account for.
+ * \param displayName Account display name.
+ * \param parameters Account parameters.
+ */
+PendingAccount::PendingAccount(AccountManager *manager,
+ const QString &connectionManager, const QString &protocol,
+ const QString &displayName, const QVariantMap ¶meters)
+ : PendingOperation(manager),
+ mPriv(new Private(manager))
+{
+ QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(
+ manager->baseInterface()->CreateAccount(connectionManager,
+ protocol, displayName, parameters), this);
+ connect(watcher,
+ SIGNAL(finished(QDBusPendingCallWatcher *)),
+ SLOT(onCallFinished(QDBusPendingCallWatcher *)));
+}
+
+/**
+ * Class destructor.
+ */
+PendingAccount::~PendingAccount()
+{
+ delete mPriv;
+}
+
+/**
+ * Return the AccountManager object through which the request was made.
+ *
+ * \return Account Manager object.
+ */
+AccountManager *PendingAccount::manager() const
+{
+ return qobject_cast<AccountManager *>(parent());
+}
+
+/**
+ * Returns the newly created Account object.
+ *
+ * \return Account object.
+ */
+Account *PendingAccount::account() const
+{
+ if (!isFinished()) {
+ warning() <<
+ "PendingAccount::account called before finished, returning 0";
+ return 0;
+ }
+
+ return mPriv->account;
+}
+
+void PendingAccount::onCallFinished(QDBusPendingCallWatcher *watcher)
+{
+ QDBusPendingReply<QDBusObjectPath> reply = *watcher;
+
+ if (!reply.isError()) {
+ debug() << "Got reply to AccountManager.CreateAccount";
+ QDBusObjectPath objectPath = reply.value();
+ debug() << "Creating account for objectPath: " << objectPath.path();
+ mPriv->account = new Account(mPriv->manager, objectPath, mPriv->manager);
+ setFinished();
+ } else {
+ debug().nospace() <<
+ "CreateAccount failed: " <<
+ reply.error().name() << ": " << reply.error().message();
+ setFinishedWithError(reply.error());
+ }
+
+ watcher->deleteLater();
+}
+
+} // Telepathy::Client
+} // Telepathy
diff --git a/TelepathyQt4/Client/pending-account.h b/TelepathyQt4/Client/pending-account.h
new file mode 100644
index 0000000..a5719b5
--- /dev/null
+++ b/TelepathyQt4/Client/pending-account.h
@@ -0,0 +1,72 @@
+/*
+ * This file is part of TelepathyQt4
+ *
+ * Copyright (C) 2008 Collabora Ltd. <http://www.collabora.co.uk/>
+ * Copyright (C) 2008 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_pending_account_h_HEADER_GUARD_
+#define _TelepathyQt4_cli_pending_account_h_HEADER_GUARD_
+
+#ifndef IN_TELEPATHY_QT4_HEADER
+#error IN_TELEPATHY_QT4_HEADER
+#endif
+
+#include <TelepathyQt4/Client/PendingOperation>
+
+#include <QString>
+#include <QVariantMap>
+
+class QDBusPendingCallWatcher;
+
+namespace Telepathy
+{
+namespace Client
+{
+
+class AccountManager;
+class Account;
+
+class PendingAccount : public PendingOperation
+{
+ Q_OBJECT
+
+public:
+ ~PendingAccount();
+
+ AccountManager *manager() const;
+ Account *account() const;
+
+private Q_SLOTS:
+ void onCallFinished(QDBusPendingCallWatcher *watcher);
+
+private:
+ Q_DISABLE_COPY(PendingAccount);
+ PendingAccount(AccountManager *manager,
+ const QString &connectionManager, const QString &protocol,
+ const QString &displayName, const QVariantMap ¶meters);
+
+ struct Private;
+ friend struct Private;
+ friend class AccountManager;
+ Private *mPriv;
+};
+
+} // Telepathy::Client
+} // Telepathy
+
+#endif
diff --git a/TelepathyQt4/Makefile.am b/TelepathyQt4/Makefile.am
index 00911d5..46ad45f 100644
--- a/TelepathyQt4/Makefile.am
+++ b/TelepathyQt4/Makefile.am
@@ -48,6 +48,7 @@ libtelepathy_qt4_la_SOURCES = \
Client/media-session-handler.cpp \
Client/media-stream-handler.cpp \
Client/optional-interface-factory.cpp \
+ Client/pending-account.cpp \
Client/pending-channel.cpp \
Client/pending-operation.cpp \
Client/pending-string-list.cpp \
@@ -88,6 +89,7 @@ nodist_libtelepathy_qt4_la_SOURCES = \
Client/_gen/connection-manager.moc.hpp \
Client/_gen/connection-manager-internal.moc.hpp \
Client/_gen/dbus-proxy.moc.hpp \
+ Client/_gen/pending-account.moc.hpp \
Client/_gen/pending-channel.moc.hpp \
Client/_gen/pending-operation.moc.hpp \
Client/_gen/pending-string-list.moc.hpp \
@@ -166,6 +168,7 @@ tpqt4clientinclude_HEADERS = \
Client/media-session-handler.h \
Client/media-stream-handler.h \
Client/optional-interface-factory.h \
+ Client/pending-account.h \
Client/pending-channel.h \
Client/pending-operation.h \
Client/pending-string-list.h \
--
1.5.6.5
More information about the Telepathy-commits
mailing list