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 _KWALLETFREEDESKTOPITEM_H_
0008 #define _KWALLETFREEDESKTOPITEM_H_
0009 #include "kwalletfreedesktopservice.h"
0010 
0011 static inline constexpr auto FDO_SS_MAGICK = 0x4950414f44465353ULL;
0012 
0013 class KWalletD;
0014 class KWalletFreedesktopCollection;
0015 
0016 class KWalletFreedesktopItem : public QObject, protected FDO_DBUS_CONTEXT
0017 {
0018     /* org.freedesktop.Secret.Item properties */
0019 public:
0020     Q_PROPERTY(StrStrMap Attributes READ attributes WRITE setAttributes)
0021     StrStrMap attributes() const;
0022     void setAttributes(const StrStrMap &value);
0023 
0024     Q_PROPERTY(qulonglong Created READ created)
0025     qulonglong created() const;
0026 
0027     Q_PROPERTY(QString Label READ label WRITE setLabel)
0028     QString label() const;
0029     void setLabel(const QString &value);
0030 
0031     Q_PROPERTY(bool Locked READ locked)
0032     bool locked() const;
0033 
0034     Q_PROPERTY(qulonglong Modified READ modified)
0035     qulonglong modified() const;
0036 
0037     Q_PROPERTY(QString Type READ type WRITE setType)
0038     QString type() const;
0039     void setType(const QString &value);
0040 
0041     Q_OBJECT
0042 
0043 public:
0044     KWalletFreedesktopItem(KWalletFreedesktopCollection *collection, FdoUniqueLabel uniqLabel, QDBusObjectPath path);
0045     ~KWalletFreedesktopItem();
0046 
0047     KWalletFreedesktopItem(const KWalletFreedesktopItem &) = delete;
0048     KWalletFreedesktopItem &operator=(const KWalletFreedesktopItem &) = delete;
0049 
0050     KWalletFreedesktopItem(KWalletFreedesktopItem &&) = delete;
0051     KWalletFreedesktopItem &operator=(KWalletFreedesktopItem &&) = delete;
0052 
0053     KWalletFreedesktopCollection *fdoCollection() const;
0054     KWalletFreedesktopService *fdoService() const;
0055     KWalletD *backend() const;
0056     QDBusObjectPath fdoObjectPath() const;
0057     const FdoUniqueLabel &uniqueLabel() const;
0058     void uniqueLabel(const FdoUniqueLabel &uniqLabel);
0059 
0060     /*
0061     QVariantMap readMap() const;
0062     void writeMap(const QVariantMap &data);
0063     */
0064 
0065     FreedesktopSecret getSecret(const QDBusConnection &connection, const QDBusMessage &message, const QDBusObjectPath &session);
0066     void setDeleted();
0067 
0068     /* Emitters */
0069     void onPropertiesChanged(const QVariantMap &properties);
0070     void enableFdoFormat();
0071 
0072 private:
0073     KWalletFreedesktopCollection *m_collection;
0074     FdoUniqueLabel m_uniqueLabel;
0075     QDBusObjectPath m_path;
0076     bool m_wasDeleted = false;
0077 
0078     /* Freedesktop API */
0079 
0080     /* org.freedesktop.Secret.Item methods */
0081 public Q_SLOTS:
0082     QDBusObjectPath Delete();
0083     FreedesktopSecret GetSecret(const QDBusObjectPath &session);
0084     void SetSecret(const FreedesktopSecret &secret);
0085 };
0086 
0087 #endif