use default widget configuration to configure telemetry

This commit is contained in:
2016-10-30 09:04:08 +03:00
parent 0332c59daf
commit a189e1af38
8 changed files with 45 additions and 68 deletions

View File

@ -34,14 +34,10 @@ AWTelemetryHandler::AWTelemetryHandler(QObject *parent, const QString clientId)
{
qCDebug(LOG_AW) << __PRETTY_FUNCTION__;
m_genericConfig = QString("%1/awesomewidgets/general.ini")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation));
m_localFile = QString("%1/awesomewidgets/telemetry.ini")
.arg(QStandardPaths::writableLocation(
QStandardPaths::GenericDataLocation));
init();
// override client id if any
if (!clientId.isEmpty())
m_clientId = clientId;
@ -78,6 +74,16 @@ QString AWTelemetryHandler::getLast(const QString group) const
}
void AWTelemetryHandler::init(const int count, const bool enableRemote, const QString clientId)
{
qCDebug(LOG_AW) << "Init telemetry with count" << count << "enable remote" << enableRemote << "client ID" << clientId;
m_storeCount = count;
m_uploadEnabled = enableRemote;
m_clientId = clientId;
}
bool AWTelemetryHandler::put(const QString group, const QString value) const
{
qCDebug(LOG_AW) << "Store data with group" << group << "and value" << value;
@ -181,44 +187,3 @@ QString AWTelemetryHandler::getKey(const int count) const
return QString("%1").arg(count, 3, 10, QChar('0'));
}
void AWTelemetryHandler::init()
{
QSettings settings(m_genericConfig, QSettings::IniFormat);
settings.beginGroup(QString("Telemetry"));
// unique client id
m_clientId
= settings.value(QString("ClientID"), QUuid::createUuid().toString())
.toString();
setConfiguration(QString("ClientID"), m_clientId, false);
// count items to store
m_storeCount = settings.value(QString("StoreHistory"), 100).toInt();
setConfiguration(QString("StoreHistory"), m_storeCount, false);
// check if upload enabled
m_uploadEnabled = settings.value(QString("Upload"), false).toBool();
setConfiguration(QString("Upload"), m_uploadEnabled, false);
settings.endGroup();
}
bool AWTelemetryHandler::setConfiguration(const QString key,
const QVariant value,
const bool override) const
{
qCDebug(LOG_AW) << "Set configuration key" << key << "to value" << value
<< "force override enabled" << override;
QSettings settings(m_genericConfig, QSettings::IniFormat);
settings.beginGroup(QString("Telemetry"));
if (settings.childKeys().contains(key) && !override)
return true;
settings.setValue(key, value);
settings.endGroup();
settings.sync();
return (settings.status() == QSettings::NoError);
}