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 
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 
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 
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__
Definition: GpgKey.h:43
Definition: KeyList.h:170
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
static void MarkKeys(QStringList *keyIds)
Definition: KeyList.cpp:422
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:261
void slot_double_clicked(const QModelIndex &index)
Definition: KeyList.cpp:435
KeyList(KeyMenuAbility::AbilityType menu_ability, QWidget *parent=nullptr)
Construct a new Key List object.
Definition: KeyList.cpp:46
void SetDoubleClickedAction(std::function< void(const GpgKey &, QWidget *)> action)
Set the Double Clicked Action object.
Definition: KeyList.cpp:446
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
std::string GetSelectedKey()
Get the Selected Key object.
Definition: KeyList.cpp:451
void import_keys(const QByteArray &inBuffer)
Definition: KeyList.cpp:428
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:415
Definition: FileReadTask.cpp:29
Definition: KeyList.h:57
Definition: KeyList.h:46
Definition: KeyList.h:73
Definition: KeyList.h:89
KeyIdArgsListPtr & GetChecked()
Get the Checked object.
Definition: KeyList.cpp:558
void Refresh(KeyLinkListPtr m_keys=nullptr)
Definition: KeyList.cpp:576
void SetChecked(KeyIdArgsListPtr key_ids)
Set the Checked object.
Definition: KeyList.cpp:572
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