Commit bd57dafb authored by Volker Krause's avatar Volker Krause
Browse files

Port usage time to AbstractDataSource too

parent 997f7a7a
......@@ -21,6 +21,7 @@
#include <provider/core/qtversionsource.h>
#include <provider/core/screeninfosource.h>
#include <provider/core/startcountsource.h>
#include <provider/core/usagetimesource.h>
#include <QDebug>
#include <QtTest/qtest.h>
......@@ -152,6 +153,18 @@ private slots:
QVERIFY(m.contains(QLatin1String("value")));
QVERIFY(m.value(QLatin1String("value")).toInt() >= 1);
}
void testUsageTimeSource()
{
Provider p;
auto src = new UsageTimeSource;
QVERIFY(!src->description().isEmpty());
p.addDataSource(src, Provider::AllStatistics);
QTest::qWait(1200);
const auto m = src->data().toMap();
QVERIFY(m.contains(QLatin1String("value")));
QVERIFY(m.value(QLatin1String("value")).toInt() >= 1);
}
};
QTEST_MAIN(DataSourceTest)
......
......@@ -34,6 +34,7 @@
#include <provider/core/provider.h>
#include <provider/core/qtversionsource.h>
#include <provider/core/startcountsource.h>
#include <provider/core/usagetimesource.h>
#include <QApplication>
#include <QDebug>
......@@ -147,6 +148,7 @@ MainWindow::MainWindow() :
m_feedbackProvider->addDataSource(new PlatformInfoSource, Provider::AllStatistics);
m_feedbackProvider->addDataSource(new QtVersionSource, Provider::AllStatistics);
m_feedbackProvider->addDataSource(new StartCountSource, Provider::BasicStatistics);
m_feedbackProvider->addDataSource(new UsageTimeSource, Provider::BasicStatistics);
}
MainWindow::~MainWindow()
......
......@@ -7,6 +7,7 @@ set(userfeedback_core_srcs
screeninfosource.cpp
startcountsource.cpp
surveyinfo.cpp
usagetimesource.cpp
)
if(Qt5Core_FOUND)
......
......@@ -22,6 +22,7 @@
#include "abstractdatasource.h"
#include "startcountsource.h"
#include "surveyinfo.h"
#include "usagetimesource.h"
#include <QCoreApplication>
#include <QDebug>
......@@ -133,9 +134,6 @@ QByteArray ProviderPrivate::jsonData() const
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QJsonObject obj;
if (statisticsMode != Provider::NoStatistics) {
QJsonObject valueObj;
valueObj.insert(QStringLiteral("value"), currentApplicationTime());
obj.insert(QStringLiteral("usageTime"), valueObj);
foreach (auto source, dataSources) {
if (statisticsMode < source->collectionMode())
continue;
......@@ -303,6 +301,8 @@ void Provider::addDataSource(AbstractDataSource *source, StatisticsCollectionMod
// 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);
if (auto timeSrc = dynamic_cast<UsageTimeSource*>(source))
timeSrc->setProvider(d);
d->dataSources.push_back(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/>.
*/
#include "usagetimesource.h"
#include "abstractdatasource_p.h"
#include "provider_p.h"
#include <QVariant>
using namespace UserFeedback;
namespace UserFeedback {
class UsageTimeSourcePrivate : public AbstractDataSourcePrivate
{
public:
UsageTimeSourcePrivate() : provider(nullptr) {}
ProviderPrivate *provider;
};
}
UsageTimeSource::UsageTimeSource() :
AbstractDataSource(QStringLiteral("usageTime"), new UsageTimeSourcePrivate)
{
}
QString UsageTimeSource::description() const
{
return tr("The total amount of time the application has been used.");
}
QVariant UsageTimeSource::data()
{
Q_D(UsageTimeSource);
Q_ASSERT(d->provider);
QVariantMap m;
m.insert(QStringLiteral("value"), d->provider->currentApplicationTime());
return m;
}
void UsageTimeSource::setProvider(ProviderPrivate* p)
{
Q_D(UsageTimeSource);
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_USAGETIMESOURCE_H
#define USERFEEDBACK_USAGETIMESOURCE_H
#include "userfeedbackcore_export.h"
#include "abstractdatasource.h"
namespace UserFeedback {
class Provider;
class ProviderPrivate;
class UsageTimeSourcePrivate;
/** Data source reporting the total usage time of the application. */
class USERFEEDBACKCORE_EXPORT UsageTimeSource : public AbstractDataSource
{
public:
Q_DECLARE_TR_FUNCTIONS(UsageTimeSource)
public:
UsageTimeSource();
QString description() const override;
QVariant data() override;
private:
Q_DECLARE_PRIVATE(UsageTimeSource)
friend class Provider;
void setProvider(ProviderPrivate *p);
};
}
#endif // USERFEEDBACK_USAGETIMESOURCE_H
......@@ -27,6 +27,7 @@
#include <provider/core/screeninfosource.h>
#include <provider/core/startcountsource.h>
#include <provider/core/surveyinfo.h>
#include <provider/core/usagetimesource.h>
#include <QApplication>
#include <QDesktopServices>
......@@ -113,6 +114,7 @@ int main(int argc, char** argv)
provider->addDataSource(new UserFeedback::QtVersionSource, UserFeedback::Provider::BasicStatistics);
provider->addDataSource(new UserFeedback::ScreenInfoSource, UserFeedback::Provider::AllStatistics);
provider->addDataSource(new UserFeedback::StartCountSource, UserFeedback::Provider::BasicStatistics);
provider->addDataSource(new UserFeedback::UsageTimeSource, 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