diff options
-rw-r--r-- | keylist.cpp | 11 | ||||
-rw-r--r-- | keylist.h | 1 | ||||
-rw-r--r-- | mainwindow.cpp | 19 | ||||
-rw-r--r-- | mainwindow.h | 12 | ||||
-rwxr-xr-x | settingsdialog.cpp | 153 | ||||
-rwxr-xr-x | settingsdialog.h | 55 |
6 files changed, 232 insertions, 19 deletions
diff --git a/keylist.cpp b/keylist.cpp index 3d93433..ff39678 100644 --- a/keylist.cpp +++ b/keylist.cpp @@ -124,6 +124,17 @@ QStringList *KeyList::getChecked() return ret; } +QStringList *KeyList::getAllPrivateKeys() +{ + QStringList *ret = new QStringList(); + for (int i = 0; i < mKeyList->rowCount(); i++) { + if (mKeyList->item(i, 1)) { + *ret << mKeyList->item(i, 4)->text(); + } + } + return ret; +} + QStringList *KeyList::getPrivateChecked() { QStringList *ret = new QStringList(); @@ -44,6 +44,7 @@ public: QStringList *getChecked(); QStringList *getPrivateChecked(); + QStringList *getAllPrivateKeys(); void setChecked(QStringList *keyIds); //QStringList *getPrivateChecked(); diff --git a/mainwindow.cpp b/mainwindow.cpp index 381b1b4..3b17e39 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -38,6 +38,9 @@ MainWindow::MainWindow() /* List of binary Attachments */ attachmentDockCreated = false; + /* Variable containing if restart is needed */ + this->slotSetRestartNeeded(false); + keyMgmt = new KeyMgmt(mCtx, this); keyMgmt->hide(); /* test attachmentdir for files alll 15s */ @@ -918,7 +921,7 @@ void MainWindow::openSettingsDialog() QString preLang = settings.value("int/lang").toString(); - new SettingsDialog(this); + new SettingsDialog(mCtx, this); // Iconsize QSize iconSize = settings.value("toolbar/iconsize", QSize(32, 32)).toSize(); this->setIconSize(iconSize); @@ -936,8 +939,8 @@ void MainWindow::openSettingsDialog() closeAttachmentDock(); } - // restart mainwindow if langugage changed - if(preLang != settings.value("int/lang").toString()) { + // restart mainwindow if necessary + if(getRestartNeeded()) { if(edit->maybeSaveAnyTab()) { saveSettings(); qApp->exit(RESTART_CODE); @@ -1001,3 +1004,13 @@ void MainWindow::cutPgpHeader() { edit->fillTextEditWithText(content.trimmed()); } + +void MainWindow::slotSetRestartNeeded(bool needed) +{ + this->restartNeeded = needed; +} + +bool MainWindow::getRestartNeeded() +{ + return this->restartNeeded; +}
\ No newline at end of file diff --git a/mainwindow.h b/mainwindow.h index 8c0bcee..c282f21 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -203,6 +203,12 @@ private slots: */ void disableTabActions(int number); + /** + * @details get value of member restartNeeded to needed. + * @param needed true, if application has to be restarted + */ + void slotSetRestartNeeded(bool needed); + private: /** * @details Create actions for the main-menu and the context-menu of the keylist. @@ -256,6 +262,11 @@ private: */ void parseMime(QByteArray *message); + /** + * @brief return true, if restart is needed + */ + bool getRestartNeeded(); + TextEdit *edit; /** Tabwidget holding the edit-windows */ QMenu *fileMenu; /** Submenu for file-operations*/ QMenu *editMenu; /** Submenu for text-operations*/ @@ -325,6 +336,7 @@ private: KeyMgmt *keyMgmt; /**< TODO */ KeyServerImportDialog *importDialog; /**< TODO */ bool attachmentDockCreated; + bool restartNeeded; }; #endif // __GPGWIN_H__ 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); diff --git a/settingsdialog.h b/settingsdialog.h index e4ca8e6..5efa1a4 100755 --- a/settingsdialog.h +++ b/settingsdialog.h @@ -22,6 +22,8 @@ #ifndef __SETTINGSDIALOG_H__ #define __SETTINGSDIALOG_H__ +#include "keylist.h" + #include <QHash> #include <QWidget> #include <QtGui> @@ -52,7 +54,7 @@ class GeneralTab : public QWidget Q_OBJECT public: - GeneralTab(QWidget *parent = 0); + GeneralTab(GpgME::GpgContext *ctx, QWidget *parent = 0); void setSettings(); void applySettings(); @@ -62,11 +64,21 @@ class GeneralTab : public QWidget QCheckBox *saveCheckedKeysCheckBox; QCheckBox *importConfirmationCheckBox; QComboBox *langSelectBox; + QComboBox *ownKeySelectBox; QHash<QString, QString> lang; + QHash<QString, QString> keyIds; + QString ownKeyId; + KeyList *mKeyList; + GpgME::GpgContext *mCtx; /** The current gpg context */ private slots: + void slotOwnKeyIdChanged(); + void slotLanguageChanged(); - }; +signals: + void signalRestartNeeded(bool needed); + +}; class MimeTab : public QWidget { @@ -81,6 +93,10 @@ private slots: QCheckBox *mimeParseCheckBox; QCheckBox *mimeQPCheckBox; QCheckBox *mimeOpenAttachmentCheckBox; + + signals: + void signalRestartNeeded(bool needed); + }; class AppearanceTab : public QWidget @@ -103,11 +119,16 @@ private slots: QRadioButton *iconIconsButton; QRadioButton *iconAllButton; QCheckBox *windowSizeCheckBox; + + signals: + void signalRestartNeeded(bool needed); + }; class KeyserverTab : public QWidget { Q_OBJECT + public: KeyserverTab(QWidget *parent = 0); void setSettings(); @@ -115,12 +136,16 @@ private slots: private: QComboBox *comboBox; - QLabel *label; -}; + + signals: + void signalRestartNeeded(bool needed); + + }; class AdvancedTab : public QWidget { Q_OBJECT + public: AdvancedTab(QWidget *parent = 0); void setSettings(); @@ -129,14 +154,17 @@ private slots: private: QCheckBox *steganoCheckBox; + signals: + void signalRestartNeeded(bool needed); + }; class SettingsDialog : public QDialog { Q_OBJECT -public: - SettingsDialog(QWidget *parent = 0); + public: + SettingsDialog(GpgME::GpgContext *ctx, QWidget *parent = 0); GeneralTab *generalTab; MimeTab *mimeTab; AppearanceTab *appearanceTab; @@ -144,13 +172,22 @@ public: AdvancedTab *advancedTab; static QHash<QString, QString> listLanguages(); + public slots: + void slotAccept(); -public slots: - void accept(); + signals: + void signalRestartNeeded(bool needed); -private: + private: QTabWidget *tabWidget; QDialogButtonBox *buttonBox; + GpgME::GpgContext *mCtx; /** The current gpg context */ + bool restartNeeded; + bool getRestartNeeded(); + + private slots: + void slotSetRestartNeeded(bool needed); + }; #endif // __SETTINGSDIALOG_H__ |