diff --git a/src/kleo/docaction.cpp b/src/kleo/docaction.cpp index c93847e46..c61fb2e41 100644 --- a/src/kleo/docaction.cpp +++ b/src/kleo/docaction.cpp @@ -1,70 +1,70 @@ /* kleo/docaction.cpp This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Andre Heinecke SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "docaction.h" #include #include #include #include #include #include #include using namespace Kleo; class Kleo::DocAction::Private { public: explicit Private(const QString &filename, const QUrl &url, const QString &pathHint); ~Private() = default; QString path; bool isEnabled = false; QUrl url; }; DocAction::Private::Private(const QString &filename, const QUrl &url, const QString &pathHint) { QString tmp = pathHint; if (!tmp.startsWith(QLatin1Char('/'))) { tmp.prepend(QLatin1Char('/')); } QDir datadir(QCoreApplication::applicationDirPath() + (pathHint.isNull() ? QStringLiteral("/../share/kleopatra") : tmp)); path = datadir.filePath(filename); QFileInfo fi(path); isEnabled = fi.exists(); if (!isEnabled) { this->url = url; isEnabled = url.isValid(); } } -DocAction::DocAction(const QIcon &icon, const QString &text, const QString &filename, const QUrl &url, const QString &pathHint, QObject *parent) +DocAction::DocAction(const QIcon &icon, const QString &text, const QString &filename, const QString &pathHint, const QUrl &url, QObject *parent) : QAction(icon, text, parent) , d(new Private(filename, url, pathHint)) { setVisible(d->isEnabled); setEnabled(d->isEnabled); connect(this, &QAction::triggered, this, [this]() { if (d->isEnabled) { qCDebug(LIBKLEO_LOG) << "Opening:" << d->path; QDesktopServices::openUrl(d->url.isValid() ? d->url : QUrl::fromLocalFile(d->path)); } }); } DocAction::~DocAction() = default; #include "moc_docaction.cpp" diff --git a/src/kleo/docaction.h b/src/kleo/docaction.h index d1bfbfac8..938deb632 100644 --- a/src/kleo/docaction.h +++ b/src/kleo/docaction.h @@ -1,63 +1,63 @@ /* kleo/docaction.h This file is part of libkleopatra, the KDE keymanagement library SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Andre Heinecke SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once #include "kleo_export.h" #include #include #include class QIcon; class QString; namespace Kleo { /** An action for custom documentation which is opened by file. This can be used for PDF documents like the GnuPG manual. The action is disabled and invisible if the corresponding file cannout be found at creation. Otherwise triggered calls QDesktopServicesOpenURL on the file. */ class KLEO_EXPORT DocAction : public QAction { Q_OBJECT public: /* Create a DocAction with icon, text and file name of the document * * @a filename The name of the documentation file. * @a url Url to a website that will be shown if the given file is not available. * @a pathHint A path relative to QCoreApplication::applicationDirPath() to look for the file. * * */ explicit DocAction(const QIcon &icon, const QString &text, const QString &filename, - const QUrl &url = {}, const QString &pathHint = QString(), + const QUrl &url = {}, QObject *parent = nullptr); ~DocAction() override; DocAction(const QString &, QObject *parent) = delete; DocAction(QObject *parent) = delete; private: class Private; std::unique_ptr d; }; } // namespace Kleo