1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 16:03:03 +01:00

Display a user warning when log fails to initialize

This commit is contained in:
Jfreegman 2015-08-19 00:42:28 -04:00
parent 2a787c1097
commit 92d76c7f99
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
6 changed files with 29 additions and 13 deletions

View File

@ -1158,11 +1158,13 @@ static void chat_onInit(ToxWindow *self, Tox *m)
char myid[TOX_ADDRESS_SIZE];
tox_self_get_address(m, (uint8_t *) myid);
log_enable(nick, myid, Friends.list[self->num].pub_key, ctx->log, LOG_CHAT);
int log_ret = log_enable(nick, myid, Friends.list[self->num].pub_key, ctx->log, LOG_CHAT);
load_chat_history(self, ctx->log);
if (!Friends.list[self->num].logging_on)
log_disable(ctx->log);
else if (log_ret == -1)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);

View File

@ -379,16 +379,18 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
char myid[TOX_ADDRESS_SIZE];
tox_self_get_address(m, (uint8_t *) myid);
int log_ret = -1;
if (self->is_chat) {
Friends.list[self->num].logging_on = true;
log_enable(self->name, myid, Friends.list[self->num].pub_key, log, LOG_CHAT);
log_ret = log_enable(self->name, myid, Friends.list[self->num].pub_key, log, LOG_CHAT);
} else if (self->is_prompt) {
log_enable(self->name, myid, NULL, log, LOG_PROMPT);
log_ret = log_enable(self->name, myid, NULL, log, LOG_PROMPT);
} else if (self->is_groupchat) {
log_enable(self->name, myid, NULL, log, LOG_GROUP);
log_ret = log_enable(self->name, myid, NULL, log, LOG_GROUP);
}
msg = "Logging enabled";
msg = log_ret == 0 ? "Logging enabled." : "Warning: Log failed to initialize.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return;
} else if (!strcmp(swch, "0") || !strcmp(swch, "off")) {
@ -397,7 +399,7 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
log_disable(log);
msg = "Logging disabled";
msg = "Logging disabled.";
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
return;
}

View File

@ -729,7 +729,9 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
if (user_settings->autolog == AUTOLOG_ON) {
char myid[TOX_ADDRESS_SIZE];
tox_self_get_address(m, (uint8_t *) myid);
log_enable(self->name, myid, NULL, ctx->log, LOG_GROUP);
if (log_enable(self->name, myid, NULL, ctx->log, LOG_GROUP) == -1)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
}
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);

View File

@ -153,15 +153,19 @@ void log_disable(struct chatlog *log)
memset(log, 0, sizeof(struct chatlog));
}
void log_enable(char *name, const char *selfkey, const char *otherkey, struct chatlog *log, int logtype)
int log_enable(char *name, const char *selfkey, const char *otherkey, struct chatlog *log, int logtype)
{
log->log_on = true;
if (log->file != NULL)
return;
return 0;
if (init_logging_session(name, selfkey, otherkey, log, logtype) == -1)
if (init_logging_session(name, selfkey, otherkey, log, logtype) == -1) {
log_disable(log);
return -1;
}
return 0;
}
/* Loads previous history from chat log */

View File

@ -39,8 +39,12 @@ enum {
/* formats/writes line to log file */
void write_to_log(const char *msg, const char *name, struct chatlog *log, bool event);
/* enables logging for specified log and creates/fetches file if necessary */
void log_enable(char *name, const char *selfkey, const char *otherkey, struct chatlog *log, int logtype);
/* enables logging for specified log and creates/fetches file if necessary.
*
* Returns 0 on success.
* Returns -1 on failure.
*/
int log_enable(char *name, const char *selfkey, const char *otherkey, struct chatlog *log, int logtype);
/* disables logging for specified log and closes file */
void log_disable(struct chatlog *log);

View File

@ -477,7 +477,9 @@ static void prompt_onInit(ToxWindow *self, Tox *m)
if (user_settings->autolog == AUTOLOG_ON) {
char myid[TOX_ADDRESS_SIZE];
tox_self_get_address(m, (uint8_t *) myid);
log_enable(self->name, myid, NULL, ctx->log, LOG_PROMPT);
if (log_enable(self->name, myid, NULL, ctx->log, LOG_PROMPT) == -1)
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, "Warning: Log failed to initialize.");
}
scrollok(ctx->history, 0);