-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add menu option for save watch configs #258
Changes from 7 commits
3ced39d
cbed9bc
e900cd2
f926973
23ff364
adc7671
bd45b5a
38b5e00
4ba002c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ | |
#include <QEventLoop> | ||
#include <QMutex> | ||
#include <QDebug> | ||
#include <QDir> | ||
#include <QJsonDocument> | ||
|
||
#include "logstore.h" | ||
|
||
|
@@ -204,6 +206,23 @@ int MovesCount::getCustomModeData(ambit_sport_mode_device_settings_t* ambitCusto | |
return ret; | ||
} | ||
|
||
int MovesCount::getWatchModeConfig(ambit_sport_mode_device_settings_t* ambitCustomModes) | ||
{ | ||
int ret = -1; | ||
|
||
if (&workerThread == QThread::currentThread()) { | ||
ret = getWatchModeDataThread(ambitCustomModes); | ||
} | ||
else { | ||
QMetaObject::invokeMethod(this, "getWatchModeDataThread", Qt::BlockingQueuedConnection, | ||
Q_RETURN_ARG(int, ret), | ||
Q_ARG(ambit_sport_mode_device_settings_t*, ambitCustomModes)); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
|
||
int MovesCount::getAppsData(ambit_app_rules_t* ambitApps) | ||
{ | ||
int ret = -1; | ||
|
@@ -220,6 +239,22 @@ int MovesCount::getAppsData(ambit_app_rules_t* ambitApps) | |
return ret; | ||
} | ||
|
||
int MovesCount::getWatchAppConfig(ambit_app_rules_t* ambitApps) | ||
{ | ||
int ret = -1; | ||
|
||
if (&workerThread == QThread::currentThread()) { | ||
ret = getWatchAppConfigThread(ambitApps); | ||
} | ||
else { | ||
QMetaObject::invokeMethod(this, "getWatchAppConfigThread", Qt::BlockingQueuedConnection, | ||
Q_RETURN_ARG(int, ret), | ||
Q_ARG(ambit_app_rules_t*, ambitApps)); | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
QList<MovesCountLogDirEntry> MovesCount::getMovescountEntries(QDate startTime, QDate endTime) | ||
{ | ||
QList<MovesCountLogDirEntry> retList; | ||
|
@@ -471,6 +506,20 @@ void MovesCount::getDeviceSettingsInThread() | |
} | ||
} | ||
|
||
void writeJson(QByteArray _data, const char* name) { | ||
QFile logfile(name); | ||
logfile.open(QIODevice::WriteOnly | QIODevice::Truncate); | ||
|
||
// pretty print JSON | ||
QJsonDocument doc = QJsonDocument::fromJson(_data); | ||
QString formattedJsonString = doc.toJson(QJsonDocument::Indented); | ||
|
||
//formattedJsonString.replace("", ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you can remove this commented code here |
||
|
||
logfile.write(formattedJsonString.toUtf8()); | ||
logfile.close(); | ||
} | ||
|
||
int MovesCount::getCustomModeDataInThread(ambit_sport_mode_device_settings_t *ambitSettings) | ||
{ | ||
int ret = -1; | ||
|
@@ -491,6 +540,28 @@ int MovesCount::getCustomModeDataInThread(ambit_sport_mode_device_settings_t *am | |
return ret; | ||
} | ||
|
||
int MovesCount::getWatchModeDataThread(ambit_sport_mode_device_settings_t *ambitSettings) | ||
{ | ||
int ret = -1; | ||
QNetworkReply *reply; | ||
|
||
reply = syncGET("/userdevices/" + device_info.serial, "", true); | ||
|
||
if (checkReplyAuthorization(reply)) { | ||
QByteArray _data = reply->readAll(); | ||
MovescountSettings settings = MovescountSettings(); | ||
|
||
writeJson(_data, QString(getenv("HOME")).toUtf8() + "/.openambit/settings.json"); | ||
|
||
if (jsonParser.parseDeviceSettingsReply(_data, settings) == 0) { | ||
settings.toAmbitData(ambitSettings); | ||
ret = 0; | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
int MovesCount::getAppsDataInThread(ambit_app_rules_t* ambitApps) | ||
{ | ||
int ret = -1; | ||
|
@@ -509,6 +580,26 @@ int MovesCount::getAppsDataInThread(ambit_app_rules_t* ambitApps) | |
return ret; | ||
} | ||
|
||
int MovesCount::getWatchAppConfigThread(ambit_app_rules_t* ambitApps) | ||
{ | ||
int ret = -1; | ||
QNetworkReply *reply; | ||
|
||
reply = syncGET("/rules/private", "", true); | ||
|
||
if (checkReplyAuthorization(reply)) { | ||
QByteArray _data = reply->readAll(); | ||
|
||
writeJson(_data, QString(getenv("HOME")).toUtf8() + "/.openambit/apprules.json"); | ||
|
||
if (jsonParser.parseAppRulesReply(_data, ambitApps) == 0) { | ||
ret = 0; | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
QList<MovesCountLogDirEntry> MovesCount::getMovescountEntriesInThread(QDate startTime, QDate endTime) | ||
{ | ||
QNetworkReply *reply; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
personal_config.h | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this gitignore useful in general or just a leftover? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a leftover. I used to store a different APPKEY there, because on Task.cpp I had:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some unrelated newline/blank changes, maybe you can revert them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, I will revert them