Alkimia API

alknewstuffwidget.cpp
1/*
2 SPDX-FileCopyrightText: 2024 Ralf Habacker ralf.habacker @freenet.de
3
4 This file is part of libalkimia.
5
6 SPDX-License-Identifier: LGPL-2.1-or-later
7*/
8
9#include "alknewstuffwidget.h"
10
11#include "alknewstuffentry_p.h"
12
13#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
14#define KNEWSTUFFWIDGETS_PRIVATE_BUILDING
15#include <KNSWidgets/Action>
16#elif QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
17#include <knewstuff_version.h>
18#include <knscore/engine.h>
19#if KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 78, 0)
20#include <kns3/downloaddialog.h>
21#else
22#include <KNS3/QtQuickDialogWrapper>
23#endif
24#else
25#include <knewstuff3/downloaddialog.h>
26#include <knewstuff3/downloadmanager.h>
27#define KNEWSTUFF_VERSION 0
28#endif
29
30#include <QEventLoop>
31#include <QPointer>
32#include <QWidget>
33
34class AlkNewStuffWidget::Private : public QObject
35{
37public:
39 QString _configFile;
40 Private(AlkNewStuffWidget *parent);
41
42 ~Private();
43};
44
45AlkNewStuffWidget::Private::Private(AlkNewStuffWidget *parent)
46 : q(parent)
47{
48}
49
50AlkNewStuffWidget::Private::~Private()
51{
52}
53
54AlkNewStuffWidget::AlkNewStuffWidget(QObject *parent)
56 , d(new Private(this))
57{
58}
59
60bool AlkNewStuffWidget::init(const QString &configFile)
61{
62 d->_configFile = configFile;
63 return true;
64}
65
66bool AlkNewStuffWidget::showInstallDialog(QWidget *parent)
67{
68 QString configFile = d->_configFile;
69
70#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
71 QPointer<KNSWidgets::Action> knsWrapper = new KNSWidgets::Action("Install Online quotes", configFile, parent);
72 QEventLoop *loop = new QEventLoop;
74 connect(knsWrapper, &KNSWidgets::Action::dialogFinished, this, [this, entries, loop](const QList<KNSCore::Entry> &changedEntries)
75 {
76 *entries = changedEntries;
77 loop->quit();
78 });
79 knsWrapper->trigger();
80 loop->exec();
81 delete loop;
82 alkDebug() << "changed entries" << *entries;
83 bool result = !entries->isEmpty();
84 delete entries;
85 return result;
86#elif KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 78, 0)
87 QPointer<KNS3::DownloadDialog> dialog = new KNS3::DownloadDialog(configFile, parent);
88 dialog->exec();
89 alkDebug() << "changed entries" << dialog->changedEntries();
90 alkDebug() << "installed entries" << dialog->installedEntries();
91 delete dialog;
92 return true;
93#elif KNEWSTUFF_VERSION < QT_VERSION_CHECK(5, 94, 0)
94 return !KNS3::QtQuickDialogWrapper(configFile).exec().isEmpty();
95#else
96 QPointer<KNS3::QtQuickDialogWrapper> knsWrapper = new KNS3::QtQuickDialogWrapper(configFile, dynamic_cast<QObject*>(parent));
97 knsWrapper->open();
98 QEventLoop loop;
99 connect(knsWrapper, &KNS3::QtQuickDialogWrapper::closed, &loop, &QEventLoop::quit);
100 loop.exec();
101 alkDebug() << "changed entries" << knsWrapper->changedEntries();
102 return !knsWrapper->changedEntries().empty();
103#endif
104}
105
106#include "alknewstuffwidget.moc"
Wrapper for new stuff widgets.
void dialogFinished(const QList< KNSCore::Entry > &changedEntries)
int exec(ProcessEventsFlags flags)
void quit()
bool isEmpty() const const
Q_OBJECTQ_OBJECT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:01:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.