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

Streamline the API for adding data sources

parent f9968ae8
......@@ -202,7 +202,7 @@ private slots:
Provider p;
auto src = new StartCountSource;
QVERIFY(!src->description().isEmpty());
p.addDataSource(src, Provider::DetailedUsageStatistics);
p.addDataSource(src);
const auto m = src->data().toMap();
QVERIFY(m.contains(QLatin1String("value")));
QVERIFY(m.value(QLatin1String("value")).toInt() >= 1);
......@@ -213,7 +213,8 @@ private slots:
Provider p;
auto src = new UsageTimeSource;
QVERIFY(!src->description().isEmpty());
p.addDataSource(src, Provider::DetailedUsageStatistics);
src->setTelemetryMode(Provider::DetailedUsageStatistics);
p.addDataSource(src);
QTest::qWait(1200);
const auto m = src->data().toMap();
QVERIFY(m.contains(QLatin1String("value")));
......
......@@ -46,8 +46,8 @@ private slots:
{
Provider p;
p.setProductIdentifier(QStringLiteral("org.kde.UserFeedback.UnitTestProduct"));
p.addDataSource(new ScreenInfoSource, Provider::BasicSystemInformation);
p.addDataSource(new PlatformInfoSource, Provider::DetailedSystemInformation);
p.addDataSource(new ScreenInfoSource);
p.addDataSource(new PlatformInfoSource);
p.setTelemetryMode(Provider::NoTelemetry);
FeedbackConfigWidget w;
......
......@@ -55,8 +55,8 @@ private slots:
{
Provider provider;
provider.setProductIdentifier(QStringLiteral("org.kde.UserFeedback.UnitTestProduct"));
provider.addDataSource(new ScreenInfoSource, Provider::BasicSystemInformation);
provider.addDataSource(new PlatformInfoSource, Provider::BasicSystemInformation);
provider.addDataSource(new ScreenInfoSource);
provider.addDataSource(new PlatformInfoSource);
provider.setTelemetryMode(Provider::NoTelemetry);
QByteArray b;
QMetaObject::invokeMethod(&provider, "jsonData", Q_RETURN_ARG(QByteArray, b), Q_ARG(KUserFeedback::Provider::TelemetryMode, provider.telemetryMode()));
......@@ -154,7 +154,7 @@ private slots:
{
Provider p;
p.addDataSource(new PlatformInfoSource, Provider::BasicSystemInformation);
p.addDataSource(new PlatformInfoSource);
p.setSurveyInterval(0);
p.setTelemetryMode(Provider::BasicSystemInformation);
QSignalSpy spy(&p, SIGNAL(showEncouragementMessage()));
......@@ -221,14 +221,16 @@ private slots:
{
Provider p1;
auto s1 = new StartCountSource;
p1.addDataSource(s1, Provider:: BasicUsageStatistics);
s1->setTelemetryMode(Provider:: BasicUsageStatistics);
p1.addDataSource(s1);
c1 = s1->data().toMap().value(QLatin1String("value")).toInt();
int c2 = -1;
{
Provider p2;
auto s2 = new StartCountSource;
p2.addDataSource(s2, Provider:: BasicUsageStatistics);
s2->setTelemetryMode(Provider::BasicUsageStatistics);
p2.addDataSource(s2);
c2 = s2->data().toMap().value(QLatin1String("value")).toInt();
}
......@@ -237,7 +239,8 @@ private slots:
Provider p3;
auto s3 = new StartCountSource;
p3.addDataSource(s3, Provider:: BasicUsageStatistics);
s3->setTelemetryMode(Provider::BasicUsageStatistics);
p3.addDataSource(s3);
int c3 = s3->data().toMap().value(QLatin1String("value")).toInt();
QVERIFY(c3 == c1 + 2);
}
......@@ -252,7 +255,8 @@ private slots:
{
Provider p1;
auto s1 = new StartCountSource;
p1.addDataSource(s1, Provider::BasicUsageStatistics);
s1->setTelemetryMode(Provider::BasicUsageStatistics);
p1.addDataSource(s1);
p1.setSurveyInterval(90);
const auto c0 = s1->data().toMap().value(QLatin1String("value")).toInt();
......@@ -266,7 +270,8 @@ private slots:
{
Provider p2;
auto s2 = new StartCountSource;
p2.addDataSource(s2, Provider::BasicUsageStatistics);
s2->setTelemetryMode(Provider::BasicUsageStatistics);
p2.addDataSource(s2);
p2.setProductIdentifier(QStringLiteral("org.kde.some.other.test"));
QCOMPARE(p2.surveyInterval(), 1);
const auto c2 = s2->data().toMap().value(QLatin1String("value")).toInt();
......
......@@ -103,8 +103,8 @@ private slots:
provider.setProductIdentifier(QStringLiteral("org.kde.UserFeedback.UnitTestProduct"));
provider.setTelemetryMode(Provider::DetailedUsageStatistics);
provider.setFeedbackServer(serverUrl);
provider.addDataSource(new ScreenInfoSource, Provider::DetailedUsageStatistics);
provider.addDataSource(new PlatformInfoSource, Provider::DetailedUsageStatistics);
provider.addDataSource(new ScreenInfoSource);
provider.addDataSource(new PlatformInfoSource);
provider.submit();
QTest::qWait(100); // HACK submit is async
......@@ -145,8 +145,8 @@ private slots:
provider.setProductIdentifier(QStringLiteral("org.kde.UserFeedback.UnitTestProduct"));
provider.setTelemetryMode(Provider::DetailedUsageStatistics);
provider.setFeedbackServer(serverUrl);
provider.addDataSource(new ScreenInfoSource, Provider::DetailedUsageStatistics);
provider.addDataSource(new PlatformInfoSource, Provider::DetailedUsageStatistics);
provider.addDataSource(new ScreenInfoSource);
provider.addDataSource(new PlatformInfoSource);
provider.submit();
QTest::qWait(500); // HACK submit is async, and we have no way of knowning the redirect loop ended...
}
......
......@@ -182,12 +182,13 @@ MainWindow::MainWindow() :
viewModeSource->addValueMapping(0, QStringLiteral("analytics"));
viewModeSource->addValueMapping(1, QStringLiteral("surveyEditor"));
viewModeSource->addValueMapping(2, QStringLiteral("schemaEditor"));
m_feedbackProvider->addDataSource(viewModeSource, Provider::DetailedUsageStatistics);
m_feedbackProvider->addDataSource(new ApplicationVersionSource, Provider::BasicSystemInformation);
m_feedbackProvider->addDataSource(new PlatformInfoSource, Provider::BasicSystemInformation);
m_feedbackProvider->addDataSource(new QtVersionSource, Provider::BasicSystemInformation);
m_feedbackProvider->addDataSource(new StartCountSource, Provider::BasicUsageStatistics);
m_feedbackProvider->addDataSource(new UsageTimeSource, Provider::BasicUsageStatistics);
viewModeSource->setTelemetryMode(Provider::DetailedUsageStatistics);
m_feedbackProvider->addDataSource(viewModeSource);
m_feedbackProvider->addDataSource(new ApplicationVersionSource);
m_feedbackProvider->addDataSource(new PlatformInfoSource);
m_feedbackProvider->addDataSource(new QtVersionSource);
m_feedbackProvider->addDataSource(new StartCountSource);
m_feedbackProvider->addDataSource(new UsageTimeSource);
m_feedbackProvider->setEncouragementDelay(60);
m_feedbackProvider->setEncouragementInterval(5);
......
......@@ -509,10 +509,8 @@ void Provider::setTelemetryMode(TelemetryMode mode)
emit telemetryModeChanged();
}
void Provider::addDataSource(AbstractDataSource *source, TelemetryMode mode)
void Provider::addDataSource(AbstractDataSource *source)
{
source->setTelemetryMode(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);
......
......@@ -162,11 +162,8 @@ public:
/*! Adds a data source for telemetry data collection.
* @param source The data source to add. The Provider takes ownership of @p source.
* @param mode The telemetry 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 NoTelemetry is not allowed.
*/
void addDataSource(AbstractDataSource *source, TelemetryMode mode);
void addDataSource(AbstractDataSource *source);
/*! Returns all data sources that have been added to this provider.
* @see addDataSource
......
......@@ -31,7 +31,7 @@ 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->telemetryMode());
static_cast<Provider*>(prop->object->parent())->addDataSource(value->source());
}
int QmlProviderExtension::sourceCount(QQmlListProperty<QmlAbstractDataSource> *prop)
......
......@@ -40,10 +40,10 @@ int main(int argc, char **argv)
QApplication app(argc, argv);
Provider provider;
provider.addDataSource(new ApplicationVersionSource, Provider::BasicSystemInformation);
provider.addDataSource(new PlatformInfoSource, Provider::BasicSystemInformation);
provider.addDataSource(new ScreenInfoSource, Provider::DetailedSystemInformation);
provider.addDataSource(new QtVersionSource, Provider::DetailedSystemInformation);
provider.addDataSource(new ApplicationVersionSource);
provider.addDataSource(new PlatformInfoSource);
provider.addDataSource(new ScreenInfoSource);
provider.addDataSource(new QtVersionSource);
FeedbackConfigDialog w;
w.setFeedbackProvider(&provider);
......
......@@ -74,7 +74,8 @@ Orwell::Orwell(QWidget* parent) :
propertyMonitorSource->setDescription(QStringLiteral("The dial position."));
propertyMonitorSource->addValueMapping(0, QStringLiteral("off"));
propertyMonitorSource->addValueMapping(11, QStringLiteral("max"));
provider->addDataSource(propertyMonitorSource, KUserFeedback::Provider::DetailedUsageStatistics);
propertyMonitorSource->setTelemetryMode(KUserFeedback::Provider::DetailedUsageStatistics);
provider->addDataSource(propertyMonitorSource);
auto notifyPopup = new KUserFeedback::NotificationPopup(this);
notifyPopup->setFeedbackProvider(provider.get());
}
......@@ -115,17 +116,17 @@ int main(int argc, char** argv)
provider->setSubmissionInterval(1);
provider->setApplicationStartsUntilEncouragement(5);
provider->setEncouragementDelay(10);
provider->addDataSource(new KUserFeedback::ApplicationVersionSource, KUserFeedback::Provider::BasicSystemInformation);
provider->addDataSource(new KUserFeedback::CompilerInfoSource, KUserFeedback::Provider::BasicSystemInformation);
provider->addDataSource(new KUserFeedback::CpuInfoSource, KUserFeedback::Provider::DetailedSystemInformation);
provider->addDataSource(new KUserFeedback::LocaleInfoSource, KUserFeedback::Provider::DetailedSystemInformation);
provider->addDataSource(new KUserFeedback::OpenGLInfoSource, KUserFeedback::Provider::DetailedSystemInformation);
provider->addDataSource(new KUserFeedback::PlatformInfoSource, KUserFeedback::Provider::BasicSystemInformation);
provider->addDataSource(new KUserFeedback::QtVersionSource, KUserFeedback::Provider::BasicSystemInformation);
provider->addDataSource(new KUserFeedback::ScreenInfoSource, KUserFeedback::Provider::DetailedSystemInformation);
provider->addDataSource(new KUserFeedback::StartCountSource, KUserFeedback::Provider::BasicUsageStatistics);
provider->addDataSource(new KUserFeedback::UsageTimeSource, KUserFeedback::Provider::BasicUsageStatistics);
provider->addDataSource(new KUserFeedback::StyleInfoSource, KUserFeedback::Provider::DetailedSystemInformation);
provider->addDataSource(new KUserFeedback::ApplicationVersionSource);
provider->addDataSource(new KUserFeedback::CompilerInfoSource);
provider->addDataSource(new KUserFeedback::CpuInfoSource);
provider->addDataSource(new KUserFeedback::LocaleInfoSource);
provider->addDataSource(new KUserFeedback::OpenGLInfoSource);
provider->addDataSource(new KUserFeedback::PlatformInfoSource);
provider->addDataSource(new KUserFeedback::QtVersionSource);
provider->addDataSource(new KUserFeedback::ScreenInfoSource);
provider->addDataSource(new KUserFeedback::StartCountSource);
provider->addDataSource(new KUserFeedback::UsageTimeSource);
provider->addDataSource(new KUserFeedback::StyleInfoSource);
Orwell mainWindow;
mainWindow.show();
......
......@@ -95,16 +95,16 @@ ApplicationWindow {
}
}
KUserFeedback.ApplicationVersionSource { mode: KUserFeedback.Provider.BasicSystemInformation }
KUserFeedback.CompilerInfoSource { mode: KUserFeedback.Provider.BasicSystemInformation }
KUserFeedback.CpuInfoSource { mode: KUserFeedback.Provider.DetailedSystemInformation }
KUserFeedback.LocaleInfoSource { mode: KUserFeedback.Provider.DetailedSystemInformation }
KUserFeedback.OpenGLInfoSource{ mode: KUserFeedback.Provider.DetailedSystemInformation }
KUserFeedback.PlatformInfoSource { mode: KUserFeedback.Provider.BasicSystemInformation }
KUserFeedback.QtVersionSource { mode: KUserFeedback.Provider.BasicSystemInformation }
KUserFeedback.ScreenInfoSource { mode: KUserFeedback.Provider.DetailedSystemInformation }
KUserFeedback.StartCountSource { mode: KUserFeedback.Provider.BasicUsageStatistics }
KUserFeedback.UsageTimeSource { mode: KUserFeedback.Provider.BasicUsageStatistics }
KUserFeedback.ApplicationVersionSource {}
KUserFeedback.CompilerInfoSource {}
KUserFeedback.CpuInfoSource {}
KUserFeedback.LocaleInfoSource {}
KUserFeedback.OpenGLInfoSource{}
KUserFeedback.PlatformInfoSource {}
KUserFeedback.QtVersionSource {}
KUserFeedback.ScreenInfoSource {}
KUserFeedback.StartCountSource {}
KUserFeedback.UsageTimeSource {}
KUserFeedback.PropertyRatioSource {
id: dialRatioSource
......
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