2000-04-26 04:03:38 -04:00
|
|
|
/*
|
2001-03-12 05:33:13 -05:00
|
|
|
statusbar-items.c : irssi
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
Copyright (C) 1999-2001 Timo Sirainen
|
2000-04-26 04:03:38 -04:00
|
|
|
|
|
|
|
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 2 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, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "module.h"
|
|
|
|
#include "signals.h"
|
|
|
|
#include "settings.h"
|
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
#include "themes.h"
|
2000-05-04 06:32:42 -04:00
|
|
|
#include "statusbar.h"
|
2001-10-13 12:11:13 -04:00
|
|
|
#include "gui-entry.h"
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-06-10 20:42:37 -04:00
|
|
|
/* how often to redraw lagging time (seconds) */
|
2000-04-26 04:03:38 -04:00
|
|
|
#define LAG_REFRESH_TIME 10
|
2000-06-10 20:42:37 -04:00
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
/* If we haven't been able to check lag for this long, "(??)" is added after
|
|
|
|
the lag */
|
|
|
|
#define MAX_LAG_UNKNOWN_TIME 30
|
|
|
|
|
|
|
|
/* activity */
|
|
|
|
static GList *activity_list;
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static GHashTable *input_entries;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_window_active(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
WINDOW_REC *window;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
window = active_win;
|
|
|
|
if (item->bar->parent_window != NULL)
|
|
|
|
window = item->bar->parent_window->active;
|
2001-03-12 05:33:13 -05:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (window != NULL && window->active != NULL) {
|
|
|
|
statusbar_item_default_handler(item, get_size_only,
|
|
|
|
NULL, "", TRUE);
|
|
|
|
} else if (get_size_only) {
|
|
|
|
item->min_size = item->max_size = 0;
|
2001-03-12 05:33:13 -05:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_window_empty(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
WINDOW_REC *window;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
window = active_win;
|
|
|
|
if (item->bar->parent_window != NULL)
|
|
|
|
window = item->bar->parent_window->active;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (window != NULL && window->active == NULL) {
|
|
|
|
statusbar_item_default_handler(item, get_size_only,
|
|
|
|
NULL, "", TRUE);
|
|
|
|
} else if (get_size_only) {
|
|
|
|
item->min_size = item->max_size = 0;
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_lag(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
SERVER_REC *server;
|
|
|
|
GString *str;
|
|
|
|
int lag_unknown, lag_min_show;
|
|
|
|
time_t now;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
server = active_win == NULL ? NULL : active_win->active_server;
|
|
|
|
if (server == NULL || server->lag_last_check == 0) {
|
|
|
|
/* No lag information */
|
|
|
|
if (get_size_only)
|
|
|
|
item->min_size = item->max_size = 0;
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
now = time(NULL);
|
|
|
|
str = g_string_new(NULL);
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
/* FIXME: ugly ugly.. */
|
|
|
|
if (server->lag_sent == 0 || now-server->lag_sent < 5) {
|
|
|
|
lag_unknown = now-server->lag_last_check >
|
|
|
|
MAX_LAG_UNKNOWN_TIME+settings_get_int("lag_check_time");
|
2001-10-21 06:25:37 -04:00
|
|
|
lag_min_show = settings_get_int("lag_min_show")*10;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (lag_min_show < 0 || (server->lag < lag_min_show && !lag_unknown)) {
|
|
|
|
/* small lag, don't display */
|
|
|
|
} else {
|
|
|
|
g_string_sprintfa(str, "%d.%02d", server->lag/1000,
|
|
|
|
(server->lag % 1000)/10);
|
|
|
|
if (lag_unknown)
|
|
|
|
g_string_append(str, " (?""?)");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* big lag, still waiting .. */
|
|
|
|
g_string_sprintfa(str, "%ld (?""?)",
|
|
|
|
(long) (now-server->lag_sent));
|
|
|
|
}
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
if (str->len != 0) {
|
|
|
|
statusbar_item_default_handler(item, get_size_only,
|
|
|
|
NULL, str->str, TRUE);
|
|
|
|
} else {
|
|
|
|
if (get_size_only)
|
|
|
|
item->min_size = item->max_size = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_string_free(str, TRUE);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
static char *get_activity_list(MAIN_WINDOW_REC *window, int normal, int hilight)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-23 17:26:03 -04:00
|
|
|
THEME_REC *theme;
|
2001-03-12 05:33:13 -05:00
|
|
|
GString *str;
|
|
|
|
GList *tmp;
|
2001-10-23 17:26:03 -04:00
|
|
|
char *ret, *name, *format, *value;
|
2001-03-12 05:33:13 -05:00
|
|
|
int is_det;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
str = g_string_new(NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
theme = window != NULL && window->active != NULL &&
|
|
|
|
window->active->theme != NULL ?
|
|
|
|
window->active->theme : current_theme;
|
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
for (tmp = activity_list; tmp != NULL; tmp = tmp->next) {
|
|
|
|
WINDOW_REC *window = tmp->data;
|
|
|
|
|
|
|
|
is_det = window->data_level >= DATA_LEVEL_HILIGHT;
|
|
|
|
if ((!is_det && !normal) || (is_det && !hilight))
|
|
|
|
continue;
|
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
/* comma separator */
|
|
|
|
if (str->len > 0) {
|
|
|
|
value = theme_format_expand(theme, "{sb_act_sep ,}");
|
|
|
|
g_string_append(str, value);
|
|
|
|
g_free(value);
|
|
|
|
}
|
2001-03-12 05:33:13 -05:00
|
|
|
|
|
|
|
switch (window->data_level) {
|
|
|
|
case DATA_LEVEL_NONE:
|
|
|
|
case DATA_LEVEL_TEXT:
|
2001-10-23 17:26:03 -04:00
|
|
|
name = "{sb_act_text %d}";
|
2001-03-12 05:33:13 -05:00
|
|
|
break;
|
|
|
|
case DATA_LEVEL_MSG:
|
2001-10-23 17:26:03 -04:00
|
|
|
name = "{sb_act_msg %d}";
|
2001-03-12 05:33:13 -05:00
|
|
|
break;
|
|
|
|
default:
|
2001-10-23 17:26:03 -04:00
|
|
|
if (window->hilight_color == NULL)
|
|
|
|
name = "{sb_act_hilight %d}";
|
|
|
|
else
|
|
|
|
name = NULL;
|
2001-03-12 05:33:13 -05:00
|
|
|
break;
|
|
|
|
}
|
2001-03-16 20:52:43 -05:00
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
if (name != NULL)
|
|
|
|
format = g_strdup_printf(name, window->refnum);
|
|
|
|
else
|
|
|
|
format = g_strdup_printf("{sb_act_hilight_color %s %d}",
|
|
|
|
window->hilight_color,
|
|
|
|
window->refnum);
|
|
|
|
|
|
|
|
value = theme_format_expand(theme, format);
|
|
|
|
g_string_append(str, value);
|
|
|
|
g_free(value);
|
|
|
|
|
|
|
|
g_free(format);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-01-31 06:23:29 -05:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
ret = str->len == 0 ? NULL : str->str;
|
|
|
|
g_string_free(str, ret == NULL);
|
|
|
|
return ret;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2001-01-31 06:23:29 -05:00
|
|
|
/* redraw activity, FIXME: if we didn't get enough size, this gets buggy.
|
|
|
|
At least "Det:" isn't printed properly. also we should rearrange the
|
|
|
|
act list so that the highest priority items comes first. */
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_act(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
char *actlist;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-23 17:26:03 -04:00
|
|
|
actlist = get_activity_list(item->bar->parent_window, TRUE, TRUE);
|
2001-10-13 12:11:13 -04:00
|
|
|
if (actlist == NULL) {
|
2001-03-12 05:33:13 -05:00
|
|
|
if (get_size_only)
|
|
|
|
item->min_size = item->max_size = 0;
|
|
|
|
return;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
statusbar_item_default_handler(item, get_size_only,
|
|
|
|
NULL, actlist, FALSE);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-14 21:26:12 -05:00
|
|
|
g_free_not_null(actlist);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_statusbar_activity_hilight(WINDOW_REC *window, gpointer oldlevel)
|
|
|
|
{
|
2001-03-12 05:33:13 -05:00
|
|
|
GList *tmp;
|
|
|
|
int inspos;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
g_return_if_fail(window != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-03-12 05:33:13 -05:00
|
|
|
if (settings_get_bool("actlist_moves")) {
|
|
|
|
/* Move the window to the first in the activity list */
|
|
|
|
if (g_list_find(activity_list, window) != NULL)
|
|
|
|
activity_list = g_list_remove(activity_list, window);
|
|
|
|
if (window->data_level != 0)
|
|
|
|
activity_list = g_list_prepend(activity_list, window);
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2001-03-12 05:33:13 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_list_find(activity_list, window) != NULL) {
|
|
|
|
/* already in activity list */
|
|
|
|
if (window->data_level == 0) {
|
|
|
|
/* remove from activity list */
|
|
|
|
activity_list = g_list_remove(activity_list, window);
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2001-03-12 05:33:13 -05:00
|
|
|
} else if (window->data_level != GPOINTER_TO_INT(oldlevel) ||
|
|
|
|
window->hilight_color != 0) {
|
|
|
|
/* different level as last time (or maybe different
|
|
|
|
hilight color?), just redraw it. */
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2001-03-12 05:33:13 -05:00
|
|
|
}
|
|
|
|
return;
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-03-12 05:33:13 -05:00
|
|
|
|
|
|
|
if (window->data_level == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* add window to activity list .. */
|
|
|
|
inspos = 0;
|
|
|
|
for (tmp = activity_list; tmp != NULL; tmp = tmp->next, inspos++) {
|
|
|
|
WINDOW_REC *rec = tmp->data;
|
|
|
|
|
|
|
|
if (window->refnum < rec->refnum) {
|
|
|
|
activity_list =
|
|
|
|
g_list_insert(activity_list, window, inspos);
|
|
|
|
break;
|
|
|
|
}
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-03-12 05:33:13 -05:00
|
|
|
if (tmp == NULL)
|
|
|
|
activity_list = g_list_append(activity_list, window);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sig_statusbar_activity_window_destroyed(WINDOW_REC *window)
|
|
|
|
{
|
2000-09-26 20:08:03 -04:00
|
|
|
g_return_if_fail(window != NULL);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2000-09-26 20:08:03 -04:00
|
|
|
if (g_list_find(activity_list, window) != NULL)
|
|
|
|
activity_list = g_list_remove(activity_list, window);
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-09-26 20:11:06 -04:00
|
|
|
static void sig_statusbar_activity_updated(void)
|
|
|
|
{
|
2001-10-20 15:52:07 -04:00
|
|
|
statusbar_items_redraw("act");
|
2000-09-26 20:11:06 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_more(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void item_input(SBAR_ITEM_REC *item, int get_size_only)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
GUI_ENTRY_REC *rec;
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
rec = g_hash_table_lookup(input_entries, item);
|
|
|
|
if (rec == NULL) {
|
|
|
|
rec = gui_entry_create(item->xpos, item->bar->real_ypos,
|
|
|
|
item->size);
|
2001-10-24 09:47:13 -04:00
|
|
|
gui_entry_set_active(rec);
|
2001-10-13 12:11:13 -04:00
|
|
|
g_hash_table_insert(input_entries, item, rec);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
2001-10-28 13:40:12 -05:00
|
|
|
|
|
|
|
if (get_size_only) {
|
|
|
|
item->min_size = 2+term_width/10;
|
|
|
|
item->max_size = term_width;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gui_entry_move(rec, item->xpos, item->bar->real_ypos,
|
|
|
|
item->size);
|
|
|
|
gui_entry_redraw(rec); /* FIXME: this is only necessary with ^L.. */
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
static void sig_statusbar_item_destroyed(SBAR_ITEM_REC *item)
|
2000-05-04 06:32:42 -04:00
|
|
|
{
|
2001-10-20 15:52:07 -04:00
|
|
|
GUI_ENTRY_REC *rec;
|
|
|
|
|
|
|
|
rec = g_hash_table_lookup(input_entries, item);
|
|
|
|
if (rec != NULL) {
|
|
|
|
gui_entry_destroy(rec);
|
|
|
|
g_hash_table_remove(input_entries, item);
|
2000-05-04 06:32:42 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void statusbar_items_init(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
|
|
|
settings_add_int("misc", "lag_min_show", 100);
|
2000-05-04 06:32:42 -04:00
|
|
|
settings_add_bool("lookandfeel", "actlist_moves", FALSE);
|
2001-10-13 12:11:13 -04:00
|
|
|
|
|
|
|
statusbar_item_register("window", NULL, item_window_active);
|
|
|
|
statusbar_item_register("window_empty", NULL, item_window_empty);
|
|
|
|
statusbar_item_register("prompt", NULL, item_window_active);
|
|
|
|
statusbar_item_register("prompt_empty", NULL, item_window_empty);
|
|
|
|
statusbar_item_register("lag", NULL, item_lag);
|
|
|
|
statusbar_item_register("act", NULL, item_act);
|
|
|
|
statusbar_item_register("more", NULL, item_more);
|
|
|
|
statusbar_item_register("input", NULL, item_input);
|
|
|
|
|
|
|
|
input_entries = g_hash_table_new((GHashFunc) g_direct_hash,
|
|
|
|
(GCompareFunc) g_direct_equal);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
activity_list = NULL;
|
|
|
|
signal_add("window activity", (SIGNAL_FUNC) sig_statusbar_activity_hilight);
|
|
|
|
signal_add("window destroyed", (SIGNAL_FUNC) sig_statusbar_activity_window_destroyed);
|
2000-09-26 20:11:06 -04:00
|
|
|
signal_add("window refnum changed", (SIGNAL_FUNC) sig_statusbar_activity_updated);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
signal_add("statusbar item destroyed", (SIGNAL_FUNC) sig_statusbar_item_destroyed);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|
|
|
|
|
2000-05-04 06:32:42 -04:00
|
|
|
void statusbar_items_deinit(void)
|
2000-04-26 04:03:38 -04:00
|
|
|
{
|
2001-10-13 12:11:13 -04:00
|
|
|
g_hash_table_destroy(input_entries);
|
|
|
|
|
2000-04-26 04:03:38 -04:00
|
|
|
signal_remove("window activity", (SIGNAL_FUNC) sig_statusbar_activity_hilight);
|
|
|
|
signal_remove("window destroyed", (SIGNAL_FUNC) sig_statusbar_activity_window_destroyed);
|
2000-09-26 20:11:06 -04:00
|
|
|
signal_remove("window refnum changed", (SIGNAL_FUNC) sig_statusbar_activity_updated);
|
2000-04-26 04:03:38 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
g_list_free(activity_list);
|
|
|
|
activity_list = NULL;
|
2000-05-04 06:32:42 -04:00
|
|
|
|
2001-10-13 12:11:13 -04:00
|
|
|
signal_remove("statusbar item destroyed", (SIGNAL_FUNC) sig_statusbar_item_destroyed);
|
2000-04-26 04:03:38 -04:00
|
|
|
}
|