GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
KeyList.h
1 
29 #pragma once
30 
31 #include "core/model/GpgKey.h"
32 
33 class Ui_KeyList;
34 
35 namespace GpgFrontend::UI {
36 
41 struct KeyListRow {
42  using KeyType = unsigned int;
43 
44  static const KeyType SECRET_OR_PUBLIC_KEY = 0;
45  static const KeyType ONLY_SECRET_KEY = 1;
46 };
47 
52 struct KeyListColumn {
53  using InfoType = unsigned int;
54 
55  static constexpr InfoType ALL = ~0;
56  static constexpr InfoType TYPE = 1 << 0;
57  static constexpr InfoType NAME = 1 << 1;
58  static constexpr InfoType EmailAddress = 1 << 2;
59  static constexpr InfoType Usage = 1 << 3;
60  static constexpr InfoType Validity = 1 << 4;
61  static constexpr InfoType FingerPrint = 1 << 5;
62 };
63 
69  using AbilityType = unsigned int;
70 
71  static constexpr AbilityType ALL = ~0;
72  static constexpr AbilityType NONE = 0;
73  static constexpr AbilityType REFRESH = 1 << 0;
74  static constexpr AbilityType SYNC_PUBLIC_KEY = 1 << 1;
75  static constexpr AbilityType UNCHECK_ALL = 1 << 3;
76  static constexpr AbilityType CHECK_ALL = 1 << 5;
77  static constexpr AbilityType SEARCH_BAR = 1 << 6;
78 };
79 
84 struct KeyTable {
85  using KeyTableFilter = std::function<bool(const GpgKey&, const KeyTable&)>;
86 
87  QTableWidget* key_list_;
88  KeyListRow::KeyType select_type_;
89  KeyListColumn::InfoType info_type_;
90  std::vector<GpgKey> buffered_keys_;
91  KeyTableFilter filter_;
92  KeyIdArgsListPtr checked_key_ids_;
93  KeyMenuAbility::AbilityType ability_;
94  QString keyword_;
95 
105  QTableWidget* _key_list, KeyListRow::KeyType _select_type,
106  KeyListColumn::InfoType _info_type,
107  KeyTableFilter _filter = [](const GpgKey&, const KeyTable&) -> bool {
108  return true;
109  })
110  : key_list_(_key_list),
111  select_type_(_select_type),
112  info_type_(_info_type),
113  filter_(std::move(_filter)) {}
114 
120  void Refresh(KeyLinkListPtr m_keys = nullptr);
121 
127  KeyIdArgsListPtr& GetChecked();
128 
133  void UncheckALL() const;
134 
139  void CheckALL() const;
140 
146  void SetChecked(KeyIdArgsListPtr key_ids);
147 
152  void SetMenuAbility(KeyMenuAbility::AbilityType ability);
153 
158  void SetFilterKeyword(QString keyword);
159 };
160 
165 class KeyList : public QWidget {
166  Q_OBJECT
167 
168  public:
175  explicit KeyList(KeyMenuAbility::AbilityType menu_ability,
176  QWidget* parent = nullptr);
177 
186  void AddListGroupTab(
187  const QString& name, const QString& id,
188  KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY,
189  KeyListColumn::InfoType infoType = KeyListColumn::ALL,
190  const KeyTable::KeyTableFilter filter =
191  [](const GpgKey&, const KeyTable&) -> bool { return true; });
192 
199  std::function<void(const GpgKey&, QWidget*)> action);
200 
207  void SetColumnWidth(int row, int size);
208 
214  void AddMenuAction(QAction* act);
215 
220  void AddSeparator();
221 
227  KeyIdArgsListPtr GetChecked();
228 
235  static KeyIdArgsListPtr GetChecked(const KeyTable& key_table);
236 
242  KeyIdArgsListPtr GetPrivateChecked();
243 
249  KeyIdArgsListPtr GetAllPrivateKeys();
250 
256  void SetChecked(KeyIdArgsListPtr key_ids);
257 
264  static void SetChecked(const KeyIdArgsListPtr& keyIds,
265  const KeyTable& key_table);
266 
272  KeyIdArgsListPtr GetSelected();
273 
279  QString GetSelectedKey();
280 
287  [[maybe_unused]] bool ContainsPrivateKeys();
288 
289  signals:
296  void SignalRefreshStatusBar(const QString& message, int timeout);
297 
302  void SignalRefreshDatabase();
303 
304  public slots:
305 
310  void SlotRefresh();
311 
316  void SlotRefreshUI();
317 
318  private:
323  void init();
324 
330  void import_keys(const QByteArray& inBuffer);
331 
336  void uncheck_all();
337 
342  void check_all();
343 
348  void filter_by_keyword();
349 
350  std::mutex buffered_key_list_mutex_;
351 
352  std::shared_ptr<Ui_KeyList> ui_;
353  QTableWidget* m_key_list_{};
354  std::vector<KeyTable> m_key_tables_;
355  QMenu* popup_menu_{};
356  GpgFrontend::KeyLinkListPtr buffered_keys_list_;
357  std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr;
358  KeyMenuAbility::AbilityType menu_ability_ = KeyMenuAbility::ALL;
359 
360  private slots:
361 
367  void slot_double_clicked(const QModelIndex& index);
368 
373  void slot_refresh_ui();
374 
379  void slot_sync_with_key_server();
380 
381  protected:
387  void contextMenuEvent(QContextMenuEvent* event) override;
388 
394  void dragEnterEvent(QDragEnterEvent* event) override;
395 
401  void dropEvent(QDropEvent* event) override;
402 };
403 
404 } // namespace GpgFrontend::UI
Definition: GpgKey.h:40
Definition: KeyList.h:165
KeyIdArgsListPtr GetSelected()
Get the Selected object.
Definition: KeyList.cpp:275
bool ContainsPrivateKeys()
Definition: KeyList.cpp:292
void dropEvent(QDropEvent *event) override
Definition: KeyList.cpp:348
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:261
void slot_double_clicked(const QModelIndex &index)
Definition: KeyList.cpp:413
KeyList(KeyMenuAbility::AbilityType menu_ability, QWidget *parent=nullptr)
Construct a new Key List object.
Definition: KeyList.cpp:43
void SetDoubleClickedAction(std::function< void(const GpgKey &, QWidget *)> action)
Set the Double Clicked Action object.
Definition: KeyList.cpp:424
KeyIdArgsListPtr GetAllPrivateKeys()
Get the All Private Keys object.
Definition: KeyList.cpp:217
KeyIdArgsListPtr GetPrivateChecked()
Get the Private Checked object.
Definition: KeyList.cpp:231
void contextMenuEvent(QContextMenuEvent *event) override
Definition: KeyList.cpp:311
void SignalRefreshStatusBar(const QString &message, int timeout)
void AddMenuAction(QAction *act)
Definition: KeyList.cpp:346
void SetColumnWidth(int row, int size)
Set the Column Width object.
Definition: KeyList.cpp:304
QString GetSelectedKey()
Get the Selected Key object.
Definition: KeyList.cpp:429
void import_keys(const QByteArray &inBuffer)
Definition: KeyList.cpp:407
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
KeyIdArgsListPtr GetChecked()
Get the Checked object.
Definition: KeyList.cpp:203
void dragEnterEvent(QDragEnterEvent *event) override
Definition: KeyList.cpp:403
Definition: FileReadTask.cpp:31
Definition: KeyList.h:52
Definition: KeyList.h:41
Definition: KeyList.h:68
Definition: KeyList.h:84
KeyIdArgsListPtr & GetChecked()
Get the Checked object.
Definition: KeyList.cpp:539
void Refresh(KeyLinkListPtr m_keys=nullptr)
Definition: KeyList.cpp:558
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:554
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:104