diff options
author | Ubbo Veentjer <[email protected]> | 2017-12-31 00:32:47 +0000 |
---|---|---|
committer | Ubbo Veentjer <[email protected]> | 2017-12-31 00:32:47 +0000 |
commit | 5c7dfbe981005580f667b66557b541ce011ae5d3 (patch) | |
tree | ce27f24e9dea7c8cd45e64ea5eef570e98743599 | |
parent | fix npe (diff) | |
parent | recommit of dbe66cf033cf8b450b74e2e3fd510310169bce24 (minor changes for keydb... (diff) | |
download | gpg4usb-5c7dfbe981005580f667b66557b541ce011ae5d3.tar.gz gpg4usb-5c7dfbe981005580f667b66557b541ce011ae5d3.zip |
Merge branch 'master' of https://github.com/gpg4usb/gpg4usb
-rw-r--r-- | gpgcontext.cpp | 22 | ||||
-rw-r--r-- | mainwindow.cpp | 1 | ||||
-rwxr-xr-x | settingsdialog.cpp | 80 | ||||
-rwxr-xr-x | settingsdialog.h | 23 |
4 files changed, 124 insertions, 2 deletions
diff --git a/gpgcontext.cpp b/gpgcontext.cpp index 8f7c07e..45e053b 100644 --- a/gpgcontext.cpp +++ b/gpgcontext.cpp @@ -68,7 +68,18 @@ GpgContext::GpgContext() #else gpgBin = appPath + "/bin/gpg"; #endif - gpgKeys = appPath + "/keydb"; + + QSettings settings; + QString accKeydbPath = settings.value("gpgpaths/keydbpath").toString(); + QString gpgKeys = appPath + "/keydb/"+accKeydbPath; + + if (accKeydbPath != "") { + if (!QDir(gpgKeys).exists()) { + QMessageBox::critical(0,tr("keydb path"),tr("Didn't find keydb directory. Switching to gpg4usb's default keydb directory for this session.")); + gpgKeys = appPath + "/keydb"; + } + } + /* err = gpgme_ctx_set_engine_info(mCtx, GPGME_PROTOCOL_OpenPGP, gpgBin.toUtf8().constData(), gpgKeys.toUtf8().constData());*/ @@ -79,6 +90,15 @@ GpgContext::GpgContext() checkErr(err); #endif + gpgme_engine_info_t engineInfo; + engineInfo = gpgme_ctx_get_engine_info(mCtx); + + + while (engineInfo !=NULL ) { + qDebug() << gpgme_get_protocol_name(engineInfo->protocol); + engineInfo=engineInfo->next; + } + /** Setting the output type must be done at the beginning */ /** think this means ascii-armor --> ? */ gpgme_set_armor(mCtx, 1); diff --git a/mainwindow.cpp b/mainwindow.cpp index 1a698ea..6e00eb9 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -944,6 +944,7 @@ void MainWindow::slotOpenSettingsDialog() { QString preLang = settings.value("int/lang").toString(); + QString preKeydbPath = settings.value("gpgpaths/keydbpath").toString(); new SettingsDialog(mCtx, this); // Iconsize diff --git a/settingsdialog.cpp b/settingsdialog.cpp index ac41092..c4eda75 100755 --- a/settingsdialog.cpp +++ b/settingsdialog.cpp @@ -31,11 +31,13 @@ SettingsDialog::SettingsDialog(GpgME::GpgContext *ctx, QWidget *parent) mimeTab = new MimeTab; keyserverTab = new KeyserverTab; advancedTab = new AdvancedTab; + gpgPathsTab = new GpgPathsTab; tabWidget->addTab(generalTab, tr("General")); tabWidget->addTab(appearanceTab, tr("Appearance")); tabWidget->addTab(mimeTab, tr("PGP/Mime")); tabWidget->addTab(keyserverTab, tr("Keyserver")); + tabWidget->addTab(gpgPathsTab, tr("Gpg paths")); tabWidget->addTab(advancedTab, tr("Advanced")); buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok @@ -81,6 +83,7 @@ void SettingsDialog::slotAccept() appearanceTab->applySettings(); keyserverTab->applySettings(); advancedTab->applySettings(); + gpgPathsTab->applySettings(); if (getRestartNeeded()) { emit signalRestartNeeded(true); } @@ -611,3 +614,80 @@ void AdvancedTab::applySettings() QSettings settings; settings.setValue("advanced/steganography", steganoCheckBox->isChecked()); } + +GpgPathsTab::GpgPathsTab(QWidget *parent) + : QWidget(parent) +{ + setSettings(); + + /***************************************** + * Keydb Box + *****************************************/ + QGroupBox *keydbBox = new QGroupBox(tr("Relative path to keydb")); + QGridLayout *keydbBoxLayout = new QGridLayout(); + + // Label containing the current keydbpath relative to default keydb path + keydbLabel = new QLabel(accKeydbPath,this); + + QPushButton *keydbButton = new QPushButton("Change keydb path",this); + connect(keydbButton, SIGNAL(clicked()), this, SLOT(chooseKeydbDir())); + QPushButton *keydbDefaultButton = new QPushButton("Set keydb to default path",this); + connect(keydbDefaultButton, SIGNAL(clicked()), this, SLOT(setKeydbPathToDefault())); + + keydbBox->setLayout(keydbBoxLayout); + keydbBoxLayout->addWidget(new QLabel(tr("Current keydb path: ")),1,1); + keydbBoxLayout->addWidget(keydbLabel,1,2); + keydbBoxLayout->addWidget(keydbButton,1,3); + keydbBoxLayout->addWidget(keydbDefaultButton,2,3); + keydbBoxLayout->addWidget(new QLabel(tr("<b>NOTE: </b> Gpg4usb will restart automatically if you change the keydb path!")),3,1,1,3); + + QVBoxLayout *mainLayout = new QVBoxLayout; + mainLayout->addWidget(keydbBox); + mainLayout->addStretch(1); + setLayout(mainLayout); +} + +QString GpgPathsTab::getRelativePath(const QString dir1,const QString dir2) +{ + QDir dir(dir1); + QString s; + + s = dir.relativeFilePath(dir2); + qDebug() << "relative path: " << s; + if (s.isEmpty()) { + s = "."; + } + return s; +} + +void GpgPathsTab::setKeydbPathToDefault() +{ + accKeydbPath = "."; + keydbLabel->setText("."); +} + +QString GpgPathsTab::chooseKeydbDir() +{ + QString dir = QFileDialog::getExistingDirectory(this,tr ("Choose keydb directory"),accKeydbPath,QFileDialog::ShowDirsOnly); + + accKeydbPath = getRelativePath(defKeydbPath, dir); + keydbLabel->setText(accKeydbPath); + return ""; +} + +void GpgPathsTab::setSettings() +{ + defKeydbPath = qApp->applicationDirPath() + "/keydb"; + + QSettings settings; + accKeydbPath = settings.value("gpgpaths/keydbpath").toString(); + if (accKeydbPath.isEmpty()) { + accKeydbPath = "."; + } +} + +void GpgPathsTab::applySettings() +{ + QSettings settings; + settings.setValue("gpgpaths/keydbpath",accKeydbPath); +} diff --git a/settingsdialog.h b/settingsdialog.h index 20bb4d2..b709b71 100755 --- a/settingsdialog.h +++ b/settingsdialog.h @@ -158,7 +158,27 @@ signals: }; -class SettingsDialog : public QDialog + class GpgPathsTab : public QWidget + { + Q_OBJECT + public: + GpgPathsTab(QWidget *parent = 0); + void applySettings(); + +private: + QString getRelativePath(const QString dir1,const QString dir2); + QString defKeydbPath; /** The default keydb path used by gpg4usb */ + QString accKeydbPath; /** The currently used keydb path */ + QLabel *keydbLabel; + void setSettings(); + + private slots: + QString chooseKeydbDir(); + void setKeydbPathToDefault(); + + }; + + class SettingsDialog : public QDialog { Q_OBJECT @@ -169,6 +189,7 @@ class SettingsDialog : public QDialog AppearanceTab *appearanceTab; KeyserverTab *keyserverTab; AdvancedTab *advancedTab; + GpgPathsTab *gpgPathsTab; static QHash<QString, QString> listLanguages(); public slots: |