Changeset View
Changeset View
Standalone View
Standalone View
src/provider/core/provider.cpp
| Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Line(s) | 122 | #ifdef Q_OS_MAC | |||
|---|---|---|---|---|---|
| 123 | QStringLiteral("kde.org"); | 123 | QStringLiteral("kde.org"); | ||
| 124 | #else | 124 | #else | ||
| 125 | QStringLiteral("KDE"); | 125 | QStringLiteral("KDE"); | ||
| 126 | #endif | 126 | #endif | ||
| 127 | std::unique_ptr<QSettings> s(new QSettings(org, QStringLiteral("UserFeedback"))); | 127 | std::unique_ptr<QSettings> s(new QSettings(org, QStringLiteral("UserFeedback"))); | ||
| 128 | return s; | 128 | return s; | ||
| 129 | } | 129 | } | ||
| 130 | 130 | | |||
| 131 | void ProviderPrivate::load() | 131 | bool ProviderPrivate::load() | ||
| 132 | { | 132 | { | ||
| 133 | if (!q->isEnabled()) | ||||
| 134 | return false; | ||||
| 133 | auto s = makeSettings(); | 135 | auto s = makeSettings(); | ||
| 134 | s->beginGroup(QStringLiteral("UserFeedback")); | 136 | s->beginGroup(QStringLiteral("UserFeedback")); | ||
| 135 | lastSubmitTime = s->value(QStringLiteral("LastSubmission")).toDateTime(); | 137 | lastSubmitTime = s->value(QStringLiteral("LastSubmission")).toDateTime(); | ||
| 136 | 138 | | |||
| 137 | const auto modeStr = s->value(QStringLiteral("StatisticsCollectionMode")).toByteArray(); | 139 | const auto modeStr = s->value(QStringLiteral("StatisticsCollectionMode")).toByteArray(); | ||
| 138 | telemetryMode = static_cast<Provider::TelemetryMode>(std::max(telemetryModeEnum().keyToValue(modeStr.constData()), 0)); | 140 | telemetryMode = static_cast<Provider::TelemetryMode>(std::max(telemetryModeEnum().keyToValue(modeStr.constData()), 0)); | ||
| 139 | 141 | | |||
| 140 | surveyInterval = s->value(QStringLiteral("SurveyInterval"), -1).toInt(); | 142 | surveyInterval = s->value(QStringLiteral("SurveyInterval"), -1).toInt(); | ||
| Show All 12 Lines | 153 | foreach (auto source, dataSources) { | |||
| 153 | source->load(s.get()); | 155 | source->load(s.get()); | ||
| 154 | s->endGroup(); | 156 | s->endGroup(); | ||
| 155 | } | 157 | } | ||
| 156 | 158 | | |||
| 157 | auto g = makeGlobalSettings(); | 159 | auto g = makeGlobalSettings(); | ||
| 158 | g->beginGroup(QStringLiteral("UserFeedback")); | 160 | g->beginGroup(QStringLiteral("UserFeedback")); | ||
| 159 | lastSurveyTime = std::max(g->value(QStringLiteral("LastSurvey")).toDateTime(), lastSurveyTime); | 161 | lastSurveyTime = std::max(g->value(QStringLiteral("LastSurvey")).toDateTime(), lastSurveyTime); | ||
| 160 | lastEncouragementTime = std::max(g->value(QStringLiteral("LastEncouragement")).toDateTime(), lastEncouragementTime); | 162 | lastEncouragementTime = std::max(g->value(QStringLiteral("LastEncouragement")).toDateTime(), lastEncouragementTime); | ||
| 163 | | ||||
| 164 | return true; | ||||
| 161 | } | 165 | } | ||
| 162 | 166 | | |||
| 163 | void ProviderPrivate::store() | 167 | void ProviderPrivate::store() | ||
| 164 | { | 168 | { | ||
| 169 | if (!q->isEnabled()) | ||||
| 170 | return; | ||||
| 165 | auto s = makeSettings(); | 171 | auto s = makeSettings(); | ||
| 166 | s->beginGroup(QStringLiteral("UserFeedback")); | 172 | s->beginGroup(QStringLiteral("UserFeedback")); | ||
| 167 | 173 | | |||
| 168 | // another process might have changed this, so read the base value first before writing | 174 | // another process might have changed this, so read the base value first before writing | ||
| 169 | usageTime = std::max(s->value(QStringLiteral("ApplicationTime"), 0).toInt(), usageTime); | 175 | usageTime = std::max(s->value(QStringLiteral("ApplicationTime"), 0).toInt(), usageTime); | ||
| 170 | s->setValue(QStringLiteral("ApplicationTime"), currentApplicationTime()); | 176 | s->setValue(QStringLiteral("ApplicationTime"), currentApplicationTime()); | ||
| 171 | usageTime = currentApplicationTime(); | 177 | usageTime = currentApplicationTime(); | ||
| 172 | startTime.restart(); | 178 | startTime.restart(); | ||
| ▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Line(s) | 398 | if (lastEncouragementTime.isValid()) { | |||
| 394 | const auto targetTime = lastEncouragementTime.addDays(encouragementInterval); | 400 | const auto targetTime = lastEncouragementTime.addDays(encouragementInterval); | ||
| 395 | timeToEncouragement = std::max(timeToEncouragement, (int)QDateTime::currentDateTime().secsTo(targetTime)); | 401 | timeToEncouragement = std::max(timeToEncouragement, (int)QDateTime::currentDateTime().secsTo(targetTime)); | ||
| 396 | } | 402 | } | ||
| 397 | encouragementTimer.start(timeToEncouragement * 1000); | 403 | encouragementTimer.start(timeToEncouragement * 1000); | ||
| 398 | } | 404 | } | ||
| 399 | 405 | | |||
| 400 | void ProviderPrivate::emitShowEncouragementMessage() | 406 | void ProviderPrivate::emitShowEncouragementMessage() | ||
| 401 | { | 407 | { | ||
| 408 | if (!q->isEnabled()) // encouragement disabled by user | ||||
| 409 | return; | ||||
| 402 | lastEncouragementTime = QDateTime::currentDateTime(); // TODO make this explicit, in case the host application decides to delay? | 410 | lastEncouragementTime = QDateTime::currentDateTime(); // TODO make this explicit, in case the host application decides to delay? | ||
| 403 | storeOne(QStringLiteral("LastEncouragement"), lastEncouragementTime); | 411 | storeOne(QStringLiteral("LastEncouragement"), lastEncouragementTime); | ||
| 404 | storeOneGlobal(QStringLiteral("LastEncouragement"), lastEncouragementTime); | 412 | storeOneGlobal(QStringLiteral("LastEncouragement"), lastEncouragementTime); | ||
| 405 | emit q->showEncouragementMessage(); | 413 | emit q->showEncouragementMessage(); | ||
| 406 | } | 414 | } | ||
| 407 | 415 | | |||
| 408 | 416 | | |||
| 409 | Provider::Provider(QObject *parent) : | 417 | Provider::Provider(QObject *parent) : | ||
| Show All 40 Lines | |||||
| 450 | 458 | | |||
| 451 | void Provider::setProductIdentifier(const QString &productId) | 459 | void Provider::setProductIdentifier(const QString &productId) | ||
| 452 | { | 460 | { | ||
| 453 | Q_ASSERT(!productId.isEmpty()); | 461 | Q_ASSERT(!productId.isEmpty()); | ||
| 454 | if (productId == d->productId) | 462 | if (productId == d->productId) | ||
| 455 | return; | 463 | return; | ||
| 456 | d->productId = productId; | 464 | d->productId = productId; | ||
| 457 | 465 | | |||
| 458 | d->load(); | 466 | if (!d->load()) { | ||
| 467 | emit providerSettingsChanged(); | ||||
| 468 | return; | ||||
| 469 | } | ||||
| 470 | | ||||
| 459 | d->startCount++; | 471 | d->startCount++; | ||
| 460 | d->storeOne(QStringLiteral("ApplicationStartCount"), d->startCount); | 472 | d->storeOne(QStringLiteral("ApplicationStartCount"), d->startCount); | ||
| 461 | 473 | | |||
| 462 | emit providerSettingsChanged(); | 474 | emit providerSettingsChanged(); | ||
| 463 | 475 | | |||
| 464 | d->scheduleEncouragement(); | 476 | d->scheduleEncouragement(); | ||
| 465 | d->scheduleNextSubmission(); | 477 | d->scheduleNextSubmission(); | ||
| 466 | } | 478 | } | ||
| ▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines | |||||