diff --git a/src/conf/appearanceconfigwidget.cpp b/src/conf/appearanceconfigwidget.cpp index 6440076a9..6713c5685 100644 --- a/src/conf/appearanceconfigwidget.cpp +++ b/src/conf/appearanceconfigwidget.cpp @@ -1,640 +1,640 @@ /* appearanceconfigwidget.cpp This file is part of kleopatra, the KDE key manager Copyright (c) 2002,2004,2008 Klarälvdalens Datakonsult AB Copyright (c) 2002,2003 Marc Mutz Libkleopatra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Libkleopatra is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include #include "appearanceconfigwidget.h" #include "ui_appearanceconfigwidget.h" #include "tooltippreferences.h" #include -#include "Libkleo/KeyFilterManager" -#include "Libkleo/Dn" -#include "Libkleo/DNAttributeOrderConfigWidget" +#include +#include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Config; enum { HasNameRole = Qt::UserRole + 0x1234, /*!< Records that the user has assigned a name (to avoid comparing with i18n-strings) */ HasFontRole, /*!< Records that the user has chosen completely different font (as opposed to italic/bold/strikeout) */ IconNameRole, /*!< Records the name of the icon (since QIcon won't give it out again, once set) */ MayChangeNameRole, MayChangeForegroundRole, MayChangeBackgroundRole, MayChangeFontRole, MayChangeItalicRole, MayChangeBoldRole, MayChangeStrikeOutRole, MayChangeIconRole, EndDummy }; static QFont tryToFindFontFor(const QListWidgetItem *item) { if (item) if (const QListWidget *const lw = item->listWidget()) { return lw->font(); } return QApplication::font("QListWidget"); } static bool is(const QListWidgetItem *item, bool (QFont::*func)() const) { if (!item) { return false; } const QVariant v = item->data(Qt::FontRole); if (!v.isValid() || v.type() != QVariant::Font) { return false; } return (v.value().*func)(); } static bool is_italic(const QListWidgetItem *item) { return is(item, &QFont::italic); } static bool is_bold(const QListWidgetItem *item) { return is(item, &QFont::bold); } static bool is_strikeout(const QListWidgetItem *item) { return is(item, &QFont::strikeOut); } static void set(QListWidgetItem *item, bool on, void (QFont::*func)(bool)) { if (!item) { return; } const QVariant v = item->data(Qt::FontRole); QFont font = v.isValid() && v.type() == QVariant::Font ? v.value() : tryToFindFontFor(item); (font.*func)(on); item->setData(Qt::FontRole, font); } static void set_italic(QListWidgetItem *item, bool on) { set(item, on, &QFont::setItalic); } static void set_bold(QListWidgetItem *item, bool on) { set(item, on, &QFont::setBold); } static void set_strikeout(QListWidgetItem *item, bool on) { set(item, on, &QFont::setStrikeOut); } static void apply_config(const KConfigGroup &group, QListWidgetItem *item) { if (!item) { return; } const QString name = group.readEntry("Name"); item->setText(name.isEmpty() ? i18nc("Key filter without user-assigned name", "") : name); item->setData(HasNameRole, !name.isEmpty()); item->setData(MayChangeNameRole, !group.isEntryImmutable("Name")); const QColor fg = group.readEntry("foreground-color", QColor()); item->setData(Qt::ForegroundRole, fg.isValid() ? QBrush(fg) : QVariant()); item->setData(MayChangeForegroundRole, !group.isEntryImmutable("foreground-color")); const QColor bg = group.readEntry("background-color", QColor()); item->setData(Qt::BackgroundRole, bg.isValid() ? QBrush(bg) : QVariant()); item->setData(MayChangeBackgroundRole, !group.isEntryImmutable("background-color")); const QFont defaultFont = tryToFindFontFor(item); if (group.hasKey("font")) { const QFont font = group.readEntry("font", defaultFont); item->setData(Qt::FontRole, font != defaultFont ? font : QVariant()); item->setData(HasFontRole, font != defaultFont); } else { QFont font = defaultFont; font.setStrikeOut(group.readEntry("font-strikeout", false)); font.setItalic(group.readEntry("font-italic", false)); font.setBold(group.readEntry("font-bold", false)); item->setData(Qt::FontRole, font); item->setData(HasFontRole, false); } item->setData(MayChangeFontRole, !group.isEntryImmutable("font")); item->setData(MayChangeItalicRole, !group.isEntryImmutable("font-italic")); item->setData(MayChangeBoldRole, !group.isEntryImmutable("font-bold")); item->setData(MayChangeStrikeOutRole, !group.isEntryImmutable("font-strikeout")); const QString iconName = group.readEntry("icon"); item->setData(Qt::DecorationRole, iconName.isEmpty() ? QVariant() : QIcon::fromTheme(iconName)); item->setData(IconNameRole, iconName.isEmpty() ? QVariant() : iconName); item->setData(MayChangeIconRole, !group.isEntryImmutable("icon")); } static void erase_if_allowed(QListWidgetItem *item, int role, int allowRole) { if (item && item->data(allowRole).toBool()) { item->setData(role, QVariant()); } } #if 0 static void erase_if_allowed(QListWidgetItem *item, const int role[], size_t numRoles, int allowRole) { if (item && item->data(allowRole).toBool()) for (unsigned int i = 0; i < numRoles; ++i) { item->setData(role[i], QVariant()); } } static void erase_if_allowed(QListWidgetItem *item, int role, const int allowRole[], size_t numAllowRoles) { if (!item) { return; } for (unsigned int i = 0; i < numAllowRoles; ++i) if (!item->data(allowRole[i]).toBool()) { return; } item->setData(role, QVariant()); } #endif static void erase_if_allowed(QListWidgetItem *item, const int role[], size_t numRoles, const int allowRole[], size_t numAllowRoles) { if (!item) { return; } for (unsigned int i = 0; i < numAllowRoles; ++i) if (!item->data(allowRole[i]).toBool()) { return; } for (unsigned int i = 0; i < numRoles; ++i) { item->setData(role[i], QVariant()); } } static void set_default_appearance(QListWidgetItem *item) { if (!item) { return; } erase_if_allowed(item, Qt::ForegroundRole, MayChangeForegroundRole); erase_if_allowed(item, Qt::BackgroundRole, MayChangeBackgroundRole); erase_if_allowed(item, Qt::DecorationRole, MayChangeIconRole); static const int fontRoles[] = { Qt::FontRole, HasFontRole }; static const int fontAllowRoles[] = { MayChangeFontRole, MayChangeItalicRole, MayChangeBoldRole, MayChangeStrikeOutRole, }; erase_if_allowed(item, fontRoles, sizeof(fontRoles) / sizeof(int), fontAllowRoles, sizeof(fontAllowRoles) / sizeof(int)); } static void writeOrDelete(KConfigGroup &group, const char *key, const QVariant &value) { if (value.isValid()) { group.writeEntry(key, value); } else { group.deleteEntry(key); } } static QVariant brush2color(const QVariant &v) { if (v.isValid()) { if (v.type() == QVariant::Color) { return v; } else if (v.type() == QVariant::Brush) { return v.value().color(); } } return QVariant(); } static void save_to_config(const QListWidgetItem *item, KConfigGroup &group) { if (!item) { return; } writeOrDelete(group, "Name", item->data(HasNameRole).toBool() ? item->text() : QVariant()); writeOrDelete(group, "foreground-color", brush2color(item->data(Qt::ForegroundRole))); writeOrDelete(group, "background-color", brush2color(item->data(Qt::BackgroundRole))); writeOrDelete(group, "icon", item->data(IconNameRole)); group.deleteEntry("font"); group.deleteEntry("font-strikeout"); group.deleteEntry("font-italic"); group.deleteEntry("font-bold"); if (item->data(HasFontRole).toBool()) { writeOrDelete(group, "font", item->data(Qt::FontRole)); return; } if (is_strikeout(item)) { group.writeEntry("font-strikeout", true); } if (is_italic(item)) { group.writeEntry("font-italic", true); } if (is_bold(item)) { group.writeEntry("font-bold", true); } } static void kiosk_enable(QWidget *w, const QListWidgetItem *item, int allowRole) { if (!w) { return; } if (item && !item->data(allowRole).toBool()) { w->setEnabled(false); w->setToolTip(i18n("This parameter has been locked down by the system administrator.")); } else { w->setEnabled(item); w->setToolTip(QString()); } } class AppearanceConfigWidget::Private : public Ui_AppearanceConfigWidget { friend class ::Kleo::Config::AppearanceConfigWidget; AppearanceConfigWidget *const q; public: explicit Private(AppearanceConfigWidget *qq) : Ui_AppearanceConfigWidget(), q(qq), dnOrderWidget(nullptr) { setupUi(q); if (QLayout *const l = q->layout()) { l->setContentsMargins(0, 0, 0, 0); } QWidget *w = new QWidget; dnOrderWidget = Kleo::DNAttributeMapper::instance()->configWidget(w); dnOrderWidget->setObjectName(QStringLiteral("dnOrderWidget")); (new QVBoxLayout(w))->addWidget(dnOrderWidget); tabWidget->addTab(w, i18n("DN-Attribute Order")); connect(dnOrderWidget, &DNAttributeOrderConfigWidget::changed, q, &AppearanceConfigWidget::changed); connect(iconButton, SIGNAL(clicked()), q, SLOT(slotIconClicked())); #ifndef QT_NO_COLORDIALOG connect(foregroundButton, SIGNAL(clicked()), q, SLOT(slotForegroundClicked())); connect(backgroundButton, SIGNAL(clicked()), q, SLOT(slotBackgroundClicked())); #else foregroundButton->hide(); backgroundButton->hide(); #endif #ifndef QT_NO_FONTDIALOG connect(fontButton, SIGNAL(clicked()), q, SLOT(slotFontClicked())); #else fontButton->hide(); #endif connect(categoriesLV, SIGNAL(itemSelectionChanged()), q, SLOT(slotSelectionChanged())); connect(defaultLookPB, SIGNAL(clicked()), q, SLOT(slotDefaultClicked())); connect(italicCB, SIGNAL(toggled(bool)), q, SLOT(slotItalicToggled(bool))); connect(boldCB, SIGNAL(toggled(bool)), q, SLOT(slotBoldToggled(bool))); connect(strikeoutCB, SIGNAL(toggled(bool)), q, SLOT(slotStrikeOutToggled(bool))); connect(tooltipValidityCheckBox, SIGNAL(toggled(bool)), q, SLOT(slotTooltipValidityChanged(bool))); connect(tooltipOwnerCheckBox, SIGNAL(toggled(bool)), q, SLOT(slotTooltipOwnerChanged(bool))); connect(tooltipDetailsCheckBox, SIGNAL(toggled(bool)), q, SLOT(slotTooltipDetailsChanged(bool))); } private: void enableDisableActions(QListWidgetItem *item); QListWidgetItem *selectedItem() const; private: void slotIconClicked(); #ifndef QT_NO_COLORDIALOG void slotForegroundClicked(); void slotBackgroundClicked(); #endif #ifndef QT_NO_FONTDIALOG void slotFontClicked(); #endif void slotSelectionChanged(); void slotDefaultClicked(); void slotItalicToggled(bool); void slotBoldToggled(bool); void slotStrikeOutToggled(bool); void slotTooltipValidityChanged(bool); void slotTooltipOwnerChanged(bool); void slotTooltipDetailsChanged(bool); private: Kleo::DNAttributeOrderConfigWidget *dnOrderWidget; }; AppearanceConfigWidget::AppearanceConfigWidget(QWidget *p, Qt::WindowFlags f) : QWidget(p, f), d(new Private(this)) { // load(); } AppearanceConfigWidget::~AppearanceConfigWidget() {} void AppearanceConfigWidget::Private::slotSelectionChanged() { enableDisableActions(selectedItem()); } QListWidgetItem *AppearanceConfigWidget::Private::selectedItem() const { const QList items = categoriesLV->selectedItems(); return items.empty() ? nullptr : items.front(); } void AppearanceConfigWidget::Private::enableDisableActions(QListWidgetItem *item) { kiosk_enable(iconButton, item, MayChangeIconRole); #ifndef QT_NO_COLORDIALOG kiosk_enable(foregroundButton, item, MayChangeForegroundRole); kiosk_enable(backgroundButton, item, MayChangeBackgroundRole); #endif #ifndef QT_NO_FONTDIALOG kiosk_enable(fontButton, item, MayChangeFontRole); #endif kiosk_enable(italicCB, item, MayChangeItalicRole); kiosk_enable(boldCB, item, MayChangeBoldRole); kiosk_enable(strikeoutCB, item, MayChangeStrikeOutRole); defaultLookPB->setEnabled(item); italicCB->setChecked(is_italic(item)); boldCB->setChecked(is_bold(item)); strikeoutCB->setChecked(is_strikeout(item)); } void AppearanceConfigWidget::Private::slotDefaultClicked() { QListWidgetItem *const item = selectedItem(); if (!item) { return; } set_default_appearance(item); enableDisableActions(item); Q_EMIT q->changed(); } void AppearanceConfigWidget::defaults() { // This simply means "default look for every category" for (int i = 0, end = d->categoriesLV->count(); i != end; ++i) { set_default_appearance(d->categoriesLV->item(i)); } d->tooltipValidityCheckBox->setChecked(true); d->tooltipOwnerCheckBox->setChecked(false); d->tooltipDetailsCheckBox->setChecked(false); d->dnOrderWidget->defaults(); Q_EMIT changed(); } void AppearanceConfigWidget::load() { d->dnOrderWidget->load(); d->categoriesLV->clear(); KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("libkleopatrarc")); if (!config) { return; } const QStringList groups = config->groupList().filter(QRegularExpression(QStringLiteral("^Key Filter #\\d+$"))); for (const QString &group : groups) { //QListWidgetItem * item = new QListWidgetItem( d->categoriesLV ); apply_config(KConfigGroup(config, group), new QListWidgetItem(d->categoriesLV)); } const TooltipPreferences prefs; d->tooltipValidityCheckBox->setChecked(prefs.showValidity()); d->tooltipOwnerCheckBox->setChecked(prefs.showOwnerInformation()); d->tooltipDetailsCheckBox->setChecked(prefs.showCertificateDetails()); } void AppearanceConfigWidget::save() { d->dnOrderWidget->save(); TooltipPreferences prefs; prefs.setShowValidity(d->tooltipValidityCheckBox->isChecked()); prefs.setShowOwnerInformation(d->tooltipOwnerCheckBox->isChecked()); prefs.setShowCertificateDetails(d->tooltipDetailsCheckBox->isChecked()); prefs.save(); KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("libkleopatrarc")); if (!config) { return; } // We know (assume) that the groups in the config object haven't changed, // so we just iterate over them and over the listviewitems, and map one-to-one. const QStringList groups = config->groupList().filter(QRegularExpression(QStringLiteral("^Key Filter #\\d+$"))); #if 0 if (groups.isEmpty()) { // If we created the default categories ourselves just now, then we need to make up their list Q3ListViewItemIterator lvit(categoriesLV); for (; lvit.current(); ++lvit) { groups << lvit.current()->text(0); } } #endif for (int i = 0, end = std::min(groups.size(), d->categoriesLV->count()); i != end; ++i) { const QListWidgetItem *const item = d->categoriesLV->item(i); Q_ASSERT(item); KConfigGroup group(config, groups[i]); save_to_config(item, group); } config->sync(); KeyFilterManager::instance()->reload(); } void AppearanceConfigWidget::Private::slotIconClicked() { QListWidgetItem *const item = selectedItem(); if (!item) { return; } const QString iconName = KIconDialog::getIcon( /* repeating default arguments begin */ KIconLoader::Desktop, KIconLoader::Application, false, 0, false, /* repeating default arguments end */ q); if (iconName.isEmpty()) { return; } item->setIcon(QIcon::fromTheme(iconName)); item->setData(IconNameRole, iconName); Q_EMIT q->changed(); } #ifndef QT_NO_COLORDIALOG void AppearanceConfigWidget::Private::slotForegroundClicked() { QListWidgetItem *const item = selectedItem(); if (!item) { return; } const QVariant v = brush2color(item->data(Qt::ForegroundRole)); const QColor initial = v.isValid() ? v.value() : categoriesLV->palette().color(QPalette::Normal, QPalette::Text); const QColor c = QColorDialog::getColor(initial, q); if (c.isValid()) { item->setData(Qt::ForegroundRole, QBrush(c)); Q_EMIT q->changed(); } } void AppearanceConfigWidget::Private::slotBackgroundClicked() { QListWidgetItem *const item = selectedItem(); if (!item) { return; } const QVariant v = brush2color(item->data(Qt::BackgroundRole)); const QColor initial = v.isValid() ? v.value() : categoriesLV->palette().color(QPalette::Normal, QPalette::Base); const QColor c = QColorDialog::getColor(initial, q); if (c.isValid()) { item->setData(Qt::BackgroundRole, QBrush(c)); Q_EMIT q->changed(); } } #endif // QT_NO_COLORDIALOG #ifndef QT_NO_FONTDIALOG void AppearanceConfigWidget::Private::slotFontClicked() { QListWidgetItem *const item = selectedItem(); if (!item) { return; } const QVariant v = item->data(Qt::FontRole); bool ok = false; const QFont defaultFont = tryToFindFontFor(item); const QFont initial = v.isValid() && v.type() == QVariant::Font ? v.value() : defaultFont; QFont f = QFontDialog::getFont(&ok, initial, q); if (!ok) { return; } // disallow circumventing KIOSK: if (!item->data(MayChangeItalicRole).toBool()) { f.setItalic(initial.italic()); } if (!item->data(MayChangeBoldRole).toBool()) { f.setBold(initial.bold()); } if (!item->data(MayChangeStrikeOutRole).toBool()) { f.setStrikeOut(initial.strikeOut()); } item->setData(Qt::FontRole, f != defaultFont ? f : QVariant()); item->setData(HasFontRole, true); Q_EMIT q->changed(); } #endif // QT_NO_FONTDIALOG void AppearanceConfigWidget::Private::slotItalicToggled(bool on) { set_italic(selectedItem(), on); Q_EMIT q->changed(); } void AppearanceConfigWidget::Private::slotBoldToggled(bool on) { set_bold(selectedItem(), on); Q_EMIT q->changed(); } void AppearanceConfigWidget::Private::slotStrikeOutToggled(bool on) { set_strikeout(selectedItem(), on); Q_EMIT q->changed(); } void AppearanceConfigWidget::Private::slotTooltipValidityChanged(bool) { Q_EMIT q->changed(); } void AppearanceConfigWidget::Private::slotTooltipOwnerChanged(bool) { Q_EMIT q->changed(); } void AppearanceConfigWidget::Private::slotTooltipDetailsChanged(bool) { Q_EMIT q->changed(); } #include "moc_appearanceconfigwidget.cpp" diff --git a/src/crypto/gui/decryptverifyfileswizard.cpp b/src/crypto/gui/decryptverifyfileswizard.cpp index 192f247d6..487d1ce94 100644 --- a/src/crypto/gui/decryptverifyfileswizard.cpp +++ b/src/crypto/gui/decryptverifyfileswizard.cpp @@ -1,276 +1,276 @@ /* -*- mode: c++; c-basic-offset:4 -*- crypto/gui/decryptverifywizard.cpp This file is part of Kleopatra, the KDE keymanager Copyright (c) 2007 Klarälvdalens Datakonsult AB Kleopatra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Kleopatra is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include #include "decryptverifyfileswizard.h" #include "decryptverifyoperationwidget.h" #include #include #include #include #include #include #include -#include "Libkleo/FileNameRequester" +#include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Crypto; using namespace Kleo::Crypto::Gui; namespace { class HLine : public QFrame { Q_OBJECT public: explicit HLine(QWidget *p = nullptr, Qt::WindowFlags f = {}) : QFrame(p, f) { setFrameStyle(QFrame::HLine | QFrame::Sunken); } }; class OperationsWidget : public WizardPage { Q_OBJECT public: explicit OperationsWidget(QWidget *p = nullptr); ~OperationsWidget() override; void setOutputDirectory(const QString &dir) { m_ui.outputDirectoryFNR.setFileName(dir); } QString outputDirectory() const { return m_ui.outputDirectoryFNR.fileName(); } bool useOutputDirectory() const { return m_ui.useOutputDirectoryCB.isChecked(); } void ensureIndexAvailable(unsigned int idx); DecryptVerifyOperationWidget *widget(unsigned int idx) { return m_widgets.at(idx); } bool isComplete() const override { return true; } private: std::vector m_widgets; struct UI { QCheckBox useOutputDirectoryCB; QLabel outputDirectoryLB; FileNameRequester outputDirectoryFNR; ScrollArea scrollArea; // ### replace with KDScrollArea when done QVBoxLayout vlay; QHBoxLayout hlay; explicit UI(OperationsWidget *q); } m_ui; }; } class DecryptVerifyFilesWizard::Private { friend class ::Kleo::Crypto::Gui::DecryptVerifyFilesWizard; DecryptVerifyFilesWizard *const q; public: Private(DecryptVerifyFilesWizard *qq); ~Private(); void ensureIndexAvailable(unsigned int idx) { operationsPage.ensureIndexAvailable(idx); } private: OperationsWidget operationsPage; Gui::ResultPage resultPage; }; DecryptVerifyFilesWizard::DecryptVerifyFilesWizard(QWidget *p, Qt::WindowFlags f) : Wizard(p, f), d(new Private(this)) { } DecryptVerifyFilesWizard::~DecryptVerifyFilesWizard() {} void DecryptVerifyFilesWizard::setOutputDirectory(const QString &dir) { d->operationsPage.setOutputDirectory(dir); } QString DecryptVerifyFilesWizard::outputDirectory() const { return d->operationsPage.outputDirectory(); } bool DecryptVerifyFilesWizard::useOutputDirectory() const { return d->operationsPage.useOutputDirectory(); } DecryptVerifyOperationWidget *DecryptVerifyFilesWizard::operationWidget(unsigned int idx) { d->ensureIndexAvailable(idx); return d->operationsPage.widget(idx); } void DecryptVerifyFilesWizard::onNext(int id) { if (id == OperationsPage) { QTimer::singleShot(0, this, &DecryptVerifyFilesWizard::operationPrepared); } Wizard::onNext(id); } void DecryptVerifyFilesWizard::setTaskCollection(const std::shared_ptr &coll) { kleo_assert(coll); d->resultPage.setTaskCollection(coll); } DecryptVerifyFilesWizard::Private::Private(DecryptVerifyFilesWizard *qq) : q(qq), operationsPage(q), resultPage(q) { q->setPage(DecryptVerifyFilesWizard::OperationsPage, &operationsPage); q->setPage(DecryptVerifyFilesWizard::ResultPage, &resultPage); std::vector order; order.push_back(DecryptVerifyFilesWizard::OperationsPage); order.push_back(DecryptVerifyFilesWizard::ResultPage); q->setPageOrder(order); operationsPage.setCommitPage(true); } DecryptVerifyFilesWizard::Private::~Private() {} OperationsWidget::OperationsWidget(QWidget *p) : WizardPage(p), m_widgets(), m_ui(this) { setTitle(i18n("Choose operations to be performed")); setSubTitle(i18n("Here you can check and, if needed, override " "the operations Kleopatra detected for the input given.")); setCommitPage(true); setCustomNextButton(KGuiItem(i18n("&Decrypt/Verify"))); } OperationsWidget::~OperationsWidget() {} OperationsWidget::UI::UI(OperationsWidget *q) : useOutputDirectoryCB(i18n("Create all output files in a single folder"), q), outputDirectoryLB(i18n("&Output folder:"), q), outputDirectoryFNR(q), scrollArea(q), vlay(q), hlay() { KDAB_SET_OBJECT_NAME(useOutputDirectoryCB); KDAB_SET_OBJECT_NAME(outputDirectoryLB); KDAB_SET_OBJECT_NAME(outputDirectoryFNR); KDAB_SET_OBJECT_NAME(scrollArea); KDAB_SET_OBJECT_NAME(vlay); KDAB_SET_OBJECT_NAME(hlay); outputDirectoryFNR.setFilter(QDir::Dirs); useOutputDirectoryCB.setChecked(true); connect(&useOutputDirectoryCB, &QCheckBox::toggled, &outputDirectoryLB, &QLabel::setEnabled); connect(&useOutputDirectoryCB, &QCheckBox::toggled, &outputDirectoryFNR, &FileNameRequester::setEnabled); Q_ASSERT(qobject_cast(scrollArea.widget()->layout())); static_cast(scrollArea.widget()->layout())->addStretch(1); outputDirectoryLB.setBuddy(&outputDirectoryFNR); hlay.setContentsMargins(0, 0, 0, 0); vlay.addWidget(&scrollArea, 1); vlay.addWidget(&useOutputDirectoryCB); vlay.addLayout(&hlay); hlay.addWidget(&outputDirectoryLB); hlay.addWidget(&outputDirectoryFNR); } void OperationsWidget::ensureIndexAvailable(unsigned int idx) { if (idx < m_widgets.size()) { return; } Q_ASSERT(m_ui.scrollArea.widget()); Q_ASSERT(qobject_cast(m_ui.scrollArea.widget()->layout())); QBoxLayout &blay = *static_cast(m_ui.scrollArea.widget()->layout()); for (unsigned int i = m_widgets.size(); i < idx + 1; ++i) { if (i) { blay.insertWidget(blay.count() - 1, new HLine(m_ui.scrollArea.widget())); } DecryptVerifyOperationWidget *w = new DecryptVerifyOperationWidget(m_ui.scrollArea.widget()); blay.insertWidget(blay.count() - 1, w); w->show(); m_widgets.push_back(w); } } #include "decryptverifyfileswizard.moc" diff --git a/src/crypto/gui/decryptverifyoperationwidget.cpp b/src/crypto/gui/decryptverifyoperationwidget.cpp index 936e0ebd3..535265926 100644 --- a/src/crypto/gui/decryptverifyoperationwidget.cpp +++ b/src/crypto/gui/decryptverifyoperationwidget.cpp @@ -1,260 +1,260 @@ /* -*- mode: c++; c-basic-offset:4 -*- uiserver/decryptverifyoperationwidget.cpp This file is part of Kleopatra, the KDE keymanager Copyright (c) 2007 Klarälvdalens Datakonsult AB Kleopatra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Kleopatra is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include #include "decryptverifyoperationwidget.h" #include -#include "Libkleo/FileNameRequester" +#include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Crypto::Gui; class DecryptVerifyOperationWidget::Private { friend class ::Kleo::Crypto::Gui::DecryptVerifyOperationWidget; DecryptVerifyOperationWidget *const q; public: explicit Private(DecryptVerifyOperationWidget *qq); ~Private(); void enableDisableWidgets() { const bool detached = ui.verifyDetachedCB.isChecked(); const bool archive = ui.archiveCB.isChecked(); ui.archiveCB.setEnabled(!detached); ui.archivesCB.setEnabled(archive && !detached); } private: struct UI { QGridLayout glay; QLabel inputLB; QStackedLayout inputStack; QLabel inputFileNameLB; FileNameRequester inputFileNameRQ; //------ QCheckBox verifyDetachedCB; //------ QLabel signedDataLB; QStackedLayout signedDataStack; QLabel signedDataFileNameLB; FileNameRequester signedDataFileNameRQ; //------ QHBoxLayout hlay; QCheckBox archiveCB; QComboBox archivesCB; explicit UI(DecryptVerifyOperationWidget *q); } ui; }; DecryptVerifyOperationWidget::Private::UI::UI(DecryptVerifyOperationWidget *q) : glay(q), inputLB(i18n("Input file:"), q), inputStack(), inputFileNameLB(q), inputFileNameRQ(q), verifyDetachedCB(i18n("&Input file is a detached signature"), q), signedDataLB(i18n("&Signed data:"), q), signedDataStack(), signedDataFileNameLB(q), signedDataFileNameRQ(q), hlay(), archiveCB(i18n("&Input file is an archive; unpack with:"), q), archivesCB(q) { KDAB_SET_OBJECT_NAME(glay); KDAB_SET_OBJECT_NAME(inputLB); KDAB_SET_OBJECT_NAME(inputStack); KDAB_SET_OBJECT_NAME(inputFileNameLB); KDAB_SET_OBJECT_NAME(inputFileNameRQ); KDAB_SET_OBJECT_NAME(verifyDetachedCB); KDAB_SET_OBJECT_NAME(signedDataLB); KDAB_SET_OBJECT_NAME(signedDataStack); KDAB_SET_OBJECT_NAME(signedDataFileNameLB); KDAB_SET_OBJECT_NAME(signedDataFileNameRQ); KDAB_SET_OBJECT_NAME(hlay); KDAB_SET_OBJECT_NAME(archiveCB); KDAB_SET_OBJECT_NAME(archivesCB); inputStack.setContentsMargins(0, 0, 0, 0); signedDataStack.setContentsMargins(0, 0, 0, 0); signedDataLB.setEnabled(false); signedDataFileNameLB.setEnabled(false); signedDataFileNameRQ.setEnabled(false); archivesCB.setEnabled(false); glay.setContentsMargins(0, 0, 0, 0); glay.addWidget(&inputLB, 0, 0); glay.addLayout(&inputStack, 0, 1); inputStack.addWidget(&inputFileNameLB); inputStack.addWidget(&inputFileNameRQ); glay.addWidget(&verifyDetachedCB, 1, 0, 1, 2); glay.addWidget(&signedDataLB, 2, 0); glay.addLayout(&signedDataStack, 2, 1); signedDataStack.addWidget(&signedDataFileNameLB); signedDataStack.addWidget(&signedDataFileNameRQ); glay.addLayout(&hlay, 3, 0, 1, 2); hlay.addWidget(&archiveCB); hlay.addWidget(&archivesCB, 1); connect(&verifyDetachedCB, &QCheckBox::toggled, &signedDataLB, &QLabel::setEnabled); connect(&verifyDetachedCB, &QCheckBox::toggled, &signedDataFileNameLB, &QLabel::setEnabled); connect(&verifyDetachedCB, &QCheckBox::toggled, &signedDataFileNameRQ, &FileNameRequester::setEnabled); connect(&verifyDetachedCB, SIGNAL(toggled(bool)), q, SLOT(enableDisableWidgets())); connect(&archiveCB, SIGNAL(toggled(bool)), q, SLOT(enableDisableWidgets())); } DecryptVerifyOperationWidget::Private::Private(DecryptVerifyOperationWidget *qq) : q(qq), ui(q) { } DecryptVerifyOperationWidget::Private::~Private() {} DecryptVerifyOperationWidget::DecryptVerifyOperationWidget(QWidget *p) : QWidget(p), d(new Private(this)) { setMode(DecryptVerifyOpaque); } DecryptVerifyOperationWidget::~DecryptVerifyOperationWidget() {} void DecryptVerifyOperationWidget::setArchiveDefinitions(const std::vector< std::shared_ptr > &archiveDefinitions) { d->ui.archivesCB.clear(); for (const std::shared_ptr &ad : archiveDefinitions) { d->ui.archivesCB.addItem(ad->label(), QVariant::fromValue(ad)); } } void DecryptVerifyOperationWidget::setMode(Mode mode) { setMode(mode, std::shared_ptr()); } void DecryptVerifyOperationWidget::setMode(Mode mode, const std::shared_ptr &ad) { d->ui.verifyDetachedCB.setChecked(mode != DecryptVerifyOpaque); QWidget *inputWidget; QWidget *signedDataWidget; if (mode == VerifyDetachedWithSignedData) { inputWidget = &d->ui.inputFileNameRQ; signedDataWidget = &d->ui.signedDataFileNameLB; } else { inputWidget = &d->ui.inputFileNameLB; signedDataWidget = &d->ui.signedDataFileNameRQ; } d->ui.inputStack.setCurrentWidget(inputWidget); d->ui.signedDataStack.setCurrentWidget(signedDataWidget); d->ui.inputLB.setBuddy(inputWidget); d->ui.signedDataLB.setBuddy(signedDataWidget); d->ui.archiveCB.setChecked(ad.get() != nullptr); for (int i = 0, end = d->ui.archivesCB.count(); i != end; ++i) if (ad == d->ui.archivesCB.itemData(i).value< std::shared_ptr >()) { d->ui.archivesCB.setCurrentIndex(i); return; } } DecryptVerifyOperationWidget::Mode DecryptVerifyOperationWidget::mode() const { if (d->ui.verifyDetachedCB.isChecked()) if (d->ui.inputStack.currentIndex() == 0) { return VerifyDetachedWithSignature; } else { return VerifyDetachedWithSignedData; } else { return DecryptVerifyOpaque; } } void DecryptVerifyOperationWidget::setInputFileName(const QString &name) { d->ui.inputFileNameLB.setText(name); d->ui.inputFileNameRQ.setFileName(name); } QString DecryptVerifyOperationWidget::inputFileName() const { if (d->ui.inputStack.currentIndex() == 0) { return d->ui.inputFileNameLB.text(); } else { return d->ui.inputFileNameRQ.fileName(); } } void DecryptVerifyOperationWidget::setSignedDataFileName(const QString &name) { d->ui.signedDataFileNameLB.setText(name); d->ui.signedDataFileNameRQ.setFileName(name); } QString DecryptVerifyOperationWidget::signedDataFileName() const { if (d->ui.signedDataStack.currentIndex() == 0) { return d->ui.signedDataFileNameLB.text(); } else { return d->ui.signedDataFileNameRQ.fileName(); } } std::shared_ptr DecryptVerifyOperationWidget::selectedArchiveDefinition() const { if (mode() == DecryptVerifyOpaque && d->ui.archiveCB.isChecked()) { return d->ui.archivesCB.itemData(d->ui.archivesCB.currentIndex()).value< std::shared_ptr >(); } else { return std::shared_ptr(); } } #include "moc_decryptverifyoperationwidget.cpp" diff --git a/src/kwatchgnupg/kwatchgnupgconfig.cpp b/src/kwatchgnupg/kwatchgnupgconfig.cpp index 1222f4d4c..5b3d3d3e7 100644 --- a/src/kwatchgnupg/kwatchgnupgconfig.cpp +++ b/src/kwatchgnupg/kwatchgnupgconfig.cpp @@ -1,218 +1,218 @@ /* kwatchgnupgconfig.cpp This file is part of Kleopatra, the KDE keymanager Copyright (c) 2001,2002,2004 Klarälvdalens Datakonsult AB Kleopatra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Kleopatra is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA In addition, as a special exception, the copyright holders give permission to link the code of this program with any edition of the Qt library by Trolltech AS, Norway (or with modified versions of Qt that use the same license as Qt), and distribute linked combinations including the two. You must obey the GNU General Public License in all respects for all of the code used other than Qt. If you modify this file, you may extend this exception to your version of the file, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ #include #include "kwatchgnupgconfig.h" #include "kwatchgnupg.h" -#include "Libkleo/FileNameRequester" +#include #include #include #include #include #include #include #include #include #include #include #include #include static const char *log_levels[] = { "none", "basic", "advanced", "expert", "guru" }; static int log_level_to_int(const QString &loglevel) { if (loglevel == QLatin1String("none")) { return 0; } else if (loglevel == QLatin1String("basic")) { return 1; } else if (loglevel == QLatin1String("advanced")) { return 2; } else if (loglevel == QLatin1String("expert")) { return 3; } else if (loglevel == QLatin1String("guru")) { return 4; } else { // default return 1; } } KWatchGnuPGConfig::KWatchGnuPGConfig(QWidget *parent) : QDialog(parent) { setWindowTitle(i18nc("@title:window", "Configure KWatchGnuPG")); QVBoxLayout *mainLayout = new QVBoxLayout(this); mButtonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); QPushButton *okButton = mButtonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(mButtonBox, &QDialogButtonBox::rejected, this, &KWatchGnuPGConfig::reject); QWidget *top = new QWidget; mainLayout->addWidget(top); mainLayout->addWidget(mButtonBox); QVBoxLayout *vlay = new QVBoxLayout(top); vlay->setContentsMargins(0, 0, 0, 0); QGroupBox *group = new QGroupBox(i18n("WatchGnuPG"), top); vlay->addWidget(group); QGridLayout *glay = new QGridLayout(group); glay->setColumnStretch(1, 1); int row = -1; ++row; mExeED = new Kleo::FileNameRequester(group); QLabel *label = new QLabel(i18n("&Executable:"), group); label->setBuddy(mExeED); glay->addWidget(label, row, 0); glay->addWidget(mExeED, row, 1); connect(mExeED, &Kleo::FileNameRequester::fileNameChanged, this, &KWatchGnuPGConfig::slotChanged); ++row; mSocketED = new Kleo::FileNameRequester(group); label = new QLabel(i18n("&Socket:"), group); label->setBuddy(mSocketED); glay->addWidget(label, row, 0); glay->addWidget(mSocketED, row, 1); connect(mSocketED, &Kleo::FileNameRequester::fileNameChanged, this, &KWatchGnuPGConfig::slotChanged); ++row; mLogLevelCB = new QComboBox(group); mLogLevelCB->addItem(i18n("None")); mLogLevelCB->addItem(i18n("Basic")); mLogLevelCB->addItem(i18n("Advanced")); mLogLevelCB->addItem(i18n("Expert")); mLogLevelCB->addItem(i18n("Guru")); label = new QLabel(i18n("Default &log level:"), group); label->setBuddy(mLogLevelCB); glay->addWidget(label, row, 0); glay->addWidget(mLogLevelCB, row, 1); connect(mLogLevelCB, static_cast(&QComboBox::activated), this, &KWatchGnuPGConfig::slotChanged); /******************* Log Window group *******************/ group = new QGroupBox(i18n("Log Window"), top); vlay->addWidget(group); glay = new QGridLayout(group); glay->setColumnStretch(1, 1); row = -1; ++row; mLoglenSB = new KPluralHandlingSpinBox(group); mLoglenSB->setRange(0, 1000000); mLoglenSB->setSingleStep(100); mLoglenSB->setSuffix(ki18ncp("history size spinbox suffix", " line", " lines")); mLoglenSB->setSpecialValueText(i18n("unlimited")); label = new QLabel(i18n("&History size:"), group); label->setBuddy(mLoglenSB); glay->addWidget(label, row, 0); glay->addWidget(mLoglenSB, row, 1); QPushButton *button = new QPushButton(i18n("Set &Unlimited"), group); glay->addWidget(button, row, 2); connect(mLoglenSB, static_cast(&KPluralHandlingSpinBox::valueChanged), this, &KWatchGnuPGConfig::slotChanged); connect(button, &QPushButton::clicked, this, &KWatchGnuPGConfig::slotSetHistorySizeUnlimited); ++row; mWordWrapCB = new QCheckBox(i18n("Enable &word wrapping"), group); mWordWrapCB->hide(); // QTextEdit doesn't support word wrapping in LogText mode glay->addWidget(mWordWrapCB, row, 0, 1, 3); connect(mWordWrapCB, &QCheckBox::clicked, this, &KWatchGnuPGConfig::slotChanged); vlay->addStretch(1); connect(okButton, &QPushButton::clicked, this, &KWatchGnuPGConfig::slotSave); } KWatchGnuPGConfig::~KWatchGnuPGConfig() {} void KWatchGnuPGConfig::slotSetHistorySizeUnlimited() { mLoglenSB->setValue(0); } void KWatchGnuPGConfig::loadConfig() { const KConfigGroup watchGnuPG(KSharedConfig::openConfig(), "WatchGnuPG"); mExeED->setFileName(watchGnuPG.readEntry("Executable", WATCHGNUPGBINARY)); mSocketED->setFileName(watchGnuPG.readEntry("Socket", WATCHGNUPGSOCKET)); mLogLevelCB->setCurrentIndex(log_level_to_int(watchGnuPG.readEntry("LogLevel", "basic"))); const KConfigGroup logWindow(KSharedConfig::openConfig(), "LogWindow"); mLoglenSB->setValue(logWindow.readEntry("MaxLogLen", 10000)); mWordWrapCB->setChecked(logWindow.readEntry("WordWrap", false)); mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } void KWatchGnuPGConfig::saveConfig() { KConfigGroup watchGnuPG(KSharedConfig::openConfig(), "WatchGnuPG"); watchGnuPG.writeEntry("Executable", mExeED->fileName()); watchGnuPG.writeEntry("Socket", mSocketED->fileName()); watchGnuPG.writeEntry("LogLevel", log_levels[mLogLevelCB->currentIndex()]); KConfigGroup logWindow(KSharedConfig::openConfig(), "LogWindow"); logWindow.writeEntry("MaxLogLen", mLoglenSB->value()); logWindow.writeEntry("WordWrap", mWordWrapCB->isChecked()); KSharedConfig::openConfig()->sync(); mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false); } void KWatchGnuPGConfig::slotChanged() { mButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true); } void KWatchGnuPGConfig::slotSave() { saveConfig(); Q_EMIT reconfigure(); accept(); }