diff options
32 files changed, 1537 insertions, 1125 deletions
diff --git a/src/ui/FindWidget.cpp b/src/ui/FindWidget.cpp index aa11f832..e6b82734 100644 --- a/src/ui/FindWidget.cpp +++ b/src/ui/FindWidget.cpp @@ -59,12 +59,12 @@ FindWidget::FindWidget(QWidget* parent, PlainTextEditorPage* edit) } void FindWidget::setBackground() { - auto cursor = mTextpage->getTextPage()->textCursor(); + auto cursor = mTextpage->GetTextPage()->textCursor(); // if match is found set background of QLineEdit to white, otherwise to red QPalette bgPalette(findEdit->palette()); if (!findEdit->text().isEmpty() && - mTextpage->getTextPage()->document()->find(findEdit->text()).position() < + mTextpage->GetTextPage()->document()->find(findEdit->text()).position() < 0) { bgPalette.setColor(QPalette::Base, "#ececba"); } else { @@ -74,45 +74,45 @@ void FindWidget::setBackground() { } void FindWidget::slotFindNext() { - QTextCursor cursor = mTextpage->getTextPage()->textCursor(); - cursor = mTextpage->getTextPage()->document()->find( + QTextCursor cursor = mTextpage->GetTextPage()->textCursor(); + cursor = mTextpage->GetTextPage()->document()->find( findEdit->text(), cursor, QTextDocument::FindCaseSensitively); // if end of document is reached, restart search from beginning if (cursor.position() == -1) { - cursor = mTextpage->getTextPage()->document()->find( + cursor = mTextpage->GetTextPage()->document()->find( findEdit->text(), cursor, QTextDocument::FindCaseSensitively); } // cursor should not stay at -1, otherwise text is not editable // todo: check how gedit handles this if (cursor.position() != -1) { - mTextpage->getTextPage()->setTextCursor(cursor); + mTextpage->GetTextPage()->setTextCursor(cursor); } this->setBackground(); } void FindWidget::slotFind() { - QTextCursor cursor = mTextpage->getTextPage()->textCursor(); + QTextCursor cursor = mTextpage->GetTextPage()->textCursor(); if (cursor.anchor() == -1) { - cursor = mTextpage->getTextPage()->document()->find( + cursor = mTextpage->GetTextPage()->document()->find( findEdit->text(), cursor, QTextDocument::FindCaseSensitively); } else { - cursor = mTextpage->getTextPage()->document()->find( + cursor = mTextpage->GetTextPage()->document()->find( findEdit->text(), cursor.anchor(), QTextDocument::FindCaseSensitively); } // if end of document is reached, restart search from beginning if (cursor.position() == -1) { - cursor = mTextpage->getTextPage()->document()->find( + cursor = mTextpage->GetTextPage()->document()->find( findEdit->text(), cursor, QTextDocument::FindCaseSensitively); } // cursor should not stay at -1, otherwise text is not editable // todo: check how gedit handles this if (cursor.position() != -1) { - mTextpage->getTextPage()->setTextCursor(cursor); + mTextpage->GetTextPage()->setTextCursor(cursor); } this->setBackground(); } @@ -122,20 +122,20 @@ void FindWidget::slotFindPrevious() { flags |= QTextDocument::FindBackward; flags |= QTextDocument::FindCaseSensitively; - QTextCursor cursor = mTextpage->getTextPage()->textCursor(); - cursor = mTextpage->getTextPage()->document()->find(findEdit->text(), cursor, + QTextCursor cursor = mTextpage->GetTextPage()->textCursor(); + cursor = mTextpage->GetTextPage()->document()->find(findEdit->text(), cursor, flags); // if begin of document is reached, restart search from end if (cursor.position() == -1) { - cursor = mTextpage->getTextPage()->document()->find( + cursor = mTextpage->GetTextPage()->document()->find( findEdit->text(), QTextCursor::End, flags); } // cursor should not stay at -1, otherwise text is not editable // todo: check how gedit handles this if (cursor.position() != -1) { - mTextpage->getTextPage()->setTextCursor(cursor); + mTextpage->GetTextPage()->setTextCursor(cursor); } this->setBackground(); } @@ -156,11 +156,11 @@ void FindWidget::keyPressEvent(QKeyEvent* e) { } void FindWidget::slotClose() { - QTextCursor cursor = mTextpage->getTextPage()->textCursor(); + QTextCursor cursor = mTextpage->GetTextPage()->textCursor(); if (cursor.position() == -1) { cursor.setPosition(0); - mTextpage->getTextPage()->setTextCursor(cursor); + mTextpage->GetTextPage()->setTextCursor(cursor); } mTextpage->setFocus(); close(); diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp index ccb49975..d236d81f 100755 --- a/src/ui/KeyMgmt.cpp +++ b/src/ui/KeyMgmt.cpp @@ -44,9 +44,9 @@ KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) { /* the list of Keys available*/ key_list_ = new KeyList(KeyMenuAbility::ALL, this); - key_list_->addListGroupTab(_("All"), KeyListRow::SECRET_OR_PUBLIC_KEY); + key_list_->AddListGroupTab(_("All"), KeyListRow::SECRET_OR_PUBLIC_KEY); - key_list_->addListGroupTab( + key_list_->AddListGroupTab( _("Only Public Key"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, @@ -55,7 +55,7 @@ KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) { !(key.IsRevoked() || key.IsDisabled() || key.IsExpired()); }); - key_list_->addListGroupTab( + key_list_->AddListGroupTab( _("Has Private Key"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, @@ -64,7 +64,7 @@ KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) { !(key.IsRevoked() || key.IsDisabled() || key.IsExpired()); }); - key_list_->addListGroupTab( + key_list_->AddListGroupTab( _("No Primary Key"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, @@ -73,24 +73,24 @@ KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) { !(key.IsRevoked() || key.IsDisabled() || key.IsExpired()); }); - key_list_->addListGroupTab( + key_list_->AddListGroupTab( _("Revoked"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, [](const GpgKey& key) -> bool { return key.IsRevoked(); }); - key_list_->addListGroupTab( + key_list_->AddListGroupTab( _("Expired"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, [](const GpgKey& key) -> bool { return key.IsExpired(); }); setCentralWidget(key_list_); - key_list_->setDoubleClickedAction([this](const GpgKey& key, QWidget* parent) { + key_list_->SetDoubleClickedAction([this](const GpgKey& key, QWidget* parent) { new KeyDetailsDialog(key, parent); }); - key_list_->slotRefresh(); + key_list_->SlotRefresh(); createActions(); createMenus(); @@ -150,8 +150,8 @@ KeyMgmt::KeyMgmt(QWidget* parent) : QMainWindow(parent) { this->statusBar()->show(); setWindowTitle(_("KeyPair Management")); - key_list_->addMenuAction(deleteSelectedKeysAct); - key_list_->addMenuAction(showKeyDetailsAct); + key_list_->AddMenuAction(deleteSelectedKeysAct); + key_list_->AddMenuAction(showKeyDetailsAct); connect(this, SIGNAL(signalKeyStatusUpdated()), SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh())); @@ -307,11 +307,11 @@ void KeyMgmt::createToolBars() { } void KeyMgmt::slotDeleteSelectedKeys() { - deleteKeysWithWarning(key_list_->getSelected()); + deleteKeysWithWarning(key_list_->GetSelected()); } void KeyMgmt::slotDeleteCheckedKeys() { - deleteKeysWithWarning(key_list_->getChecked()); + deleteKeysWithWarning(key_list_->GetChecked()); } void KeyMgmt::deleteKeysWithWarning(KeyIdArgsListPtr key_ids) { @@ -347,7 +347,7 @@ void KeyMgmt::deleteKeysWithWarning(KeyIdArgsListPtr key_ids) { } void KeyMgmt::slotShowKeyDetails() { - auto keys_selected = key_list_->getSelected(); + auto keys_selected = key_list_->GetSelected(); if (keys_selected->empty()) return; auto key = GpgKeyGetter::GetInstance().GetKey(keys_selected->front()); @@ -361,7 +361,7 @@ void KeyMgmt::slotShowKeyDetails() { } void KeyMgmt::slotExportKeyToKeyPackage() { - auto keys_checked = key_list_->getChecked(); + auto keys_checked = key_list_->GetChecked(); if (keys_checked->empty()) { QMessageBox::critical( this, _("Forbidden"), @@ -374,7 +374,7 @@ void KeyMgmt::slotExportKeyToKeyPackage() { } void KeyMgmt::slotExportKeyToClipboard() { - auto keys_checked = key_list_->getChecked(); + auto keys_checked = key_list_->GetChecked(); if (keys_checked->empty()) { QMessageBox::critical( this, _("Forbidden"), @@ -401,7 +401,7 @@ void KeyMgmt::closeEvent(QCloseEvent* event) { } void KeyMgmt::slotGenerateSubKey() { - auto keys_selected = key_list_->getSelected(); + auto keys_selected = key_list_->GetSelected(); if (keys_selected->empty()) { QMessageBox::information( this, _("Invalid Operation"), @@ -472,7 +472,7 @@ void KeyMgmt::slotSaveWindowState() { void KeyMgmt::slotExportAsOpenSSHFormat() { ByteArrayPtr key_export_data = nullptr; - auto keys_checked = key_list_->getChecked(); + auto keys_checked = key_list_->GetChecked(); if (keys_checked->empty()) { QMessageBox::critical( diff --git a/src/ui/MainWindow.cpp b/src/ui/MainWindow.cpp index 8cc6f7a9..71301cbd 100644 --- a/src/ui/MainWindow.cpp +++ b/src/ui/MainWindow.cpp @@ -70,7 +70,7 @@ void MainWindow::init() noexcept { create_status_bar(); create_dock_windows(); - connect(edit_->tabWidget, SIGNAL(currentChanged(int)), this, + connect(edit_->tab_widget_, SIGNAL(currentChanged(int)), this, SLOT(slot_disable_tab_actions(int))); connect(SignalStation::GetInstance(), &SignalStation::signalRefreshStatusBar, this, @@ -78,10 +78,10 @@ void MainWindow::init() noexcept { statusBar()->showMessage(message, timeout); }); - m_key_list_->addMenuAction(append_selected_keys_act_); - m_key_list_->addMenuAction(copy_mail_address_to_clipboard_act_); - m_key_list_->addSeparator(); - m_key_list_->addMenuAction(show_key_details_act_); + m_key_list_->AddMenuAction(append_selected_keys_act_); + m_key_list_->AddMenuAction(copy_mail_address_to_clipboard_act_); + m_key_list_->AddSeparator(); + m_key_list_->AddMenuAction(show_key_details_act_); restore_settings(); @@ -89,10 +89,10 @@ void MainWindow::init() noexcept { QStringList args = qApp->arguments(); if (args.size() > 1) { if (!args[1].startsWith("-")) { - if (QFile::exists(args[1])) edit_->loadFile(args[1]); + if (QFile::exists(args[1])) edit_->LoadFile(args[1]); } } - edit_->curTextPage()->setFocus(); + edit_->CurTextPage()->setFocus(); auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); @@ -233,7 +233,7 @@ void MainWindow::restore_settings() { LOG(INFO) << "get checked key id" << key_id; key_ids_ptr->push_back(key_id); } - m_key_list_->setChecked(std::move(key_ids_ptr)); + m_key_list_->SetChecked(std::move(key_ids_ptr)); } } catch (...) { LOG(ERROR) << "restore default_key_checked failed"; @@ -276,7 +276,7 @@ void MainWindow::save_settings() { // keyid-list of private checked keys if (save_key_checked) { - auto key_ids_need_to_store = m_key_list_->getChecked(); + auto key_ids_need_to_store = m_key_list_->GetChecked(); SettingsObject default_key_checked("default_key_checked"); default_key_checked.clear(); @@ -307,7 +307,7 @@ void MainWindow::closeEvent(QCloseEvent* event) { * ask to save changes, if there are * modified documents in any tab */ - if (edit_->maybeSaveAnyTab()) { + if (edit_->MaybeSaveAnyTab()) { save_settings(); event->accept(); } else { diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index b72ee925..c9fa1de2 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -46,7 +46,7 @@ std::unique_ptr<GpgFrontend::UI::CommonUtils> #ifdef SMTP_SUPPORT void send_an_email(QWidget* parent, InfoBoardWidget* info_board, const QString& text, bool attach_signature) { - info_board->addOptionalAction(_("Send Encrypted Mail"), [=]() { + info_board->AddOptionalAction(_("Send Encrypted Mail"), [=]() { bool smtp_enabled = false; try { smtp_enabled = GlobalSettingStation::GetInstance().GetUISettings().lookup( @@ -71,8 +71,8 @@ void send_an_email(QWidget* parent, InfoBoardWidget* info_board, void show_verify_details(QWidget* parent, InfoBoardWidget* info_board, GpgError error, const GpgVerifyResult& verify_result) { // take out result - info_board->resetOptionActionsMenu(); - info_board->addOptionalAction("Show Verify Details", [=]() { + info_board->ResetOptionActionsMenu(); + info_board->AddOptionalAction("Show Verify Details", [=]() { VerifyDetailsDialog(parent, error, verify_result); }); } @@ -103,18 +103,18 @@ void import_unknown_key_from_keyserver(QWidget* parent, void refresh_info_board(InfoBoardWidget* info_board, int status, const std::string& report_text) { if (status < 0) - info_board->slotRefresh(QString::fromStdString(report_text), + info_board->SlotRefresh(QString::fromStdString(report_text), INFO_ERROR_CRITICAL); else if (status > 0) - info_board->slotRefresh(QString::fromStdString(report_text), INFO_ERROR_OK); + info_board->SlotRefresh(QString::fromStdString(report_text), INFO_ERROR_OK); else - info_board->slotRefresh(QString::fromStdString(report_text), + info_board->SlotRefresh(QString::fromStdString(report_text), INFO_ERROR_WARN); } void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, const ResultAnalyse& result_analyse) { - info_board->associateTabWidget(edit->tabWidget); + info_board->AssociateTabWidget(edit->tab_widget_); refresh_info_board(info_board, result_analyse.GetStatus(), result_analyse.GetResultReport()); } @@ -124,7 +124,7 @@ void process_result_analyse(TextEdit* edit, InfoBoardWidget* info_board, const ResultAnalyse& result_analyse_b) { LOG(INFO) << "process_result_analyse Started"; - info_board->associateTabWidget(edit->tabWidget); + info_board->AssociateTabWidget(edit->tab_widget_); refresh_info_board( info_board, diff --git a/src/ui/keypair_details/KeyUIDSignDialog.cpp b/src/ui/keypair_details/KeyUIDSignDialog.cpp index 674d0ddb..b8f10f92 100644 --- a/src/ui/keypair_details/KeyUIDSignDialog.cpp +++ b/src/ui/keypair_details/KeyUIDSignDialog.cpp @@ -37,7 +37,7 @@ KeyUIDSignDialog::KeyUIDSignDialog(const GpgKey& key, UIDArgsListPtr uid, : QDialog(parent), m_uids_(std::move(uid)), m_key_(key) { const auto key_id = m_key_.GetId(); m_key_list_ = new KeyList(KeyMenuAbility::NONE, this); - m_key_list_->addListGroupTab( + m_key_list_->AddListGroupTab( _("Signers"), KeyListRow::ONLY_SECRET_KEY, KeyListColumn::NAME | KeyListColumn::EmailAddress, [key_id](const GpgKey& key) -> bool { @@ -48,7 +48,7 @@ KeyUIDSignDialog::KeyUIDSignDialog(const GpgKey& key, UIDArgsListPtr uid, else return true; }); - m_key_list_->slotRefresh(); + m_key_list_->SlotRefresh(); sign_key_button_ = new QPushButton("Sign"); @@ -104,7 +104,7 @@ void KeyUIDSignDialog::slot_sign_key(bool clicked) { LOG(INFO) << "Called"; // Set Signers - auto key_ids = m_key_list_->getChecked(); + auto key_ids = m_key_list_->GetChecked(); auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); LOG(INFO) << "Key Info Got"; diff --git a/src/ui/main_window/MainWindowFileSlotFunction.cpp b/src/ui/main_window/MainWindowFileSlotFunction.cpp index ab8aea87..4ab7385e 100644 --- a/src/ui/main_window/MainWindowFileSlotFunction.cpp +++ b/src/ui/main_window/MainWindowFileSlotFunction.cpp @@ -57,13 +57,13 @@ bool file_pre_check(QWidget* parent, const QString& path) { } void MainWindow::SlotFileEncrypt() { - auto fileTreeView = edit_->slotCurPageFileTreeView(); - auto path = fileTreeView->getSelected(); + auto fileTreeView = edit_->SlotCurPageFileTreeView(); + auto path = fileTreeView->GetSelected(); if (!file_pre_check(this, path)) return; // check selected keys - auto key_ids = m_key_list_->getChecked(); + auto key_ids = m_key_list_->GetChecked(); GpgEncrResult result = nullptr; GpgError error; bool if_error = false; @@ -157,8 +157,8 @@ void MainWindow::SlotFileEncrypt() { } void MainWindow::SlotFileDecrypt() { - auto fileTreeView = edit_->slotCurPageFileTreeView(); - auto path = fileTreeView->getSelected(); + auto fileTreeView = edit_->SlotCurPageFileTreeView(); + auto path = fileTreeView->GetSelected(); if (!file_pre_check(this, path)) return; @@ -205,12 +205,12 @@ void MainWindow::SlotFileDecrypt() { } void MainWindow::SlotFileSign() { - auto fileTreeView = edit_->slotCurPageFileTreeView(); - auto path = fileTreeView->getSelected(); + auto fileTreeView = edit_->SlotCurPageFileTreeView(); + auto path = fileTreeView->GetSelected(); if (!file_pre_check(this, path)) return; - auto key_ids = m_key_list_->getChecked(); + auto key_ids = m_key_list_->GetChecked(); auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); if (keys->empty()) { @@ -292,8 +292,8 @@ void MainWindow::SlotFileSign() { } void MainWindow::SlotFileVerify() { - auto fileTreeView = edit_->slotCurPageFileTreeView(); - auto path = fileTreeView->getSelected(); + auto fileTreeView = edit_->SlotCurPageFileTreeView(); + auto path = fileTreeView->GetSelected(); boost::filesystem::path in_path = path.toStdString(); boost::filesystem::path sign_file_path = in_path, data_file_path; @@ -376,13 +376,13 @@ void MainWindow::SlotFileVerify() { } void MainWindow::SlotFileEncryptSign() { - auto fileTreeView = edit_->slotCurPageFileTreeView(); - auto path = fileTreeView->getSelected(); + auto fileTreeView = edit_->SlotCurPageFileTreeView(); + auto path = fileTreeView->GetSelected(); if (!file_pre_check(this, path)) return; // check selected keys - auto key_ids = m_key_list_->getChecked(); + auto key_ids = m_key_list_->GetChecked(); auto p_keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); if (p_keys->empty()) { @@ -438,7 +438,7 @@ void MainWindow::SlotFileEncryptSign() { connect(signersPicker, SIGNAL(finished(int)), &loop, SLOT(quit())); loop.exec(); - auto signer_key_ids = signersPicker->getCheckedSigners(); + auto signer_key_ids = signersPicker->GetCheckedSigners(); auto p_signer_keys = GpgKeyGetter::GetInstance().GetKeys(signer_key_ids); GpgEncrResult encr_result = nullptr; @@ -474,8 +474,8 @@ void MainWindow::SlotFileEncryptSign() { } void MainWindow::SlotFileDecryptVerify() { - auto fileTreeView = edit_->slotCurPageFileTreeView(); - auto path = fileTreeView->getSelected(); + auto fileTreeView = edit_->SlotCurPageFileTreeView(); + auto path = fileTreeView->GetSelected(); if (!file_pre_check(this, path)) return; diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 2c290497..7090021a 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -52,9 +52,9 @@ namespace GpgFrontend::UI { * Encrypt Entry(Text & File) */ void MainWindow::slot_encrypt() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) return; + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return; - auto key_ids = m_key_list_->getChecked(); + auto key_ids = m_key_list_->GetChecked(); GpgEncrResult result = nullptr; GpgError error; @@ -74,7 +74,7 @@ void MainWindow::slot_encrypt() { process_operation(this, _("Symmetrically Encrypting"), [&]() { try { auto buffer = - edit_->curTextPage()->getTextPage()->toPlainText().toStdString(); + edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString(); error = GpgFrontend::BasicOperator::GetInstance().EncryptSymmetric( buffer, tmp, result); } catch (const std::runtime_error& e) { @@ -100,7 +100,7 @@ void MainWindow::slot_encrypt() { process_operation(this, _("Encrypting"), [&]() { try { auto buffer = - edit_->curTextPage()->getTextPage()->toPlainText().toStdString(); + edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString(); error = GpgFrontend::BasicOperator::GetInstance().Encrypt( std::move(keys), buffer, tmp, result); } catch (const std::runtime_error& e) { @@ -116,12 +116,12 @@ void MainWindow::slot_encrypt() { process_result_analyse(edit_, info_board_, resultAnalyse); if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) - edit_->slotFillTextEditWithText(QString::fromStdString(*tmp)); - info_board_->resetOptionActionsMenu(); + edit_->SlotFillTextEditWithText(QString::fromStdString(*tmp)); + info_board_->ResetOptionActionsMenu(); #ifdef SMTP_SUPPORT if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) send_an_email(this, info_board_, - edit_->curTextPage()->getTextPage()->toPlainText()); + edit_->CurTextPage()->GetTextPage()->toPlainText()); #endif } else { QMessageBox::critical(this, _("Error"), @@ -131,9 +131,9 @@ void MainWindow::slot_encrypt() { } void MainWindow::slot_sign() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) return; + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return; - auto key_ids = m_key_list_->getPrivateChecked(); + auto key_ids = m_key_list_->GetPrivateChecked(); if (key_ids->empty()) { QMessageBox::critical( @@ -164,8 +164,8 @@ void MainWindow::slot_sign() { process_operation(this, _("Signing"), [&]() { try { - auto buffer = edit_->curTextPage() - ->getTextPage() + auto buffer = edit_->CurTextPage() + ->GetTextPage() ->toPlainText() .toUtf8() .toStdString(); @@ -182,7 +182,7 @@ void MainWindow::slot_sign() { process_result_analyse(edit_, info_board_, resultAnalyse); if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) - edit_->slotFillTextEditWithText(QString::fromStdString(*tmp)); + edit_->SlotFillTextEditWithText(QString::fromStdString(*tmp)); } else { QMessageBox::critical(this, _("Error"), _("An error occurred during operation.")); @@ -191,10 +191,10 @@ void MainWindow::slot_sign() { } void MainWindow::slot_decrypt() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) return; + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return; auto decrypted = std::make_unique<ByteArray>(); - QByteArray text = edit_->curTextPage()->getTextPage()->toPlainText().toUtf8(); + QByteArray text = edit_->CurTextPage()->GetTextPage()->toPlainText().toUtf8(); if (text.trimmed().startsWith(GpgConstants::GPG_FRONTEND_SHORT_CRYPTO_HEAD)) { QMessageBox::critical( @@ -222,7 +222,7 @@ void MainWindow::slot_decrypt() { process_result_analyse(edit_, info_board_, resultAnalyse); if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) - edit_->slotFillTextEditWithText(QString::fromStdString(*decrypted)); + edit_->SlotFillTextEditWithText(QString::fromStdString(*decrypted)); } else { QMessageBox::critical(this, _("Error"), _("An error occurred during operation.")); @@ -231,21 +231,21 @@ void MainWindow::slot_decrypt() { } void MainWindow::slot_find() { - if (edit_->tabCount() == 0 || edit_->curTextPage() == nullptr) { + if (edit_->TabCount() == 0 || edit_->CurTextPage() == nullptr) { return; } // At first close verifynotification, if existing - edit_->slotCurPageTextEdit()->closeNoteByClass("findwidget"); + edit_->SlotCurPageTextEdit()->CloseNoteByClass("findwidget"); - auto* fw = new FindWidget(this, edit_->curTextPage()); - edit_->slotCurPageTextEdit()->showNotificationWidget(fw, "findWidget"); + auto* fw = new FindWidget(this, edit_->CurTextPage()); + edit_->SlotCurPageTextEdit()->ShowNotificationWidget(fw, "findWidget"); } void MainWindow::slot_verify() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) return; + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return; - auto text = edit_->curTextPage()->getTextPage()->toPlainText().toUtf8(); + auto text = edit_->CurTextPage()->GetTextPage()->toPlainText().toUtf8(); // TODO(Saturneric) PreventNoDataErr auto sig_buffer = std::make_unique<ByteArray>(); @@ -278,9 +278,9 @@ void MainWindow::slot_verify() { } void MainWindow::slot_encrypt_sign() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) return; + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return; - auto key_ids = m_key_list_->getChecked(); + auto key_ids = m_key_list_->GetChecked(); if (key_ids->empty()) { QMessageBox::critical( @@ -309,7 +309,7 @@ void MainWindow::slot_encrypt_sign() { connect(signersPicker, SIGNAL(finished(int)), &loop, SLOT(quit())); loop.exec(); - auto signer_key_ids = signersPicker->getCheckedSigners(); + auto signer_key_ids = signersPicker->GetCheckedSigners(); auto signer_keys = GpgKeyGetter::GetInstance().GetKeys(signer_key_ids); for (const auto& key : *keys) { @@ -328,8 +328,8 @@ void MainWindow::slot_encrypt_sign() { auto tmp = std::make_unique<ByteArray>(); process_operation(this, _("Encrypting and Signing"), [&]() { try { - auto buffer = edit_->curTextPage() - ->getTextPage() + auto buffer = edit_->CurTextPage() + ->GetTextPage() ->toPlainText() .toUtf8() .toStdString(); @@ -362,13 +362,13 @@ void MainWindow::slot_encrypt_sign() { sign_res.Analyse(); process_result_analyse(edit_, info_board_, encrypt_res, sign_res); if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) - edit_->slotFillTextEditWithText(QString::fromStdString(*tmp)); + edit_->SlotFillTextEditWithText(QString::fromStdString(*tmp)); - info_board_->resetOptionActionsMenu(); + info_board_->ResetOptionActionsMenu(); #ifdef SMTP_SUPPORT if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) send_an_email(this, info_board_, - edit_->curTextPage()->getTextPage()->toPlainText(), false); + edit_->CurTextPage()->GetTextPage()->toPlainText(), false); #endif #ifdef ADVANCE_SUPPORT @@ -390,9 +390,9 @@ void MainWindow::slot_encrypt_sign() { } void MainWindow::slot_decrypt_verify() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) return; + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return; - QString plainText = edit_->curTextPage()->getTextPage()->toPlainText(); + QString plainText = edit_->CurTextPage()->GetTextPage()->toPlainText(); #ifdef ADVANCE_SUPPORT if (plainText.trimmed().startsWith( @@ -442,7 +442,7 @@ void MainWindow::slot_decrypt_verify() { verify_res.Analyse(); process_result_analyse(edit_, info_board_, decrypt_res, verify_res); if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) - edit_->slotFillTextEditWithText(QString::fromStdString(*decrypted)); + edit_->SlotFillTextEditWithText(QString::fromStdString(*decrypted)); if (verify_res.GetStatus() == -2) import_unknown_key_from_keyserver(this, verify_res); @@ -461,20 +461,20 @@ void MainWindow::slot_decrypt_verify() { * Append the selected (not checked!) Key(s) To Textedit */ void MainWindow::slot_append_selected_keys() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) { + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) { return; } auto exported = std::make_unique<ByteArray>(); - auto key_ids = m_key_list_->getSelected(); + auto key_ids = m_key_list_->GetSelected(); GpgKeyImportExporter::GetInstance().ExportKeys(key_ids, exported); - edit_->curTextPage()->getTextPage()->appendPlainText( + edit_->CurTextPage()->GetTextPage()->appendPlainText( QString::fromStdString(*exported)); } void MainWindow::slot_copy_mail_address_to_clipboard() { - auto key_ids = m_key_list_->getSelected(); + auto key_ids = m_key_list_->GetSelected(); if (key_ids->empty()) return; auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); @@ -487,7 +487,7 @@ void MainWindow::slot_copy_mail_address_to_clipboard() { } void MainWindow::slot_show_key_details() { - auto key_ids = m_key_list_->getSelected(); + auto key_ids = m_key_list_->GetSelected(); if (key_ids->empty()) return; auto key = GpgKeyGetter::GetInstance().GetKey(key_ids->front()); @@ -499,7 +499,7 @@ void MainWindow::slot_show_key_details() { } void MainWindow::refresh_keys_from_key_server() { - auto key_ids = m_key_list_->getSelected(); + auto key_ids = m_key_list_->GetSelected(); if (key_ids->empty()) return; auto* dialog = new KeyServerImportDialog(this); @@ -508,13 +508,13 @@ void MainWindow::refresh_keys_from_key_server() { } void MainWindow::upload_key_to_server() { - auto key_ids = m_key_list_->getSelected(); + auto key_ids = m_key_list_->GetSelected(); auto* dialog = new KeyUploadDialog(key_ids, this); dialog->show(); dialog->slotUpload(); } -void MainWindow::SlotOpenFile(QString& path) { edit_->slotOpenFile(path); } +void MainWindow::SlotOpenFile(QString& path) { edit_->SlotOpenFile(path); } void MainWindow::slot_version_upgrade(const SoftwareVersion& version) { LOG(INFO) << _("called"); diff --git a/src/ui/main_window/MainWindowSlotUI.cpp b/src/ui/main_window/MainWindowSlotUI.cpp index 6fdca5fa..052bc018 100644 --- a/src/ui/main_window/MainWindowSlotUI.cpp +++ b/src/ui/main_window/MainWindowSlotUI.cpp @@ -43,9 +43,9 @@ void MainWindow::slot_start_wizard() { } void MainWindow::slot_import_key_from_edit() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) return; + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) return; CommonUtils::GetInstance()->slotImportKeys( - this, edit_->curTextPage()->getTextPage()->toPlainText().toStdString()); + this, edit_->CurTextPage()->GetTextPage()->toPlainText().toStdString()); } void MainWindow::slot_open_key_management() { @@ -54,7 +54,7 @@ void MainWindow::slot_open_key_management() { dialog->raise(); } -void MainWindow::slot_open_file_tab() { edit_->slotNewFileTab(); } +void MainWindow::slot_open_file_tab() { edit_->SlotNewFileTab(); } void MainWindow::slot_disable_tab_actions(int number) { bool disable; @@ -64,7 +64,7 @@ void MainWindow::slot_disable_tab_actions(int number) { else disable = false; - if (edit_->curFilePage() != nullptr) { + if (edit_->CurFilePage() != nullptr) { disable = true; } @@ -121,7 +121,7 @@ void MainWindow::slot_open_settings_dialog() { // restart mainwindow if necessary if (get_restart_needed()) { - if (edit_->maybeSaveAnyTab()) { + if (edit_->MaybeSaveAnyTab()) { save_settings(); qApp->exit(RESTART_CODE); } @@ -139,35 +139,35 @@ void MainWindow::slot_open_settings_dialog() { } void MainWindow::slot_clean_double_line_breaks() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) { + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) { return; } - QString content = edit_->curTextPage()->getTextPage()->toPlainText(); + QString content = edit_->CurTextPage()->GetTextPage()->toPlainText(); content.replace("\n\n", "\n"); - edit_->slotFillTextEditWithText(content); + edit_->SlotFillTextEditWithText(content); } void MainWindow::slot_add_pgp_header() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) { + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) { return; } QString content = - edit_->curTextPage()->getTextPage()->toPlainText().trimmed(); + edit_->CurTextPage()->GetTextPage()->toPlainText().trimmed(); content.prepend("\n\n").prepend(GpgConstants::PGP_CRYPT_BEGIN); content.append("\n").append(GpgConstants::PGP_CRYPT_END); - edit_->slotFillTextEditWithText(content); + edit_->SlotFillTextEditWithText(content); } void MainWindow::slot_cut_pgp_header() { - if (edit_->tabCount() == 0 || edit_->slotCurPageTextEdit() == nullptr) { + if (edit_->TabCount() == 0 || edit_->SlotCurPageTextEdit() == nullptr) { return; } - QString content = edit_->curTextPage()->getTextPage()->toPlainText(); + QString content = edit_->CurTextPage()->GetTextPage()->toPlainText(); int start = content.indexOf(GpgConstants::PGP_CRYPT_BEGIN); int end = content.indexOf(GpgConstants::PGP_CRYPT_END); @@ -183,7 +183,7 @@ void MainWindow::slot_cut_pgp_header() { end = content.indexOf(GpgConstants::PGP_CRYPT_END); content.remove(end, QString(GpgConstants::PGP_CRYPT_END).size()); - edit_->slotFillTextEditWithText(content.trimmed()); + edit_->SlotFillTextEditWithText(content.trimmed()); } void MainWindow::slot_set_restart_needed(bool needed) { diff --git a/src/ui/main_window/MainWindowUI.cpp b/src/ui/main_window/MainWindowUI.cpp index 8c093e6f..85e2ae08 100644 --- a/src/ui/main_window/MainWindowUI.cpp +++ b/src/ui/main_window/MainWindowUI.cpp @@ -490,7 +490,7 @@ void MainWindow::create_dock_windows() { key_list_dock_->setMinimumWidth(460); addDockWidget(Qt::RightDockWidgetArea, key_list_dock_); - m_key_list_->addListGroupTab( + m_key_list_->AddListGroupTab( _("Default"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, @@ -498,7 +498,7 @@ void MainWindow::create_dock_windows() { return !(key.IsRevoked() || key.IsDisabled() || key.IsExpired()); }); - m_key_list_->addListGroupTab( + m_key_list_->AddListGroupTab( _("Only Public Key"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, @@ -507,7 +507,7 @@ void MainWindow::create_dock_windows() { !(key.IsRevoked() || key.IsDisabled() || key.IsExpired()); }); - m_key_list_->addListGroupTab( + m_key_list_->AddListGroupTab( _("Has Private Key"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::TYPE | KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage | KeyListColumn::Validity, @@ -516,7 +516,7 @@ void MainWindow::create_dock_windows() { !(key.IsRevoked() || key.IsDisabled() || key.IsExpired()); }); - m_key_list_->slotRefresh(); + m_key_list_->SlotRefresh(); key_list_dock_->setWidget(m_key_list_); view_menu_->addAction(key_list_dock_->toggleViewAction()); diff --git a/src/ui/smtp/RecipientsPicker.cpp b/src/ui/smtp/RecipientsPicker.cpp index 17a08705..88e823a9 100644 --- a/src/ui/smtp/RecipientsPicker.cpp +++ b/src/ui/smtp/RecipientsPicker.cpp @@ -38,19 +38,19 @@ GpgFrontend::UI::RecipientsPicker::RecipientsPicker( // Setup KeyList key_list_ = new KeyList(KeyMenuAbility::NONE, this); - key_list_->addListGroupTab( + key_list_->AddListGroupTab( _("Recipient(s)"), KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::NAME | KeyListColumn::EmailAddress, [](const GpgKey& key) -> bool { return !key.IsPrivateKey() && key.IsHasActualEncryptionCapability(); }); - key_list_->slotRefresh(); + key_list_->SlotRefresh(); auto key_ids = std::make_unique<GpgFrontend::KeyIdArgsList>(); for (const auto& key_id : *current_key_ids) { key_ids->push_back(key_id); } - key_list_->setChecked(std::move(key_ids)); + key_list_->SetChecked(std::move(key_ids)); auto* vbox2 = new QVBoxLayout(); vbox2->addWidget(new QLabel(QString(_("Select Recipient(s)")) + ": ")); @@ -76,5 +76,5 @@ GpgFrontend::UI::RecipientsPicker::RecipientsPicker( GpgFrontend::KeyIdArgsListPtr GpgFrontend::UI::RecipientsPicker::GetCheckedRecipients() { - return key_list_->getChecked(); + return key_list_->GetChecked(); } diff --git a/src/ui/smtp/SenderPicker.cpp b/src/ui/smtp/SenderPicker.cpp index e88f57cc..dce72332 100644 --- a/src/ui/smtp/SenderPicker.cpp +++ b/src/ui/smtp/SenderPicker.cpp @@ -38,16 +38,16 @@ GpgFrontend::UI::SenderPicker::SenderPicker(const KeyId& current_key_id, // Setup KeyList key_list_ = new KeyList(KeyMenuAbility::NONE, this); - key_list_->addListGroupTab(_("Sender"), KeyListRow::ONLY_SECRET_KEY, + key_list_->AddListGroupTab(_("Sender"), KeyListRow::ONLY_SECRET_KEY, KeyListColumn::NAME | KeyListColumn::EmailAddress, [](const GpgKey& key) -> bool { return key.IsHasActualSigningCapability(); }); - key_list_->slotRefresh(); + key_list_->SlotRefresh(); auto key_ids = std::make_unique<GpgFrontend::KeyIdArgsList>(); key_ids->push_back(current_key_id); - key_list_->setChecked(std::move(key_ids)); + key_list_->SetChecked(std::move(key_ids)); auto* vbox2 = new QVBoxLayout(); vbox2->addWidget(new QLabel(QString(_("Select Sender")) + ": ")); @@ -72,9 +72,9 @@ GpgFrontend::UI::SenderPicker::SenderPicker(const KeyId& current_key_id, } GpgFrontend::KeyId GpgFrontend::UI::SenderPicker::GetCheckedSender() { - auto checked_keys = key_list_->getChecked(); + auto checked_keys = key_list_->GetChecked(); if (!checked_keys->empty()) { - return key_list_->getChecked()->front(); + return key_list_->GetChecked()->front(); } else { return {}; } diff --git a/src/ui/widgets/ExportKeyPackageDialog.cpp b/src/ui/widgets/ExportKeyPackageDialog.cpp index 29d2922e..1317c1e6 100644 --- a/src/ui/widgets/ExportKeyPackageDialog.cpp +++ b/src/ui/widgets/ExportKeyPackageDialog.cpp @@ -37,42 +37,42 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog( KeyIdArgsListPtr key_ids, QWidget* parent) : QDialog(parent), - ui(std::make_shared<Ui_exportKeyPackageDialog>()), + ui_(std::make_shared<Ui_exportKeyPackageDialog>()), key_ids_(std::move(key_ids)), - mt(rd()) { - ui->setupUi(this); + mt_(rd_()) { + ui_->setupUi(this); generate_key_package_name(); - connect(ui->gnerateNameButton, &QPushButton::clicked, this, + connect(ui_->gnerateNameButton, &QPushButton::clicked, this, [=]() { generate_key_package_name(); }); - connect(ui->setOutputPathButton, &QPushButton::clicked, this, [=]() { + connect(ui_->setOutputPathButton, &QPushButton::clicked, this, [=]() { auto file_name = QFileDialog::getSaveFileName( - this, _("Export Key Package"), ui->nameValueLabel->text() + ".gfepack", + this, _("Export Key Package"), ui_->nameValueLabel->text() + ".gfepack", QString(_("Key Package")) + " (*.gfepack);;All Files (*)"); - ui->outputPathLabel->setText(file_name); + ui_->outputPathLabel->setText(file_name); }); - connect(ui->generatePassphraseButton, &QPushButton::clicked, this, [=]() { + connect(ui_->generatePassphraseButton, &QPushButton::clicked, this, [=]() { passphrase_ = generate_passphrase(256); auto file_name = QFileDialog::getSaveFileName( this, _("Export Key Package Passphrase"), - ui->nameValueLabel->text() + ".key", + ui_->nameValueLabel->text() + ".key", QString(_("Key File")) + " (*.key);;All Files (*)"); - ui->passphraseValueLabel->setText(file_name); + ui_->passphraseValueLabel->setText(file_name); write_buffer_to_file(file_name.toStdString(), passphrase_); }); - connect(ui->button_box_, &QDialogButtonBox::accepted, this, [=]() { - if (ui->outputPathLabel->text().isEmpty()) { + connect(ui_->button_box_, &QDialogButtonBox::accepted, this, [=]() { + if (ui_->outputPathLabel->text().isEmpty()) { QMessageBox::critical( this, _("Forbidden"), _("Please select an output path before exporting.")); return; } - if (ui->passphraseValueLabel->text().isEmpty()) { + if (ui_->passphraseValueLabel->text().isEmpty()) { QMessageBox::critical( this, _("Forbidden"), _("Please generate a password to protect your key before exporting, " @@ -84,7 +84,7 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog( auto key_id_exported = std::make_unique<KeyIdArgsList>(); auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids_); for (const auto& key : *keys) { - if (ui->noPublicKeyCheckBox->isChecked() && !key.IsPrivateKey()) { + if (ui_->noPublicKeyCheckBox->isChecked() && !key.IsPrivateKey()) { continue; } key_id_exported->push_back(key.GetId()); @@ -93,7 +93,7 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog( ByteArrayPtr key_export_data = nullptr; if (!GpgKeyImportExporter::GetInstance().ExportKeys( key_ids_, key_export_data, - ui->includeSecretKeyCheckBox->isChecked())) { + ui_->includeSecretKeyCheckBox->isChecked())) { QMessageBox::critical(this, _("Error"), _("Export Key(s) Failed.")); this->close(); return; @@ -108,7 +108,7 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog( QAESEncryption::Padding::ISO); auto encoded = encryption.encode(data, hash_key); - write_buffer_to_file(ui->outputPathLabel->text().toStdString(), + write_buffer_to_file(ui_->outputPathLabel->text().toStdString(), encoded.toStdString()); QMessageBox::information( @@ -125,22 +125,22 @@ GpgFrontend::UI::ExportKeyPackageDialog::ExportKeyPackageDialog( "</b>"); }); - connect(ui->button_box_, &QDialogButtonBox::rejected, this, + connect(ui_->button_box_, &QDialogButtonBox::rejected, this, [=]() { this->close(); }); - ui->nameLabel->setText(_("Key Package Name")); - ui->selectOutputPathLabel->setText(_("Output Path")); - ui->passphraseLabel->setText(_("Passphrase")); - ui->tipsLabel->setText( + ui_->nameLabel->setText(_("Key Package Name")); + ui_->selectOutputPathLabel->setText(_("Output Path")); + ui_->passphraseLabel->setText(_("Passphrase")); + ui_->tipsLabel->setText( _("Tips: You can use Key Package to safely and conveniently transfer " "your public and private keys between devices.")); - ui->generatePassphraseButton->setText(_("Generate and Save Passphrase")); - ui->gnerateNameButton->setText(_("Generate Key Package Name")); - ui->setOutputPathButton->setText(_("Select Output Path")); + ui_->generatePassphraseButton->setText(_("Generate and Save Passphrase")); + ui_->gnerateNameButton->setText(_("Generate Key Package Name")); + ui_->setOutputPathButton->setText(_("Select Output Path")); - ui->includeSecretKeyCheckBox->setText( + ui_->includeSecretKeyCheckBox->setText( _("Include secret key (Think twice before acting)")); - ui->noPublicKeyCheckBox->setText( + ui_->noPublicKeyCheckBox->setText( _("Exclude keys that do not have a private key")); setAttribute(Qt::WA_DeleteOnClose); @@ -158,7 +158,7 @@ std::string GpgFrontend::UI::ExportKeyPackageDialog::generate_passphrase( tmp_str.reserve(len); for (int i = 0; i < len; ++i) { - tmp_str += alphanum[dist(mt) % (sizeof(alphanum) - 1)]; + tmp_str += alphanum[dist(mt_) % (sizeof(alphanum) - 1)]; } return tmp_str; @@ -166,8 +166,8 @@ std::string GpgFrontend::UI::ExportKeyPackageDialog::generate_passphrase( void GpgFrontend::UI::ExportKeyPackageDialog::generate_key_package_name() { std::uniform_int_distribution<int> dist(999, 99999); - auto file_string = boost::format("KeyPackage_%1%") % dist(mt); - ui->nameValueLabel->setText(file_string.str().c_str()); - ui->outputPathLabel->clear(); - ui->passphraseValueLabel->clear(); + auto file_string = boost::format("KeyPackage_%1%") % dist(mt_); + ui_->nameValueLabel->setText(file_string.str().c_str()); + ui_->outputPathLabel->clear(); + ui_->passphraseValueLabel->clear(); } diff --git a/src/ui/widgets/ExportKeyPackageDialog.h b/src/ui/widgets/ExportKeyPackageDialog.h index 5a7c3952..68f9b433 100644 --- a/src/ui/widgets/ExportKeyPackageDialog.h +++ b/src/ui/widgets/ExportKeyPackageDialog.h @@ -35,23 +35,41 @@ class Ui_exportKeyPackageDialog; namespace GpgFrontend::UI { +/** + * @brief + * + */ class ExportKeyPackageDialog : public QDialog { Q_OBJECT public: + /** + * @brief Construct a new Export Key Package Dialog object + * + * @param key_ids + * @param parent + */ explicit ExportKeyPackageDialog(KeyIdArgsListPtr key_ids, QWidget* parent); - std::string generate_passphrase(int len); - private: - std::shared_ptr<Ui_exportKeyPackageDialog> ui; - KeyIdArgsListPtr key_ids_; - - std::random_device rd; - std::mt19937 mt; + std::shared_ptr<Ui_exportKeyPackageDialog> ui_; ///< + KeyIdArgsListPtr key_ids_; ///< + std::random_device rd_; ///< + std::mt19937 mt_; ///< + std::string passphrase_; ///< - std::string passphrase_; + /** + * @brief + * + * @param len + * @return std::string + */ + std::string generate_passphrase(int len); + /** + * @brief + * + */ void generate_key_package_name(); }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp index 508bba9e..49ecd9dd 100644 --- a/src/ui/widgets/FilePage.cpp +++ b/src/ui/widgets/FilePage.cpp @@ -38,46 +38,47 @@ namespace GpgFrontend::UI { FilePage::FilePage(QWidget* parent) - : QWidget(parent), ui(std::make_shared<Ui_FilePage>()) { - ui->setupUi(this); - - firstParent = parent; - - dirModel = new QFileSystemModel(); - dirModel->setRootPath(QDir::currentPath()); - dirModel->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); - - ui->fileTreeView->setModel(dirModel); - ui->fileTreeView->setColumnWidth(0, 320); - ui->fileTreeView->sortByColumn(0, Qt::AscendingOrder); - mPath = boost::filesystem::path(dirModel->rootPath().toStdString()); - - createPopupMenu(); - - connect(ui->upPathButton, &QPushButton::clicked, this, - &FilePage::slotUpLevel); - connect(ui->refreshButton, &QPushButton::clicked, this, - &FilePage::slotGoPath); - ui->optionsButton->setMenu(optionPopUpMenu); - - ui->pathEdit->setText(dirModel->rootPath()); - - pathEditCompleter = new QCompleter(this); - pathCompleteModel = new QStringListModel(); - pathEditCompleter->setModel(pathCompleteModel); - pathEditCompleter->setCaseSensitivity(Qt::CaseInsensitive); - pathEditCompleter->setCompletionMode(QCompleter::UnfilteredPopupCompletion); - ui->pathEdit->setCompleter(pathEditCompleter); - - connect(ui->fileTreeView, &QTreeView::clicked, this, - &FilePage::fileTreeViewItemClicked); - connect(ui->fileTreeView, &QTreeView::doubleClicked, this, - &FilePage::fileTreeViewItemDoubleClicked); - connect(ui->fileTreeView, &QTreeView::customContextMenuRequested, this, + : QWidget(parent), ui_(std::make_shared<Ui_FilePage>()) { + ui_->setupUi(this); + + first_parent_ = parent; + + dir_model_ = new QFileSystemModel(); + dir_model_->setRootPath(QDir::currentPath()); + dir_model_->setFilter(QDir::AllDirs | QDir::Files | QDir::NoDotAndDotDot); + + ui_->fileTreeView->setModel(dir_model_); + ui_->fileTreeView->setColumnWidth(0, 320); + ui_->fileTreeView->sortByColumn(0, Qt::AscendingOrder); + m_path_ = boost::filesystem::path(dir_model_->rootPath().toStdString()); + + create_popup_menu(); + + connect(ui_->upPathButton, &QPushButton::clicked, this, + &FilePage::slot_up_level); + connect(ui_->refreshButton, &QPushButton::clicked, this, + &FilePage::SlotGoPath); + ui_->optionsButton->setMenu(option_popup_menu_); + + ui_->pathEdit->setText(dir_model_->rootPath()); + + path_edit_completer_ = new QCompleter(this); + path_complete_model_ = new QStringListModel(); + path_edit_completer_->setModel(path_complete_model_); + path_edit_completer_->setCaseSensitivity(Qt::CaseInsensitive); + path_edit_completer_->setCompletionMode( + QCompleter::UnfilteredPopupCompletion); + ui_->pathEdit->setCompleter(path_edit_completer_); + + connect(ui_->fileTreeView, &QTreeView::clicked, this, + &FilePage::slot_file_tree_view_item_clicked); + connect(ui_->fileTreeView, &QTreeView::doubleClicked, this, + &FilePage::slot_file_tree_view_item_double_clicked); + connect(ui_->fileTreeView, &QTreeView::customContextMenuRequested, this, &FilePage::onCustomContextMenu); - connect(ui->pathEdit, &QLineEdit::textChanged, [=]() { - auto path = ui->pathEdit->text(); + connect(ui_->pathEdit, &QLineEdit::textChanged, [=]() { + auto path = ui_->pathEdit->text(); auto dir = QDir(path); if (path.endsWith("/") && dir.isReadable()) { auto dir_list = dir.entryInfoList(QDir::AllEntries); @@ -88,215 +89,218 @@ FilePage::FilePage(QWidget* parent) if (file_name == "." || file_name == "..") continue; paths.append(file_path); } - pathCompleteModel->setStringList(paths); + path_complete_model_->setStringList(paths); } }); - connect(this, &FilePage::signalRefreshInfoBoard, SignalStation::GetInstance(), + connect(this, &FilePage::SignalRefreshInfoBoard, SignalStation::GetInstance(), &SignalStation::signalRefreshInfoBoard); } -void FilePage::fileTreeViewItemClicked(const QModelIndex& index) { - selectedPath = boost::filesystem::path( - dirModel->fileInfo(index).absoluteFilePath().toStdString()); - mPath = selectedPath; - LOG(INFO) << "selected path" << selectedPath; +void FilePage::slot_file_tree_view_item_clicked(const QModelIndex& index) { + selected_path_ = boost::filesystem::path( + dir_model_->fileInfo(index).absoluteFilePath().toStdString()); + m_path_ = selected_path_; + LOG(INFO) << "selected path" << selected_path_; } -void FilePage::slotUpLevel() { - QModelIndex currentRoot = ui->fileTreeView->rootIndex(); +void FilePage::slot_up_level() { + QModelIndex currentRoot = ui_->fileTreeView->rootIndex(); auto utf8_path = - dirModel->fileInfo(currentRoot).absoluteFilePath().toStdString(); + dir_model_->fileInfo(currentRoot).absoluteFilePath().toStdString(); boost::filesystem::path path_obj(utf8_path); - mPath = path_obj; - LOG(INFO) << "get path" << mPath; - if (mPath.has_parent_path() && !mPath.parent_path().empty()) { - mPath = mPath.parent_path(); - LOG(INFO) << "parent path" << mPath; - ui->pathEdit->setText(mPath.string().c_str()); - this->slotGoPath(); + m_path_ = path_obj; + LOG(INFO) << "get path" << m_path_; + if (m_path_.has_parent_path() && !m_path_.parent_path().empty()) { + m_path_ = m_path_.parent_path(); + LOG(INFO) << "parent path" << m_path_; + ui_->pathEdit->setText(m_path_.string().c_str()); + this->SlotGoPath(); } } -void FilePage::fileTreeViewItemDoubleClicked(const QModelIndex& index) { - QFileInfo file_info(dirModel->fileInfo(index).absoluteFilePath()); +void FilePage::slot_file_tree_view_item_double_clicked( + const QModelIndex& index) { + QFileInfo file_info(dir_model_->fileInfo(index).absoluteFilePath()); if (file_info.isFile()) { - slotOpenItem(); + slot_open_item(); } else { - ui->pathEdit->setText(file_info.filePath()); - slotGoPath(); + ui_->pathEdit->setText(file_info.filePath()); + SlotGoPath(); } } -QString FilePage::getSelected() const { - return QString::fromStdString(selectedPath.string()); +QString FilePage::GetSelected() const { + return QString::fromStdString(selected_path_.string()); } -void FilePage::slotGoPath() { - const auto path_edit = ui->pathEdit->text().toStdString(); +void FilePage::SlotGoPath() { + const auto path_edit = ui_->pathEdit->text().toStdString(); boost::filesystem::path path_obj(path_edit); - if (mPath.string() != path_edit) mPath = path_obj; - auto fileInfo = QFileInfo(mPath.string().c_str()); + if (m_path_.string() != path_edit) m_path_ = path_obj; + auto fileInfo = QFileInfo(m_path_.string().c_str()); if (fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) { - mPath = boost::filesystem::path(fileInfo.filePath().toStdString()); - LOG(INFO) << "set path" << mPath; - ui->fileTreeView->setRootIndex(dirModel->index(fileInfo.filePath())); - dirModel->setRootPath(fileInfo.filePath()); - for (int i = 1; i < dirModel->columnCount(); ++i) { - ui->fileTreeView->resizeColumnToContents(i); + m_path_ = boost::filesystem::path(fileInfo.filePath().toStdString()); + LOG(INFO) << "set path" << m_path_; + ui_->fileTreeView->setRootIndex(dir_model_->index(fileInfo.filePath())); + dir_model_->setRootPath(fileInfo.filePath()); + for (int i = 1; i < dir_model_->columnCount(); ++i) { + ui_->fileTreeView->resizeColumnToContents(i); } - ui->pathEdit->setText(mPath.generic_path().string().c_str()); + ui_->pathEdit->setText(m_path_.generic_path().string().c_str()); } else { QMessageBox::critical( this, _("Error"), _("The path is not exists, unprivileged or unreachable.")); } - emit pathChanged(mPath.string().c_str()); + emit SignalPathChanged(m_path_.string().c_str()); } -void FilePage::createPopupMenu() { - popUpMenu = new QMenu(); - - ui->actionOpenFile->setText(_("Open")); - connect(ui->actionOpenFile, &QAction::triggered, this, - &FilePage::slotOpenItem); - ui->actionRenameFile->setText(_("Rename")); - connect(ui->actionRenameFile, &QAction::triggered, this, - &FilePage::slotRenameItem); - ui->actionDeleteFile->setText(_("Delete")); - connect(ui->actionDeleteFile, &QAction::triggered, this, - &FilePage::slotDeleteItem); - - ui->actionEncrypt->setText(_("Encrypt")); - connect(ui->actionEncrypt, &QAction::triggered, this, - &FilePage::slotEncryptItem); - ui->actionEncryptSign->setText(_("Encrypt Sign")); - connect(ui->actionEncryptSign, &QAction::triggered, this, - &FilePage::slotEncryptSignItem); - ui->actionDecrypt->setText(QString(_("Decrypt Verify")) + " " + - _("(.gpg .asc)")); - connect(ui->actionDecrypt, &QAction::triggered, this, - &FilePage::slotDecryptItem); - ui->actionSign->setText(_("Sign")); - connect(ui->actionSign, &QAction::triggered, this, &FilePage::slotSignItem); - ui->actionVerify->setText(QString(_("Verify")) + " " + _("(.sig .gpg .asc)")); - connect(ui->actionVerify, &QAction::triggered, this, - &FilePage::slotVerifyItem); - - ui->actionCalculateHash->setText(_("Calculate Hash")); - connect(ui->actionCalculateHash, &QAction::triggered, this, - &FilePage::slotCalculateHash); - - ui->actionMakeDirectory->setText(_("Make New Directory")); - connect(ui->actionMakeDirectory, &QAction::triggered, this, - &FilePage::slotMkdir); - - ui->actionCreateEmptyFile->setText(_("Create Empty File")); - connect(ui->actionCreateEmptyFile, &QAction::triggered, this, - &FilePage::slotCreateEmptyFile); - - popUpMenu->addAction(ui->actionOpenFile); - popUpMenu->addAction(ui->actionRenameFile); - popUpMenu->addAction(ui->actionDeleteFile); - popUpMenu->addSeparator(); - popUpMenu->addAction(ui->actionEncrypt); - popUpMenu->addAction(ui->actionEncryptSign); - popUpMenu->addAction(ui->actionDecrypt); - popUpMenu->addAction(ui->actionSign); - popUpMenu->addAction(ui->actionVerify); - popUpMenu->addSeparator(); - popUpMenu->addAction(ui->actionMakeDirectory); - popUpMenu->addAction(ui->actionCreateEmptyFile); - popUpMenu->addAction(ui->actionCalculateHash); - - optionPopUpMenu = new QMenu(); +void FilePage::create_popup_menu() { + popup_menu_ = new QMenu(); + + ui_->actionOpenFile->setText(_("Open")); + connect(ui_->actionOpenFile, &QAction::triggered, this, + &FilePage::slot_open_item); + ui_->actionRenameFile->setText(_("Rename")); + connect(ui_->actionRenameFile, &QAction::triggered, this, + &FilePage::slot_rename_item); + ui_->actionDeleteFile->setText(_("Delete")); + connect(ui_->actionDeleteFile, &QAction::triggered, this, + &FilePage::slot_delete_item); + + ui_->actionEncrypt->setText(_("Encrypt")); + connect(ui_->actionEncrypt, &QAction::triggered, this, + &FilePage::slot_encrypt_item); + ui_->actionEncryptSign->setText(_("Encrypt Sign")); + connect(ui_->actionEncryptSign, &QAction::triggered, this, + &FilePage::slot_encrypt_sign_item); + ui_->actionDecrypt->setText(QString(_("Decrypt Verify")) + " " + + _("(.gpg .asc)")); + connect(ui_->actionDecrypt, &QAction::triggered, this, + &FilePage::slot_decrypt_item); + ui_->actionSign->setText(_("Sign")); + connect(ui_->actionSign, &QAction::triggered, this, + &FilePage::slot_sign_item); + ui_->actionVerify->setText(QString(_("Verify")) + " " + + _("(.sig .gpg .asc)")); + connect(ui_->actionVerify, &QAction::triggered, this, + &FilePage::slot_verify_item); + + ui_->actionCalculateHash->setText(_("Calculate Hash")); + connect(ui_->actionCalculateHash, &QAction::triggered, this, + &FilePage::slot_calculate_hash); + + ui_->actionMakeDirectory->setText(_("Make New Directory")); + connect(ui_->actionMakeDirectory, &QAction::triggered, this, + &FilePage::slot_mkdir); + + ui_->actionCreateEmptyFile->setText(_("Create Empty File")); + connect(ui_->actionCreateEmptyFile, &QAction::triggered, this, + &FilePage::slot_create_empty_file); + + popup_menu_->addAction(ui_->actionOpenFile); + popup_menu_->addAction(ui_->actionRenameFile); + popup_menu_->addAction(ui_->actionDeleteFile); + popup_menu_->addSeparator(); + popup_menu_->addAction(ui_->actionEncrypt); + popup_menu_->addAction(ui_->actionEncryptSign); + popup_menu_->addAction(ui_->actionDecrypt); + popup_menu_->addAction(ui_->actionSign); + popup_menu_->addAction(ui_->actionVerify); + popup_menu_->addSeparator(); + popup_menu_->addAction(ui_->actionMakeDirectory); + popup_menu_->addAction(ui_->actionCreateEmptyFile); + popup_menu_->addAction(ui_->actionCalculateHash); + + option_popup_menu_ = new QMenu(); auto showHiddenAct = new QAction(_("Show Hidden File"), this); showHiddenAct->setCheckable(true); connect(showHiddenAct, &QAction::triggered, this, [&](bool checked) { LOG(INFO) << "Set Hidden" << checked; if (checked) - dirModel->setFilter(dirModel->filter() | QDir::Hidden); + dir_model_->setFilter(dir_model_->filter() | QDir::Hidden); else - dirModel->setFilter(dirModel->filter() & ~QDir::Hidden); - dirModel->setRootPath(mPath.string().c_str()); + dir_model_->setFilter(dir_model_->filter() & ~QDir::Hidden); + dir_model_->setRootPath(m_path_.string().c_str()); }); - optionPopUpMenu->addAction(showHiddenAct); + option_popup_menu_->addAction(showHiddenAct); auto showSystemAct = new QAction(_("Show System File"), this); showSystemAct->setCheckable(true); connect(showSystemAct, &QAction::triggered, this, [&](bool checked) { LOG(INFO) << "Set Hidden" << checked; if (checked) - dirModel->setFilter(dirModel->filter() | QDir::System); + dir_model_->setFilter(dir_model_->filter() | QDir::System); else - dirModel->setFilter(dirModel->filter() & ~QDir::System); - dirModel->setRootPath(mPath.string().c_str()); + dir_model_->setFilter(dir_model_->filter() & ~QDir::System); + dir_model_->setRootPath(m_path_.string().c_str()); }); - optionPopUpMenu->addAction(showSystemAct); + option_popup_menu_->addAction(showSystemAct); } void FilePage::onCustomContextMenu(const QPoint& point) { - QModelIndex index = ui->fileTreeView->indexAt(point); - selectedPath = boost::filesystem::path( - dirModel->fileInfo(index).absoluteFilePath().toStdString()); - LOG(INFO) << "right click" << selectedPath; + QModelIndex index = ui_->fileTreeView->indexAt(point); + selected_path_ = boost::filesystem::path( + dir_model_->fileInfo(index).absoluteFilePath().toStdString()); + LOG(INFO) << "right click" << selected_path_; if (index.isValid()) { - ui->actionOpenFile->setEnabled(true); - ui->actionRenameFile->setEnabled(true); - ui->actionDeleteFile->setEnabled(true); - - QFileInfo info(QString::fromStdString(selectedPath.string())); - ui->actionEncrypt->setEnabled(info.isFile() && (info.suffix() != "gpg" && - info.suffix() != "sig" && - info.suffix() != "asc")); - ui->actionEncryptSign->setEnabled( + ui_->actionOpenFile->setEnabled(true); + ui_->actionRenameFile->setEnabled(true); + ui_->actionDeleteFile->setEnabled(true); + + QFileInfo info(QString::fromStdString(selected_path_.string())); + ui_->actionEncrypt->setEnabled(info.isFile() && (info.suffix() != "gpg" && + info.suffix() != "sig" && + info.suffix() != "asc")); + ui_->actionEncryptSign->setEnabled( info.isFile() && (info.suffix() != "gpg" && info.suffix() != "sig" && info.suffix() != "asc")); - ui->actionDecrypt->setEnabled( + ui_->actionDecrypt->setEnabled( info.isFile() && (info.suffix() == "gpg" || info.suffix() == "asc")); - ui->actionSign->setEnabled(info.isFile() && (info.suffix() != "gpg" && - info.suffix() != "sig" && - info.suffix() != "asc")); - ui->actionVerify->setEnabled(info.isFile() && (info.suffix() == "sig" || - info.suffix() == "gpg" || - info.suffix() == "asc")); - ui->actionCalculateHash->setEnabled(info.isFile() && info.isReadable()); + ui_->actionSign->setEnabled(info.isFile() && (info.suffix() != "gpg" && + info.suffix() != "sig" && + info.suffix() != "asc")); + ui_->actionVerify->setEnabled(info.isFile() && (info.suffix() == "sig" || + info.suffix() == "gpg" || + info.suffix() == "asc")); + ui_->actionCalculateHash->setEnabled(info.isFile() && info.isReadable()); } else { - ui->actionOpenFile->setEnabled(false); - ui->actionRenameFile->setEnabled(false); - ui->actionDeleteFile->setEnabled(false); - - ui->actionEncrypt->setEnabled(false); - ui->actionEncryptSign->setEnabled(false); - ui->actionDecrypt->setEnabled(false); - ui->actionSign->setEnabled(false); - ui->actionVerify->setEnabled(false); - ui->actionCalculateHash->setEnabled(false); + ui_->actionOpenFile->setEnabled(false); + ui_->actionRenameFile->setEnabled(false); + ui_->actionDeleteFile->setEnabled(false); + + ui_->actionEncrypt->setEnabled(false); + ui_->actionEncryptSign->setEnabled(false); + ui_->actionDecrypt->setEnabled(false); + ui_->actionSign->setEnabled(false); + ui_->actionVerify->setEnabled(false); + ui_->actionCalculateHash->setEnabled(false); } - popUpMenu->exec(ui->fileTreeView->viewport()->mapToGlobal(point)); + popup_menu_->exec(ui_->fileTreeView->viewport()->mapToGlobal(point)); } -void FilePage::slotOpenItem() { - QFileInfo info(QString::fromStdString(selectedPath.string())); +void FilePage::slot_open_item() { + QFileInfo info(QString::fromStdString(selected_path_.string())); if (info.isDir()) { if (info.isReadable() && info.isExecutable()) { const auto file_path = info.filePath().toStdString(); LOG(INFO) << "set path" << file_path; - ui->pathEdit->setText(info.filePath()); - slotGoPath(); + ui_->pathEdit->setText(info.filePath()); + SlotGoPath(); } else { QMessageBox::critical(this, _("Error"), _("The directory is unprivileged or unreachable.")); } } else { if (info.isReadable()) { - auto mainWindow = qobject_cast<MainWindow*>(firstParent); - LOG(INFO) << "open item" << selectedPath; - auto qt_path = QString::fromStdString(selectedPath.string()); + auto mainWindow = qobject_cast<MainWindow*>(first_parent_); + LOG(INFO) << "open item" << selected_path_; + auto qt_path = QString::fromStdString(selected_path_.string()); if (mainWindow != nullptr) mainWindow->SlotOpenFile(qt_path); } else { QMessageBox::critical(this, _("Error"), @@ -305,8 +309,8 @@ void FilePage::slotOpenItem() { } } -void FilePage::slotRenameItem() { - auto new_name_path = selectedPath, old_name_path = selectedPath; +void FilePage::slot_rename_item() { + auto new_name_path = selected_path_, old_name_path = selected_path_; auto old_name = old_name_path.filename(); new_name_path = new_name_path.remove_filename(); @@ -320,7 +324,7 @@ void FilePage::slotRenameItem() { LOG(INFO) << "new name path" << new_name_path; boost::filesystem::rename(old_name_path, new_name_path); // refresh - this->slotGoPath(); + this->SlotGoPath(); } catch (...) { LOG(ERROR) << "rename error" << new_name_path; QMessageBox::critical(this, _("Error"), @@ -329,9 +333,9 @@ void FilePage::slotRenameItem() { } } -void FilePage::slotDeleteItem() { - QModelIndex index = ui->fileTreeView->currentIndex(); - QVariant data = ui->fileTreeView->model()->data(index); +void FilePage::slot_delete_item() { + QModelIndex index = ui_->fileTreeView->currentIndex(); + QVariant data = ui_->fileTreeView->model()->data(index); auto ret = QMessageBox::warning(this, _("Warning"), _("Are you sure you want to delete it?"), @@ -341,47 +345,47 @@ void FilePage::slotDeleteItem() { LOG(INFO) << "Delete Item" << data.toString().toStdString(); - if (!dirModel->remove(index)) { + if (!dir_model_->remove(index)) { QMessageBox::critical(this, _("Error"), _("Unable to delete the file or folder.")); } } -void FilePage::slotEncryptItem() { - auto mainWindow = qobject_cast<MainWindow*>(firstParent); +void FilePage::slot_encrypt_item() { + auto mainWindow = qobject_cast<MainWindow*>(first_parent_); if (mainWindow != nullptr) mainWindow->SlotFileEncrypt(); } -void FilePage::slotEncryptSignItem() { - auto mainWindow = qobject_cast<MainWindow*>(firstParent); +void FilePage::slot_encrypt_sign_item() { + auto mainWindow = qobject_cast<MainWindow*>(first_parent_); if (mainWindow != nullptr) mainWindow->SlotFileEncryptSign(); } -void FilePage::slotDecryptItem() { - auto mainWindow = qobject_cast<MainWindow*>(firstParent); +void FilePage::slot_decrypt_item() { + auto mainWindow = qobject_cast<MainWindow*>(first_parent_); if (mainWindow != nullptr) mainWindow->SlotFileDecryptVerify(); } -void FilePage::slotSignItem() { - auto mainWindow = qobject_cast<MainWindow*>(firstParent); +void FilePage::slot_sign_item() { + auto mainWindow = qobject_cast<MainWindow*>(first_parent_); if (mainWindow != nullptr) mainWindow->SlotFileSign(); } -void FilePage::slotVerifyItem() { - auto mainWindow = qobject_cast<MainWindow*>(firstParent); +void FilePage::slot_verify_item() { + auto mainWindow = qobject_cast<MainWindow*>(first_parent_); if (mainWindow != nullptr) mainWindow->SlotFileVerify(); } -void FilePage::slotCalculateHash() { +void FilePage::slot_calculate_hash() { // Returns empty QByteArray() on failure. - QFileInfo info(QString::fromStdString(selectedPath.string())); + QFileInfo info(QString::fromStdString(selected_path_.string())); if (info.isFile() && info.isReadable()) { std::stringstream ss; ss << "[#] " << _("File Hash Information") << std::endl; ss << " " << _("filename") << _(": ") - << selectedPath.filename().string().c_str() << std::endl; + << selected_path_.filename().string().c_str() << std::endl; QFile f(info.filePath()); f.open(QFile::ReadOnly); @@ -415,14 +419,14 @@ void FilePage::slotCalculateHash() { ss << std::endl; - emit signalRefreshInfoBoard(ss.str().c_str(), + emit SignalRefreshInfoBoard(ss.str().c_str(), InfoBoardStatus::INFO_ERROR_OK); } } } -void FilePage::slotMkdir() { - auto index = ui->fileTreeView->rootIndex(); +void FilePage::slot_mkdir() { + auto index = ui_->fileTreeView->rootIndex(); QString new_dir_name; bool ok; @@ -430,12 +434,12 @@ void FilePage::slotMkdir() { QInputDialog::getText(this, _("Make New Directory"), _("Directory Name"), QLineEdit::Normal, new_dir_name, &ok); if (ok && !new_dir_name.isEmpty()) { - dirModel->mkdir(index, new_dir_name); + dir_model_->mkdir(index, new_dir_name); } } -void FilePage::slotCreateEmptyFile() { - auto root_path_str = dirModel->rootPath().toStdString(); +void FilePage::slot_create_empty_file() { + auto root_path_str = dir_model_->rootPath().toStdString(); boost::filesystem::path root_path(root_path_str); QString new_file_name; @@ -455,15 +459,15 @@ void FilePage::slotCreateEmptyFile() { void FilePage::keyPressEvent(QKeyEvent* event) { LOG(INFO) << "Key Press" << event->key(); - if (ui->pathEdit->hasFocus() && + if (ui_->pathEdit->hasFocus() && (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter)) { - slotGoPath(); - } else if (ui->fileTreeView->currentIndex().isValid()) { + SlotGoPath(); + } else if (ui_->fileTreeView->currentIndex().isValid()) { if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) - slotOpenItem(); + slot_open_item(); else if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace) - slotDeleteItem(); + slot_delete_item(); } } diff --git a/src/ui/widgets/FilePage.h b/src/ui/widgets/FilePage.h index b83e0f9e..7c1880ee 100644 --- a/src/ui/widgets/FilePage.h +++ b/src/ui/widgets/FilePage.h @@ -38,62 +38,174 @@ class Ui_FilePage; namespace GpgFrontend::UI { +/** + * @brief + * + */ class FilePage : public QWidget { Q_OBJECT public: + /** + * @brief Construct a new File Page object + * + * @param parent + */ explicit FilePage(QWidget* parent = nullptr); - [[nodiscard]] QString getSelected() const; + /** + * @brief Get the Selected object + * + * @return QString + */ + [[nodiscard]] QString GetSelected() const; public slots: - void slotGoPath(); + /** + * @brief + * + */ + void SlotGoPath(); signals: - void pathChanged(const QString& path); - void signalRefreshInfoBoard(const QString& text, + /** + * @brief + * + * @param path + */ + void SignalPathChanged(const QString& path); + + /** + * @brief + * + * @param text + * @param verify_label_status + */ + void SignalRefreshInfoBoard(const QString& text, InfoBoardStatus verify_label_status); private slots: - void fileTreeViewItemClicked(const QModelIndex& index); - void fileTreeViewItemDoubleClicked(const QModelIndex& index); - - void slotUpLevel(); - - void slotOpenItem(); - void slotRenameItem(); - void slotDeleteItem(); - void slotEncryptItem(); - void slotEncryptSignItem(); - void slotDecryptItem(); - void slotSignItem(); - void slotVerifyItem(); - void slotCalculateHash(); - void slotMkdir(); - void slotCreateEmptyFile(); - - void onCustomContextMenu(const QPoint& point); + /** + * @brief + * + * @param index + */ + void slot_file_tree_view_item_clicked(const QModelIndex& index); + + /** + * @brief + * + * @param index + */ + void slot_file_tree_view_item_double_clicked(const QModelIndex& index); + + /** + * @brief + * + */ + void slot_up_level(); + + /** + * @brief + * + */ + void slot_open_item(); + + /** + * @brief + * + */ + void slot_rename_item(); + + /** + * @brief + * + */ + void slot_delete_item(); + + /** + * @brief + * + */ + void slot_encrypt_item(); + + /** + * @brief + * + */ + void slot_encrypt_sign_item(); + + /** + * @brief + * + */ + void slot_decrypt_item(); + + /** + * @brief + * + */ + void slot_sign_item(); + + /** + * @brief + * + */ + void slot_verify_item(); + + /** + * @brief + * + */ + void slot_calculate_hash(); + + /** + * @brief + * + */ + void slot_mkdir(); + + /** + * @brief + * + */ + void slot_create_empty_file(); protected: + /** + * @brief + * + * @param event + */ void keyPressEvent(QKeyEvent* event) override; + /** + * @brief + * + * @param point + */ + void onCustomContextMenu(const QPoint& point); + private: - void createPopupMenu(); + /** + * @brief Create a popup menu object + * + */ + void create_popup_menu(); - std::shared_ptr<Ui_FilePage> ui; + std::shared_ptr<Ui_FilePage> ui_; ///< - QFileSystemModel* dirModel; - QCompleter* pathEditCompleter; - QStringListModel* pathCompleteModel; + QFileSystemModel* dir_model_; ///< + QCompleter* path_edit_completer_; ///< + QStringListModel* path_complete_model_; ///< - // using boost path - boost::filesystem::path mPath; - boost::filesystem::path selectedPath; + boost::filesystem::path m_path_; ///< + boost::filesystem::path selected_path_; ///< - QMenu* popUpMenu{}; - QMenu* optionPopUpMenu{}; - QWidget* firstParent; + QMenu* popup_menu_{}; ///< + QMenu* option_popup_menu_{}; ///< + QWidget* first_parent_{}; ///< }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/GroupKeyList.cpp b/src/ui/widgets/GroupKeyList.cpp deleted file mode 100644 index d4bbf08e..00000000 --- a/src/ui/widgets/GroupKeyList.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * This file is part of GpgFrontend. - * - * GpgFrontend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GpgFrontend is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from - * the gpg4usb project, which is under GPL-3.0-or-later. - * - * All the source code of GpgFrontend was modified and released by - * Saturneric<[email protected]> starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#include "GroupKeyList.h" diff --git a/src/ui/widgets/GroupKeyList.h b/src/ui/widgets/GroupKeyList.h deleted file mode 100644 index 537f156f..00000000 --- a/src/ui/widgets/GroupKeyList.h +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright (C) 2021 Saturneric - * - * This file is part of GpgFrontend. - * - * GpgFrontend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * GpgFrontend is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GpgFrontend. If not, see <https://www.gnu.org/licenses/>. - * - * The initial version of the source code is inherited from - * the gpg4usb project, which is under GPL-3.0-or-later. - * - * All the source code of GpgFrontend was modified and released by - * Saturneric<[email protected]> starting on May 12, 2021. - * - * SPDX-License-Identifier: GPL-3.0-or-later - * - */ - -#ifndef GPGFRONTEND_GROUPKEYLIST_H -#define GPGFRONTEND_GROUPKEYLIST_H - -#include "ui/GpgFrontendUI.h" - -class GroupKeyList : public QWidget { - Q_OBJECT -}; - -#endif // GPGFRONTEND_GROUPKEYLIST_H diff --git a/src/ui/widgets/HelpPage.cpp b/src/ui/widgets/HelpPage.cpp index 0bb54890..04bf609c 100644 --- a/src/ui/widgets/HelpPage.cpp +++ b/src/ui/widgets/HelpPage.cpp @@ -33,32 +33,33 @@ namespace GpgFrontend::UI { HelpPage::HelpPage(const QString& path, QWidget* parent) : QWidget(parent) { - browser = new QTextBrowser(); + browser_ = new QTextBrowser(); auto* mainLayout = new QVBoxLayout(); mainLayout->setSpacing(0); - mainLayout->addWidget(browser); + mainLayout->addWidget(browser_); mainLayout->setContentsMargins(0, 0, 0, 0); setLayout(mainLayout); - connect(browser, SIGNAL(anchorClicked(QUrl)), this, SLOT(slotOpenUrl(QUrl))); - browser->setOpenLinks(false); - browser->setSource(localizedHelp(QUrl(path))); - browser->setFocus(); + connect(browser_, SIGNAL(anchorClicked(QUrl)), this, + SLOT(slot_open_url(QUrl))); + browser_->setOpenLinks(false); + browser_->setSource(localized_help(QUrl(path))); + browser_->setFocus(); } -void HelpPage::slotOpenUrl(const QUrl& url) { - browser->setSource(localizedHelp(url)); +void HelpPage::slot_open_url(const QUrl& url) { + browser_->setSource(localized_help(url)); }; /** - * @brief HelpPage::localizedHelp + * @brief HelpPage::localized_help * check if the requested file is also available with the locale, * e.g. return index.de.html if index.html was requested but the * locale is de and index.de.html is available * @param url * @return */ -QUrl HelpPage::localizedHelp(const QUrl& url) { +QUrl HelpPage::localized_help(const QUrl& url) { QString path = url.toLocalFile(); QString filename = path.mid(path.lastIndexOf("/") + 1); QString filepath = path.left(path.lastIndexOf("/") + 1); @@ -81,6 +82,6 @@ QUrl HelpPage::localizedHelp(const QUrl& url) { } } -QTextBrowser* HelpPage::getBrowser() { return browser; } +QTextBrowser* HelpPage::GetBrowser() { return browser_; } } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/HelpPage.h b/src/ui/widgets/HelpPage.h index 1406f779..0b0db5ea 100644 --- a/src/ui/widgets/HelpPage.h +++ b/src/ui/widgets/HelpPage.h @@ -33,22 +33,40 @@ namespace GpgFrontend::UI { +/** + * @brief + * + */ class HelpPage : public QWidget { Q_OBJECT public: + /** + * @brief Construct a new Help Page object + * + * @param path + * @param parent + */ explicit HelpPage(const QString& path, QWidget* parent = nullptr); - QTextBrowser* getBrowser(); - - signals: + /** + * @brief Get the Browser object + * + * @return QTextBrowser* + */ + QTextBrowser* GetBrowser(); public slots: - void slotOpenUrl(const QUrl& url); + /** + * @brief + * + * @param url + */ + void slot_open_url(const QUrl& url); private: - QTextBrowser* browser; /** The textbrowser of the tab */ - QUrl localizedHelp(const QUrl& path); + QTextBrowser* browser_; ///< The textbrowser of the tab + QUrl localized_help(const QUrl& path); }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp index 3819674c..3911acc1 100644 --- a/src/ui/widgets/InfoBoardWidget.cpp +++ b/src/ui/widgets/InfoBoardWidget.cpp @@ -35,30 +35,30 @@ namespace GpgFrontend::UI { InfoBoardWidget::InfoBoardWidget(QWidget* parent) - : QWidget(parent), ui(std::make_shared<Ui_InfoBoard>()) { - ui->setupUi(this); + : QWidget(parent), ui_(std::make_shared<Ui_InfoBoard>()) { + ui_->setupUi(this); - ui->actionButtonLayout->addStretch(); - ui->copyButton->setText(_("Copy")); - ui->saveButton->setText(_("Save File")); - ui->clearButton->setText(_("Clear")); + ui_->actionButtonLayout->addStretch(); + ui_->copyButton->setText(_("Copy")); + ui_->saveButton->setText(_("Save File")); + ui_->clearButton->setText(_("Clear")); - connect(ui->copyButton, &QPushButton::clicked, this, - &InfoBoardWidget::slotCopy); - connect(ui->saveButton, &QPushButton::clicked, this, - &InfoBoardWidget::slotSave); - connect(ui->clearButton, &QPushButton::clicked, this, - &InfoBoardWidget::slotReset); + connect(ui_->copyButton, &QPushButton::clicked, this, + &InfoBoardWidget::slot_copy); + connect(ui_->saveButton, &QPushButton::clicked, this, + &InfoBoardWidget::slot_save); + connect(ui_->clearButton, &QPushButton::clicked, this, + &InfoBoardWidget::SlotReset); connect(SignalStation::GetInstance(), &SignalStation::signalRefreshInfoBoard, - this, &InfoBoardWidget::slotRefresh); + this, &InfoBoardWidget::SlotRefresh); } -void InfoBoardWidget::setInfoBoard(const QString& text, - InfoBoardStatus verifyLabelStatus) { +void InfoBoardWidget::SetInfoBoard(const QString& text, + InfoBoardStatus verify_label_status) { QString color; - ui->infoBoard->clear(); - switch (verifyLabelStatus) { + ui_->infoBoard->clear(); + switch (verify_label_status) { case INFO_ERROR_OK: color = "#008000"; break; @@ -71,12 +71,12 @@ void InfoBoardWidget::setInfoBoard(const QString& text, default: break; } - ui->infoBoard->append(text); + ui_->infoBoard->append(text); - ui->infoBoard->setAutoFillBackground(true); - QPalette status = ui->infoBoard->palette(); + ui_->infoBoard->setAutoFillBackground(true); + QPalette status = ui_->infoBoard->palette(); status.setColor(QPalette::Text, color); - ui->infoBoard->setPalette(status); + ui_->infoBoard->setPalette(status); auto& settings = GlobalSettingStation::GetInstance().GetUISettings(); @@ -88,81 +88,82 @@ void InfoBoardWidget::setInfoBoard(const QString& text, } catch (...) { LOG(ERROR) << _("Setting Operation Error") << _("info_font_size"); } - ui->infoBoard->setFont(QFont("Times", info_font_size)); + ui_->infoBoard->setFont(QFont("Times", info_font_size)); } -void InfoBoardWidget::slotRefresh(const QString& text, InfoBoardStatus status) { - ui->infoBoard->clear(); - setInfoBoard(text, status); - ui->infoBoard->verticalScrollBar()->setValue(0); +void InfoBoardWidget::SlotRefresh(const QString& text, InfoBoardStatus status) { + ui_->infoBoard->clear(); + SetInfoBoard(text, status); + ui_->infoBoard->verticalScrollBar()->setValue(0); } -void InfoBoardWidget::associateTextEdit(QTextEdit* edit) { - if (mTextPage != nullptr) - disconnect(mTextPage, SIGNAL(textChanged()), this, SLOT(slotReset())); - this->mTextPage = edit; - connect(edit, SIGNAL(textChanged()), this, SLOT(slotReset())); +void InfoBoardWidget::AssociateTextEdit(QTextEdit* edit) { + if (m_text_page_ != nullptr) + disconnect(m_text_page_, SIGNAL(textChanged()), this, SLOT(SlotReset())); + this->m_text_page_ = edit; + connect(edit, SIGNAL(textChanged()), this, SLOT(SlotReset())); } -void InfoBoardWidget::associateTabWidget(QTabWidget* tab) { - mTextPage = nullptr; - mTabWidget = tab; - connect(tab, SIGNAL(tabBarClicked(int)), this, SLOT(slotReset())); - connect(tab, SIGNAL(tabCloseRequested(int)), this, SLOT(slotReset())); +void InfoBoardWidget::AssociateTabWidget(QTabWidget* tab) { + m_text_page_ = nullptr; + m_tab_widget_ = tab; + connect(tab, SIGNAL(tabBarClicked(int)), this, SLOT(SlotReset())); + connect(tab, SIGNAL(tabCloseRequested(int)), this, SLOT(SlotReset())); // reset - this->slotReset(); + this->SlotReset(); } -void InfoBoardWidget::addOptionalAction(const QString& name, +void InfoBoardWidget::AddOptionalAction(const QString& name, const std::function<void()>& action) { LOG(INFO) << "add option" << name.toStdString(); auto actionButton = new QPushButton(name); auto layout = new QHBoxLayout(); layout->setContentsMargins(5, 0, 5, 0); - ui->infoBoard->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + ui_->infoBoard->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); // set margin from surroundings layout->addWidget(actionButton); - ui->actionButtonLayout->addLayout(layout); + ui_->actionButtonLayout->addLayout(layout); connect(actionButton, &QPushButton::clicked, this, [=]() { action(); }); } /** * Delete All item in actionButtonLayout */ -void InfoBoardWidget::resetOptionActionsMenu() { +void InfoBoardWidget::ResetOptionActionsMenu() { // skip stretch - deleteWidgetsInLayout(ui->actionButtonLayout, 1); + delete_widgets_in_layout(ui_->actionButtonLayout, 1); } -void InfoBoardWidget::slotReset() { - ui->infoBoard->clear(); - resetOptionActionsMenu(); +void InfoBoardWidget::SlotReset() { + ui_->infoBoard->clear(); + ResetOptionActionsMenu(); } /** * Try Delete all widget from target layout * @param layout target layout */ -void InfoBoardWidget::deleteWidgetsInLayout(QLayout* layout, int start_index) { +void InfoBoardWidget::delete_widgets_in_layout(QLayout* layout, + int start_index) { LOG(INFO) << "Called"; QLayoutItem* item; while ((item = layout->layout()->takeAt(start_index)) != nullptr) { layout->removeItem(item); if (item->layout() != nullptr) - deleteWidgetsInLayout(item->layout()); + delete_widgets_in_layout(item->layout()); else if (item->widget() != nullptr) delete item->widget(); delete item; } } -void InfoBoardWidget::slotCopy() { +void InfoBoardWidget::slot_copy() { auto* clipboard = QGuiApplication::clipboard(); - clipboard->setText(ui->infoBoard->toPlainText()); + clipboard->setText(ui_->infoBoard->toPlainText()); } -void InfoBoardWidget::slotSave() { +void InfoBoardWidget::slot_save() { auto file_path = QFileDialog::getSaveFileName( this, _("Save Information Board's Content"), {}, tr("Text (*.txt)")); LOG(INFO) << "file path" << file_path.toStdString(); @@ -170,7 +171,7 @@ void InfoBoardWidget::slotSave() { QFile file(file_path); if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)) { - file.write(ui->infoBoard->toPlainText().toUtf8()); + file.write(ui_->infoBoard->toPlainText().toUtf8()); } else { QMessageBox::critical( this, _("Error"), diff --git a/src/ui/widgets/InfoBoardWidget.h b/src/ui/widgets/InfoBoardWidget.h index cde3b00a..3d68215a 100644 --- a/src/ui/widgets/InfoBoardWidget.h +++ b/src/ui/widgets/InfoBoardWidget.h @@ -38,7 +38,7 @@ class Ui_InfoBoard; namespace GpgFrontend::UI { /** - * @details Enumeration for the status of Verifylabel + * @details Enumeration for the status of Verify label */ typedef enum { INFO_ERROR_OK = 0, @@ -48,7 +48,7 @@ typedef enum { } InfoBoardStatus; /** - * @brief Class for handling the verifylabel shown at buttom of a textedit-page + * @brief Class for handling the verify label shown at bottom of a textedit-page */ class InfoBoardWidget : public QWidget { Q_OBJECT @@ -61,45 +61,86 @@ class InfoBoardWidget : public QWidget { */ explicit InfoBoardWidget(QWidget* parent); - void associateTextEdit(QTextEdit* edit); + /** + * @brief + * + * @param edit + */ + void AssociateTextEdit(QTextEdit* edit); - void associateTabWidget(QTabWidget* tab); + /** + * @brief + * + * @param tab + */ + void AssociateTabWidget(QTabWidget* tab); - void addOptionalAction(const QString& name, + /** + * @brief + * + * @param name + * @param action + */ + void AddOptionalAction(const QString& name, const std::function<void()>& action); - void resetOptionActionsMenu(); + /** + * @brief + * + */ + void ResetOptionActionsMenu(); /** * @details Set the text and background-color of verify notification. * * @param text The text to be set. - * @param verifyLabelStatus The status of label to set the specified color. + * @param verify_label_status The status of label to set the specified color. */ - void setInfoBoard(const QString& text, InfoBoardStatus verifyLabelStatus); + void SetInfoBoard(const QString& text, + GpgFrontend::UI::InfoBoardStatus verify_label_status); public slots: - void slotReset(); + /** + * @brief + * + */ + void SlotReset(); /** * @details Refresh the contents of dialog. */ - void slotRefresh(const QString& text, InfoBoardStatus status); + void SlotRefresh(const QString& text, + GpgFrontend::UI::InfoBoardStatus status); private slots: - void slotCopy(); + /** + * @brief + * + */ + void slot_copy(); - void slotSave(); + /** + * @brief + * + */ + void slot_save(); private: - std::shared_ptr<Ui_InfoBoard> ui; + std::shared_ptr<Ui_InfoBoard> ui_; ///< - QTextEdit* mTextPage{nullptr}; /** TextEdit associated to the notification */ - QTabWidget* mTabWidget{nullptr}; + QTextEdit* m_text_page_{ + nullptr}; ///< TextEdit associated to the notification + QTabWidget* m_tab_widget_{nullptr}; ///< - void deleteWidgetsInLayout(QLayout* layout, int start_index = 0); + /** + * @brief + * + * @param layout + * @param start_index + */ + void delete_widgets_in_layout(QLayout* layout, int start_index = 0); }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/KeyList.cpp b/src/ui/widgets/KeyList.cpp index 8c3a2e83..32a2e4ed 100644 --- a/src/ui/widgets/KeyList.cpp +++ b/src/ui/widgets/KeyList.cpp @@ -40,12 +40,12 @@ namespace GpgFrontend::UI { -int KeyList::key_list_id = 2048; +int KeyList::key_list_id_ = 2048; KeyList::KeyList(KeyMenuAbility::AbilityType menu_ability, QWidget* parent) : QWidget(parent), - _m_key_list_id(key_list_id++), - ui(std::make_shared<Ui_KeyList>()), + m_key_list_id_(key_list_id_++), + ui_(std::make_shared<Ui_KeyList>()), menu_ability_(menu_ability) { init(); } @@ -61,62 +61,64 @@ void KeyList::init() { _m_key_list_id, std::make_unique<GpgContext>(true, db_path.string(), true, gpg_path.string())); #else - new_default_settings_channel(_m_key_list_id); + new_default_settings_channel(m_key_list_id_); #endif - ui->setupUi(this); + ui_->setupUi(this); - ui->menuWidget->setHidden(!menu_ability_); - ui->refreshKeyListButton->setHidden(~menu_ability_ & KeyMenuAbility::REFRESH); - ui->syncButton->setHidden(~menu_ability_ & KeyMenuAbility::SYNC_PUBLIC_KEY); - ui->uncheckButton->setHidden(~menu_ability_ & KeyMenuAbility::UNCHECK_ALL); + ui_->menuWidget->setHidden(!menu_ability_); + ui_->refreshKeyListButton->setHidden(~menu_ability_ & + KeyMenuAbility::REFRESH); + ui_->syncButton->setHidden(~menu_ability_ & KeyMenuAbility::SYNC_PUBLIC_KEY); + ui_->uncheckButton->setHidden(~menu_ability_ & KeyMenuAbility::UNCHECK_ALL); - ui->keyGroupTab->clear(); - popupMenu = new QMenu(this); + ui_->keyGroupTab->clear(); + popup_menu_ = new QMenu(this); // register key database refresh signal - connect(this, &KeyList::signalRefreshDatabase, SignalStation::GetInstance(), + connect(this, &KeyList::SignalRefreshDatabase, SignalStation::GetInstance(), &SignalStation::KeyDatabaseRefresh); connect(SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh()), this, - SLOT(slotRefresh())); - connect(ui->refreshKeyListButton, &QPushButton::clicked, this, - &KeyList::slotRefresh); - connect(ui->uncheckButton, &QPushButton::clicked, this, - &KeyList::slotUncheckALL); - connect(ui->checkALLButton, &QPushButton::clicked, this, - &KeyList::slotCheckALL); - connect(ui->syncButton, &QPushButton::clicked, this, - &KeyList::slotSyncWithKeyServer); - connect(this, &KeyList::signalRefreshStatusBar, SignalStation::GetInstance(), + SLOT(SlotRefresh())); + connect(ui_->refreshKeyListButton, &QPushButton::clicked, this, + &KeyList::SlotRefresh); + connect(ui_->uncheckButton, &QPushButton::clicked, this, + &KeyList::uncheck_all); + connect(ui_->checkALLButton, &QPushButton::clicked, this, + &KeyList::check_all); + connect(ui_->syncButton, &QPushButton::clicked, this, + &KeyList::slot_sync_with_key_server); + connect(this, &KeyList::SignalRefreshStatusBar, SignalStation::GetInstance(), &SignalStation::signalRefreshStatusBar); setAcceptDrops(true); - ui->refreshKeyListButton->setText(_("Refresh")); - ui->refreshKeyListButton->setToolTip( + ui_->refreshKeyListButton->setText(_("Refresh")); + ui_->refreshKeyListButton->setToolTip( _("Refresh the key list to synchronize changes.")); - ui->syncButton->setText(_("Sync Public Key")); - ui->syncButton->setToolTip(_("Sync public key with your default keyserver.")); - ui->uncheckButton->setText(_("Uncheck ALL")); - ui->uncheckButton->setToolTip( + ui_->syncButton->setText(_("Sync Public Key")); + ui_->syncButton->setToolTip( + _("Sync public key with your default keyserver.")); + ui_->uncheckButton->setText(_("Uncheck ALL")); + ui_->uncheckButton->setToolTip( _("Cancel all checked items in the current tab at once.")); - ui->checkALLButton->setText(_("Check ALL")); - ui->checkALLButton->setToolTip( + ui_->checkALLButton->setText(_("Check ALL")); + ui_->checkALLButton->setToolTip( _("Check all items in the current tab at once")); } -void KeyList::addListGroupTab( +void KeyList::AddListGroupTab( const QString& name, KeyListRow::KeyType selectType, KeyListColumn::InfoType infoType, const std::function<bool(const GpgKey&)>& filter) { LOG(INFO) << _("Called") << name.toStdString(); auto key_list = new QTableWidget(this); - if (mKeyList == nullptr) { - mKeyList = key_list; + if (m_key_list_ == nullptr) { + m_key_list_ = key_list; } - ui->keyGroupTab->addTab(key_list, name); - mKeyTables.emplace_back(key_list, selectType, infoType, filter); + ui_->keyGroupTab->addTab(key_list, name); + m_key_tables_.emplace_back(key_list, selectType, infoType, filter); key_list->setColumnCount(7); key_list->horizontalHeader()->setSectionResizeMode( @@ -163,39 +165,40 @@ void KeyList::addListGroupTab( key_list->horizontalHeader()->setStretchLastSection(false); connect(key_list, &QTableWidget::doubleClicked, this, - &KeyList::slotDoubleClicked); + &KeyList::slot_double_clicked); } -void KeyList::slotRefresh() { - LOG(INFO) << _("Called") << "_m_key_list_id" << _m_key_list_id; - emit signalRefreshStatusBar(_("Refreshing Key List..."), 3000); - auto thread = QThread::create([this, _id = _m_key_list_id]() { - std::lock_guard<std::mutex> guard(buffered_key_list_mutex); - _buffered_keys_list = nullptr; +void KeyList::SlotRefresh() { + LOG(INFO) << _("Called") << "_m_key_list_id" << m_key_list_id_; + emit SignalRefreshStatusBar(_("Refreshing Key List..."), 3000); + auto thread = QThread::create([this, _id = m_key_list_id_]() { + std::lock_guard<std::mutex> guard(buffered_key_list_mutex_); + buffered_keys_list_ = nullptr; // buffered keys list - _buffered_keys_list = GpgKeyGetter::GetInstance(_id).FetchKey(); + buffered_keys_list_ = GpgKeyGetter::GetInstance(_id).FetchKey(); }); - connect(thread, &QThread::finished, this, &KeyList::slotRefreshUI); + connect(thread, &QThread::finished, this, &KeyList::slot_refresh_ui); connect(thread, &QThread::finished, thread, &QThread::deleteLater); - ui->refreshKeyListButton->setDisabled(true); - ui->syncButton->setDisabled(true); + ui_->refreshKeyListButton->setDisabled(true); + ui_->syncButton->setDisabled(true); thread->start(); } -KeyIdArgsListPtr KeyList::getChecked(const KeyTable& key_table) { +KeyIdArgsListPtr KeyList::GetChecked(const KeyTable& key_table) { auto ret = std::make_unique<KeyIdArgsList>(); - for (int i = 0; i < key_table.key_list->rowCount(); i++) { - if (key_table.key_list->item(i, 0)->checkState() == Qt::Checked) { - ret->push_back(key_table.buffered_keys[i].GetId()); + for (int i = 0; i < key_table.key_list_->rowCount(); i++) { + if (key_table.key_list_->item(i, 0)->checkState() == Qt::Checked) { + ret->push_back(key_table.buffered_keys_[i].GetId()); } } return ret; } -KeyIdArgsListPtr KeyList::getChecked() { - auto key_list = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); +KeyIdArgsListPtr KeyList::GetChecked() { + auto key_list = + qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); const auto& buffered_keys = - mKeyTables[ui->keyGroupTab->currentIndex()].buffered_keys; + m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; auto ret = std::make_unique<KeyIdArgsList>(); for (int i = 0; i < key_list->rowCount(); i++) { if (key_list->item(i, 0)->checkState() == Qt::Checked) { @@ -205,10 +208,11 @@ KeyIdArgsListPtr KeyList::getChecked() { return ret; } -KeyIdArgsListPtr KeyList::getAllPrivateKeys() { - auto key_list = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); +KeyIdArgsListPtr KeyList::GetAllPrivateKeys() { + auto key_list = + qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); const auto& buffered_keys = - mKeyTables[ui->keyGroupTab->currentIndex()].buffered_keys; + m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; auto ret = std::make_unique<KeyIdArgsList>(); for (int i = 0; i < key_list->rowCount(); i++) { if (key_list->item(i, 1) && buffered_keys[i].IsPrivateKey()) { @@ -218,13 +222,14 @@ KeyIdArgsListPtr KeyList::getAllPrivateKeys() { return ret; } -KeyIdArgsListPtr KeyList::getPrivateChecked() { +KeyIdArgsListPtr KeyList::GetPrivateChecked() { auto ret = std::make_unique<KeyIdArgsList>(); - if (ui->keyGroupTab->size().isEmpty()) return ret; + if (ui_->keyGroupTab->size().isEmpty()) return ret; - auto key_list = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); + auto key_list = + qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); const auto& buffered_keys = - mKeyTables[ui->keyGroupTab->currentIndex()].buffered_keys; + m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; for (int i = 0; i < key_list->rowCount(); i++) { if ((key_list->item(i, 0)->checkState() == Qt::Checked) && @@ -235,24 +240,25 @@ KeyIdArgsListPtr KeyList::getPrivateChecked() { return ret; } -void KeyList::setChecked(const KeyIdArgsListPtr& keyIds, +void KeyList::SetChecked(const KeyIdArgsListPtr& keyIds, const KeyTable& key_table) { if (!keyIds->empty()) { - for (int i = 0; i < key_table.key_list->rowCount(); i++) { + for (int i = 0; i < key_table.key_list_->rowCount(); i++) { if (std::find(keyIds->begin(), keyIds->end(), - key_table.buffered_keys[i].GetId()) != keyIds->end()) { - key_table.key_list->item(i, 0)->setCheckState(Qt::Checked); + key_table.buffered_keys_[i].GetId()) != keyIds->end()) { + key_table.key_list_->item(i, 0)->setCheckState(Qt::Checked); } } } } -void KeyList::setChecked(KeyIdArgsListPtr key_ids) { - auto key_list = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); +void KeyList::SetChecked(KeyIdArgsListPtr key_ids) { + auto key_list = + qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); if (key_list == nullptr) return; - if (!mKeyTables.empty()) { - for (auto& key_table : mKeyTables) { - if (key_table.key_list == key_list) { + if (!m_key_tables_.empty()) { + for (auto& key_table : m_key_tables_) { + if (key_table.key_list_ == key_list) { key_table.SetChecked(std::move(key_ids)); break; } @@ -260,13 +266,14 @@ void KeyList::setChecked(KeyIdArgsListPtr key_ids) { } } -KeyIdArgsListPtr KeyList::getSelected() { +KeyIdArgsListPtr KeyList::GetSelected() { auto ret = std::make_unique<KeyIdArgsList>(); - if (ui->keyGroupTab->size().isEmpty()) return ret; + if (ui_->keyGroupTab->size().isEmpty()) return ret; - auto key_list = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); + auto key_list = + qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); const auto& buffered_keys = - mKeyTables[ui->keyGroupTab->currentIndex()].buffered_keys; + m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; for (int i = 0; i < key_list->rowCount(); i++) { if (key_list->item(i, 0)->isSelected() == 1) { @@ -276,37 +283,37 @@ KeyIdArgsListPtr KeyList::getSelected() { return ret; } -[[maybe_unused]] bool KeyList::containsPrivateKeys() { - if (ui->keyGroupTab->size().isEmpty()) return false; - mKeyList = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); +[[maybe_unused]] bool KeyList::ContainsPrivateKeys() { + if (ui_->keyGroupTab->size().isEmpty()) return false; + m_key_list_ = qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); - for (int i = 0; i < mKeyList->rowCount(); i++) { - if (mKeyList->item(i, 1)) { + for (int i = 0; i < m_key_list_->rowCount(); i++) { + if (m_key_list_->item(i, 1)) { return true; } } return false; } -void KeyList::setColumnWidth(int row, int size) { - if (ui->keyGroupTab->size().isEmpty()) return; - mKeyList = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); +void KeyList::SetColumnWidth(int row, int size) { + if (ui_->keyGroupTab->size().isEmpty()) return; + m_key_list_ = qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); - mKeyList->setColumnWidth(row, size); + m_key_list_->setColumnWidth(row, size); } void KeyList::contextMenuEvent(QContextMenuEvent* event) { - if (ui->keyGroupTab->size().isEmpty()) return; - mKeyList = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); + if (ui_->keyGroupTab->size().isEmpty()) return; + m_key_list_ = qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); - if (mKeyList->selectedItems().length() > 0) { - popupMenu->exec(event->globalPos()); + if (m_key_list_->selectedItems().length() > 0) { + popup_menu_->exec(event->globalPos()); } } -void KeyList::addSeparator() { popupMenu->addSeparator(); } +void KeyList::AddSeparator() { popup_menu_->addSeparator(); } -void KeyList::addMenuAction(QAction* act) { popupMenu->addAction(act); } +void KeyList::AddMenuAction(QAction* act) { popup_menu_->addAction(act); } void KeyList::dropEvent(QDropEvent* event) { auto* dialog = new QDialog(); @@ -371,12 +378,12 @@ void KeyList::dropEvent(QDropEvent* event) { << tmp.toString().toStdString(); } QByteArray inBuffer = file.readAll(); - this->importKeys(inBuffer); + this->import_keys(inBuffer); file.close(); } } else { QByteArray inBuffer(event->mimeData()->text().toUtf8()); - this->importKeys(inBuffer); + this->import_keys(inBuffer); } } @@ -387,102 +394,103 @@ void KeyList::dragEnterEvent(QDragEnterEvent* event) { /** set background color for Keys and put them to top * */ -[[maybe_unused]] void KeyList::markKeys(QStringList* keyIds) { +[[maybe_unused]] void KeyList::MarkKeys(QStringList* keyIds) { foreach (QString id, *keyIds) { qDebug() << "marked: " << id; } } -void KeyList::importKeys(const QByteArray& inBuffer) { +void KeyList::import_keys(const QByteArray& inBuffer) { auto std_buffer = std::make_unique<ByteArray>(inBuffer.toStdString()); GpgImportInformation result = - GpgKeyImportExporter::GetInstance(_m_key_list_id) + GpgKeyImportExporter::GetInstance(m_key_list_id_) .ImportKey(std::move(std_buffer)); new KeyImportDetailDialog(result, false, this); } -void KeyList::slotDoubleClicked(const QModelIndex& index) { - if (ui->keyGroupTab->size().isEmpty()) return; +void KeyList::slot_double_clicked(const QModelIndex& index) { + if (ui_->keyGroupTab->size().isEmpty()) return; const auto& buffered_keys = - mKeyTables[ui->keyGroupTab->currentIndex()].buffered_keys; - if (mAction != nullptr) { - const auto key = GpgKeyGetter::GetInstance(_m_key_list_id) + m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; + if (m_action_ != nullptr) { + const auto key = GpgKeyGetter::GetInstance(m_key_list_id_) .GetKey(buffered_keys[index.row()].GetId()); - mAction(key, this); + m_action_(key, this); } } -void KeyList::setDoubleClickedAction( +void KeyList::SetDoubleClickedAction( std::function<void(const GpgKey&, QWidget*)> action) { - this->mAction = std::move(action); + this->m_action_ = std::move(action); } -std::string KeyList::getSelectedKey() { - if (ui->keyGroupTab->size().isEmpty()) return {}; +std::string KeyList::GetSelectedKey() { + if (ui_->keyGroupTab->size().isEmpty()) return {}; const auto& buffered_keys = - mKeyTables[ui->keyGroupTab->currentIndex()].buffered_keys; + m_key_tables_[ui_->keyGroupTab->currentIndex()].buffered_keys_; - for (int i = 0; i < mKeyList->rowCount(); i++) { - if (mKeyList->item(i, 0)->isSelected() == 1) { + for (int i = 0; i < m_key_list_->rowCount(); i++) { + if (m_key_list_->item(i, 0)->isSelected() == 1) { return buffered_keys[i].GetId(); } } return {}; } -void KeyList::slotRefreshUI() { - LOG(INFO) << _("Called") << _buffered_keys_list.get(); - if (_buffered_keys_list != nullptr) { - std::lock_guard<std::mutex> guard(buffered_key_list_mutex); - for (auto& key_table : mKeyTables) { - key_table.Refresh(GpgKeyGetter::GetKeysCopy(_buffered_keys_list)); +void KeyList::slot_refresh_ui() { + LOG(INFO) << _("Called") << buffered_keys_list_.get(); + if (buffered_keys_list_ != nullptr) { + std::lock_guard<std::mutex> guard(buffered_key_list_mutex_); + for (auto& key_table : m_key_tables_) { + key_table.Refresh(GpgKeyGetter::GetKeysCopy(buffered_keys_list_)); } } - emit signalRefreshStatusBar(_("Key List Refreshed."), 1000); - ui->refreshKeyListButton->setDisabled(false); - ui->syncButton->setDisabled(false); + emit SignalRefreshStatusBar(_("Key List Refreshed."), 1000); + ui_->refreshKeyListButton->setDisabled(false); + ui_->syncButton->setDisabled(false); } -void KeyList::slotSyncWithKeyServer() { +void KeyList::slot_sync_with_key_server() { KeyIdArgsList key_ids; { - std::lock_guard<std::mutex> guard(buffered_key_list_mutex); - for (const auto& key : *_buffered_keys_list) { + std::lock_guard<std::mutex> guard(buffered_key_list_mutex_); + for (const auto& key : *buffered_keys_list_) { if (!(key.IsPrivateKey() && key.IsHasMasterKey())) key_ids.push_back(key.GetId()); } } - ui->refreshKeyListButton->setDisabled(true); - ui->syncButton->setDisabled(true); + ui_->refreshKeyListButton->setDisabled(true); + ui_->syncButton->setDisabled(true); - emit signalRefreshStatusBar(_("Syncing Key List..."), 3000); + emit SignalRefreshStatusBar(_("Syncing Key List..."), 3000); CommonUtils::slotImportKeyFromKeyServer( - _m_key_list_id, key_ids, + m_key_list_id_, key_ids, [=](const std::string& key_id, const std::string& status, size_t current_index, size_t all_index) { LOG(INFO) << _("Called") << key_id << status << current_index << all_index; - auto key = GpgKeyGetter::GetInstance(_m_key_list_id).GetKey(key_id); + auto key = GpgKeyGetter::GetInstance(m_key_list_id_).GetKey(key_id); boost::format status_str = boost::format(_("Sync [%1%/%2%] %3% %4%")) % current_index % all_index % key.GetUIDs()->front().GetUID() % status; - emit signalRefreshStatusBar(status_str.str().c_str(), 1500); + emit SignalRefreshStatusBar(status_str.str().c_str(), 1500); if (current_index == all_index) { - ui->syncButton->setDisabled(false); - ui->refreshKeyListButton->setDisabled(false); - emit signalRefreshStatusBar(_("Key List Sync Done."), 3000); - emit signalRefreshDatabase(); + ui_->syncButton->setDisabled(false); + ui_->refreshKeyListButton->setDisabled(false); + emit SignalRefreshStatusBar(_("Key List Sync Done."), 3000); + emit SignalRefreshDatabase(); } }); } -void KeyList::slotUncheckALL() { - auto key_list = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); +void KeyList::uncheck_all() { + auto key_list = + qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); if (key_list == nullptr) return; - if (!mKeyTables.empty()) { - for (auto& key_table : mKeyTables) { - if (key_table.key_list == key_list) { + if (!m_key_tables_.empty()) { + for (auto& key_table : m_key_tables_) { + if (key_table.key_list_ == key_list) { key_table.UncheckALL(); break; } @@ -490,12 +498,13 @@ void KeyList::slotUncheckALL() { } } -void KeyList::slotCheckALL() { - auto key_list = qobject_cast<QTableWidget*>(ui->keyGroupTab->currentWidget()); +void KeyList::check_all() { + auto key_list = + qobject_cast<QTableWidget*>(ui_->keyGroupTab->currentWidget()); if (key_list == nullptr) return; - if (!mKeyTables.empty()) { - for (auto& key_table : mKeyTables) { - if (key_table.key_list == key_list) { + if (!m_key_tables_.empty()) { + for (auto& key_table : m_key_tables_) { + if (key_table.key_list_ == key_list) { key_table.CheckALL(); break; } @@ -508,9 +517,9 @@ KeyIdArgsListPtr& KeyTable::GetChecked() { if (checked_key_ids_ == nullptr) checked_key_ids_ = std::make_unique<KeyIdArgsList>(); auto& ret = checked_key_ids_; - for (int i = 0; i < key_list->rowCount(); i++) { - auto key_id = buffered_keys[i].GetId(); - if (key_list->item(i, 0)->checkState() == Qt::Checked && + for (int i = 0; i < key_list_->rowCount(); i++) { + auto key_id = buffered_keys_[i].GetId(); + if (key_list_->item(i, 0)->checkState() == Qt::Checked && std::find(ret->begin(), ret->end(), key_id) == ret->end()) { ret->push_back(key_id); } @@ -529,8 +538,8 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { auto& checked_key_list = GetChecked(); // while filling the table, sort enabled causes errors - key_list->setSortingEnabled(false); - key_list->clearContents(); + key_list_->setSortingEnabled(false); + key_list_->clearContents(); // Optimization for copy KeyLinkListPtr keys = nullptr; @@ -543,13 +552,13 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { int row_count = 0; while (it != keys->end()) { - if (filter != nullptr) { - if (!filter(*it)) { + if (filter_ != nullptr) { + if (!filter_(*it)) { it = keys->erase(it); continue; } } - if (select_type == KeyListRow::ONLY_SECRET_KEY && !it->IsPrivateKey()) { + if (select_type_ == KeyListRow::ONLY_SECRET_KEY && !it->IsPrivateKey()) { it = keys->erase(it); continue; } @@ -557,12 +566,12 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { it++; } - key_list->setRowCount(row_count); + key_list_->setRowCount(row_count); int row_index = 0; it = keys->begin(); - auto& table_buffered_keys = buffered_keys; + auto& table_buffered_keys = buffered_keys_; table_buffered_keys.clear(); @@ -574,7 +583,7 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { Qt::ItemIsSelectable); tmp0->setTextAlignment(Qt::AlignCenter); tmp0->setCheckState(Qt::Unchecked); - key_list->setItem(row_index, 0, tmp0); + key_list_->setItem(row_index, 0, tmp0); QString type_str; QTextStream type_steam(&type_str); @@ -593,12 +602,12 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { } auto* tmp1 = new QTableWidgetItem(type_str); - key_list->setItem(row_index, 1, tmp1); + key_list_->setItem(row_index, 1, tmp1); auto* tmp2 = new QTableWidgetItem(QString::fromStdString(it->GetName())); - key_list->setItem(row_index, 2, tmp2); + key_list_->setItem(row_index, 2, tmp2); auto* tmp3 = new QTableWidgetItem(QString::fromStdString(it->GetEmail())); - key_list->setItem(row_index, 3, tmp3); + key_list_->setItem(row_index, 3, tmp3); QString usage; QTextStream usage_steam(&usage); @@ -610,17 +619,17 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { auto* temp_usage = new QTableWidgetItem(usage); temp_usage->setTextAlignment(Qt::AlignCenter); - key_list->setItem(row_index, 4, temp_usage); + key_list_->setItem(row_index, 4, temp_usage); auto* temp_validity = new QTableWidgetItem(QString::fromStdString(it->GetOwnerTrust())); temp_validity->setTextAlignment(Qt::AlignCenter); - key_list->setItem(row_index, 5, temp_validity); + key_list_->setItem(row_index, 5, temp_validity); auto* temp_fpr = new QTableWidgetItem(QString::fromStdString(it->GetFingerprint())); temp_fpr->setTextAlignment(Qt::AlignCenter); - key_list->setItem(row_index, 6, temp_fpr); + key_list_->setItem(row_index, 6, temp_fpr); // strike out expired keys if (it->IsExpired() || it->IsRevoked()) { @@ -639,10 +648,10 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { } if (!checked_key_list->empty()) { - for (int i = 0; i < key_list->rowCount(); i++) { + for (int i = 0; i < key_list_->rowCount(); i++) { if (std::find(checked_key_list->begin(), checked_key_list->end(), - buffered_keys[i].GetId()) != checked_key_list->end()) { - key_list->item(i, 0)->setCheckState(Qt::Checked); + buffered_keys_[i].GetId()) != checked_key_list->end()) { + key_list_->item(i, 0)->setCheckState(Qt::Checked); } } } @@ -651,14 +660,14 @@ void KeyTable::Refresh(KeyLinkListPtr m_keys) { } void KeyTable::UncheckALL() const { - for (int i = 0; i < key_list->rowCount(); i++) { - key_list->item(i, 0)->setCheckState(Qt::Unchecked); + for (int i = 0; i < key_list_->rowCount(); i++) { + key_list_->item(i, 0)->setCheckState(Qt::Unchecked); } } void KeyTable::CheckALL() const { - for (int i = 0; i < key_list->rowCount(); i++) { - key_list->item(i, 0)->setCheckState(Qt::Checked); + for (int i = 0; i < key_list_->rowCount(); i++) { + key_list_->item(i, 0)->setCheckState(Qt::Checked); } } } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/KeyList.h b/src/ui/widgets/KeyList.h index 0e28d74a..182152c2 100644 --- a/src/ui/widgets/KeyList.h +++ b/src/ui/widgets/KeyList.h @@ -38,140 +38,350 @@ class Ui_KeyList; namespace GpgFrontend::UI { +/** + * @brief + * + */ struct KeyListRow { using KeyType = unsigned int; - static const KeyType SECRET_OR_PUBLIC_KEY = 0; - static const KeyType ONLY_SECRET_KEY = 1; + static const KeyType SECRET_OR_PUBLIC_KEY = 0; ///< + static const KeyType ONLY_SECRET_KEY = 1; ///< }; +/** + * @brief + * + */ struct KeyListColumn { using InfoType = unsigned int; - static constexpr InfoType ALL = ~0; - static constexpr InfoType TYPE = 1 << 0; - static constexpr InfoType NAME = 1 << 1; - static constexpr InfoType EmailAddress = 1 << 2; - static constexpr InfoType Usage = 1 << 3; - static constexpr InfoType Validity = 1 << 4; - static constexpr InfoType FingerPrint = 1 << 5; + static constexpr InfoType ALL = ~0; ///< + static constexpr InfoType TYPE = 1 << 0; ///< + static constexpr InfoType NAME = 1 << 1; ///< + static constexpr InfoType EmailAddress = 1 << 2; ///< + static constexpr InfoType Usage = 1 << 3; ///< + static constexpr InfoType Validity = 1 << 4; ///< + static constexpr InfoType FingerPrint = 1 << 5; ///< }; +/** + * @brief + * + */ struct KeyMenuAbility { using AbilityType = unsigned int; - static constexpr AbilityType ALL = ~0; - static constexpr AbilityType NONE = 0; - static constexpr AbilityType REFRESH = 1 << 0; - static constexpr AbilityType SYNC_PUBLIC_KEY = 1 << 1; - static constexpr AbilityType UNCHECK_ALL = 1 << 3; - static constexpr AbilityType CHECK_ALL = 1 << 5; + static constexpr AbilityType ALL = ~0; ///< + static constexpr AbilityType NONE = 0; ///< + static constexpr AbilityType REFRESH = 1 << 0; ///< + static constexpr AbilityType SYNC_PUBLIC_KEY = 1 << 1; ///< + static constexpr AbilityType UNCHECK_ALL = 1 << 3; ///< + static constexpr AbilityType CHECK_ALL = 1 << 5; ///< }; +/** + * @brief + * + */ struct KeyTable { - QTableWidget* key_list; - KeyListRow::KeyType select_type; - KeyListColumn::InfoType info_type; - std::vector<GpgKey> buffered_keys; - std::function<bool(const GpgKey&)> filter; - KeyIdArgsListPtr checked_key_ids_; - + QTableWidget* key_list_; ///< + KeyListRow::KeyType select_type_; ///< + KeyListColumn::InfoType info_type_; ///< + std::vector<GpgKey> buffered_keys_; ///< + std::function<bool(const GpgKey&)> filter_; ///< + KeyIdArgsListPtr checked_key_ids_; ///< + + /** + * @brief Construct a new Key Table object + * + * @param _key_list + * @param _select_type + * @param _info_type + * @param _filter + */ KeyTable( QTableWidget* _key_list, KeyListRow::KeyType _select_type, KeyListColumn::InfoType _info_type, std::function<bool(const GpgKey&)> _filter = [](const GpgKey&) -> bool { return true; }) - : key_list(_key_list), - select_type(_select_type), - info_type(_info_type), - filter(std::move(_filter)) {} - + : key_list_(_key_list), + select_type_(_select_type), + info_type_(_info_type), + filter_(std::move(_filter)) {} + + /** + * @brief + * + * @param m_keys + */ void Refresh(KeyLinkListPtr m_keys = nullptr); + /** + * @brief Get the Checked object + * + * @return KeyIdArgsListPtr& + */ KeyIdArgsListPtr& GetChecked(); + /** + * @brief + * + */ void UncheckALL() const; + /** + * @brief + * + */ void CheckALL() const; + /** + * @brief Set the Checked object + * + * @param key_ids + */ void SetChecked(KeyIdArgsListPtr key_ids); }; +/** + * @brief + * + */ class KeyList : public QWidget { Q_OBJECT public: + /** + * @brief Construct a new Key List object + * + * @param menu_ability + * @param parent + */ explicit KeyList(KeyMenuAbility::AbilityType menu_ability, QWidget* parent = nullptr); - void addListGroupTab( + /** + * @brief + * + * @param name + * @param selectType + * @param infoType + * @param filter + */ + void AddListGroupTab( const QString& name, KeyListRow::KeyType selectType = KeyListRow::SECRET_OR_PUBLIC_KEY, KeyListColumn::InfoType infoType = KeyListColumn::ALL, const std::function<bool(const GpgKey&)>& filter = [](const GpgKey&) -> bool { return true; }); - void setDoubleClickedAction( + /** + * @brief Set the Double Clicked Action object + * + * @param action + */ + void SetDoubleClickedAction( std::function<void(const GpgKey&, QWidget*)> action); - void setColumnWidth(int row, int size); - void addMenuAction(QAction* act); - void addSeparator(); + /** + * @brief Set the Column Width object + * + * @param row + * @param size + */ + void SetColumnWidth(int row, int size); + + /** + * @brief + * + * @param act + */ + void AddMenuAction(QAction* act); + + /** + * @brief + * + */ + void AddSeparator(); + + /** + * @brief Get the Checked object + * + * @return KeyIdArgsListPtr + */ + KeyIdArgsListPtr GetChecked(); + + /** + * @brief Get the Checked object + * + * @param key_table + * @return KeyIdArgsListPtr + */ + static KeyIdArgsListPtr GetChecked(const KeyTable& key_table); + + /** + * @brief Get the Private Checked object + * + * @return KeyIdArgsListPtr + */ + KeyIdArgsListPtr GetPrivateChecked(); + + /** + * @brief Get the All Private Keys object + * + * @return KeyIdArgsListPtr + */ + KeyIdArgsListPtr GetAllPrivateKeys(); + + /** + * @brief Set the Checked object + * + * @param key_ids + */ + void SetChecked(KeyIdArgsListPtr key_ids); - KeyIdArgsListPtr getChecked(); - static KeyIdArgsListPtr getChecked(const KeyTable& key_table); - KeyIdArgsListPtr getPrivateChecked(); - KeyIdArgsListPtr getAllPrivateKeys(); - void setChecked(KeyIdArgsListPtr key_ids); - static void setChecked(const KeyIdArgsListPtr& keyIds, + /** + * @brief Set the Checked object + * + * @param keyIds + * @param key_table + */ + static void SetChecked(const KeyIdArgsListPtr& keyIds, const KeyTable& key_table); - KeyIdArgsListPtr getSelected(); - std::string getSelectedKey(); - - [[maybe_unused]] static void markKeys(QStringList* keyIds); - [[maybe_unused]] bool containsPrivateKeys(); + /** + * @brief Get the Selected object + * + * @return KeyIdArgsListPtr + */ + KeyIdArgsListPtr GetSelected(); + + /** + * @brief Get the Selected Key object + * + * @return std::string + */ + std::string GetSelectedKey(); + + /** + * @brief + * + * @param keyIds + */ + [[maybe_unused]] static void MarkKeys(QStringList* keyIds); + + /** + * @brief + * + * @return true + * @return false + */ + [[maybe_unused]] bool ContainsPrivateKeys(); signals: - void signalRefreshStatusBar(const QString& message, int timeout); - void signalRefreshDatabase(); + /** + * @brief + * + * @param message + * @param timeout + */ + void SignalRefreshStatusBar(const QString& message, int timeout); + + /** + * @brief + * + */ + void SignalRefreshDatabase(); public slots: - void slotRefresh(); + /** + * @brief + * + */ + void SlotRefresh(); private: + /** + * @brief + * + */ void init(); - void importKeys(const QByteArray& inBuffer); - void slotUncheckALL(); - void slotCheckALL(); - - static int key_list_id; - int _m_key_list_id; - std::mutex buffered_key_list_mutex; - - std::shared_ptr<Ui_KeyList> ui; - QTableWidget* mKeyList{}; - std::vector<KeyTable> mKeyTables; - QMenu* popupMenu{}; - GpgFrontend::KeyLinkListPtr _buffered_keys_list; - std::function<void(const GpgKey&, QWidget*)> mAction = nullptr; - KeyMenuAbility::AbilityType menu_ability_ = KeyMenuAbility::ALL; - private slots: + /** + * @brief + * + * @param inBuffer + */ + void import_keys(const QByteArray& inBuffer); + + /** + * @brief + * + */ + void uncheck_all(); + + /** + * @brief + * + */ + void check_all(); + + static int key_list_id_; ///< + int m_key_list_id_; ///< + std::mutex buffered_key_list_mutex_; ///< + + std::shared_ptr<Ui_KeyList> ui_; ///< + QTableWidget* m_key_list_{}; ///< + std::vector<KeyTable> m_key_tables_; ///< + QMenu* popup_menu_{}; ///< + GpgFrontend::KeyLinkListPtr buffered_keys_list_; ///< + std::function<void(const GpgKey&, QWidget*)> m_action_ = nullptr; ///< + KeyMenuAbility::AbilityType menu_ability_ = KeyMenuAbility::ALL; ///< - void slotDoubleClicked(const QModelIndex& index); - - void slotRefreshUI(); + private slots: - void slotSyncWithKeyServer(); + /** + * @brief + * + * @param index + */ + void slot_double_clicked(const QModelIndex& index); + + /** + * @brief + * + */ + void slot_refresh_ui(); + + /** + * @brief + * + */ + void slot_sync_with_key_server(); protected: + /** + * @brief + * + * @param event + */ void contextMenuEvent(QContextMenuEvent* event) override; + /** + * @brief + * + * @param event + */ void dragEnterEvent(QDragEnterEvent* event) override; + /** + * @brief + * + * @param event + */ void dropEvent(QDropEvent* event) override; }; diff --git a/src/ui/widgets/PlainTextEditorPage.cpp b/src/ui/widgets/PlainTextEditorPage.cpp index ee08fff3..749283e6 100644 --- a/src/ui/widgets/PlainTextEditorPage.cpp +++ b/src/ui/widgets/PlainTextEditorPage.cpp @@ -38,54 +38,54 @@ namespace GpgFrontend::UI { PlainTextEditorPage::PlainTextEditorPage(QString filePath, QWidget* parent) : QWidget(parent), - ui(std::make_shared<Ui_PlainTextEditor>()), + ui_(std::make_shared<Ui_PlainTextEditor>()), full_file_path_(std::move(filePath)) { - ui->setupUi(this); + ui_->setupUi(this); if (full_file_path_.isEmpty()) read_done_ = true; - ui->textPage->setFocus(); - ui->loadingLabel->setHidden(true); + ui_->textPage->setFocus(); + ui_->loadingLabel->setHidden(true); // Front in same width this->setFont({"Courier"}); this->setAttribute(Qt::WA_DeleteOnClose); - this->ui->characterLabel->setText(_("0 character")); - this->ui->lfLabel->setText(_("None")); - this->ui->encodingLabel->setText(_("Binary")); + this->ui_->characterLabel->setText(_("0 character")); + this->ui_->lfLabel->setText(_("None")); + this->ui_->encodingLabel->setText(_("Binary")); - connect(ui->textPage, &QPlainTextEdit::textChanged, this, [=]() { + connect(ui_->textPage, &QPlainTextEdit::textChanged, this, [=]() { if (!read_done_) return; - auto text = ui->textPage->document()->toPlainText(); + auto text = ui_->textPage->document()->toPlainText(); auto str = boost::format(_("%1% character(s)")) % text.size(); - this->ui->characterLabel->setText(str.str().c_str()); + this->ui_->characterLabel->setText(str.str().c_str()); detect_cr_lf(text); detect_encoding(text.toStdString()); }); - ui->loadingLabel->setText(_("Loading...")); + ui_->loadingLabel->setText(_("Loading...")); } -const QString& PlainTextEditorPage::getFilePath() const { +const QString& PlainTextEditorPage::GetFilePath() const { return full_file_path_; } -QPlainTextEdit* PlainTextEditorPage::getTextPage() { return ui->textPage; } +QPlainTextEdit* PlainTextEditorPage::GetTextPage() { return ui_->textPage; } -void PlainTextEditorPage::setFilePath(const QString& filePath) { +void PlainTextEditorPage::SetFilePath(const QString& filePath) { full_file_path_ = filePath; } -void PlainTextEditorPage::showNotificationWidget(QWidget* widget, +void PlainTextEditorPage::ShowNotificationWidget(QWidget* widget, const char* className) { widget->setProperty(className, true); - ui->verticalLayout->addWidget(widget); + ui_->verticalLayout->addWidget(widget); } -void PlainTextEditorPage::closeNoteByClass(const char* className) { +void PlainTextEditorPage::CloseNoteByClass(const char* className) { QList<QWidget*> widgets = findChildren<QWidget*>(); for (QWidget* widget : widgets) { if (widget->property(className) == true) { @@ -94,8 +94,8 @@ void PlainTextEditorPage::closeNoteByClass(const char* className) { } } -void PlainTextEditorPage::slotFormatGpgHeader() { - QString content = ui->textPage->toPlainText(); +void PlainTextEditorPage::slot_format_gpg_header() { + QString content = ui_->textPage->toPlainText(); // Get positions of the gpg-headers, if they exist int start = content.indexOf(GpgFrontend::GpgConstants::PGP_SIGNED_BEGIN); @@ -103,11 +103,11 @@ void PlainTextEditorPage::slotFormatGpgHeader() { content.indexOf(GpgFrontend::GpgConstants::PGP_SIGNATURE_BEGIN); int endSig = content.indexOf(GpgFrontend::GpgConstants::PGP_SIGNATURE_END); - if (start < 0 || startSig < 0 || endSig < 0 || signMarked) { + if (start < 0 || startSig < 0 || endSig < 0 || sign_marked_) { return; } - signMarked = true; + sign_marked_ = true; // Set the fontstyle for the header QTextCharFormat signFormat; @@ -115,7 +115,7 @@ void PlainTextEditorPage::slotFormatGpgHeader() { signFormat.setFontPointSize(9); // set font style for the signature - QTextCursor cursor(ui->textPage->document()); + QTextCursor cursor(ui_->textPage->document()); cursor.setPosition(startSig, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, endSig); cursor.setCharFormat(signFormat); @@ -132,18 +132,18 @@ void PlainTextEditorPage::ReadFile() { read_done_ = false; read_bytes_ = 0; - ui->textPage->setEnabled(false); - ui->textPage->setReadOnly(true); - ui->textPage->blockSignals(true); - ui->loadingLabel->setHidden(false); - ui->textPage->document()->blockSignals(true); + ui_->textPage->setEnabled(false); + ui_->textPage->setReadOnly(true); + ui_->textPage->blockSignals(true); + ui_->loadingLabel->setHidden(false); + ui_->textPage->document()->blockSignals(true); - auto text_page = this->getTextPage(); + auto text_page = this->GetTextPage(); text_page->setReadOnly(true); auto thread = new FileReadThread(this->full_file_path_.toStdString()); connect(thread, &FileReadThread::SignalSendReadBlock, this, - &PlainTextEditorPage::slotInsertText); + &PlainTextEditorPage::slot_insert_text); connect(thread, &FileReadThread::SignalReadDone, this, [=]() { LOG(INFO) << "thread read done"; @@ -157,11 +157,11 @@ void PlainTextEditorPage::ReadFile() { thread->deleteLater(); read_done_ = true; read_thread_ = nullptr; - ui->textPage->setEnabled(true); + ui_->textPage->setEnabled(true); text_page->document()->setModified(false); - ui->textPage->blockSignals(false); - ui->textPage->document()->blockSignals(false); - ui->loadingLabel->setHidden(true); + ui_->textPage->blockSignals(false); + ui_->textPage->document()->blockSignals(false); + ui_->loadingLabel->setHidden(true); }); connect(this, &PlainTextEditorPage::destroyed, [=]() { @@ -181,7 +181,7 @@ std::string binary_to_string(const std::string& source) { return ss.str(); } -void PlainTextEditorPage::slotInsertText(const std::string& data) { +void PlainTextEditorPage::slot_insert_text(const std::string& data) { LOG(INFO) << "data size" << data.size(); read_bytes_ += data.size(); // If binary format is detected, the entire file is converted to binary format @@ -194,22 +194,22 @@ void PlainTextEditorPage::slotInsertText(const std::string& data) { if (binary_mode_) { if (if_last_binary_mode != binary_mode_) { auto text_buffer = - ui->textPage->document()->toRawText().toLocal8Bit().toStdString(); - ui->textPage->clear(); - this->getTextPage()->insertPlainText( + ui_->textPage->document()->toRawText().toLocal8Bit().toStdString(); + ui_->textPage->clear(); + this->GetTextPage()->insertPlainText( binary_to_string(text_buffer).c_str()); - this->ui->lfLabel->setText("None"); + this->ui_->lfLabel->setText("None"); } - this->getTextPage()->insertPlainText(binary_to_string(data).c_str()); + this->GetTextPage()->insertPlainText(binary_to_string(data).c_str()); auto str = boost::format(_("%1% byte(s)")) % read_bytes_; - this->ui->characterLabel->setText(str.str().c_str()); + this->ui_->characterLabel->setText(str.str().c_str()); } else { - this->getTextPage()->insertPlainText(data.c_str()); + this->GetTextPage()->insertPlainText(data.c_str()); - auto text = this->getTextPage()->toPlainText(); + auto text = this->GetTextPage()->toPlainText(); auto str = boost::format(_("%1% character(s)")) % text.size(); - this->ui->characterLabel->setText(str.str().c_str()); + this->ui_->characterLabel->setText(str.str().c_str()); detect_cr_lf(text); } } @@ -228,32 +228,32 @@ void PlainTextEditorPage::detect_encoding(const std::string& data) { if (encoding == AutoIt::Common::TextEncodingDetect::None) { binary_mode_ = true; - ui->encodingLabel->setText(_("Binary")); + ui_->encodingLabel->setText(_("Binary")); } else if (encoding == AutoIt::Common::TextEncodingDetect::ASCII) { - ui->encodingLabel->setText(_("ASCII(7 bits)")); + ui_->encodingLabel->setText(_("ASCII(7 bits)")); } else if (encoding == AutoIt::Common::TextEncodingDetect::ANSI) { - ui->encodingLabel->setText(_("ASCII(8 bits)")); + ui_->encodingLabel->setText(_("ASCII(8 bits)")); } else if (encoding == AutoIt::Common::TextEncodingDetect::UTF8_BOM || encoding == AutoIt::Common::TextEncodingDetect::UTF8_NOBOM) { - ui->encodingLabel->setText(_("UTF-8")); + ui_->encodingLabel->setText(_("UTF-8")); } else if (encoding == AutoIt::Common::TextEncodingDetect::UTF16_LE_BOM || encoding == AutoIt::Common::TextEncodingDetect::UTF16_LE_NOBOM) { - ui->encodingLabel->setText(_("UTF-16")); + ui_->encodingLabel->setText(_("UTF-16")); } else if (encoding == AutoIt::Common::TextEncodingDetect::UTF16_BE_BOM || encoding == AutoIt::Common::TextEncodingDetect::UTF16_BE_NOBOM) { - ui->encodingLabel->setText(_("UTF-16(BE)")); + ui_->encodingLabel->setText(_("UTF-16(BE)")); } } void PlainTextEditorPage::detect_cr_lf(const QString& data) { if (binary_mode_) { - this->ui->lfLabel->setText("None"); + this->ui_->lfLabel->setText("None"); return; } if (data.contains("\r\n")) { - this->ui->lfLabel->setText("CRLF"); + this->ui_->lfLabel->setText("CRLF"); } else { - this->ui->lfLabel->setText("LF"); + this->ui_->lfLabel->setText("LF"); } } diff --git a/src/ui/widgets/PlainTextEditorPage.h b/src/ui/widgets/PlainTextEditorPage.h index bc9c9dfc..64ad73ee 100644 --- a/src/ui/widgets/PlainTextEditorPage.h +++ b/src/ui/widgets/PlainTextEditorPage.h @@ -55,19 +55,19 @@ class PlainTextEditorPage : public QWidget { /** * @details Get the filepath of the currently activated tab. */ - [[nodiscard]] const QString& getFilePath() const; + [[nodiscard]] const QString& GetFilePath() const; /** * @details Set filepath of currently activated tab. * * @param filePath The path to be set */ - void setFilePath(const QString& filePath); + void SetFilePath(const QString& filePath); /** * @details Return pointer tp the textedit of the currently activated tab. */ - QPlainTextEdit* getTextPage(); + QPlainTextEdit* GetTextPage(); /** * @details Show additional widget at buttom of currently active tab @@ -75,32 +75,56 @@ class PlainTextEditorPage : public QWidget { * @param widget The widget to be added * @param className The name to handle the added widget */ - void showNotificationWidget(QWidget* widget, const char* className); + void ShowNotificationWidget(QWidget* widget, const char* className); /** * @details Hide all widgets with the given className * * @param className The classname of the widgets to hide */ - void closeNoteByClass(const char* className); + void CloseNoteByClass(const char* className); + /** + * @brief + * + */ void ReadFile(); + /** + * @brief + * + * @return true + * @return false + */ [[nodiscard]] bool ReadDone() const { return this->read_done_; } + /** + * @brief + * + */ void PrepareToDestroy(); private: - std::shared_ptr<Ui_PlainTextEditor> ui; - QString full_file_path_; /** The path to the file handled in the tab */ - bool signMarked{}; /** true, if the signed header is marked, false if not */ - bool read_done_ = false; - QThread* read_thread_ = nullptr; - bool binary_mode_ = false; - size_t read_bytes_ = 0; + std::shared_ptr<Ui_PlainTextEditor> ui_; ///< + QString full_file_path_; ///< The path to the file handled in the tab + bool sign_marked_{}; ///< true, if the signed header is marked, false if not + bool read_done_ = false; ///< + QThread* read_thread_ = nullptr; ///< + bool binary_mode_ = false; ///< + size_t read_bytes_ = 0; ///< + /** + * @brief + * + * @param data + */ void detect_encoding(const std::string& data); + /** + * @brief + * + * @param data + */ void detect_cr_lf(const QString& data); private slots: @@ -108,9 +132,14 @@ class PlainTextEditorPage : public QWidget { /** * @details Format the gpg header in another font-style */ - void slotFormatGpgHeader(); + void slot_format_gpg_header(); - void slotInsertText(const std::string& data); + /** + * @brief + * + * @param data + */ + void slot_insert_text(const std::string& data); }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/SignersPicker.cpp b/src/ui/widgets/SignersPicker.cpp index c7802e08..b7551c9c 100644 --- a/src/ui/widgets/SignersPicker.cpp +++ b/src/ui/widgets/SignersPicker.cpp @@ -38,13 +38,13 @@ SignersPicker::SignersPicker(QWidget* parent) : QDialog(parent) { /*Setup KeyList*/ key_list_ = new KeyList(false, this); - key_list_->addListGroupTab( + key_list_->AddListGroupTab( _("Signers"), KeyListRow::ONLY_SECRET_KEY, KeyListColumn::NAME | KeyListColumn::EmailAddress | KeyListColumn::Usage, [](const GpgKey& key) -> bool { return key.IsHasActualSigningCapability(); }); - key_list_->slotRefresh(); + key_list_->SlotRefresh(); auto* vbox2 = new QVBoxLayout(); vbox2->addWidget(new QLabel(QString(_("Select Signer(s)")) + ": ")); @@ -67,8 +67,8 @@ SignersPicker::SignersPicker(QWidget* parent) : QDialog(parent) { this->show(); } -GpgFrontend::KeyIdArgsListPtr SignersPicker::getCheckedSigners() { - return key_list_->getPrivateChecked(); +GpgFrontend::KeyIdArgsListPtr SignersPicker::GetCheckedSigners() { + return key_list_->GetPrivateChecked(); } } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/SignersPicker.h b/src/ui/widgets/SignersPicker.h index cf4c5478..30f872f8 100644 --- a/src/ui/widgets/SignersPicker.h +++ b/src/ui/widgets/SignersPicker.h @@ -35,16 +35,30 @@ namespace GpgFrontend::UI { class KeyList; +/** + * @brief + * + */ class SignersPicker : public QDialog { Q_OBJECT public: + /** + * @brief Construct a new Signers Picker object + * + * @param parent + */ explicit SignersPicker(QWidget* parent = nullptr); - GpgFrontend::KeyIdArgsListPtr getCheckedSigners(); + /** + * @brief Get the Checked Signers object + * + * @return GpgFrontend::KeyIdArgsListPtr + */ + GpgFrontend::KeyIdArgsListPtr GetCheckedSigners(); private: - KeyList* key_list_; + KeyList* key_list_; ///< }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/TOFUInfoPage.h b/src/ui/widgets/TOFUInfoPage.h index e64c3a63..761aa284 100644 --- a/src/ui/widgets/TOFUInfoPage.h +++ b/src/ui/widgets/TOFUInfoPage.h @@ -31,13 +31,22 @@ #include "ui/GpgFrontendUI.h" namespace GpgFrontend::UI { + +/** + * @brief + * + */ class TOFUInfoPage : public QWidget { Q_OBJECT public: + /** + * @brief Construct a new TOFUInfoPage object + * + * @param tofu_info + * @param parent + */ explicit TOFUInfoPage(const GpgTOFUInfo &tofu_info, QWidget *parent = nullptr); - - private: }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index f6b5f36e..3ac6e138 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -33,68 +33,68 @@ namespace GpgFrontend::UI { TextEdit::TextEdit(QWidget* parent) : QWidget(parent) { - countPage = 0; - tabWidget = new QTabWidget(this); - tabWidget->setMovable(true); - tabWidget->setTabsClosable(true); - tabWidget->setDocumentMode(true); + count_page_ = 0; + tab_widget_ = new QTabWidget(this); + tab_widget_->setMovable(true); + tab_widget_->setTabsClosable(true); + tab_widget_->setDocumentMode(true); auto* layout = new QVBoxLayout; - layout->addWidget(tabWidget); + layout->addWidget(tab_widget_); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); setLayout(layout); - connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, - SLOT(removeTab(int))); - slotNewTab(); + connect(tab_widget_, SIGNAL(tabCloseRequested(int)), this, + SLOT(slot_remove_tab(int))); + SlotNewTab(); setAcceptDrops(false); } -void TextEdit::slotNewTab() { - QString header = _("untitled") + QString::number(++countPage) + ".txt"; +void TextEdit::SlotNewTab() { + QString header = _("untitled") + QString::number(++count_page_) + ".txt"; auto* page = new PlainTextEditorPage(); - auto index = tabWidget->addTab(page, header); - tabWidget->setTabIcon(index, QIcon(":file.png")); - tabWidget->setCurrentIndex(tabWidget->count() - 1); - page->getTextPage()->setFocus(); - connect(page->getTextPage()->document(), &QTextDocument::modificationChanged, - this, &TextEdit::slotShowModified); + auto index = tab_widget_->addTab(page, header); + tab_widget_->setTabIcon(index, QIcon(":file.png")); + tab_widget_->setCurrentIndex(tab_widget_->count() - 1); + page->GetTextPage()->setFocus(); + connect(page->GetTextPage()->document(), &QTextDocument::modificationChanged, + this, &TextEdit::SlotShowModified); } void TextEdit::slotNewHelpTab(const QString& title, const QString& path) const { auto* page = new HelpPage(path); - tabWidget->addTab(page, title); - tabWidget->setCurrentIndex(tabWidget->count() - 1); + tab_widget_->addTab(page, title); + tab_widget_->setCurrentIndex(tab_widget_->count() - 1); } -void TextEdit::slotNewFileTab() const { +void TextEdit::SlotNewFileTab() const { auto* page = new FilePage(qobject_cast<QWidget*>(parent())); - auto index = tabWidget->addTab(page, QString()); - tabWidget->setTabIcon(index, QIcon(":file-browser.png")); - tabWidget->setCurrentIndex(tabWidget->count() - 1); - connect(page, &FilePage::pathChanged, this, - &TextEdit::slotFilePagePathChanged); - page->slotGoPath(); + auto index = tab_widget_->addTab(page, QString()); + tab_widget_->setTabIcon(index, QIcon(":file-browser.png")); + tab_widget_->setCurrentIndex(tab_widget_->count() - 1); + connect(page, &FilePage::SignalPathChanged, this, + &TextEdit::slot_file_page_path_changed); + page->SlotGoPath(); } -void TextEdit::slotOpenFile(QString& path) { +void TextEdit::SlotOpenFile(QString& path) { QFile file(path); LOG(INFO) << "path" << path.toStdString(); auto result = file.open(QIODevice::ReadOnly | QIODevice::Text); if (result) { auto* page = new PlainTextEditorPage(path); - connect(page->getTextPage()->document(), + connect(page->GetTextPage()->document(), &QTextDocument::modificationChanged, this, - &TextEdit::slotShowModified); + &TextEdit::SlotShowModified); QApplication::setOverrideCursor(Qt::WaitCursor); - auto index = tabWidget->addTab(page, strippedName(path)); - tabWidget->setTabIcon(index, QIcon(":file.png")); - tabWidget->setCurrentIndex(tabWidget->count() - 1); + auto index = tab_widget_->addTab(page, stripped_name(path)); + tab_widget_->setTabIcon(index, QIcon(":file.png")); + tab_widget_->setCurrentIndex(tab_widget_->count() - 1); QApplication::restoreOverrideCursor(); - page->getTextPage()->setFocus(); + page->GetTextPage()->setFocus(); page->ReadFile(); } else { QMessageBox::warning(this, _("Warning"), @@ -107,7 +107,7 @@ void TextEdit::slotOpenFile(QString& path) { file.close(); } -void TextEdit::slotOpen() { +void TextEdit::SlotOpen() { QStringList fileNames = QFileDialog::getOpenFileNames(this, _("Open file"), QDir::currentPath()); for (const auto& fileName : fileNames) { @@ -119,18 +119,18 @@ void TextEdit::slotOpen() { QTextStream in(&file); QApplication::setOverrideCursor(Qt::WaitCursor); - page->getTextPage()->setPlainText(in.readAll()); - page->setFilePath(fileName); - QTextDocument* document = page->getTextPage()->document(); + page->GetTextPage()->setPlainText(in.readAll()); + page->SetFilePath(fileName); + QTextDocument* document = page->GetTextPage()->document(); document->setModified(false); - tabWidget->addTab(page, strippedName(fileName)); - tabWidget->setCurrentIndex(tabWidget->count() - 1); + tab_widget_->addTab(page, stripped_name(fileName)); + tab_widget_->setCurrentIndex(tab_widget_->count() - 1); QApplication::restoreOverrideCursor(); - page->getTextPage()->setFocus(); - connect(page->getTextPage()->document(), + page->GetTextPage()->setFocus(); + connect(page->GetTextPage()->document(), SIGNAL(modificationChanged(bool)), this, - SLOT(slotShowModified())); + SLOT(SlotShowModified())); // enableAction(true) file.close(); } else { @@ -145,23 +145,23 @@ void TextEdit::slotOpen() { } } -void TextEdit::slotSave() { - if (tabWidget->count() == 0 || slotCurPageTextEdit() == 0) { +void TextEdit::SlotSave() { + if (tab_widget_->count() == 0 || SlotCurPageTextEdit() == 0) { return; } - QString fileName = slotCurPageTextEdit()->getFilePath(); + QString fileName = SlotCurPageTextEdit()->GetFilePath(); if (fileName.isEmpty()) { // QString docname = tabWidget->tabText(tabWidget->currentIndex()); // docname.remove(0,2); - slotSaveAs(); + SlotSaveAs(); } else { - saveFile(fileName); + save_file(fileName); } } -bool TextEdit::saveFile(const QString& fileName) { +bool TextEdit::save_file(const QString& fileName) { if (fileName.isEmpty()) { return false; } @@ -169,19 +169,19 @@ bool TextEdit::saveFile(const QString& fileName) { QFile file(fileName); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { - PlainTextEditorPage* page = slotCurPageTextEdit(); + PlainTextEditorPage* page = SlotCurPageTextEdit(); QTextStream outputStream(&file); QApplication::setOverrideCursor(Qt::WaitCursor); - outputStream << page->getTextPage()->toPlainText(); + outputStream << page->GetTextPage()->toPlainText(); QApplication::restoreOverrideCursor(); - QTextDocument* document = page->getTextPage()->document(); + QTextDocument* document = page->GetTextPage()->document(); document->setModified(false); - int curIndex = tabWidget->currentIndex(); - tabWidget->setTabText(curIndex, strippedName(fileName)); - page->setFilePath(fileName); + int curIndex = tab_widget_->currentIndex(); + tab_widget_->setTabText(curIndex, stripped_name(fileName)); + page->SetFilePath(fileName); // statusBar()->showMessage(_("File saved"), 2000); file.close(); return true; @@ -196,53 +196,53 @@ bool TextEdit::saveFile(const QString& fileName) { } } -bool TextEdit::slotSaveAs() { - if (tabWidget->count() == 0 || slotCurPageTextEdit() == nullptr) { +bool TextEdit::SlotSaveAs() { + if (tab_widget_->count() == 0 || SlotCurPageTextEdit() == nullptr) { return true; } - PlainTextEditorPage* page = slotCurPageTextEdit(); + PlainTextEditorPage* page = SlotCurPageTextEdit(); QString path; - if (!page->getFilePath().isEmpty()) { - path = page->getFilePath(); + if (!page->GetFilePath().isEmpty()) { + path = page->GetFilePath(); } else { - path = tabWidget->tabText(tabWidget->currentIndex()).remove(0, 2); + path = tab_widget_->tabText(tab_widget_->currentIndex()).remove(0, 2); } QString fileName = QFileDialog::getSaveFileName(this, _("Save file"), path); - return saveFile(fileName); + return save_file(fileName); } -void TextEdit::slotCloseTab() { - removeTab(tabWidget->currentIndex()); - if (tabWidget->count() != 0) { - slotCurPageTextEdit()->getTextPage()->setFocus(); +void TextEdit::SlotCloseTab() { + slot_remove_tab(tab_widget_->currentIndex()); + if (tab_widget_->count() != 0) { + SlotCurPageTextEdit()->GetTextPage()->setFocus(); } } -void TextEdit::removeTab(int index) { +void TextEdit::slot_remove_tab(int index) { // Do nothing, if no tab is opened - if (tabWidget->count() == 0) { + if (tab_widget_->count() == 0) { return; } // get the index of the actual current tab - int lastIndex = tabWidget->currentIndex(); + int last_index = tab_widget_->currentIndex(); // set the focus to argument index - tabWidget->setCurrentIndex(index); + tab_widget_->setCurrentIndex(index); - if (maybeSaveCurrentTab(true)) { - tabWidget->removeTab(index); + if (maybe_save_current_tab(true)) { + tab_widget_->removeTab(index); - if (index >= lastIndex) { - tabWidget->setCurrentIndex(lastIndex); + if (index >= last_index) { + tab_widget_->setCurrentIndex(last_index); } else { - tabWidget->setCurrentIndex(lastIndex - 1); + tab_widget_->setCurrentIndex(last_index - 1); } } - if (tabWidget->count() == 0) { + if (tab_widget_->count() == 0) { // enableAction(false); } } @@ -253,28 +253,28 @@ void TextEdit::removeTab(int index) { * * If it returns false, the close event should be aborted. */ -bool TextEdit::maybeSaveCurrentTab(bool askToSave) { - PlainTextEditorPage* page = slotCurPageTextEdit(); +bool TextEdit::maybe_save_current_tab(bool askToSave) { + PlainTextEditorPage* page = SlotCurPageTextEdit(); // if this page is no textedit, there should be nothing to save if (page == nullptr) { return true; } - QTextDocument* document = page->getTextPage()->document(); + QTextDocument* document = page->GetTextPage()->document(); if (page->ReadDone() && document->isModified()) { QMessageBox::StandardButton result = QMessageBox::Cancel; // write title of tab to docname and remove the leading * - QString docname = tabWidget->tabText(tabWidget->currentIndex()); - docname.remove(0, 2); + QString doc_name = tab_widget_->tabText(tab_widget_->currentIndex()); + doc_name.remove(0, 2); - const QString& filePath = page->getFilePath(); + const QString& file_path = page->GetFilePath(); if (askToSave) { result = QMessageBox::warning( this, _("Unsaved document"), QString(_("The document \"%1\" has been modified. Do you want to " "save your changes?")) - .arg(docname) + + .arg(doc_name) + "<br/><b>" + _("Note:") + "</b>" + _("If you don't save these files, all changes are " "lost.") + @@ -282,12 +282,12 @@ bool TextEdit::maybeSaveCurrentTab(bool askToSave) { QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); } if ((result == QMessageBox::Save) || (!askToSave)) { - if (filePath.isEmpty()) { + if (file_path.isEmpty()) { // QString docname = tabWidget->tabText(tabWidget->currentIndex()); // docname.remove(0,2); - return slotSaveAs(); + return SlotSaveAs(); } else { - return saveFile(filePath); + return save_file(file_path); } } else if (result == QMessageBox::Discard) { return true; @@ -301,9 +301,9 @@ bool TextEdit::maybeSaveCurrentTab(bool askToSave) { return true; } -bool TextEdit::maybeSaveAnyTab() { +bool TextEdit::MaybeSaveAnyTab() { // get a list of all unsaved documents and their tabids - QHash<int, QString> unsaved_docs = this->unsavedDocuments(); + QHash<int, QString> unsaved_docs = this->UnsavedDocuments(); /* * no unsaved documents, so app can be closed @@ -317,8 +317,8 @@ bool TextEdit::maybeSaveAnyTab() { */ if (unsaved_docs.size() == 1) { int modifiedTab = unsaved_docs.keys().at(0); - tabWidget->setCurrentIndex(modifiedTab); - return maybeSaveCurrentTab(true); + tab_widget_->setCurrentIndex(modifiedTab); + return maybe_save_current_tab(true); } /* @@ -344,8 +344,8 @@ bool TextEdit::maybeSaveAnyTab() { QList<int> tabIdsToSave = dialog->getTabIdsToSave(); for (const auto& tabId : tabIdsToSave) { - tabWidget->setCurrentIndex(tabId); - if (!maybeSaveCurrentTab(false)) { + tab_widget_->setCurrentIndex(tabId); + if (!maybe_save_current_tab(false)) { all_saved = false; } } @@ -356,12 +356,12 @@ bool TextEdit::maybeSaveAnyTab() { return false; } -PlainTextEditorPage* TextEdit::curTextPage() const { - return qobject_cast<PlainTextEditorPage*>(tabWidget->currentWidget()); +PlainTextEditorPage* TextEdit::CurTextPage() const { + return qobject_cast<PlainTextEditorPage*>(tab_widget_->currentWidget()); } -FilePage* TextEdit::curFilePage() const { - auto* curFilePage = qobject_cast<FilePage*>(tabWidget->currentWidget()); +FilePage* TextEdit::CurFilePage() const { + auto* curFilePage = qobject_cast<FilePage*>(tab_widget_->currentWidget()); if (curFilePage != nullptr) { return curFilePage; } else { @@ -369,25 +369,25 @@ FilePage* TextEdit::curFilePage() const { } } -int TextEdit::tabCount() const { return tabWidget->count(); } +int TextEdit::TabCount() const { return tab_widget_->count(); } -PlainTextEditorPage* TextEdit::slotCurPageTextEdit() const { +PlainTextEditorPage* TextEdit::SlotCurPageTextEdit() const { auto* curPage = - qobject_cast<PlainTextEditorPage*>(tabWidget->currentWidget()); + qobject_cast<PlainTextEditorPage*>(tab_widget_->currentWidget()); return curPage; } -FilePage* TextEdit::slotCurPageFileTreeView() const { - auto* curPage = qobject_cast<FilePage*>(tabWidget->currentWidget()); +FilePage* TextEdit::SlotCurPageFileTreeView() const { + auto* curPage = qobject_cast<FilePage*>(tab_widget_->currentWidget()); return curPage; } -void TextEdit::slotQuote() const { - if (tabWidget->count() == 0 || curTextPage() == nullptr) { +void TextEdit::SlotQuote() const { + if (tab_widget_->count() == 0 || CurTextPage() == nullptr) { return; } - QTextCursor cursor(curTextPage()->getTextPage()->document()); + QTextCursor cursor(CurTextPage()->GetTextPage()->document()); // beginEditBlock and endEditBlock() let operation look like single undo/redo // operation @@ -404,15 +404,15 @@ void TextEdit::slotQuote() const { cursor.endEditBlock(); } -void TextEdit::slotFillTextEditWithText(const QString& text) const { - QTextCursor cursor(curTextPage()->getTextPage()->document()); +void TextEdit::SlotFillTextEditWithText(const QString& text) const { + QTextCursor cursor(CurTextPage()->GetTextPage()->document()); cursor.beginEditBlock(); - this->curTextPage()->getTextPage()->selectAll(); - this->curTextPage()->getTextPage()->insertPlainText(text); + this->CurTextPage()->GetTextPage()->selectAll(); + this->CurTextPage()->GetTextPage()->insertPlainText(text); cursor.endEditBlock(); } -void TextEdit::loadFile(const QString& fileName) { +void TextEdit::LoadFile(const QString& fileName) { QFile file(fileName); if (!file.open(QFile::ReadOnly | QFile::Text)) { QMessageBox::warning( @@ -425,27 +425,27 @@ void TextEdit::loadFile(const QString& fileName) { } QTextStream in(&file); QApplication::setOverrideCursor(Qt::WaitCursor); - curTextPage()->getTextPage()->setPlainText(in.readAll()); + CurTextPage()->GetTextPage()->setPlainText(in.readAll()); QApplication::restoreOverrideCursor(); - slotCurPageTextEdit()->setFilePath(fileName); - tabWidget->setTabText(tabWidget->currentIndex(), strippedName(fileName)); + SlotCurPageTextEdit()->SetFilePath(fileName); + tab_widget_->setTabText(tab_widget_->currentIndex(), stripped_name(fileName)); file.close(); // statusBar()->showMessage(_("File loaded"), 2000); } -QString TextEdit::strippedName(const QString& full_file_name) { +QString TextEdit::stripped_name(const QString& full_file_name) { return QFileInfo(full_file_name).fileName(); } -void TextEdit::slotPrint() { - if (tabWidget->count() == 0) { +void TextEdit::SlotPrint() { + if (tab_widget_->count() == 0) { return; } #ifndef QT_NO_PRINTER QTextDocument* document; - if (curTextPage() != nullptr) { - document = curTextPage()->getTextPage()->document(); + if (CurTextPage() != nullptr) { + document = CurTextPage()->GetTextPage()->document(); } QPrinter printer; @@ -459,45 +459,45 @@ void TextEdit::slotPrint() { #endif } -void TextEdit::slotShowModified() const { - int index = tabWidget->currentIndex(); - QString title = tabWidget->tabText(index); +void TextEdit::SlotShowModified() const { + int index = tab_widget_->currentIndex(); + QString title = tab_widget_->tabText(index); // if doc is modified now, add leading * to title, // otherwise remove the leading * from the title - if (curTextPage()->getTextPage()->document()->isModified()) { - tabWidget->setTabText(index, title.prepend("* ")); + if (CurTextPage()->GetTextPage()->document()->isModified()) { + tab_widget_->setTabText(index, title.prepend("* ")); } else { - tabWidget->setTabText(index, title.remove(0, 2)); + tab_widget_->setTabText(index, title.remove(0, 2)); } } -void TextEdit::slotSwitchTabUp() const { - if (tabWidget->count() > 1) { - int new_index = (tabWidget->currentIndex() + 1) % (tabWidget->count()); - tabWidget->setCurrentIndex(new_index); +void TextEdit::SlotSwitchTabUp() const { + if (tab_widget_->count() > 1) { + int new_index = (tab_widget_->currentIndex() + 1) % (tab_widget_->count()); + tab_widget_->setCurrentIndex(new_index); } } -void TextEdit::slotSwitchTabDown() const { - if (tabWidget->count() > 1) { - int newindex = (tabWidget->currentIndex() - 1 + tabWidget->count()) % - tabWidget->count(); - tabWidget->setCurrentIndex(newindex); +void TextEdit::SlotSwitchTabDown() const { + if (tab_widget_->count() > 1) { + int newindex = (tab_widget_->currentIndex() - 1 + tab_widget_->count()) % + tab_widget_->count(); + tab_widget_->setCurrentIndex(newindex); } } /* * return a hash of tabindexes and title of unsaved tabs */ -QHash<int, QString> TextEdit::unsavedDocuments() const { +QHash<int, QString> TextEdit::UnsavedDocuments() const { QHash<int, QString> unsavedDocs; // this list could be used to implement // gedit like "unsaved changed"-dialog - for (int i = 0; i < tabWidget->count(); i++) { - auto* ep = qobject_cast<PlainTextEditorPage*>(tabWidget->widget(i)); + for (int i = 0; i < tab_widget_->count(); i++) { + auto* ep = qobject_cast<PlainTextEditorPage*>(tab_widget_->widget(i)); if (ep != nullptr && ep->ReadDone() && - ep->getTextPage()->document()->isModified()) { - QString doc_name = tabWidget->tabText(i); + ep->GetTextPage()->document()->isModified()) { + QString doc_name = tab_widget_->tabText(i); LOG(INFO) << "unsaved" << doc_name.toStdString(); // remove * before name of modified doc @@ -508,77 +508,77 @@ QHash<int, QString> TextEdit::unsavedDocuments() const { return unsavedDocs; } -void TextEdit::slotCut() const { - if (tabWidget->count() == 0 || curTextPage() == nullptr) { +void TextEdit::slot_cut() const { + if (tab_widget_->count() == 0 || CurTextPage() == nullptr) { return; } - curTextPage()->getTextPage()->cut(); + CurTextPage()->GetTextPage()->cut(); } -void TextEdit::slotCopy() const { - if (tabWidget->count() == 0) { +void TextEdit::slot_copy() const { + if (tab_widget_->count() == 0) { return; } - if (curTextPage() != nullptr) { - curTextPage()->getTextPage()->copy(); + if (CurTextPage() != nullptr) { + CurTextPage()->GetTextPage()->copy(); } } -void TextEdit::slotPaste() const { - if (tabWidget->count() == 0 || curTextPage() == nullptr) { +void TextEdit::slot_paste() const { + if (tab_widget_->count() == 0 || CurTextPage() == nullptr) { return; } - curTextPage()->getTextPage()->paste(); + CurTextPage()->GetTextPage()->paste(); } -void TextEdit::slotUndo() const { - if (tabWidget->count() == 0 || curTextPage() == nullptr) { +void TextEdit::slot_undo() const { + if (tab_widget_->count() == 0 || CurTextPage() == nullptr) { return; } - curTextPage()->getTextPage()->undo(); + CurTextPage()->GetTextPage()->undo(); } -void TextEdit::slotRedo() const { - if (tabWidget->count() == 0 || curTextPage() == nullptr) { +void TextEdit::slot_redo() const { + if (tab_widget_->count() == 0 || CurTextPage() == nullptr) { return; } - curTextPage()->getTextPage()->redo(); + CurTextPage()->GetTextPage()->redo(); } -void TextEdit::slotZoomIn() const { - if (tabWidget->count() == 0) { +void TextEdit::slot_zoom_in() const { + if (tab_widget_->count() == 0) { return; } - if (curTextPage() != nullptr) { - curTextPage()->getTextPage()->zoomIn(); + if (CurTextPage() != nullptr) { + CurTextPage()->GetTextPage()->zoomIn(); } } -void TextEdit::slotZoomOut() const { - if (tabWidget->count() == 0) { +void TextEdit::slot_zoom_out() const { + if (tab_widget_->count() == 0) { return; } - if (curTextPage() != nullptr) { - curTextPage()->getTextPage()->zoomOut(); + if (CurTextPage() != nullptr) { + CurTextPage()->GetTextPage()->zoomOut(); } } -void TextEdit::slotSelectAll() const { - if (tabWidget->count() == 0 || curTextPage() == nullptr) { +void TextEdit::slot_select_all() const { + if (tab_widget_->count() == 0 || CurTextPage() == nullptr) { return; } - curTextPage()->getTextPage()->selectAll(); + CurTextPage()->GetTextPage()->selectAll(); } -void TextEdit::slotFilePagePathChanged(const QString& path) const { - int index = tabWidget->currentIndex(); +void TextEdit::slot_file_page_path_changed(const QString& path) const { + int index = tab_widget_->currentIndex(); QString mPath; QFileInfo fileInfo(path); QString tPath = fileInfo.absoluteFilePath(); @@ -587,7 +587,7 @@ void TextEdit::slotFilePagePathChanged(const QString& path) const { } else { mPath = tPath; } - tabWidget->setTabText(index, mPath); + tab_widget_->setTabText(index, mPath); } } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/TextEdit.h b/src/ui/widgets/TextEdit.h index 1c14c0e1..c4d2699d 100644 --- a/src/ui/widgets/TextEdit.h +++ b/src/ui/widgets/TextEdit.h @@ -52,7 +52,7 @@ class TextEdit : public QWidget { * @param fileName QString containing the filename to load * @return nothing */ - void loadFile(const QString& fileName); + void LoadFile(const QString& fileName); /** * @details Checks if there are unsaved documents in any tab, @@ -61,26 +61,36 @@ class TextEdit : public QWidget { * @return \li false, if the close event should be aborted. * \li true, otherwise */ - bool maybeSaveAnyTab(); + bool MaybeSaveAnyTab(); - [[nodiscard]] int tabCount() const; + /** + * @brief + * + * @return int + */ + [[nodiscard]] int TabCount() const; /** * @details textpage of the currently activated tab * @return \li reference to QTextEdit if tab has one * \li 0 otherwise (e.g. if helppage) */ - [[nodiscard]] PlainTextEditorPage* curTextPage() const; + [[nodiscard]] PlainTextEditorPage* CurTextPage() const; - [[nodiscard]] FilePage* curFilePage() const; + /** + * @brief + * + * @return FilePage* + */ + [[nodiscard]] FilePage* CurFilePage() const; /** * @details List of currently unsaved tabs. - * @returns QHash<int, QString> Hash of tabindexes and title of unsaved tabs. + * @returns QHash<int, QString> Hash of tab indexes and title of unsaved tabs. */ - [[nodiscard]] QHash<int, QString> unsavedDocuments() const; + [[nodiscard]] QHash<int, QString> UnsavedDocuments() const; - QTabWidget* tabWidget; /** Widget containing the tabs of the editor */ + QTabWidget* tab_widget_; /** Widget containing the tabs of the editor */ public slots: @@ -88,62 +98,62 @@ class TextEdit : public QWidget { * @details Return pointer to the currently activated text edit tab page. * */ - PlainTextEditorPage* slotCurPageTextEdit() const; + PlainTextEditorPage* SlotCurPageTextEdit() const; /** - * @details Return pointer to the currently activated file treeview tab page. + * @details Return pointer to the currently activated file tree view tab page. * */ - FilePage* slotCurPageFileTreeView() const; + FilePage* SlotCurPageFileTreeView() const; /** - * @details Insert a ">" at the begining of every line of current textedit. + * @details Insert a ">" at the beginning of every line of current textedit. */ - void slotQuote() const; + void SlotQuote() const; /** * @details replace the text of currently active textedit with given text. * @param text to fill on. */ - void slotFillTextEditWithText(const QString& text) const; + void SlotFillTextEditWithText(const QString& text) const; /** * @details Saves the content of the current tab, if it has a filepath * otherwise it calls saveAs for the current tab */ - void slotSave(); + void SlotSave(); /** - * @details Opens a savefiledialog and calls saveFile with the choosen + * @details Opens a savefiledialog and calls save_file with the choosen * filename. * * @return Return the return value of the savefile method */ - bool slotSaveAs(); + bool SlotSaveAs(); /** * @details Show an OpenFileDoalog and open the file in a new tab. * Shows an error dialog, if the open fails. * Set the focus to the tab of the opened file. */ - void slotOpen(); + void SlotOpen(); /** * @details Open a print-dialog for the current tab */ - void slotPrint(); + void SlotPrint(); /** * @details Adds a new tab with the title "untitled"+countpage+".txt" * Sets the focus to the new tab. Increase Tab-Count by * one */ - void slotNewTab(); + void SlotNewTab(); /** * @details Adds a new tab with opening file by path */ - void slotOpenFile(QString& path); + void SlotOpenFile(QString& path); /** * @details Adds a new tab with the given title and opens given html file. @@ -156,31 +166,31 @@ class TextEdit : public QWidget { /** * New File Tab to do file operation */ - void slotNewFileTab() const; + void SlotNewFileTab() const; /** * @details put a * in front of current tabs title, if current textedit is * modified */ - void slotShowModified() const; + void SlotShowModified() const; /** * @details close the current tab and decrease TabWidget->count by \a 1 * */ - void slotCloseTab(); + void SlotCloseTab(); /** * @details Switch to the next tab. * */ - void slotSwitchTabUp() const; + void SlotSwitchTabUp() const; /** * @details Switch to the previous tab. * */ - void slotSwitchTabDown() const; + void SlotSwitchTabDown() const; private: /** @@ -189,96 +199,80 @@ class TextEdit : public QWidget { * @param a filename path * @return QString containing the filename */ - static QString strippedName(const QString& full_file_name); + static QString stripped_name(const QString& full_file_name); /** * @brief * * @param askToSave */ - bool maybeSaveCurrentTab(bool askToSave); + bool maybe_save_current_tab(bool askToSave); - /**************************************************************************************** - * Name: countPage - * Description: int cotaining the number of added tabs - */ - int countPage; /* TODO */ + int count_page_; ///< int containing the number of added tabs private slots: - void slotFilePagePathChanged(const QString& path) const; + void slot_file_page_path_changed(const QString& path) const; /** * @details Remove the tab with given index * * @param index Tab-number to remove */ - void removeTab(int index); + void slot_remove_tab(int index); /** - * @details Cut selected text in current textpage. + * @details Cut selected text in current text page. */ - void slotCut() const; + void slot_cut() const; /** - * @details Copy selected text of current textpage to clipboard. + * @details Copy selected text of current text page to clipboard. */ - void slotCopy() const; + void slot_copy() const; /** - * @details Paste text from clipboard to current textpage. + * @details Paste text from clipboard to current text page. */ - void slotPaste() const; + void slot_paste() const; /** * @details Undo last change in current textpage. * */ - void slotUndo() const; - /**************************************************************************************** - * Name: redo - * Description: redo last change in current textpage - * Parameters: none - * Return Values: none - * Change on members: none + void slot_undo() const; + + /** + * @brief redo last change in current text page + * */ + void slot_redo() const; + /** * @brief * */ - void slotRedo() const; - - void slotZoomIn() const; + void slot_zoom_in() const; - void slotZoomOut() const; - /**************************************************************************************** - * Name: selectAll - * Description: select all in current textpage - * Parameters: none - * Return Values: none - * Change on members: none - */ /** * @brief * */ - void slotSelectAll() const; + void slot_zoom_out() const; - protected: - /**************************************************************************************** - * Name: saveFile - * Description: Saves the content of currentTab to the file filename - * Parameters: QString filename contains the full path of the file to - * save Return Values: true, if the file was saved succesfully false, if - * parameter filename is empty or the saving failed Change on members: sets - * isModified of the current tab to false + /** + * @brief select all in current text page + * */ + void slot_select_all() const; + + protected: /** - * @brief + * @brief Saves the content of currentTab to the file filename * * @param fileName */ - bool saveFile(const QString& fileName); + bool save_file(const QString& fileName); }; } // namespace GpgFrontend::UI diff --git a/src/ui/widgets/VerifyKeyDetailBox.cpp b/src/ui/widgets/VerifyKeyDetailBox.cpp index b9b03be7..02afa4ee 100644 --- a/src/ui/widgets/VerifyKeyDetailBox.cpp +++ b/src/ui/widgets/VerifyKeyDetailBox.cpp @@ -34,7 +34,7 @@ namespace GpgFrontend::UI { VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, QWidget* parent) - : QGroupBox(parent), fpr(signature.GetFingerprint()) { + : QGroupBox(parent), fpr_(signature.GetFingerprint()) { auto* vbox = new QVBoxLayout(); switch (gpg_err_code(signature.GetStatus())) { @@ -42,9 +42,9 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, this->setTitle("A Error Signature"); auto* importButton = new QPushButton(_("Import from keyserver")); connect(importButton, SIGNAL(clicked()), this, - SLOT(slotImportFormKeyserver())); + SLOT(slot_import_form_key_server())); - this->setTitle(QString(_("Key not present with id 0x")) + fpr.c_str()); + this->setTitle(QString(_("Key not present with id 0x")) + fpr_.c_str()); auto grid = new QGridLayout(); @@ -59,7 +59,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, } case GPG_ERR_NO_ERROR: { this->setTitle(QString(_("A Signature")) + ":"); - auto gird = createKeyInfoGrid(signature); + auto gird = create_key_info_grid(signature); if (gird != nullptr) { vbox->addLayout(gird); } else { @@ -75,7 +75,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, this->setTitle("An Error Signature"); vbox->addWidget( new QLabel(QString(_("Status")) + ":" + _("Cert Revoked"))); - auto gird = createKeyInfoGrid(signature); + auto gird = create_key_info_grid(signature); if (gird != nullptr) { vbox->addLayout(gird); } else { @@ -91,7 +91,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, this->setTitle("An Error Signature"); vbox->addWidget( new QLabel(QString(_("Status")) + ":" + _("Signature Expired"))); - auto gird = createKeyInfoGrid(signature); + auto gird = create_key_info_grid(signature); if (gird != nullptr) { vbox->addLayout(gird); } else { @@ -109,7 +109,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, new QLabel(QString(_("Status")) + ":" + _("Key Expired"))); vbox->addWidget( new QLabel(QString(_("Status")) + ":" + _("Key Expired"))); - auto gird = createKeyInfoGrid(signature); + auto gird = create_key_info_grid(signature); if (gird != nullptr) { vbox->addLayout(gird); } else { @@ -125,7 +125,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, this->setTitle("An Error Signature"); vbox->addWidget( new QLabel(QString(_("Status")) + ":" + _("General Error"))); - auto gird = createKeyInfoGrid(signature); + auto gird = create_key_info_grid(signature); if (gird != nullptr) { vbox->addLayout(gird); } else { @@ -140,7 +140,7 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, default: { this->setTitle("An Error Signature"); this->setTitle(QString(_("Status")) + ":" + _("Unknown Error ")); - auto gird = createKeyInfoGrid(signature); + auto gird = create_key_info_grid(signature); if (gird != nullptr) { vbox->addLayout(gird); } else { @@ -156,17 +156,17 @@ VerifyKeyDetailBox::VerifyKeyDetailBox(const GpgSignature& signature, this->setLayout(vbox); } -void VerifyKeyDetailBox::slotImportFormKeyserver() { +void VerifyKeyDetailBox::slot_import_form_key_server() { auto* importDialog = new KeyServerImportDialog(false, this); auto key_ids = std::make_unique<KeyIdArgsList>(); - key_ids->push_back(fpr); + key_ids->push_back(fpr_); importDialog->slotImport(key_ids); } -QGridLayout* VerifyKeyDetailBox::createKeyInfoGrid( +QGridLayout* VerifyKeyDetailBox::create_key_info_grid( const GpgSignature& signature) { auto grid = new QGridLayout(); - GpgKey key = GpgKeyGetter::GetInstance().GetKey(fpr); + GpgKey key = GpgKeyGetter::GetInstance().GetKey(fpr_); if (!key.IsGood()) return nullptr; grid->addWidget(new QLabel(QString(_("Signer Name")) + ":"), 0, 0); @@ -177,7 +177,7 @@ QGridLayout* VerifyKeyDetailBox::createKeyInfoGrid( grid->addWidget(new QLabel(QString::fromStdString(key.GetName())), 0, 1); grid->addWidget(new QLabel(QString::fromStdString(key.GetEmail())), 1, 1); - grid->addWidget(new QLabel(beautify_fingerprint(fpr).c_str()), 2, 1); + grid->addWidget(new QLabel(beautify_fingerprint(fpr_).c_str()), 2, 1); if (signature.GetSummary() & GPGME_SIGSUM_VALID) { grid->addWidget(new QLabel(_("Fully Valid")), 3, 1); diff --git a/src/ui/widgets/VerifyKeyDetailBox.h b/src/ui/widgets/VerifyKeyDetailBox.h index 8cf413ca..0b6b1d34 100644 --- a/src/ui/widgets/VerifyKeyDetailBox.h +++ b/src/ui/widgets/VerifyKeyDetailBox.h @@ -33,20 +33,39 @@ #include "ui/widgets/KeyList.h" namespace GpgFrontend::UI { - +/** + * @brief + * + */ class VerifyKeyDetailBox : public QGroupBox { Q_OBJECT public: + /** + * @brief Construct a new Verify Key Detail Box object + * + * @param signature + * @param parent + */ explicit VerifyKeyDetailBox(const GpgSignature& signature, QWidget* parent); private slots: - void slotImportFormKeyserver(); + /** + * @brief + * + */ + void slot_import_form_key_server(); private: - QGridLayout* createKeyInfoGrid(const GpgSignature& signature); + /** + * @brief Create a key info grid object + * + * @param signature + * @return QGridLayout* + */ + QGridLayout* create_key_info_grid(const GpgSignature& signature); - std::string fpr; + std::string fpr_; ///< }; } // namespace GpgFrontend::UI |