Debian Codegraph @

src/fdosecrets/widgets/SettingsModels.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_SETTINGSMODELS_H
19 #define KEEPASSXC_FDOSECRETS_SETTINGSMODELS_H
20
21 #include "fdosecrets/dbus/DBusClient.h"
22
23 #include <QAbstractTableModel>
24
25 class DatabaseTabWidget;
26 class DatabaseWidget;
27
28 namespace FdoSecrets
29 {
30 class SettingsDatabaseModel : public QAbstractTableModel
31 {
32 Q_OBJECT
33 public:
34 explicit SettingsDatabaseModel(DatabaseTabWidget* dbTabs, QObject* parent = nullptr);
35
36 void setTabWidget(DatabaseTabWidget* dbTabs);
37
38 int rowCount(const QModelIndex& parent) const override;
39 int columnCount(const QModelIndex& parent) const override;
40 QVariant data(const QModelIndex& index, int role) const override;
41 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
42
43 enum Column
44 {
45 ColumnFileName,
46 ColumnGroup,
47 ColumnManage,
48 };
49 static constexpr const char* ColumnNames[] = {
50 QT_TRANSLATE_NOOP("SettingsDatabaseModel", "File Name"),
51 QT_TRANSLATE_NOOP("SettingsDatabaseModel", "Group"),
52 QT_TRANSLATE_NOOP("SettingsDatabaseModel", "Manage"),
53 };
54
55 private:
56 QVariant dataForName(DatabaseWidget* db, int role) const;
57 static QVariant dataForExposedGroup(DatabaseWidget* db, int role);
58 QVariant dataForManage(DatabaseWidget* db, int role) const;
59
60 private slots:
61 void populateModel();
62 void databaseAdded(DatabaseWidget* db, bool emitSignals);
63 void databaseRemoved(const QString& filePath);
64
65 private:
66 // source
67 QPointer<DatabaseTabWidget> m_dbTabs;
68
69 // internal store
70 QList<QPointer<DatabaseWidget>> m_dbs;
71 };
72
73 class DBusMgr;
74
75 class SettingsClientModel : public QAbstractTableModel
76 {
77 Q_OBJECT
78 public:
79 explicit SettingsClientModel(DBusMgr& dbus, QObject* parent = nullptr);
80
81 int rowCount(const QModelIndex& parent) const override;
82 int columnCount(const QModelIndex& parent) const override;
83 QVariant data(const QModelIndex& index, int role) const override;
84 QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
85
86 enum Column
87 {
88 ColumnApplication,
89 ColumnPID,
90 ColumnDBus,
91 ColumnManage,
92 };
93 static constexpr const char* ColumnNames[] = {
94 QT_TRANSLATE_NOOP("SettingsClientModel", "Application"),
95 QT_TRANSLATE_NOOP("SettingsClientModel", "PID"),
96 QT_TRANSLATE_NOOP("SettingsClientModel", "DBus Address"),
97 QT_TRANSLATE_NOOP("SettingsClientModel", "Manage"),
98 };
99
100 private:
101 QVariant dataForApplication(const DBusClientPtr& client, int role) const;
102 QVariant dataForPID(const DBusClientPtr& client, int role) const;
103 QVariant dataForDBus(const DBusClientPtr& client, int role) const;
104 QVariant dataForManage(const DBusClientPtr& client, int role) const;
105
106 private slots:
107 void populateModel();
108 void clientConnected(const DBusClientPtr& client, bool emitSignals);
109 void clientDisconnected(const DBusClientPtr& client);
110
111 private:
112 // source
113 DBusMgr& m_dbus;
114
115 // internal copy, so we can emit with changed index
116 QList<DBusClientPtr> m_clients;
117 };
118
119 } // namespace FdoSecrets
120
121 #endif // KEEPASSXC_FDOSECRETS_SETTINGSMODELS_H