mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
use default widget configuration to configure telemetry
This commit is contained in:
parent
0332c59daf
commit
a189e1af38
@ -62,7 +62,10 @@
|
||||
<entry name="acOffline" type="string">
|
||||
<default>( )</default>
|
||||
</entry>
|
||||
<entry name="telemetry" type="bool">
|
||||
<entry name="telemetryCount" type="int">
|
||||
<default>100</default>
|
||||
</entry>
|
||||
<entry name="telemetryRemote" type="bool">
|
||||
<default>false</default>
|
||||
</entry>
|
||||
<entry name="telemetryId" type="string">
|
||||
|
@ -51,7 +51,8 @@ Item {
|
||||
property alias cfg_customUptime: customUptime.value
|
||||
property alias cfg_acOnline: acOnline.value
|
||||
property alias cfg_acOffline: acOffline.value
|
||||
property alias cfg_telemetry: telemetry.checked
|
||||
property alias cfg_telemetryCount: telemetryCount.value
|
||||
property alias cfg_telemetryRemote: telemetryRemote.checked
|
||||
property alias cfg_telemetryId: telemetryId.value
|
||||
|
||||
|
||||
@ -234,9 +235,17 @@ Item {
|
||||
height: implicitHeight
|
||||
width: parent.width
|
||||
CheckBoxSelector {
|
||||
id: telemetry
|
||||
id: telemetryRemote
|
||||
text: i18n("Enable remote telemetry")
|
||||
}
|
||||
IntegerSelector {
|
||||
id: telemetryCount
|
||||
maximumValue: 10000
|
||||
minimumValue: 0
|
||||
stepSize: 50
|
||||
text: i18n("History count")
|
||||
value: plasmoid.configuration.telemetryCount
|
||||
}
|
||||
LineSelector {
|
||||
id: telemetryId
|
||||
text: i18n("Telemetry ID")
|
||||
@ -249,17 +258,5 @@ Item {
|
||||
|
||||
Component.onCompleted: {
|
||||
if (debug) console.debug()
|
||||
|
||||
// generate UUID if missing
|
||||
if (telemetryId.value.length == 0)
|
||||
telemetryId.value = generateUuid()
|
||||
}
|
||||
|
||||
// code from http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
||||
function generateUuid() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +210,13 @@ Item {
|
||||
awKeys.setAggregatorProperty("customUptime", plasmoid.configuration.customUptime)
|
||||
awKeys.setAggregatorProperty("tempUnits", plasmoid.configuration.tempUnits)
|
||||
awKeys.setAggregatorProperty("translate", plasmoid.configuration.translateStrings)
|
||||
// update telemetry ID
|
||||
if (plasmoid.configuration.telemetryId.length == 0)
|
||||
plasmoid.configuration.telemetryId = generateUuid()
|
||||
// save telemetry
|
||||
awTelemetryHandler.init(plasmoid.configuration.telemetryCount,
|
||||
plasmoid.configuration.telemetryRemote,
|
||||
plasmoid.configuration.telemetryId)
|
||||
if (awTelemetryHandler.put("awwidgetconfig", plasmoid.configuration.text))
|
||||
awTelemetryHandler.uploadTelemetry("awwidgetconfig", plasmoid.configuration.text)
|
||||
}
|
||||
@ -241,4 +247,12 @@ Item {
|
||||
tagSelectorBox.model = awKeys.dictKeys(true)
|
||||
return tagSelector.open()
|
||||
}
|
||||
|
||||
// code from http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
|
||||
function generateUuid() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,6 @@ Item {
|
||||
AWActions {
|
||||
id: awActions
|
||||
}
|
||||
AWTelemetryHandler {
|
||||
id: awTelemetryHandler
|
||||
}
|
||||
|
||||
width: childrenRect.width
|
||||
height: childrenRect.height
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ public:
|
||||
virtual ~AWTelemetryHandler();
|
||||
Q_INVOKABLE QStringList get(const QString group) const;
|
||||
Q_INVOKABLE QString getLast(const QString group) const;
|
||||
Q_INVOKABLE void init(const int count, const bool enableRemote, const QString clientId);
|
||||
Q_INVOKABLE bool put(const QString group, const QString value) const;
|
||||
Q_INVOKABLE void uploadTelemetry(const QString group, const QString value);
|
||||
|
||||
@ -50,11 +51,7 @@ private slots:
|
||||
|
||||
private:
|
||||
QString getKey(const int count) const;
|
||||
void init();
|
||||
bool setConfiguration(const QString key, const QVariant value,
|
||||
const bool override) const;
|
||||
QString m_clientId;
|
||||
QString m_genericConfig;
|
||||
QString m_localFile;
|
||||
int m_storeCount = 0;
|
||||
bool m_uploadEnabled = false;
|
||||
|
@ -31,6 +31,9 @@ Row {
|
||||
AWFormatterConfigFactory {
|
||||
id: awFormatter
|
||||
}
|
||||
AWTelemetryHandler {
|
||||
id: awTelemetryHandler
|
||||
}
|
||||
// parent object in which text will be replaced
|
||||
property var textArea
|
||||
|
||||
|
@ -26,7 +26,8 @@
|
||||
|
||||
void TestAWTelemetryHandler::initTestCase()
|
||||
{
|
||||
plugin = new AWTelemetryHandler(this, telemetryId);
|
||||
plugin = new AWTelemetryHandler(this);
|
||||
plugin->init(1, true, telemetryId);
|
||||
telemetryData = AWTestLibrary::randomString();
|
||||
telemetryGroup = AWTestLibrary::randomString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user