diff options
author | Saturn&Eric <[email protected]> | 2021-07-19 20:13:05 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-07-19 20:13:05 +0000 |
commit | 837e9748bb6bc5b3255b0475b8bbb3106e061b9c (patch) | |
tree | 67acd04b79d0ce779fc2ade5bb3e43a872f660cd /src | |
parent | Merge pull request #13 from saturneric/develop (diff) | |
parent | Add multi-language support. (diff) | |
download | GpgFrontend-1.2.2.tar.gz GpgFrontend-1.2.2.zip |
Merge pull request #14 from saturneric/developv1.2.2
Version 1.2.2
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/MainWindow.cpp | 2 | ||||
-rw-r--r-- | src/gpg/GpgContext.cpp | 73 | ||||
-rwxr-xr-x | src/ui/KeyMgmt.cpp | 2 | ||||
-rw-r--r-- | src/ui/KeyServerImportDialog.cpp | 10 | ||||
-rwxr-xr-x | src/ui/SettingsDialog.cpp | 4 | ||||
-rw-r--r-- | src/ui/help/AboutDialog.cpp | 7 | ||||
-rw-r--r-- | src/ui/help/VersionCheckThread.cpp | 5 | ||||
-rw-r--r-- | src/ui/keygen/KeygenDialog.cpp | 2 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairDetailTab.cpp | 80 | ||||
-rw-r--r-- | src/ui/keypair_details/KeyPairUIDTab.cpp | 4 | ||||
-rw-r--r-- | src/ui/main_window/MainWindowSlotFunction.cpp | 2 | ||||
-rw-r--r-- | src/ui/widgets/FilePage.cpp | 33 | ||||
-rw-r--r-- | src/ui/widgets/InfoBoardWidget.cpp | 2 | ||||
-rw-r--r-- | src/ui/widgets/TextEdit.cpp | 2 |
15 files changed, 170 insertions, 62 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 03eaac9e..3b225a09 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,7 +36,9 @@ message(STATUS "RESOURCE_OUTPUT_DIRECTORY ${RESOURCE_OUTPUT_DIRECTORY}") file(GLOB_RECURSE ALL_SOURCE_FILES RELACTIVE ${CMAKE_SOURCE_DIR}/src/*.cpp) # Set Translation Files -set(QT_TS_FILES gpgfrontend_en_us.ts gpgfrontend_zh_chs.ts gpgfrontend_zh_cht.ts gpg_frontend_fr.ts gpg_frontend_ru.ts) +set(QT_TS_FILES + gpgfrontend_en_us.ts gpgfrontend_zh_cn.ts + gpgfrontend_fr.ts gpgfrontend_ru.ts gpgfrontend_es.ts) list(TRANSFORM QT_TS_FILES PREPEND ${CMAKE_SOURCE_DIR}/resource/ts/) message(STATUS "QT_TS_FILES ${QT_TS_FILES}") set(QT_QM_FILES_OUTPUT_DIR ${RESOURCE_OUTPUT_DIRECTORY}/ts) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 08433da9..eb8b96b1 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -32,7 +32,7 @@ MainWindow::MainWindow() networkAccessManager = new QNetworkAccessManager(this); - auto waitingDialog = new WaitingDialog("Loading Gnupg", this); + auto waitingDialog = new WaitingDialog(tr("Loading Gnupg"), this); // Init Gnupg auto ctx_thread = QThread::create([&]() { mCtx = new GpgME::GpgContext(); }); diff --git a/src/gpg/GpgContext.cpp b/src/gpg/GpgContext.cpp index 7ec521a7..0462433d 100644 --- a/src/gpg/GpgContext.cpp +++ b/src/gpg/GpgContext.cpp @@ -24,6 +24,7 @@ #include "gpg/GpgContext.h" +#include <functional> #include <unistd.h> /* contains read/write */ #ifdef _WIN32 @@ -72,8 +73,10 @@ namespace GpgME { << engineInfo->home_dir << engineInfo->version; if (engineInfo->protocol == GPGME_PROTOCOL_GPGCONF && strcmp(engineInfo->version, "1.0.0") != 0) find_gpgconf = true; - if (engineInfo->protocol == GPGME_PROTOCOL_OpenPGP && strcmp(engineInfo->version, "1.0.0") != 0) + if (engineInfo->protocol == GPGME_PROTOCOL_OpenPGP && strcmp(engineInfo->version, "1.0.0") != 0) { + gpgExec = engineInfo->file_name; find_openpgp = true; + } if (engineInfo->protocol == GPGME_PROTOCOL_CMS && strcmp(engineInfo->version, "1.0.0") != 0) find_cms = true; if (engineInfo->protocol == GPGME_PROTOCOL_ASSUAN) @@ -625,20 +628,31 @@ namespace GpgME { } /** return type should be gpgme_error_t*/ - void GpgContext::executeGpgCommand(const QStringList &arguments, QByteArray *stdOut, QByteArray *stdErr) { + QProcess * GpgContext::executeGpgCommand(const QStringList &arguments, QByteArray *stdOut, QByteArray *stdErr, + const std::function<void(QProcess *)> &interactFunc) { QStringList args; - args << "--homedir" << gpgKeys << "--batch" << arguments; + args << arguments; + + auto *gpgProcess = new QProcess(this); + qDebug() << "gpgExec" << gpgExec << args; - qDebug() << args; - QProcess gpg; - // qDebug() << "engine->file_name" << engine->file_name; + gpgProcess->setReadChannel(QProcess::StandardOutput); + connect(gpgProcess, SIGNAL(finished(int,QProcess::ExitStatus)), + gpgProcess, SLOT(deleteLater())); + connect(gpgProcess, &QProcess::readyReadStandardOutput, this, [gpgProcess, interactFunc]() { + qDebug() << "Function Called" << &gpgProcess; + // interactFunc(gpgProcess); + }); - gpg.start(gpgBin, args); - gpg.waitForFinished(); + gpgProcess->start(gpgExec, args); - *stdOut = gpg.readAllStandardOutput(); - *stdErr = gpg.readAllStandardError(); - qDebug() << *stdOut; + if (gpgProcess->waitForStarted()){ + qDebug() << "Gpg Process Started Success"; + } else { + qDebug() << "Gpg Process Started Failed"; + } + + return gpgProcess; } /*** @@ -1180,4 +1194,41 @@ namespace GpgME { } return true; } + + QProcess * GpgContext::generateRevokeCert(const GpgKey &key, const QString &outputFileName) { + QByteArray out, stdErr; + auto process = executeGpgCommand({ + "--command-fd", + "0", + "--status-fd", "1", + "-o", + outputFileName, + "--gen-revoke", + key.fpr + }, &out, &stdErr, + [](QProcess *proc) { + qDebug() << "Function Called" << proc; + while (proc->canReadLine()) { + const QString line = QString::fromUtf8(proc->readLine()).trimmed(); + // Command-fd is a stable interface, while this is all kind of hacky we + // are on a deadline :-/ + if (line == QLatin1String("[GNUPG:] GET_BOOL gen_revoke.okay")) { + proc->write("y\n"); + } else if (line == QLatin1String("[GNUPG:] GET_LINE ask_revocation_reason.code")) { + proc->write("0\n"); + } else if (line == QLatin1String("[GNUPG:] GET_LINE ask_revocation_reason.text")) { + proc->write("\n"); + } else if (line == QLatin1String("[GNUPG:] GET_BOOL openfile.overwrite.okay")) { + // We asked before + proc->write("y\n"); + } else if (line == QLatin1String("[GNUPG:] GET_BOOL ask_revocation_reason.okay")) { + proc->write("y\n"); + } + } + }); + + qDebug() << "GenerateRevokeCert Process" << process; + + return process; + } } diff --git a/src/ui/KeyMgmt.cpp b/src/ui/KeyMgmt.cpp index 0e2d9c9a..ce5343bf 100755 --- a/src/ui/KeyMgmt.cpp +++ b/src/ui/KeyMgmt.cpp @@ -78,7 +78,7 @@ KeyMgmt::KeyMgmt(GpgME::GpgContext *ctx, QWidget *parent ) : this->settings.setValue("keymgmt/setWindowSize", true); } - setWindowTitle(tr("KeyPairs Management")); + setWindowTitle(tr("Key Pair Management")); mKeyList->addMenuAction(deleteSelectedKeysAct); mKeyList->addMenuAction(showKeyDetailsAct); } diff --git a/src/ui/KeyServerImportDialog.cpp b/src/ui/KeyServerImportDialog.cpp index ec740691..a1355120 100644 --- a/src/ui/KeyServerImportDialog.cpp +++ b/src/ui/KeyServerImportDialog.cpp @@ -176,7 +176,7 @@ void KeyServerImportDialog::setMessage(const QString &text, bool error) { void KeyServerImportDialog::slotSearch() { if (searchLineEdit->text().isEmpty()) { - setMessage(tr("<h4>Text is empty.</h4>"), false); + setMessage("<h4>" + tr("Text is empty.") + "</h4>", false); return; } @@ -227,23 +227,23 @@ void KeyServerImportDialog::slotSearchFinished() { if (firstLine.contains("Error")) { QString text = QString(reply->readLine(1024)); if (text.contains("Too many responses")) { - setMessage(tr("<h4>CToo many responses from keyserver!</h4>"), true); + setMessage("<h4>" +tr("Too many responses from keyserver!") + "</h4>", true); return; } else if (text.contains("No keys found")) { // if string looks like hex string, search again with 0x prepended QRegExp rx("[0-9A-Fa-f]*"); QString query = searchLineEdit->text(); if (rx.exactMatch(query)) { - setMessage(tr("<h4>No keys found, input may be kexId, retrying search with 0x.</h4>"), true); + setMessage("<h4>" + tr("No keys found, input may be kexId, retrying search with 0x.") + "</h4>", true); searchLineEdit->setText(query.prepend("0x")); this->slotSearch(); return; } else { - setMessage(tr("<h4>No keys found containing the search string!</h4>"), true); + setMessage("<h4>" +tr("No keys found containing the search string!") + "</h4>", true); return; } } else if (text.contains("Insufficiently specific words")) { - setMessage(tr("<h4>Insufficiently specific search string!</h4>"), true); + setMessage("<h4>" + tr("Insufficiently specific search string!") + "</h4>", true); return; } else { setMessage(text, true); diff --git a/src/ui/SettingsDialog.cpp b/src/ui/SettingsDialog.cpp index d0a107c4..1732d718 100755 --- a/src/ui/SettingsDialog.cpp +++ b/src/ui/SettingsDialog.cpp @@ -498,7 +498,7 @@ AppearanceTab::AppearanceTab(QWidget *parent) infoBoardFontSizeSpin->setRange(9, 18); infoBoardFontSizeSpin->setValue(10); infoBoardFontSizeSpin->setSingleStep(1); - infoBoardLayout->addWidget(new QLabel(" Front Size")); + infoBoardLayout->addWidget(new QLabel(tr(" Front Size"))); infoBoardLayout->addWidget(infoBoardFontSizeSpin); infoBoardBox->setLayout(infoBoardLayout); @@ -604,7 +604,7 @@ KeyserverTab::KeyserverTab(QWidget *parent) auto *mainLayout = new QVBoxLayout(this); - auto *label = new QLabel(tr("Default Keyserver for import:")); + auto *label = new QLabel(tr("Default Key Server for import:")); comboBox = new QComboBox; comboBox->setEditable(false); comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); diff --git a/src/ui/help/AboutDialog.cpp b/src/ui/help/AboutDialog.cpp index 4c9b54c9..807c509d 100644 --- a/src/ui/help/AboutDialog.cpp +++ b/src/ui/help/AboutDialog.cpp @@ -181,6 +181,13 @@ void UpdateTab::getLatestVersion() { this->pb->setHidden(true); + if(replay->error() != QNetworkReply::NoError) { + qDebug() << "VersionCheckThread Found Network Error"; + auto latestVersion = "Unknown"; + latestVersionLabel->setText("<center><b>" + tr("Latest Version From Github: ") + latestVersion + "</b></center>"); + return; + } + QByteArray bytes = replay->readAll(); Document d; diff --git a/src/ui/help/VersionCheckThread.cpp b/src/ui/help/VersionCheckThread.cpp index 7bd0eb8f..c7c77d1c 100644 --- a/src/ui/help/VersionCheckThread.cpp +++ b/src/ui/help/VersionCheckThread.cpp @@ -20,6 +20,11 @@ void VersionCheckThread::run() { QApplication::processEvents(); } + if(mNetworkReply->error() != QNetworkReply::NoError) { + qDebug() << "VersionCheckThread Found Network Error"; + return; + } + QByteArray bytes = mNetworkReply->readAll(); Document d; diff --git a/src/ui/keygen/KeygenDialog.cpp b/src/ui/keygen/KeygenDialog.cpp index 8637a643..7991ddd1 100644 --- a/src/ui/keygen/KeygenDialog.cpp +++ b/src/ui/keygen/KeygenDialog.cpp @@ -147,7 +147,7 @@ QGroupBox *KeyGenDialog::create_key_usage_group_box() { auto *groupBox = new QGroupBox(this); auto *grid = new QGridLayout(this); - groupBox->setTitle("Key Usage"); + groupBox->setTitle(tr("Key Usage")); auto* encrypt = new QCheckBox(tr("Encryption"), groupBox); encrypt->setTristate(false); diff --git a/src/ui/keypair_details/KeyPairDetailTab.cpp b/src/ui/keypair_details/KeyPairDetailTab.cpp index f2a3e613..9ca4e37e 100644 --- a/src/ui/keypair_details/KeyPairDetailTab.cpp +++ b/src/ui/keypair_details/KeyPairDetailTab.cpp @@ -23,8 +23,10 @@ */ #include "ui/keypair_details/KeyPairDetailTab.h" +#include "ui/WaitingDialog.h" -KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, QWidget *parent) : mKey(mKey), QWidget(parent) { +KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, QWidget *parent) : mKey(mKey), + QWidget(parent) { mCtx = ctx; keyid = new QString(mKey.id); @@ -53,8 +55,8 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q algorithmVarLabel = new QLabel(); // Show the situation that master key not exists. - masterKeyExistVarLabel = new QLabel(mKey.has_master_key ? "Exists" : "Not Exists"); - if(!mKey.has_master_key){ + masterKeyExistVarLabel = new QLabel(mKey.has_master_key ? tr("Exists") : tr("Not Exists")); + if (!mKey.has_master_key) { auto paletteExpired = masterKeyExistVarLabel->palette(); paletteExpired.setColor(masterKeyExistVarLabel->foregroundRole(), Qt::red); masterKeyExistVarLabel->setPalette(paletteExpired); @@ -64,7 +66,7 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q masterKeyExistVarLabel->setPalette(paletteValid); } - if(mKey.expired){ + if (mKey.expired) { auto paletteExpired = expireVarLabel->palette(); paletteExpired.setColor(expireVarLabel->foregroundRole(), Qt::red); expireVarLabel->setPalette(paletteExpired); @@ -131,18 +133,27 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q auto *privKeyBox = new QGroupBox(tr("Operations")); auto *vboxPK = new QVBoxLayout(); - auto *exportButton = new QPushButton(tr("Export Private Key (Include Subkeys)")); + auto *exportButton = new QPushButton(tr("Export Private Key (Include Subkey)")); vboxPK->addWidget(exportButton); connect(exportButton, SIGNAL(clicked()), this, SLOT(slotExportPrivateKey())); - if(mKey.has_master_key) { + if (mKey.has_master_key) { auto *editExpiresButton = new QPushButton(tr("Modify Expiration Datetime (Master Key)")); vboxPK->addWidget(editExpiresButton); connect(editExpiresButton, SIGNAL(clicked()), this, SLOT(slotModifyEditDatetime())); + auto hBoxLayout = new QHBoxLayout(); auto *keyServerOperaButton = new QPushButton(tr("Key Server Operation (Pubkey)")); keyServerOperaButton->setStyleSheet("text-align:center;"); - vboxPK->addWidget(keyServerOperaButton); + + auto *revokeCertGenButton = new QPushButton(tr("Generate Revoke Certificate")); + revokeCertGenButton->setDisabled(true); + connect(revokeCertGenButton, SIGNAL(clicked()), this, SLOT(slotGenRevokeCert())); + + hBoxLayout->addWidget(keyServerOperaButton); + hBoxLayout->addWidget(revokeCertGenButton); + + vboxPK->addLayout(hBoxLayout); connect(keyServerOperaButton, SIGNAL(clicked()), this, SLOT(slotModifyEditDatetime())); // Set Menu @@ -167,7 +178,7 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q expLabel->setText(tr("Warning: The Master Key has been revoked")); } - iconLabel->setPixmap(pixmap.scaled(24,24,Qt::KeepAspectRatio)); + iconLabel->setPixmap(pixmap.scaled(24, 24, Qt::KeepAspectRatio)); QFont font = expLabel->font(); font.setBold(true); expLabel->setFont(font); @@ -189,22 +200,23 @@ KeyPairDetailTab::KeyPairDetailTab(GpgME::GpgContext *ctx, const GpgKey &mKey, Q void KeyPairDetailTab::slotExportPrivateKey() { // Show a information box with explanation about private key int ret = QMessageBox::information(this, tr("Exporting private Key"), - tr("<h3>You are about to export your <font color=\"red\">PRIVATE KEY</font>!</h3>\n" - "This is NOT your Public Key, so DON'T give it away.<br />" - "Do you REALLY want to export your PRIVATE KEY?"), + "<h3>" + tr("You are about to export your") + "<font color=\"red\">" + + tr("PRIVATE KEY") + "</font>!</h3>\n" + + tr("This is NOT your Public Key, so DON'T give it away.") + "<br />" + + tr("Do you REALLY want to export your PRIVATE KEY?"), QMessageBox::Cancel | QMessageBox::Ok); // export key, if ok was clicked if (ret == QMessageBox::Ok) { auto *keyArray = new QByteArray(); - if(!mCtx->exportSecretKey(mKey, keyArray)) { - QMessageBox::critical(this, "Error", "An error occurred during the export operation."); - return; - } + if (!mCtx->exportSecretKey(mKey, keyArray)) { + QMessageBox::critical(this, "Error", "An error occurred during the export operation."); + return; + } auto &key = mCtx->getKeyById(*keyid); - QString fileString = key.name + " " +key.email + "(" + + QString fileString = key.name + " " + key.email + "(" + key.id + ")_secret.asc"; QString fileName = QFileDialog::getSaveFileName(this, tr("Export Key To File"), fileString, tr("Key Files") + " (*.asc *.txt);;All Files (*)"); @@ -250,13 +262,13 @@ void KeyPairDetailTab::slotRefreshKeyInfo() { QString usage; QTextStream usage_steam(&usage); - if(mKey.can_certify) + if (mKey.can_certify) usage_steam << "Cert "; - if(mKey.can_encrypt) + if (mKey.can_encrypt) usage_steam << "Encr "; - if(mKey.can_sign) + if (mKey.can_sign) usage_steam << "Sign "; - if(mKey.can_authenticate) + if (mKey.can_authenticate) usage_steam << "Auth "; usageVarLabel->setText(usage); @@ -264,13 +276,13 @@ void KeyPairDetailTab::slotRefreshKeyInfo() { QString actualUsage; QTextStream actual_usage_steam(&actualUsage); - if(GpgME::GpgContext::checkIfKeyCanCert(mKey)) + if (GpgME::GpgContext::checkIfKeyCanCert(mKey)) actual_usage_steam << "Cert "; - if(GpgME::GpgContext::checkIfKeyCanEncr(mKey)) + if (GpgME::GpgContext::checkIfKeyCanEncr(mKey)) actual_usage_steam << "Encr "; - if(GpgME::GpgContext::checkIfKeyCanSign(mKey)) + if (GpgME::GpgContext::checkIfKeyCanSign(mKey)) actual_usage_steam << "Sign "; - if(GpgME::GpgContext::checkIfKeyCanAuth(mKey)) + if (GpgME::GpgContext::checkIfKeyCanAuth(mKey)) actual_usage_steam << "Auth "; actualUsageVarLabel->setText(actualUsage); @@ -300,7 +312,7 @@ void KeyPairDetailTab::slotRefreshKeyInfo() { void KeyPairDetailTab::createKeyServerOperaMenu() { keyServerOperaMenu = new QMenu(this); - auto *uploadKeyPair = new QAction(tr("Upload Key Pair"), this); + auto *uploadKeyPair = new QAction(tr("Upload Key Pair to Key Server"), this); connect(uploadKeyPair, SIGNAL(triggered()), this, SLOT(slotUploadKeyToServer())); auto *updateKeyPair = new QAction(tr("Update Key Pair"), this); connect(updateKeyPair, SIGNAL(triggered()), this, SLOT(slotUpdateKeyToServer())); @@ -324,3 +336,21 @@ void KeyPairDetailTab::slotUpdateKeyToServer() { dialog->slotImportKey(keys); } +void KeyPairDetailTab::slotGenRevokeCert() { + auto mOutputFileName = QFileDialog::getSaveFileName(this, tr("Generate revocation certificate"), + QString(), + QStringLiteral("%1 (*.rev)").arg( + tr("Revocation Certificates"))); + + auto process = mCtx->generateRevokeCert(mKey, mOutputFileName); + + auto *dialog = new WaitingDialog("Generating", this); + + while (process->state() == QProcess::Running) { + QApplication::processEvents(); + } + + dialog->close(); + +} + diff --git a/src/ui/keypair_details/KeyPairUIDTab.cpp b/src/ui/keypair_details/KeyPairUIDTab.cpp index 2a84cef4..2954aadb 100644 --- a/src/ui/keypair_details/KeyPairUIDTab.cpp +++ b/src/ui/keypair_details/KeyPairUIDTab.cpp @@ -56,7 +56,7 @@ KeyPairUIDTab::KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget auto uidGroupBox = new QGroupBox(); uidGroupBox->setLayout(gridLayout); - uidGroupBox->setTitle("UIDs"); + uidGroupBox->setTitle(tr("UIDs")); auto signGridLayout = new QGridLayout(); signGridLayout->addWidget(sigList, 0, 0); @@ -64,7 +64,7 @@ KeyPairUIDTab::KeyPairUIDTab(GpgME::GpgContext *ctx, const GpgKey &key, QWidget auto signGroupBox = new QGroupBox(); signGroupBox->setLayout(signGridLayout); - signGroupBox->setTitle("Signature of Selected UID"); + signGroupBox->setTitle(tr("Signature of Selected UID")); auto vboxLayout = new QVBoxLayout(); vboxLayout->addWidget(uidGroupBox); diff --git a/src/ui/main_window/MainWindowSlotFunction.cpp b/src/ui/main_window/MainWindowSlotFunction.cpp index 8a4b786e..4bcee080 100644 --- a/src/ui/main_window/MainWindowSlotFunction.cpp +++ b/src/ui/main_window/MainWindowSlotFunction.cpp @@ -398,7 +398,7 @@ void MainWindow::slotDecryptVerify() { connect(thread, SIGNAL(finished(QPrivateSignal)), thread, SLOT(deleteLater())); thread->start(); - WaitingDialog *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this); + auto *dialog = new WaitingDialog(tr("Decrypting and Verifying"), this); while (thread->isRunning()) { QApplication::processEvents(); } diff --git a/src/ui/widgets/FilePage.cpp b/src/ui/widgets/FilePage.cpp index 65755509..b9602d58 100644 --- a/src/ui/widgets/FilePage.cpp +++ b/src/ui/widgets/FilePage.cpp @@ -105,17 +105,22 @@ FilePage::FilePage(QWidget *parent) : QWidget(parent) { } void FilePage::fileTreeViewItemClicked(const QModelIndex &index) { - mPath = dirModel->fileInfo(index).absoluteFilePath(); - qDebug() << "mPath" << mPath; + selectedPath = dirModel->fileInfo(index).absoluteFilePath(); + qDebug() << "selectedPath" << selectedPath; } void FilePage::slotUpLevel() { QModelIndex currentRoot = dirTreeView->rootIndex(); - mPath = dirModel->fileInfo(currentRoot.parent()).absoluteFilePath(); - auto fileInfo = QFileInfo(mPath); + + mPath = dirModel->fileInfo(currentRoot).absoluteFilePath(); + QDir dir(mPath); + dir.makeAbsolute(); + dir.setPath(QDir::cleanPath(dir.filePath(QStringLiteral("..")))); + mPath = dir.absolutePath(); + auto fileInfo = QFileInfo(dir.absolutePath()); if(fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) { - dirTreeView->setRootIndex(currentRoot.parent()); pathEdit->setText(mPath); + slotGoPath(); } qDebug() << "Current Root mPath" << mPath; emit pathChanged(mPath); @@ -124,8 +129,9 @@ void FilePage::slotUpLevel() { void FilePage::fileTreeViewItemDoubleClicked(const QModelIndex &index) { mPath = dirModel->fileInfo(index).absoluteFilePath(); auto fileInfo = QFileInfo(mPath); + auto targetModelIndex = dirTreeView->model()->index(index.row(), 0, index.parent()); if(fileInfo.isDir() && fileInfo.isReadable() && fileInfo.isExecutable()) { - dirTreeView->setRootIndex(index); + dirTreeView->setRootIndex(targetModelIndex); pathEdit->setText(mPath); } qDebug() << "Index mPath" << mPath; @@ -133,7 +139,7 @@ void FilePage::fileTreeViewItemDoubleClicked(const QModelIndex &index) { } QString FilePage::getSelected() const { - return mPath; + return selectedPath; } void FilePage::slotGoPath() { @@ -177,10 +183,10 @@ void FilePage::createPopupMenu() { void FilePage::onCustomContextMenu(const QPoint &point) { QModelIndex index = dirTreeView->indexAt(point); - mPath = dirModel->fileInfo(index).absoluteFilePath(); - qDebug() << "Right Click" << mPath; + selectedPath = dirModel->fileInfo(index).absoluteFilePath(); + qDebug() << "Right Click" << selectedPath; if (index.isValid()) { - QFileInfo info(mPath); + QFileInfo info(selectedPath); encryptItemAct->setEnabled(info.isFile() && (info.suffix() != "gpg" && info.suffix() != "sig")); decryptItemAct->setEnabled(info.isFile() && info.suffix() == "gpg"); signItemAct->setEnabled(info.isFile() && (info.suffix() != "gpg" && info.suffix() != "sig")); @@ -252,3 +258,10 @@ void FilePage::slotVerifyItem() { if(mainWindow != nullptr) mainWindow->slotFileVerify(); } + +void FilePage::keyPressEvent(QKeyEvent *event) { + qDebug() << "Key Press" << event->key(); + if(event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) { + slotGoPath(); + } +} diff --git a/src/ui/widgets/InfoBoardWidget.cpp b/src/ui/widgets/InfoBoardWidget.cpp index fb1e55d5..f26917a4 100644 --- a/src/ui/widgets/InfoBoardWidget.cpp +++ b/src/ui/widgets/InfoBoardWidget.cpp @@ -54,7 +54,7 @@ InfoBoardWidget::InfoBoardWidget(QWidget *parent, GpgME::GpgContext *ctx, KeyLis actionButtonLayout->setSpacing(0); actionButtonMenu->setLayout(actionButtonLayout); - auto label = new QLabel("Optional Actions Menu"); + auto label = new QLabel(tr("Optional Actions Menu")); label->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); label->setContentsMargins(0, 0, 0, 0); diff --git a/src/ui/widgets/TextEdit.cpp b/src/ui/widgets/TextEdit.cpp index c9968565..eab0f799 100644 --- a/src/ui/widgets/TextEdit.cpp +++ b/src/ui/widgets/TextEdit.cpp @@ -637,7 +637,7 @@ void TextEdit::slotFilePagePathChanged(const QString &path) { int index = tabWidget->currentIndex(); QString mPath; QFileInfo fileInfo(path); - QString tPath = fileInfo.path(); + QString tPath = fileInfo.absoluteFilePath(); if (path.size() > 18) { mPath = tPath.mid(tPath.size() - 18, 18).prepend("..."); } else { |