Fixed bug when destroying last server

This commit is contained in:
Sebastien Helleu 2003-10-01 21:50:50 +00:00
parent 77e0d01d7a
commit d0bb1e0c2a
10 changed files with 118 additions and 68 deletions

View File

@ -552,7 +552,7 @@ weechat_cmd_connect (int argc, char **argv)
return -1; return -1;
} }
if (!ptr_server->window) if (!ptr_server->window)
server_create_window (ptr_server); gui_window_new (ptr_server, NULL);
if (server_connect (ptr_server)) if (server_connect (ptr_server))
{ {
irc_login (ptr_server); irc_login (ptr_server);
@ -935,7 +935,7 @@ weechat_cmd_server (int argc, char **argv)
if (new_server->autoconnect) if (new_server->autoconnect)
{ {
server_create_window (new_server); gui_window_new (new_server, NULL);
if (server_connect (new_server)) if (server_connect (new_server))
irc_login (new_server); irc_login (new_server);
} }

View File

@ -958,17 +958,34 @@ gui_draw_window_input (t_gui_window *window)
} }
else else
{ {
sprintf (format, "%%s> %%-%ds", input_width); if (SERVER(window))
if (SERVER(window) && (SERVER(window)->is_connected)) {
ptr_nickname = SERVER(window)->nick; sprintf (format, "%%s> %%-%ds", input_width);
if (SERVER(window) && (SERVER(window)->is_connected))
ptr_nickname = SERVER(window)->nick;
else
ptr_nickname = cfg_look_no_nickname;
mvwprintw (window->win_input, 0, 0, format,
ptr_nickname,
window->input_buffer + window->input_buffer_1st_display);
wclrtoeol (window->win_input);
move (LINES - 1, strlen (ptr_nickname) + 2 +
(window->input_buffer_pos - window->input_buffer_1st_display));
}
else else
ptr_nickname = cfg_look_no_nickname; {
mvwprintw (window->win_input, 0, 0, format, sprintf (format, "%%s> %%-%ds", input_width);
ptr_nickname, if (SERVER(window) && (SERVER(window)->is_connected))
window->input_buffer + window->input_buffer_1st_display); ptr_nickname = SERVER(window)->nick;
wclrtoeol (window->win_input); else
move (LINES - 1, strlen (ptr_nickname) + 2 + ptr_nickname = cfg_look_no_nickname;
(window->input_buffer_pos - window->input_buffer_1st_display)); mvwprintw (window->win_input, 0, 0, format,
ptr_nickname,
window->input_buffer + window->input_buffer_1st_display);
wclrtoeol (window->win_input);
move (LINES - 1, strlen (ptr_nickname) + 2 +
(window->input_buffer_pos - window->input_buffer_1st_display));
}
} }
wrefresh (window->win_input); wrefresh (window->win_input);
@ -1228,7 +1245,21 @@ gui_window_new (void *server, void *channel
/*int x, int y, int width, int height*/) /*int x, int y, int width, int height*/)
{ {
t_gui_window *new_window; t_gui_window *new_window;
if (gui_windows)
{
if (!SERVER(gui_windows))
{
if (server)
((t_irc_server *)(server))->window = gui_windows;
if (channel)
((t_irc_channel *)(channel))->window = gui_windows;
SERVER(gui_windows) = server;
CHANNEL(gui_windows) = channel;
return gui_windows;
}
}
if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window))))) if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window)))))
{ {
/* assign server and channel to window */ /* assign server and channel to window */
@ -1289,6 +1320,7 @@ gui_window_new (void *server, void *channel
} }
else else
return NULL; return NULL;
return new_window; return new_window;
} }
@ -1301,9 +1333,13 @@ gui_window_free (t_gui_window *window)
{ {
t_gui_line *ptr_line; t_gui_line *ptr_line;
t_gui_message *ptr_message; t_gui_message *ptr_message;
int create_new;
create_new = (window->server || window->channel);
/* TODO: manage splitted windows! */ /* TODO: manage splitted windows! */
if (window == gui_current_window) if ((window == gui_current_window) &&
((window->next_window) || (window->prev_window)))
gui_switch_to_previous_window (); gui_switch_to_previous_window ();
/* free lines and messages */ /* free lines and messages */
@ -1338,6 +1374,10 @@ gui_window_free (t_gui_window *window)
last_gui_window = window->prev_window; last_gui_window = window->prev_window;
free (window); free (window);
/* always at least one window */
if (!gui_windows && create_new)
gui_window_new (NULL, NULL);
} }
/* /*
@ -1539,7 +1579,7 @@ gui_end ()
/* TODO: free input buffer, lines, messages, completion */ /* TODO: free input buffer, lines, messages, completion */
} }
/* end of ncurses output */ /* end of curses output */
refresh (); refresh ();
endwin (); endwin ();
} }

