File indexing completed on 2024-10-06 12:23:26
0001 /* 0002 knewstuff3/ui/knewstuffbutton.cpp. 0003 SPDX-FileCopyrightText: 2004 Aaron J. Seigo <aseigo@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-or-later 0006 */ 0007 0008 #include "button.h" 0009 0010 #if KNEWSTUFF_BUILD_DEPRECATED_SINCE(5, 91) 0011 0012 #include "entry_p.h" 0013 #include "qtquickdialogwrapper.h" 0014 #include "ui/widgetquestionlistener.h" 0015 #include <KAuthorized> 0016 #include <KLocalizedString> 0017 #include <KMessageBox> 0018 0019 #include <QPointer> 0020 0021 namespace KNS3 0022 { 0023 class ButtonPrivate 0024 { 0025 public: 0026 QString configFile; 0027 QPointer<QtQuickDialogWrapper> dialog; 0028 }; 0029 0030 Button::Button(const QString &text, const QString &configFile, QWidget *parent) 0031 : QPushButton(parent) 0032 , d(new ButtonPrivate) 0033 { 0034 setText(text); 0035 d->configFile = configFile; 0036 init(); 0037 } 0038 0039 Button::Button(QWidget *parent) 0040 : QPushButton(parent) 0041 , d(new ButtonPrivate) 0042 { 0043 setText(i18n("Download New Stuff...")); 0044 init(); 0045 } 0046 0047 Button::~Button() = default; 0048 0049 void Button::init() 0050 { 0051 const bool authorized = KAuthorized::authorize(KAuthorized::GHNS); 0052 if (!authorized) { 0053 setEnabled(false); 0054 setVisible(false); 0055 } 0056 0057 setIcon(QIcon::fromTheme(QStringLiteral("get-hot-new-stuff"))); 0058 connect(this, &QAbstractButton::clicked, this, &Button::showDialog); 0059 WidgetQuestionListener::instance(); 0060 } 0061 0062 #if KNEWSTUFF_BUILD_DEPRECATED_SINCE(5, 76) 0063 void Button::setButtonText(const QString &what) 0064 { 0065 setText(what); 0066 } 0067 #endif 0068 0069 void Button::setConfigFile(const QString &configFile) 0070 { 0071 d->configFile = configFile; 0072 } 0073 0074 void Button::showDialog() 0075 { 0076 if (!KAuthorized::authorize(KAuthorized::GHNS)) { 0077 KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled")); 0078 return; 0079 } 0080 Q_EMIT aboutToShowDialog(); 0081 0082 if (!d->dialog) { 0083 d->dialog = new QtQuickDialogWrapper(d->configFile, this); 0084 } 0085 const auto changedInternalEntries = d->dialog->exec(); 0086 QList<KNS3::Entry> changedEntries; 0087 for (const KNSCore::EntryInternal &e : changedInternalEntries) { 0088 changedEntries << EntryPrivate::fromInternal(&e); 0089 } 0090 Q_EMIT dialogFinished(changedEntries); 0091 } 0092 0093 } 0094 0095 #include "moc_button.cpp" 0096 0097 #endif