GpgFrontend Project
A Free, Powerful, Easy-to-Use, Compact, Cross-Platform, and Installation-Free OpenPGP(pgp) Crypto Tool.
UserInterfaceUtils.h
1 
29 #pragma once
30 
31 #include "core/function/result_analyse/GpgVerifyResultAnalyse.h"
32 #include "core/model/GpgKey.h"
33 #include "core/thread/Task.h"
34 #include "core/typedef/GpgTypedef.h"
35 
36 namespace GpgFrontend {
37 class GpgResultAnalyse;
38 class GpgImportInformation;
39 } // namespace GpgFrontend
40 
41 namespace GpgFrontend::UI {
42 
43 class InfoBoardWidget;
44 class TextEdit;
45 
46 using OperaWaitingHd = std::function<void()>;
47 using OperaWaitingCb = const std::function<void(OperaWaitingHd)>;
48 
57 void show_verify_details(QWidget* parent, InfoBoardWidget* info_board,
58  GpgError error, const GpgVerifyResult& verify_result);
59 
67  QWidget* parent, const GpgVerifyResultAnalyse& verify_res);
68 
76 void refresh_info_board(InfoBoardWidget* info_board, int status,
77  const QString& report_text);
78 
86 void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board,
87  const GpgResultAnalyse& result_analyse);
88 
97 void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board,
98  const GpgResultAnalyse& result_analyse_a,
99  const GpgResultAnalyse& result_analyse_b);
100 
108 void process_operation(QWidget* parent, const QString& waiting_title,
109  Thread::Task::TaskRunnable func,
110  Thread::Task::TaskCallback callback = nullptr,
111  DataObjectPtr data_object = nullptr);
112 
117 class CommonUtils : public QWidget {
118  Q_OBJECT
119  public:
124  using ImportCallbackFunctiopn =
125  std::function<void(const QString&, const QString&, size_t, size_t)>;
126 
131  CommonUtils();
132 
138  static CommonUtils* GetInstance();
139 
145  static void WaitForOpera(QWidget* parent, const QString&,
146  const OperaWaitingCb&);
147 
153  static void RaiseMessageBox(QWidget* parent, GpgError err);
154 
160  static void RaiseFailureMessageBox(QWidget* parent, GpgError err);
161 
166  bool isApplicationNeedRestart();
167 
172  bool KeyExistsinFavouriteList(const GpgKey& key);
173 
178  void AddKey2Favourtie(const GpgKey& key);
179 
184  void RemoveKeyFromFavourite(const GpgKey& key);
185 
190  void ImportKeyFromKeyServer(const KeyIdArgsList&);
191 
192  signals:
197  void SignalKeyStatusUpdated();
198 
203  void SignalBadGnupgEnv(QString);
204 
210 
215  void SignalRestartApplication(int);
216 
217  public slots:
224  void SlotImportKeys(QWidget* parent, const QString& in_buffer);
225 
231  void SlotImportKeyFromFile(QWidget* parent);
232 
238  void SlotImportKeyFromKeyServer(QWidget* parent);
239 
245  void SlotImportKeyFromClipboard(QWidget* parent);
246 
254  static void SlotImportKeyFromKeyServer(
255  const GpgFrontend::KeyIdArgsList& key_ids,
256  const GpgFrontend::UI::CommonUtils::ImportCallbackFunctiopn& callback);
257 
265  const QStringList& arguments,
266  const std::function<void(QProcess*)>& interact_func);
267 
274  void SlotExecuteCommand(const QString& cmd, const QStringList& arguments,
275  const std::function<void(QProcess*)>& interact_func);
276 
281  void SlotRestartApplication(int);
282 
283  private slots:
284 
289  void slot_update_key_status();
290 
295  void slot_update_key_from_server_finished(
296  bool, QString, QByteArray, std::shared_ptr<GpgImportInformation>);
297 
298  private:
299  static std::unique_ptr<CommonUtils> instance_;
300  bool application_need_to_restart_at_once_ = false;
301 };
302 
303 } // namespace GpgFrontend::UI
Definition: GpgKey.h:40
Definition: UserInterfaceUtils.h:117
void SlotImportKeyFromFile(QWidget *parent)
Definition: UserInterfaceUtils.cpp:278
void SlotImportKeyFromClipboard(QWidget *parent)
Definition: UserInterfaceUtils.cpp:314
void SignalKeyDatabaseRefreshDone()
emit when the key database is refreshed
static void RaiseMessageBox(QWidget *parent, GpgError err)
Definition: UserInterfaceUtils.cpp:246
void SlotExecuteCommand(const QString &cmd, const QStringList &arguments, const std::function< void(QProcess *)> &interact_func)
Definition: UserInterfaceUtils.cpp:319
static void RaiseFailureMessageBox(QWidget *parent, GpgError err)
Definition: UserInterfaceUtils.cpp:258
static CommonUtils * GetInstance()
Get the Instance object.
Definition: UserInterfaceUtils.cpp:150
CommonUtils()
Construct a new Common Utils object.
Definition: UserInterfaceUtils.cpp:157
void slot_update_key_status()
update the key status when signal is emitted
Definition: UserInterfaceUtils.cpp:479
static void WaitForOpera(QWidget *parent, const QString &, const OperaWaitingCb &)
Definition: UserInterfaceUtils.cpp:222
void SlotImportKeys(QWidget *parent, const QString &in_buffer)
Definition: UserInterfaceUtils.cpp:270
void SlotImportKeyFromKeyServer(QWidget *parent)
Definition: UserInterfaceUtils.cpp:309
void SlotExecuteGpgCommand(const QStringList &arguments, const std::function< void(QProcess *)> &interact_func)
Definition: UserInterfaceUtils.cpp:351
Definition: FileReadTask.cpp:31
void process_operation(QWidget *parent, const QString &waiting_title, const Thread::Task::TaskRunnable func, const Thread::Task::TaskCallback callback, DataObjectPtr data_object)
Definition: UserInterfaceUtils.cpp:121
void show_verify_details(QWidget *parent, InfoBoardWidget *info_board, GpgError error, const GpgVerifyResult &verify_result)
Definition: UserInterfaceUtils.cpp:59
void import_unknown_key_from_keyserver(QWidget *parent, const GpgVerifyResultAnalyse &verify_res)
Definition: UserInterfaceUtils.cpp:68
void process_result_analyse(TextEdit *edit, InfoBoardWidget *info_board, const GpgResultAnalyse &result_analyse)
Definition: UserInterfaceUtils.cpp:103
void refresh_info_board(InfoBoardWidget *info_board, int status, const QString &report_text)
Definition: UserInterfaceUtils.cpp:92
Definition: app.cpp:39
gpgme_error_t GpgError
gpgme error
Definition: GpgTypedef.h:42