summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Heinecke <aheinecke@intevation.de>2016-08-03 15:53:20 (GMT)
committerAndre Heinecke <aheinecke@intevation.de>2016-08-05 07:57:29 (GMT)
commite2fbd723826a1edab3dfbf584d635828613d4b04 (patch)
treebf58dda3e905223f004d6d4d9931aae624b6ac89
parentca707754b5d5cf6f3f4f6a9ed289f9e40729ed4b (diff)
Make ArchiveCommand configurable
To avoid linking ArchiveDefinition into kleopatras config KCM we parse libkleopatrarc directly in the KCM and just work with Label and Id values from it.
-rw-r--r--src/conf/cryptooperationsconfigwidget.cpp58
-rw-r--r--src/conf/cryptooperationsconfigwidget.h3
-rw-r--r--src/kcfg/fileoperationspreferences.kcfg5
3 files changed, 55 insertions, 11 deletions
diff --git a/src/conf/cryptooperationsconfigwidget.cpp b/src/conf/cryptooperationsconfigwidget.cpp
index 8225057..3de49bc 100644
--- a/src/conf/cryptooperationsconfigwidget.cpp
+++ b/src/conf/cryptooperationsconfigwidget.cpp
@@ -38,6 +38,7 @@
#include "fileoperationspreferences.h"
#include <Libkleo/ChecksumDefinition>
+#include <Libkleo/CryptoBackendFactory>
#include <gpgme++/context.h>
@@ -52,6 +53,7 @@
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QLabel>
+#include <QRegularExpression>
#include <boost/shared_ptr.hpp>
@@ -85,13 +87,19 @@ void CryptoOperationsConfigWidget::setupGui()
mAutoDecryptVerifyCB = new QCheckBox(i18n("Automatically start operation based on input detection for decrypt/verify."));
fileGrpLay->addWidget(mPGPFileExtCB);
fileGrpLay->addWidget(mAutoDecryptVerifyCB);
- QHBoxLayout *chkLay = new QHBoxLayout;
+
+ QGridLayout *comboLay = new QGridLayout;
QLabel *chkLabel = new QLabel(i18n("Checksum program to use when creating checksum files:"));
- chkLay->addWidget(chkLabel);
+ comboLay->addWidget(chkLabel, 0, 0);
mChecksumDefinitionCB = new QComboBox;
- chkLay->addWidget(mChecksumDefinitionCB);
- chkLay->addStretch(1);
- fileGrpLay->addLayout(chkLay);
+ comboLay->addWidget(mChecksumDefinitionCB, 0, 1);
+
+ QLabel *archLabel = new QLabel(i18n("Archive command to use when archiving files:"));
+ comboLay->addWidget(archLabel, 1, 0);
+ mArchiveDefinitionCB = new QComboBox;
+ comboLay->addWidget(mArchiveDefinitionCB, 1, 1);
+ fileGrpLay->addLayout(comboLay);
+
fileGrp->setLayout(fileGrpLay);
baseLay->addWidget(fileGrp);
@@ -109,6 +117,8 @@ void CryptoOperationsConfigWidget::setupGui()
connect(mQuickEncryptCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
connect(mChecksumDefinitionCB, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
this, &CryptoOperationsConfigWidget::changed);
+ connect(mArchiveDefinitionCB, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
+ this, &CryptoOperationsConfigWidget::changed);
connect(mPGPFileExtCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
connect(mAutoDecryptVerifyCB, &QCheckBox::toggled, this, &CryptoOperationsConfigWidget::changed);
}
@@ -130,6 +140,10 @@ void CryptoOperationsConfigWidget::defaults()
if (mChecksumDefinitionCB->count()) {
mChecksumDefinitionCB->setCurrentIndex(0);
}
+
+ if (mArchiveDefinitionCB->count()) {
+ mArchiveDefinitionCB->setCurrentIndex(0);
+ }
}
Q_DECLARE_METATYPE(boost::shared_ptr<Kleo::ChecksumDefinition>)
@@ -149,6 +163,7 @@ void CryptoOperationsConfigWidget::load()
const shared_ptr<ChecksumDefinition> default_cd = ChecksumDefinition::getDefaultChecksumDefinition(cds);
mChecksumDefinitionCB->clear();
+ mArchiveDefinitionCB->clear();
Q_FOREACH (const shared_ptr<ChecksumDefinition> &cd, cds) {
mChecksumDefinitionCB->addItem(cd->label(), qVariantFromValue(cd));
@@ -156,6 +171,25 @@ void CryptoOperationsConfigWidget::load()
mChecksumDefinitionCB->setCurrentIndex(mChecksumDefinitionCB->count() - 1);
}
}
+
+ const QString ad_default_id = filePrefs.archiveCommand();
+
+ // This is a weird hack but because we are a KCM we can't link
+ // against ArchiveDefinition which pulls in loads of other classes.
+ // So we do the parsing which archive definitions exist here ourself.
+ if (KConfig *config = CryptoBackendFactory::instance()->configObject()) {
+ const QStringList groups = config->groupList().filter(QRegularExpression(QStringLiteral("^Archive Definition #")));
+ Q_FOREACH (const QString &group, groups) {
+ const KConfigGroup cGroup(config, group);
+ const QString id = cGroup.readEntryUntranslated(QStringLiteral("id"));
+ const QString name = cGroup.readEntry("Name");
+ mArchiveDefinitionCB->addItem(name, QVariant(id));
+ if (id == ad_default_id) {
+ mArchiveDefinitionCB->setCurrentIndex(mArchiveDefinitionCB->count() - 1);
+ }
+ }
+
+ }
}
void CryptoOperationsConfigWidget::save()
@@ -169,14 +203,18 @@ void CryptoOperationsConfigWidget::save()
FileOperationsPreferences filePrefs;
filePrefs.setUsePGPFileExt(mPGPFileExtCB->isChecked());
filePrefs.setAutoDecryptVerify(mAutoDecryptVerifyCB->isChecked());
- filePrefs.save();
const int idx = mChecksumDefinitionCB->currentIndex();
- if (idx < 0) {
- return; // ### pick first?
+ if (idx >= 0) {
+ const shared_ptr<ChecksumDefinition> cd = qvariant_cast< shared_ptr<ChecksumDefinition> >(mChecksumDefinitionCB->itemData(idx));
+ ChecksumDefinition::setDefaultChecksumDefinition(cd);
}
- const shared_ptr<ChecksumDefinition> cd = qvariant_cast< shared_ptr<ChecksumDefinition> >(mChecksumDefinitionCB->itemData(idx));
- ChecksumDefinition::setDefaultChecksumDefinition(cd);
+ const int aidx = mArchiveDefinitionCB->currentIndex();
+ if (aidx >= 0) {
+ const QString id = mArchiveDefinitionCB->itemData(aidx).toString();
+ filePrefs.setArchiveCommand(id);
+ }
+ filePrefs.save();
}
diff --git a/src/conf/cryptooperationsconfigwidget.h b/src/conf/cryptooperationsconfigwidget.h
index 44a8f7a..7cdab12 100644
--- a/src/conf/cryptooperationsconfigwidget.h
+++ b/src/conf/cryptooperationsconfigwidget.h
@@ -66,7 +66,8 @@ private:
*mQuickSignCB,
*mPGPFileExtCB,
*mAutoDecryptVerifyCB;
- QComboBox *mChecksumDefinitionCB;
+ QComboBox *mChecksumDefinitionCB,
+ *mArchiveDefinitionCB;
};
}
diff --git a/src/kcfg/fileoperationspreferences.kcfg b/src/kcfg/fileoperationspreferences.kcfg
index a9df02e..aec5dce 100644
--- a/src/kcfg/fileoperationspreferences.kcfg
+++ b/src/kcfg/fileoperationspreferences.kcfg
@@ -16,5 +16,10 @@
<whatsthis>With this option set Kleopatra no longer asks you what you want to do with input files but instead automatically starts the operations it detects as applicable to the input.</whatsthis>
<default>true</default>
</entry>
+ <entry name="ArchiveCommand" key="default-archive-cmd" type="String">
+ <label>Use this command to create file archives.</label>
+ <whatsthis>When encrypting multiple files or a folder Kleopatra creates an encrypted archive with this command.</whatsthis>
+ <default>tar</default>
+ </entry>
</group>
</kcfg>