1
0
Fork 0

Lots of changes again. Biggest ones:

- window's text buffer should work better
- themes are almost working, you can change the text formats with /format
- automatically try to rejoin the channel after 5 minutes if the join there
failed because it was "temporarily unavailable" (netsplits)
- generally cleaning code..


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@216 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Timo Sirainen 2000-05-15 08:25:45 +00:00 committed by cras
parent 969cfe8abc
commit cbdaf7d06d
63 changed files with 2479 additions and 1920 deletions

22
TODO
View File

@ -1,8 +1,16 @@
- teemat
- /rehash
- teeman vaihto
- teemoihin tee jotain pientä selitystä edes!
- irssi can't find new themes in ~/.irssi/ while running - scan for new
themes when opening themes dialog? irssi-text also needs to be restarted
to use new themes..
- use different themes in different channels/queries?
- logi voisi käyttää omaa teemaa
- /IRCNET ADD/REMOVE
- mites se awaylogi? se /cattaamaan myös se /away:n jälkeen
- poista se common-setup.h
- quitissa se räpeltää ruutua liikaa..
- perli kaatui välillä ym. kivaa.
[21:48] < santo> [20:51] ¤¤¤ #twiggy,#tanum,#d2mac,#linux.nu,#sweden2k
Cannot join channel (illegal name)
@ -19,15 +27,6 @@ lis
- gnome versio..
- pluginit
- teemat (toimiiko ne edes?)
- teeman vaihto tekstiversiolla, tekstien muuttaminen tekstiversiolla
- teemoihin tee jotain pientä selitystä edes!
- irssi can't find new themes in ~/.irssi/ while running - scan for new
themes when opening themes dialog? irssi-text also needs to be restarted
to use new themes..
- use different themes in different channels/queries?
- logi voisi käyttää omaa teemaa
- /set hold_mode, ja /CAT toimimaan sen kanssa jotenkin nerokkaasti..
- curses sijainti jotain rikkoo, ja openbsd:ssä on -lcurses, ei -lncurses
@ -40,7 +39,6 @@ lis
- line-split.c: varmista että se 64k limitti toimii eikä esim. kaada!
- /exec
- autorun.ircnet
- channel not available rejoini
*** Bugs

View File

@ -201,7 +201,7 @@ dnl **
if test "x$want_textui" = "xyes"; then
AC_CHECK_CURSES
if test "x$ncurses_version" != "x"; then
if test "x$has_ncurses" != "x"; then
AC_CHECK_LIB(ncurses, use_default_colors, [
AC_DEFINE(HAVE_NCURSES_USE_DEFAULT_COLORS)
],, $CURSES_LIBS)

View File

