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  static constexpr InfoType KeyID = 1 << 6;
63 };
64 
70  using AbilityType = unsigned int;
71 
72  static constexpr AbilityType ALL = ~0;
73  static constexpr AbilityType NONE = 0;
74  static constexpr AbilityType REFRESH = 1 << 0;
75  static constexpr AbilityType SYNC_PUBLIC_KEY = 1 << 1;
76  static constexpr AbilityType UNCHECK_ALL = 1 << 3;
77  static constexpr AbilityType CHECK_ALL = 1 << 5;
78  static constexpr AbilityType SEARCH_BAR = 1 << 6;
79 };
80 
85 struct KeyTable {
86  using KeyTableFilter = std::function<bool(const GpgKey&, const KeyTable&)>;
87 
88  QTableWidget* key_list_;
89  KeyListRow::KeyType select_type_;
90  KeyListColumn::InfoType info_type_;
91  std::vector<GpgKey> buffered_keys_;
92  KeyTableFilter filter_;
93  KeyIdArgsListPtr checked_key_ids_;
94  KeyMenuAbility::AbilityType ability_;
95  QString keyword_;
96 
106  QTableWidget* _key_list, KeyListRow::KeyType _select_type,
107  KeyListColumn::InfoType _info_type,
108  KeyTableFilter _filter = [](const GpgKey&, const KeyTable&) -> bool {
109  return true;
110  })
111  : key_list_(_key_list),
112  select_type_(_select_type),
113  info_type_(_info_type),
114  filter_(std::move(_filter)) {}
115 
121  void Refresh(KeyLinkListPtr m_keys = nullptr);
122 
128  KeyIdArgsListPtr& GetChecked();
129 
134  void UncheckALL() const;
135 
140  void CheckALL() const;
141 
147  void SetChecked(KeyIdArgsListPtr key_ids);
148 
153  void SetMenuAbility(KeyMenuAbility::AbilityType ability);
154 
159  void SetFilterKeyword(QString keyword);
160 };
161 
166 class KeyList : public QWidget {
167  Q_OBJECT
168 
169  public:
176  explicit KeyList(KeyMenuAbility::AbilityType menu_ability,
177  QWidget* parent = nullptr);
178 
187  void AddListGroupTab(
188  const QString& name, const QString& id,
189  KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY,
190  KeyListColumn::InfoType infoType = KeyListColumn::ALL,
191  KeyTable::KeyTableFilter filter =
192  [](const GpgKey&, const KeyTable&) -> bool { return true; });
193 
200  std::function<void(const GpgKey&, QWidget*)> action);
201 
208  void SetColumnWidth(int row, int size);
209 
215  void AddMenuAction(QAction* act);
216 
221  void AddSeparator();
222 
228  auto GetChecked() -> KeyIdArgsListPtr;
229 
236  static auto GetChecked(const KeyTable& key_table) -> KeyIdArgsListPtr;
237 
243  auto GetCheckedPrivateKey() -> KeyIdArgsListPtr;
244 
250  auto GetCheckedPublicKey() -> KeyIdArgsListPtr;
251 
257  auto GetAllPrivateKeys() -> KeyIdArgsListPtr;
258 
264  void SetChecked(KeyIdArgsListPtr key_ids);
265 
272  static void SetChecked(const KeyIdArgsListPtr& keyIds,
273  const KeyTable& key_table);
274 
280  auto GetSelected() -> KeyIdArgsListPtr;
281 
287  auto GetSelectedKey() -> QString;
288 
295  [[maybe_unused]] auto ContainsPrivateKeys() -> bool;
296 
297  signals:
304  void SignalRefreshStatusBar(const QString& message, int timeout);
305 
310  void SignalRefreshDatabase();
311 
312  public slots:
313 
318  void SlotRefresh();
319 
324  void SlotRefreshUI();
325 
326  private:
331  void init();
332 
338  void import_keys(const QByteArray& inBuffer);
339 
344  void uncheck_all();
345 
350  void check_all();
351 
356  void filter_by_keyword();
357 
358  std::mutex buffered_key_list_mutex_;
359 
360  std::shared_ptr<Ui_KeyList> ui_;
361  QTableWidget* m_key_list_{};
362  std::vector<KeyTable> m_key_tables_;
363  QMenu* popup_menu_{};
364  GpgFrontend::KeyLinkListPtr buffered_keys_list_;
365  std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr;
366  KeyMenuAbility::AbilityType menu_ability_ = KeyMenuAbility::ALL;
367 
368  private slots:
369 
375  void slot_double_clicked(const QModelIndex& index);
376 
381  void slot_refresh_ui();
382 
387  void slot_sync_with_key_server();
388 
389  protected:
395  void contextMenuEvent(QContextMenuEvent* event) override;
396 
402  void dragEnterEvent(QDragEnterEvent* event) override;
403 
409  void dropEvent(QDropEvent* event) override;
410 };
411 
412 } // namespace GpgFrontend::UI
Definition: GpgKey.h:40
Definition: KeyList.h:166
auto GetAllPrivateKeys() -> KeyIdArgsListPtr
Get the All Private Keys object.
Definition: KeyList.cpp:220
void dropEvent(QDropEvent *event) override
Definition: KeyList.cpp:371
void AddListGroupTab(const QString &name, const QString &id, KeyListRow::KeyType selectType=KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::InfoType infoType=KeyListColumn::ALL, KeyTable::KeyTableFilter filter=[](const GpgKey &, const KeyTable &) -> bool { return true;})
Definition: KeyList.cpp:114
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:284
auto GetSelected() -> KeyIdArgsListPtr
Get the Selected object.
Definition: KeyList.cpp:298
void slot_double_clicked(const QModelIndex &index)
Definition: KeyList.cpp:436
auto GetCheckedPrivateKey() -> KeyIdArgsListPtr
Get the Private Checked object.
Definition: KeyList.cpp:234
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:447
void contextMenuEvent(QContextMenuEvent *event) override
Definition: KeyList.cpp:334
auto GetCheckedPublicKey() -> KeyIdArgsListPtr
Definition: KeyList.cpp:253
void SignalRefreshStatusBar(const QString &message, int timeout)
void AddMenuAction(QAction *act)
Definition: KeyList.cpp:369
void SetColumnWidth(int row, int size)
Set the Column Width object.
Definition: KeyList.cpp:327
void import_keys(const QByteArray &inBuffer)
Definition: KeyList.cpp:430
auto ContainsPrivateKeys() -> bool
Definition: KeyList.cpp:315
auto GetChecked() -> KeyIdArgsListPtr
Get the Checked object.
Definition: KeyList.cpp:206
void dragEnterEvent(QDragEnterEvent *event) override
Definition: KeyList.cpp:426
auto GetSelectedKey() -> QString
Get the Selected Key object.
Definition: KeyList.cpp:452
Definition: FileReadTask.cpp:31
Definition: KeyList.h:52
Definition: KeyList.h:41
Definition: KeyList.h:69
Definition: KeyList.h:85
KeyIdArgsListPtr & GetChecked()
Get the Checked object.
Definition: KeyList.cpp:576
void Refresh(KeyLinkListPtr m_keys=nullptr)
Definition: KeyList.cpp:595
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:591
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:105