Skip to content
Snippets Groups Projects
Commit 4f435677 authored by Vitaly Fanaskov's avatar Vitaly Fanaskov
Browse files

Basic implementation of Settings Functionality

parent 566d0b91
No related branches found
No related tags found
No related merge requests found
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company
** Contact: https://www.qt.io/licensing/
**
** Created 8/3/2019.
**
** This file is part of UsageStatistic plugin for Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "settings.h"
#include <QtCore/QSettings>
#include <KUserFeedback/AbstractDataSource>
#include <KUserFeedback/Provider>
namespace UsageStatistic::Internal::Settings {
using namespace KUserFeedback;
static const QString telemetryModeKey() { return QStringLiteral("telemetryMode"); }
static const QString sourcesActiveStateKey() { return QStringLiteral("sourcesActiveState"); }
using ActiveStateById = QPair<QString, bool>;
static QVariantList sourcesStatesById(const QVector<AbstractDataSource*> &dataSources)
{
QVariantList result;
for (auto &&src : dataSources) {
if (src) {
result << QVariant::fromValue(qMakePair(src->id(), src->isActive()));
}
}
return result;
}
static void restoreSourceStates(
const QVector<AbstractDataSource*> &dataSources, const QVariantList &states)
{
QHash<QString, AbstractDataSource*> sourcesById;
for (auto &&src : dataSources) {
if (src) {
sourcesById[src->id()] = src;
}
}
for (auto &&p : states) {
auto idAndActiveState = p.value<ActiveStateById>();
if (auto it = sourcesById.find(idAndActiveState.first); it != sourcesById.end()) {
(*it)->setActive(idAndActiveState.second);
}
}
}
static constexpr KUserFeedback::Provider::TelemetryMode telemetryModeDflt()
{ return KUserFeedback::Provider::NoTelemetry; }
void restore(const QSettings &settings, KUserFeedback::Provider &p)
{
p.setTelemetryMode(
Provider::TelemetryMode(settings.value(telemetryModeKey(), telemetryModeDflt()).toInt()));
restoreSourceStates(p.dataSources(), settings.value(sourcesActiveStateKey()).toList());
}
void store(QSettings &settings, const KUserFeedback::Provider &p)
{
settings.setValue(telemetryModeKey(), int(p.telemetryMode()));
settings.setValue(sourcesActiveStateKey(), sourcesStatesById(p.dataSources()));
}
} // namespace UsageStatistic::Internal::Settings
Q_DECLARE_METATYPE(UsageStatistic::Internal::Settings::ActiveStateById)
/****************************************************************************
**
** Copyright (C) 2019 The Qt Company
** Contact: https://www.qt.io/licensing/
**
** Created 8/3/2019.
**
** This file is part of UsageStatistic plugin for Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QtCore/QtGlobal>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
namespace KUserFeedback { class Provider; }
namespace UsageStatistic::Internal::Settings {
void restore(const QSettings &settings, KUserFeedback::Provider &p);
void store(QSettings &settings, const KUserFeedback::Provider &p);
} // namespace UsageStatistic::Internal::Settings
......@@ -20,7 +20,8 @@ SOURCES += \
datasources/examplesdatasource.cpp \
datasources/kitsource.cpp \
datasources/qmldesignerusagetimesource.cpp \
ui/usagestatisticpage.cpp
ui/usagestatisticpage.cpp \
common/settings.cpp
HEADERS += \
usagestatisticplugin.h \
......@@ -35,7 +36,8 @@ HEADERS += \
datasources/examplesdatasource.h \
datasources/kitsource.h \
datasources/qmldesignerusagetimesource.h \
ui/usagestatisticpage.h
ui/usagestatisticpage.h \
common/settings.h
# Qt Creator linking
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment