aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2013-01-21 22:33:23 +0000
committernils <nils@34ebc366-c3a9-4b3c-9f84-69acf7962910>2013-01-21 22:33:23 +0000
commit5e96dd4ed86f63096cebc4c497c6954010a3f3b9 (patch)
tree5bc08c6ea3ba2c9e6701e1ab60a7b39b781dc336
parentkeysize & date in detailsdialog (diff)
downloadgpg4usb-5e96dd4ed86f63096cebc4c497c6954010a3f3b9.tar.gz
gpg4usb-5e96dd4ed86f63096cebc4c497c6954010a3f3b9.zip
added encrypt to self functionality
git-svn-id: http://cpunk.de/svn/src/gpg4usb/trunk@1005 34ebc366-c3a9-4b3c-9f84-69acf7962910
-rw-r--r--TODO2
-rw-r--r--keylist.cpp11
-rw-r--r--keylist.h1
-rw-r--r--mainwindow.cpp2
-rwxr-xr-xsettingsdialog.cpp122
-rwxr-xr-xsettingsdialog.h16
6 files changed, 145 insertions, 9 deletions
diff --git a/TODO b/TODO
index 332e4f2..815e2b4 100644
--- a/TODO
+++ b/TODO
@@ -4,6 +4,7 @@ Release 0.4
- MacOS build
- replace gpgme with kgpg (lots of work and trouble!!!)
- Refresh key from keyserver [DONE]
+- add encrypt to self functionality [DONE]
- add find action in textedit [DONE]
- BUG: hit strg+f, then hit escape -> text not editable anymore, same with not found expression
- When search previous, text should be searched from end again, if no hit is found
@@ -33,6 +34,7 @@ Release 0.4
BUG:
- check PGP-Mime
- for secret keys the name is not shown in details dialog
+- remove double line breaks doesn't work for text containing a signature
Release 0.4.1
- Add default key functionality
diff --git a/keylist.cpp b/keylist.cpp
index 9f4c4fb..4ad30c0 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();
diff --git a/keylist.h b/keylist.h
index f7c739a..9936e3d 100644
--- a/keylist.h
+++ b/keylist.h
@@ -46,6 +46,7 @@ public:
QStringList *getChecked();
QStringList *getPrivateChecked();
+ QStringList *getAllPrivateKeys();
void setChecked(QStringList *keyIds);
//QStringList *getPrivateChecked();
diff --git a/mainwindow.cpp b/mainwindow.cpp
index 73cfb15..816b8bb 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -1260,7 +1260,7 @@ void MainWindow::slotOpenSettingsDialog()
QString preLang = settings.value("int/lang").toString();
QString preKeydbPath = settings.value("gpgpaths/keydbpath").toString();
- new SettingsDialog(this);
+ new SettingsDialog(mCtx, this);
// Iconsize
QSize iconSize = settings.value("toolbar/iconsize", QSize(32, 32)).toSize();
this->setIconSize(iconSize);
diff --git a/settingsdialog.cpp b/settingsdialog.cpp
index 72e0cce..065e31f 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;
@@ -42,7 +43,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;
@@ -98,9 +99,10 @@ QHash<QString, QString> SettingsDialog::listLanguages()
-GeneralTab::GeneralTab(QWidget *parent)
+GeneralTab::GeneralTab(GpgME::GpgContext *ctx,QWidget *parent)
: QWidget(parent)
{
+ mCtx=ctx;
/*****************************************
* remember Password-Box
@@ -145,11 +147,49 @@ GeneralTab::GeneralTab(QWidget *parent)
langBoxLayout->addWidget(new QLabel(tr("<b>NOTE: </b> Gpg4usb will restart automatically if you change the language!")));
langBox->setLayout(langBoxLayout);
+ /*****************************************
+ * 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()) {
+ KgpgCore::KgpgKey key = mCtx->getKeyDetails(keyid);
+ QString newKey = " ("+key.id()+")";
+ if (! key.email().isEmpty()) {
+ newKey.prepend( " <"+ key.email()+">");
+ }
+ if (! key.name().isEmpty()) {
+ newKey.prepend( " "+ key.name());
+ }
+ keyIds.insert(key.id(), newKey);
+ }
+ foreach(QString k , keyIds) {
+ ownKeySelectBox->addItem(k);
+ }
+ connect(ownKeySelectBox,SIGNAL(currentIndexChanged(int)),this,SLOT(slotOwnKeyIdChanged()));
+
+ ownKeyBoxLayout->addWidget(new QLabel(tr("All messages are additionaly encrypted to the following 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);
@@ -179,7 +219,33 @@ 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("hidden-encrypt-to")){
+ 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(ownKeySelectBox->findText("none", Qt::MatchContains));
+ } else {
+ ownKeySelectBox->setCurrentIndex(ownKeySelectBox->findText(ownKeyId, Qt::MatchContains));
+ qDebug() << ownKeySelectBox->findText(ownKeyId);
+ }
+
+
if (settings.value("general/confirmImportKeys",Qt::Checked).toBool()){
importConfirmationCheckBox->setCheckState(Qt::Checked);
}
@@ -199,6 +265,52 @@ void GeneralTab::applySettings()
settings.setValue("general/confirmImportKeys", importConfirmationCheckBox->isChecked());
}
+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("hidden-encrypt-to")) {
+ gpgConfTempFile.write(line);
+ }
+ }
+
+ // add line with hidden-encrypt-to, if a key is chosen
+ if (!ownKeyId.isEmpty()) {
+ QByteArray string("hidden-encrypt-to ");
+ 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)
{
diff --git a/settingsdialog.h b/settingsdialog.h
index 65d4f31..2cb0377 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>
@@ -51,7 +53,7 @@ class GeneralTab : public QWidget
Q_OBJECT
public:
- GeneralTab(QWidget *parent = 0);
+ GeneralTab(GpgME::GpgContext *ctx, QWidget *parent = 0);
void setSettings();
void applySettings();
@@ -61,10 +63,15 @@ 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();
};
class MimeTab : public QWidget
@@ -102,6 +109,7 @@ private slots:
QRadioButton *iconIconsButton;
QRadioButton *iconAllButton;
QCheckBox *windowSizeCheckBox;
+
};
class KeyserverTab : public QWidget
@@ -160,7 +168,7 @@ private:
Q_OBJECT
public:
- SettingsDialog(QWidget *parent = 0);
+ SettingsDialog(GpgME::GpgContext *ctx, QWidget *parent = 0);
GeneralTab *generalTab;
MimeTab *mimeTab;
AppearanceTab *appearanceTab;
@@ -176,6 +184,8 @@ public slots:
private:
QTabWidget *tabWidget;
QDialogButtonBox *buttonBox;
+ GpgME::GpgContext *mCtx; /** The current gpg context */
+
};
#endif // __SETTINGSDIALOG_H__