1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 01:53:02 +01:00

save logging preference for friend chats and improve log command message

This commit is contained in:
Jfreegman 2014-02-27 23:33:00 -05:00
parent 46b046a209
commit 4fb82cceaa
6 changed files with 39 additions and 23 deletions

View File

@ -95,9 +95,6 @@ void chat_enable_log(ToxWindow *self)
{ {
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
if (ctx->log.log_on)
return;
ctx->log.log_on = true; ctx->log.log_on = true;
if (!ctx->log.log_path[0]) if (!ctx->log.log_path[0])
@ -108,10 +105,10 @@ void chat_disable_log(ToxWindow *self)
{ {
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
if (ctx->log.log_on) { if (ctx->log.log_on)
write_to_log(ctx); write_to_log(ctx);
ctx->log.log_on = false; ctx->log.log_on = false;
}
} }
static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint16_t len) static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint16_t len)
@ -692,9 +689,14 @@ static void chat_onInit(ToxWindow *self, Tox *m)
scrollok(ctx->history, 1); scrollok(ctx->history, 1);
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2-CHATBOX_HEIGHT, 0); ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2-CHATBOX_HEIGHT, 0);
wprintw(ctx->history, "\n\n"); wprintw(ctx->history, "\n\n");
execute(ctx->history, self, m, "/help", CHAT_COMMAND_MODE);
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
wmove(self->window, y2 - CURS_Y_OFFSET, 0); wmove(self->window, y2 - CURS_Y_OFFSET, 0);
execute(ctx->history, self, m, "/help", CHAT_COMMAND_MODE);
if (friends[self->num].logging_on)
chat_enable_log(self);
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
} }
ToxWindow new_chat(Tox *m, int friendnum) ToxWindow new_chat(Tox *m, int friendnum)

View File

@ -37,6 +37,7 @@ typedef struct {
bool active; bool active;
bool online; bool online;
bool is_typing; bool is_typing;
bool logging_on; /* saves preference for friend irrespective of chat windows */
TOX_USERSTATUS status; TOX_USERSTATUS status;
struct FileReceiver file_receiver; struct FileReceiver file_receiver;
} ToxicFriend; } ToxicFriend;

View File

@ -222,16 +222,27 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE]) void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
{ {
if (!self->is_chat && !self->is_groupchat) /* remove if prompt logging gets implemented */ if (!self->is_chat && !self->is_groupchat) { /* remove if prompt logging gets implemented */
wprintw(window, "Invalid command.\n");
return; return;
}
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
if (argc == 0) { if (argc == 0) {
if (ctx->log.log_on) if (ctx->log.log_on) {
wprintw(window, "Logging for this chat is on. Type \"/log off\" to disable.\n"); wprintw(window, "Logging for this chat is ");
else wattron(window, COLOR_PAIR(GREEN) | A_BOLD);
wprintw(window, "Logging for this chat is off. Type \"/log on\" to enable.\n"); wprintw(window, "[on]");
wattroff(window, COLOR_PAIR(GREEN) | A_BOLD);
wprintw(window, ". Type \"/log off\" to disable.\n");
} else {
wprintw(window, "Logging for this chat is ");
wattron(window, COLOR_PAIR(RED) | A_BOLD);
wprintw(window, "[off]");
wattroff(window, COLOR_PAIR(RED) | A_BOLD);
wprintw(window, ". Type \"/log on\" to enable.\n");
}
return; return;
} }
@ -239,10 +250,13 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
uint8_t *swch = argv[1]; uint8_t *swch = argv[1];
if (!strcmp(swch, "1") || !strcmp(swch, "on")) { if (!strcmp(swch, "1") || !strcmp(swch, "on")) {
if (self->is_chat) if (self->is_chat) {
chat_enable_log(self); chat_enable_log(self);
else if (self->is_groupchat) friends[self->num].logging_on = true;
} else if (self->is_groupchat) {
groupchat_enable_log(self); groupchat_enable_log(self);
friends[self->num].logging_on = false;
}
wprintw(window, "Logging "); wprintw(window, "Logging ");
wattron(window, COLOR_PAIR(GREEN) | A_BOLD); wattron(window, COLOR_PAIR(GREEN) | A_BOLD);
@ -250,10 +264,12 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
wattroff(window, COLOR_PAIR(GREEN) | A_BOLD); wattroff(window, COLOR_PAIR(GREEN) | A_BOLD);
return; return;
} else if (!strcmp(swch, "0") || !strcmp(swch, "off")) { } else if (!strcmp(swch, "0") || !strcmp(swch, "off")) {
if (self->is_chat) if (self->is_chat) {
chat_disable_log(self); chat_disable_log(self);
else if (self->is_groupchat) friends[self->num].logging_on = false;
} else if (self->is_groupchat) {
groupchat_disable_log(self); groupchat_disable_log(self);
}
wprintw(window, "Logging "); wprintw(window, "Logging ");
wattron(window, COLOR_PAIR(RED) | A_BOLD); wattron(window, COLOR_PAIR(RED) | A_BOLD);

View File

@ -106,9 +106,6 @@ void groupchat_enable_log(ToxWindow *self)
{ {
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
if (ctx->log.log_on)
return;
ctx->log.log_on = true; ctx->log.log_on = true;
if (!ctx->log.log_path[0]) if (!ctx->log.log_path[0])

View File

@ -48,7 +48,7 @@ void init_logging_session(uint8_t *name, uint8_t *key, ChatContext *ctx)
ident[KEY_IDENT_DIGITS*2+1] = '\0'; ident[KEY_IDENT_DIGITS*2+1] = '\0';
} else { } else {
struct tm *tminfo = get_time(); struct tm *tminfo = get_time();
snprintf(ident, 32, snprintf(ident, sizeof(ident),
"%04d-%02d-%02d-%02d:%02d:%02d", tminfo->tm_year+1900,tminfo->tm_mon+1, tminfo->tm_mday, "%04d-%02d-%02d-%02d:%02d:%02d", tminfo->tm_year+1900,tminfo->tm_mon+1, tminfo->tm_mday,
tminfo->tm_hour, tminfo->tm_min, tminfo->tm_sec); tminfo->tm_hour, tminfo->tm_min, tminfo->tm_sec);
path_len += strlen(ident) + 1; path_len += strlen(ident) + 1;
@ -69,7 +69,7 @@ void init_logging_session(uint8_t *name, uint8_t *key, ChatContext *ctx)
return; return;
} }
fprintf(logfile, "\n***NEW SESSION***\n\n"); fprintf(logfile, "\n*** NEW SESSION ***\n\n");
fclose(logfile); fclose(logfile);
free(user_config_dir); free(user_config_dir);

View File

@ -144,7 +144,7 @@ struct chatlog {
uint8_t log_path[MAX_STR_SIZE]; uint8_t log_path[MAX_STR_SIZE];
uint8_t log_buf[MAX_LOG_BUF_LINES][MAX_LOG_LINE_SIZE]; uint8_t log_buf[MAX_LOG_BUF_LINES][MAX_LOG_LINE_SIZE];
int pos; int pos;
bool log_on; bool log_on; /* specific to current chat window */
}; };
#define MAX_LINE_HIST 128 #define MAX_LINE_HIST 128