[Telepathy-commits] [telepathy-qt4/master] ConnectionManager: add client API to get at CM parameters
Simon McVittie
simon.mcvittie at collabora.co.uk
Mon Dec 8 08:54:34 PST 2008
---
TelepathyQt4/cli-connection-manager.cpp | 166 +++++++++++++++++++++++++++++--
TelepathyQt4/cli-connection-manager.h | 134 +++++++++++++++++++++++++-
2 files changed, 291 insertions(+), 9 deletions(-)
diff --git a/TelepathyQt4/cli-connection-manager.cpp b/TelepathyQt4/cli-connection-manager.cpp
index f46c5c1..38ed616 100644
--- a/TelepathyQt4/cli-connection-manager.cpp
+++ b/TelepathyQt4/cli-connection-manager.cpp
@@ -37,16 +37,125 @@ namespace Client
{
+struct ProtocolInfo::Private
+{
+ QString cmName;
+ QString protocolName;
+
+ QMap<QString,QDBusSignature> parameters;
+ QMap<QString,QVariant> defaults;
+ QSet<QString> requiredParameters;
+ QSet<QString> registerParameters;
+ QSet<QString> propertyParameters;
+ QSet<QString> secretParameters;
+
+ Private(const QString& cmName, const QString& protocolName)
+ : cmName(cmName), protocolName(protocolName)
+ {
+ }
+};
+
+
+ProtocolInfo::ProtocolInfo(const QString& cmName, const QString& protocol)
+ : mPriv(new Private(cmName, protocol))
+{
+}
+
+
+ProtocolInfo::~ProtocolInfo()
+{
+}
+
+
+QString ProtocolInfo::cmName() const
+{
+ return mPriv->cmName;
+}
+
+
+QString ProtocolInfo::protocolName() const
+{
+ return mPriv->protocolName;
+}
+
+
+QStringList ProtocolInfo::parameters() const
+{
+ return mPriv->parameters.keys();
+}
+
+
+bool ProtocolInfo::hasParameter(const QString& param) const
+{
+ return mPriv->parameters.contains(param);
+}
+
+
+QDBusSignature ProtocolInfo::parameterDBusSignature(const QString& param) const
+{
+ return mPriv->parameters.value(param);
+}
+
+
+QVariant::Type ProtocolInfo::parameterType(const QString& param) const
+{
+ return QVariant::Invalid;
+}
+
+
+bool ProtocolInfo::parameterIsRequired(const QString& param,
+ bool registering) const
+{
+ if (registering)
+ return mPriv->registerParameters.contains(param);
+ else
+ return mPriv->requiredParameters.contains(param);
+}
+
+
+bool ProtocolInfo::parameterIsSecret(const QString& param) const
+{
+ return mPriv->secretParameters.contains(param);
+}
+
+
+bool ProtocolInfo::parameterIsDBusProperty(const QString& param) const
+{
+ return mPriv->propertyParameters.contains(param);
+}
+
+
+bool ProtocolInfo::parameterHasDefault(const QString& param) const
+{
+ return mPriv->defaults.contains(param);
+}
+
+
+QVariant ProtocolInfo::getParameterDefault(const QString& param) const
+{
+ return mPriv->defaults.value(param);
+}
+
+
+bool ProtocolInfo::canRegister() const
+{
+ return hasParameter(QLatin1String("register"));
+}
+
+
struct ConnectionManager::Private
{
ConnectionManager& parent;
+ QString cmName;
ConnectionManagerInterface* baseInterface;
bool ready;
QQueue<void (Private::*)()> introspectQueue;
+ QQueue<QString> getParametersQueue;
QQueue<QString> protocolQueue;
QStringList interfaces;
- QStringList protocols;
+
+ QMap<QString,ProtocolInfo*> protocols;
static inline QString makeBusName(const QString& name)
{
@@ -80,7 +189,8 @@ struct ConnectionManager::Private
void callGetParameters()
{
- QString protocol = protocolQueue.dequeue();
+ QString protocol = getParametersQueue.dequeue();
+ protocolQueue.enqueue(protocol);
debug() << "Calling ConnectionManager::GetParameters(" <<
protocol << ")";
QDBusPendingCallWatcher* watcher = new QDBusPendingCallWatcher(
@@ -100,8 +210,9 @@ struct ConnectionManager::Private
SLOT(onListProtocolsReturn(QDBusPendingCallWatcher*)));
}
- Private(ConnectionManager& parent)
+ Private(ConnectionManager& parent, QString name)
: parent(parent),
+ cmName(name),
baseInterface(new ConnectionManagerInterface(parent.dbusConnection(),
parent.busName(), parent.objectPath(), &parent)),
ready(false)
@@ -119,7 +230,7 @@ ConnectionManager::ConnectionManager(const QString& name, QObject* parent)
: StatelessDBusProxy(QDBusConnection::sessionBus(),
Private::makeBusName(name), Private::makeObjectPath(name),
parent),
- mPriv(new Private(*this))
+ mPriv(new Private(*this, name))
{
}
@@ -128,7 +239,7 @@ ConnectionManager::ConnectionManager(const QDBusConnection& bus,
const QString& name, QObject* parent)
: StatelessDBusProxy(bus, Private::makeBusName(name),
Private::makeObjectPath(name), parent),
- mPriv(new Private(*this))
+ mPriv(new Private(*this, name))
{
}
@@ -139,6 +250,12 @@ ConnectionManager::~ConnectionManager()
}
+QString ConnectionManager::cmName() const
+{
+ return mPriv->cmName;
+}
+
+
QStringList ConnectionManager::interfaces() const
{
return mPriv->interfaces;
@@ -147,7 +264,14 @@ QStringList ConnectionManager::interfaces() const
QStringList ConnectionManager::supportedProtocols() const
{
- return mPriv->protocols;
+ return mPriv->protocols.keys();
+}
+
+
+const ProtocolInfo* ConnectionManager::protocolInfo(
+ const QString& protocol) const
+{
+ return mPriv->protocols.value(protocol);
}
@@ -202,9 +326,11 @@ void ConnectionManager::onListProtocolsReturn(
reply.error().name() << ": " << reply.error().message();
}
- mPriv->protocols = protocols;
Q_FOREACH (const QString& protocol, protocols) {
- mPriv->protocolQueue.enqueue(protocol);
+ mPriv->protocols.insert(protocol, new ProtocolInfo(mPriv->cmName,
+ protocol));
+
+ mPriv->getParametersQueue.enqueue(protocol);
mPriv->introspectQueue.enqueue(&Private::callGetParameters);
}
continueIntrospection();
@@ -216,6 +342,8 @@ void ConnectionManager::onGetParametersReturn(
{
QDBusPendingReply<ParamSpecList> reply = *watcher;
ParamSpecList parameters;
+ QString protocol = mPriv->protocolQueue.dequeue();
+ ProtocolInfo* info = mPriv->protocols.value(protocol);
if (!reply.isError()) {
debug() << "Got reply to ConnectionManager.GetParameters";
@@ -229,6 +357,28 @@ void ConnectionManager::onGetParametersReturn(
Q_FOREACH (const ParamSpec& spec, parameters) {
debug() << "Parameter" << spec.name << "has flags" << spec.flags
<< "and signature" << spec.signature;
+ info->mPriv->parameters.insert(spec.name,
+ QDBusSignature(spec.signature));
+
+ if (spec.flags & ConnMgrParamFlagHasDefault)
+ info->mPriv->defaults.insert(spec.name,
+ spec.defaultValue.variant());
+
+ if (spec.flags & ConnMgrParamFlagRequired)
+ info->mPriv->requiredParameters.insert(spec.name);
+
+ if (spec.flags & ConnMgrParamFlagRegister)
+ info->mPriv->registerParameters.insert(spec.name);
+
+ if ((spec.flags & ConnMgrParamFlagSecret)
+ || spec.name.endsWith("password"))
+ info->mPriv->secretParameters.insert(spec.name);
+
+#if 0
+ // enable when we merge the new telepathy-spec
+ if (spec.flags & ConnMgrParamFlag)
+ info->mPriv->propertyParameters.insert(spec.name);
+#endif
}
continueIntrospection();
}
diff --git a/TelepathyQt4/cli-connection-manager.h b/TelepathyQt4/cli-connection-manager.h
index 3b67462..2bc3f8c 100644
--- a/TelepathyQt4/cli-connection-manager.h
+++ b/TelepathyQt4/cli-connection-manager.h
@@ -52,6 +52,136 @@ namespace Client
{
+class ProtocolInfo
+{
+public:
+ ~ProtocolInfo();
+
+ /**
+ * Get the short name of the connection manager (e.g. "gabble").
+ *
+ * \return The name of the connection manager
+ */
+ QString cmName() const;
+
+ /**
+ * Get the untranslated name of the protocol as described in the Telepathy
+ * D-Bus API Specification (e.g. "jabber").
+ */
+ QString protocolName() const;
+
+ /**
+ * Return the names of all supported parameters. The parameters' names
+ * may either be the well-known strings specified by the Telepathy D-Bus
+ * API Specification (e.g. "account" and "password"), or
+ * implementation-specific strings.
+ *
+ * \return A list of parameter names
+ */
+ QStringList parameters() const;
+
+ /**
+ * Return whether a given parameter can be passed to the connection
+ * manager when creating a connection to this protocol.
+ *
+ * \param param The name of a parameter
+ * \return true if the given parameter exists
+ */
+ bool hasParameter(const QString& param) const;
+
+ /**
+ * Return the D-Bus signature of the given parameter. Commonly used
+ * signatures include "s" (string) and "u" (32-bit unsigned integer).
+ *
+ * \return A D-Bus signature
+ */
+ QDBusSignature parameterDBusSignature(const QString& param) const;
+
+ /**
+ * Return the QVariant::Type corresponding to the D-Bus signature of
+ * the given parameter, if a suitable type is known. Otherwise return
+ * QVariant::Invalid.
+ *
+ * \param param The name of a parameter
+ * \return A QVariant type, or QVariant::Invalid
+ */
+ QVariant::Type parameterType(const QString& param) const;
+
+ /**
+ * Return whether the given parameter is required.
+ *
+ * The set of required parameters can be different depending on the value
+ * of the special parameter <code>register</code>, which indicates
+ * whether we are registering for a new account, or connecting to an
+ * existing account. Normally, <code>register</code> is false.
+ *
+ * \param param The name of a parameter
+ * \param registering The value that will be given to the special
+ * parameter <code>register</code>
+ * \return true if this parameter must always be given
+ */
+ bool parameterIsRequired(const QString& param,
+ bool registering = false) const;
+
+ /**
+ * Return whether this parameter is marked as "secret". Secret parameters
+ * (such as passwords) should be stored in an appropriate password store
+ * (such as KWallet) rather than in normal configuration files, and should
+ * not appear in debugging logs.
+ *
+ * \param param The name of a parameter
+ * \return true if this parameter is a password, key or other secret
+ */
+ bool parameterIsSecret(const QString& param) const;
+
+ /**
+ * Return whether this parameter corresponds to a D-Bus property with
+ * the same name. These parameters should be handled specially by the
+ * AccountManager.
+ *
+ * \param param The name of a parameter
+ * \return true if this parameter is a D-Bus property
+ */
+ bool parameterIsDBusProperty(const QString& param) const;
+
+ /**
+ * Return whether this parameter has a default value.
+ *
+ * \param param The name of a parameter
+ * \return true if omitting this parameter when creating a connection
+ * is equivalent to using getParameterDefault()
+ */
+ bool parameterHasDefault(const QString& param) const;
+
+ /**
+ * If parameterHasDefault() returns true for the given parameter, return
+ * the default value of the parameter. Otherwise, return an invalid
+ * variant.
+ *
+ * \param param The name of a parameter
+ * \return The default value of the given parameter, if any
+ */
+ QVariant getParameterDefault(const QString& param) const;
+
+ /**
+ * Return whether it might be possible to register new accounts on this
+ * protocol via Telepathy, by setting the special parameter named
+ * <code>register</code> to <code>true</code>.
+ *
+ * \return The same thing as hasParameter("register")
+ */
+ bool canRegister() const;
+
+private:
+ ProtocolInfo(const QString& cmName, const QString& protocol);
+
+ struct Private;
+ friend struct Private;
+ friend class ConnectionManager;
+ Private *mPriv;
+};
+
+
/**
* \class ConnectionManager
* \ingroup clientcm
@@ -76,11 +206,13 @@ public:
virtual ~ConnectionManager();
+ QString cmName() const;
+
QStringList interfaces() const;
QStringList supportedProtocols() const;
- // TODO: add some sort of access to protocols' parameters etc.
+ const ProtocolInfo* protocolInfo(const QString& protocol) const;
/**
* Convenience function for getting a Properties interface proxy. The
--
1.5.6.5
More information about the Telepathy-commits
mailing list