GpgFrontend Project A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.

KeyList.h
1
29 #ifndef __KEYLIST_H__
30 #define __KEYLIST_H__
31
32 #include <utility>
33
34 #include "core/GpgContext.h"
35 #include "ui/dialog/import_export/KeyImportDetailDialog.h"
36
37 class Ui_KeyList;
38
39 namespace GpgFrontend::UI {
40
45 struct KeyListRow {
46 using KeyType = unsigned int;
47
48 static const KeyType SECRET_OR_PUBLIC_KEY = 0;
49 static const KeyType ONLY_SECRET_KEY = 1;
50 };
51
56 struct KeyListColumn {
57 using InfoType = unsigned int;
58
59 static constexpr InfoType ALL = ~0;
60 static constexpr InfoType TYPE = 1 << 0;
61 static constexpr InfoType NAME = 1 << 1;
62 static constexpr InfoType EmailAddress = 1 << 2;
63 static constexpr InfoType Usage = 1 << 3;
64 static constexpr InfoType Validity = 1 << 4;
65 static constexpr InfoType FingerPrint = 1 << 5;
66 };
67
72 struct KeyMenuAbility {
73 using AbilityType = unsigned int;
74
75 static constexpr AbilityType ALL = ~0;
76 static constexpr AbilityType NONE = 0;
77 static constexpr AbilityType REFRESH = 1 << 0;
78 static constexpr AbilityType SYNC_PUBLIC_KEY = 1 << 1;
79 static constexpr AbilityType UNCHECK_ALL = 1 << 3;
80 static constexpr AbilityType CHECK_ALL = 1 << 5;
81 };
82
87 struct KeyTable {
88 QTableWidget* key_list_;
89 KeyListRow::KeyType select_type_;
90 KeyListColumn::InfoType info_type_;
91 std::vector<GpgKey> buffered_keys_;
92 std::function<bool(const GpgKey&)> filter_;
93 KeyIdArgsListPtr checked_key_ids_;
94
103 KeyTable(
104 QTableWidget* _key_list, KeyListRow::KeyType _select_type,
105 KeyListColumn::InfoType _info_type,
106 std::function<bool(const GpgKey&)> _filter = [](const GpgKey&) -> bool {
107 return true;
108 })
109 : key_list_(_key_list),
110 select_type_(_select_type),
111 info_type_(_info_type),
112 filter_(std::move(_filter)) {}
113
119 void Refresh(KeyLinkListPtr m_keys = nullptr);
120
126 KeyIdArgsListPtr& GetChecked();
127
132 void UncheckALL() const;
133
138 void CheckALL() const;
139
145 void SetChecked(KeyIdArgsListPtr key_ids);
146 };
147
152 class KeyList : public QWidget {
153 Q_OBJECT
154
155 public:
162 explicit KeyList(KeyMenuAbility::AbilityType menu_ability,
163 QWidget* parent = nullptr);
164
173 void AddListGroupTab(
174 const QString& name,
175 KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY,
176 KeyListColumn::InfoType infoType = KeyListColumn::ALL,
177 const std::function<bool(const GpgKey&)>& filter =
178 [](const GpgKey&) -> bool { return true; });
179
185 void SetDoubleClickedAction(
186 std::function<void(const GpgKey&, QWidget*)> action);
187
194 void SetColumnWidth(int row, int size);
195
201 void AddMenuAction(QAction* act);
202
207 void AddSeparator();
208
214 KeyIdArgsListPtr GetChecked();
215
222 static KeyIdArgsListPtr GetChecked(const KeyTable& key_table);
223
229 KeyIdArgsListPtr GetPrivateChecked();
230
236 KeyIdArgsListPtr GetAllPrivateKeys();
237
243 void SetChecked(KeyIdArgsListPtr key_ids);
244
251 static void SetChecked(const KeyIdArgsListPtr& keyIds,
252 const KeyTable& key_table);
253
259 KeyIdArgsListPtr GetSelected();
260
266 std::string GetSelectedKey();
267
273 [[maybe_unused]] static void MarkKeys(QStringList* keyIds);
274
281 [[maybe_unused]] bool ContainsPrivateKeys();
282
283 signals:
290 void SignalRefreshStatusBar(const QString& message, int timeout);
291
296 void SignalRefreshDatabase();
297
298 public slots:
299
304 void SlotRefresh();
305
306 private:
311 void init();
312
318 void import_keys(const QByteArray& inBuffer);
319
324 void uncheck_all();
325
330 void check_all();
331
332 std::mutex buffered_key_list_mutex_;
333
334 std::shared_ptr<Ui_KeyList> ui_;
335 QTableWidget* m_key_list_{};
336 std::vector<KeyTable> m_key_tables_;
337 QMenu* popup_menu_{};
338 GpgFrontend::KeyLinkListPtr buffered_keys_list_;
339 std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr;
340 KeyMenuAbility::AbilityType menu_ability_ = KeyMenuAbility::ALL;
341
342 private slots:
343
349 void slot_double_clicked(const QModelIndex& index);
350
355 void slot_refresh_ui();
356
361 void slot_sync_with_key_server();
362
363 protected:
369 void contextMenuEvent(QContextMenuEvent* event) override;
370
376 void dragEnterEvent(QDragEnterEvent* event) override;
377
383 void dropEvent(QDropEvent* event) override;
384 };
385
386 } // namespace GpgFrontend::UI
387
388 #endif // __KEYLIST_H__
GpgFrontend::GpgKey
Definition: GpgKey.h:43
GpgFrontend::UI::KeyList
Definition: KeyList.h:152
GpgFrontend::UI::KeyList::GetSelected
KeyIdArgsListPtr GetSelected()
Get the Selected object.
Definition: KeyList.cpp:260
GpgFrontend::UI::KeyList::ContainsPrivateKeys
bool ContainsPrivateKeys()
Definition: KeyList.cpp:277
GpgFrontend::UI::KeyList::dropEvent
void dropEvent(QDropEvent *event) override
Definition: KeyList.cpp:309
GpgFrontend::UI::KeyList::MarkKeys
static void MarkKeys(QStringList *keyIds)
Definition: KeyList.cpp:383
GpgFrontend::UI::KeyList::SetChecked
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:246
GpgFrontend::UI::KeyList::slot_double_clicked
void slot_double_clicked(const QModelIndex &index)
Definition: KeyList.cpp:396
GpgFrontend::UI::KeyList::AddListGroupTab
void AddListGroupTab(const QString &name, KeyListRow::KeyType selectType=KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::InfoType infoType=KeyListColumn::ALL, const std::function< bool(const GpgKey &)> &filter=[](const GpgKey &) -> bool { return true;})
Definition: KeyList.cpp:106
GpgFrontend::UI::KeyList::KeyList
KeyList(KeyMenuAbility::AbilityType menu_ability, QWidget *parent=nullptr)
Construct a new Key List object.
Definition: KeyList.cpp:44
GpgFrontend::UI::KeyList::SetDoubleClickedAction
void SetDoubleClickedAction(std::function< void(const GpgKey &, QWidget *)> action)
Set the Double Clicked Action object.
Definition: KeyList.cpp:407
GpgFrontend::UI::KeyList::GetAllPrivateKeys
KeyIdArgsListPtr GetAllPrivateKeys()
Get the All Private Keys object.
Definition: KeyList.cpp:202
GpgFrontend::UI::KeyList::GetPrivateChecked
KeyIdArgsListPtr GetPrivateChecked()
Get the Private Checked object.
Definition: KeyList.cpp:216
GpgFrontend::UI::KeyList::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event) override
Definition: KeyList.cpp:296
GpgFrontend::UI::KeyList::SignalRefreshStatusBar
void SignalRefreshStatusBar(const QString &message, int timeout)
GpgFrontend::UI::KeyList::AddMenuAction
void AddMenuAction(QAction *act)
Definition: KeyList.cpp:307
GpgFrontend::UI::KeyList::SetColumnWidth
void SetColumnWidth(int row, int size)
Set the Column Width object.
Definition: KeyList.cpp:289
GpgFrontend::UI::KeyList::GetSelectedKey
std::string GetSelectedKey()
Get the Selected Key object.
Definition: KeyList.cpp:412
GpgFrontend::UI::KeyList::import_keys
void import_keys(const QByteArray &inBuffer)
Definition: KeyList.cpp:389
GpgFrontend::UI::KeyList::GetChecked
KeyIdArgsListPtr GetChecked()
Get the Checked object.
Definition: KeyList.cpp:188
GpgFrontend::UI::KeyList::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *event) override
Definition: KeyList.cpp:376
GpgFrontend::UI
Definition: FileReadTask.cpp:29
GpgFrontend::UI::KeyListColumn
Definition: KeyList.h:56
GpgFrontend::UI::KeyListRow
Definition: KeyList.h:45
GpgFrontend::UI::KeyMenuAbility
Definition: KeyList.h:72
GpgFrontend::UI::KeyTable
Definition: KeyList.h:87
GpgFrontend::UI::KeyTable::GetChecked
KeyIdArgsListPtr & GetChecked()
Get the Checked object.
Definition: KeyList.cpp:504
GpgFrontend::UI::KeyTable::KeyTable
KeyTable(QTableWidget *_key_list, KeyListRow::KeyType _select_type, KeyListColumn::InfoType _info_type, std::function< bool(const GpgKey &)> _filter=[](const GpgKey &) -> bool { return true;})
Construct a new Key Table object.
Definition: KeyList.h:103
GpgFrontend::UI::KeyTable::Refresh
void Refresh(KeyLinkListPtr m_keys=nullptr)
Definition: KeyList.cpp:523
GpgFrontend::UI::KeyTable::SetChecked
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:519