From ff7b3a1a10b2c9183a29ac218253ea1a805091e4 Mon Sep 17 00:00:00 2001 From: Kamil Date: Sat, 22 Jun 2019 00:27:50 +0200 Subject: [PATCH] Added code to make android activity AddCustomTask working properly --- .../Source/Classes/jsonactionparser.cpp | 34 +++++++++++++++++-- .../Source/Classes/jsonactionparser.h | 1 + 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Windows/AutoSwitch/Source/Classes/jsonactionparser.cpp b/Windows/AutoSwitch/Source/Classes/jsonactionparser.cpp index 96400ab..f245db7 100644 --- a/Windows/AutoSwitch/Source/Classes/jsonactionparser.cpp +++ b/Windows/AutoSwitch/Source/Classes/jsonactionparser.cpp @@ -32,13 +32,41 @@ bool JsonActionParser::parseNewAction(QJsonObject jsonObject) case 'm': monitorOff(); break; default: return false; } - return true; } - else if(jsonObject.value("TimeMode").toString() == "Seconds") + else if(jsonObject.value("TimeMode").toString() == "Postponed") { + if(jsonObject.contains("dt")) + { + QJsonObject dtObj = jsonObject.value("dt").toObject(); + QTime t; + t.setHMS(dtObj.value("hourOfDay").toInt(), dtObj.value("minute").toInt(), 0); + task.time.dt.setTime(t); + + if(dtObj.value("year").toInt() != 1900) + { + QDate d; + d.setDate(dtObj.value("year").toInt(), dtObj.value("month").toInt() + 1, dtObj.value("dayOfMonth").toInt()); + task.time.dt.setDate(d); + } + else + { + QDateTime dt = QDateTime::currentDateTime(); + if(dtObj.value("hourOfDay").toInt() <= dt.time().hour() && dtObj.value("minute").toInt() <= dt.time().minute() && 0 < dt.time().second()) + { + task.time = countDate('d', 1, task.time); + } + else task.time.dt.setDate(dt.date()); + } + qDebug() << task.time.dt.date() << task.time.dt.time(); + preAutomat(task); + } + else if(jsonObject.contains("seconds")) + { + task.time = countTime(jsonObject.value("seconds").toInt(), 's', task.time); + preAutomat(task); + } } else return false; - return true; } diff --git a/Windows/AutoSwitch/Source/Classes/jsonactionparser.h b/Windows/AutoSwitch/Source/Classes/jsonactionparser.h index 442e713..d5af93c 100644 --- a/Windows/AutoSwitch/Source/Classes/jsonactionparser.h +++ b/Windows/AutoSwitch/Source/Classes/jsonactionparser.h @@ -1,4 +1,5 @@ #pragma once +#include #include "QJsonDocument" #include "QJsonObject"