File indexing completed on 2024-10-06 12:23:26

0001 /*
0002     knewstuff3/ui/downloaddialog.cpp.
0003     SPDX-FileCopyrightText: 2005 Enrico Ros <eros.kde@email.it>
0004     SPDX-FileCopyrightText: 2005-2007 Josef Spillner <spillner@kde.org>
0005     SPDX-FileCopyrightText: 2007 Dirk Mueller <mueller@kde.org>
0006     SPDX-FileCopyrightText: 2007-2009 Jeremy Whiting <jpwhiting@kde.org>
0007     SPDX-FileCopyrightText: 2009-2010 Frederik Gladhorn <gladhorn@kde.org>
0008 
0009     SPDX-License-Identifier: LGPL-2.1-or-later
0010 */
0011 
0012 #include "downloaddialog.h"
0013 
0014 #if KNEWSTUFF_BUILD_DEPRECATED_SINCE(5, 80)
0015 
0016 #include <KAuthorized>
0017 #include <KLocalizedString>
0018 #include <KMessageBox>
0019 #include <KSharedConfig>
0020 #include <KStandardGuiItem>
0021 #include <KTitleWidget>
0022 #include <QCoreApplication>
0023 #include <kwindowconfig.h>
0024 
0025 #include "downloadwidget.h"
0026 #include "downloadwidget_p.h"
0027 #include "ui/widgetquestionlistener.h"
0028 
0029 namespace KNS3
0030 {
0031 class DownloadDialogPrivate
0032 {
0033 public:
0034     ~DownloadDialogPrivate()
0035     {
0036         delete downloadWidget;
0037     }
0038 
0039     DownloadWidget *downloadWidget = nullptr;
0040 };
0041 }
0042 
0043 using namespace KNS3;
0044 
0045 const char ConfigGroup[] = "DownloadDialog Settings";
0046 
0047 DownloadDialog::DownloadDialog(QWidget *parent)
0048     : QDialog(parent)
0049     , d(new DownloadDialogPrivate)
0050 {
0051     const QString name = QCoreApplication::applicationName();
0052     init(name + QStringLiteral(".knsrc"));
0053 }
0054 
0055 DownloadDialog::DownloadDialog(const QString &configFile, QWidget *parent)
0056     : QDialog(parent)
0057     , d(new DownloadDialogPrivate)
0058 {
0059     init(configFile);
0060 }
0061 
0062 void DownloadDialog::init(const QString &configFile)
0063 {
0064     // load the last size from config
0065     KConfigGroup group(KSharedConfig::openConfig(), ConfigGroup);
0066     KWindowConfig::restoreWindowSize(windowHandle(), group);
0067     setMinimumSize(700, 400);
0068 
0069     setWindowTitle(i18n("Get Hot New Stuff"));
0070 
0071     QVBoxLayout *layout = new QVBoxLayout(this);
0072     d->downloadWidget = new DownloadWidget(configFile, this);
0073     // DownloadWidget already provides margins, which would duplicate the dialog layout margins.
0074     // As the widget theme could use different margin sizes for a dialog/window outer layout,
0075     // so from the duplicated margins we pick the internal margins to remove here.
0076     d->downloadWidget->layout()->setContentsMargins(0, 0, 0, 0);
0077     layout->addWidget(d->downloadWidget);
0078 
0079     if (group.hasKey("Name")) {
0080         d->downloadWidget->setTitle(group.readEntry("Name"));
0081     } else {
0082         QString displayName = QGuiApplication::applicationDisplayName();
0083         if (displayName.isEmpty()) {
0084             displayName = QCoreApplication::applicationName();
0085         }
0086         d->downloadWidget->setTitle(i18nc("Program name followed by 'Add On Installer'", "%1 Add-On Installer", displayName));
0087     }
0088     // d->downloadWidget->d->ui.m_titleWidget->setPixmap(QIcon::fromTheme(KGlobal::activeComponent().aboutData()->programIconName()));
0089     d->downloadWidget->d->ui.m_titleWidget->setVisible(true);
0090     d->downloadWidget->d->ui.closeButton->setVisible(true);
0091     KStandardGuiItem::assign(d->downloadWidget->d->ui.closeButton, KStandardGuiItem::Close);
0092     d->downloadWidget->d->dialogMode = true;
0093     connect(d->downloadWidget->d->ui.closeButton, &QAbstractButton::clicked, this, &QDialog::accept);
0094     WidgetQuestionListener::instance();
0095 }
0096 
0097 DownloadDialog::~DownloadDialog()
0098 {
0099     KConfigGroup group(KSharedConfig::openConfig(), ConfigGroup);
0100     KWindowConfig::saveWindowSize(windowHandle(), group, KConfigBase::Persistent);
0101     delete d;
0102 }
0103 
0104 int DownloadDialog::exec()
0105 {
0106     if (!KAuthorized::authorize(KAuthorized::GHNS)) {
0107         KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
0108         return QDialog::Rejected;
0109     }
0110     return QDialog::exec();
0111 }
0112 
0113 void DownloadDialog::open()
0114 {
0115     if (!KAuthorized::authorize(KAuthorized::GHNS)) {
0116         KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
0117         return;
0118     }
0119     QDialog::open();
0120 }
0121 
0122 void DownloadDialog::showEvent(QShowEvent *event)
0123 {
0124     if (!KAuthorized::authorize(KAuthorized::GHNS)) {
0125         KMessageBox::information(this, QStringLiteral("Get Hot New Stuff is disabled by the administrator"), QStringLiteral("Get Hot New Stuff disabled"));
0126         return;
0127     }
0128     QWidget::showEvent(event);
0129 }
0130 
0131 void DownloadDialog::setTitle(const QString &title)
0132 {
0133     d->downloadWidget->setTitle(title);
0134 }
0135 
0136 QString DownloadDialog::title() const
0137 {
0138     return d->downloadWidget->title();
0139 }
0140 
0141 KNSCore::Engine *DownloadDialog::engine()
0142 {
0143     return d->downloadWidget->engine();
0144 }
0145 
0146 Entry::List DownloadDialog::changedEntries()
0147 {
0148     return d->downloadWidget->changedEntries();
0149 }
0150 
0151 Entry::List DownloadDialog::installedEntries()
0152 {
0153     return d->downloadWidget->installedEntries();
0154 }
0155 
0156 #include "moc_downloaddialog.cpp"
0157 
0158 #endif