diff options
-rw-r--r-- | src/core/function/ArchiveFileOperator.cpp | 15 | ||||
-rw-r--r-- | src/core/function/CharsetOperator.cpp | 6 | ||||
-rw-r--r-- | src/core/function/aes/aes_ssl_cbc.cpp | 4 | ||||
-rw-r--r-- | src/core/model/GpgData.cpp | 3 | ||||
-rw-r--r-- | src/core/thread/Task.cpp | 2 | ||||
-rw-r--r-- | src/ui/GpgFrontendUIInit.cpp | 4 | ||||
-rw-r--r-- | src/ui/UserInterfaceUtils.cpp | 52 | ||||
-rw-r--r-- | src/ui/dialog/details/VerifyDetailsDialog.h | 1 | ||||
-rw-r--r-- | src/ui/dialog/help/AboutDialog.h | 1 | ||||
-rw-r--r-- | src/ui/dialog/import_export/KeyImportDetailDialog.cpp | 40 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/KeygenDialog.cpp | 4 | ||||
-rw-r--r-- | src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp | 2 | ||||
-rw-r--r-- | src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp | 2 |
13 files changed, 60 insertions, 76 deletions
diff --git a/src/core/function/ArchiveFileOperator.cpp b/src/core/function/ArchiveFileOperator.cpp index 04c9326f..8aad0500 100644 --- a/src/core/function/ArchiveFileOperator.cpp +++ b/src/core/function/ArchiveFileOperator.cpp @@ -136,8 +136,6 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( } for (;;) { - bool needcr = false; - entry = archive_entry_new(); r = archive_read_next_header2(disk, entry); @@ -149,15 +147,6 @@ void GpgFrontend::ArchiveFileOperator::CreateArchive( } archive_read_disk_descend(disk); -#ifdef WINDOWS - auto entry_path = - QString::fromStdWString(std::wstring(archive_entry_pathname_w(entry))) - .toUtf8() - .toStdString(); -#else - auto entry_path = std::string(archive_entry_pathname_utf8(entry)); -#endif - SPDLOG_DEBUG("Adding: {} size: {} bytes: {} file type: {}", archive_entry_pathname_utf8(entry), archive_entry_size(entry), archive_entry_filetype(entry)); @@ -201,7 +190,6 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive( struct archive *a; struct archive *ext; struct archive_entry *entry; - int r; a = archive_read_new(); ext = archive_write_disk_new(); @@ -241,8 +229,9 @@ void GpgFrontend::ArchiveFileOperator::ExtractArchive( archive_error_string(a)); throw std::runtime_error("archive_read_open_filename() failed"); } + for (;;) { - r = archive_read_next_header(a, &entry); + int r = archive_read_next_header(a, &entry); if (r == ARCHIVE_EOF) break; if (r != ARCHIVE_OK) { SPDLOG_ERROR("archive_read_next_header() failed: {}", diff --git a/src/core/function/CharsetOperator.cpp b/src/core/function/CharsetOperator.cpp index 0e40e317..72c5e72b 100644 --- a/src/core/function/CharsetOperator.cpp +++ b/src/core/function/CharsetOperator.cpp @@ -117,12 +117,10 @@ bool GpgFrontend::CharsetOperator::Convert2Utf8(const std::string &buffer, if (status == U_BUFFER_OVERFLOW_ERROR) { status = U_ZERO_ERROR; - target_limit = target_capacity + 1; out_buffer.clear(); out_buffer.resize(target_capacity); - target_capacity = - ucnv_convert(from_encode.c_str(), to_encode.c_str(), out_buffer.data(), - out_buffer.size(), buffer.data(), buffer.size(), &status); + ucnv_convert(from_encode.c_str(), to_encode.c_str(), out_buffer.data(), + out_buffer.size(), buffer.data(), buffer.size(), &status); } if (U_FAILURE(status)) { diff --git a/src/core/function/aes/aes_ssl_cbc.cpp b/src/core/function/aes/aes_ssl_cbc.cpp index 88a54baa..3aa80ef5 100644 --- a/src/core/function/aes/aes_ssl_cbc.cpp +++ b/src/core/function/aes/aes_ssl_cbc.cpp @@ -59,7 +59,7 @@ uint8_t *aes_256_cbc_encrypt(EVP_CIPHER_CTX *e, uint8_t *plaintext, int *len) { /* max ciphertext len for a n bytes of plaintext is n + AES_BLOCK_SIZE -1 * bytes */ int c_len = *len + AES_BLOCK_SIZE, f_len = 0; - auto *ciphertext = (uint8_t *)malloc(c_len); + auto *ciphertext = static_cast<uint8_t *>(malloc(c_len)); /* allows reusing of 'e' for multiple encryption cycles */ EVP_EncryptInit_ex(e, nullptr, nullptr, nullptr, nullptr); @@ -86,7 +86,7 @@ uint8_t *aes_256_cbc_encrypt(EVP_CIPHER_CTX *e, uint8_t *plaintext, int *len) { uint8_t *aes_256_cbc_decrypt(EVP_CIPHER_CTX *e, uint8_t *ciphertext, int *len) { /* plaintext will always be equal to or lesser than length of ciphertext*/ int p_len = *len, f_len = 0; - auto *plaintext = (uint8_t *)malloc(p_len); + auto *plaintext = static_cast<uint8_t *>(malloc(p_len)); EVP_DecryptInit_ex(e, nullptr, nullptr, nullptr, nullptr); EVP_DecryptUpdate(e, plaintext, &p_len, ciphertext, *len); diff --git a/src/core/model/GpgData.cpp b/src/core/model/GpgData.cpp index 5aa95dc6..05f61a46 100644 --- a/src/core/model/GpgData.cpp +++ b/src/core/model/GpgData.cpp @@ -40,7 +40,8 @@ GpgFrontend::GpgData::GpgData() { GpgFrontend::GpgData::GpgData(void* buffer, size_t size, bool copy) { gpgme_data_t data; - auto err = gpgme_data_new_from_mem(&data, (const char*)buffer, size, copy); + auto err = gpgme_data_new_from_mem(&data, static_cast<const char*>(buffer), + size, copy); assert(gpgme_err_code(err) == GPG_ERR_NO_ERROR); data_ref_ = std::unique_ptr<struct gpgme_data, _data_ref_deleter>(data); diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp index f3c6ae86..7173b69e 100644 --- a/src/core/thread/Task.cpp +++ b/src/core/thread/Task.cpp @@ -218,7 +218,7 @@ void GpgFrontend::Thread::Task::DataObject::free_heap_ptr(Destructor *ptr) { if (ptr->destroy != nullptr) { ptr->destroy(ptr->p_obj); } - free((void *)ptr->p_obj); + free(const_cast<void *>(ptr->p_obj)); delete ptr; } diff --git a/src/ui/GpgFrontendUIInit.cpp b/src/ui/GpgFrontendUIInit.cpp index d363f886..b90493a5 100644 --- a/src/ui/GpgFrontendUIInit.cpp +++ b/src/ui/GpgFrontendUIInit.cpp @@ -270,7 +270,7 @@ void init_locale() { #ifndef WINDOWS if (!lang.empty()) { - std::string lc = lang.empty() ? "" : lang + ".UTF-8"; + std::string lc = lang + ".UTF-8"; // set LC_ALL auto* locale_name = setlocale(LC_ALL, lc.c_str()); @@ -286,7 +286,7 @@ void init_locale() { } #else if (!lang.empty()) { - std::string lc = lang.empty() ? "" : lang; + std::string lc = lang; // set LC_ALL auto* locale_name = setlocale(LC_ALL, lc.c_str()); diff --git a/src/ui/UserInterfaceUtils.cpp b/src/ui/UserInterfaceUtils.cpp index f944e037..5a11e119 100644 --- a/src/ui/UserInterfaceUtils.cpp +++ b/src/ui/UserInterfaceUtils.cpp @@ -299,38 +299,36 @@ void CommonUtils::SlotExecuteGpgCommand( void CommonUtils::SlotImportKeyFromKeyServer( const KeyIdArgsList &key_ids, const ImportCallbackFunctiopn &callback) { + // target key server that we need to import key from it std::string target_keyserver; - if (target_keyserver.empty()) { - try { - auto &settings = GlobalSettingStation::GetInstance().GetUISettings(); - SettingsObject key_server_json("key_server"); + try { + auto &settings = GlobalSettingStation::GetInstance().GetUISettings(); + SettingsObject key_server_json("key_server"); - // get key servers from settings - const auto key_server_list = - key_server_json.Check("server_list", nlohmann::json::array()); - if (key_server_list.empty()) { - throw std::runtime_error("No key server configured"); - } + // get key servers from settings + const auto key_server_list = + key_server_json.Check("server_list", nlohmann::json::array()); + if (key_server_list.empty()) { + throw std::runtime_error("No key server configured"); + } - const int target_key_server_index = - key_server_json.Check("default_server", 0); - if (target_key_server_index >= key_server_list.size()) { - throw std::runtime_error("default_server index out of range"); - } - target_keyserver = - key_server_list[target_key_server_index].get<std::string>(); - - SPDLOG_DEBUG("set target key server to default Key Server: {}", - target_keyserver); - } catch (...) { - SPDLOG_ERROR(_("Cannot read default_keyserver From Settings")); - QMessageBox::critical( - nullptr, _("Default Keyserver Not Found"), - _("Cannot read default keyserver from your settings, " - "please set a default keyserver first")); - return; + const int target_key_server_index = + key_server_json.Check("default_server", 0); + if (target_key_server_index >= key_server_list.size()) { + throw std::runtime_error("default_server index out of range"); } + target_keyserver = + key_server_list[target_key_server_index].get<std::string>(); + + SPDLOG_DEBUG("set target key server to default Key Server: {}", + target_keyserver); + } catch (...) { + SPDLOG_ERROR(_("Cannot read default_keyserver From Settings")); + QMessageBox::critical(nullptr, _("Default Keyserver Not Found"), + _("Cannot read default keyserver from your settings, " + "please set a default keyserver first")); + return; } auto thread = QThread::create([target_keyserver, key_ids, callback]() { diff --git a/src/ui/dialog/details/VerifyDetailsDialog.h b/src/ui/dialog/details/VerifyDetailsDialog.h index 97e2cc2d..5bc09884 100644 --- a/src/ui/dialog/details/VerifyDetailsDialog.h +++ b/src/ui/dialog/details/VerifyDetailsDialog.h @@ -60,7 +60,6 @@ class VerifyDetailsDialog : public QDialog { void slot_refresh(); private: - KeyList* key_list_; ///< QHBoxLayout* main_layout_; ///< QWidget* m_vbox_{}; ///< QByteArray* input_data_{}; ///< diff --git a/src/ui/dialog/help/AboutDialog.h b/src/ui/dialog/help/AboutDialog.h index 09a63734..6d7ce265 100644 --- a/src/ui/dialog/help/AboutDialog.h +++ b/src/ui/dialog/help/AboutDialog.h @@ -80,7 +80,6 @@ class UpdateTab : public QWidget { QLabel* upgrade_label_; ///< QProgressBar* pb_; ///< QString current_version_; ///< - QPushButton* download_button_; ///< public: /** diff --git a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp index e9b1af93..4e10146b 100644 --- a/src/ui/dialog/import_export/KeyImportDetailDialog.cpp +++ b/src/ui/dialog/import_export/KeyImportDetailDialog.cpp @@ -124,7 +124,6 @@ void KeyImportDetailDialog::create_general_info_box() { new QLabel(QString(_("Private Unchanged")) + ": "), row, 0); generalInfoBoxLayout->addWidget( new QLabel(QString::number(m_result_.secret_unchanged)), row, 1); - row++; } } @@ -162,36 +161,35 @@ void KeyImportDetailDialog::create_keys_table() { keys_table_->resizeColumnsToContents(); } -QString KeyImportDetailDialog::get_status_string(int keyStatus) { - QString statusString; +QString KeyImportDetailDialog::get_status_string(int key_status) { + QString status_string; // keystatus is greater than 15, if key is private - if (keyStatus > 15) { - statusString.append(_("Private")); - keyStatus = keyStatus - 16; + if (key_status > 15) { + status_string.append(_("Private")); + key_status = key_status - 16; } else { - statusString.append(_("Public")); + status_string.append(_("Public")); } - if (keyStatus == 0) { - statusString.append(", " + QString(_("Unchanged"))); + if (key_status == 0) { + status_string.append(", " + QString(_("Unchanged"))); } else { - if (keyStatus == 1) { - statusString.append(", " + QString(_("New Key"))); + if (key_status == 1) { + status_string.append(", " + QString(_("New Key"))); } else { - if (keyStatus > 7) { - statusString.append(", " + QString(_("New Subkey"))); - keyStatus = keyStatus - 8; + if (key_status > 7) { + status_string.append(", " + QString(_("New Subkey"))); + return status_string; } - if (keyStatus > 3) { - statusString.append(", " + QString(_("New Signature"))); - keyStatus = keyStatus - 4; + if (key_status > 3) { + status_string.append(", " + QString(_("New Signature"))); + return status_string; } - if (keyStatus > 1) { - statusString.append(", " + QString(_("New UID"))); - keyStatus = keyStatus - 2; + if (key_status > 1) { + status_string.append(", " + QString(_("New UID"))); + return status_string; } } } - return statusString; } void KeyImportDetailDialog::create_button_box() { diff --git a/src/ui/dialog/key_generate/KeygenDialog.cpp b/src/ui/dialog/key_generate/KeygenDialog.cpp index f103f0b1..ea874ed2 100644 --- a/src/ui/dialog/key_generate/KeygenDialog.cpp +++ b/src/ui/dialog/key_generate/KeygenDialog.cpp @@ -28,6 +28,8 @@ #include "KeygenDialog.h" +#include <qobject.h> + #include "core/common/CoreCommonUtil.h" #include "core/function/GlobalSettingStation.h" #include "core/function/gpg/GpgKeyOpera.h" @@ -178,7 +180,7 @@ void KeyGenDialog::slot_key_gen_accept() { SPDLOG_DEBUG("generate done"); if (gpgme_err_code(error) == GPG_ERR_NO_ERROR) { - auto* msg_box = new QMessageBox((QWidget*)this->parent()); + auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent())); msg_box->setAttribute(Qt::WA_DeleteOnClose); msg_box->setStandardButtons(QMessageBox::Ok); msg_box->setWindowTitle(_("Success")); diff --git a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp index 1569fc5d..f4263962 100644 --- a/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp +++ b/src/ui/dialog/key_generate/SubkeyGenerateDialog.cpp @@ -327,7 +327,7 @@ void SubkeyGenerateDialog::slot_key_gen_accept() { } if (check_gpg_error_2_err_code(error) == GPG_ERR_NO_ERROR) { - auto* msg_box = new QMessageBox((QWidget*)this->parent()); + auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent())); msg_box->setAttribute(Qt::WA_DeleteOnClose); msg_box->setStandardButtons(QMessageBox::Ok); msg_box->setWindowTitle(_("Success")); diff --git a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp index d09662e1..89d2ce74 100644 --- a/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/dialog/keypair_details/KeySetExpireDateDialog.cpp @@ -79,7 +79,7 @@ void KeySetExpireDateDialog::slot_confirm() { auto err = GpgKeyOpera::GetInstance().SetExpire(m_key_, m_subkey_, expires); if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) { - auto* msg_box = new QMessageBox((QWidget*)this->parent()); + auto* msg_box = new QMessageBox(qobject_cast<QWidget*>(this->parent())); msg_box->setAttribute(Qt::WA_DeleteOnClose); msg_box->setStandardButtons(QMessageBox::Ok); msg_box->setWindowTitle(_("Success")); |