Debian Codegraph @

src/fdosecrets/objects/Item.h

raw
1 /*
2 * Copyright (C) 2019 Aetf <[email protected]>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 or (at your option)
7 * version 3 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef KEEPASSXC_FDOSECRETS_ITEM_H
19 #define KEEPASSXC_FDOSECRETS_ITEM_H
20
21 #include "fdosecrets/dbus/DBusClient.h"
22 #include "fdosecrets/dbus/DBusObject.h"
23
24 class Entry;
25
26 namespace FdoSecrets
27 {
28
29 namespace ItemAttributes
30 {
31 constexpr const auto UuidKey = "Uuid";
32 constexpr const auto PathKey = "Path";
33 constexpr const auto TotpKey = "TOTP";
34 } // namespace ItemAttributes
35
36 class Session;
37 class Collection;
38 class PromptBase;
39
40 class Item : public DBusObject
41 {
42 Q_OBJECT
43 Q_CLASSINFO("D-Bus Interface", DBUS_INTERFACE_SECRET_ITEM_LITERAL)
44
45 explicit Item(Collection* parent, Entry* backend);
46
47 public:
48 /**
49 * @brief Create a new instance of `Item`.
50 * @param parent the owning `Collection`
51 * @param backend the `Entry` containing the data
52 * @return pointer to newly created Item, or nullptr if error
53 * This may be caused by
54 * - DBus path registration error
55 */
56 static Item* Create(Collection* parent, Entry* backend);
57
58 Q_INVOKABLE DBUS_PROPERTY DBusResult locked(const DBusClientPtr& client, bool& locked) const;
59
60 Q_INVOKABLE DBUS_PROPERTY DBusResult attributes(StringStringMap& attrs) const;
61 Q_INVOKABLE DBusResult setAttributes(const StringStringMap& attrs);
62
63 Q_INVOKABLE DBUS_PROPERTY DBusResult label(QString& label) const;
64 Q_INVOKABLE DBusResult setLabel(const QString& label);
65
66 Q_INVOKABLE DBUS_PROPERTY DBusResult created(qulonglong& created) const;
67
68 Q_INVOKABLE DBUS_PROPERTY DBusResult modified(qulonglong& modified) const;
69
70 Q_INVOKABLE DBusResult remove(PromptBase*& prompt);
71 Q_INVOKABLE DBusResult getSecret(const DBusClientPtr& client, Session* session, Secret& secret);
72 Q_INVOKABLE DBusResult setSecret(const DBusClientPtr& client, const Secret& secret);
73
74 signals:
75 void itemChanged();
76 void itemAboutToDelete();
77
78 public:
79 static const QSet<QString> ReadOnlyAttributes;
80
81 DBusResult getSecretNoNotification(const DBusClientPtr& client, Session* session, Secret& secret) const;
82 DBusResult setProperties(const QVariantMap& properties);
83
84 Entry* backend() const;
85 Collection* collection() const;
86 Service* service() const;
87
88 /**
89 * Compute the entry path relative to the exposed group
90 * @return the entry path
91 */
92 QString path() const;
93
94 public slots:
95 // will actually delete the entry in KPXC
96 bool doDelete();
97
98 // Only delete from dbus, will remove self. Do not affect database in KPXC
99 void removeFromDBus();
100
101 private slots:
102 /**
103 * Check if the backend is a valid object, send error reply if not.
104 * @return No error if the backend is valid.
105 */
106 DBusResult ensureBackend() const;
107
108 /**
109 * Ensure the database is unlocked, send error reply if locked.
110 * @return true if the database is locked
111 */
112 DBusResult ensureUnlocked() const;
113
114 private:
115 QPointer<Entry> m_backend;
116 };
117
118 } // namespace FdoSecrets
119 Q_DECLARE_METATYPE(FdoSecrets::ItemSecretMap);
120
121 #endif // KEEPASSXC_FDOSECRETS_ITEM_H