mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:53:02 +01:00
Display a user warning when log fails to initialize
This commit is contained in:
parent
2a787c1097
commit
92d76c7f99
@ -1158,11 +1158,13 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
|||||||
char myid[TOX_ADDRESS_SIZE];
|
char myid[TOX_ADDRESS_SIZE];
|
||||||
tox_self_get_address(m, (uint8_t *) myid);
|
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);
|
load_chat_history(self, ctx->log);
|
||||||
|
|
||||||
if (!Friends.list[self->num].logging_on)
|
if (!Friends.list[self->num].logging_on)
|
||||||
log_disable(ctx->log);
|
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);
|
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
|
||||||
|
|
||||||
|
@ -379,16 +379,18 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
|||||||
char myid[TOX_ADDRESS_SIZE];
|
char myid[TOX_ADDRESS_SIZE];
|
||||||
tox_self_get_address(m, (uint8_t *) myid);
|
tox_self_get_address(m, (uint8_t *) myid);
|
||||||
|
|
||||||
|
int log_ret = -1;
|
||||||
|
|
||||||
if (self->is_chat) {
|
if (self->is_chat) {
|
||||||
Friends.list[self->num].logging_on = true;
|
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) {
|
} 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) {
|
} 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);
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
||||||
return;
|
return;
|
||||||
} else if (!strcmp(swch, "0") || !strcmp(swch, "off")) {
|
} 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);
|
log_disable(log);
|
||||||
|
|
||||||
msg = "Logging disabled";
|
msg = "Logging disabled.";
|
||||||
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, 0, msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -729,7 +729,9 @@ static void groupchat_onInit(ToxWindow *self, Tox *m)
|
|||||||
if (user_settings->autolog == AUTOLOG_ON) {
|
if (user_settings->autolog == AUTOLOG_ON) {
|
||||||
char myid[TOX_ADDRESS_SIZE];
|
char myid[TOX_ADDRESS_SIZE];
|
||||||
tox_self_get_address(m, (uint8_t *) myid);
|
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);
|
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
|
||||||
|
10
src/log.c
10
src/log.c
@ -153,15 +153,19 @@ void log_disable(struct chatlog *log)
|
|||||||
memset(log, 0, sizeof(struct chatlog));
|
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;
|
log->log_on = true;
|
||||||
|
|
||||||
if (log->file != NULL)
|
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);
|
log_disable(log);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loads previous history from chat log */
|
/* Loads previous history from chat log */
|
||||||
|
@ -39,8 +39,12 @@ enum {
|
|||||||
/* formats/writes line to log file */
|
/* formats/writes line to log file */
|
||||||
void write_to_log(const char *msg, const char *name, struct chatlog *log, bool event);
|
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 */
|
/* 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);
|
*
|
||||||
|
* 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 */
|
/* disables logging for specified log and closes file */
|
||||||
void log_disable(struct chatlog *log);
|
void log_disable(struct chatlog *log);
|
||||||
|
@ -477,7 +477,9 @@ static void prompt_onInit(ToxWindow *self, Tox *m)
|
|||||||
if (user_settings->autolog == AUTOLOG_ON) {
|
if (user_settings->autolog == AUTOLOG_ON) {
|
||||||
char myid[TOX_ADDRESS_SIZE];
|
char myid[TOX_ADDRESS_SIZE];
|
||||||
tox_self_get_address(m, (uint8_t *) myid);
|
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);
|
scrollok(ctx->history, 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user