KNewStuff

action.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Oleg Solovyov <mcpain@altlinux.org>
3 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
4
5 SPDX-License-Identifier: LGPL-2.1-or-later
6*/
7
8#include "action.h"
9
10#include "dialog.h"
11#include <KAuthorized>
12#include <KLocalizedString>
13
14namespace KNSWidgets
15{
16class ActionPrivate
17{
18public:
19 QString configFile;
20 std::unique_ptr<Dialog> dialog;
21};
22
23Action::Action(const QString &text, const QString &configFile, QObject *parent)
24 : QAction(parent)
25 , d(new ActionPrivate)
26{
27 if (text.isEmpty()) {
28 setText(i18n("Download New Stuff..."));
29 } else {
31 }
32 d->configFile = configFile;
33
34 const bool authorized = KAuthorized::authorize(KAuthorized::GHNS);
35 if (!authorized) {
36 setEnabled(false);
37 setVisible(false);
38 }
39
40 setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")));
41 connect(this, &QAction::triggered, this, [this]() {
42 if (!KAuthorized::authorize(KAuthorized::GHNS)) {
43 return;
44 }
45
46 if (!d->dialog) {
47 d->dialog.reset(new KNSWidgets::Dialog(d->configFile));
48 d->dialog->setWindowTitle(this->text().remove(QLatin1Char('&')));
49 connect(d->dialog.get(), &KNSWidgets::Dialog::finished, this, [this]() {
50 Q_EMIT dialogFinished(d->dialog->changedEntries());
51 });
52 }
53 d->dialog->open();
54 });
55}
56
57Action::~Action() = default;
58}
59
60#include "moc_action.cpp"
static Q_INVOKABLE bool authorize(const QString &action)
Action(const QString &text, const QString &configFile, QObject *parent)
Constrcuts a KNSWidgets::Action instance.
Definition action.cpp:23
QString i18n(const char *text, const TYPE &arg...)
void setEnabled(bool)
void setIcon(const QIcon &icon)
void triggered(bool checked)
void setVisible(bool)
QIcon fromTheme(const QString &name)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:48:13 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.