From 10feea4474e53c12b74e4334042b13a5d5cfe94f Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 16:44:32 -0700 Subject: Adds timestamp to toxic, fixes issue #217 --- testing/toxic/chat.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'testing') diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 854d3817..10837aa7 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "../../core/Messenger.h" #include "../../core/network.h" @@ -26,11 +27,15 @@ typedef struct { extern void fix_name(uint8_t* name); - static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { ChatContext* ctx = (ChatContext*) self->x; uint8_t nick[MAX_NAME_LENGTH] = {0}; + time_t now; + time(&now); + struct tm * timeinfo; + timeinfo = localtime(&now); + if(ctx->friendnum != num) return; @@ -42,10 +47,21 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) fix_name(msg); fix_name(nick); + int inthour = timeinfo->tm_hour; + int intmin = timeinfo->tm_min; + char min[2]; + char hour[2]; + sprintf(hour,"%d",inthour); + sprintf(min,"%d",intmin); + + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); + wprintw(ctx->history,":%s ",min); + wattron(ctx->history, COLOR_PAIR(4)); + wprintw(ctx->history, "%s: ", now); wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); - wprintw(ctx->history, "%s\n", msg); self->blink = true; @@ -74,6 +90,11 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1 static void chat_onKey(ToxWindow* self, int key) { ChatContext* ctx = (ChatContext*) self->x; + time_t now; + time(&now); + struct tm * timeinfo; + timeinfo = localtime(&now); + if(isprint(key)) { if(ctx->pos != sizeof(ctx->line)-1) { @@ -82,6 +103,17 @@ static void chat_onKey(ToxWindow* self, int key) { } } else if(key == '\n') { + + int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done + int intmin = timeinfo->tm_min; + char min[2]; + char hour[2]; + sprintf(hour,"%d",inthour); + sprintf(min,"%d",intmin); + + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); + wprintw(ctx->history,":%s ",min); wattron(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "you: ", ctx->line); wattroff(ctx->history, COLOR_PAIR(1)); -- cgit v1.2.3 From 9267ab2fcaaaedb70c68de6daccea1660138312d Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 17:14:47 -0700 Subject: Fixed a bug with the minutes only being 1 character long when less than 10 --- testing/toxic/chat.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'testing') diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 10837aa7..50aa81b0 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -52,7 +52,12 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) char min[2]; char hour[2]; sprintf(hour,"%d",inthour); - sprintf(min,"%d",intmin); + if (intmin < 10) { + sprintf(min,"0%d",intmin); + } else { + sprintf(min,"%d",intmin); + } + wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history,"%s",hour); @@ -109,7 +114,11 @@ static void chat_onKey(ToxWindow* self, int key) { char min[2]; char hour[2]; sprintf(hour,"%d",inthour); - sprintf(min,"%d",intmin); + if (intmin < 10) { + sprintf(min,"0%d",intmin); + } else { + sprintf(min,"%d",intmin); + } wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history,"%s",hour); -- cgit v1.2.3 From 8bc8016291aa3f153390e505f614c7b52a6613ae Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 17:44:30 -0700 Subject: By popular demand, I made a patch to add seconds to the timestamp --- testing/toxic/seconds.patch | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 testing/toxic/seconds.patch (limited to 'testing') diff --git a/testing/toxic/seconds.patch b/testing/toxic/seconds.patch new file mode 100644 index 00000000..d7ce33a2 --- /dev/null +++ b/testing/toxic/seconds.patch @@ -0,0 +1,61 @@ +--- chat.c 2013-08-02 17:41:08.866583333 -0700 ++++ chat2.c 2013-08-02 17:38:13.672991322 -0700 +@@ -49,8 +49,10 @@ + + int inthour = timeinfo->tm_hour; + int intmin = timeinfo->tm_min; ++ int intsec = timeinfo->tm_sec; + char min[2]; + char hour[2]; ++ char sec[2]; + sprintf(hour,"%d",inthour); + if (intmin < 10) { + sprintf(min,"0%d",intmin); +@@ -58,10 +60,17 @@ + sprintf(min,"%d",intmin); + } + ++ if (intsec < 10) { ++ sprintf(sec,"0%d",intsec); ++ } else { ++ sprintf(sec,"%d",intsec); ++ } ++ + + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); +- wprintw(ctx->history,":%s ",min); ++ wprintw(ctx->history,":%s",min); ++ wprintw(ctx->history,":%s",sec); + wattron(ctx->history, COLOR_PAIR(4)); + wprintw(ctx->history, "%s: ", now); + wattron(ctx->history, COLOR_PAIR(4)); +@@ -111,8 +120,10 @@ + + int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done + int intmin = timeinfo->tm_min; ++ int intsec = timeinfo ->tm_sec; + char min[2]; + char hour[2]; ++ char sec[2]; + sprintf(hour,"%d",inthour); + if (intmin < 10) { + sprintf(min,"0%d",intmin); +@@ -120,9 +131,16 @@ + sprintf(min,"%d",intmin); + } + ++ if (intsec < 10) { ++ sprintf(sec,"0%d",intsec); ++ } else { ++ sprintf(sec,"%d",intsec); ++ } ++ + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); +- wprintw(ctx->history,":%s ",min); ++ wprintw(ctx->history,":%s",min); ++ wprintw(ctx->history,":%s ",sec); + wattron(ctx->history, COLOR_PAIR(1)); + wprintw(ctx->history, "you: ", ctx->line); + wattroff(ctx->history, COLOR_PAIR(1)); -- cgit v1.2.3 From d19b4b9db125cb3c75d1fcbe34103bf4bb6b55ff Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 17:50:35 -0700 Subject: Moved PATCH.md to the toxic folder --- PATCH.md | 2 -- testing/toxic/PATCH.md | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) delete mode 100644 PATCH.md create mode 100644 testing/toxic/PATCH.md (limited to 'testing') diff --git a/PATCH.md b/PATCH.md deleted file mode 100644 index 4af250f3..00000000 --- a/PATCH.md +++ /dev/null @@ -1,2 +0,0 @@ -Seconds.patch adds support for seconds to the timestamp in toxic. -To use seconds.patch run patch < seconds.patch while in the directory testing/toxic diff --git a/testing/toxic/PATCH.md b/testing/toxic/PATCH.md new file mode 100644 index 00000000..4af250f3 --- /dev/null +++ b/testing/toxic/PATCH.md @@ -0,0 +1,2 @@ +Seconds.patch adds support for seconds to the timestamp in toxic. +To use seconds.patch run patch < seconds.patch while in the directory testing/toxic -- cgit v1.2.3 From 62bf320b6e3cb946cc70a972c35c114b0bcdbad1 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 19:58:00 -0700 Subject: Removed the seconds patch, it breaks things --- testing/toxic/PATCH.md | 2 -- testing/toxic/seconds.patch | 61 --------------------------------------------- 2 files changed, 63 deletions(-) delete mode 100644 testing/toxic/PATCH.md delete mode 100644 testing/toxic/seconds.patch (limited to 'testing') diff --git a/testing/toxic/PATCH.md b/testing/toxic/PATCH.md deleted file mode 100644 index 4af250f3..00000000 --- a/testing/toxic/PATCH.md +++ /dev/null @@ -1,2 +0,0 @@ -Seconds.patch adds support for seconds to the timestamp in toxic. -To use seconds.patch run patch < seconds.patch while in the directory testing/toxic diff --git a/testing/toxic/seconds.patch b/testing/toxic/seconds.patch deleted file mode 100644 index d7ce33a2..00000000 --- a/testing/toxic/seconds.patch +++ /dev/null @@ -1,61 +0,0 @@ ---- chat.c 2013-08-02 17:41:08.866583333 -0700 -+++ chat2.c 2013-08-02 17:38:13.672991322 -0700 -@@ -49,8 +49,10 @@ - - int inthour = timeinfo->tm_hour; - int intmin = timeinfo->tm_min; -+ int intsec = timeinfo->tm_sec; - char min[2]; - char hour[2]; -+ char sec[2]; - sprintf(hour,"%d",inthour); - if (intmin < 10) { - sprintf(min,"0%d",intmin); -@@ -58,10 +60,17 @@ - sprintf(min,"%d",intmin); - } - -+ if (intsec < 10) { -+ sprintf(sec,"0%d",intsec); -+ } else { -+ sprintf(sec,"%d",intsec); -+ } -+ - - wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history,"%s",hour); -- wprintw(ctx->history,":%s ",min); -+ wprintw(ctx->history,":%s",min); -+ wprintw(ctx->history,":%s",sec); - wattron(ctx->history, COLOR_PAIR(4)); - wprintw(ctx->history, "%s: ", now); - wattron(ctx->history, COLOR_PAIR(4)); -@@ -111,8 +120,10 @@ - - int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done - int intmin = timeinfo->tm_min; -+ int intsec = timeinfo ->tm_sec; - char min[2]; - char hour[2]; -+ char sec[2]; - sprintf(hour,"%d",inthour); - if (intmin < 10) { - sprintf(min,"0%d",intmin); -@@ -120,9 +131,16 @@ - sprintf(min,"%d",intmin); - } - -+ if (intsec < 10) { -+ sprintf(sec,"0%d",intsec); -+ } else { -+ sprintf(sec,"%d",intsec); -+ } -+ - wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history,"%s",hour); -- wprintw(ctx->history,":%s ",min); -+ wprintw(ctx->history,":%s",min); -+ wprintw(ctx->history,":%s ",sec); - wattron(ctx->history, COLOR_PAIR(1)); - wprintw(ctx->history, "you: ", ctx->line); - wattroff(ctx->history, COLOR_PAIR(1)); -- cgit v1.2.3 From e9c330dc60eb54606299abb8cafe0408f7fb76c3 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 01:52:13 -0700 Subject: Merged a change from a pull request, added a break Merged from https://github.com/greato/ProjectTox-Core --- testing/toxic/prompt.c | 1 + 1 file changed, 1 insertion(+) (limited to 'testing') diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index b0f83811..8536b940 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -141,6 +141,7 @@ static void execute(ToxWindow* self, char* cmd) { case -2: wprintw(self->window, "Please add a message to your request.\n"); case -3: + break; wprintw(self->window, "That appears to be your own ID.\n"); break; case -4: -- cgit v1.2.3 From 52f1dcd9ffc6116d8f45a5451a23cc99becb0d2e Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 03:59:27 -0700 Subject: Fixed a segfault when recieving text --- testing/toxic/chat.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'testing') diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 0e14a295..b835cf2d 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -63,8 +63,6 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) wprintw(ctx->history,"%s",hour); wprintw(ctx->history,":%s ",min); wattron(ctx->history, COLOR_PAIR(4)); - wprintw(ctx->history, "%s: ", now); - wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s\n", msg); @@ -109,17 +107,19 @@ static void chat_onKey(ToxWindow* self, int key) { } else if(key == '\n') { + printf("Get times to int"); int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done int intmin = timeinfo->tm_min; char min[2]; char hour[2]; + printf("Turn to varible"); sprintf(hour,"%d",inthour); if (intmin < 10) { sprintf(min,"0%d",intmin); } else { sprintf(min,"%d",intmin); } - + printf("Display"); wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history,"%s",hour); wprintw(ctx->history,":%s ",min); -- cgit v1.2.3 From 86d7734efea1e7f345a9635f78bbf055116f8d84 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 04:10:47 -0700 Subject: Removed some useless code --- testing/toxic/chat.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'testing') diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index b835cf2d..19f5c972 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -107,19 +107,16 @@ static void chat_onKey(ToxWindow* self, int key) { } else if(key == '\n') { - printf("Get times to int"); int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done int intmin = timeinfo->tm_min; char min[2]; char hour[2]; - printf("Turn to varible"); sprintf(hour,"%d",inthour); if (intmin < 10) { sprintf(min,"0%d",intmin); } else { sprintf(min,"%d",intmin); } - printf("Display"); wattron(ctx->history, COLOR_PAIR(2)); wprintw(ctx->history,"%s",hour); wprintw(ctx->history,":%s ",min); -- cgit v1.2.3 From 28944151c71bae923f8b5cbcdf090cb3190bf098 Mon Sep 17 00:00:00 2001 From: Michael Kress Date: Sat, 3 Aug 2013 16:00:48 +0200 Subject: fixed printing time stamp in toxic --- testing/toxic/chat.c | 34 ++++------------------------------ 1 file changed, 4 insertions(+), 30 deletions(-) (limited to 'testing') diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 19f5c972..ddf59233 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -47,21 +47,8 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) fix_name(msg); fix_name(nick); - int inthour = timeinfo->tm_hour; - int intmin = timeinfo->tm_min; - char min[2]; - char hour[2]; - sprintf(hour,"%d",inthour); - if (intmin < 10) { - sprintf(min,"0%d",intmin); - } else { - sprintf(min,"%d",intmin); - } - - wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history,"%s",hour); - wprintw(ctx->history,":%s ",min); + wprintw(ctx->history, "%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min); wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); @@ -106,24 +93,11 @@ static void chat_onKey(ToxWindow* self, int key) { } } else if(key == '\n') { - - int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done - int intmin = timeinfo->tm_min; - char min[2]; - char hour[2]; - sprintf(hour,"%d",inthour); - if (intmin < 10) { - sprintf(min,"0%d",intmin); - } else { - sprintf(min,"%d",intmin); - } wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history,"%s",hour); - wprintw(ctx->history,":%s ",min); + wprintw(ctx->history, "%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min); wattron(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "you: ", ctx->line); wattroff(ctx->history, COLOR_PAIR(1)); - wprintw(ctx->history, "%s\n", ctx->line); if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { @@ -140,7 +114,7 @@ static void chat_onKey(ToxWindow* self, int key) { ctx->line[--ctx->pos] = '\0'; } } - + } static void chat_onDraw(ToxWindow* self) { @@ -188,7 +162,7 @@ ToxWindow new_chat(int friendnum) { uint8_t nick[MAX_NAME_LENGTH] = {0}; getname(friendnum, (uint8_t*) &nick); fix_name(nick); - + snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); ChatContext* x = calloc(1, sizeof(ChatContext)); -- cgit v1.2.3 From 1ae2bfbb7530d3bf856a60587efc3932b4438df6 Mon Sep 17 00:00:00 2001 From: Michael Kress Date: Sat, 3 Aug 2013 16:26:23 +0200 Subject: added seconds to time stamp in toxic --- testing/toxic/chat.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'testing') diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index ddf59233..7cae1c0a 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c @@ -48,7 +48,7 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) fix_name(nick); wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history, "%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min); + wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); @@ -94,7 +94,7 @@ static void chat_onKey(ToxWindow* self, int key) { } else if(key == '\n') { wattron(ctx->history, COLOR_PAIR(2)); - wprintw(ctx->history, "%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min); + wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); wattron(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "you: ", ctx->line); wattroff(ctx->history, COLOR_PAIR(1)); -- cgit v1.2.3 From 54aebfd8071c3e2c7a92c10154dc3644b66ad76b Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Sat, 3 Aug 2013 11:51:40 -0700 Subject: Removed an early break --- testing/toxic/prompt.c | 1 - 1 file changed, 1 deletion(-) (limited to 'testing') diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c index e80bdab0..1db60883 100644 --- a/testing/toxic/prompt.c +++ b/testing/toxic/prompt.c @@ -142,7 +142,6 @@ static void execute(ToxWindow* self, char* cmd) { wprintw(self->window, "Please add a message to your request.\n"); break; case -3: - break; wprintw(self->window, "That appears to be your own ID.\n"); break; case -4: -- cgit v1.2.3