mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 01:43:01 +01:00
fix window cleanup bugs & give prompt its own cleanup func
This commit is contained in:
parent
5b9fd70f30
commit
9fa5a3fdb6
16
src/chat.c
16
src/chat.c
@ -114,15 +114,11 @@ static void chat_set_window_name(ToxWindow *self, char *nick, int len)
|
|||||||
snprintf(self->name, sizeof(self->name), "%s", nick);
|
snprintf(self->name, sizeof(self->name), "%s", nick);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kill_chat_window(ToxWindow *self, Tox *m)
|
void kill_chat_window(ToxWindow *self)
|
||||||
{
|
{
|
||||||
set_active_window(0);
|
|
||||||
ChatContext *ctx = self->chatwin;
|
ChatContext *ctx = self->chatwin;
|
||||||
StatusBar *statusbar = self->stb;
|
StatusBar *statusbar = self->stb;
|
||||||
|
|
||||||
if (ctx->self_is_typing)
|
|
||||||
set_typingstatus(self, m, 0);
|
|
||||||
|
|
||||||
log_disable(ctx->log);
|
log_disable(ctx->log);
|
||||||
line_info_cleanup(ctx->hst);
|
line_info_cleanup(ctx->hst);
|
||||||
|
|
||||||
@ -130,21 +126,17 @@ void kill_chat_window(ToxWindow *self, Tox *m)
|
|||||||
stop_current_call(self);
|
stop_current_call(self);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int f_num = self->num;
|
|
||||||
|
|
||||||
delwin(ctx->linewin);
|
delwin(ctx->linewin);
|
||||||
delwin(ctx->history);
|
delwin(ctx->history);
|
||||||
delwin(self->window);
|
|
||||||
delwin(statusbar->topline);
|
delwin(statusbar->topline);
|
||||||
|
|
||||||
del_window(self);
|
|
||||||
disable_chatwin(f_num);
|
|
||||||
|
|
||||||
free(ctx->log);
|
free(ctx->log);
|
||||||
free(ctx->hst);
|
free(ctx->hst);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
free(self->help);
|
free(self->help);
|
||||||
free(statusbar);
|
free(statusbar);
|
||||||
|
|
||||||
|
disable_chatwin(self->num);
|
||||||
del_window(self);
|
del_window(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,7 +708,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
|||||||
|
|
||||||
if (line[0] == '/') {
|
if (line[0] == '/') {
|
||||||
if (strcmp(line, "/close") == 0) {
|
if (strcmp(line, "/close") == 0) {
|
||||||
kill_chat_window(self, m);
|
kill_chat_window(self);
|
||||||
return;
|
return;
|
||||||
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
|
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
|
||||||
send_action(self, ctx, m, line + strlen("/me "));
|
send_action(self, ctx, m, line + strlen("/me "));
|
||||||
|
@ -93,7 +93,6 @@ void kill_groupchat_window(ToxWindow *self)
|
|||||||
delwin(ctx->linewin);
|
delwin(ctx->linewin);
|
||||||
delwin(ctx->history);
|
delwin(ctx->history);
|
||||||
delwin(ctx->sidebar);
|
delwin(ctx->sidebar);
|
||||||
delwin(self->window);
|
|
||||||
free(ctx->log);
|
free(ctx->log);
|
||||||
free(ctx->hst);
|
free(ctx->hst);
|
||||||
free(ctx);
|
free(ctx);
|
||||||
@ -103,7 +102,6 @@ void kill_groupchat_window(ToxWindow *self)
|
|||||||
|
|
||||||
static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
|
static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
|
||||||
{
|
{
|
||||||
set_active_window(0);
|
|
||||||
tox_del_groupchat(m, groupnum);
|
tox_del_groupchat(m, groupnum);
|
||||||
|
|
||||||
free(groupchats[groupnum].peer_names);
|
free(groupchats[groupnum].peer_names);
|
||||||
|
@ -80,6 +80,13 @@ void line_info_cleanup(struct history *hst)
|
|||||||
free(tmp1);
|
free(tmp1);
|
||||||
tmp1 = tmp2;
|
tmp1 = tmp2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < hst->queue_sz; ++i) {
|
||||||
|
if (hst->queue[i])
|
||||||
|
free(hst->queue[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* moves root forward and frees previous root */
|
/* moves root forward and frees previous root */
|
||||||
|
@ -213,7 +213,7 @@ void get_file_name(char *namebuf, const char *pathname)
|
|||||||
filename = tmpname;
|
filename = tmpname;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(namebuf, MAX_STR_SIZE, "%s", filename);
|
snprintf(namebuf, sizeof(namebuf), "%s", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* converts str to all lowercase */
|
/* converts str to all lowercase */
|
||||||
|
22
src/prompt.c
22
src/prompt.c
@ -69,6 +69,26 @@ const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
|
|||||||
#endif /* _SUPPORT_AUDIO */
|
#endif /* _SUPPORT_AUDIO */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void kill_prompt_window(ToxWindow *self) {
|
||||||
|
ChatContext *ctx = self->chatwin;
|
||||||
|
StatusBar *statusbar = self->stb;
|
||||||
|
|
||||||
|
log_disable(ctx->log);
|
||||||
|
line_info_cleanup(ctx->hst);
|
||||||
|
|
||||||
|
delwin(ctx->linewin);
|
||||||
|
delwin(ctx->history);
|
||||||
|
delwin(statusbar->topline);
|
||||||
|
|
||||||
|
free(ctx->log);
|
||||||
|
free(ctx->hst);
|
||||||
|
free(ctx);
|
||||||
|
free(self->help);
|
||||||
|
free(statusbar);
|
||||||
|
|
||||||
|
del_window(self);
|
||||||
|
}
|
||||||
|
|
||||||
/* Updates own nick in prompt statusbar */
|
/* Updates own nick in prompt statusbar */
|
||||||
void prompt_update_nick(ToxWindow *prompt, char *nick)
|
void prompt_update_nick(ToxWindow *prompt, char *nick)
|
||||||
{
|
{
|
||||||
@ -348,7 +368,7 @@ void prompt_init_statusbar(ToxWindow *self, Tox *m)
|
|||||||
const char *toxic_ver = strtok(ver, "_");
|
const char *toxic_ver = strtok(ver, "_");
|
||||||
|
|
||||||
if ( (!strcmp("Online", statusmsg) || !strncmp("Toxing on Toxic", statusmsg, 15)) && toxic_ver != NULL) {
|
if ( (!strcmp("Online", statusmsg) || !strncmp("Toxing on Toxic", statusmsg, 15)) && toxic_ver != NULL) {
|
||||||
snprintf(statusmsg, MAX_STR_SIZE, "Toxing on Toxic v.%s", toxic_ver);
|
snprintf(statusmsg, sizeof(statusmsg), "Toxing on Toxic v.%s", toxic_ver);
|
||||||
s_len = strlen(statusmsg);
|
s_len = strlen(statusmsg);
|
||||||
statusmsg[s_len] = '\0';
|
statusmsg[s_len] = '\0';
|
||||||
}
|
}
|
||||||
|
@ -39,5 +39,6 @@ void prompt_update_nick(ToxWindow *prompt, char *nick);
|
|||||||
void prompt_update_statusmessage(ToxWindow *prompt, char *statusmsg);
|
void prompt_update_statusmessage(ToxWindow *prompt, char *statusmsg);
|
||||||
void prompt_update_status(ToxWindow *prompt, uint8_t status);
|
void prompt_update_status(ToxWindow *prompt, uint8_t status);
|
||||||
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected);
|
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected);
|
||||||
|
void kill_prompt_window(ToxWindow *self);
|
||||||
|
|
||||||
#endif /* end of include guard: PROMPT_H_UZYGWFFL */
|
#endif /* end of include guard: PROMPT_H_UZYGWFFL */
|
||||||
|
@ -96,15 +96,10 @@ void exit_toxic_success(Tox *m)
|
|||||||
store_data(m, DATA_FILE);
|
store_data(m, DATA_FILE);
|
||||||
close_all_file_senders(m);
|
close_all_file_senders(m);
|
||||||
kill_all_windows();
|
kill_all_windows();
|
||||||
log_disable(prompt->chatwin->log);
|
|
||||||
line_info_cleanup(prompt->chatwin->hst);
|
|
||||||
free(DATA_FILE);
|
free(DATA_FILE);
|
||||||
free(prompt->stb);
|
|
||||||
free(prompt->help);
|
|
||||||
free(prompt->chatwin->log);
|
|
||||||
free(prompt->chatwin->hst);
|
|
||||||
free(prompt->chatwin);
|
|
||||||
free(user_settings);
|
free(user_settings);
|
||||||
|
|
||||||
#ifdef _SUPPORT_AUDIO
|
#ifdef _SUPPORT_AUDIO
|
||||||
terminate_audio();
|
terminate_audio();
|
||||||
#endif /* _SUPPORT_AUDIO */
|
#endif /* _SUPPORT_AUDIO */
|
||||||
|
@ -254,17 +254,12 @@ int add_window(Tox *m, ToxWindow w)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Deletes window w and cleans up */
|
void set_active_window(int index)
|
||||||
void del_window(ToxWindow *w)
|
|
||||||
{
|
{
|
||||||
active_window = windows; /* Go to prompt screen */
|
if (index < 0 || index >= MAX_WINDOWS_NUM)
|
||||||
|
return;
|
||||||
|
|
||||||
delwin(w->window);
|
active_window = windows + index;
|
||||||
memset(w, 0, sizeof(ToxWindow));
|
|
||||||
|
|
||||||
clear();
|
|
||||||
refresh();
|
|
||||||
--num_active_windows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Shows next window when tab or back-tab is pressed */
|
/* Shows next window when tab or back-tab is pressed */
|
||||||
@ -288,12 +283,17 @@ void set_next_window(int ch)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_active_window(int index)
|
/* Deletes window w and cleans up */
|
||||||
|
void del_window(ToxWindow *w)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= MAX_WINDOWS_NUM)
|
set_active_window(0); /* Go to prompt screen */
|
||||||
return;
|
|
||||||
|
|
||||||
active_window = windows + index;
|
delwin(w->window);
|
||||||
|
memset(w, 0, sizeof(ToxWindow));
|
||||||
|
|
||||||
|
clear();
|
||||||
|
refresh();
|
||||||
|
--num_active_windows;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToxWindow *init_windows(Tox *m)
|
ToxWindow *init_windows(Tox *m)
|
||||||
@ -497,6 +497,8 @@ int get_num_active_windows(void)
|
|||||||
/* destroys all chat and groupchat windows (should only be called on shutdown) */
|
/* destroys all chat and groupchat windows (should only be called on shutdown) */
|
||||||
void kill_all_windows(void)
|
void kill_all_windows(void)
|
||||||
{
|
{
|
||||||
|
kill_prompt_window(prompt);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||||
|
Loading…
Reference in New Issue
Block a user