diff --git a/src/conf/dirservconfigpage.cpp b/src/conf/dirservconfigpage.cpp index e06465a57..51cad75c6 100644 --- a/src/conf/dirservconfigpage.cpp +++ b/src/conf/dirservconfigpage.cpp @@ -1,392 +1,392 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/dirservconfigpage.cpp This file is part of Kleopatra, the KDE keymanager Copyright (c) 2004,2008 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 "dirservconfigpage.h" #include #include #include #include #include #include "kleopatra_debug.h" #include #include #include -#include +#include #include #include using namespace Kleo; #if 0 // disabled, since it is apparently confusing // For sync'ing kabldaprc class KABSynchronizer { public: KABSynchronizer() : mConfig("kabldaprc") { mConfig.setGroup("LDAP"); } KUrl::List readCurrentList() const { KUrl::List lst; // stolen from kabc/ldapclient.cpp const uint numHosts = mConfig.readEntry("NumSelectedHosts"); for (uint j = 0; j < numHosts; j++) { const QString num = QString::number(j); KUrl url; url.setProtocol("ldap"); url.setPath("/"); // workaround KUrl parsing bug const QString host = mConfig.readEntry(QString("SelectedHost") + num).trimmed(); url.setHost(host); const int port = mConfig.readEntry(QString("SelectedPort") + num); if (port != 0) { url.setPort(port); } const QString base = mConfig.readEntry(QString("SelectedBase") + num).trimmed(); url.setQuery(base); const QString bindDN = mConfig.readEntry(QString("SelectedBind") + num).trimmed(); url.setUser(bindDN); const QString pwdBindDN = mConfig.readEntry(QString("SelectedPwdBind") + num).trimmed(); url.setPass(pwdBindDN); lst.append(url); } return lst; } void writeList(const KUrl::List &lst) { mConfig.writeEntry("NumSelectedHosts", lst.count()); KUrl::List::const_iterator it = lst.begin(); KUrl::List::const_iterator end = lst.end(); unsigned j = 0; for (; it != end; ++it, ++j) { const QString num = QString::number(j); KUrl url = *it; Q_ASSERT(url.scheme() == "ldap"); mConfig.writeEntry(QString("SelectedHost") + num, url.host()); mConfig.writeEntry(QString("SelectedPort") + num, url.port()); // KUrl automatically encoded the query (e.g. for spaces inside it), // so decode it before writing it out const QString base = KUrl::decode_string(url.query().mid(1)); mConfig.writeEntry(QString("SelectedBase") + num, base); mConfig.writeEntry(QString("SelectedBind") + num, url.user()); mConfig.writeEntry(QString("SelectedPwdBind") + num, url.pass()); } mConfig.sync(); } private: KConfig mConfig; }; #endif static const char s_x509services_componentName[] = "dirmngr"; static const char s_x509services_groupName[] = "LDAP"; static const char s_x509services_entryName[] = "LDAP Server"; static const char s_x509services_new_componentName[] = "gpgsm"; static const char s_x509services_new_groupName[] = "Configuration"; static const char s_x509services_new_entryName[] = "keyserver"; static const char s_pgpservice_componentName[] = "gpg"; static const char s_pgpservice_groupName[] = "Keyserver"; static const char s_pgpservice_entryName[] = "keyserver"; static const char s_timeout_componentName[] = "dirmngr"; static const char s_timeout_groupName[] = "LDAP"; static const char s_timeout_entryName[] = "ldaptimeout"; static const char s_maxitems_componentName[] = "dirmngr"; static const char s_maxitems_groupName[] = "LDAP"; static const char s_maxitems_entryName[] = "max-replies"; #ifdef NOT_USEFUL_CURRENTLY static const char s_addnewservers_componentName[] = "dirmngr"; static const char s_addnewservers_groupName[] = "LDAP"; static const char s_addnewservers_entryName[] = "add-servers"; #endif DirectoryServicesConfigurationPage::DirectoryServicesConfigurationPage(QWidget *parent, const QVariantList &args) : KCModule(parent, args) { mConfig = QGpgME::cryptoConfig(); QGridLayout *glay = new QGridLayout(this); glay->setContentsMargins(0, 0, 0, 0); int row = 0; mWidget = new Kleo::DirectoryServicesWidget(this); if (QLayout *l = mWidget->layout()) { l->setContentsMargins(0, 0, 0, 0); } glay->addWidget(mWidget, row, 0, 1, 3); connect(mWidget, SIGNAL(changed()), this, SLOT(changed())); // LDAP timeout ++row; QLabel *label = new QLabel(i18n("LDAP &timeout (minutes:seconds):"), this); mTimeout = new QTimeEdit(this); mTimeout->setDisplayFormat(QStringLiteral("mm:ss")); connect(mTimeout, SIGNAL(timeChanged(QTime)), this, SLOT(changed())); label->setBuddy(mTimeout); glay->addWidget(label, row, 0); glay->addWidget(mTimeout, row, 1); // Max number of items returned by queries ++row; mMaxItemsLabel = new QLabel(i18n("&Maximum number of items returned by query:"), this); mMaxItems = new QSpinBox(this); mMaxItems->setMinimum(0); mMaxItemsLabel->setBuddy(mMaxItems); connect(mMaxItems, SIGNAL(valueChanged(int)), this, SLOT(changed())); glay->addWidget(mMaxItemsLabel, row, 0); glay->addWidget(mMaxItems, row, 1); #ifdef NOT_USEFUL_CURRENTLY ++row mAddNewServersCB = new QCheckBox(i18n("Automatically add &new servers discovered in CRL distribution points"), this); connect(mAddNewServersCB, SIGNAL(clicked()), this, SLOT(changed())); glay->addWidget(mAddNewServersCB, row, 0, 1, 3); #endif glay->setRowStretch(++row, 1); glay->setColumnStretch(2, 1); load(); } static QList string2urls(const QString &str) { QList ret; if (str.isEmpty()) { return ret; } ret << QUrl::fromEncoded(str.toLocal8Bit()); return ret; } void DirectoryServicesConfigurationPage::load() { mWidget->clear(); // gpgsm/Configuration/keyserver is not provided by older gpgconf versions; if ((mX509ServicesEntry = configEntry(s_x509services_new_componentName, s_x509services_new_groupName, s_x509services_new_entryName, QGpgME::CryptoConfigEntry::ArgType_LDAPURL, /*isList=*/true, /*showError=*/false))) { mWidget->addX509Services(mX509ServicesEntry->urlValueList()); } else if ((mX509ServicesEntry = configEntry(s_x509services_componentName, s_x509services_groupName, s_x509services_entryName, QGpgME::CryptoConfigEntry::ArgType_LDAPURL, true))) { mWidget->addX509Services(mX509ServicesEntry->urlValueList()); } mWidget->setX509ReadOnly(mX509ServicesEntry && mX509ServicesEntry->isReadOnly()); mOpenPGPServiceEntry = configEntry(s_pgpservice_componentName, s_pgpservice_groupName, s_pgpservice_entryName, QGpgME::CryptoConfigEntry::ArgType_String, false); if (mOpenPGPServiceEntry) { mWidget->addOpenPGPServices(string2urls(parseKeyserver(mOpenPGPServiceEntry->stringValue()).url)); } mWidget->setOpenPGPReadOnly(mOpenPGPServiceEntry && mOpenPGPServiceEntry->isReadOnly()); if (mX509ServicesEntry) if (mOpenPGPServiceEntry) { mWidget->setAllowedProtocols(DirectoryServicesWidget::AllProtocols); } else { mWidget->setAllowedProtocols(DirectoryServicesWidget::X509Protocol); } else if (mOpenPGPServiceEntry) { mWidget->setAllowedProtocols(DirectoryServicesWidget::OpenPGPProtocol); } else { mWidget->setDisabled(true); } DirectoryServicesWidget::Protocols readOnlyProtocols; if (mX509ServicesEntry && mX509ServicesEntry->isReadOnly()) { readOnlyProtocols = DirectoryServicesWidget::X509Protocol; } mTimeoutConfigEntry = configEntry(s_timeout_componentName, s_timeout_groupName, s_timeout_entryName, QGpgME::CryptoConfigEntry::ArgType_UInt, false); if (mTimeoutConfigEntry) { QTime time = QTime(0, 0, 0, 0).addSecs(mTimeoutConfigEntry->uintValue()); //qCDebug(KLEOPATRA_LOG) <<"timeout:" << mTimeoutConfigEntry->uintValue() <<" ->" << time; mTimeout->setTime(time); } mMaxItemsConfigEntry = configEntry(s_maxitems_componentName, s_maxitems_groupName, s_maxitems_entryName, QGpgME::CryptoConfigEntry::ArgType_UInt, false); if (mMaxItemsConfigEntry) { mMaxItems->blockSignals(true); // KNumInput emits valueChanged from setValue! mMaxItems->setValue(mMaxItemsConfigEntry->uintValue()); mMaxItems->blockSignals(false); } const bool maxItemsEnabled = mMaxItemsConfigEntry && !mMaxItemsConfigEntry->isReadOnly(); mMaxItems->setEnabled(maxItemsEnabled); mMaxItemsLabel->setEnabled(maxItemsEnabled); #ifdef NOT_USEFUL_CURRENTLY mAddNewServersConfigEntry = configEntry(s_addnewservers_componentName, s_addnewservers_groupName, s_addnewservers_entryName, QGpgME::CryptoConfigEntry::ArgType_None, false); if (mAddNewServersConfigEntry) { mAddNewServersCB->setChecked(mAddNewServersConfigEntry->boolValue()); } #endif } void DirectoryServicesConfigurationPage::save() { if (mX509ServicesEntry) { mX509ServicesEntry->setURLValueList(mWidget->x509Services()); } if (mOpenPGPServiceEntry) { const QList serv = mWidget->openPGPServices(); if (serv.empty()) { mOpenPGPServiceEntry->setStringValue(QString()); } else { ParsedKeyserver pks = parseKeyserver(mOpenPGPServiceEntry->stringValue()); pks.url = serv.front().url(); mOpenPGPServiceEntry->setStringValue(assembleKeyserver(pks)); } } QTime time(mTimeout->time()); unsigned int timeout = time.minute() * 60 + time.second(); if (mTimeoutConfigEntry && mTimeoutConfigEntry->uintValue() != timeout) { mTimeoutConfigEntry->setUIntValue(timeout); } if (mMaxItemsConfigEntry && mMaxItemsConfigEntry->uintValue() != (uint)mMaxItems->value()) { mMaxItemsConfigEntry->setUIntValue(mMaxItems->value()); } #ifdef NOT_USEFUL_CURRENTLY if (mAddNewServersConfigEntry && mAddNewServersConfigEntry->boolValue() != mAddNewServersCB->isChecked()) { mAddNewServersConfigEntry->setBoolValue(mAddNewServersCB->isChecked()); } #endif mConfig->sync(true); #if 0 // Also write the LDAP URLs to kabldaprc so that they are used by kaddressbook KABSynchronizer sync; const KUrl::List toAdd = mWidget->urlList(); KUrl::List currentList = sync.readCurrentList(); KUrl::List::const_iterator it = toAdd.begin(); KUrl::List::const_iterator end = toAdd.end(); for (; it != end; ++it) { // check if the URL is already in currentList if (currentList.find(*it) == currentList.end()) // if not, add it { currentList.append(*it); } } sync.writeList(currentList); #endif } void DirectoryServicesConfigurationPage::defaults() { // these guys don't have a default, to clear them: if (mX509ServicesEntry) { mX509ServicesEntry->setURLValueList(QList()); } if (mOpenPGPServiceEntry) { mOpenPGPServiceEntry->setStringValue(QString()); } // these presumably have a default, use that one: if (mTimeoutConfigEntry) { mTimeoutConfigEntry->resetToDefault(); } if (mMaxItemsConfigEntry) { mMaxItemsConfigEntry->resetToDefault(); } #ifdef NOT_USEFUL_CURRENTLY if (mAddNewServersConfigEntry) { mAddNewServersConfigEntry->resetToDefault(); } #endif load(); } extern "C" { Q_DECL_EXPORT KCModule *create_kleopatra_config_dirserv(QWidget *parent = nullptr, const QVariantList &args = QVariantList()) { DirectoryServicesConfigurationPage *page = new DirectoryServicesConfigurationPage(parent, args); page->setObjectName(QStringLiteral("kleopatra_config_dirserv")); return page; } } // Find config entry for ldap servers. Implements runtime checks on the configuration option. QGpgME::CryptoConfigEntry *DirectoryServicesConfigurationPage::configEntry(const char *componentName, const char *groupName, const char *entryName, QGpgME::CryptoConfigEntry::ArgType argType, bool isList, bool showError) { QGpgME::CryptoConfigEntry *entry = mConfig->entry(QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName)); if (!entry) { if (showError) { KMessageBox::error(this, i18n("Backend error: gpgconf does not seem to know the entry for %1/%2/%3", QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName))); } return nullptr; } if (entry->argType() != argType || entry->isList() != isList) { if (showError) { KMessageBox::error(this, i18n("Backend error: gpgconf has wrong type for %1/%2/%3: %4 %5", QLatin1String(componentName), QLatin1String(groupName), QLatin1String(entryName), entry->argType(), entry->isList())); } return nullptr; } return entry; } diff --git a/src/crlview.cpp b/src/crlview.cpp index ba5a79729..67cce4584 100644 --- a/src/crlview.cpp +++ b/src/crlview.cpp @@ -1,148 +1,148 @@ /* crlview.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 "crlview.h" #include #include #include #include #include #include -#include +#include #include #include #include #include #include #include CRLView::CRLView(QWidget *parent) : QDialog(parent), _process(0) { QVBoxLayout *topLayout = new QVBoxLayout(this); topLayout->setSpacing(4); topLayout->setMargin(10); topLayout->addWidget(new QLabel(i18n("CRL cache dump:"), this)); _textView = new QTextEdit(this); _textView->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); _textView->setReadOnly(true); topLayout->addWidget(_textView); QHBoxLayout *hbLayout = new QHBoxLayout(); topLayout->addItem(hbLayout); _updateButton = new QPushButton(i18n("&Update"), this); _closeButton = new QPushButton(this); KGuiItem::assign(_closeButton, KStandardGuiItem::close()); hbLayout->addWidget(_updateButton); hbLayout->addStretch(); hbLayout->addWidget(_closeButton); // connections: connect(_updateButton, &QPushButton::clicked, this, &CRLView::slotUpdateView); connect(_closeButton, &QPushButton::clicked, this, &CRLView::close); resize(_textView->fontMetrics().width('M') * 80, _textView->fontMetrics().lineSpacing() * 25); _timer = new QTimer(this); connect(_timer, &QTimer::timeout, this, &CRLView::slotAppendBuffer); } CRLView::~CRLView() { delete _process; _process = nullptr; } void CRLView::closeEvent(QCloseEvent *e) { QDialog::closeEvent(e); delete _process; _process = nullptr; } void CRLView::slotUpdateView() { _updateButton->setEnabled(false); _textView->clear(); _buffer.clear(); if (!_process) { _process = new KProcess(); *_process << "gpgsm" << "--call-dirmngr" << "listcrls"; connect(_process, &KProcess::readyReadStandardOutput, this, &CRLView::slotReadStdout); connect(_process, &KProcess::finished, this, &CRLView::slotProcessExited); } if (_process->state() == QProcess::Running) { _process->kill(); } _process->setOutputChannelMode(KProcess::OnlyStdoutChannel); _process->start(); if (!_process->waitForStarted()) { KMessageBox::error(this, i18n("Unable to start gpgsm process. Please check your installation."), i18n("Certificate Manager Error")); processExited(); } _timer->start(1000); } void CRLView::slotReadStdout() { _buffer.append(_process->readAllStandardOutput()); } void CRLView::slotAppendBuffer() { _textView->append(_buffer); _buffer.clear(); } void CRLView::processExited() { _timer->stop(); slotAppendBuffer(); _updateButton->setEnabled(true); } void CRLView::slotProcessExited(int, QProcess::ExitStatus _status) { processExited(); if (_status != QProcess::NormalExit) { KMessageBox::error(this, i18n("The GpgSM process ended prematurely because of an unexpected error."), i18n("Certificate Manager Error")); } } diff --git a/src/dialogs/ownertrustdialog.h b/src/dialogs/ownertrustdialog.h index 327edad2b..5be06b100 100644 --- a/src/dialogs/ownertrustdialog.h +++ b/src/dialogs/ownertrustdialog.h @@ -1,75 +1,75 @@ /* -*- mode: c++; c-basic-offset:4 -*- dialogs/ownertrustdialog.h This file is part of Kleopatra, the KDE keymanager Copyright (c) 2008 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. */ #ifndef __KLEOPATRA_DIALOGS_OWNERTRUSTDIALOG_H__ #define __KLEOPATRA_DIALOGS_OWNERTRUSTDIALOG_H__ -#include +#include #include #include namespace Kleo { namespace Dialogs { class OwnerTrustDialog : public QDialog { Q_OBJECT public: explicit OwnerTrustDialog(QWidget *parent = nullptr); ~OwnerTrustDialog(); void setFormattedCertificateName(const QString &formatted); QString formattedCertificateName() const; void setHasSecretKey(bool secret); bool hasSecretKey() const; void setAdvancedMode(bool advanced); bool isAdvancedMode() const; void setOwnerTrust(GpgME::Key::OwnerTrust); GpgME::Key::OwnerTrust ownerTrust() const; private: class Private; kdtools::pimpl_ptr d; Q_PRIVATE_SLOT(d, void slotTrustLevelChanged()) }; } } #endif /* __KLEOPATRA_DIALOGS_OWNERTRUSTDIALOG_H__ */ diff --git a/src/kwatchgnupg/kwatchgnupgmainwin.cpp b/src/kwatchgnupg/kwatchgnupgmainwin.cpp index 0de54ce6d..acb281c03 100644 --- a/src/kwatchgnupg/kwatchgnupgmainwin.cpp +++ b/src/kwatchgnupg/kwatchgnupgmainwin.cpp @@ -1,284 +1,284 @@ /* kwatchgnupgmainwin.cpp This file is part of Kleopatra, the KDE keymanager Copyright (c) 2001,2002,2004 Klar�vdalens 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 "kwatchgnupgmainwin.h" #include "kwatchgnupgconfig.h" #include "kwatchgnupg.h" #include "tray.h" #include #include #include "kdlogtextwidget.h" #include #include #include -#include +#include #include #include #include #include #include #include #include #include #include #include #include #include #include KWatchGnuPGMainWindow::KWatchGnuPGMainWindow(QWidget *parent) : KXmlGuiWindow(parent, Qt::Window), mConfig(nullptr) { createActions(); createGUI(); mCentralWidget = new KDLogTextWidget(this); KDAB_SET_OBJECT_NAME(mCentralWidget); setCentralWidget(mCentralWidget); mWatcher = new KProcess; connect(mWatcher, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotWatcherExited(int,QProcess::ExitStatus))); connect(mWatcher, &QProcess::readyReadStandardOutput, this, &KWatchGnuPGMainWindow::slotReadStdout); slotReadConfig(); mSysTray = new KWatchGnuPGTray(this); QAction *act = mSysTray->action(QStringLiteral("quit")); if (act) { connect(act, &QAction::triggered, this, &KWatchGnuPGMainWindow::slotQuit); } setAutoSaveSettings(); } KWatchGnuPGMainWindow::~KWatchGnuPGMainWindow() { delete mWatcher; } void KWatchGnuPGMainWindow::slotClear() { mCentralWidget->clear(); mCentralWidget->message(i18n("[%1] Log cleared", QDateTime::currentDateTime().toString(Qt::ISODate))); } void KWatchGnuPGMainWindow::createActions() { QAction *action = actionCollection()->addAction(QStringLiteral("clear_log")); action->setIcon(QIcon::fromTheme(QStringLiteral("edit-clear-history"))); action->setText(i18n("C&lear History")); connect(action, &QAction::triggered, this, &KWatchGnuPGMainWindow::slotClear); actionCollection()->setDefaultShortcut(action, QKeySequence(Qt::CTRL + Qt::Key_L)); (void)KStandardAction::saveAs(this, SLOT(slotSaveAs()), actionCollection()); (void)KStandardAction::close(this, SLOT(close()), actionCollection()); (void)KStandardAction::quit(this, SLOT(slotQuit()), actionCollection()); (void)KStandardAction::preferences(this, SLOT(slotConfigure()), actionCollection()); (void)KStandardAction::keyBindings(this, SLOT(configureShortcuts()), actionCollection()); (void)KStandardAction::configureToolbars(this, SLOT(slotConfigureToolbars()), actionCollection()); } void KWatchGnuPGMainWindow::configureShortcuts() { KShortcutsDialog::configure(actionCollection(), KShortcutsEditor::LetterShortcutsAllowed, this); } void KWatchGnuPGMainWindow::slotConfigureToolbars() { KEditToolBar dlg(factory()); dlg.exec(); } void KWatchGnuPGMainWindow::startWatcher() { disconnect(mWatcher, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotWatcherExited(int,QProcess::ExitStatus))); if (mWatcher->state() == QProcess::Running) { mWatcher->kill(); while (mWatcher->state() == QProcess::Running) { qApp->processEvents(QEventLoop::ExcludeUserInputEvents); } mCentralWidget->message(i18n("[%1] Log stopped", QDateTime::currentDateTime().toString(Qt::ISODate))); } mWatcher->clearProgram(); { const KConfigGroup config(KSharedConfig::openConfig(), "WatchGnuPG"); *mWatcher << config.readEntry("Executable", WATCHGNUPGBINARY); *mWatcher << QStringLiteral("--force"); *mWatcher << config.readEntry("Socket", WATCHGNUPGSOCKET); } mWatcher->setOutputChannelMode(KProcess::OnlyStdoutChannel); mWatcher->start(); const bool ok = mWatcher->waitForStarted(); if (!ok) { KMessageBox::sorry(this, i18n("The watchgnupg logging process could not be started.\nPlease install watchgnupg somewhere in your $PATH.\nThis log window is unable to display any useful information.")); } else { mCentralWidget->message(i18n("[%1] Log started", QDateTime::currentDateTime().toString(Qt::ISODate))); } connect(mWatcher, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotWatcherExited(int,QProcess::ExitStatus))); } void KWatchGnuPGMainWindow::setGnuPGConfig() { QStringList logclients; // Get config object QGpgME::CryptoConfig *cconfig = QGpgME::cryptoConfig(); if (!cconfig) { return; } //Q_ASSERT( cconfig ); KConfigGroup config(KSharedConfig::openConfig(), "WatchGnuPG"); const QStringList comps = cconfig->componentList(); for (QStringList::const_iterator it = comps.constBegin(); it != comps.constEnd(); ++it) { QGpgME::CryptoConfigComponent *comp = cconfig->component(*it); Q_ASSERT(comp); // Look for log-file entry in Debug group QGpgME::CryptoConfigGroup *group = comp->group(QStringLiteral("Debug")); if (group) { QGpgME::CryptoConfigEntry *entry = group->entry(QStringLiteral("log-file")); if (entry) { entry->setStringValue(QLatin1String("socket://") + config.readEntry("Socket", WATCHGNUPGSOCKET)); logclients << QStringLiteral("%1 (%2)").arg(*it, comp->description()); } entry = group->entry(QStringLiteral("debug-level")); if (entry) { entry->setStringValue(config.readEntry("LogLevel", "basic")); } } } cconfig->sync(true); if (logclients.isEmpty()) { KMessageBox::sorry(nullptr, i18n("There are no components available that support logging.")); } } void KWatchGnuPGMainWindow::slotWatcherExited(int, QProcess::ExitStatus) { if (KMessageBox::questionYesNo(this, i18n("The watchgnupg logging process died.\nDo you want to try to restart it?"), QString(), KGuiItem(i18n("Try Restart")), KGuiItem(i18n("Do Not Try"))) == KMessageBox::Yes) { mCentralWidget->message(i18n("====== Restarting logging process =====")); startWatcher(); } else { KMessageBox::sorry(this, i18n("The watchgnupg logging process is not running.\nThis log window is unable to display any useful information.")); } } void KWatchGnuPGMainWindow::slotReadStdout() { if (!mWatcher) { return; } while (mWatcher->canReadLine()) { QString str = QString::fromUtf8(mWatcher->readLine()); if (str.endsWith(QLatin1Char('\n'))) { str.chop(1); } if (str.endsWith(QLatin1Char('\r'))) { str.chop(1); } mCentralWidget->message(str); if (!isVisible()) { // Change tray icon to show something happened // PENDING(steffen) mSysTray->setAttention(true); } } } void KWatchGnuPGMainWindow::show() { mSysTray->setAttention(false); KMainWindow::show(); } void KWatchGnuPGMainWindow::slotSaveAs() { const QString filename = QFileDialog::getSaveFileName(this, i18n("Save Log to File")); if (filename.isEmpty()) { return; } QFile file(filename); if (file.open(QIODevice::WriteOnly)) { QTextStream(&file) << mCentralWidget->text(); } else KMessageBox::information(this, i18n("Could not save file %1: %2", filename, file.errorString())); } void KWatchGnuPGMainWindow::slotQuit() { disconnect(mWatcher, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(slotWatcherExited(int,QProcess::ExitStatus))); mWatcher->kill(); qApp->quit(); } void KWatchGnuPGMainWindow::slotConfigure() { if (!mConfig) { mConfig = new KWatchGnuPGConfig(this); mConfig->setObjectName(QStringLiteral("config dialog")); connect(mConfig, &KWatchGnuPGConfig::reconfigure, this, &KWatchGnuPGMainWindow::slotReadConfig); } mConfig->loadConfig(); mConfig->exec(); } void KWatchGnuPGMainWindow::slotReadConfig() { const KConfigGroup config(KSharedConfig::openConfig(), "LogWindow"); const int maxLogLen = config.readEntry("MaxLogLen", 10000); mCentralWidget->setHistorySize(maxLogLen < 1 ? -1 : maxLogLen); setGnuPGConfig(); startWatcher(); } bool KWatchGnuPGMainWindow::queryClose() { if (!qApp->isSavingSession()) { hide(); return false; } return KMainWindow::queryClose(); } diff --git a/tests/kleo_test.h b/tests/kleo_test.h index a8243d333..8e1fd35ce 100644 --- a/tests/kleo_test.h +++ b/tests/kleo_test.h @@ -1,56 +1,56 @@ /* This file is part of Kleopatra's test suite. 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. */ #ifndef KLEO_TEST_H #define KLEO_TEST_H -#include +#include #include #include #include #ifndef KLEO_TEST_GNUPGHOME #error KLEO_TEST_GNUPGHOME not defined! #endif // based on qtest_kde.h #define QTEST_KLEOMAIN(TestObject) \ int main(int argc, char *argv[]) \ { \ qputenv("GNUPGHOME", KLEO_TEST_GNUPGHOME); \ qputenv("LC_ALL", "C"); \ qputenv("KDEHOME", QFile::encodeName(QDir::homePath() + QLatin1String("/.kde-unit-test"))); \ KAboutData aboutData( QLatin1String("qttest"), i18n("qttest"), QLatin1String("version") ); \ QApplication app( argc, argv); \ app.setApplicationName( QLatin1String("qttest") ); \ TestObject tc; \ return QTest::qExec( &tc, argc, argv ); \ } #endif