forked from hluk/CopyQ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
itemencrypted.h
146 lines (99 loc) · 3.45 KB
/
itemencrypted.h
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
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef ITEMENCRYPTED_H
#define ITEMENCRYPTED_H
#include "item/itemwidget.h"
#include "gui/icons.h"
#include <QProcess>
#include <QVariant>
#include <QWidget>
#include <memory>
namespace Ui {
class ItemEncryptedSettings;
}
class QIODevice;
class ItemEncrypted final : public QWidget, public ItemWidget
{
Q_OBJECT
public:
explicit ItemEncrypted(QWidget *parent);
};
class ItemEncryptedSaver final : public QObject, public ItemSaverInterface
{
Q_OBJECT
public:
bool saveItems(const QString &tabName, const QAbstractItemModel &model, QIODevice *file) override;
signals:
void error(const QString &);
private:
void emitEncryptFailed();
};
class ItemEncryptedScriptable final : public ItemScriptable
{
Q_OBJECT
public slots:
bool isEncrypted();
QByteArray encrypt();
QByteArray decrypt();
void encryptItem();
void decryptItem();
void encryptItems();
void decryptItems();
void copyEncryptedItems();
void pasteEncryptedItems();
QString generateTestKeys();
bool isGpgInstalled();
private:
QByteArray encrypt(const QByteArray &bytes);
QByteArray decrypt(const QByteArray &bytes);
};
class ItemEncryptedLoader final : public QObject, public ItemLoaderInterface
{
Q_OBJECT
Q_PLUGIN_METADATA(IID COPYQ_PLUGIN_ITEM_LOADER_ID)
Q_INTERFACES(ItemLoaderInterface)
public:
ItemEncryptedLoader();
~ItemEncryptedLoader();
ItemWidget *create(const QVariantMap &data, QWidget *parent, bool) const override;
QString id() const override { return "itemencrypted"; }
QString name() const override { return tr("Encryption"); }
QString author() const override { return QString(); }
QString description() const override { return tr("Encrypt items and tabs."); }
QVariant icon() const override { return QVariant(IconLock); }
QStringList formatsToSave() const override;
void applySettings(QSettings &settings) override;
void loadSettings(const QSettings &settings) override;
QWidget *createSettingsWidget(QWidget *parent) override;
bool canLoadItems(QIODevice *file) const override;
bool canSaveItems(const QString &tabName) const override;
ItemSaverPtr loadItems(const QString &tabName, QAbstractItemModel *model, QIODevice *file, int maxItems) override;
ItemSaverPtr initializeTab(const QString &, QAbstractItemModel *model, int maxItems) override;
QObject *tests(const TestInterfacePtr &test) const override;
const QObject *signaler() const override { return this; }
ItemScriptable *scriptableObject() override;
QVector<Command> commands() const override;
bool data(QVariantMap *data, const QModelIndex &) const override;
bool setData(const QVariantMap &data, const QModelIndex &index, QAbstractItemModel *model) const override;
signals:
void error(const QString &);
private:
void setPassword();
void terminateGpgProcess();
void onGpgProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
enum GpgProcessStatus {
GpgCheckIfInstalled,
GpgNotInstalled,
GpgNotRunning,
GpgGeneratingKeys,
GpgChangingPassword
};
void updateUi();
void emitDecryptFailed();
ItemSaverPtr createSaver();
GpgProcessStatus status() const;
std::unique_ptr<Ui::ItemEncryptedSettings> ui;
QStringList m_encryptTabs;
mutable GpgProcessStatus m_gpgProcessStatus;
QProcess *m_gpgProcess;
};
#endif // ITEMENCRYPTED_H