aboutsummaryrefslogtreecommitdiffstats
path: root/wizard.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'wizard.cpp')
-rw-r--r--wizard.cpp97
1 files changed, 96 insertions, 1 deletions
diff --git a/wizard.cpp b/wizard.cpp
index 320a9ad..5bb6823 100644
--- a/wizard.cpp
+++ b/wizard.cpp
@@ -29,9 +29,11 @@ Wizard::Wizard(GpgME::GpgContext *ctx, QWidget *parent)
mCtx=ctx;
IntroPage *introPage = new IntroPage();
KeyGenPage *keyGenPage = new KeyGenPage(mCtx);
+ ImportPage *importPage = new ImportPage(mCtx);
ConclusionPage *conclusionPage = new ConclusionPage();
addPage(introPage);
addPage(keyGenPage);
+ addPage(importPage);
addPage(conclusionPage);
#ifndef Q_WS_MAC
@@ -66,7 +68,7 @@ KeyGenPage::KeyGenPage(GpgME::GpgContext *ctx, QWidget *parent)
setTitle(tr("Key-Generating"));
topLabel = new QLabel(tr("First you've got to create an own key."));
createKeyButton = new QPushButton(tr("Create New Key"));
- layout = new QVBoxLayout;
+ layout = new QVBoxLayout();
layout->addWidget(topLabel);
layout->addWidget(createKeyButton);
connect(createKeyButton, SIGNAL(clicked()), this, SLOT(generateKeyDialog()));
@@ -91,6 +93,99 @@ void KeyGenPage::showKeyGeneratedMessage()
layout->addWidget(new QLabel(tr("key generated. Now you can crypt and sign texts.")));
}
+ImportPage::ImportPage(GpgME::GpgContext *ctx, QWidget *parent)
+ : QWizardPage(parent)
+{
+ mCtx=ctx;
+ setTitle(tr("Keyring Import from GnuPG-home-directory"));
+ topLabel = new QLabel(tr("Should I try to import keys from gnupg?"));
+
+ // Layout for private keys
+ privateKeysCheckBox = new QCheckBox();
+ QLabel *privateKeysLabel = new QLabel(tr("Private keys"));
+ QWidget *privHBox = new QWidget(this);
+ QHBoxLayout *privHBoxLayout = new QHBoxLayout();
+ privHBoxLayout->addWidget(privateKeysCheckBox);
+ privHBoxLayout->addWidget(privateKeysLabel);
+ privHBox->setLayout(privHBoxLayout);
+
+ // Layout for public keys
+ publicKeysCheckBox = new QCheckBox();
+ QLabel *publicKeysLabel = new QLabel(tr("Public keys"));
+ QWidget *pubHBox = new QWidget();
+ QHBoxLayout *pubHBoxLayout = new QHBoxLayout();
+ pubHBoxLayout->addWidget(publicKeysCheckBox);
+ pubHBoxLayout->addWidget(publicKeysLabel);
+ pubHBox->setLayout(pubHBoxLayout);
+
+ importKeyButton = new QPushButton(tr("Import keys"));
+ layout = new QVBoxLayout();
+ layout->addWidget(topLabel);
+ layout->addWidget(privHBox);
+ layout->addWidget(pubHBox);
+ layout->addWidget(importKeyButton);
+ connect(importKeyButton, SIGNAL(clicked()), this, SLOT(importKeys()));
+ setLayout(layout);
+}
+
+bool ImportPage::importKeys()
+{
+ // first get gnupghomedir and check, if it exists
+ QString gnuPGHome = getGnuPGHome();
+ if (gnuPGHome == NULL) {
+ qDebug() << "couldn't locate gnupg-Homedirectory";
+ return false;
+ }
+
+ // try to import private files, if private key checkbox is checked
+ if (privateKeysCheckBox->isChecked()) {
+ QString privRingFile = gnuPGHome+"/secring.gpg";
+ QFile file;
+ file.setFileName(privRingFile);
+ if (!file.open(QIODevice::ReadOnly)) {
+ qDebug() << tr("Couldn't Open Private Keyringfile: ") + privRingFile;
+ }
+ QByteArray inBuffer = file.readAll();
+
+ mCtx->importKey(inBuffer);
+ }
+
+ // try to import public keys, if public checkbox is checked
+ if (publicKeysCheckBox->isChecked()) {
+ QString pubRingFile = gnuPGHome+"/pubring.gpg";
+ QFile file;
+ file.setFileName(pubRingFile);
+ if (!file.open(QIODevice::ReadOnly)) {
+ qDebug() << tr("Couldn't Open Public Keyringfile: ") + pubRingFile;
+ }
+ QByteArray inBuffer = file.readAll();
+
+ mCtx->importKey(inBuffer);
+ }
+
+ return true;
+}
+
+QString ImportPage::getGnuPGHome()
+{
+ QString gnuPGHome="";
+ #ifdef _WIN32
+ QSettings gnuPGsettings("HKEY_CURRENT_USER\\Software\\GNU\\GNUPG\\Default", QSettings::Nativeformat);
+ gnuPGsettings.value();
+ #else
+ gnuPGHome=QDir::homePath()+"/.gnupg";
+ if (! QFile(gnuPGHome).exists()) {
+ return NULL;
+ }
+ #endif
+
+ return gnuPGHome;
+}
+
+int ImportPage::nextId() const
+{
+ return 3;
+}
ConclusionPage::ConclusionPage(QWidget *parent)
: QWizardPage(parent)