1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 13:23:26 +01:00

add settings to toggle typing notifications for self and others

This commit is contained in:
Jfreegman 2014-07-29 20:10:28 -04:00
parent 973f6206ee
commit 476dec46b6
6 changed files with 67 additions and 14 deletions

View File

@ -66,6 +66,20 @@ Select between 24 and 12 hour time.
Values: 24, 12 Values: 24, 12
.RE .RE
.PP .PP
.B show_typing_other
.RS
Show you when others are typing in a 1-on-1 chat
.br
Values: 'true' to enable, 'false' to disable
.RE
.PP
.B show_typing_self
.RS
Show others when you're typing in a 1-on-1 chat
.br
Values: 'true' to enable, 'false' to disable
.RE
.PP
.B history_size .B history_size
.RS .RS
Maximum lines for chat window history. Maximum lines for chat window history.
@ -294,6 +308,14 @@ ui = {
// 24 or 12 hour time // 24 or 12 hour time
.br .br
time_format=24; time_format=24;
.br
// true to show you when others are typing a message in 1-on-1 chats
.br
show_typing_other=true;
.br
// true to show others when you're typing a message in 1-on-1 chats
.br
show_typing_self=true;
.br .br
// maximum lines for chat window history // maximum lines for chat window history
.br .br

View File

@ -3,20 +3,26 @@
ui = { ui = {
// true to enable timestamps, false to disable // true to enable timestamps, false to disable
timestamps:true; timestamps=true;
// true to enable terminal alerts on messages, false to disable // true to enable terminal alerts on messages, false to disable
alerts:true; alerts=true;
// true to use native terminal colours, false to use toxic default colour theme // true to use native terminal colours, false to use toxic default colour theme
native_colors:false; native_colors=false;
// true to enable autologging, false to disable // true to enable autologging, false to disable
autolog:false; autolog=false;
// 24 or 12 hour time // 24 or 12 hour time
time_format=24; time_format=24;
// true to show you when others are typing a message in 1-on-1 chats
show_typing_other=true;
// true to show others when you're typing a message in 1-on-1 chats
show_typing_self=true;
// maximum lines for chat window history // maximum lines for chat window history
history_size=700; history_size=700;
}; };

View File

@ -103,8 +103,11 @@ static const char chat_cmd_list[AC_NUM_CHAT_COMMANDS][MAX_CMDNAME_SIZE] = {
#endif /* _AUDIO */ #endif /* _AUDIO */
}; };
static void set_typingstatus(ToxWindow *self, Tox *m, uint8_t is_typing) static void set_self_typingstatus(ToxWindow *self, Tox *m, uint8_t is_typing)
{ {
if (user_settings_->show_typing_self == SHOW_TYPING_OFF)
return;
ChatContext *ctx = self->chatwin; ChatContext *ctx = self->chatwin;
tox_set_user_is_typing(m, self->num, is_typing); tox_set_user_is_typing(m, self->num, is_typing);
@ -173,14 +176,18 @@ static void chat_onConnectionChange(ToxWindow *self, Tox *m, int32_t num, uint8_
StatusBar *statusbar = self->stb; StatusBar *statusbar = self->stb;
if (status == 1) { /* Friend shows online */ if (status == 1) { /* Friend goes online */
statusbar->is_online = true; statusbar->is_online = true;
friends[num].is_typing = tox_get_is_typing(m, num); friends[num].is_typing = user_settings_->show_typing_other == SHOW_TYPING_ON
? tox_get_is_typing(m, num) : 0;
notify(self, user_log_in, NT_NOFOCUS); notify(self, user_log_in, NT_NOFOCUS);
} else { /* Friend goes offline */ } else { /* Friend goes offline */
statusbar->is_online = false; statusbar->is_online = false;
friends[num].is_typing = 0; friends[num].is_typing = 0;
notify(self, user_log_out, NT_NOFOCUS); notify(self, user_log_out, NT_NOFOCUS);
if (self->chatwin->self_is_typing)
set_self_typingstatus(self, m, 0);
} }
} }
@ -743,8 +750,8 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
if (ltr) { /* char is printable */ if (ltr) { /* char is printable */
input_new_char(self, key, x, y, x2, y2); input_new_char(self, key, x, y, x2, y2);
if (ctx->line[0] != '/') if (ctx->line[0] != '/' && !ctx->self_is_typing && statusbar->is_online)
set_typingstatus(self, m, 1); set_self_typingstatus(self, m, 1);
return; return;
} }
@ -815,7 +822,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
} }
if (ctx->len <= 0 && ctx->self_is_typing) if (ctx->len <= 0 && ctx->self_is_typing)
set_typingstatus(self, m, 0); set_self_typingstatus(self, m, 0);
} }
static void chat_onDraw(ToxWindow *self, Tox *m) static void chat_onDraw(ToxWindow *self, Tox *m)

