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

fix window cleanup bugs & give prompt its own cleanup func

This commit is contained in:
Jfreegman 2014-07-08 19:24:44 -04:00
parent 5b9fd70f30
commit 9fa5a3fdb6
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
8 changed files with 52 additions and 37 deletions

View File

@ -114,15 +114,11 @@ static void chat_set_window_name(ToxWindow *self, char *nick, int len)
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;
StatusBar *statusbar = self->stb;
if (ctx->self_is_typing)
set_typingstatus(self, m, 0);
log_disable(ctx->log);
line_info_cleanup(ctx->hst);
@ -130,21 +126,17 @@ void kill_chat_window(ToxWindow *self, Tox *m)
stop_current_call(self);
#endif
int f_num = self->num;
delwin(ctx->linewin);
delwin(ctx->history);
delwin(self->window);
delwin(statusbar->topline);
del_window(self);
disable_chatwin(f_num);
free(ctx->log);
free(ctx->hst);
free(ctx);
free(self->help);
free(statusbar);
disable_chatwin(self->num);
del_window(self);
}
@ -716,7 +708,7 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
if (line[0] == '/') {
if (strcmp(line, "/close") == 0) {
kill_chat_window(self, m);
kill_chat_window(self);
return;
} else if (strncmp(line, "/me ", strlen("/me ")) == 0) {
send_action(self, ctx, m, line + strlen("/me "));

View File

@ -93,7 +93,6 @@ void kill_groupchat_window(ToxWindow *self)
delwin(ctx->linewin);
delwin(ctx->history);
delwin(ctx->sidebar);
delwin(self->window);
free(ctx->log);
free(ctx->hst);
free(ctx);
@ -103,7 +102,6 @@ void kill_groupchat_window(ToxWindow *self)
static void close_groupchat(ToxWindow *self, Tox *m, int groupnum)
{
set_active_window(0);
tox_del_groupchat(m, groupnum);
free(groupchats[groupnum].peer_names);

View File

@ -80,6 +80,13 @@ void line_info_cleanup(struct history *hst)
free(tmp1);
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 */

View File

@ -213,7 +213,7 @@ void get_file_name(char *namebuf, const char *pathname)
filename = tmpname;
}
snprintf(namebuf, MAX_STR_SIZE, "%s", filename);
snprintf(namebuf, sizeof(namebuf), "%s", filename);
}
/* converts str to all lowercase */

View File

@ -69,6 +69,26 @@ const char glob_cmd_list[AC_NUM_GLOB_COMMANDS][MAX_CMDNAME_SIZE] = {
#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 */
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, "_");
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);
statusmsg[s_len] = '\0';
}

View File

@ -39,5 +39,6 @@ void prompt_update_nick(ToxWindow *prompt, char *nick);
void prompt_update_statusmessage(ToxWindow *prompt, char *statusmsg);
void prompt_update_status(ToxWindow *prompt, uint8_t status);
void prompt_update_connectionstatus(ToxWindow *prompt, bool is_connected);
void kill_prompt_window(ToxWindow *self);
#endif /* end of include guard: PROMPT_H_UZYGWFFL */

View File

@ -96,15 +96,10 @@ void exit_toxic_success(Tox *m)
store_data(m, DATA_FILE);
close_all_file_senders(m);
kill_all_windows();
log_disable(prompt->chatwin->log);
line_info_cleanup(prompt->chatwin->hst);
free(DATA_FILE);
free(prompt->stb);
free(prompt->help);
free(prompt->chatwin->log);
free(prompt->chatwin->hst);
free(prompt->chatwin);
free(user_settings);
#ifdef _SUPPORT_AUDIO
terminate_audio();
#endif /* _SUPPORT_AUDIO */

View File

@ -254,17 +254,12 @@ int add_window(Tox *m, ToxWindow w)
return -1;
}
/* Deletes window w and cleans up */
void del_window(ToxWindow *w)
void set_active_window(int index)
{
active_window = windows; /* Go to prompt screen */
if (index < 0 || index >= MAX_WINDOWS_NUM)
return;
delwin(w->window);
memset(w, 0, sizeof(ToxWindow));
clear();
refresh();
--num_active_windows;
active_window = windows + index;
}
/* 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)
return;
set_active_window(0); /* Go to prompt screen */
active_window = windows + index;
delwin(w->window);
memset(w, 0, sizeof(ToxWindow));
clear();
refresh();
--num_active_windows;
}
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) */
void kill_all_windows(void)
{
kill_prompt_window(prompt);
int i;
for (i = 0; i < MAX_WINDOWS_NUM; ++i) {