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 "downloaddialog.h"
14 #include "ui/widgetquestionlistener.h"
15 
16 #include <QPointer>
17 
18 namespace KNS3
19 {
20 class ButtonPrivate
21 {
22 public:
23  QString configFile;
24 };
25 
26 Button::Button(const QString &text,
27  const QString &configFile,
28  QWidget *parent)
29  : QPushButton(parent),
30  d(new ButtonPrivate)
31 {
32  setButtonText(text);
33  d->configFile = configFile;
34  init();
35 }
36 
38  : QPushButton(parent),
39  d(new ButtonPrivate)
40 {
41  setButtonText(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(QStringLiteral("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 void Button::setButtonText(const QString &what)
64 {
65  setText(what);
66 }
67 
68 void Button::setConfigFile(const QString &configFile)
69 {
70  d->configFile = configFile;
71 }
72 
73 void Button::showDialog()
74 {
75  if (!KAuthorized::authorize(QStringLiteral("ghns"))) {
76  KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
77  return;
78  }
79  emit aboutToShowDialog();
80 
81  QPointer<DownloadDialog> dialog = new DownloadDialog(d->configFile, this);
82  dialog->exec();
83 
84  if (dialog)
85  emit dialogFinished(dialog->changedEntries());
86 
87  delete dialog;
88 }
89 
90 }
91 
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)
KNewStuff download dialog.
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:26
void setButtonText(const QString &text)
set the text that should appear on the button.
Definition: button.cpp:63
void setConfigFile(const QString &configFile)
set the name of the .knsrc file to use
Definition: button.cpp:68
QString i18n(const char *text, const TYPE &arg...)
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
Definition: button.cpp:18
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 11 2020 22:43:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.