File indexing completed on 2024-04-28 05:02:30

0001 /*
0002     SPDX-FileCopyrightText: 2024 Ralf Habacker ralf.habacker @freenet.de
0003 
0004     This file is part of libalkimia.
0005 
0006     SPDX-License-Identifier: LGPL-2.1-or-later
0007 */
0008 
0009 #include "alknewstuffwidget.h"
0010 
0011 #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
0012     #include <knscore/engine.h>
0013     #include <knewstuff_version.h>
0014 #if KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 78, 0)
0015     #include <kns3/downloaddialog.h>
0016 #else
0017     #include <KNS3/QtQuickDialogWrapper>
0018 #endif
0019 #else
0020     #include <knewstuff3/downloadmanager.h>
0021     #include <knewstuff3/downloaddialog.h>
0022 #define KNEWSTUFF_VERSION 0
0023 #endif
0024 
0025 #include <QEventLoop>
0026 #include <QtDebug>
0027 #include <QPointer>
0028 #include <QWidget>
0029 
0030 class AlkNewStuffWidget::Private : public QObject
0031 {
0032     Q_OBJECT
0033 public:
0034     AlkNewStuffWidget *q;
0035     QString _configFile;
0036     Private(AlkNewStuffWidget *parent);
0037 
0038     ~Private();
0039 };
0040 
0041 AlkNewStuffWidget::Private::Private(AlkNewStuffWidget *parent)
0042     : q(parent)
0043 {
0044 }
0045 
0046 AlkNewStuffWidget::Private::~Private()
0047 {
0048 }
0049 
0050 AlkNewStuffWidget::AlkNewStuffWidget(QObject *parent)
0051     : QObject{parent}
0052     , d(new Private(this))
0053 {
0054 }
0055 
0056 bool AlkNewStuffWidget::init(const QString &configFile)
0057 {
0058     d->_configFile = configFile;
0059     return true;
0060 }
0061 
0062 bool AlkNewStuffWidget::showInstallDialog(QWidget *parent)
0063 {
0064     QString configFile = d->_configFile;
0065 
0066 #if KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 78, 0)
0067     QPointer<KNS3::DownloadDialog> dialog = new KNS3::DownloadDialog(configFile, parent);
0068     dialog->exec();
0069     delete dialog;
0070     return true;
0071 #elif KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 94, 0)
0072     return !KNS3::QtQuickDialogWrapper(configFile).exec().isEmpty();
0073 #else
0074     QPointer<KNS3::QtQuickDialogWrapper> knsWrapper = new KNS3::QtQuickDialogWrapper(configFile, dynamic_cast<QObject*>(parent));
0075     knsWrapper->open();
0076     QEventLoop loop;
0077     connect(knsWrapper, &KNS3::QtQuickDialogWrapper::closed, &loop, &QEventLoop::quit);
0078     loop.exec();
0079     return !knsWrapper->changedEntries().empty();
0080 #endif
0081 }
0082 
0083 #include "alknewstuffwidget.moc"