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 <string>
33 #include <utility>
34
35 #include "core/GpgContext.h"
36 #include "ui/dialog/import_export/KeyImportDetailDialog.h"
37
38 class Ui_KeyList;
39
40 namespace GpgFrontend::UI {
41
46 struct KeyListRow {
47 using KeyType = unsigned int;
48
49 static const KeyType SECRET_OR_PUBLIC_KEY = 0;
50 static const KeyType ONLY_SECRET_KEY = 1;
51 };
52
57 struct KeyListColumn {
58 using InfoType = unsigned int;
59
60 static constexpr InfoType ALL = ~0;
61 static constexpr InfoType TYPE = 1 << 0;
62 static constexpr InfoType NAME = 1 << 1;
63 static constexpr InfoType EmailAddress = 1 << 2;
64 static constexpr InfoType Usage = 1 << 3;
65 static constexpr InfoType Validity = 1 << 4;
66 static constexpr InfoType FingerPrint = 1 << 5;
67 };
68
73 struct KeyMenuAbility {
74 using AbilityType = unsigned int;
75
76 static constexpr AbilityType ALL = ~0;
77 static constexpr AbilityType NONE = 0;
78 static constexpr AbilityType REFRESH = 1 << 0;
79 static constexpr AbilityType SYNC_PUBLIC_KEY = 1 << 1;
80 static constexpr AbilityType UNCHECK_ALL = 1 << 3;
81 static constexpr AbilityType CHECK_ALL = 1 << 5;
82 static constexpr AbilityType SEARCH_BAR = 1 << 6;
83 };
84
89 struct KeyTable {
90 using KeyTableFilter = std::function<bool(const GpgKey&, const KeyTable&)>;
91
92 QTableWidget* key_list_;
93 KeyListRow::KeyType select_type_;
94 KeyListColumn::InfoType info_type_;
95 std::vector<GpgKey> buffered_keys_;
96 KeyTableFilter filter_;
97 KeyIdArgsListPtr checked_key_ids_;
98 KeyMenuAbility::AbilityType ability_;
99 std::string keyword_;
100
109 KeyTable(
110 QTableWidget* _key_list, KeyListRow::KeyType _select_type,
111 KeyListColumn::InfoType _info_type,
112 KeyTableFilter _filter = [](const GpgKey&, const KeyTable&) -> bool {
113 return true;
114 })
115 : key_list_(_key_list),
116 select_type_(_select_type),
117 info_type_(_info_type),
118 filter_(std::move(_filter)) {}
119
125 void Refresh(KeyLinkListPtr m_keys = nullptr);
126
132 KeyIdArgsListPtr& GetChecked();
133
138 void UncheckALL() const;
139
144 void CheckALL() const;
145
151 void SetChecked(KeyIdArgsListPtr key_ids);
152
157 void SetMenuAbility(KeyMenuAbility::AbilityType ability);
158
163 void SetFilterKeyword(std::string keyword);
164 };
165
170 class KeyList : public QWidget {
171 Q_OBJECT
172
173 public:
180 explicit KeyList(KeyMenuAbility::AbilityType menu_ability,
181 QWidget* parent = nullptr);
182
191 void AddListGroupTab(
192 const QString& name, const QString& id,
193 KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY,
194 KeyListColumn::InfoType infoType = KeyListColumn::ALL,
195 const KeyTable::KeyTableFilter filter =
196 [](const GpgKey&, const KeyTable&) -> bool { return true; });
197
203 void SetDoubleClickedAction(
204 std::function<void(const GpgKey&, QWidget*)> action);
205
212 void SetColumnWidth(int row, int size);
213
219 void AddMenuAction(QAction* act);
220
225 void AddSeparator();
226
232 KeyIdArgsListPtr GetChecked();
233
240 static KeyIdArgsListPtr GetChecked(const KeyTable& key_table);
241
247 KeyIdArgsListPtr GetPrivateChecked();
248
254 KeyIdArgsListPtr GetAllPrivateKeys();
255
261 void SetChecked(KeyIdArgsListPtr key_ids);
262
269 static void SetChecked(const KeyIdArgsListPtr& keyIds,
270 const KeyTable& key_table);
271
277 KeyIdArgsListPtr GetSelected();
278
284 std::string GetSelectedKey();
285
291 [[maybe_unused]] static void MarkKeys(QStringList* keyIds);
292
299 [[maybe_unused]] bool ContainsPrivateKeys();
300
301 signals:
308 void SignalRefreshStatusBar(const QString& message, int timeout);
309
314 void SignalRefreshDatabase();
315
316 public slots:
317
322 void SlotRefresh();
323
328 void SlotRefreshUI();
329
330 private:
335 void init();
336
342 void import_keys(const QByteArray& inBuffer);
343
348 void uncheck_all();
349
354 void check_all();
355
360 void filter_by_keyword();
361
362 std::mutex buffered_key_list_mutex_;
363
364 std::shared_ptr<Ui_KeyList> ui_;
365 QTableWidget* m_key_list_{};
366 std::vector<KeyTable> m_key_tables_;
367 QMenu* popup_menu_{};
368 GpgFrontend::KeyLinkListPtr buffered_keys_list_;
369 std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr;
370 KeyMenuAbility::AbilityType menu_ability_ = KeyMenuAbility::ALL;
371
372 private slots:
373
379 void slot_double_clicked(const QModelIndex& index);
380
385 void slot_refresh_ui();
386
391 void slot_sync_with_key_server();
392
393 protected:
399 void contextMenuEvent(QContextMenuEvent* event) override;
400
406 void dragEnterEvent(QDragEnterEvent* event) override;
407
413 void dropEvent(QDropEvent* event) override;
414 };
415
416 } // namespace GpgFrontend::UI
417
418 #endif // __KEYLIST_H__
GpgFrontend::GpgKey
Definition: GpgKey.h:43
GpgFrontend::UI::KeyList
Definition: KeyList.h:170
GpgFrontend::UI::KeyList::GetSelected
KeyIdArgsListPtr GetSelected()
Get the Selected object.
Definition: KeyList.cpp:275
GpgFrontend::UI::KeyList::ContainsPrivateKeys
bool ContainsPrivateKeys()
Definition: KeyList.cpp:292
GpgFrontend::UI::KeyList::dropEvent
void dropEvent(QDropEvent *event) override
Definition: KeyList.cpp:348
GpgFrontend::UI::KeyList::MarkKeys
static void MarkKeys(QStringList *keyIds)
Definition: KeyList.cpp:422
GpgFrontend::UI::KeyList::SetChecked
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:261
GpgFrontend::UI::KeyList::slot_double_clicked
void slot_double_clicked(const QModelIndex &index)
Definition: KeyList.cpp:435
GpgFrontend::UI::KeyList::KeyList
KeyList(KeyMenuAbility::AbilityType menu_ability, QWidget *parent=nullptr)
Construct a new Key List object.
Definition: KeyList.cpp:46
GpgFrontend::UI::KeyList::SetDoubleClickedAction
void SetDoubleClickedAction(std::function< void(const GpgKey &, QWidget *)> action)
Set the Double Clicked Action object.
Definition: KeyList.cpp:446
GpgFrontend::UI::KeyList::GetAllPrivateKeys
KeyIdArgsListPtr GetAllPrivateKeys()
Get the All Private Keys object.
Definition: KeyList.cpp:217
GpgFrontend::UI::KeyList::GetPrivateChecked
KeyIdArgsListPtr GetPrivateChecked()
Get the Private Checked object.
Definition: KeyList.cpp:231
GpgFrontend::UI::KeyList::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event) override
Definition: KeyList.cpp:311
GpgFrontend::UI::KeyList::SignalRefreshStatusBar
void SignalRefreshStatusBar(const QString &message, int timeout)
GpgFrontend::UI::KeyList::AddMenuAction
void AddMenuAction(QAction *act)
Definition: KeyList.cpp:346
GpgFrontend::UI::KeyList::SetColumnWidth
void SetColumnWidth(int row, int size)
Set the Column Width object.
Definition: KeyList.cpp:304
GpgFrontend::UI::KeyList::GetSelectedKey
std::string GetSelectedKey()
Get the Selected Key object.
Definition: KeyList.cpp:451
GpgFrontend::UI::KeyList::import_keys
void import_keys(const QByteArray &inBuffer)
Definition: KeyList.cpp:428
GpgFrontend::UI::KeyList::AddListGroupTab
void AddListGroupTab(const QString &name, const QString &id, KeyListRow::KeyType selectType=KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::InfoType infoType=KeyListColumn::ALL, const KeyTable::KeyTableFilter filter=[](const GpgKey &, const KeyTable &) -> bool { return true;})
Definition: KeyList.cpp:114
GpgFrontend::UI::KeyList::GetChecked
KeyIdArgsListPtr GetChecked()
Get the Checked object.
Definition: KeyList.cpp:203
GpgFrontend::UI::KeyList::dragEnterEvent
void dragEnterEvent(QDragEnterEvent *event) override
Definition: KeyList.cpp:415
GpgFrontend::UI
Definition: FileReadTask.cpp:29
GpgFrontend::UI::KeyListColumn
Definition: KeyList.h:57
GpgFrontend::UI::KeyListRow
Definition: KeyList.h:46
GpgFrontend::UI::KeyMenuAbility
Definition: KeyList.h:73
GpgFrontend::UI::KeyTable
Definition: KeyList.h:89
GpgFrontend::UI::KeyTable::GetChecked
KeyIdArgsListPtr & GetChecked()
Get the Checked object.
Definition: KeyList.cpp:558
GpgFrontend::UI::KeyTable::Refresh
void Refresh(KeyLinkListPtr m_keys=nullptr)
Definition: KeyList.cpp:577
GpgFrontend::UI::KeyTable::SetChecked
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:573
GpgFrontend::UI::KeyTable::KeyTable
KeyTable(QTableWidget *_key_list, KeyListRow::KeyType _select_type, KeyListColumn::InfoType _info_type, KeyTableFilter _filter=[](const GpgKey &, const KeyTable &) -> bool { return true;})
Construct a new Key Table object.
Definition: KeyList.h:109