Commit 3e0402b2 authored by Volker Krause's avatar Volker Krause
Browse files

Add extendable data sources to the client.

parent 7466fd45
set(userfeedback_core_srcs
abstractdatasource.cpp
platforminfosource.cpp
provider.cpp
surveyinfo.cpp
)
......
/*
Copyright (C) 2016 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 "abstractdatasource.h"
#include "abstractdatasource_p.h"
using namespace UserFeedback;
AbstractDataSourcePrivate::AbstractDataSourcePrivate() = default;
AbstractDataSourcePrivate::~AbstractDataSourcePrivate() = default;
AbstractDataSource::AbstractDataSource() :
d(new AbstractDataSourcePrivate)
{
}
AbstractDataSource::~AbstractDataSource()
{
delete d;
}
Provider::StatisticsCollectionMode AbstractDataSource::collectionMode() const
{
Q_ASSERT(d->mode != Provider::NoStatistics);
if (d->mode == Provider::NoStatistics)
return Provider::AllStatistics;
return d->mode;
}
void AbstractDataSource::setCollectionMode(Provider::StatisticsCollectionMode mode)
{
Q_ASSERT(mode != Provider::NoStatistics);
d->mode = mode;
}
/*
Copyright (C) 2016 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_ABSTRACTDATASOURCE_H
#define USERFEEDBACK_ABSTRACTDATASOURCE_H
#include "userfeedbackcore_export.h"
#include "provider.h"
class QJsonObject;
namespace UserFeedback {
class AbstractDataSourcePrivate;
/** Base class for data sources for statistical data. */
class USERFEEDBACKCORE_EXPORT AbstractDataSource
{
public:
AbstractDataSource();
virtual ~AbstractDataSource();
/** Override this to serialize the data you collected. */
virtual void toJson(QJsonObject &obj) = 0;
/** Returns which colleciton mode this data source belongs to. */
Provider::StatisticsCollectionMode collectionMode() const;
/** Sets which colleciton mode this data source belongs to. */
void setCollectionMode(Provider::StatisticsCollectionMode mode);
private:
Q_DISABLE_COPY(AbstractDataSource)
class AbstractDataSourcePrivate* const d;
};
}
#endif // USERFEEDBACK_ABSTRACTDATASOURCE_H
/*
Copyright (C) 2016 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 ABSTRACTDATASOURCEPRIVATE_H
#define ABSTRACTDATASOURCEPRIVATE_H
#include "provider.h"
namespace UserFeedback {
class AbstractDataSourcePrivate
{
public:
AbstractDataSourcePrivate();
virtual ~AbstractDataSourcePrivate();
Provider::StatisticsCollectionMode mode = Provider::AllStatistics;
};
}
#endif // ABSTRACTDATASOURCEPRIVATE_H
/*
Copyright (C) 2016 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 "platforminfosource.h"
#include <QJsonObject>
#include <QSysInfo>
using namespace UserFeedback;
PlatformInfoSource::PlatformInfoSource()
{
}
void PlatformInfoSource::toJson(QJsonObject& obj)
{
obj.insert(QStringLiteral("platformOS"), QSysInfo::productType());
obj.insert(QStringLiteral("platformVersion"), QSysInfo::productVersion());
}
/*
Copyright (C) 2016 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_PLATFORMINFOSOURCE_H
#define USERFEEDBACK_PLATFORMINFOSOURCE_H
#include "abstractdatasource.h"
namespace UserFeedback {
/** Reports information about the platform the application is running on.
* This includes two string data fields:
* - platformOS: the operating system name
* - platformVersion: the operating system or distribution version.
*/
class USERFEEDBACKCORE_EXPORT PlatformInfoSource : public AbstractDataSource
{
public:
PlatformInfoSource();
void toJson(QJsonObject &obj) Q_DECL_OVERRIDE;
};
}
#endif // USERFEEDBACK_PLATFORMINFOSOURCE_H
......@@ -16,6 +16,8 @@
*/
#include <config-userfeedback-version.h>
#include "abstractdatasource.h"
#include "provider.h"
#include "surveyinfo.h"
......@@ -85,6 +87,8 @@ public:
int encouragementTime;
int encouragementDelay;
bool encouragementDisplayed;
QVector<AbstractDataSource*> dataSources;
};
}
......@@ -176,6 +180,10 @@ QByteArray ProviderPrivate::jsonData() const
obj.insert(QStringLiteral("startCount"), startCount);
obj.insert(QStringLiteral("usageTime"), currentApplicationTime());
obj.insert(QStringLiteral("version"), QCoreApplication::applicationVersion());
foreach (auto source, dataSources) {
if (statisticsMode >= source->collectionMode())
source->toJson(obj);
}
}
QJsonDocument doc(obj);
......@@ -302,6 +310,13 @@ void Provider::setStatisticsCollectionMode(StatisticsCollectionMode mode)
d->scheduleEncouragement();
}
void Provider::addDataSource(AbstractDataSource *source, StatisticsCollectionMode mode)
{
Q_ASSERT(mode != NoStatistics);
source->setCollectionMode(mode);
d->dataSources.push_back(source);
}
int Provider::surveyInterval() const
{
return d->surveyInterval;
......
......@@ -26,6 +26,7 @@
namespace UserFeedback {
class AbstractDataSource;
class ProviderPrivate;
class SurveyInfo;
......@@ -61,6 +62,14 @@ public:
/** Set which statistics should be submitted. */
void setStatisticsCollectionMode(StatisticsCollectionMode mode);
/** Adds a data source for statistical data collection.
* @param source The data source to add.
* @param mode The statistics collection mode this source belongs to. Data is only
* send to the server for this source is a sufficiently high collection mode is configured
* by the user. @c NoStatistics is not allowed.
*/
void addDataSource(AbstractDataSource *source, StatisticsCollectionMode mode);
/** Returns the minimum time between two surveys in days. */
int surveyInterval() const;
......
......@@ -19,6 +19,7 @@
#include "ui_orwell.h"
#include <provider/widgets/feedbackconfigdialog.h>
#include <provider/core/platforminfosource.h>
#include <provider/core/provider.h>
#include <provider/core/surveyinfo.h>
......@@ -96,6 +97,7 @@ int main(int argc, char** argv)
provider->setSubmissionInterval(1);
provider->setApplicationStartsUntilEncouragement(5);
provider->setEncouragementDelay(10);
provider->addDataSource(new UserFeedback::PlatformInfoSource, UserFeedback::Provider::AllStatistics);
Orwell mainWindow;
mainWindow.show();
......
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