Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Service.h « objects « fdosecrets « src - github.com/keepassxreboot/keepassxc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5de48da1cd5752ff3ed0c1fe37c210d70358a441 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 *  Copyright (C) 2018 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_FDOSECRETS_SERVICE_H
#define KEEPASSXC_FDOSECRETS_SERVICE_H

#include "fdosecrets/objects/DBusObject.h"
#include "fdosecrets/objects/adaptors/ServiceAdaptor.h"

#include <QHash>
#include <QObject>
#include <QPointer>
#include <QScopedPointer>
#include <QVariant>

class QDBusServiceWatcher;

class DatabaseTabWidget;
class DatabaseWidget;
class Group;

class FdoSecretsPlugin;

namespace FdoSecrets
{

    class Collection;
    class Item;
    class PromptBase;
    class ServiceAdaptor;
    class Session;

    class Service : public DBusObject // clazy: exclude=ctor-missing-parent-argument
    {
        Q_OBJECT
    public:
        explicit Service(FdoSecretsPlugin* plugin, QPointer<DatabaseTabWidget> dbTabs);
        ~Service() override;

        bool initialize();

        DBusReturn<QVariant> openSession(const QString& algorithm, const QVariant& input, Session*& result);
        DBusReturn<Collection*>
        createCollection(const QVariantMap& properties, const QString& alias, PromptBase*& prompt);
        DBusReturn<const QList<Item*>> searchItems(const StringStringMap& attributes, QList<Item*>& locked);

        DBusReturn<const QList<DBusObject*>> unlock(const QList<DBusObject*>& objects, PromptBase*& prompt);

        DBusReturn<const QList<DBusObject*>> lock(const QList<DBusObject*>& objects, PromptBase*& prompt);

        DBusReturn<const QHash<Item*, SecretStruct>> getSecrets(const QList<Item*>& items, Session* session);

        DBusReturn<Collection*> readAlias(const QString& name);

        DBusReturn<void> setAlias(const QString& name, Collection* collection);

        /**
         * List of collections
         * @return
         */
        DBusReturn<const QList<Collection*>> collections() const;

    signals:
        void collectionCreated(Collection* collection);
        void collectionDeleted(Collection* collection);
        void collectionChanged(Collection* collection);

        void sessionOpened(Session* sess);
        void sessionClosed(Session* sess);

        /**
         * Report error message to the GUI
         * @param msg
         */
        void error(const QString& msg);

        /**
         * Finish signal for async action doUnlockDatabaseInDialog
         * @param accepted If false, the action is canceled by the user
         * @param dbWidget The unlocked the dbWidget if succeed
         */
        void doneUnlockDatabaseInDialog(bool accepted, DatabaseWidget* dbWidget);

    public:
        /**
         * List of sessions
         * @return
         */
        const QList<Session*> sessions() const;

        FdoSecretsPlugin* plugin() const
        {
            return m_plugin;
        }

    public slots:
        bool doCloseDatabase(DatabaseWidget* dbWidget);
        Collection* doNewDatabase();
        void doSwitchToChangeDatabaseSettings(DatabaseWidget* dbWidget);

        /**
         * Async, connect to signal doneUnlockDatabaseInDialog for finish notification
         * @param dbWidget
         */
        void doUnlockDatabaseInDialog(DatabaseWidget* dbWidget);

    private slots:
        void dbusServiceUnregistered(const QString& service);
        void ensureDefaultAlias();

        void onDatabaseTabOpened(DatabaseWidget* dbWidget, bool emitSignal);
        void monitorDatabaseExposedGroup(DatabaseWidget* dbWidget);

        void onCollectionAliasAboutToAdd(const QString& alias);
        void onCollectionAliasAdded(const QString& alias);

        void onCollectionAliasRemoved(const QString& alias);

    private:
        /**
         * Find collection by alias name
         * @param alias
         * @return the collection under alias
         */
        Collection* findCollection(const QString& alias) const;

        /**
         * Find collection by dbWidget
         * @param db
         * @return the collection corresponding to the db
         */
        Collection* findCollection(const DatabaseWidget* db) const;

    private:
        FdoSecretsPlugin* m_plugin;
        QPointer<DatabaseTabWidget> m_databases;

        QHash<QString, Collection*> m_aliases;
        QList<Collection*> m_collections;
        QHash<const DatabaseWidget*, Collection*> m_dbToCollection;

        QList<Session*> m_sessions;
        QHash<QString, Session*> m_peerToSession;

        bool m_insdieEnsureDefaultAlias;

        QScopedPointer<QDBusServiceWatcher> m_serviceWatcher;
    };

} // namespace FdoSecrets

#endif // KEEPASSXC_FDOSECRETS_SERVICE_H