diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/plugins/irc/Makefile.am | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-bar-item.c | 164 | ||||
-rw-r--r-- | src/plugins/irc/irc-bar-item.h | 25 | ||||
-rw-r--r-- | src/plugins/irc/irc-buffer.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-color.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-completion.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-display.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-mode.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-nick.c | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 12 | ||||
-rw-r--r-- | src/plugins/irc/irc.c | 3 | ||||
-rw-r--r-- | src/plugins/irc/irc.h | 5 | ||||
-rw-r--r-- | src/plugins/plugin.c | 7 | ||||
-rw-r--r-- | src/plugins/weechat-plugin.h | 18 |
16 files changed, 238 insertions, 13 deletions
diff --git a/src/plugins/irc/CMakeLists.txt b/src/plugins/irc/CMakeLists.txt index 7ed63016c..4a2b6e250 100644 --- a/src/plugins/irc/CMakeLists.txt +++ b/src/plugins/irc/CMakeLists.txt @@ -16,6 +16,7 @@ ADD_LIBRARY(irc MODULE irc.c irc.h +irc-bar-item.c irc-bar-item.h irc-buffer.c irc-buffer.h irc-channel.c irc-channel.h irc-color.c irc-color.h diff --git a/src/plugins/irc/Makefile.am b/src/plugins/irc/Makefile.am index f6ff77f85..13648f691 100644 --- a/src/plugins/irc/Makefile.am +++ b/src/plugins/irc/Makefile.am @@ -22,6 +22,8 @@ lib_LTLIBRARIES = irc.la irc_la_SOURCES = irc.c \ irc.h \ + irc-bar-item.c \ + irc-bar-item.h \ irc-buffer.c \ irc-buffer.h \ irc-channel.c \ diff --git a/src/plugins/irc/irc-bar-item.c b/src/plugins/irc/irc-bar-item.c new file mode 100644 index 000000000..9f8258736 --- /dev/null +++ b/src/plugins/irc/irc-bar-item.c @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/* irc-bar-item.c: bar items for IRC plugin */ + + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +#include "../weechat-plugin.h" +#include "irc.h" +#include "irc-buffer.h" +#include "irc-config.h" +#include "irc-server.h" +#include "irc-channel.h" + + +/* + * irc_bar_item_buffer_name: bar item with buffer name + */ + +char * +irc_bar_item_buffer_name (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width, int max_height) +{ + char buf[256], buf_name[256], *name; + int number; + struct t_gui_buffer *buffer; + struct t_irc_server *server; + struct t_irc_channel *channel; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) max_width; + (void) max_height; + + if (!window) + window = weechat_current_window; + + buf_name[0] = '\0'; + + buffer = weechat_window_get_pointer (window, "buffer"); + + if (buffer) + { + number = weechat_buffer_get_integer (buffer, "number"); + + irc_buffer_get_server_channel (buffer, &server, &channel); + if (server || channel) + { + if (server && !channel) + { + snprintf (buf_name, sizeof (buf_name), "%s%s[%s%s%s]", + _("server"), + IRC_COLOR_BAR_DELIM, + IRC_COLOR_STATUS_NAME, + server->name, + IRC_COLOR_BAR_DELIM); + } + else + { + if (channel) + { + snprintf (buf_name, sizeof (buf_name), + "%s%s%s/%s%s%s(%s%s%s)", + IRC_COLOR_STATUS_NAME, + server->name, + IRC_COLOR_BAR_DELIM, + IRC_COLOR_STATUS_NAME, + channel->name, + IRC_COLOR_BAR_DELIM, + IRC_COLOR_STATUS_NAME, + channel->modes, + IRC_COLOR_BAR_DELIM); + } + } + } + else + { + name = weechat_buffer_get_string (buffer, "name"); + if (name) + snprintf (buf_name, sizeof (buf_name), "%s", name); + } + + snprintf (buf, sizeof (buf), "%s%d%s:%s%s", + IRC_COLOR_STATUS_NUMBER, + number, + IRC_COLOR_BAR_DELIM, + IRC_COLOR_STATUS_NAME, + buf_name); + return strdup (buf); + } + + return NULL; +} + +/* + * irc_bar_item_lag: bar item with lag value + */ + +char * +irc_bar_item_lag (void *data, struct t_gui_bar_item *item, + struct t_gui_window *window, + int max_width, int max_height) +{ + char buf[32]; + struct t_gui_buffer *buffer; + struct t_irc_server *server; + + /* make C compiler happy */ + (void) data; + (void) item; + (void) window; + (void) max_width; + (void) max_height; + + buffer = weechat_window_get_pointer (window, "buffer"); + + if (buffer) + { + irc_buffer_get_server_channel (buffer, &server, NULL); + + if (server + && (server->lag >= weechat_config_integer (irc_config_network_lag_min_show) * 1000)) + { + snprintf (buf, sizeof (buf), + "%s: %.1f", + _("Lag"), + ((float)(server->lag)) / 1000); + return strdup (buf); + } + } + + return NULL; +} + +/* + * irc_bar_item_init: initialize IRC bar items + */ + +void +irc_bar_item_init () +{ + weechat_bar_item_new ("buffer_name", &irc_bar_item_buffer_name, NULL); + weechat_bar_item_new ("lag", &irc_bar_item_lag, NULL); +} diff --git a/src/plugins/irc/irc-bar-item.h b/src/plugins/irc/irc-bar-item.h new file mode 100644 index 000000000..749a27301 --- /dev/null +++ b/src/plugins/irc/irc-bar-item.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org> + * See README for License detail, AUTHORS for developers list. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef __WEECHAT_IRC_BAR_ITEM_H +#define __WEECHAT_IRC_BAR_ITEM_H 1 + +extern void irc_bar_item_init (); + +#endif /* irc-bar_item.h */ diff --git a/src/plugins/irc/irc-buffer.c b/src/plugins/irc/irc-buffer.c index 268f4c7d0..ab3862035 100644 --- a/src/plugins/irc/irc-buffer.c +++ b/src/plugins/irc/irc-buffer.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* irc-buffer.c: manages buffers for IRC protocol */ +/* irc-buffer.c: manages buffers for IRC plugin */ #include <stdlib.h> diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index a4ccf0d41..dcc3350df 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* irc-channel.c: manages a chat (channel or private chat) */ +/* irc-channel.c: manages a chat (channel or private chat) for IRC plugin */ #include <stdlib.h> diff --git a/src/plugins/irc/irc-color.c b/src/plugins/irc/irc-color.c index dd2bf28c3..974e20f7e 100644 --- a/src/plugins/irc/irc-color.c +++ b/src/plugins/irc/irc-color.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* irc-color.c: IRC color decoding/encidong in messages */ +/* irc-color.c: IRC color decoding/encoding in messages */ #include <stdlib.h> diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c index cf28f50c3..6ca570412 100644 --- a/src/plugins/irc/irc-completion.c +++ b/src/plugins/irc/irc-completion.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* irc-command.c: IRC commands managment */ +/* irc-completion.c: completion for IRC commands */ #include <stdlib.h> diff --git a/src/plugins/irc/irc-display.c b/src/plugins/irc/irc-display.c index e6c31889a..e1c8a4a61 100644 --- a/src/plugins/irc/irc-display.c +++ b/src/plugins/irc/irc-display.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* irc-display.c: display functions for IRC */ +/* irc-display.c: display functions for IRC plugin */ #include <stdlib.h> diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c index 3afaacf5f..e7520253b 100644 --- a/src/plugins/irc/irc-mode.c +++ b/src/plugins/irc/irc-mode.c @@ -206,6 +206,8 @@ irc_mode_channel_set (struct t_irc_server *server, free (str_modes); if (argv) weechat_string_free_exploded (argv); + + weechat_bar_item_update ("buffer_name"); } /* diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c index fb68993ec..96312fc58 100644 --- a/src/plugins/irc/irc-nick.c +++ b/src/plugins/irc/irc-nick.c @@ -16,7 +16,7 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* irc-nick.c: manages nick list for channels */ +/* irc-nick.c: manages nick list for channels for IRC plugin */ #include <stdlib.h> diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 2871ea445..57db6947c 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -/* irc-protocol.c: description of IRC commands, according to RFC 1459, 2810, - 2811 2812 */ +/* irc-protocol.c: implementation of IRC protocol, according to + RFC 1459, 2810, 2811 2812 */ #ifndef __USE_XOPEN @@ -989,10 +989,10 @@ irc_protocol_cmd_pong (struct t_irc_server *server, const char *command, /* calculate lag (time diff with lag check) */ old_lag = server->lag; gettimeofday (&tv, NULL); - server->lag = (int) weechat_timeval_diff (&(server->lag_check_time), &tv); - /* TODO: update lag indicator */ - //if (old_lag != server->lag) - // gui_status_draw (gui_current_window->buffer, 1); + server->lag = (int) weechat_timeval_diff (&(server->lag_check_time), + &tv); + if (old_lag != server->lag) + weechat_bar_item_update ("lag"); /* schedule next lag check */ server->lag_check_time.tv_sec = 0; diff --git a/src/plugins/irc/irc.c b/src/plugins/irc/irc.c index f2ada2b7d..d836f02ce 100644 --- a/src/plugins/irc/irc.c +++ b/src/plugins/irc/irc.c @@ -24,6 +24,7 @@ #include "../weechat-plugin.h" #include "irc.h" +#include "irc-bar-item.h" #include "irc-command.h" #include "irc-completion.h" #include "irc-config.h" @@ -128,6 +129,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) /* hook completions */ irc_completion_init (); + irc_bar_item_init (); + /* look at arguments */ auto_connect = 1; upgrading = 0; diff --git a/src/plugins/irc/irc.h b/src/plugins/irc/irc.h index 4702f6e1f..14b75a6f9 100644 --- a/src/plugins/irc/irc.h +++ b/src/plugins/irc/irc.h @@ -58,6 +58,11 @@ #define IRC_COLOR_NICKLIST_PREFIX3 weechat_color("nicklist_prefix3") #define IRC_COLOR_NICKLIST_PREFIX4 weechat_color("nicklist_prefix4") #define IRC_COLOR_NICKLIST_PREFIX5 weechat_color("nicklist_prefix5") +#define IRC_COLOR_BAR_FG weechat_color("bar_fg") +#define IRC_COLOR_BAR_BG weechat_color("bar_bg") +#define IRC_COLOR_BAR_DELIM weechat_color("bar_delim") +#define IRC_COLOR_STATUS_NUMBER weechat_color("status_number") +#define IRC_COLOR_STATUS_NAME weechat_color("status_name") extern struct t_weechat_plugin *weechat_irc_plugin; extern struct t_hook *irc_hook_timer_check_away; diff --git a/src/plugins/plugin.c b/src/plugins/plugin.c index 78bb8f732..c08de42ad 100644 --- a/src/plugins/plugin.c +++ b/src/plugins/plugin.c @@ -49,6 +49,7 @@ #include "../gui/gui-buffer.h" #include "../gui/gui-chat.h" #include "../gui/gui-nicklist.h" +#include "../gui/gui-window.h" #include "plugin.h" #include "plugin-api.h" #include "plugin-config.h" @@ -399,7 +400,11 @@ plugin_load (const char *filename) new_plugin->buffer_get_string = &gui_buffer_get_string; new_plugin->buffer_get_pointer = &gui_buffer_get_pointer; new_plugin->buffer_set = &gui_buffer_set; - + + new_plugin->window_get_integer = &gui_window_get_integer; + new_plugin->window_get_string = &gui_window_get_string; + new_plugin->window_get_pointer = &gui_window_get_pointer; + new_plugin->nicklist_add_group = &gui_nicklist_add_group; new_plugin->nicklist_search_group = &gui_nicklist_search_group; new_plugin->nicklist_add_nick = &gui_nicklist_add_nick; diff --git a/src/plugins/weechat-plugin.h b/src/plugins/weechat-plugin.h index 43066d8cf..de2c7c567 100644 --- a/src/plugins/weechat-plugin.h +++ b/src/plugins/weechat-plugin.h @@ -415,6 +415,14 @@ struct t_weechat_plugin const char *property); void (*buffer_set) (struct t_gui_buffer *buffer, const char *property, void *value); + + /* windows */ + int (*window_get_integer) (struct t_gui_window *window, + const char *property); + char *(*window_get_string) (struct t_gui_window *window, + const char *property); + void *(*window_get_pointer) (struct t_gui_window *window, + const char *property); /* nicklist */ struct t_gui_nick_group *(*nicklist_add_group) (struct t_gui_buffer *buffer, @@ -890,6 +898,16 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin); #define weechat_buffer_set(__buffer, __property, __value) \ weechat_plugin->buffer_set(__buffer, __property, __value) +/* windows */ +#define weechat_window_get_integer(__window, __property) \ + weechat_plugin->window_get_integer(__window, __property) +#define weechat_window_get_string(__window, __property) \ + weechat_plugin->window_get_string(__window, __property) +#define weechat_window_get_pointer(__window, __property) \ + weechat_plugin->window_get_pointer(__window, __property) +#define weechat_current_window \ + weechat_plugin->window_get_pointer(NULL, "current") + /* nicklist */ #define weechat_nicklist_add_group(__buffer, __parent_group, __name, \ __color, __visible) \ |