File indexing completed on 2024-11-24 03:41:06

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2021 Slava Aseev <nullptrnine@basealt.ru>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 #ifndef _KWALLETFREEDESKTOPCOLLECTION_H_
0008 #define _KWALLETFREEDESKTOPCOLLECTION_H_
0009 #include "kwalletfreedesktopattributes.h"
0010 #include "kwalletfreedesktopservice.h"
0011 
0012 #define FDO_SECRETS_COLLECTION_PATH FDO_SECRETS_SERVICE_OBJECT "/collection/"
0013 #define FDO_SECRETS_DEFAULT_DIR "Secret Service"
0014 #define FDO_KEY_MODIFIED QStringLiteral("$fdo_modified")
0015 #define FDO_KEY_CREATED QStringLiteral("$fdo_created")
0016 #define FDO_KEY_MIME QStringLiteral("$fdo_mime_type")
0017 #define FDO_KEY_XDG_SCHEMA QStringLiteral("xdg:schema")
0018 
0019 class KWalletFreedesktopItem;
0020 
0021 class KWalletFreedesktopCollection : public QObject, protected QDBusContext
0022 {
0023     /* org.freedesktop.Secret.Collection properties */
0024 public:
0025     Q_PROPERTY(qulonglong Created READ created)
0026     qulonglong created() const;
0027 
0028     Q_PROPERTY(qulonglong Modified READ modified)
0029     qulonglong modified() const;
0030 
0031     Q_PROPERTY(QList<QDBusObjectPath> Items READ items)
0032     QList<QDBusObjectPath> items() const;
0033 
0034     Q_PROPERTY(QString Label READ label WRITE setLabel)
0035     const QString &label() const;
0036     void setLabel(const QString &value);
0037 
0038     Q_PROPERTY(bool Locked READ locked)
0039     bool locked() const;
0040 
0041     Q_OBJECT
0042 
0043 public:
0044     KWalletFreedesktopCollection(KWalletFreedesktopService *service, int handle, const QString &walletName, QDBusObjectPath objectPath);
0045 
0046     KWalletFreedesktopCollection(const KWalletFreedesktopCollection &) = delete;
0047     KWalletFreedesktopCollection &operator=(const KWalletFreedesktopCollection &) = delete;
0048 
0049     KWalletFreedesktopCollection(KWalletFreedesktopCollection &&) = delete;
0050     KWalletFreedesktopCollection &&operator=(KWalletFreedesktopCollection &&) = delete;
0051 
0052     EntryLocation makeUniqueEntryLocation(const QString &label);
0053     FdoUniqueLabel makeUniqueItemLabel(const QString &label);
0054 
0055     QDBusObjectPath nextItemPath();
0056 
0057     KWalletFreedesktopService *fdoService() const;
0058     KWalletD *backend() const;
0059     QDBusObjectPath fdoObjectPath() const;
0060     const FdoUniqueLabel &uniqueLabel() const;
0061     QString walletName() const;
0062     int walletHandle() const;
0063 
0064     KWalletFreedesktopItem *getItemByObjectPath(const QString &objectPath) const;
0065     KWalletFreedesktopItem *findItemByEntryLocation(const EntryLocation &entryLocation) const;
0066     KWalletFreedesktopItem &pushNewItem(FdoUniqueLabel label, const QDBusObjectPath &path);
0067     KWalletFreedesktopAttributes &itemAttributes();
0068     const KWalletFreedesktopAttributes &itemAttributes() const;
0069 
0070     /* Emitters */
0071     void onWalletChangeState(int handle);
0072     void onItemCreated(const QDBusObjectPath &item);
0073     void onItemChanged(const QDBusObjectPath &item);
0074     void onItemDeleted(const QDBusObjectPath &item);
0075     void onPropertiesChanged(const QVariantMap &properties);
0076 
0077 private:
0078     KWalletFreedesktopItem &pushNewItem(const QString &label, const QDBusObjectPath &path);
0079 
0080 private:
0081     KWalletFreedesktopService *m_service;
0082     int m_handle;
0083     FdoUniqueLabel m_uniqueLabel;
0084     QDBusObjectPath m_objectPath;
0085     KWalletFreedesktopAttributes m_itemAttribs;
0086     std::map<QString, std::unique_ptr<KWalletFreedesktopItem>> m_items;
0087     uint64_t m_itemCounter = 0;
0088 
0089     /* Freedesktop API */
0090 
0091     /* org.freedesktop.Secret.Collection methods */
0092 public Q_SLOTS:
0093     QDBusObjectPath CreateItem(const PropertiesMap &properties, const FreedesktopSecret &secret, bool replace, QDBusObjectPath &prompt);
0094     QDBusObjectPath Delete();
0095     QList<QDBusObjectPath> SearchItems(const StrStrMap &attributes);
0096 
0097     /* org.freedesktop.Secret.Service signals */
0098 Q_SIGNALS:
0099     void ItemChanged(const QDBusObjectPath &item);
0100     void ItemCreated(const QDBusObjectPath &item);
0101     void ItemDeleted(const QDBusObjectPath &item);
0102 };
0103 
0104 #endif