View File

@ -49,6 +49,8 @@ const struct _ui_strings {
const char* autolog; const char* autolog;
const char* time_format; const char* time_format;
const char* history_size; const char* history_size;
const char* show_typing_self;
const char* show_typing_other;
} ui_strings = { } ui_strings = {
"ui", "ui",
"timestamps", "timestamps",
@ -56,7 +58,9 @@ const struct _ui_strings {
"native_colors", "native_colors",
"autolog", "autolog",
"time_format", "time_format",
"history_size" "history_size",
"show_typing_self",
"show_typing_other",
}; };
static void ui_defaults(struct user_settings* settings) static void ui_defaults(struct user_settings* settings)
@ -67,6 +71,8 @@ static void ui_defaults(struct user_settings* settings)
settings->alerts = ALERTS_ENABLED; settings->alerts = ALERTS_ENABLED;
settings->colour_theme = DFLT_COLS; settings->colour_theme = DFLT_COLS;
settings->history_size = 700; settings->history_size = 700;
settings->show_typing_self = SHOW_TYPING_ON;
settings->show_typing_other = SHOW_TYPING_ON;
} }
const struct _keys_strings { const struct _keys_strings {
@ -233,8 +239,9 @@ int settings_load(struct user_settings *s, const char *patharg)
config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts); config_setting_lookup_bool(setting, ui_strings.alerts, &s->alerts);
config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog); config_setting_lookup_bool(setting, ui_strings.autolog, &s->autolog);
config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme); config_setting_lookup_bool(setting, ui_strings.native_colors, &s->colour_theme);
config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size); config_setting_lookup_int(setting, ui_strings.history_size, &s->history_size);
config_setting_lookup_bool(setting, ui_strings.show_typing_self, &s->show_typing_self);
config_setting_lookup_bool(setting, ui_strings.show_typing_other, &s->show_typing_other);
config_setting_lookup_int(setting, ui_strings.time_format, &s->time); config_setting_lookup_int(setting, ui_strings.time_format, &s->time);
s->time = s->time == TIME_24 || s->time == TIME_12 ? s->time : TIME_24; /* Check defaults */ s->time = s->time == TIME_24 || s->time == TIME_12 ? s->time : TIME_24; /* Check defaults */
} }
@ -244,6 +251,7 @@ int settings_load(struct user_settings *s, const char *patharg)
strcpy(s->download_path, str); strcpy(s->download_path, str);
} }
} }
/* keys */ /* keys */
if((setting = config_lookup(cfg, key_strings.self)) != NULL) { if((setting = config_lookup(cfg, key_strings.self)) != NULL) {
const char* tmp = NULL; const char* tmp = NULL;

View File

@ -31,6 +31,9 @@ struct user_settings {
int timestamps; /* boolean */ int timestamps; /* boolean */
int colour_theme; /* boolean (0 for default toxic colours) */ int colour_theme; /* boolean (0 for default toxic colours) */
int history_size; /* int between MIN_HISTORY and MAX_HISTORY */ int history_size; /* int between MIN_HISTORY and MAX_HISTORY */
int show_typing_self; /* boolean */
int show_typing_other; /* boolean */
char download_path[MAX_STR_SIZE]; char download_path[MAX_STR_SIZE];
int key_next_tab; /* character code */ int key_next_tab; /* character code */
@ -62,8 +65,11 @@ enum {
ALERTS_DISABLED = 0, ALERTS_DISABLED = 0,
ALERTS_ENABLED = 1, ALERTS_ENABLED = 1,
NATIVE_COLS = 1,
DFLT_COLS = 0, DFLT_COLS = 0,
NATIVE_COLS = 1,
SHOW_TYPING_OFF = 0,
SHOW_TYPING_ON = 1,
DFLT_HST_SIZE = 700, DFLT_HST_SIZE = 700,
} settings_values; } settings_values;

View File

@ -43,6 +43,7 @@ extern ToxWindow *prompt;
extern struct user_settings *user_settings_; extern struct user_settings *user_settings_;
static int num_active_windows; static int num_active_windows;
/* CALLBACKS START */ /* CALLBACKS START */
void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata) void on_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
{ {
@ -66,6 +67,9 @@ void on_connectionchange(Tox *m, int32_t friendnumber, uint8_t status, void *use
void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata) void on_typing_change(Tox *m, int32_t friendnumber, uint8_t is_typing, void *userdata)
{ {
if (user_settings_->show_typing_other == SHOW_TYPING_OFF)
return;
int i; int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) { for (i = 0; i < MAX_WINDOWS_NUM; ++i) {