Skip to content

Commit

Permalink
feat: improve ui logic of email verification and make project structu…
Browse files Browse the repository at this point in the history
…re better
  • Loading branch information
saturneric committed Nov 26, 2024
1 parent 296de12 commit 83be6ce
Show file tree
Hide file tree
Showing 11 changed files with 297 additions and 142 deletions.
1 change: 1 addition & 0 deletions gpgfrontend.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
<file alias="minus.png">resource/lfs/icons/minus.png</file>
<file alias="database.png">resource/lfs/icons/database.png</file>
<file alias="publish.png">resource/lfs/icons/publish.png</file>
<file alias="email-check.png">resource/lfs/icons/email-check.png</file>
</qresource>
<qresource prefix="/test/key">
<file alias="pv1.key">resource/lfs/test/data/pv1.key</file>
Expand Down
2 changes: 1 addition & 1 deletion modules
Submodule modules updated from 723848 to 37bbb8
Binary file added resource/lfs/icons/email-check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 0 additions & 29 deletions src/ui/UserInterfaceUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,35 +91,6 @@ void ImportUnknownKeyFromKeyserver(
}
}

void refresh_info_board(InfoBoardWidget *info_board, int status,
const QString &report_text) {
if (status < 0) {
info_board->SlotRefresh(report_text, INFO_ERROR_CRITICAL);
} else if (status > 0) {
info_board->SlotRefresh(report_text, INFO_ERROR_OK);
} else {
info_board->SlotRefresh(report_text, INFO_ERROR_WARN);
}
}

void process_result_analyse(TextEdit *edit, InfoBoardWidget *info_board,
const GpgResultAnalyse &result_analyse) {
info_board->AssociateTabWidget(edit->tab_widget_);
refresh_info_board(info_board, result_analyse.GetStatus(),
result_analyse.GetResultReport());
}

void process_result_analyse(TextEdit *edit, InfoBoardWidget *info_board,
const GpgResultAnalyse &result_analyse_a,
const GpgResultAnalyse &result_analyse_b) {
info_board->AssociateTabWidget(edit->tab_widget_);

refresh_info_board(
info_board,
std::min(result_analyse_a.GetStatus(), result_analyse_b.GetStatus()),
result_analyse_a.GetResultReport() + result_analyse_b.GetResultReport());
}

void process_operation(QWidget *parent, const QString &waiting_title,
const Thread::Task::TaskRunnable func,
const Thread::Task::TaskCallback callback,
Expand Down
32 changes: 0 additions & 32 deletions src/ui/UserInterfaceUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,6 @@ void show_verify_details(QWidget* parent, InfoBoardWidget* info_board,
void ImportUnknownKeyFromKeyserver(QWidget* parent,
const GpgVerifyResultAnalyse& verify_res);

/**
* @brief
*
* @param info_board
* @param status
* @param report_text
*/
void refresh_info_board(InfoBoardWidget* info_board, int status,
const QString& report_text);

/**
* @brief
*
* @param edit
* @param info_board
* @param result_analyse
*/
void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board,
const GpgResultAnalyse& result_analyse);

/**
* @brief
*
* @param edit
* @param info_board
* @param result_analyse_a
* @param result_analyse_b
*/
void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board,
const GpgResultAnalyse& result_analyse_a,
const GpgResultAnalyse& result_analyse_b);

/**
* @brief
*
Expand Down
54 changes: 52 additions & 2 deletions src/ui/main_window/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

namespace GpgFrontend {
class GpgPassphraseContext;
}
class GpgResultAnalyse;
class GpgVerifyResultAnalyse;
} // namespace GpgFrontend

namespace GpgFrontend::UI {

Expand Down Expand Up @@ -396,6 +398,53 @@ class MainWindow : public GeneralMainWindow {
*/
void slot_verify_email_by_eml_data(const QByteArray& buffer);

/**
* @brief
*
* @param buffer
*/
void slot_verify_email_by_eml_data_result_helper(
const QMap<QString, QString>& p);

/**
* @brief
*
* @param result_analyse
*/
void slot_verifying_unknown_signature_helper(const GpgVerifyResultAnalyse& r);

