| 1 |
/* |
| 2 |
* Copyright (C) 2013 Francois Ferrand |
| 3 |
* Copyright (C) 2017 KeePassXC Team <[email protected]> |
| 4 |
* Copyright (C) 2020 Aetf <[email protected]> |
| 5 |
* |
| 6 |
* This program is free software: you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU General Public License as published by |
| 8 |
* the Free Software Foundation, either version 3 of the License, or |
| 9 |
* (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef KEEPASSXC_FDOSECRETS_ACCESSCONTROLDIALOG_H |
| 21 |
#define KEEPASSXC_FDOSECRETS_ACCESSCONTROLDIALOG_H |
| 22 |
|
| 23 |
#include <QAbstractTableModel> |
| 24 |
#include <QCheckBox> |
| 25 |
#include <QDialog> |
| 26 |
#include <QPointer> |
| 27 |
#include <QPushButton> |
| 28 |
#include <QSet> |
| 29 |
|
| 30 |
#include "core/Global.h" |
| 31 |
|
| 32 |
class Entry; |
| 33 |
|
| 34 |
namespace Ui |
| 35 |
{ |
| 36 |
class AccessControlDialog; |
| 37 |
} |
| 38 |
|
| 39 |
namespace FdoSecrets |
| 40 |
{ |
| 41 |
struct PeerInfo; |
| 42 |
} |
| 43 |
|
| 44 |
enum class AuthOption |
| 45 |
{ |
| 46 |
None = 0, |
| 47 |
Remember = 1 << 1, |
| 48 |
PerEntryDeny = 1 << 2, |
| 49 |
}; |
| 50 |
Q_DECLARE_FLAGS(AuthOptions, AuthOption); |
| 51 |
Q_DECLARE_OPERATORS_FOR_FLAGS(AuthOptions); |
| 52 |
|
| 53 |
class AccessControlDialog : public QDialog |
| 54 |
{ |
| 55 |
Q_OBJECT |
| 56 |
|
| 57 |
public: |
| 58 |
explicit AccessControlDialog(QWindow* parent, |
| 59 |
const QList<Entry*>& entries, |
| 60 |
const QString& app, |
| 61 |
const FdoSecrets::PeerInfo& info, |
| 62 |
AuthOptions authOptions = AuthOption::Remember | AuthOption::PerEntryDeny); |
| 63 |
~AccessControlDialog() override; |
| 64 |
|
| 65 |
enum DialogCode |
| 66 |
{ |
| 67 |
Rejected, |
| 68 |
AllowSelected, |
| 69 |
AllowAll, |
| 70 |
DenyAll, |
| 71 |
}; |
| 72 |
|
| 73 |
QHash<Entry*, AuthDecision> decisions() const; |
| 74 |
|
| 75 |
signals: |
| 76 |
void finished(const QHash<Entry*, AuthDecision>& results, AuthDecision forFutureEntries); |
| 77 |
|
| 78 |
private slots: |
| 79 |
void denyEntryClicked(Entry* entry, const QModelIndex& index); |
| 80 |
void dialogFinished(int result); |
| 81 |
|
| 82 |
private: |
| 83 |
class EntryModel; |
| 84 |
class DenyButton; |
| 85 |
|
| 86 |
void setupDetails(const FdoSecrets::PeerInfo& info); |
| 87 |
|
| 88 |
QScopedPointer<Ui::AccessControlDialog> m_ui; |
| 89 |
QPointer<QCheckBox> m_rememberCheck; |
| 90 |
QScopedPointer<EntryModel> m_model; |
| 91 |
QHash<Entry*, AuthDecision> m_decisions; |
| 92 |
}; |
| 93 |
|
| 94 |
class AccessControlDialog::EntryModel : public QAbstractTableModel |
| 95 |
{ |
| 96 |
Q_OBJECT |
| 97 |
public: |
| 98 |
explicit EntryModel(QList<Entry*> entries, QObject* parent = nullptr); |
| 99 |
|
| 100 |
int rowCount(const QModelIndex& parent) const override; |
| 101 |
int columnCount(const QModelIndex& parent) const override; |
| 102 |
QVariant data(const QModelIndex& index, int role) const override; |
| 103 |
bool removeRows(int row, int count, const QModelIndex& parent) override; |
| 104 |
|
| 105 |
public slots: |
| 106 |
void toggleCheckState(const QModelIndex& index); |
| 107 |
|
| 108 |
private: |
| 109 |
bool isValid(const QModelIndex& index) const; |
| 110 |
|
| 111 |
QList<Entry*> m_entries; |
| 112 |
QSet<Entry*> m_selected; |
| 113 |
}; |
| 114 |
|
| 115 |
class AccessControlDialog::DenyButton : public QPushButton |
| 116 |
{ |
| 117 |
Q_OBJECT |
| 118 |
|
| 119 |
Q_PROPERTY(Entry* entry READ entry WRITE setEntry USER true) |
| 120 |
|
| 121 |
QPersistentModelIndex m_index; |
| 122 |
QPointer<Entry> m_entry; |
| 123 |
|
| 124 |
public: |
| 125 |
explicit DenyButton(QWidget* p, const QModelIndex& idx); |
| 126 |
|
| 127 |
void setEntry(Entry* e); |
| 128 |
Entry* entry() const; |
| 129 |
|
| 130 |
signals: |
| 131 |
void clicked(Entry*, const QModelIndex& idx); |
| 132 |
}; |
| 133 |
|
| 134 |
#endif // KEEPASSXC_FDOSECRETS_ACCESSCONTROLDIALOG_H |