diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2006-08-20 22:28:31 +0000 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2006-08-20 22:28:31 +0000 |
commit | 1f801ff07964a9c2d605a97715b5fea0aafd078c (patch) | |
tree | c09618afaca5bb6f8de939baf1d2383afc8360af /src | |
parent | 0d2afafbd02c3a8a847f584b793b84b612684011 (diff) | |
download | weechat-1f801ff07964a9c2d605a97715b5fea0aafd078c.zip |
Added hotlist in session file when using /upgrade command (task #5449)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/hotlist.c | 6 | ||||
-rw-r--r-- | src/common/hotlist.h | 2 | ||||
-rw-r--r-- | src/common/session.c | 121 | ||||
-rw-r--r-- | src/common/session.h | 11 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 20 | ||||
-rw-r--r-- | src/gui/gui-common.c | 8 | ||||
-rw-r--r-- | src/gui/gui.h | 1 | ||||
-rw-r--r-- | src/irc/irc-dcc.c | 2 | ||||
-rw-r--r-- | src/irc/irc-recv.c | 4 |
9 files changed, 155 insertions, 20 deletions
diff --git a/src/common/hotlist.c b/src/common/hotlist.c index 690183826..40518fe5d 100644 --- a/src/common/hotlist.c +++ b/src/common/hotlist.c @@ -76,7 +76,8 @@ hotlist_find_pos (t_weechat_hotlist *new_hotlist) */ void -hotlist_add (int priority, t_irc_server *server, t_gui_buffer *buffer) +hotlist_add (int priority, t_irc_server *server, t_gui_buffer *buffer, + int allow_current_buffer) { t_weechat_hotlist *new_hotlist, *pos_hotlist; @@ -84,7 +85,8 @@ hotlist_add (int priority, t_irc_server *server, t_gui_buffer *buffer) return; /* do not highlight current buffer */ - if (buffer == gui_current_window->buffer) + if ((buffer == gui_current_window->buffer) + && (!allow_current_buffer)) return; if ((pos_hotlist = hotlist_search (buffer))) diff --git a/src/common/hotlist.h b/src/common/hotlist.h index e4759ef96..3368c82e6 100644 --- a/src/common/hotlist.h +++ b/src/common/hotlist.h @@ -43,7 +43,7 @@ struct t_weechat_hotlist extern t_weechat_hotlist *hotlist; extern t_gui_buffer *hotlist_initial_buffer; -extern void hotlist_add (int, t_irc_server *, t_gui_buffer *); +extern void hotlist_add (int, t_irc_server *, t_gui_buffer *, int); extern void hotlist_free (t_weechat_hotlist *); extern void hotlist_free_all (); extern void hotlist_remove_buffer (t_gui_buffer *); diff --git a/src/common/session.c b/src/common/session.c index 59156dfa4..0b93f1278 100644 --- a/src/common/session.c +++ b/src/common/session.c @@ -36,6 +36,7 @@ #include "weechat.h" #include "session.h" +#include "hotlist.h" #include "log.h" #include "../irc/irc.h" #include "../gui/gui.h" @@ -437,6 +438,33 @@ session_save_uptime (FILE *file) } /* + * session_save_hotlist: save hotlist into session file + */ + +int +session_save_hotlist (FILE *file) +{ + int rc; + t_weechat_hotlist *ptr_hotlist; + + rc = 1; + + for (ptr_hotlist = hotlist; ptr_hotlist; + ptr_hotlist = ptr_hotlist->next_hotlist) + { + rc = rc && (session_write_id (file, SESSION_OBJ_HOTLIST)); + rc = rc && (session_write_int (file, SESSION_HOTL_PRIORITY, ptr_hotlist->priority)); + rc = rc && (session_write_str (file, SESSION_HOTL_SERVER, (ptr_hotlist->server) ? ptr_hotlist->server->name : NULL)); + rc = rc && (session_write_int (file, SESSION_HOTL_BUFFER_NUMBER, ptr_hotlist->buffer->number)); + rc = rc && (session_write_id (file, SESSION_HOTL_END)); + + if (!rc) + return 0; + } + return rc; +} + +/* * session_save: save current session */ @@ -456,6 +484,7 @@ session_save (char *filename) rc = rc && (session_save_history (file, history_global_last)); rc = rc && (session_save_buffers (file)); rc = rc && (session_save_uptime (file)); + rc = rc && (session_save_hotlist (file)); fclose (file); @@ -976,7 +1005,8 @@ session_load_server (FILE *file) break; default: weechat_log_printf (_("session: warning: ignoring value from " - "server (object id: %d)\n")); + "server (object id: %d)\n"), + object_id); rc = rc && (session_read_ignore_value (file)); break; } @@ -1078,7 +1108,8 @@ session_load_channel (FILE *file) break; default: weechat_log_printf (_("session: warning: ignoring value from " - "channel (object id: %d)\n")); + "channel (object id: %d)\n"), + object_id); rc = rc && (session_read_ignore_value (file)); break; } @@ -1148,7 +1179,8 @@ session_load_nick (FILE *file) break; default: weechat_log_printf (_("session: warning: ignoring value from " - "nick (object id: %d)\n")); + "nick (object id: %d)\n"), + object_id); rc = rc && (session_read_ignore_value (file)); break; } @@ -1311,7 +1343,8 @@ session_load_dcc (FILE *file) break; default: weechat_log_printf (_("session: warning: ignoring value from " - "DCC (object id: %d)\n")); + "DCC (object id: %d)\n"), + object_id); rc = rc && (session_read_ignore_value (file)); break; } @@ -1361,7 +1394,8 @@ session_load_history (FILE *file) break; default: weechat_log_printf (_("session: warning: ignoring value from " - "history (object id: %d)\n")); + "history (object id: %d)\n"), + object_id); rc = rc && (session_read_ignore_value (file)); break; } @@ -1463,7 +1497,8 @@ session_load_buffer (FILE *file) break; default: weechat_log_printf (_("session: warning: ignoring value from " - "buffer (object id: %d)\n")); + "buffer (object id: %d)\n"), + object_id); rc = rc && (session_read_ignore_value (file)); break; } @@ -1540,7 +1575,8 @@ session_load_line (FILE *file) break; default: weechat_log_printf (_("session: warning: ignoring value from " - "line (object id: %d)\n")); + "line (object id: %d)\n"), + object_id); rc = rc && (session_read_ignore_value (file)); break; } @@ -1577,7 +1613,67 @@ session_load_uptime (FILE *file) break; default: weechat_log_printf (_("session: warning: ignoring value from " - "uptime (object id: %d)\n")); + "uptime (object id: %d)\n"), + object_id); + rc = rc && (session_read_ignore_value (file)); + break; + } + } + return 0; +} + +/* + * session_load_hotlist: load hotlist from file + */ + +int +session_load_hotlist (FILE *file) +{ + int object_id, rc; + int priority; + char *server_name; + t_irc_server *ptr_server; + int buffer_number; + t_gui_buffer *ptr_buffer; + + priority = 0; + ptr_server = NULL; + ptr_buffer = NULL; + + /* read hotlist values */ + rc = 1; + while (rc) + { + if (feof (file)) + { + session_crash (file, _("unexpected end of file (reading hotlist)")); + return 0; + } + if (fread ((void *)(&object_id), sizeof (int), 1, file) == 0) + return 0; + switch (object_id) + { + case SESSION_HOTL_END: + hotlist_add (priority, ptr_server, ptr_buffer, 1); + return 1; + case SESSION_HOTL_PRIORITY: + rc = rc && (session_read_int (file, &priority)); + break; + case SESSION_HOTL_SERVER: + server_name = NULL; + if (!session_read_str (file, &server_name)) + return 0; + ptr_server = server_search (server_name); + free (server_name); + break; + case SESSION_HOTL_BUFFER_NUMBER: + rc = rc && (session_read_int (file, &buffer_number)); + ptr_buffer = gui_buffer_search_by_number (buffer_number); + break; + default: + weechat_log_printf (_("session: warning: ignoring value from " + "history (object id: %d)\n"), + object_id); rc = rc && (session_read_ignore_value (file)); break; } @@ -1690,6 +1786,13 @@ session_load (char *filename) return 0; } break; + case SESSION_OBJ_HOTLIST: + if (!session_load_hotlist (file)) + { + session_crash (file, _("failed to load hotlist")); + return 0; + } + break; default: weechat_log_printf (_("ignoring object (id: %d)\n"), object_id); @@ -1720,7 +1823,7 @@ session_load (char *filename) irc_display_prefix (NULL, gui_current_window->buffer, PREFIX_ERROR); gui_printf_nolog (gui_current_window->buffer, _("%s can't delete session file (%s)\n"), - WEECHAT_ERROR); + WEECHAT_ERROR, filename); } irc_display_prefix (NULL, gui_current_window->buffer, PREFIX_INFO); diff --git a/src/common/session.h b/src/common/session.h index 62129ca25..343e40db2 100644 --- a/src/common/session.h +++ b/src/common/session.h @@ -44,7 +44,8 @@ enum t_session_object SESSION_OBJ_HISTORY, SESSION_OBJ_BUFFER, SESSION_OBJ_LINE, - SESSION_OBJ_UPTIME + SESSION_OBJ_UPTIME, + SESSION_OBJ_HOTLIST }; enum t_session_server @@ -187,6 +188,14 @@ enum t_session_uptime SESSION_UPT_START_TIME }; +enum t_session_hotlist +{ + SESSION_HOTL_END = 0, + SESSION_HOTL_PRIORITY, + SESSION_HOTL_SERVER, + SESSION_HOTL_BUFFER_NUMBER +}; + int session_save (char *filename); int session_load (char *filename); diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index e53379a04..034a221be 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -290,6 +290,26 @@ gui_buffer_search (char *server, char *channel) } /* + * gui_buffer_search_by_number: search a buffer by number + */ + +t_gui_buffer * +gui_buffer_search_by_number (int number) +{ + t_gui_buffer *ptr_buffer; + + for (ptr_buffer = gui_buffers; ptr_buffer; + ptr_buffer = ptr_buffer->next_buffer) + { + if (ptr_buffer->number == number) + return ptr_buffer; + } + + /* buffer not found */ + return NULL; +} + +/* * gui_buffer_find_window: find a window displaying buffer */ diff --git a/src/gui/gui-common.c b/src/gui/gui-common.c index f01e07dc7..edf0541b2 100644 --- a/src/gui/gui-common.c +++ b/src/gui/gui-common.c @@ -180,13 +180,13 @@ gui_add_to_line (t_gui_buffer *buffer, int type, char *nick, char *message) buffer->notify_level) { if (buffer->last_line->line_with_highlight) - hotlist_add (HOTLIST_HIGHLIGHT, SERVER(buffer), buffer); + hotlist_add (HOTLIST_HIGHLIGHT, SERVER(buffer), buffer, 0); else if (BUFFER_IS_PRIVATE(buffer) && (buffer->last_line->line_with_message)) - hotlist_add (HOTLIST_PRIVATE, SERVER(buffer), buffer); + hotlist_add (HOTLIST_PRIVATE, SERVER(buffer), buffer, 0); else if (buffer->last_line->line_with_message) - hotlist_add (HOTLIST_MSG, SERVER(buffer), buffer); + hotlist_add (HOTLIST_MSG, SERVER(buffer), buffer, 0); else - hotlist_add (HOTLIST_LOW, SERVER(buffer), buffer); + hotlist_add (HOTLIST_LOW, SERVER(buffer), buffer, 0); gui_status_draw (gui_current_window->buffer, 1); } } diff --git a/src/gui/gui.h b/src/gui/gui.h index 9de39f1e5..d028bc748 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -83,6 +83,7 @@ extern void gui_window_print_log (t_gui_window *); extern t_gui_buffer *gui_buffer_servers_search (); extern t_gui_buffer *gui_buffer_new (t_gui_window *, void *, void *, int, int); extern t_gui_buffer *gui_buffer_search (char *, char *); +extern t_gui_buffer *gui_buffer_search_by_number (int); extern t_gui_window *gui_buffer_find_window (t_gui_buffer *); extern t_gui_buffer *gui_buffer_get_dcc (t_gui_window *); extern void gui_buffer_clear (t_gui_buffer *); diff --git a/src/irc/irc-dcc.c b/src/irc/irc-dcc.c index 9c4d17893..fd1a90d5c 100644 --- a/src/irc/irc-dcc.c +++ b/src/irc/irc-dcc.c @@ -66,7 +66,7 @@ dcc_redraw (int highlight) gui_window_redraw_buffer (gui_buffer_get_dcc (gui_current_window)); if (highlight) { - hotlist_add (highlight, NULL, gui_buffer_get_dcc (gui_current_window)); + hotlist_add (highlight, NULL, gui_buffer_get_dcc (gui_current_window), 0); gui_status_draw (gui_current_window->buffer, 0); } } diff --git a/src/irc/irc-recv.c b/src/irc/irc-recv.c index 3010ad5bf..0428a6363 100644 --- a/src/irc/irc-recv.c +++ b/src/irc/irc-recv.c @@ -413,7 +413,7 @@ irc_cmd_recv_invite (t_irc_server *server, char *host, char *nick, char *argumen GUI_COLOR(COLOR_WIN_CHAT), GUI_COLOR(COLOR_WIN_CHAT_NICK), nick); - hotlist_add (HOTLIST_HIGHLIGHT, server, server->buffer); + hotlist_add (HOTLIST_HIGHLIGHT, server, server->buffer, 0); gui_status_draw (gui_current_window->buffer, 1); } } @@ -1023,7 +1023,7 @@ irc_cmd_recv_notice (t_irc_server *server, char *host, char *nick, char *argumen (ascii_strcasecmp (nick, "chanserv") != 0) && (ascii_strcasecmp (nick, "memoserv") != 0)) { - hotlist_add (HOTLIST_PRIVATE, server, server->buffer); + hotlist_add (HOTLIST_PRIVATE, server, server->buffer, 0); gui_status_draw (gui_current_window->buffer, 1); } } |