KNewStuff

button.cpp
1 /*
2  knewstuff3/ui/knewstuffbutton.cpp.
3  SPDX-FileCopyrightText: 2004 Aaron J. Seigo <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.1-or-later
6 */
7 
8 #include "button.h"
9 
10 #include "entry_p.h"
11 #include "qtquickdialogwrapper.h"
12 #include "ui/widgetquestionlistener.h"
13 #include <KAuthorized>
14 #include <KLocalizedString>
15 #include <KMessageBox>
16 
17 #include <QPointer>
18 
19 namespace KNS3
20 {
21 class ButtonPrivate
22 {
23 public:
24  QString configFile;
26 };
27 
28 Button::Button(const QString &text, const QString &configFile, QWidget *parent)
29  : QPushButton(parent)
30  , d(new ButtonPrivate)
31 {
32  setText(text);
33  d->configFile = configFile;
34  init();
35 }
36 
38  : QPushButton(parent)
39  , d(new ButtonPrivate)
40 {
41  setText(i18n("Download New Stuff..."));
42  init();
43 }
44 
45 Button::~Button()
46 {
47  delete d;
48 }
49 
50 void Button::init()
51 {
52  const bool authorized = KAuthorized::authorize(KAuthorized::GHNS);
53  if (!authorized) {
54  setEnabled(false);
55  setVisible(false);
56  }
57 
58  setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")));
59  connect(this, &QAbstractButton::clicked, this, &Button::showDialog);
60  WidgetQuestionListener::instance();
61 }
62 
63 #if KNEWSTUFF_BUILD_DEPRECATED_SINCE(5, 76)
64 void Button::setButtonText(const QString &what)
65 {
66  setText(what);
67 }
68 #endif
69 
70 void Button::setConfigFile(const QString &configFile)
71 {
72  d->configFile = configFile;
73 }
74 
75 void Button::showDialog()
76 {
77  if (!KAuthorized::authorize(KAuthorized::GHNS)) {
78  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
79  return;
80  }
82 
83  if (!d->dialog) {
84  d->dialog = new QtQuickDialogWrapper(d->configFile, this);
85  }
86  const auto changedInternalEntries = d->dialog->exec();
87  QList<KNS3::Entry> changedEntries;
88  for (const KNSCore::EntryInternal &e : changedInternalEntries) {
89  changedEntries << EntryPrivate::fromInternal(&e);
90  }
91  Q_EMIT dialogFinished(changedEntries);
92 }
93 
94 }
virtual void setVisible(bool visible)
void aboutToShowDialog()
emitted when the Hot New Stuff dialog is about to be shown, usually as a result of the user having cl...
void setIcon(const QIcon &icon)
void setEnabled(bool)
void clicked(bool checked)
Button(const QString &text, const QString &configFile, QWidget *parent)
Constructor used when the details of the KHotNewStuff download is known when the button is created...
Definition: button.cpp:28
void setButtonText(const QString &text)
Set the text that should appear on the button.
Definition: button.cpp:64
void setConfigFile(const QString &configFile)
set the name of the .knsrc file to use
Definition: button.cpp:70
QString i18n(const char *text, const TYPE &arg...)
KNewStuff data entry container.
Definition: entryinternal.h:49
This class is a wrapper around the QtQuick QML dialog.
KCONFIGCORE_EXPORT bool authorize(const QString &action)
void setText(const QString &text)
QIcon fromTheme(const QString &name)
void information(QWidget *parent, const QString &text, const QString &caption=QString(), const QString &dontShowAgainName=QString(), Options options=Notify)
void dialogFinished(const KNS3::Entry::List &changedEntries)
emitted when the Hot New Stuff dialog has been closed
The namespace for the KNewStuff classes.
Definition: button.cpp:19
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
Q_EMITQ_EMIT
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Nov 30 2021 22:38:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.