Commit 751e94af authored by Volker Krause's avatar Volker Krause
Browse files

Add QML bindings for basic data sources

parent ace114c5
set(provider_qml_srcs
qmlabstractdatasource.cpp
qmldatasources.cpp
qmlplugin.cpp
qmlproviderextension.cpp
)
add_library(UserFeedbackQml SHARED ${provider_qml_srcs})
......
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qmlabstractdatasource.h"
#include <AbstractDataSource>
using namespace UserFeedback;
QmlAbstractDataSource::QmlAbstractDataSource(AbstractDataSource *source, QObject* parent)
: QObject(parent)
, m_source(source)
{
}
QmlAbstractDataSource::~QmlAbstractDataSource()
{
}
Provider::StatisticsCollectionMode QmlAbstractDataSource::collectionMode() const
{
return m_source->collectionMode();
}
void QmlAbstractDataSource::setCollectionMode(Provider::StatisticsCollectionMode mode)
{
if (m_source->collectionMode() == mode)
return;
m_source->setCollectionMode(mode);
emit collectionModeChanged();
}
AbstractDataSource* QmlAbstractDataSource::source() const
{
return m_source;
}
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USERFEEDBACK_QMLABSTRACTDATASOURCE_H
#define USERFEEDBACK_QMLABSTRACTDATASOURCE_H
#include <Provider>
namespace UserFeedback {
class AbstractDataSource;
class QmlAbstractDataSource : public QObject
{
Q_OBJECT
Q_PROPERTY(UserFeedback::Provider::StatisticsCollectionMode mode READ collectionMode
WRITE setCollectionMode NOTIFY collectionModeChanged)
public:
explicit QmlAbstractDataSource(AbstractDataSource *source, QObject *parent);
~QmlAbstractDataSource();
Provider::StatisticsCollectionMode collectionMode() const;
void setCollectionMode(Provider::StatisticsCollectionMode mode);
AbstractDataSource* source() const;
Q_SIGNALS:
void collectionModeChanged();
private:
AbstractDataSource *m_source;
};
}
#endif // USERFEEDBACK_QMLABSTRACTDATASOURCE_H
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qmldatasources.h"
#include <ApplicationVersionSource>
#include <CompilerInfoSource>
#include <CpuInfoSource>
#include <LocaleInfoSource>
#include <OpenGLInfoSource>
#include <PlatformInfoSource>
#include <QtVersionSource>
#include <ScreenInfoSource>
#include <StartCountSource>
#include <UsageTimeSource>
using namespace UserFeedback;
#define MAKE_BASIC_QML_WRAPPER(x) Qml ## x::Qml ## x(QObject *parent) : QmlAbstractDataSource(new x, parent) {}
MAKE_BASIC_QML_WRAPPER(ApplicationVersionSource)
MAKE_BASIC_QML_WRAPPER(CompilerInfoSource)
MAKE_BASIC_QML_WRAPPER(CpuInfoSource)
MAKE_BASIC_QML_WRAPPER(LocaleInfoSource)
MAKE_BASIC_QML_WRAPPER(OpenGLInfoSource)
MAKE_BASIC_QML_WRAPPER(PlatformInfoSource)
MAKE_BASIC_QML_WRAPPER(QtVersionSource)
MAKE_BASIC_QML_WRAPPER(ScreenInfoSource)
MAKE_BASIC_QML_WRAPPER(StartCountSource)
MAKE_BASIC_QML_WRAPPER(UsageTimeSource)
#undef MAKE_DEFAULT_SOURCE
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USERFEEDBACK_QMLDATASOURCES_H
#define USERFEEDBACK_QMLDATASOURCES_H
#include "qmlabstractdatasource.h"
namespace UserFeedback {
#define MAKE_BASIC_QML_WRAPPER(x) \
class Qml ## x : public QmlAbstractDataSource { \
Q_OBJECT \
public: \
explicit Qml ## x (QObject *parent = nullptr);\
};
MAKE_BASIC_QML_WRAPPER(ApplicationVersionSource)
MAKE_BASIC_QML_WRAPPER(CompilerInfoSource)
MAKE_BASIC_QML_WRAPPER(CpuInfoSource)
MAKE_BASIC_QML_WRAPPER(LocaleInfoSource)
MAKE_BASIC_QML_WRAPPER(OpenGLInfoSource)
MAKE_BASIC_QML_WRAPPER(PlatformInfoSource)
MAKE_BASIC_QML_WRAPPER(QtVersionSource)
MAKE_BASIC_QML_WRAPPER(ScreenInfoSource)
MAKE_BASIC_QML_WRAPPER(StartCountSource)
MAKE_BASIC_QML_WRAPPER(UsageTimeSource)
#undef MAKE_BASIC_QML_WRAPPER
}
#endif // USERFEEDBACK_QMLDATASOURCES_H
......@@ -16,6 +16,8 @@
*/
#include "qmlplugin.h"
#include "qmldatasources.h"
#include "qmlproviderextension.h"
#include <Provider>
......@@ -25,5 +27,17 @@ using namespace UserFeedback;
void QmlPlugin::registerTypes(const char* uri)
{
qmlRegisterType<Provider>(uri, 1, 0, "Provider");
qmlRegisterExtendedType<Provider, QmlProviderExtension>(uri, 1, 0, "Provider");
qmlRegisterUncreatableType<QmlAbstractDataSource>(uri, 1, 0, "AbstractDataSource", QStringLiteral("abstract base class"));
qmlRegisterType<QmlApplicationVersionSource>(uri, 1, 0, "ApplicationVersionSource");
qmlRegisterType<QmlCompilerInfoSource>(uri, 1, 0, "CompilerInfoSource");
qmlRegisterType<QmlCpuInfoSource>(uri, 1, 0, "CpuInfoSource");
qmlRegisterType<QmlLocaleInfoSource>(uri, 1, 0, "LocaleInfoSource");
qmlRegisterType<QmlOpenGLInfoSource>(uri, 1, 0, "OpenGLInfoSource");
qmlRegisterType<QmlPlatformInfoSource>(uri, 1, 0, "PlatformInfoSource");
qmlRegisterType<QmlQtVersionSource>(uri, 1, 0, "QtVersionSource");
qmlRegisterType<QmlScreenInfoSource>(uri, 1, 0, "ScreenInfoSource");
qmlRegisterType<QmlStartCountSource>(uri, 1, 0, "StartCountSource");
qmlRegisterType<QmlUsageTimeSource>(uri, 1, 0, "UsageTimeSource");
}
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qmlproviderextension.h"
using namespace UserFeedback;
QmlProviderExtension::QmlProviderExtension(QObject* parent) :
QObject(parent)
{
}
QmlProviderExtension::~QmlProviderExtension()
{
}
void QmlProviderExtension::sourceAppend(QQmlListProperty<QmlAbstractDataSource> *prop, QmlAbstractDataSource *value)
{
static_cast<QmlProviderExtension*>(prop->object)->m_sourceWrappers.push_back(value);
static_cast<Provider*>(prop->object->parent())->addDataSource(value->source(), value->collectionMode());
}
int QmlProviderExtension::sourceCount(QQmlListProperty<QmlAbstractDataSource> *prop)
{
return static_cast<QmlProviderExtension*>(prop->object)->m_sourceWrappers.size();
}
QmlAbstractDataSource* QmlProviderExtension::sourceAt(QQmlListProperty<QmlAbstractDataSource> *prop, int index)
{
return static_cast<QmlProviderExtension*>(prop->object)->m_sourceWrappers.at(index);
}
void QmlProviderExtension::sourceClear(QQmlListProperty<QmlAbstractDataSource> *prop)
{
static_cast<QmlProviderExtension*>(prop->object)->m_sourceWrappers.clear();
}
QQmlListProperty<QmlAbstractDataSource> QmlProviderExtension::sources()
{
return QQmlListProperty<QmlAbstractDataSource>(this, nullptr,
QmlProviderExtension::sourceAppend, QmlProviderExtension::sourceCount,
QmlProviderExtension::sourceAt, QmlProviderExtension::sourceClear);
}
/*
Copyright (C) 2017 Volker Krause <vkrause@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef USERFEEDBACK_QMLPROVIDEREXTENSION_H
#define USERFEEDBACK_QMLPROVIDEREXTENSION_H
#include "qmlabstractdatasource.h"
#include <QObject>
#include <QQmlListProperty>
#include <QVector>
namespace UserFeedback {
class QmlProviderExtension : public QObject
{
Q_OBJECT
Q_PROPERTY(QQmlListProperty<UserFeedback::QmlAbstractDataSource> sources READ sources)
Q_CLASSINFO("DefaultProperty", "sources")
public:
explicit QmlProviderExtension(QObject *parent = nullptr);
~QmlProviderExtension();
QQmlListProperty<QmlAbstractDataSource> sources();
private:
static void sourceAppend(QQmlListProperty<QmlAbstractDataSource> *prop, QmlAbstractDataSource *value);
static int sourceCount(QQmlListProperty<QmlAbstractDataSource> *prop);
static QmlAbstractDataSource* sourceAt(QQmlListProperty<QmlAbstractDataSource> *prop, int index);
static void sourceClear(QQmlListProperty<QmlAbstractDataSource> *prop);
QVector<QmlAbstractDataSource*> m_sourceWrappers;
};
}
#endif // USERFEEDBACK_QMLPROVIDEREXTENSION_H
......@@ -21,6 +21,8 @@ import org.kde.userfeedback 1.0 as UserFeedback
ApplicationWindow {
id: root
width: 480
height: 640
UserFeedback.Provider {
id: provider
......@@ -28,6 +30,17 @@ ApplicationWindow {
productIdentifier: "org.kde.orwell"
feedbackServer: "https://feedback.volkerkrause.eu/"
statisticsCollectionMode: UserFeedback.Provider.DetailedUsageStatistics
UserFeedback.ApplicationVersionSource { mode: UserFeedback.Provider.BasicSystemInformation }
UserFeedback.CompilerInfoSource { mode: UserFeedback.Provider.BasicSystemInformation }
UserFeedback.CpuInfoSource { mode: UserFeedback.Provider.DetailedSystemInformation }
UserFeedback.LocaleInfoSource { mode: UserFeedback.Provider.DetailedSystemInformation }
UserFeedback.OpenGLInfoSource{ mode: UserFeedback.Provider.DetailedSystemInformation }
UserFeedback.PlatformInfoSource { mode: UserFeedback.Provider.BasicSystemInformation }
UserFeedback.QtVersionSource { mode: UserFeedback.Provider.BasicSystemInformation }
UserFeedback.ScreenInfoSource { mode: UserFeedback.Provider.DetailedSystemInformation }
UserFeedback.StartCountSource { mode: UserFeedback.Provider.BasicUsageStatistics }
UserFeedback.UsageTimeSource { mode: UserFeedback.Provider.BasicUsageStatistics }
}
Button {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment