1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-09 11:13:12 +02:00

Add IRC bar items (buffer name, lag indicator), use bar items from plugins with callback to core items if not found

This commit is contained in:
Sebastien Helleu
2008-09-21 19:32:41 +02:00
parent e1bb85457a
commit a8b12f2597
30 changed files with 396 additions and 47 deletions
+1
View File
@@ -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
+2
View File
@@ -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 \
+164
View File
@@ -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);
}
+25
View File
@@ -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 */
+1 -1
View File
@@ -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>
+1 -1
View File
@@ -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>
+1 -1
View File
@@ -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>
+1 -1
View File
@@ -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>
+1 -1
View File
@@ -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>
+2
View File
@@ -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");
}
/*
+1 -1
View File
@@ -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>
+6 -6
View File
@@ -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;
+3
View File
@@ -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;
+5
View File
@@ -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;
+6 -1
View File
@@ -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;
+18
View File
@@ -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) \