View File

@ -113,22 +113,6 @@ server_alloc ()
return new_server; return new_server;
} }
/*
* server_create_window: create windows for a server
*/
void
server_create_window (t_irc_server *server)
{
if (!SERVER(gui_windows))
{
server->window = gui_windows;
SERVER(gui_windows) = server;
}
else
gui_window_new (server, NULL);
}
/* /*
* server_destroy: free server data (not struct himself) * server_destroy: free server data (not struct himself)
*/ */
@ -181,6 +165,8 @@ server_free (t_irc_server *server)
(server->next_server)->prev_server = server->prev_server; (server->next_server)->prev_server = server->prev_server;
server_destroy (server); server_destroy (server);
if (server->window)
gui_window_free (server->window);
free (server); free (server);
irc_servers = new_irc_servers; irc_servers = new_irc_servers;
} }

View File

@ -140,7 +140,6 @@ extern t_irc_channel *current_channel;
extern void server_init (t_irc_server *); extern void server_init (t_irc_server *);
extern t_irc_server *server_alloc (); extern t_irc_server *server_alloc ();
extern void server_create_window (t_irc_server *);
extern void server_destroy (t_irc_server *); extern void server_destroy (t_irc_server *);
extern void server_free (t_irc_server *); extern void server_free (t_irc_server *);
extern void server_free_all (); extern void server_free_all ();

View File

@ -211,8 +211,8 @@ wee_init_log ()
void void
wee_shutdown () wee_shutdown ()
{ {
gui_end ();
server_free_all (); server_free_all ();
gui_end ();
if (log_file) if (log_file)
fclose (log_file); fclose (log_file);
exit (0); exit (0);
@ -298,7 +298,7 @@ main (int argc, char *argv[])
{ {
if (ptr_server->autoconnect) if (ptr_server->autoconnect)
{ {
server_create_window (ptr_server); gui_window_new (ptr_server, NULL);
if (server_connect (ptr_server)) if (server_connect (ptr_server))
irc_login (ptr_server); irc_login (ptr_server);
} }

View File

@ -552,7 +552,7 @@ weechat_cmd_connect (int argc, char **argv)
return -1; return -1;
} }
if (!ptr_server->window) if (!ptr_server->window)
server_create_window (ptr_server); gui_window_new (ptr_server, NULL);
if (server_connect (ptr_server)) if (server_connect (ptr_server))
{ {
irc_login (ptr_server); irc_login (ptr_server);
@ -935,7 +935,7 @@ weechat_cmd_server (int argc, char **argv)
if (new_server->autoconnect) if (new_server->autoconnect)
{ {
server_create_window (new_server); gui_window_new (new_server, NULL);
if (server_connect (new_server)) if (server_connect (new_server))
irc_login (new_server); irc_login (new_server);
} }

View File

@ -958,17 +958,34 @@ gui_draw_window_input (t_gui_window *window)
} }
else else
{ {
sprintf (format, "%%s> %%-%ds", input_width); if (SERVER(window))
if (SERVER(window) && (SERVER(window)->is_connected)) {
ptr_nickname = SERVER(window)->nick; sprintf (format, "%%s> %%-%ds", input_width);
if (SERVER(window) && (SERVER(window)->is_connected))
ptr_nickname = SERVER(window)->nick;
else
ptr_nickname = cfg_look_no_nickname;
mvwprintw (window->win_input, 0, 0, format,
ptr_nickname,
window->input_buffer + window->input_buffer_1st_display);
wclrtoeol (window->win_input);
move (LINES - 1, strlen (ptr_nickname) + 2 +
(window->input_buffer_pos - window->input_buffer_1st_display));
}
else else
ptr_nickname = cfg_look_no_nickname; {
mvwprintw (window->win_input, 0, 0, format, sprintf (format, "%%s> %%-%ds", input_width);
ptr_nickname, if (SERVER(window) && (SERVER(window)->is_connected))
window->input_buffer + window->input_buffer_1st_display); ptr_nickname = SERVER(window)->nick;
wclrtoeol (window->win_input); else
move (LINES - 1, strlen (ptr_nickname) + 2 + ptr_nickname = cfg_look_no_nickname;
(window->input_buffer_pos - window->input_buffer_1st_display)); mvwprintw (window->win_input, 0, 0, format,
ptr_nickname,
window->input_buffer + window->input_buffer_1st_display);
wclrtoeol (window->win_input);
move (LINES - 1, strlen (ptr_nickname) + 2 +
(window->input_buffer_pos - window->input_buffer_1st_display));
}
} }
wrefresh (window->win_input); wrefresh (window->win_input);
@ -1228,7 +1245,21 @@ gui_window_new (void *server, void *channel
/*int x, int y, int width, int height*/) /*int x, int y, int width, int height*/)
{ {
t_gui_window *new_window; t_gui_window *new_window;
if (gui_windows)
{
if (!SERVER(gui_windows))
{
if (server)
((t_irc_server *)(server))->window = gui_windows;
if (channel)
((t_irc_channel *)(channel))->window = gui_windows;
SERVER(gui_windows) = server;
CHANNEL(gui_windows) = channel;
return gui_windows;
}
}
if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window))))) if ((new_window = (t_gui_window *)(malloc (sizeof (t_gui_window)))))
{ {
/* assign server and channel to window */ /* assign server and channel to window */
@ -1289,6 +1320,7 @@ gui_window_new (void *server, void *channel
} }
else else
return NULL; return NULL;
return new_window; return new_window;
} }
@ -1301,9 +1333,13 @@ gui_window_free (t_gui_window *window)
{ {
t_gui_line *ptr_line; t_gui_line *ptr_line;
t_gui_message *ptr_message; t_gui_message *ptr_message;
int create_new;
create_new = (window->server || window->channel);
/* TODO: manage splitted windows! */ /* TODO: manage splitted windows! */
if (window == gui_current_window) if ((window == gui_current_window) &&
((window->next_window) || (window->prev_window)))
gui_switch_to_previous_window (); gui_switch_to_previous_window ();
/* free lines and messages */ /* free lines and messages */
@ -1338,6 +1374,10 @@ gui_window_free (t_gui_window *window)
last_gui_window = window->prev_window; last_gui_window = window->prev_window;
free (window); free (window);
/* always at least one window */
if (!gui_windows && create_new)
gui_window_new (NULL, NULL);
} }
/* /*
@ -1539,7 +1579,7 @@ gui_end ()
/* TODO: free input buffer, lines, messages, completion */ /* TODO: free input buffer, lines, messages, completion */
} }
/* end of ncurses output */ /* end of curses output */
refresh (); refresh ();
endwin (); endwin ();
} }

