aboutsummaryrefslogtreecommitdiffstats
path: root/settingsdialog.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'settingsdialog.cpp')
-rwxr-xr-xsettingsdialog.cpp153
1 files changed, 146 insertions, 7 deletions
diff --git a/settingsdialog.cpp b/settingsdialog.cpp
index ffdb5b5..ac41092 100755
--- a/settingsdialog.cpp
+++ b/settingsdialog.cpp
@@ -21,11 +21,12 @@
#include "settingsdialog.h"
-SettingsDialog::SettingsDialog(QWidget *parent)
+SettingsDialog::SettingsDialog(GpgME::GpgContext *ctx, QWidget *parent)
: QDialog(parent)
{
+ mCtx=ctx;
tabWidget = new QTabWidget;
- generalTab = new GeneralTab;
+ generalTab = new GeneralTab(mCtx);
appearanceTab = new AppearanceTab;
mimeTab = new MimeTab;
keyserverTab = new KeyserverTab;
@@ -40,7 +41,7 @@ SettingsDialog::SettingsDialog(QWidget *parent)
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
+ connect(buttonBox, SIGNAL(accepted()), this, SLOT(slotAccept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
QVBoxLayout *mainLayout = new QVBoxLayout;
@@ -50,16 +51,39 @@ SettingsDialog::SettingsDialog(QWidget *parent)
setWindowTitle(tr("Settings"));
+ // slots for handling the restartneeded member
+ this->slotSetRestartNeeded(false);
+ connect(generalTab, SIGNAL(signalRestartNeeded(bool)), this, SLOT(slotSetRestartNeeded(bool)));
+ connect(appearanceTab, SIGNAL(signalRestartNeeded(bool)), this, SLOT(slotSetRestartNeeded(bool)));
+ connect(mimeTab, SIGNAL(signalRestartNeeded(bool)), this, SLOT(slotSetRestartNeeded(bool)));
+ connect(keyserverTab, SIGNAL(signalRestartNeeded(bool)), this, SLOT(slotSetRestartNeeded(bool)));
+ connect(advancedTab, SIGNAL(signalRestartNeeded(bool)), this, SLOT(slotSetRestartNeeded(bool)));
+
+ connect(this, SIGNAL(signalRestartNeeded(bool)), parent, SLOT(slotSetRestartNeeded(bool)));
+
exec();
}
-void SettingsDialog::accept()
+bool SettingsDialog::getRestartNeeded()
+{
+ return this->restartNeeded;
+}
+
+void SettingsDialog::slotSetRestartNeeded(bool needed)
+{
+ this->restartNeeded = needed;
+}
+
+void SettingsDialog::slotAccept()
{
generalTab->applySettings();
mimeTab->applySettings();
appearanceTab->applySettings();
keyserverTab->applySettings();
advancedTab->applySettings();
+ if (getRestartNeeded()) {
+ emit signalRestartNeeded(true);
+ }
close();
}
@@ -95,9 +119,10 @@ QHash<QString, QString> SettingsDialog::listLanguages()
-GeneralTab::GeneralTab(QWidget *parent)
+GeneralTab::GeneralTab(GpgME::GpgContext *ctx,QWidget *parent)
: QWidget(parent)
{
+ mCtx=ctx;
/*****************************************
* remember Password-Box
@@ -139,13 +164,52 @@ GeneralTab::GeneralTab(QWidget *parent)
}
langBoxLayout->addWidget(langSelectBox);
+ langBoxLayout->addWidget(new QLabel(tr("<b>NOTE: </b> Gpg4usb will restart automatically if you change the language!")));
langBox->setLayout(langBoxLayout);
+ connect(langSelectBox,SIGNAL(currentIndexChanged(int)),this,SLOT(slotLanguageChanged()));
+ /*****************************************
+ * Own Key Select Box
+ *****************************************/
+ QGroupBox *ownKeyBox = new QGroupBox(tr("Own key"));
+ QVBoxLayout *ownKeyBoxLayout = new QVBoxLayout();
+ ownKeySelectBox = new QComboBox;
+
+ ownKeyBox->setLayout(ownKeyBoxLayout);
+ mKeyList = new KeyList(mCtx);
+
+ // Fill the keyid hashmap
+ keyIds.insert("", tr("<none>"));
+
+ foreach (QString keyid, *mKeyList->getAllPrivateKeys()) {
+ gpgme_key_t key = mCtx->getKeyDetails(keyid);
+ QString newKey = " (" + keyid + ")";
+ if (! QString(key->uids->email).isEmpty()) {
+ newKey.prepend( " <"+ QString::fromUtf8(key->uids->email) +">");
+ }
+ if (! QString(key->uids->name).isEmpty()) {
+ newKey.prepend( " "+ QString::fromUtf8(key->uids->name));
+ }
+ keyIds.insert(key->uids->uid, newKey);
+ }
+ foreach(QString k , keyIds) {
+ ownKeySelectBox->addItem(k);
+ }
+ connect(ownKeySelectBox,SIGNAL(currentIndexChanged(int)),this,SLOT(slotOwnKeyIdChanged()));
+
+ ownKeyBoxLayout->addWidget(new QLabel(tr("Encrypt all messages additionally to the chosen key:")));
+ ownKeyBoxLayout->addWidget(ownKeySelectBox);
+
+ /*****************************************
+ * Mainlayout
+ *****************************************/
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(rememberPasswordBox);
mainLayout->addWidget(saveCheckedKeysBox);
mainLayout->addWidget(importConfirmationBox);
mainLayout->addWidget(langBox);
+ mainLayout->addWidget(ownKeyBox);
+
setSettings();
mainLayout->addStretch(1);
setLayout(mainLayout);
@@ -175,7 +239,31 @@ void GeneralTab::setSettings()
if (langKey != "") {
langSelectBox->setCurrentIndex(langSelectBox->findText(langValue));
}
- // Ask for confirmation to import, if keyfiles are dropped on keylist
+
+ // Get own key information from keydb/gpg.conf (if contained)
+ QFile gpgConfFile(qApp->applicationDirPath() + "/keydb/gpg.conf");
+ gpgConfFile.open(QFile::ReadOnly);
+ while (!gpgConfFile.atEnd())
+ {
+ QString line = gpgConfFile.readLine();
+ if (line.startsWith("recipient")){
+ QStringList args;
+
+ // get key id from gpg.conf
+ args=line.split(" ");
+ ownKeyId = args.at(1);
+ // remove linebreak at end of id
+ ownKeyId.remove("\n");
+ ownKeyId.remove("\r");
+ }
+ }
+ gpgConfFile.close();
+ if (ownKeyId.isEmpty()) {
+ ownKeySelectBox->setCurrentIndex(0);
+ } else {
+ ownKeySelectBox->setCurrentIndex(ownKeySelectBox->findText(ownKeyId, Qt::MatchContains));
+ }
+
if (settings.value("general/confirmImportKeys",Qt::Checked).toBool()){
importConfirmationCheckBox->setCheckState(Qt::Checked);
}
@@ -195,6 +283,57 @@ void GeneralTab::applySettings()
settings.setValue("general/confirmImportKeys", importConfirmationCheckBox->isChecked());
}
+void GeneralTab::slotLanguageChanged()
+{
+ emit signalRestartNeeded(true);
+}
+
+void GeneralTab::slotOwnKeyIdChanged()
+{
+ // Set ownKeyId to currently selected
+
+ QHashIterator<QString, QString> i(keyIds);
+ while (i.hasNext()) {
+ i.next();
+ if (ownKeySelectBox->currentText() == i.value()) {
+ ownKeyId = i.key();
+ }
+ }
+
+ /*****************************************
+ * Write keyid of own key to gpg.conf
+ *****************************************/
+ QFile gpgConfFile(qApp->applicationDirPath() + "/keydb/gpg.conf");
+ gpgConfFile.open(QFile::ReadWrite);
+ QFile gpgConfTempFile(qApp->applicationDirPath() + "/keydb/gpg.conf.swp");
+ gpgConfTempFile.open(QFile::WriteOnly);
+
+ // remove line with the hidden-encrypt-to
+ while (!gpgConfFile.atEnd())
+ {
+ QByteArray line = gpgConfFile.readLine();
+ if (!line.startsWith("recipient")) {
+ gpgConfTempFile.write(line);
+ }
+ }
+
+ // add line with hidden-encrypt-to, if a key is chosen
+ if (!ownKeyId.isEmpty()) {
+ QByteArray string("recipient ");
+ string.append(ownKeyId);
+ string.append("\n");
+ gpgConfTempFile.write(string);
+ }
+
+ gpgConfFile.close();
+ gpgConfTempFile.close();
+
+ // move the temporary gpg.conffile to the actual one
+ gpgConfFile.remove();
+ gpgConfTempFile.copy(gpgConfTempFile.fileName(),gpgConfFile.fileName());
+ gpgConfTempFile.remove();
+}
+
MimeTab::MimeTab(QWidget *parent)
: QWidget(parent)
{
@@ -401,7 +540,7 @@ KeyserverTab::KeyserverTab(QWidget *parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
- label = new QLabel(tr("Default Keyserver for import:"));
+ QLabel *label = new QLabel(tr("Default Keyserver for import:"));
comboBox = new QComboBox;
comboBox->setEditable(true);
comboBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);