From 32aa05de42ffebd6465e06970fd8a8cd94b2abd0 Mon Sep 17 00:00:00 2001 From: Anselme Date: Tue, 25 Aug 2015 13:21:12 +0200 Subject: [PATCH] todo module command parsing works --- app/main.cpp | 2 + app/sparrowmodule.cpp | 2 +- app/todomodule.cpp | 125 +++++++++++++++++++++++++++++++++++------- app/todomodule.h | 2 - 4 files changed, 107 insertions(+), 24 deletions(-) diff --git a/app/main.cpp b/app/main.cpp index c2bdd92..d91b456 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -6,6 +6,7 @@ #include "sparrowmodule.h" #include "poilaumodule.h" #include "fourasmodule.h" +#include "todomodule.h" class HelloWorldModule : public Module { @@ -36,5 +37,6 @@ int main(int argc, char *argv[]) app.addModule(new SparrowModule()); app.addModule(new PoilAuModule()); app.addModule(new FourasModule()); + app.addModule(new TodoModule()); return app.exec(); } diff --git a/app/sparrowmodule.cpp b/app/sparrowmodule.cpp index 3e2fc2f..0d41bea 100644 --- a/app/sparrowmodule.cpp +++ b/app/sparrowmodule.cpp @@ -28,7 +28,7 @@ bool SparrowModule::messageHandler(Message msg) } else if(msg.args.compare("!version") == 0) { - answer = say("sparrowModule v1.0"); + answer = say("sparrowModule v1.1"); return true; } else if(msg.args.compare("re", Qt::CaseInsensitive) == 0) diff --git a/app/todomodule.cpp b/app/todomodule.cpp index fe11d29..2980af0 100644 --- a/app/todomodule.cpp +++ b/app/todomodule.cpp @@ -2,6 +2,7 @@ #include "message.h" #include #include +#include TodoModule::TodoModule() { @@ -18,26 +19,121 @@ bool TodoModule::messageHandler(Message msg) Task t; int deltaIndex = 1; t.isPrivate = !msg.target.contains(getChan()); - t.emitter = msg.nick; - t.date = time(NULL); + t.recipient = msg.nick; + t.repeat = 0; QStringList splitter = msg.args.split(' '); if(splitter[deltaIndex].compare("to") == 0) { deltaIndex += 2; - t.emitter = splitter[2]; + t.recipient = splitter[2]; } if(splitter.size() < deltaIndex+2) return true; QString dateString = splitter[deltaIndex]; + QStringList dateSplitter; + bool ok; if(dateString.startsWith("date(")) { - //t.date += dateString; + answer = usage(DATE); + dateString = dateString.mid(5, dateString.size() - 6); + dateSplitter = dateString.split('/'); + if(dateSplitter.size() < 2) + return true; + int day = dateSplitter[0].toUInt(&ok); + if(!ok || day > 31 || day < 1) return true; + dateSplitter = dateSplitter[1].split('-'); + int month = dateSplitter[0].toUInt(&ok); + if(!ok || month > 12 || month < 1) return true; + int hours = 0; + int minutes = 0; + int seconds = 0; + if(dateSplitter.size() > 1) + { + dateSplitter = dateSplitter[1].split(':'); + hours = dateSplitter[0].toUInt(&ok); + if(!ok || hours > 23) return true; + if(dateSplitter.size() > 1) + { + minutes = dateSplitter[1].toUInt(&ok); + if(!ok || minutes > 59) return true; + } + if(dateSplitter.size() > 2) + { + seconds = dateSplitter[2].toUInt(&ok); + if(!ok || seconds > 59) return true; + } + } + QDateTime date(QDate(QDate::currentDate().year(), month, day), QTime(hours, minutes, seconds)); + t.date = date.toTime_t(); } else { - + answer = usage(DURATION); + dateSplitter = dateString.split(':'); + int hours = dateSplitter[0].toUInt(&ok); + int minutes = 0; + int seconds = 0; + if(!ok) return true; + if(dateSplitter.size() > 1) + { + minutes = dateSplitter[1].toUInt(&ok); + if(!ok || minutes > 59) return true; + } + if(dateSplitter.size() > 2) + { + seconds = dateSplitter[2].toUInt(&ok); + if(!ok || seconds > 59) return true; + } + QDateTime date = QDateTime::currentDateTime(); + minutes += hours*60; + seconds += minutes*60; + date.addSecs(seconds); + t.date = date.toTime_t(); } - + ++deltaIndex; + if(splitter[deltaIndex].compare("every") == 0) + { + answer = usage(DURATION); + dateSplitter = dateString.split(':'); + int hours = dateSplitter[0].toUInt(&ok); + int minutes = 0; + int seconds = 0; + if(!ok) return true; + if(dateSplitter.size() > 1) + { + minutes = dateSplitter[1].toUInt(&ok); + if(!ok || minutes > 59) return true; + } + if(dateSplitter.size() > 2) + { + seconds = dateSplitter[2].toUInt(&ok); + if(!ok || seconds > 59) return true; + } + minutes += hours*60; + seconds += minutes*60; + t.repeat = seconds; + deltaIndex += 2; + } + QString desc; + bool first = true; + for(int i=deltaIndex; i append it to save file -} diff --git a/app/todomodule.h b/app/todomodule.h index 623c848..f26f916 100644 --- a/app/todomodule.h +++ b/app/todomodule.h @@ -27,8 +27,6 @@ public: virtual bool messageHandler(Message msg); virtual QString getName() {return "todo";} - - void addTask(unsigned long date, unsigned long repeat, QString description, QString emitter, QString recipient, bool isPrivate); }; #endif // TODOMODULE_H