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 <KLocalizedString>
11 #include <KAuthorized>
12 #include <KMessageBox>
13 #include "qtquickdialogwrapper.h"
14 #include "entry_p.h"
15 #include "ui/widgetquestionlistener.h"
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,
29  const QString &configFile,
30  QWidget *parent)
31  : QPushButton(parent),
32  d(new ButtonPrivate)
33 {
34  setText(text);
35  d->configFile = configFile;
36  init();
37 }
38 
40  : QPushButton(parent),
41  d(new ButtonPrivate)
42 {
43  setText(i18n("Download New Stuff..."));
44  init();
45 }
46 
47 Button::~Button()
48 {
49  delete d;
50 }
51 
52 void Button::init()
53 {
54  const bool authorized = KAuthorized::authorize(QStringLiteral("ghns"));
55  if (!authorized) {
56  setEnabled(false);
57  setVisible(false);
58  }
59 
60  setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff")));
61  connect(this, &QAbstractButton::clicked, this, &Button::showDialog);
62  WidgetQuestionListener::instance();
63 }
64 
65 #if KNEWSTUFF_BUILD_DEPRECATED_SINCE(5, 76)
66 void Button::setButtonText(const QString &what)
67 {
68  setText(what);
69 }
70 #endif
71 
72 void Button::setConfigFile(const QString &configFile)
73 {
74  d->configFile = configFile;
75 }
76 
77 void Button::showDialog()
78 {
79  if (!KAuthorized::authorize(QStringLiteral("ghns"))) {
80  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
81  return;
82  }
84 
85  if (!d->dialog) {
86  d->dialog = new QtQuickDialogWrapper(d->configFile, this);
87  }
88  const auto changedInternalEntries = d->dialog->exec();
89  QList<KNS3::Entry> changedEntries;
90  for (const KNSCore::EntryInternal &e : changedInternalEntries) {
91  changedEntries << EntryPrivate::fromInternal(&e);
92  }
93  Q_EMIT dialogFinished(changedEntries);
94 }
95 
96 }
97 
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:66
void setConfigFile(const QString &configFile)
set the name of the .knsrc file to use
Definition: button.cpp:72
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 Mon Jan 18 2021 22:43:49 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.