diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gpg/GpgConstants.cpp | 4 | ||||
-rw-r--r-- | src/gpg/GpgConstants.h | 2 | ||||
-rw-r--r-- | src/gpg/function/GpgFileOpera.cpp | 17 | ||||
-rw-r--r-- | src/main.cpp | 3 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairDetailTab.cpp | 5 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairSubkeyTab.cpp | 9 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairUIDTab.cpp | 34 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairUIDTab.h | 8 | ||||
-rw-r--r-- | src/ui/keypair_details/KeySetExpireDateDialog.cpp | 9 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyUIDSignDialog.cpp | 19 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyUIDSignDialog.h | 8 | ||||
-rw-r--r-- | src/ui/settings/SettingsGeneral.cpp | 36 | ||||
-rw-r--r-- | src/ui/settings/SettingsGeneral.h | 22 |
13 files changed, 133 insertions, 43 deletions
diff --git a/src/gpg/GpgConstants.cpp b/src/gpg/GpgConstants.cpp index 6f1b2250..497f7e0c 100644 --- a/src/gpg/GpgConstants.cpp +++ b/src/gpg/GpgConstants.cpp @@ -145,13 +145,13 @@ std::string GpgFrontend::get_file_extension(const std::string& path) { return {}; } -std::string GpgFrontend::get_file_name_with_path(const std::string& path) { +std::string GpgFrontend::get_only_file_name_with_path(const std::string& path) { // Create a Path object from given string std::filesystem::path path_obj(path); // Check if file name in the path object has extension if (path_obj.has_filename()) { // Fetch the extension from path object and return - return path_obj.parent_path() / path_obj.filename(); + return path_obj.parent_path() / path_obj.stem(); } // In case of no extension return empty string throw std::runtime_error("invalid file path"); diff --git a/src/gpg/GpgConstants.h b/src/gpg/GpgConstants.h index 78a9a3b0..da8860e8 100644 --- a/src/gpg/GpgConstants.h +++ b/src/gpg/GpgConstants.h @@ -84,7 +84,7 @@ bool write_buffer_to_file(const std::string& path, const std::string& out_buffer); std::string get_file_extension(const std::string& path); -std::string get_file_name_with_path(const std::string& path); +std::string get_only_file_name_with_path(const std::string& path); // Check int text_is_signed(BypeArrayRef text); diff --git a/src/gpg/function/GpgFileOpera.cpp b/src/gpg/function/GpgFileOpera.cpp index b8e204b8..ae912ada 100644 --- a/src/gpg/function/GpgFileOpera.cpp +++ b/src/gpg/function/GpgFileOpera.cpp @@ -53,7 +53,7 @@ GpgFrontend::GpgError GpgFrontend::GpgFileOpera::DecryptFile( assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); - std::string out_file_name = get_file_name_with_path(path), + std::string out_file_name = get_only_file_name_with_path(path), file_extension = get_file_extension(path); if (!(file_extension == ".asc" || file_extension == ".gpg")) @@ -131,20 +131,27 @@ gpg_error_t GpgFrontend::GpgFileOpera::EncryptSignFile( gpg_error_t GpgFrontend::GpgFileOpera::DecryptVerifyFile( const std::string& path, GpgDecrResult& decr_res, GpgVerifyResult& verify_res) { + LOG(INFO) << "GpgFrontend::GpgFileOpera::DecryptVerifyFile Called"; + auto in_buffer = read_all_data_in_file(path); + + LOG(INFO) << "GpgFrontend::GpgFileOpera::DecryptVerifyFile in_buffer" + << in_buffer.size(); std::unique_ptr<std::string> out_buffer = nullptr; auto err = BasicOperator::GetInstance().DecryptVerify(in_buffer, out_buffer, decr_res, verify_res); - assert(check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR); - std::string out_file_name = get_file_name_with_path(path), + std::string out_file_name = get_only_file_name_with_path(path), file_extension = get_file_extension(path); if (!(file_extension == ".asc" || file_extension == ".gpg")) out_file_name = path + ".out"; - - write_buffer_to_file(out_file_name, *out_buffer); + LOG(INFO) << "GpgFrontend::GpgFileOpera::DecryptVerifyFile out_file_name" + << out_file_name; + if (!write_buffer_to_file(out_file_name, *out_buffer)) { + throw std::runtime_error("write_buffer_to_file error"); + }; return err; } diff --git a/src/main.cpp b/src/main.cpp index 71e517da..36f549a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,6 @@ INITIALIZE_EASYLOGGINGPP int main(int argc, char* argv[]) { - el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); Q_INIT_RESOURCE(gpgfrontend); @@ -48,7 +47,7 @@ int main(int argc, char* argv[]) { // unicode in source QTextCodec::setCodecForLocale(QTextCodec::codecForName("utf-8")); -#ifdef WINDOWS +#if (OS_PLATFORM == WINDOWS) // css QFile file(RESOURCE_DIR(qApp->applicationDirPath()) + "/css/default.qss"); file.open(QFile::ReadOnly); diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp index 3608ef63..34639cbb 100644 --- a/src/ui/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/keypair_details/KeyPairDetailTab.cpp @@ -335,14 +335,15 @@ void KeyPairDetailTab::createKeyServerOperaMenu() { SLOT(slotUpdateKeyToServer())); keyServerOperaMenu->addAction(uploadKeyPair); - // TODO Solve Refresh Problem - // keyServerOperaMenu->addAction(updateKeyPair); + keyServerOperaMenu->addAction(updateKeyPair); } void KeyPairDetailTab::slotUploadKeyToServer() { auto keys = std::make_unique<KeyIdArgsList>(); keys->push_back(mKey.id()); auto* dialog = new KeyUploadDialog(keys, this); + dialog->show(); + dialog->slotUpload(); } void KeyPairDetailTab::slotUpdateKeyToServer() { diff --git a/src/ui/keypair_details/KeyPairSubkeyTab.cpp b/src/ui/keypair_details/KeyPairSubkeyTab.cpp index a2841f50..61007b37 100644 --- a/src/ui/keypair_details/KeyPairSubkeyTab.cpp +++ b/src/ui/keypair_details/KeyPairSubkeyTab.cpp @@ -177,6 +177,12 @@ void KeyPairSubkeyTab::slotRefreshSubkeyList() { tmp4->setTextAlignment(Qt::AlignCenter); subkeyList->setItem(row, 4, tmp4); + if (!row) { + for (auto i = 0; i < subkeyList->columnCount(); i++) { + subkeyList->item(row, i)->setTextColor(QColor(65, 105, 255)); + } + } + row++; } @@ -255,7 +261,8 @@ void KeyPairSubkeyTab::createSubkeyOperaMenu() { } void KeyPairSubkeyTab::slotEditSubkey() { - LOG(INFO) << "KeyPairSubkeyTab::slotEditSubkey Fpr" << getSelectedSubkey().fpr(); + LOG(INFO) << "KeyPairSubkeyTab::slotEditSubkey Fpr" + << getSelectedSubkey().fpr(); auto dialog = new KeySetExpireDateDialog(mKey.id(), getSelectedSubkey().fpr(), this); diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp index 24461011..f787bebd 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/keypair_details/KeyPairUIDTab.cpp @@ -84,6 +84,9 @@ KeyPairUIDTab::KeyPairUIDTab(const std::string& key_id, QWidget* parent) connect(SignalStation::GetInstance(), SIGNAL(KeyDatabaseRefresh()), this, SLOT(slotRefreshKey())); + connect(this, SIGNAL(signalUpdateUIDInfo()), SignalStation::GetInstance(), + SIGNAL(KeyDatabaseRefresh())); + setLayout(vboxLayout); setAttribute(Qt::WA_DeleteOnClose, true); @@ -172,6 +175,12 @@ void KeyPairUIDTab::slotRefreshUIDList() { tmp3->setCheckState(Qt::Unchecked); uidList->setItem(row, 0, tmp3); + if (!row) { + for (auto i = 0; i < uidList->columnCount(); i++) { + uidList->item(row, i)->setTextColor(QColor(65, 105, 255)); + } + } + row++; } @@ -249,7 +258,8 @@ void KeyPairUIDTab::slotAddSign() { return; } - auto keySignDialog = new KeyUIDSignDialog(mKey, selected_uids, this); + auto keySignDialog = + new KeyUIDSignDialog(mKey, std::move(selected_uids), this); keySignDialog->show(); } @@ -318,19 +328,22 @@ void KeyPairUIDTab::slotDelUID() { tr("The action can not be undone."), QMessageBox::No | QMessageBox::Yes); - bool if_success = true; + bool if_all_success = true; if (ret == QMessageBox::Yes) { for (const auto& uid : *selected_uids) { - if (UidOperator::GetInstance().revUID(mKey, uid)) { - if_success = false; + LOG(INFO) << "KeyPairUIDTab::slotDelUID UID" << uid; + if (!UidOperator::GetInstance().revUID(mKey, uid)) { + if_all_success = false; } } - if (!if_success) { - QMessageBox::critical(nullptr, tr("Operation Failed"), - tr("An error occurred during the operation.")); + if (!if_all_success) { + QMessageBox::critical( + nullptr, tr("Operation Failed"), + tr("At least an error occurred during the operation.")); } + emit signalUpdateUIDInfo(); } } @@ -361,6 +374,8 @@ void KeyPairUIDTab::slotSetPrimaryUID() { selected_uids->front())) { QMessageBox::critical(nullptr, tr("Operation Failed"), tr("An error occurred during the operation.")); + } else { + emit signalUpdateUIDInfo(); } } } @@ -425,7 +440,8 @@ void KeyPairUIDTab::slotAddSignSingle() { return; } - auto keySignDialog = new KeyUIDSignDialog(mKey, selected_uids, this); + auto keySignDialog = + new KeyUIDSignDialog(mKey, std::move(selected_uids), this); keySignDialog->show(); } @@ -454,6 +470,8 @@ void KeyPairUIDTab::slotDelUIDSingle() { if (!UidOperator::GetInstance().revUID(mKey, selected_uids->front())) { QMessageBox::critical(nullptr, tr("Operation Failed"), tr("An error occurred during the operation.")); + } else { + emit signalUpdateUIDInfo(); } } } diff --git a/src/ui/keypair_details/KeyPairUIDTab.h b/src/ui/keypair_details/KeyPairUIDTab.h index 58d0bc2a..1f88e7b7 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.h +++ b/src/ui/keypair_details/KeyPairUIDTab.h @@ -25,11 +25,10 @@ #ifndef GPGFRONTEND_KEYPAIRUIDTAB_H #define GPGFRONTEND_KEYPAIRUIDTAB_H -#include "gpg/GpgContext.h" -#include "ui/GpgFrontendUI.h" - #include "KeyNewUIDDialog.h" #include "KeyUIDSignDialog.h" +#include "gpg/GpgContext.h" +#include "ui/GpgFrontendUI.h" namespace GpgFrontend::UI { @@ -39,6 +38,9 @@ class KeyPairUIDTab : public QWidget { public: KeyPairUIDTab(const std::string& key_id, QWidget* parent); + signals: + void signalUpdateUIDInfo(); + private: GpgKey mKey; QTableWidget* uidList{}; diff --git a/src/ui/keypair_details/KeySetExpireDateDialog.cpp b/src/ui/keypair_details/KeySetExpireDateDialog.cpp index b6e9da6c..2c5b837f 100644 --- a/src/ui/keypair_details/KeySetExpireDateDialog.cpp +++ b/src/ui/keypair_details/KeySetExpireDateDialog.cpp @@ -48,7 +48,6 @@ KeySetExpireDateDialog::KeySetExpireDateDialog(const KeyId& key_id, } void KeySetExpireDateDialog::slotConfirm() { - LOG(INFO) << "KeySetExpireDateDialog::slotConfirm Called"; std::unique_ptr<boost::gregorian::date> expires = nullptr; @@ -57,11 +56,13 @@ void KeySetExpireDateDialog::slotConfirm() { boost::posix_time::from_time_t( this->dateTimeEdit->dateTime().toTime_t()) .date()); + LOG(INFO) << "KeySetExpireDateDialog::slotConfirm" << mKey.id() << mSubkey + << *expires; + } else { + LOG(INFO) << "KeySetExpireDateDialog::slotConfirm" << mKey.id() << mSubkey + << "Non Expired"; } - LOG(INFO) << "KeySetExpireDateDialog::slotConfirm" << mKey.id() << mSubkey - << *expires; - auto err = GpgKeyOpera::GetInstance().SetExpire(mKey, mSubkey, expires); if (check_gpg_error_2_err_code(err) == GPG_ERR_NO_ERROR) { diff --git a/src/ui/keypair_details/KeyUIDSignDialog.cpp b/src/ui/keypair_details/KeyUIDSignDialog.cpp index f49a16bc..0614024f 100644 --- a/src/ui/keypair_details/KeyUIDSignDialog.cpp +++ b/src/ui/keypair_details/KeyUIDSignDialog.cpp @@ -23,15 +23,16 @@ */ #include "ui/keypair_details/KeyUIDSignDialog.h" + #include "gpg/function/GpgKeyGetter.h" #include "gpg/function/GpgKeyManager.h" +#include "ui/SignalStation.h" namespace GpgFrontend::UI { -KeyUIDSignDialog::KeyUIDSignDialog(const GpgKey& key, - const UIDArgsListPtr& uid, +KeyUIDSignDialog::KeyUIDSignDialog(const GpgKey& key, UIDArgsListPtr uid, QWidget* parent) - : mKey(key), mUids(uid), QDialog(parent) { + : QDialog(parent), mUids(std::move(uid)), mKey(key) { mKeyList = new KeyList(KeyListRow::ONLY_SECRET_KEY, KeyListColumn::NAME | KeyListColumn::EmailAddress, this); @@ -90,18 +91,26 @@ KeyUIDSignDialog::KeyUIDSignDialog(const GpgKey& key, this->adjustSize(); setAttribute(Qt::WA_DeleteOnClose, true); + + connect(this, SIGNAL(signalKeyUIDSignUpdate()), SignalStation::GetInstance(), + SIGNAL(KeyDatabaseRefresh())); } void KeyUIDSignDialog::slotSignKey(bool clicked) { + LOG(INFO) << "KeyUIDSignDialog::slotSignKey Called"; + // Set Signers auto key_ids = mKeyList->getChecked(); - auto keys = GpgKeyGetter::GetInstance().GetKeys(std::move(key_ids)); + auto keys = GpgKeyGetter::GetInstance().GetKeys(key_ids); + LOG(INFO) << "KeyUIDSignDialog::slotSignKey Key Info Got"; auto expires = std::make_unique<boost::gregorian::date>( boost::posix_time::from_time_t(expiresEdit->dateTime().toTime_t()) .date()); + LOG(INFO) << "KeyUIDSignDialog::slotSignKey Sign Start"; for (const auto& uid : *mUids) { + LOG(INFO) << "KeyUIDSignDialog::slotSignKey Sign UID" << uid; // Sign For mKey if (!GpgKeyManager::GetInstance().signKey(mKey, *keys, uid, expires)) { QMessageBox::critical( @@ -114,8 +123,8 @@ void KeyUIDSignDialog::slotSignKey(bool clicked) { QMessageBox::information( nullptr, tr("Operation Complete"), tr("The signature operation of the UID is complete")); - this->close(); + emit signalKeyUIDSignUpdate(); } } // namespace GpgFrontend::UI diff --git a/src/ui/keypair_details/KeyUIDSignDialog.h b/src/ui/keypair_details/KeyUIDSignDialog.h index cd35c4e6..1bd68416 100644 --- a/src/ui/keypair_details/KeyUIDSignDialog.h +++ b/src/ui/keypair_details/KeyUIDSignDialog.h @@ -35,10 +35,12 @@ class KeyUIDSignDialog : public QDialog { Q_OBJECT public: - explicit KeyUIDSignDialog(const GpgKey& key, - const UIDArgsListPtr& uid, + explicit KeyUIDSignDialog(const GpgKey& key, UIDArgsListPtr uid, QWidget* parent = nullptr); + signals: + void signalKeyUIDSignUpdate(); + private: KeyList* mKeyList; @@ -48,7 +50,7 @@ class KeyUIDSignDialog : public QDialog { QCheckBox* nonExpireCheck; - const UIDArgsListPtr& mUids; + UIDArgsListPtr mUids; const GpgKey& mKey; diff --git a/src/ui/settings/SettingsGeneral.cpp b/src/ui/settings/SettingsGeneral.cpp index 8ecb2213..f5a98282 100644 --- a/src/ui/settings/SettingsGeneral.cpp +++ b/src/ui/settings/SettingsGeneral.cpp @@ -40,6 +40,8 @@ GeneralTab::GeneralTab(QWidget* parent) appPath(qApp->applicationDirPath()), settings(RESOURCE_DIR(appPath) + "/conf/gpgfrontend.ini", QSettings::IniFormat) { +#ifdef SERVER_SUPPORT + /***************************************** * GpgFrontend Server *****************************************/ @@ -51,6 +53,7 @@ GeneralTab::GeneralTab(QWidget* parent) tr("Server that provides short key and key exchange services"))); serverBox->setLayout(serverBoxLayout); +#endif /***************************************** * Save-Checked-Keys-Box @@ -74,6 +77,7 @@ GeneralTab::GeneralTab(QWidget* parent) importConfirmationBoxLayout->addWidget(importConfirmationCheckBox); importConfirmationBox->setLayout(importConfirmationBoxLayout); +#ifdef MULT_LANGUAGE_SUPPORT /***************************************** * Language Select Box *****************************************/ @@ -93,7 +97,9 @@ GeneralTab::GeneralTab(QWidget* parent) langBox->setLayout(langBoxLayout); connect(langSelectBox, SIGNAL(currentIndexChanged(int)), this, SLOT(slotLanguageChanged())); +#endif +#ifdef SERVER_SUPPORT /***************************************** * Own Key Select Box *****************************************/ @@ -106,6 +112,7 @@ GeneralTab::GeneralTab(QWidget* parent) serviceTokenLabel->setAlignment(Qt::AlignCenter); ownKeyBox->setLayout(ownKeyBoxLayout); + mKeyList = new KeyList(); // Fill the keyid hashmap @@ -135,15 +142,23 @@ GeneralTab::GeneralTab(QWidget* parent) ownKeyServiceTokenLayout->addWidget(serviceTokenLabel); ownKeyServiceTokenLayout->stretch(0); +#endif + /***************************************** * Mainlayout *****************************************/ auto* mainLayout = new QVBoxLayout; +#ifdef SERVER_SUPPORT mainLayout->addWidget(serverBox); +#endif mainLayout->addWidget(saveCheckedKeysBox); mainLayout->addWidget(importConfirmationBox); +#ifdef MULT_LANGUAGE_SUPPORT mainLayout->addWidget(langBox); +#endif +#ifdef SERVER_SUPPORT mainLayout->addWidget(ownKeyBox); +#endif setSettings(); mainLayout->addStretch(1); @@ -161,6 +176,7 @@ void GeneralTab::setSettings() { saveCheckedKeysCheckBox->setCheckState(Qt::Checked); } +#ifdef SERVER_SUPPORT auto serverList = settings.value("general/gpgfrontendServerList").toStringList(); if (serverList.empty()) { @@ -181,6 +197,9 @@ void GeneralTab::setSettings() { [&](const QString& current) -> void { settings.setValue("general/currentGpgfrontendServer", current); }); +#endif + +#ifdef MULT_LANGUAGE_SUPPORT // Language setting QString langKey = settings.value("int/lang").toString(); @@ -189,6 +208,10 @@ void GeneralTab::setSettings() { langSelectBox->setCurrentIndex(langSelectBox->findText(langValue)); } +#endif + +#ifdef SERVER_SUPPORT + auto own_key_id = settings.value("general/ownKeyId").toString().toStdString(); if (own_key_id.empty()) { ownKeySelectBox->setCurrentText("<none>"); @@ -203,6 +226,8 @@ void GeneralTab::setSettings() { serviceTokenLabel->setText(QString::fromStdString(serviceToken)); } +#endif + // Get own key information from keydb/gpg.conf (if contained) if (settings.value("general/confirmImportKeys", Qt::Checked).toBool()) { importConfirmationCheckBox->setCheckState(Qt::Checked); @@ -216,7 +241,7 @@ void GeneralTab::setSettings() { void GeneralTab::applySettings() { settings.setValue("keys/saveKeyChecked", saveCheckedKeysCheckBox->isChecked()); - +#ifdef SERVER_SUPPORT qDebug() << "serverSelectBox currentText" << serverSelectBox->currentText(); settings.setValue("general/currentGpgfrontendServer", serverSelectBox->currentText()); @@ -226,27 +251,36 @@ void GeneralTab::applySettings() { serverList->append(serverSelectBox->itemText(i)); settings.setValue("general/gpgfrontendServerList", *serverList); delete serverList; +#endif +#ifdef MULT_LANGUAGE_SUPPORT settings.setValue("int/lang", lang.key(langSelectBox->currentText())); +#endif +#ifdef SERVER_SUPPORT settings.setValue( "general/ownKeyId", QString::fromStdString(keyIdsList[ownKeySelectBox->currentIndex()])); settings.setValue("general/serviceToken", QString::fromStdString(serviceToken)); +#endif settings.setValue("general/confirmImportKeys", importConfirmationCheckBox->isChecked()); } +#ifdef MULT_LANGUAGE_SUPPORT void GeneralTab::slotLanguageChanged() { emit signalRestartNeeded(true); } +#endif +#ifdef SERVER_SUPPORT void GeneralTab::slotOwnKeyIdChanged() { // Set ownKeyId to currently selected this->serviceTokenLabel->setText(tr("No Service Token Found")); serviceToken.clear(); } +#endif #ifdef SERVER_SUPPORT void GeneralTab::slotGetServiceToken() { diff --git a/src/ui/settings/SettingsGeneral.h b/src/ui/settings/SettingsGeneral.h index ea4061e7..cc61d8bc 100644 --- a/src/ui/settings/SettingsGeneral.h +++ b/src/ui/settings/SettingsGeneral.h @@ -44,25 +44,35 @@ class GeneralTab : public QWidget { QString appPath; QSettings settings; - QComboBox* serverSelectBox; QCheckBox* saveCheckedKeysCheckBox; QCheckBox* importConfirmationCheckBox; + +#ifdef MULT_LANGUAGE_SUPPORT QComboBox* langSelectBox; + QHash<QString, QString> lang; +#endif + +#ifdef SERVER_SUPPORT + QComboBox* serverSelectBox; QComboBox* ownKeySelectBox; QPushButton* getServiceTokenButton; QLabel* serviceTokenLabel; - QHash<QString, QString> lang; - + std::string serviceToken; std::unordered_map<std::string, std::string> keyIds; +#endif + std::vector<std::string> keyIdsList; - std::string serviceToken; - KeyList* mKeyList; - private slots: + KeyList* mKeyList{}; + private slots: +#ifdef MULT_LANGUAGE_SUPPORT void slotOwnKeyIdChanged(); +#endif +#ifdef SERVER_SUPPORT void slotLanguageChanged(); +#endif signals: |