View File

@ -113,22 +113,6 @@ server_alloc ()
return new_server; return new_server;
} }
/*
* server_create_window: create windows for a server
*/
void
server_create_window (t_irc_server *server)
{
if (!SERVER(gui_windows))
{
server->window = gui_windows;
SERVER(gui_windows) = server;
}
else
gui_window_new (server, NULL);
}
/* /*
* server_destroy: free server data (not struct himself) * server_destroy: free server data (not struct himself)
*/ */
@ -181,6 +165,8 @@ server_free (t_irc_server *server)
(server->next_server)->prev_server = server->prev_server; (server->next_server)->prev_server = server->prev_server;
server_destroy (server); server_destroy (server);
if (server->window)
gui_window_free (server->window);
free (server); free (server);
irc_servers = new_irc_servers; irc_servers = new_irc_servers;
} }

View File

@ -140,7 +140,6 @@ extern t_irc_channel *current_channel;
extern void server_init (t_irc_server *); extern void server_init (t_irc_server *);
extern t_irc_server *server_alloc (); extern t_irc_server *server_alloc ();
extern void server_create_window (t_irc_server *);
extern void server_destroy (t_irc_server *); extern void server_destroy (t_irc_server *);
extern void server_free (t_irc_server *); extern void server_free (t_irc_server *);
extern void server_free_all (); extern void server_free_all ();

View File

@ -211,8 +211,8 @@ wee_init_log ()
void void
wee_shutdown () wee_shutdown ()
{ {
gui_end ();
server_free_all (); server_free_all ();
gui_end ();
if (log_file) if (log_file)
fclose (log_file); fclose (log_file);
exit (0); exit (0);
@ -298,7 +298,7 @@ main (int argc, char *argv[])
{ {
if (ptr_server->autoconnect) if (ptr_server->autoconnect)
{ {
server_create_window (ptr_server); gui_window_new (ptr_server, NULL);
if (server_connect (ptr_server)) if (server_connect (ptr_server))
irc_login (ptr_server); irc_login (ptr_server);
} }