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 {
30 setText(text);
31 }
32 d->configFile = configFile;
33
34 const bool authorized = KAuthorized::authorize(action: KAuthorized::GHNS);
35 if (!authorized) {
36 setEnabled(false);
37 setVisible(false);
38 }
39
40 setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")));
41 connect(sender: this, signal: &QAction::triggered, context: this, slot: [this]() {
42 if (!KAuthorized::authorize(action: KAuthorized::GHNS)) {
43 return;
44 }
45
46 if (!d->dialog) {
47 d->dialog.reset(p: new KNSWidgets::Dialog(d->configFile));
48 d->dialog->setWindowTitle(this->text().remove(c: QLatin1Char('&')));
49 connect(sender: d->dialog.get(), signal: &KNSWidgets::Dialog::finished, context: this, slot: [this]() {
50 Q_EMIT dialogFinished(changedEntries: d->dialog->changedEntries());
51 });
52 }
53 d->dialog->open();
54 });
55}
56
57Action::~Action() = default;
58}
59
60#include "moc_action.cpp"
61

source code of knewstuff/src/widgets/action.cpp