123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- /*
- * Copyright (C) 2020 Aetf <aetf@unlimitedcodeworks.xyz>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 or (at your option)
- * version 3 of the License.
- *
- * This program 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 General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- #ifndef KEEPASSXC_FDOSECRETSPROXY_H
- #define KEEPASSXC_FDOSECRETSPROXY_H
- #include "fdosecrets/dbus/DBusTypes.h"
- #include <QtDBus>
- /**
- * Mimic the interface of QDBusPendingReply so the same code can be used in test
- */
- template <typename T> class PropertyReply
- {
- QDBusPendingReply<QDBusVariant> m_reply;
- public:
- /*implicit*/ PropertyReply(const QDBusMessage& reply)
- : m_reply(reply)
- {
- }
- bool isFinished() const
- {
- return m_reply.isFinished();
- }
- bool isValid() const
- {
- return m_reply.isValid();
- }
- bool isError() const
- {
- return m_reply.isError();
- }
- QDBusError error() const
- {
- return m_reply.error();
- }
- T value() const
- {
- return qdbus_cast<T>(m_reply.value().variant());
- }
- template <int> T argumentAt() const
- {
- return value();
- }
- };
- #define IMPL_GET_PROPERTY(name) \
- QDBusMessage msg = QDBusMessage::createMethodCall( \
- service(), path(), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("Get")); \
- msg << interface() << QStringLiteral(#name); \
- return \
- { \
- connection().call(msg, QDBus::BlockWithGui) \
- }
- #define IMPL_SET_PROPERTY(name, value) \
- QDBusMessage msg = QDBusMessage::createMethodCall( \
- service(), path(), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("Set")); \
- msg << interface() << QStringLiteral(#name) << QVariant::fromValue(QDBusVariant(QVariant::fromValue(value))); \
- return \
- { \
- connection().call(msg, QDBus::BlockWithGui) \
- }
- /*
- * Proxy class for interface org.freedesktop.Secret.Service
- */
- class ServiceProxy : public QDBusAbstractInterface
- {
- Q_OBJECT
- public:
- static inline const char* staticInterfaceName()
- {
- return "org.freedesktop.Secret.Service";
- }
- public:
- ServiceProxy(const QString& service,
- const QString& path,
- const QDBusConnection& connection,
- QObject* parent = nullptr);
- ~ServiceProxy() override;
- inline PropertyReply<QList<QDBusObjectPath>> collections() const
- {
- IMPL_GET_PROPERTY(Collections);
- }
- public Q_SLOTS: // METHODS
- inline QDBusPendingReply<QDBusObjectPath, QDBusObjectPath> CreateCollection(const QVariantMap& properties,
- const QString& alias)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(properties) << QVariant::fromValue(alias);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("CreateCollection"), argumentList)};
- }
- inline QDBusPendingReply<FdoSecrets::wire::ObjectPathSecretMap> GetSecrets(const QList<QDBusObjectPath>& items,
- const QDBusObjectPath& session)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(items) << QVariant::fromValue(session);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("GetSecrets"), argumentList)};
- }
- inline QDBusPendingReply<QList<QDBusObjectPath>, QDBusObjectPath> Lock(const QList<QDBusObjectPath>& paths)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(paths);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Lock"), argumentList)};
- }
- inline QDBusPendingReply<QDBusVariant, QDBusObjectPath> OpenSession(const QString& algorithm,
- const QDBusVariant& input)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(algorithm) << QVariant::fromValue(input);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("OpenSession"), argumentList)};
- }
- inline QDBusPendingReply<QDBusObjectPath> ReadAlias(const QString& name)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(name);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("ReadAlias"), argumentList)};
- }
- inline QDBusPendingReply<QList<QDBusObjectPath>, QList<QDBusObjectPath>>
- SearchItems(FdoSecrets::wire::StringStringMap attributes)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(attributes);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("SearchItems"), argumentList)};
- }
- inline QDBusPendingReply<> SetAlias(const QString& name, const QDBusObjectPath& collection)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(name) << QVariant::fromValue(collection);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("SetAlias"), argumentList)};
- }
- inline QDBusPendingReply<QList<QDBusObjectPath>, QDBusObjectPath> Unlock(const QList<QDBusObjectPath>& paths)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(paths);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Unlock"), argumentList)};
- }
- Q_SIGNALS: // SIGNALS
- void CollectionChanged(const QDBusObjectPath& collection);
- void CollectionCreated(const QDBusObjectPath& collection);
- void CollectionDeleted(const QDBusObjectPath& collection);
- };
- /*
- * Proxy class for interface org.freedesktop.Secret.Collection
- */
- class CollectionProxy : public QDBusAbstractInterface
- {
- Q_OBJECT
- public:
- static inline const char* staticInterfaceName()
- {
- return "org.freedesktop.Secret.Collection";
- }
- public:
- CollectionProxy(const QString& service,
- const QString& path,
- const QDBusConnection& connection,
- QObject* parent = nullptr);
- ~CollectionProxy() override;
- inline PropertyReply<qulonglong> created() const
- {
- IMPL_GET_PROPERTY(Created);
- }
- inline PropertyReply<QList<QDBusObjectPath>> items() const
- {
- IMPL_GET_PROPERTY(Items);
- }
- inline PropertyReply<QString> label() const
- {
- IMPL_GET_PROPERTY(Label);
- }
- inline QDBusPendingReply<> setLabel(const QString& value)
- {
- IMPL_SET_PROPERTY(Label, value);
- }
- inline PropertyReply<bool> locked() const
- {
- IMPL_GET_PROPERTY(Locked);
- }
- inline PropertyReply<qulonglong> modified() const
- {
- IMPL_GET_PROPERTY(Modified);
- }
- public Q_SLOTS: // METHODS
- inline QDBusPendingReply<QDBusObjectPath, QDBusObjectPath>
- CreateItem(const QVariantMap& properties, FdoSecrets::wire::Secret secret, bool replace)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(properties) << QVariant::fromValue(secret) << QVariant::fromValue(replace);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("CreateItem"), argumentList)};
- }
- inline QDBusPendingReply<QDBusObjectPath> Delete()
- {
- QList<QVariant> argumentList;
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Delete"), argumentList)};
- }
- inline QDBusPendingReply<QList<QDBusObjectPath>> SearchItems(FdoSecrets::wire::StringStringMap attributes)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(attributes);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("SearchItems"), argumentList)};
- }
- Q_SIGNALS: // SIGNALS
- void ItemChanged(const QDBusObjectPath& item);
- void ItemCreated(const QDBusObjectPath& item);
- void ItemDeleted(const QDBusObjectPath& item);
- };
- /*
- * Proxy class for interface org.freedesktop.Secret.Item
- */
- class ItemProxy : public QDBusAbstractInterface
- {
- Q_OBJECT
- public:
- static inline const char* staticInterfaceName()
- {
- return "org.freedesktop.Secret.Item";
- }
- public:
- ItemProxy(const QString& service,
- const QString& path,
- const QDBusConnection& connection,
- QObject* parent = nullptr);
- ~ItemProxy() override;
- inline PropertyReply<FdoSecrets::wire::StringStringMap> attributes() const
- {
- IMPL_GET_PROPERTY(Attributes);
- }
- inline QDBusPendingReply<> setAttributes(FdoSecrets::wire::StringStringMap value)
- {
- IMPL_SET_PROPERTY(Attributes, value);
- }
- inline PropertyReply<qulonglong> created() const
- {
- IMPL_GET_PROPERTY(Created);
- }
- inline PropertyReply<QString> label() const
- {
- IMPL_GET_PROPERTY(Label);
- }
- inline QDBusPendingReply<> setLabel(const QString& value)
- {
- IMPL_SET_PROPERTY(Label, value);
- }
- inline PropertyReply<bool> locked() const
- {
- IMPL_GET_PROPERTY(Locked);
- }
- inline PropertyReply<qulonglong> modified() const
- {
- IMPL_GET_PROPERTY(Modified);
- }
- public Q_SLOTS: // METHODS
- inline QDBusPendingReply<QDBusObjectPath> Delete()
- {
- QList<QVariant> argumentList;
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Delete"), argumentList)};
- }
- inline QDBusPendingReply<FdoSecrets::wire::Secret> GetSecret(const QDBusObjectPath& session)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(session);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("GetSecret"), argumentList)};
- }
- inline QDBusPendingReply<> SetSecret(FdoSecrets::wire::Secret secret)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(secret);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("SetSecret"), argumentList)};
- }
- Q_SIGNALS: // SIGNALS
- };
- /*
- * Proxy class for interface org.freedesktop.Secret.Session
- */
- class SessionProxy : public QDBusAbstractInterface
- {
- Q_OBJECT
- public:
- static inline const char* staticInterfaceName()
- {
- return "org.freedesktop.Secret.Session";
- }
- public:
- SessionProxy(const QString& service,
- const QString& path,
- const QDBusConnection& connection,
- QObject* parent = nullptr);
- ~SessionProxy() override;
- public Q_SLOTS: // METHODS
- inline QDBusPendingReply<> Close()
- {
- QList<QVariant> argumentList;
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Close"), argumentList)};
- }
- Q_SIGNALS: // SIGNALS
- };
- /*
- * Proxy class for interface org.freedesktop.Secret.Prompt
- */
- class PromptProxy : public QDBusAbstractInterface
- {
- Q_OBJECT
- public:
- static inline const char* staticInterfaceName()
- {
- return "org.freedesktop.Secret.Prompt";
- }
- public:
- PromptProxy(const QString& service,
- const QString& path,
- const QDBusConnection& connection,
- QObject* parent = nullptr);
- ~PromptProxy() override;
- public Q_SLOTS: // METHODS
- inline QDBusPendingReply<> Dismiss()
- {
- QList<QVariant> argumentList;
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Dismiss"), argumentList)};
- }
- inline QDBusPendingReply<> Prompt(const QString& windowId)
- {
- QList<QVariant> argumentList;
- argumentList << QVariant::fromValue(windowId);
- return {callWithArgumentList(QDBus::BlockWithGui, QStringLiteral("Prompt"), argumentList)};
- }
- Q_SIGNALS: // SIGNALS
- void Completed(bool dismissed, const QDBusVariant& result);
- };
- #undef IMPL_GET_PROPERTY
- #undef IMPL_SET_PROPERTY
- #endif // KEEPASSXC_FDOSECRETSPROXY_H
|