/**
* @brief
*
* @param result_analyse
*/
void slot_result_analyse_show_helper(const GpgResultAnalyse& r);

/**
* @brief
*
* @param r_a
* @param r_b
*/
void slot_result_analyse_show_helper(const GpgResultAnalyse& r_a,
const GpgResultAnalyse& r_b);

/**
* @brief
*
* @param result_analyse
*/
void slot_eml_verify_show_helper(const QString& email_info,
const GpgVerifyResultAnalyse& r);

/**
* @brief
*
* @param status
* @param text
*/
void slot_refresh_info_board(int status, const QString& text);

private:
/**
* @details Create actions for the main-menu and the context-menu of the
Expand Down Expand Up @@ -460,6 +509,7 @@ class MainWindow : public GeneralMainWindow {
QToolBar*
special_edit_tool_bar_{}; ///< Toolbar holding special edit actions
QToolBar* key_tool_bar_{}; ///< Toolbar holding key operations
QToolBar* email_tool_bar_{};
QToolButton*
import_button_{}; ///< Tool button for import dropdown menu in toolbar
QDockWidget* key_list_dock_{}; ///< Encrypt Dock
Expand Down Expand Up @@ -530,7 +580,7 @@ class MainWindow : public GeneralMainWindow {
QAction* import_key_from_file_act_{}; ///<
QAction* import_key_from_clipboard_act_{}; ///<
QAction* import_key_from_key_server_act_{}; ///<
QAction* verify_email_by_eml_data_{}; ///<
QAction* verify_email_by_eml_data_act_{}; ///<

QLabel* status_bar_icon_{}; ///<

Expand Down
80 changes: 38 additions & 42 deletions src/ui/main_window/MainWindowFileSlotFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void MainWindow::SlotFileEncrypt(const QString& path) {
result);
result_analyse.Analyse();

process_result_analyse(edit_, info_board_, result_analyse);
slot_result_analyse_show_helper(result_analyse);
this->slot_refresh_current_file_view();
});
});
Expand Down Expand Up @@ -163,7 +163,7 @@ void MainWindow::SlotFileEncrypt(const QString& path) {
m_key_list_->GetCurrentGpgContextChannel(), err, result);
result_analyse.Analyse();

process_result_analyse(edit_, info_board_, result_analyse);
slot_result_analyse_show_helper(result_analyse);
this->slot_refresh_current_file_view();
});
});
Expand Down Expand Up @@ -237,7 +237,7 @@ void MainWindow::SlotDirectoryEncrypt(const QString& path) {
result);
result_analyse.Analyse();

process_result_analyse(edit_, info_board_, result_analyse);
slot_result_analyse_show_helper(result_analyse);
this->slot_refresh_current_file_view();
});
});
Expand Down Expand Up @@ -289,7 +289,7 @@ void MainWindow::SlotDirectoryEncrypt(const QString& path) {
m_key_list_->GetCurrentGpgContextChannel(), err, result);
result_analyse.Analyse();

process_result_analyse(edit_, info_board_, result_analyse);
slot_result_analyse_show_helper(result_analyse);
this->slot_refresh_current_file_view();
});
});
Expand Down Expand Up @@ -343,7 +343,7 @@ void MainWindow::SlotFileDecrypt(const QString& path) {
m_key_list_->GetCurrentGpgContextChannel(), err, result);
result_analyse.Analyse();

process_result_analyse(edit_, info_board_, result_analyse);
slot_result_analyse_show_helper(result_analyse);
this->slot_refresh_current_file_view();
});
});
Expand Down Expand Up @@ -396,7 +396,7 @@ void MainWindow::SlotArchiveDecrypt(const QString& path) {
m_key_list_->GetCurrentGpgContextChannel(), err, result);
result_analyse.Analyse();

process_result_analyse(edit_, info_board_, result_analyse);
slot_result_analyse_show_helper(result_analyse);
this->slot_refresh_current_file_view();
});
});
Expand Down Expand Up @@ -459,29 +459,29 @@ void MainWindow::SlotFileSign(const QString& path) {
CommonUtils::WaitForOpera(
this, tr("Signing"), [=](const OperaWaitingHd& op_hd) {
GpgFileOpera::GetInstance(m_key_list_->GetCurrentGpgContextChannel())
.SignFile(
{keys->begin(), keys->end()}, path,
!non_ascii_at_file_operation, sig_file_path,
[=](GpgError err, const DataObjectPtr& data_obj) {
// stop waiting
op_hd();

if (CheckGpgError(err) == GPG_ERR_USER_1 ||
data_obj == nullptr ||
!data_obj->Check<GpgSignResult>()) {
QMessageBox::critical(this, tr("Error"),
tr("Unknown error occurred"));
return;
}

auto result = ExtractParams<GpgSignResult>(data_obj, 0);
auto result_analyse = GpgSignResultAnalyse(
m_key_list_->GetCurrentGpgContextChannel(), err, result);
result_analyse.Analyse();

process_result_analyse(edit_, info_board_, result_analyse);
this->slot_refresh_current_file_view();
});
.SignFile({keys->begin(), keys->end()}, path,
!non_ascii_at_file_operation, sig_file_path,
[=](GpgError err, const DataObjectPtr& data_obj) {
// stop waiting
op_hd();

if (CheckGpgError(err) == GPG_ERR_USER_1 ||
data_obj == nullptr ||
!data_obj->Check<GpgSignResult>()) {
QMessageBox::critical(this, tr("Error"),
tr("Unknown error occurred"));
return;
}

auto result = ExtractParams<GpgSignResult>(data_obj, 0);
auto result_analyse = GpgSignResultAnalyse(
m_key_list_->GetCurrentGpgContextChannel(), err,
result);
result_analyse.Analyse();

slot_result_analyse_show_helper(result_analyse);
this->slot_refresh_current_file_view();
});
});
}

Expand Down Expand Up @@ -553,7 +553,7 @@ void MainWindow::SlotFileVerify(const QString& path) {
m_key_list_->GetCurrentGpgContextChannel(), err, result);
result_analyse.Analyse();

process_result_analyse(edit_, info_board_, result_analyse);
slot_result_analyse_show_helper(result_analyse);

if (!result_analyse.GetUnknownSignatures().isEmpty() &&
Module::IsModuleActivate(kKeyServerSyncModuleID)) {
Expand Down Expand Up @@ -706,9 +706,8 @@ void MainWindow::SlotFileEncryptSign(const QString& path) {
sign_result);
sign_result_analyse.Analyse();

process_result_analyse(edit_, info_board_,
encrypt_result_analyse,
sign_result_analyse);
slot_result_analyse_show_helper(encrypt_result_analyse,
sign_result_analyse);

this->slot_refresh_current_file_view();
});
Expand Down Expand Up @@ -827,9 +826,8 @@ void MainWindow::SlotDirectoryEncryptSign(const QString& path) {
sign_result);
sign_result_analyse.Analyse();

process_result_analyse(edit_, info_board_,
encrypt_result_analyse,
sign_result_analyse);
slot_result_analyse_show_helper(encrypt_result_analyse,
sign_result_analyse);

this->slot_refresh_current_file_view();
});
Expand Down Expand Up @@ -893,9 +891,8 @@ void MainWindow::SlotFileDecryptVerify(const QString& path) {
verify_result);
verify_result_analyse.Analyse();

process_result_analyse(edit_, info_board_,
decrypt_result_analyse,
verify_result_analyse);
slot_result_analyse_show_helper(decrypt_result_analyse,
verify_result_analyse);

this->slot_refresh_current_file_view();

Expand Down Expand Up @@ -996,9 +993,8 @@ void MainWindow::SlotArchiveDecryptVerify(const QString& path) {
verify_result);
verify_result_analyse.Analyse();

process_result_analyse(edit_, info_board_,
decrypt_result_analyse,
verify_result_analyse);
slot_result_analyse_show_helper(decrypt_result_analyse,
verify_result_analyse);

// pause this feature
// if (verify_result_analyse.GetStatus() == -2) {
Expand Down
Loading

0 comments on commit 83be6ce

Please sign in to comment.