diff options
author | irungentoo <irungentoo@gmail.com> | 2013-08-03 13:33:27 -0700 |
---|---|---|
committer | irungentoo <irungentoo@gmail.com> | 2013-08-03 13:33:27 -0700 |
commit | 1ddd28f52b86951d6ca0aed267ebdc8775e8c74b (patch) | |
tree | fc4e592efb78f37077b76b03ed4a724b09de713e /testing | |
parent | 0c3cd5d7fb477b2e61a1f5f9ae16406345aa15b4 (diff) | |
parent | 54aebfd8071c3e2c7a92c10154dc3644b66ad76b (diff) |
Merge pull request #276 from stqism/master
Adds timestamp to toxic, fixes issue #217
Diffstat (limited to 'testing')
-rw-r--r-- | testing/toxic/chat.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c index 1bfd94f5..7cae1c0a 100644 --- a/testing/toxic/chat.c +++ b/testing/toxic/chat.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <stdint.h> | 8 | #include <stdint.h> |
9 | #include <ctype.h> | 9 | #include <ctype.h> |
10 | #include <time.h> | ||
10 | 11 | ||
11 | #include "../../core/Messenger.h" | 12 | #include "../../core/Messenger.h" |
12 | #include "../../core/network.h" | 13 | #include "../../core/network.h" |
@@ -26,11 +27,15 @@ typedef struct { | |||
26 | 27 | ||
27 | extern void fix_name(uint8_t* name); | 28 | extern void fix_name(uint8_t* name); |
28 | 29 | ||
29 | |||
30 | static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { | 30 | static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { |
31 | ChatContext* ctx = (ChatContext*) self->x; | 31 | ChatContext* ctx = (ChatContext*) self->x; |
32 | uint8_t nick[MAX_NAME_LENGTH] = {0}; | 32 | uint8_t nick[MAX_NAME_LENGTH] = {0}; |
33 | 33 | ||
34 | time_t now; | ||
35 | time(&now); | ||
36 | struct tm * timeinfo; | ||
37 | timeinfo = localtime(&now); | ||
38 | |||
34 | if(ctx->friendnum != num) | 39 | if(ctx->friendnum != num) |
35 | return; | 40 | return; |
36 | 41 | ||
@@ -42,10 +47,11 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) | |||
42 | fix_name(msg); | 47 | fix_name(msg); |
43 | fix_name(nick); | 48 | fix_name(nick); |
44 | 49 | ||
50 | wattron(ctx->history, COLOR_PAIR(2)); | ||
51 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | ||
45 | wattron(ctx->history, COLOR_PAIR(4)); | 52 | wattron(ctx->history, COLOR_PAIR(4)); |
46 | wprintw(ctx->history, "%s: ", nick); | 53 | wprintw(ctx->history, "%s: ", nick); |
47 | wattroff(ctx->history, COLOR_PAIR(4)); | 54 | wattroff(ctx->history, COLOR_PAIR(4)); |
48 | |||
49 | wprintw(ctx->history, "%s\n", msg); | 55 | wprintw(ctx->history, "%s\n", msg); |
50 | 56 | ||
51 | self->blink = true; | 57 | self->blink = true; |
@@ -74,6 +80,11 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1 | |||
74 | static void chat_onKey(ToxWindow* self, int key) { | 80 | static void chat_onKey(ToxWindow* self, int key) { |
75 | ChatContext* ctx = (ChatContext*) self->x; | 81 | ChatContext* ctx = (ChatContext*) self->x; |
76 | 82 | ||
83 | time_t now; | ||
84 | time(&now); | ||
85 | struct tm * timeinfo; | ||
86 | timeinfo = localtime(&now); | ||
87 | |||
77 | if(isprint(key)) { | 88 | if(isprint(key)) { |
78 | 89 | ||
79 | if(ctx->pos != sizeof(ctx->line)-1) { | 90 | if(ctx->pos != sizeof(ctx->line)-1) { |
@@ -82,10 +93,11 @@ static void chat_onKey(ToxWindow* self, int key) { | |||
82 | } | 93 | } |
83 | } | 94 | } |
84 | else if(key == '\n') { | 95 | else if(key == '\n') { |
96 | wattron(ctx->history, COLOR_PAIR(2)); | ||
97 | wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); | ||
85 | wattron(ctx->history, COLOR_PAIR(1)); | 98 | wattron(ctx->history, COLOR_PAIR(1)); |
86 | wprintw(ctx->history, "you: ", ctx->line); | 99 | wprintw(ctx->history, "you: ", ctx->line); |
87 | wattroff(ctx->history, COLOR_PAIR(1)); | 100 | wattroff(ctx->history, COLOR_PAIR(1)); |
88 | |||
89 | wprintw(ctx->history, "%s\n", ctx->line); | 101 | wprintw(ctx->history, "%s\n", ctx->line); |
90 | 102 | ||
91 | if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { | 103 | if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { |
@@ -102,7 +114,7 @@ static void chat_onKey(ToxWindow* self, int key) { | |||
102 | ctx->line[--ctx->pos] = '\0'; | 114 | ctx->line[--ctx->pos] = '\0'; |
103 | } | 115 | } |
104 | } | 116 | } |
105 | 117 | ||
106 | } | 118 | } |
107 | 119 | ||
108 | static void chat_onDraw(ToxWindow* self) { | 120 | static void chat_onDraw(ToxWindow* self) { |
@@ -150,7 +162,7 @@ ToxWindow new_chat(int friendnum) { | |||
150 | uint8_t nick[MAX_NAME_LENGTH] = {0}; | 162 | uint8_t nick[MAX_NAME_LENGTH] = {0}; |
151 | getname(friendnum, (uint8_t*) &nick); | 163 | getname(friendnum, (uint8_t*) &nick); |
152 | fix_name(nick); | 164 | fix_name(nick); |
153 | 165 | ||
154 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); | 166 | snprintf(ret.title, sizeof(ret.title), "[%s (%d)]", nick, friendnum); |
155 | 167 | ||
156 | ChatContext* x = calloc(1, sizeof(ChatContext)); | 168 | ChatContext* x = calloc(1, sizeof(ChatContext)); |