@ -131,13 +131,7 @@ AC_DEFUN(AC_CHECK_CURSES,[
if test x$withval = xno ; then
search_ncurses=false
elif test x$withval != xyes ; then
CURSES_LIBS="$LIBS -L$withval/lib -lncurses"
CURSES_INCLUDEDIR="-I$withval/include"
search_ncurses=false
screen_manager="ncurses"
AC_DEFINE(USE_NCURSES)
AC_DEFINE(HAS_CURSES)
has_curses=true
AC_NCURSES($withval/include, ncurses.h, -L$withval/lib -lncurses, -I$withval/include, "ncurses on $withval/include")
fi
)
@ -222,6 +216,7 @@ AC_DEFUN(AC_NCURSES, [
screen_manager=$5
AC_DEFINE(HAS_CURSES)
has_curses=true
has_ncurses=true
AC_DEFINE(USE_NCURSES)
fi
fi
@ -256,6 +251,7 @@ USE_NCURSES
CURSES_INCLUDEDIR="$CURSES_INCLUDEDIR -DRENAMED_NCURSES"
AC_DEFINE(HAS_CURSES)
has_curses=true
has_ncurses=true
AC_DEFINE(USE_NCURSES)
search_ncurses=false
screen_manager="ncurses installed as curses"

View File

@ -436,8 +436,24 @@ static void cmd_cd(const char *data)
g_free(str);
}
static void cmd_rehash(const char *data)
{
char *fname;
fname = *data != '\0' ? g_strdup(data) :
g_strdup_printf("%s/.irssi/config", g_get_home_dir());
settings_reread(fname);
g_free(fname);
}
static void cmd_save(const char *data)
{
settings_save(*data != '\0' ? data : NULL);
}
void commands_init(void)
{
commands = NULL;
cmdget_funcs = NULL;
current_command = NULL;
@ -448,6 +464,8 @@ void commands_init(void)
command_bind("eval", NULL, (SIGNAL_FUNC) cmd_eval);
command_bind("cd", NULL, (SIGNAL_FUNC) cmd_cd);
command_bind("rehash", NULL, (SIGNAL_FUNC) cmd_rehash);
command_bind("save", NULL, (SIGNAL_FUNC) cmd_save);
}
void commands_deinit(void)
@ -459,4 +477,6 @@ void commands_deinit(void)
command_unbind("eval", (SIGNAL_FUNC) cmd_eval);
command_unbind("cd", (SIGNAL_FUNC) cmd_cd);
command_unbind("rehash", (SIGNAL_FUNC) cmd_rehash);
command_unbind("save", (SIGNAL_FUNC) cmd_save);
}

View File

@ -10,16 +10,11 @@ typedef struct {
COMMAND_REC;
enum {
CMDERR_PARAM, /* invalid parameter */
CMDERR_ERRNO, /* get the error from errno */
CMDERR_NOT_ENOUGH_PARAMS, /* not enough parameters given */
CMDERR_NOT_CONNECTED, /* not connected to IRC server */
CMDERR_NOT_JOINED, /* not joined to any channels in this window */
CMDERR_GETSOCKNAME, /* getsockname() failed */
CMDERR_LISTEN, /* listen() failed */
CMDERR_MULTIPLE_MATCHES, /* multiple matches found, didn't do anything */
CMDERR_NICK_NOT_FOUND, /* nick not found */
CMDERR_CHAN_NOT_FOUND, /* channel not found */
CMDERR_SERVER_NOT_FOUND, /* server not found */
CMDERR_CHAN_NOT_SYNCED, /* channel not fully synchronized yet */
CMDERR_NOT_GOOD_IDEA /* not good idea to do, -yes overrides this */
};

View File

@ -43,9 +43,9 @@ void core_init(void)
net_disconnect_init();
signals_init();
settings_init();
commands_init();
servers_init();
commands_init();
log_init();
rawlog_init();
special_vars_init();
@ -56,9 +56,9 @@ void core_deinit(void)
special_vars_deinit();
rawlog_deinit();
log_deinit();
commands_deinit();
servers_deinit();
commands_deinit();
settings_deinit();
signals_deinit();
net_disconnect_deinit();

View File

@ -132,35 +132,26 @@ static void *data_remove(void *p, const char *file, int line)
void *ig_malloc(int size, const char *file, int line)
{
#if 1
void *p;
size += BUFFER_CHECK_SIZE*2;
p = g_malloc(size);
data_add(p, size, file, line);
return p+BUFFER_CHECK_SIZE;
#else
return g_malloc(size);
#endif
}
void *ig_malloc0(int size, const char *file, int line)
{
#if 1
void *p;
size += BUFFER_CHECK_SIZE*2;
p = g_malloc0(size);
data_add(p, size, file, line);
return p+BUFFER_CHECK_SIZE;
#else
return g_malloc0(size);
#endif
}
void *ig_realloc(void *mem, unsigned long size, const char *file, int line)
{
#if 1
void *p;
size += BUFFER_CHECK_SIZE*2;
@ -169,9 +160,6 @@ void *ig_realloc(void *mem, unsigned long size, const char *file, int line)
p = g_realloc(mem, size);
data_add(p, size, file, line);
return p+BUFFER_CHECK_SIZE;
#else
return g_realloc(mem, size);
#endif
}
char *ig_strdup(const char *str, const char *file, int line)
@ -264,12 +252,11 @@ char *ig_strdup_vprintf(const char *file, int line, const char *format, va_list
void ig_free(void *p)
{
#if 1
if (p == NULL) g_error("ig_free() : trying to free NULL");
p -= BUFFER_CHECK_SIZE;
p = data_remove(p, "??", 0);
if (p != NULL)
#endif
g_free(p);
if (p != NULL) g_free(p);
}
GString *ig_string_new(const char *file, int line, const char *str)

View File

@ -21,6 +21,7 @@
#include "module.h"
#include "signals.h"
#include "commands.h"
#include "misc.h"
#include "lib-config/iconfig.h"
#include "settings.h"
@ -278,15 +279,16 @@ static void init_configfile(void)
signal(SIGTERM, sig_term);
}
static void cmd_rehash(const char *data)
void settings_reread(const char *fname)
{
CONFIG_REC *tempconfig;
char *str, *fname;
char *str;
fname = *data != '\0' ? g_strdup(data) :
g_strdup_printf("%s/.irssi/config", g_get_home_dir());
tempconfig = parse_configfile(fname);
g_free(fname);
if (fname == NULL) fname = "~/.irssi/config";
str = convert_home(fname);
tempconfig = parse_configfile(str);
g_free(str);
if (tempconfig == NULL) {
signal_emit("gui dialog", 2, "error", g_strerror(errno));
@ -310,11 +312,11 @@ static void cmd_rehash(const char *data)
signal_emit("setup reread", 0);
}
static void cmd_save(const char *data)
void settings_save(const char *fname)
{
char *str;
if (config_write(mainconfig, *data == '\0' ? NULL : data, 0660) == 0)
if (config_write(mainconfig, fname, 0660) == 0)
return;
/* error */
@ -329,8 +331,6 @@ void settings_init(void)
settings = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
init_configfile();
command_bind("rehash", NULL, (SIGNAL_FUNC) cmd_rehash);
command_bind("save", NULL, (SIGNAL_FUNC) cmd_save);
}
static void settings_hash_free(const char *key, SETTINGS_REC *rec)
@ -340,9 +340,6 @@ static void settings_hash_free(const char *key, SETTINGS_REC *rec)
void settings_deinit(void)
{
command_unbind("rehash", (SIGNAL_FUNC) cmd_rehash);
command_unbind("save", (SIGNAL_FUNC) cmd_save);
g_free_not_null(last_error_msg);
g_hash_table_foreach(settings, (GHFunc) settings_hash_free, NULL);
g_hash_table_destroy(settings);

View File

@ -53,6 +53,10 @@ GSList *settings_get_sorted(void);
/* Get the record of the setting */
SETTINGS_REC *settings_get_record(const char *key);
/* if `fname' is NULL, the default is used */
void settings_reread(const char *fname);
void settings_save(const char *fname);
void settings_init(void);
void settings_deinit(void);

View File

@ -17,10 +17,11 @@ libfe_common_core_la_SOURCES = \
hilight-text.c \
keyboard.c \
module-formats.c \
window-activity.c \
printtext.c \
themes.c \
translation.c \
window-activity.c \
window-commands.c \
window-items.c \
windows.c

View File

@ -18,6 +18,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "module.h"
#include "module-formats.h"
#include "levels.h"
#include "settings.h"
@ -50,6 +51,9 @@ void fe_settings_deinit(void);
void window_activity_init(void);
void window_activity_deinit(void);
void window_commands_init(void);
void window_commands_deinit(void);
void fe_core_commands_init(void);
void fe_core_commands_deinit(void);
@ -73,8 +77,10 @@ void fe_common_core_init(void)
settings_add_int("lookandfeel", "tab_orientation", 3);*/
settings_add_str("lookandfeel", "current_theme", "default");
themes_init();
theme_register(fecommon_core_formats);
autorun_init();
window_activity_init();
hilight_text_init();
command_history_init();
keyboard_init();
@ -82,9 +88,10 @@ void fe_common_core_init(void)
fe_log_init();
fe_server_init();
fe_settings_init();
themes_init();
translation_init();
windows_init();
window_activity_init();
window_commands_init();
window_items_init();
fe_core_commands_init();
}
@ -92,7 +99,6 @@ void fe_common_core_init(void)
void fe_common_core_deinit(void)
{
autorun_deinit();
window_activity_deinit();
hilight_text_deinit();
command_history_deinit();
keyboard_deinit();
@ -100,11 +106,15 @@ void fe_common_core_deinit(void)
fe_log_deinit();
fe_server_deinit();
fe_settings_deinit();
themes_deinit();
translation_deinit();
windows_deinit();
window_activity_deinit();
window_commands_deinit();
window_items_deinit();
fe_core_commands_deinit();
theme_unregister();
themes_deinit();
}
void fe_common_core_finish_init(void)

View File

@ -30,16 +30,11 @@
#include "windows.h"
static const char *ret_texts[] = {
"Invalid parameter",
NULL,
"Not enough parameters given",
"Not connected to IRC server yet",
"Not joined to any channels yet",
"Error: getsockname() failed",
"Error: listen() failed",
"Multiple matches found, be more specific",
"Nick not found",
"Not joined to such channel",
"Server not found",
"Channel not fully synchronized yet, try again after a while",
"Doing this is not a good idea. Add -YES if you really mean it",
};
@ -269,9 +264,15 @@ static void cmd_unknown(const char *data, void *server, WI_ITEM_REC *item)
signal_stop();
}
static void event_cmderror(gpointer error)
static void event_cmderror(gpointer errorp)
{
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, ret_texts[GPOINTER_TO_INT(error)]);
int error;
error = GPOINTER_TO_INT(errorp);
if (error == CMDERR_ERRNO)
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, g_strerror(errno));
else
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, ret_texts[error]);
}
void fe_core_commands_init(void)

