Commit 997f7a7a authored by Volker Krause's avatar Volker Krause
Browse files

Port start count reporting to AbstractDataSource

This makes it show up in the configuration dialog correctly.
parent a7568d74
......@@ -20,6 +20,7 @@
#include <provider/core/propertyratiosource.h>
#include <provider/core/qtversionsource.h>
#include <provider/core/screeninfosource.h>
#include <provider/core/startcountsource.h>
#include <QDebug>
#include <QtTest/qtest.h>
......@@ -140,6 +141,17 @@ private slots:
QVERIFY(m.contains(QLatin1String("value")));
QCOMPARE(m.value(QLatin1String("value")).toString(), QLatin1String(QT_VERSION_STR));
}
void testStartCountSource()
{
Provider p;
auto src = new StartCountSource;
QVERIFY(!src->description().isEmpty());
p.addDataSource(src, Provider::AllStatistics);
const auto m = src->data().toMap();
QVERIFY(m.contains(QLatin1String("value")));
QVERIFY(m.value(QLatin1String("value")).toInt() >= 1);
}
};
QTEST_MAIN(DataSourceTest)
......
......@@ -33,6 +33,7 @@
#include <provider/core/propertyratiosource.h>
#include <provider/core/provider.h>
#include <provider/core/qtversionsource.h>
#include <provider/core/startcountsource.h>
#include <QApplication>
#include <QDebug>
......@@ -145,6 +146,7 @@ MainWindow::MainWindow() :
m_feedbackProvider->addDataSource(new ApplicationVersionSource, Provider::BasicStatistics);
m_feedbackProvider->addDataSource(new PlatformInfoSource, Provider::AllStatistics);
m_feedbackProvider->addDataSource(new QtVersionSource, Provider::AllStatistics);
m_feedbackProvider->addDataSource(new StartCountSource, Provider::BasicStatistics);
}
MainWindow::~MainWindow()
......
......@@ -5,6 +5,7 @@ set(userfeedback_core_srcs
provider.cpp
qtversionsource.cpp
screeninfosource.cpp
startcountsource.cpp
surveyinfo.cpp
)
......
......@@ -20,6 +20,7 @@
#include "provider.h"
#include "provider_p.h"
#include "abstractdatasource.h"
#include "startcountsource.h"
#include "surveyinfo.h"
#include <QCoreApplication>
......@@ -133,8 +134,6 @@ QByteArray ProviderPrivate::jsonData() const
QJsonObject obj;
if (statisticsMode != Provider::NoStatistics) {
QJsonObject valueObj;
valueObj.insert(QStringLiteral("value"), startCount);
obj.insert(QStringLiteral("startCount"), valueObj);
valueObj.insert(QStringLiteral("value"), currentApplicationTime());
obj.insert(QStringLiteral("usageTime"), valueObj);
foreach (auto source, dataSources) {
......@@ -300,6 +299,11 @@ void Provider::addDataSource(AbstractDataSource *source, StatisticsCollectionMod
Q_ASSERT(mode != NoStatistics);
Q_ASSERT(!source->description().isEmpty());
source->setCollectionMode(mode);
// special cases for sources where we track the data here, as it's needed even if we don't report it
if (auto countSrc = dynamic_cast<StartCountSource*>(source))
countSrc->setProvider(d);
d->dataSources.push_back(source);
QSettings settings;
......
/*
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 "startcountsource.h"
#include "abstractdatasource_p.h"
#include "provider_p.h"
#include <QVariant>
using namespace UserFeedback;
namespace UserFeedback {
class StartCountSourcePrivate : public AbstractDataSourcePrivate
{
public:
StartCountSourcePrivate() : provider(nullptr) {}
ProviderPrivate *provider;
};
}
StartCountSource::StartCountSource() :
AbstractDataSource(QStringLiteral("startCount"), new StartCountSourcePrivate)
{
}
QString StartCountSource::description() const
{
return tr("How often the application has been started.");
}
QVariant StartCountSource::data()
{
Q_D(StartCountSource);
Q_ASSERT(d->provider);
QVariantMap m;
m.insert(QStringLiteral("value"), d->provider->startCount);
return m;
}
void StartCountSource::setProvider(ProviderPrivate *p)
{
Q_D(StartCountSource);
d->provider = p;
}
/*
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_STARTCOUNTSOURCE_H
#define USERFEEDBACK_STARTCOUNTSOURCE_H
#include "userfeedbackcore_export.h"
#include "abstractdatasource.h"
namespace UserFeedback {
class Provider;
class ProviderPrivate;
class StartCountSourcePrivate;
/** Data source reporting the total amount of applications starts. */
class USERFEEDBACKCORE_EXPORT StartCountSource : public AbstractDataSource
{
Q_DECLARE_TR_FUNCTIONS(StartCountSource)
public:
StartCountSource();
QString description() const override;
QVariant data() override;
private:
Q_DECLARE_PRIVATE(StartCountSource)
friend class Provider;
void setProvider(ProviderPrivate *p);
};
}
#endif // USERFEEDBACK_STARTCOUNTSOURCE_H
......@@ -25,6 +25,7 @@
#include <provider/core/provider.h>
#include <provider/core/qtversionsource.h>
#include <provider/core/screeninfosource.h>
#include <provider/core/startcountsource.h>
#include <provider/core/surveyinfo.h>
#include <QApplication>
......@@ -111,6 +112,7 @@ int main(int argc, char** argv)
provider->addDataSource(new UserFeedback::PlatformInfoSource, UserFeedback::Provider::AllStatistics);
provider->addDataSource(new UserFeedback::QtVersionSource, UserFeedback::Provider::BasicStatistics);
provider->addDataSource(new UserFeedback::ScreenInfoSource, UserFeedback::Provider::AllStatistics);
provider->addDataSource(new UserFeedback::StartCountSource, UserFeedback::Provider::BasicStatistics);
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