View File

@ -297,25 +297,27 @@ static void autolog_log(void *server, const char *target)
g_free(fname);
}
/* write to logs created with /WINDOW LOG */
static void sig_printtext_stripped(void *server, const char *target, gpointer levelp, const char *text)
static void sig_printtext_stripped(WINDOW_REC *window, void *server, const char *target, gpointer levelp, const char *text)
{
char windownum[MAX_INT_STRLEN];
WINDOW_REC *window;
LOG_REC *log;
int level;
level = GPOINTER_TO_INT(levelp);
if (level == MSGLEVEL_NEVER) return;
/* let autolog create the log records */
if ((autolog_level & level) && target != NULL && *target != '\0')
autolog_log(server, target);
window = window_find_closest(server, target, level);
if (window != NULL) {
ltoa(windownum, window->refnum);
/* save to log created with /WINDOW LOG */
ltoa(windownum, window->refnum);
log = log_find_item(windownum);
if (log != NULL) log_write_rec(log, text);
log = log_find_item(windownum);
if (log != NULL) log_write_rec(log, text);
}
/* save line to logs */
if (logs != NULL)
log_write(target, level, text);
}
static int sig_autoremove(void)

View File

@ -132,7 +132,7 @@ static HILIGHT_REC *hilight_find(const char *text, char **channels)
return NULL;
}
static void sig_print_text(SERVER_REC *server, const char *channel, gpointer level, const char *str)
static void sig_print_text(WINDOW_REC *window, SERVER_REC *server, const char *channel, gpointer level, const char *str)
{
if (hilight_next) {
hilight_next = FALSE;
@ -140,7 +140,7 @@ static void sig_print_text(SERVER_REC *server, const char *channel, gpointer lev
}
}
static void sig_print_text_stripped(SERVER_REC *server, const char *channel, gpointer plevel, const char *str)
static void sig_print_text_stripped(WINDOW_REC *window, SERVER_REC *server, const char *channel, gpointer plevel, const char *str)
{
GSList *tmp;
char *color, *newstr;
@ -184,7 +184,7 @@ static void sig_print_text_stripped(SERVER_REC *server, const char *channel, gpo
if (color == NULL) color = "\00316";
newstr = g_strconcat(isdigit(*color) ? "\003" : "", color, str, NULL);
signal_emit("print text", 4, server, channel, GINT_TO_POINTER(level | MSGLEVEL_HILIGHT), newstr);
signal_emit("print text", 5, window, server, channel, GINT_TO_POINTER(level | MSGLEVEL_HILIGHT), newstr);
g_free(newstr);
hilight_next = TRUE;

View File

@ -258,12 +258,6 @@ static void read_keyboard_config(void)
CONFIG_NODE *node;
GSList *tmp;
while (keyinfos != NULL)
keyinfo_remove(keyinfos->data);
if (keys != NULL) g_hash_table_destroy(keys);
keys = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
node = iconfig_node_traverse("keyboard", FALSE);
if (node == NULL) return;
@ -280,7 +274,9 @@ static void read_keyboard_config(void)
void keyboard_init(void)
{
keyinfos = NULL; keys = NULL;
keys = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
keyinfos = NULL;
key_bind("command", NULL, "Run any IRC command", NULL, (SIGNAL_FUNC) sig_command);
read_keyboard_config();

View File

@ -21,73 +21,75 @@
#include "module.h"
#include "printtext.h"
FORMAT_REC fecommon_core_formats[] =
{
{ MODULE_NAME, "Core", 0 },
FORMAT_REC fecommon_core_formats[] = {
{ MODULE_NAME, "Core", 0 },
/* ---- */
{ NULL, "Windows", 0 },
/* ---- */
{ NULL, "Windows", 0 },
{ "line_start", "%B-%W!%B-%n ", 0 },
{ "line_start_irssi", "%B-%W!%B- %WIrssi:%n ", 0 },
{ "timestamp", "[$[-2.0]3:$[-2.0]4] ", 6, { 1, 1, 1, 1, 1, 1 } },
{ "daychange", "Day changed to ${[-2.0]1}-$[-2.0]0 $2", 3, { 1, 1, 1 } },
{ "talking_with", "You are now talking with %_$0%_", 1, { 0 } },
{ "refnum_too_low", "Window number must be greater than 1", 0 },
{ "windowlist_header", "Ref Name Active item Server Level", 0 },
{ "windowlist_line", "$[3]0 %|$[20]1 $[15]2 $[15]3 $4", 5, { 1, 0, 0, 0, 0 } },
{ "windowlist_footer", "", 0 },
{ "line_start", "%B-%W!%B-%n ", 0 },
{ "line_start_irssi", "%B-%W!%B- %WIrssi:%n ", 0 },
{ "timestamp", "[$[-2.0]3:$[-2.0]4] ", 6, { 1, 1, 1, 1, 1, 1 } },
{ "daychange", "Day changed to $[-2.0]{0}-$[-2.0]1 $2", 3, { 1, 1, 1 } },
{ "talking_with", "You are now talking with %_$0%_", 1, { 0 } },
{ "refnum_too_low", "Window number must be greater than 1", 0 },
{ "refnum_not_found", "No such window: $0", 1, { 0 } }, /*REMOVE!!!!!!!!*/
{ "windowlist_header", "Ref Name Active item Server Level", 0 },
{ "windowlist_line", "$[3]0 %|$[20]1 $[15]2 $[15]3 $4", 5, { 1, 0, 0, 0, 0 } },
{ "windowlist_footer", "", 0 },
/* ---- */
{ NULL, "Server", 0 },
/* ---- */
{ NULL, "Server", 0 },
{ "looking_up", "Looking up %_$0%_", 1, { 0 } },
{ "connecting", "Connecting to %_$0%_ %K[%n$1%K]%n port %_$2%_", 3, { 0, 0, 1 } },
{ "connection_established", "Connection to %_$0%_ established", 1, { 0 } },
{ "cant_connect", "Unable to connect server %_$0%_ port %_$1%_ %K[%n$2%K]", 3, { 0, 1, 0 } },
{ "connection_lost", "Connection lost to %_$0%_", 1, { 0 } },
{ "server_quit", "Disconnecting from server $0: %K[%n$1%K]", 2, { 0, 0 } },
{ "server_changed", "Changed to %_$2%_ server %_$1%_", 3, { 0, 0, 0 } },
{ "unknown_server_tag", "Unknown server tag %_$0%_", 1, { 0 } },
{ "looking_up", "Looking up %_$0%_", 1, { 0 } },
{ "connecting", "Connecting to %_$0%_ %K[%n$1%K]%n port %_$2%_", 3, { 0, 0, 1 } },
{ "connection_established", "Connection to %_$0%_ established", 1, { 0 } },
{ "cant_connect", "Unable to connect server %_$0%_ port %_$1%_ %K[%n$2%K]", 3, { 0, 1, 0 } },
{ "connection_lost", "Connection lost to %_$0%_", 1, { 0 } },
{ "server_quit", "Disconnecting from server $0: %K[%n$1%K]", 2, { 0, 0 } },
{ "server_changed", "Changed to %_$2%_ server %_$1%_", 3, { 0, 0, 0 } },
{ "unknown_server_tag", "Unknown server tag %_$0%_", 1, { 0 } },
/* ---- */
{ NULL, "Highlighting", 0 },
/* ---- */
{ NULL, "Highlighting", 0 },
{ "hilight_header", "Highlights:", 0 },
{ "hilight_line", "$[-4]0 $1 $2 $3$3$4$5", 7, { 1, 0, 0, 0, 0, 0, 0 } },
{ "hilight_footer", "", 0 },
{ "hilight_not_found", "Highlight not found: $0", 1, { 0 } },
{ "hilight_removed", "Highlight removed: $0", 1, { 0 } },
{ "hilight_header", "Highlights:", 0 },
{ "hilight_line", "$[-4]0 $1 $2 $3$3$4$5", 7, { 1, 0, 0, 0, 0, 0, 0 } },
{ "hilight_footer", "", 0 },
{ "hilight_not_found", "Highlight not found: $0", 1, { 0 } },
{ "hilight_removed", "Highlight removed: $0", 1, { 0 } },
/* ---- */
{ NULL, "Aliases", 0 },
/* ---- */
{ NULL, "Aliases", 0 },
{ "alias_added", "Alias $0 added", 1, { 0 } },
{ "alias_removed", "Alias $0 removed", 1, { 0 } },
{ "alias_not_found", "No such alias: $0", 1, { 0 } },
{ "aliaslist_header", "Aliases:", 0 },
{ "aliaslist_line", "$[10]0 $1", 2, { 0, 0 } },
{ "aliaslist_footer", "", 0 },
{ "alias_added", "Alias $0 added", 1, { 0 } },
{ "alias_removed", "Alias $0 removed", 1, { 0 } },
{ "alias_not_found", "No such alias: $0", 1, { 0 } },
{ "aliaslist_header", "Aliases:", 0 },
{ "aliaslist_line", "$[10]0 $1", 2, { 0, 0 } },
{ "aliaslist_footer", "", 0 },
/* ---- */
{ NULL, "Logging", 0 },
/* ---- */
{ NULL, "Logging", 0 },
{ "log_opened", "Log file %W$0%n opened", 1, { 0 } },
{ "log_closed", "Log file %W$0%n closed", 1, { 0 } },
{ "log_create_failed", "Couldn't create log file %W$0", 1, { 0 } },
{ "log_locked", "Log file %W$0%n is locked, probably by another running Irssi", 1, { 0 } },
{ "log_not_open", "Log file %W$0%n not open", 1, { 0 } },
{ "log_started", "Started logging to file %W$0", 1, { 0 } },
{ "log_stopped", "Stopped logging to file %W$0", 1, { 0 } },
{ "log_list_header", "Logs:", 0 },
{ "log_list", "$0: $1 $2$3$4", 5, { 0, 0, 0, 0, 0 } },
{ "log_list_footer", "", 0 },
{ "windowlog_file", "Window LOGFILE set to $0", 1, { 0 } },
{ "windowlog_file_logging", "Can't change window's logfile while log is on", 0 },
{ "log_opened", "Log file %W$0%n opened", 1, { 0 } },
{ "log_closed", "Log file %W$0%n closed", 1, { 0 } },
{ "log_create_failed", "Couldn't create log file %W$0", 1, { 0 } },
{ "log_locked", "Log file %W$0%n is locked, probably by another running Irssi", 1, { 0 } },
{ "log_not_open", "Log file %W$0%n not open", 1, { 0 } },
{ "log_started", "Started logging to file %W$0", 1, { 0 } },
{ "log_stopped", "Stopped logging to file %W$0", 1, { 0 } },
{ "log_list_header", "Logs:", 0 },
{ "log_list", "$0: $1 $2$3$4", 5, { 0, 0, 0, 0, 0 } },
{ "log_list_footer", "", 0 },
{ "windowlog_file", "Window LOGFILE set to $0", 1, { 0 } },
{ "windowlog_file_logging", "Can't change window's logfile while log is on", 0 },
/* ---- */
{ NULL, "Misc", 0 },
/* ---- */
{ NULL, "Misc", 0 },
{ "not_toggle", "Value must be either ON, OFF or TOGGLE", 0 },
{ "perl_error", "Perl error: $0", 1, { 0 } }
{ "not_toggle", "Value must be either ON, OFF or TOGGLE", 0 },
{ "perl_error", "Perl error: $0", 1, { 0 } },
{ NULL, NULL, 0 }
};

View File

@ -65,6 +65,3 @@ enum {
};
extern FORMAT_REC fecommon_core_formats[];
#define MODULE_FORMATS fecommon_core_formats
#include "printformat.h"

View File

@ -1,25 +0,0 @@
/* printformat(...) = printformat_format(module_formats, ...)
Could this be any harder? :) With GNU C compiler and C99 compilers,
use #define. With others use either inline functions if they are
supported or static functions if they are not..
*/
#if defined (__GNUC__) && !defined (__STRICT_ANSI__)
/* GCC */
# define printformat(server, channel, level, formatnum...) \
printformat_format(MODULE_FORMATS, server, channel, level, ##formatnum)
#elif defined (_ISOC99_SOURCE)
/* C99 */
# define printformat(server, channel, level, formatnum, ...) \
printformat_format(MODULE_FORMATS, server, channel, level, formatnum, __VA_ARGS__)
#else
/* inline/static */
static
#ifdef G_CAN_INLINE
inline
#endif
void printformat(void *server, const char *channel, int level, int formatnum, ...)
{
printformat_format(MODULE_FORMATS, server, channel, level, formatnum);
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,8 @@
#ifndef __PRINTTEXT_H
#define __PRINTTEXT_H
#include "windows.h"
enum {
FORMAT_STRING,
FORMAT_INT,
@ -24,9 +26,14 @@ typedef struct {
#define PRINTFLAG_MIRC_COLOR 0x20
#define PRINTFLAG_INDENT 0x40
void printformat_format(FORMAT_REC *formats, void *server, const char *channel, int level, int formatnum, ...);
void printformat_module(const char *module, void *server, const char *channel, int level, int formatnum, ...);
void printformat_module_window(const char *module, WINDOW_REC *window, int level, int formatnum, ...);
void printtext(void *server, const char *channel, int level, const char *str, ...);
void printformat_module_args(const char *module, void *server, const char *channel, int level, int formatnum, va_list va);
void printformat_module_window_args(const char *module, WINDOW_REC *window, int level, int formatnum, va_list va);
void printtext(void *server, const char *channel, int level, const char *text, ...);
void printtext_window(WINDOW_REC *window, int level, const char *text, ...);
void printtext_multiline(void *server, const char *channel, int level, const char *format, const char *text);
void printbeep(void);
@ -36,4 +43,51 @@ char *strip_codes(const char *input);
void printtext_init(void);
void printtext_deinit(void);
/* printformat(...) = printformat_format(MODULE_NAME, ...)
Could this be any harder? :) With GNU C compiler and C99 compilers,
use #define. With others use either inline functions if they are
supported or static functions if they are not..
*/
#if defined (__GNUC__) && !defined (__STRICT_ANSI__)
/* GCC */
# define printformat(server, channel, level, formatnum...) \
printformat_module(MODULE_NAME, server, channel, level, ##formatnum)
# define printformat_window(window, level, formatnum...) \
printformat_module_window(MODULE_NAME, window, level, ##formatnum)
#elif defined (_ISOC99_SOURCE)
/* C99 */
# define printformat(server, channel, level, formatnum, ...) \
printformat_module(MODULE_NAME, server, channel, level, formatnum, __VA_ARGS__)
# define printformat_window(window, level, formatnum, ...) \
printformat_module_window(MODULE_NAME, window, level, formatnum, __VA_ARGS__)
#else
/* inline/static */
static
#ifdef G_CAN_INLINE
inline
#endif
void printformat(void *server, const char *channel, int level, int formatnum, ...)
{
va_list va;
va_start(va, formatnum);
printformat_module_args(MODULE_NAME, server, channel, level, formatnum, va);
va_end(va);
}
static
#ifdef G_CAN_INLINE
inline
#endif
void printformat_window(WINDOW_REC *window, int level, int formatnum, ...)
{
va_list va;
va_start(va, formatnum);
printformat_module_window_args(MODULE_NAME, window, level, formatnum, va);
va_end(va);
}
#endif
#endif

View File

@ -20,6 +20,8 @@
#include "module.h"
#include "signals.h"
#include "commands.h"
#include "levels.h"
#include "misc.h"
#include "lib-config/iconfig.h"
#include "settings.h"
@ -29,6 +31,7 @@
GSList *themes;
THEME_REC *current_theme;
GHashTable *default_formats;
THEME_REC *theme_create(const char *path, const char *name)
{
@ -46,17 +49,15 @@ THEME_REC *theme_create(const char *path, const char *name)
return rec;
}
static void theme_destroy_hash(const char *key, MODULE_THEME_REC *rec)
static void theme_module_destroy(const char *key, MODULE_THEME_REC *rec)
{
int n, max;
int n;
max = strarray_length(rec->formatlist);
for (n = 0; n < max; n++)
if (rec->format[n] != NULL)
g_free(rec->format[n]);
g_free(rec->format);
for (n = 0; n < rec->count; n++)
if (rec->formats[n] != NULL)
g_free(rec->formats[n]);
g_free(rec->formats);
g_strfreev(rec->formatlist);
g_free(rec->name);
g_free(rec);
}
@ -64,7 +65,7 @@ static void theme_destroy_hash(const char *key, MODULE_THEME_REC *rec)
void theme_destroy(THEME_REC *rec)
{
signal_emit("theme destroyed", 1, rec);
g_hash_table_foreach(rec->modules, (GHFunc) theme_destroy_hash, NULL);
g_hash_table_foreach(rec->modules, (GHFunc) theme_module_destroy, NULL);
g_hash_table_destroy(rec->modules);
if (rec->bg_pixmap != NULL) g_free(rec->bg_pixmap);
@ -74,6 +75,119 @@ void theme_destroy(THEME_REC *rec)
g_free(rec);
}
static MODULE_THEME_REC *theme_module_create(THEME_REC *theme, const char *module)
{
MODULE_THEME_REC *rec;
FORMAT_REC *formats;
rec = g_hash_table_lookup(theme->modules, module);
if (rec != NULL) return rec;
formats = g_hash_table_lookup(default_formats, module);
g_return_val_if_fail(formats != NULL, NULL);
rec = g_new0(MODULE_THEME_REC, 1);
rec->name = g_strdup(module);
for (rec->count = 0; formats[rec->count].def != NULL; rec->count++) ;
rec->formats = g_new0(char *, rec->count);
g_hash_table_insert(theme->modules, rec->name, rec);
return rec;
}
static void theme_read_formats(CONFIG_REC *config, THEME_REC *theme, const char *module)
{
MODULE_THEME_REC *rec;
FORMAT_REC *formats;
CONFIG_NODE *node;
GSList *tmp;
int n;
formats = g_hash_table_lookup(default_formats, module);
if (formats == NULL) return;
node = config_node_traverse(config, "formats", FALSE);
if (node == NULL) return;
node = config_node_section(node, module, -1);
if (node == NULL) return;
rec = theme_module_create(theme, module);
for (tmp = node->value; tmp != NULL; tmp = tmp->next) {
node = tmp->data;
if (node->key == NULL || node->value == NULL)
continue;
for (n = 0; formats[n].def != NULL; n++) {
if (formats[n].tag != NULL &&
g_strcasecmp(formats[n].tag, node->key) == 0) {
rec->formats[n] = g_strdup(node->value);
break;
}
}
}
}
static void theme_read_module(THEME_REC *theme, const char *module)
{
CONFIG_REC *config;
char *msg;
config = config_open(theme->path, -1);
if (config == NULL) return;
config_parse(config);
if (config_last_error(mainconfig) != NULL) {
msg = g_strdup_printf(_("Ignored errors in theme:\n%s"),
config_last_error(mainconfig));
signal_emit("gui dialog", 2, "error", msg);
g_free(msg);
}
theme_read_formats(config, theme, module);
config_close(config);
}
static void theme_remove_module(THEME_REC *theme, const char *module)
{
MODULE_THEME_REC *rec;
rec = g_hash_table_lookup(theme->modules, module);
if (rec == NULL) return;
g_hash_table_remove(theme->modules, module);
theme_module_destroy(module, rec);
}
void theme_register_module(const char *module, FORMAT_REC *formats)
{
if (g_hash_table_lookup(default_formats, module) != NULL)
return;
g_hash_table_insert(default_formats, g_strdup(module), formats);
if (current_theme != NULL)
theme_read_module(current_theme, module);
}
void theme_unregister_module(const char *module)
{
gpointer key, value;
if (!g_hash_table_lookup_extended(default_formats, module, &key, &value))
return;
g_hash_table_remove(default_formats, key);
g_free(key);
if (current_theme != NULL)
theme_remove_module(current_theme, module);
}
static THEME_REC *theme_find(const char *name)
{
GSList *tmp;
@ -115,49 +229,19 @@ static void find_themes(gchar *path)
closedir(dirp);
}
/* Read module texts into theme */
static void theme_read_module_texts(const char *hashkey, MODULE_THEME_REC *rec, CONFIG_REC *config)
static void theme_read(THEME_REC *theme, const char *path)
{
CONFIG_NODE *formats;
GSList *tmp;
char **flist;
int n;
formats = config_node_traverse(config, "moduleformats", FALSE);
if (formats == NULL) return;
for (tmp = formats->value; tmp != NULL; tmp = tmp->next) {
CONFIG_NODE *node = tmp->data;
if (node->key == NULL || node->value == NULL)
continue;
for (n = 0, flist = rec->formatlist; *flist != NULL; flist++, n++) {
if (g_strcasecmp(*flist, node->key) == 0) {
rec->format[n] = g_strdup(node->value);
break;
}
}
}
}
static int theme_read(THEME_REC *theme, const char *path)
{
MODULE_THEME_REC *mrec;
CONFIG_REC *config;
CONFIG_NODE *formats;
GSList *tmp;
char *value;
int errors;
config = config_open(path, -1);
if (config == NULL) {
/* didn't exist or no access? */
theme->default_color = 15;
return FALSE;
return;
}
errors = config_parse(config) == -1;
config_parse(config);
/* default color */
theme->default_color = config_get_int(config, NULL, "default_color", 15);
@ -175,58 +259,172 @@ static int theme_read(THEME_REC *theme, const char *path)
theme->flags |= THEME_FLAG_BG_SCALED;
if (config_get_bool(config, NULL, "bg_shaded", FALSE))
theme->flags |= THEME_FLAG_BG_SHADED;
/* Read modules that are defined in this theme. */
formats = config_node_traverse(config, "modules", FALSE);
if (formats != NULL) {
for (tmp = formats->value; tmp != NULL; tmp = tmp->next) {
CONFIG_NODE *node = tmp->data;
if (node->key == NULL || node->value == NULL)
continue;
mrec = g_new0(MODULE_THEME_REC, 1);
mrec->name = g_strdup(node->key);
mrec->formatlist = g_strsplit(node->value, " ", -1);
mrec->format = g_new0(char*, strarray_length(mrec->formatlist));
g_hash_table_insert(theme->modules, mrec->name, mrec);
}
}
/* Read the texts inside the plugin */
g_hash_table_foreach(theme->modules, (GHFunc) theme_read_module_texts, config);
if (errors) {
/* errors fixed - save the theme */
if (config_write(config, NULL, 0660) == -1) {
/* we probably tried to save to global directory
where we didn't have access.. try saving it to
home dir instead. */
char *str;
/* check that we really didn't try to save
it to home dir.. */
str = g_strdup_printf("%s/.irssi/", g_get_home_dir());
if (strncmp(path, str, strlen(str)) != 0) {
g_free(str);
str = g_strdup_printf("%s/.irssi/%s", g_get_home_dir(), g_basename(path));
config_write(config, str, 0660);
}
g_free(str);
}
}
config_close(config);
return errors;
}
static void sig_formats_error(void)
typedef struct {
char *name;
char *short_name;
} THEME_SEARCH_REC;
static int theme_search_equal(THEME_SEARCH_REC *r1, THEME_SEARCH_REC *r2)
{
signal_emit("gui dialog", 2, "warning",
"Your theme(s) had some old format strings, "
"these have been changed back to their default values.");
signal_remove("irssi init finished", (SIGNAL_FUNC) sig_formats_error);
return g_strcasecmp(r1->short_name, r2->short_name);
}
static void theme_get_modules(char *module, FORMAT_REC *formats, GSList **list)
{
THEME_SEARCH_REC *rec;
rec = g_new(THEME_SEARCH_REC, 1);
rec->name = module;
rec->short_name = strrchr(module, '/');
if (rec->short_name != NULL)
rec->short_name++; else rec->short_name = module;
*list = g_slist_insert_sorted(*list, rec, (GCompareFunc) theme_search_equal);
}
static GSList *get_sorted_modules(void)
{
GSList *list;
list = NULL;
g_hash_table_foreach(default_formats, (GHFunc) theme_get_modules, &list);
return list;
}
static THEME_SEARCH_REC *theme_search(GSList *list, const char *module)
{
THEME_SEARCH_REC *rec;
while (list != NULL) {
rec = list->data;
if (g_strcasecmp(rec->short_name, module) == 0)
return rec;
list = list->next;
}
return NULL;
}
static void theme_show(THEME_SEARCH_REC *rec, const char *key, const char *value)
{
MODULE_THEME_REC *theme;
FORMAT_REC *formats;
const char *text, *last_title;
int n, first;
formats = g_hash_table_lookup(default_formats, rec->name);
theme = g_hash_table_lookup(current_theme->modules, rec->name);
last_title = NULL; first = TRUE;
for (n = 1; formats[n].def != NULL; n++) {
text = theme != NULL && theme->formats[n] != NULL ?
theme->formats[n] : formats[n].def;
if (formats[n].tag == NULL)
last_title = text;
else if ((value != NULL && key != NULL && g_strcasecmp(formats[n].tag, key) == 0) ||
(value == NULL && (key == NULL || stristr(formats[n].tag, key) != NULL))) {
if (first) {
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "");
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%K[%W%s%K] - [%W%s%K]", rec->short_name, formats[0].def);
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "");
first = FALSE;
}
if (last_title != NULL)
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%K[%W%s%K]", last_title);
if (value != NULL) {
theme = theme_module_create(current_theme, rec->name);
theme->formats[n] = g_strdup(value);
text = value;
}
printtext(NULL, NULL, MSGLEVEL_CLIENTCRAP, "%s %K=%n %s", formats[n].tag, text);
last_title = NULL;
}
}
}
static void cmd_format(const char *data)
{
char *params, *module, *key, *value;
GSList *tmp, *modules;
/* /FORMAT [<module>] [<key> [<value>]] */
params = cmd_get_params(data, 3 | PARAM_FLAG_GETREST, &module, &key, &value);
modules = get_sorted_modules();
if (*module != '\0' && theme_search(modules, module) == NULL) {
/* first argument isn't module.. */
g_free(params);
params = cmd_get_params(data, 2 | PARAM_FLAG_GETREST, &key, &value);
module = "";
}
if (*key == '\0') key = NULL;
if (*value == '\0') value = NULL;
for (tmp = modules; tmp != NULL; tmp = tmp->next) {
THEME_SEARCH_REC *rec = tmp->data;
if (*module == '\0' || g_strcasecmp(rec->short_name, module) == 0)
theme_show(rec, key, value);
}
g_slist_foreach(modules, (GFunc) g_free, NULL);
g_slist_free(modules);
g_free(params);
}
static void module_save(const char *module, MODULE_THEME_REC *rec, CONFIG_NODE *fnode)
{
CONFIG_NODE *node;
FORMAT_REC *formats;
int n;
formats = g_hash_table_lookup(default_formats, rec->name);
if (formats == NULL) return;
node = config_node_section(fnode, rec->name, NODE_TYPE_BLOCK);
for (n = 0; formats[n].def != NULL; n++) {
if (rec->formats[n] != NULL)
iconfig_node_set_str(node, formats[n].tag, rec->formats[n]);
}
}
/* save changed formats */
static void cmd_save(void)
{
CONFIG_REC *config;
CONFIG_NODE *fnode;
config = config_open(current_theme->path, 0660);
if (config == NULL) return;
config_parse(config);
fnode = config_node_traverse(config, "formats", TRUE);
g_hash_table_foreach(current_theme->modules, (GHFunc) module_save, fnode);
if (config_write(config, NULL, 0660) == -1) {
/* we probably tried to save to global directory
where we didn't have access.. try saving it to
home dir instead. */
char *str;
/* check that we really didn't try to save
it to home dir.. */
str = g_strdup_printf("%s/.irssi/", g_get_home_dir());
if (strncmp(current_theme->path, str, strlen(str)) != 0) {
g_free(str);
str = g_strdup_printf("%s/.irssi/%s", g_get_home_dir(), g_basename(current_theme->path));
config_write(config, str, 0660);
}
g_free(str);
}
config_close(config);
}
void themes_init(void)
@ -235,7 +433,8 @@ void themes_init(void)
GSList *tmp;
const char *value;
char *str;
int errors;
default_formats = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
/* first there's default theme.. */
str = g_strdup_printf("%s/.irssi/default.theme", g_get_home_dir());
@ -251,22 +450,20 @@ void themes_init(void)
find_themes(SYSCONFDIR"/irssi");
/* read formats for all themes */
errors = FALSE;
for (tmp = themes; tmp != NULL; tmp = tmp->next) {
rec = tmp->data;
if (theme_read(rec, rec->path))
errors = TRUE;
theme_read(rec, rec->path);
}
if (errors)
signal_add("irssi init finished", (SIGNAL_FUNC) sig_formats_error);
/* find the current theme to use */
value = settings_get_str("current_theme");
rec = theme_find(value);
if (rec != NULL) current_theme = rec;
command_bind("format", NULL, (SIGNAL_FUNC) cmd_format);
command_bind("save", NULL, (SIGNAL_FUNC) cmd_save);
}
void themes_deinit(void)
@ -275,4 +472,9 @@ void themes_deinit(void)
g_slist_foreach(themes, (GFunc) theme_destroy, NULL);
g_slist_free(themes);
themes = NULL;
g_hash_table_destroy(default_formats);
command_unbind("format", (SIGNAL_FUNC) cmd_format);
command_unbind("save", (SIGNAL_FUNC) cmd_save);
}

View File

@ -1,18 +1,18 @@
#ifndef __THEMES_H
#define __THEMES_H
#include "printtext.h"
#define THEME_FLAG_BG_SCROLLABLE 0x0001
#define THEME_FLAG_BG_SCALED 0x0002
#define THEME_FLAG_BG_SHADED 0x0004
typedef struct
{
typedef struct {
char *name;