mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
Theme fixes: /RELOAD reloads them, /SET current_theme changes the default
theme, you can have window specific themes with /WINDOW THEME. git-svn-id: http://svn.irssi.org/repos/irssi/trunk@561 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
138079e3bd
commit
b82d10ca57
@ -81,7 +81,6 @@ void fe_common_core_init(void)
|
||||
/*settings_add_bool("lookandfeel", "autoraise_msgs_window", FALSE);*/
|
||||
/*settings_add_bool("lookandfeel", "use_tabbed_windows", TRUE);
|
||||
settings_add_int("lookandfeel", "tab_orientation", 3);*/
|
||||
settings_add_str("lookandfeel", "current_theme", "default");
|
||||
|
||||
themes_init();
|
||||
theme_register(fecommon_core_formats);
|
||||
|
@ -112,11 +112,19 @@ FORMAT_REC fecommon_core_formats[] = {
|
||||
{ "not_good_idea", "Doing this is not a good idea. Add -YES if you really mean it", 0 },
|
||||
|
||||
/* ---- */
|
||||
{ NULL, "Misc", 0 },
|
||||
{ NULL, "Themes", 0 },
|
||||
|
||||
{ "theme_saved", "Theme saved to %_$0%_", 1, { 0 } },
|
||||
{ "theme_save_failed", "Error saving theme to %_$0%_", 1, { 0 } },
|
||||
{ "theme_not_found", "Theme %_$0%_ not found", 1, { 0 } },
|
||||
{ "window_theme_changed", "Using theme %_$0%_ in this window", 1, { 0 } },
|
||||
{ "format_title", "%:%K[%W$0%K] - [%W$1%K]%:%:", 2, { 0, 0 } },
|
||||
{ "format_subtitle", "%K[%W$0%K]", 1, { 0 } },
|
||||
{ "format_item", "$0 %K=%n $1", 2, { 0, 0 } },
|
||||
|
||||
/* ---- */
|
||||
{ NULL, "Misc", 0 },
|
||||
|
||||
{ "not_toggle", "Value must be either ON, OFF or TOGGLE", 0 },
|
||||
{ "perl_error", "Perl error: $0", 1, { 0 } },
|
||||
{ "bind_key", "$[10]0 $1 $2", 3, { 0, 0, 0 } },
|
||||
|
@ -85,9 +85,16 @@ enum {
|
||||
|
||||
IRCTXT_FILL_8,
|
||||
|
||||
IRCTXT_THEME_SAVED,
|
||||
IRCTXT_THEME_SAVE_FAILED,
|
||||
IRCTXT_THEME_NOT_FOUND,
|
||||
IRCTXT_WINDOW_THEME_CHANGED,
|
||||
IRCTXT_FORMAT_TITLE,
|
||||
IRCTXT_FORMAT_SUBTITLE,
|
||||
IRCTXT_FORMAT_ITEM,
|
||||
|
||||
IRCTXT_FILL_9,
|
||||
|
||||
IRCTXT_NOT_TOGGLE,
|
||||
IRCTXT_PERL_ERROR,
|
||||
IRCTXT_BIND_KEY,
|
||||
|
@ -114,7 +114,8 @@ char *strip_codes(const char *input)
|
||||
}
|
||||
|
||||
/* parse ANSI color string */
|
||||
static char *convert_ansi(char *str, int *fgcolor, int *bgcolor, int *flags)
|
||||
static char *convert_ansi(THEME_REC *theme, char *str,
|
||||
int *fgcolor, int *bgcolor, int *flags)
|
||||
{
|
||||
static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 };
|
||||
char *start;
|
||||
@ -124,7 +125,7 @@ static char *convert_ansi(char *str, int *fgcolor, int *bgcolor, int *flags)
|
||||
return str;
|
||||
start = str++;
|
||||
|
||||
fg = *fgcolor < 0 ? current_theme->default_color : *fgcolor;
|
||||
fg = *fgcolor < 0 ? theme->default_color : *fgcolor;
|
||||
bg = *bgcolor < 0 ? -1 : *bgcolor;
|
||||
fl = *flags;
|
||||
|
||||
@ -143,7 +144,7 @@ static char *convert_ansi(char *str, int *fgcolor, int *bgcolor, int *flags)
|
||||
switch (num) {
|
||||
case 0:
|
||||
/* reset colors back to default */
|
||||
fg = current_theme->default_color;
|
||||
fg = theme->default_color;
|
||||
bg = -1;
|
||||
fl &= ~(PRINTFLAG_BEEP|PRINTFLAG_INDENT);
|
||||
break;
|
||||
@ -336,7 +337,19 @@ static void read_arglist(va_list va, FORMAT_REC *format,
|
||||
}
|
||||
}
|
||||
|
||||
static char *output_format_text_args(TEXT_DEST_REC *dest, FORMAT_REC *format, const char *text, va_list args)
|
||||
static void create_dest_rec(TEXT_DEST_REC *dest,
|
||||
void *server, const char *channel,
|
||||
int level, WINDOW_REC *window)
|
||||
{
|
||||
dest->server = server;
|
||||
dest->channel = channel;
|
||||
dest->level = level;
|
||||
dest->window = window != NULL ? window :
|
||||
window_find_closest(server, channel, level);
|
||||
}
|
||||
|
||||
static char *output_format_text_args(TEXT_DEST_REC *dest, FORMAT_REC *format,
|
||||
const char *text, va_list args)
|
||||
{
|
||||
GString *out;
|
||||
char *arglist[10];
|
||||
@ -346,7 +359,7 @@ static char *output_format_text_args(TEXT_DEST_REC *dest, FORMAT_REC *format, co
|
||||
char code, *ret;
|
||||
int need_free;
|
||||
|
||||
str = current_theme != NULL && text != NULL ? text : format->def;
|
||||
str = text != NULL ? text : format->def;
|
||||
|
||||
/* read all optional arguments to arglist[] list
|
||||
so they can be used in any order.. */
|
||||
@ -394,37 +407,44 @@ static char *output_format_text_args(TEXT_DEST_REC *dest, FORMAT_REC *format, co
|
||||
|
||||
static char *output_format_text(TEXT_DEST_REC *dest, int formatnum, ...)
|
||||
{
|
||||
MODULE_THEME_REC *theme;
|
||||
THEME_REC *theme;
|
||||
MODULE_THEME_REC *module_theme;
|
||||
va_list args;
|
||||
char *ret;
|
||||
|
||||
theme = g_hash_table_lookup(current_theme->modules, MODULE_NAME);
|
||||
theme = dest->window->theme == NULL ? current_theme :
|
||||
dest->window->theme;
|
||||
module_theme = g_hash_table_lookup(theme->modules, MODULE_NAME);
|
||||
|
||||
va_start(args, formatnum);
|
||||
ret = output_format_text_args(dest, &fecommon_core_formats[formatnum],
|
||||
theme == NULL ? NULL : theme->formats[formatnum], args);
|
||||
module_theme == NULL ? NULL :
|
||||
module_theme->formats[formatnum], args);
|
||||
va_end(args);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void printformat_module_args(const char *module, void *server, const char *channel, int level, int formatnum, va_list va)
|
||||
void printformat_module_args(const char *module, void *server,
|
||||
const char *channel, int level,
|
||||
int formatnum, va_list va)
|
||||
{
|
||||
MODULE_THEME_REC *theme;
|
||||
THEME_REC *theme;
|
||||
MODULE_THEME_REC *module_theme;
|
||||
TEXT_DEST_REC dest;
|
||||
FORMAT_REC *formats;
|
||||
char *str;
|
||||
|
||||
dest.window = NULL;
|
||||
dest.server = server;
|
||||
dest.channel = channel;
|
||||
dest.level = level;
|
||||
create_dest_rec(&dest, server, channel, level, NULL);
|
||||
theme = dest.window->theme == NULL ? current_theme :
|
||||
dest.window->theme;
|
||||
|
||||
theme = g_hash_table_lookup(current_theme->modules, module);
|
||||
module_theme = g_hash_table_lookup(theme->modules, module);
|
||||
formats = g_hash_table_lookup(default_formats, module);
|
||||
|
||||
str = output_format_text_args(&dest, &formats[formatnum],
|
||||
theme == NULL ? NULL : theme->formats[formatnum], va);
|
||||
module_theme == NULL ? NULL :
|
||||
module_theme->formats[formatnum], va);
|
||||
if (*str != '\0') print_string(&dest, str);
|
||||
g_free(str);
|
||||
}
|
||||
@ -440,21 +460,21 @@ void printformat_module(const char *module, void *server, const char *channel, i
|
||||
|
||||
void printformat_module_window_args(const char *module, WINDOW_REC *window, int level, int formatnum, va_list va)
|
||||
{
|
||||
MODULE_THEME_REC *theme;
|
||||
THEME_REC *theme;
|
||||
MODULE_THEME_REC *module_theme;
|
||||
TEXT_DEST_REC dest;
|
||||
FORMAT_REC *formats;
|
||||
char *str;
|
||||
|
||||
dest.window = window;
|
||||
dest.server = NULL;
|
||||
dest.channel = NULL;
|
||||
dest.level = level;
|
||||
create_dest_rec(&dest, NULL, NULL, level, window);
|
||||
theme = window->theme == NULL ? current_theme :
|
||||
window->theme;
|
||||
module_theme = g_hash_table_lookup(theme->modules, module);
|
||||
|
||||
theme = g_hash_table_lookup(current_theme->modules, module);
|
||||
formats = g_hash_table_lookup(default_formats, module);
|
||||
|
||||
str = output_format_text_args(&dest, &formats[formatnum],
|
||||
theme == NULL ? NULL : theme->formats[formatnum], va);
|
||||
module_theme == NULL ? NULL :
|
||||
module_theme->formats[formatnum], va);
|
||||
if (*str != '\0') print_string(&dest, str);
|
||||
g_free(str);
|
||||
}
|
||||
@ -496,9 +516,6 @@ static void print_string(TEXT_DEST_REC *dest, const char *text)
|
||||
g_return_if_fail(dest != NULL);
|
||||
g_return_if_fail(text != NULL);
|
||||
|
||||
if (dest->window == NULL)
|
||||
dest->window = window_find_closest(dest->server, dest->channel, dest->level);
|
||||
|
||||
tmp = get_line_start_text(dest);
|
||||
str = tmp == NULL ? (char *) text :
|
||||
g_strconcat(tmp, text, NULL);
|
||||
@ -603,10 +620,7 @@ void printtext(void *server, const char *channel, int level, const char *text, .
|
||||
|
||||
g_return_if_fail(text != NULL);
|
||||
|
||||
dest.window = NULL;
|
||||
dest.server = server;
|
||||
dest.channel = channel;
|
||||
dest.level = level;
|
||||
create_dest_rec(&dest, server, channel, level, NULL);
|
||||
|
||||
va_start(va, text);
|
||||
str = printtext_get_args(&dest, text, va);
|
||||
@ -624,10 +638,8 @@ void printtext_window(WINDOW_REC *window, int level, const char *text, ...)
|
||||
|
||||
g_return_if_fail(text != NULL);
|
||||
|
||||
dest.window = window != NULL ? window : active_win;
|
||||
dest.server = NULL;
|
||||
dest.channel = NULL;
|
||||
dest.level = level;
|
||||
create_dest_rec(&dest, NULL, NULL, level,
|
||||
window != NULL ? window : active_win);
|
||||
|
||||
va_start(va, text);
|
||||
str = printtext_get_args(&dest, text, va);
|
||||
@ -709,11 +721,7 @@ static void sig_print_text(WINDOW_REC *window, SERVER_REC *server,
|
||||
g_return_if_fail(text != NULL);
|
||||
g_return_if_fail(window != NULL);
|
||||
|
||||
dest.window = window;
|
||||
dest.server = server;
|
||||
dest.channel = target;
|
||||
dest.level = GPOINTER_TO_INT(level);
|
||||
|
||||
create_dest_rec(&dest, server, target, GPOINTER_TO_INT(level), window);
|
||||
msg_beep_check(server, dest.level);
|
||||
|
||||
flags = 0; fgcolor = -1; bgcolor = -1; type = '\0';
|
||||
@ -786,7 +794,8 @@ static void sig_print_text(WINDOW_REC *window, SERVER_REC *server,
|
||||
flags ^= PRINTFLAG_UNDERLINE;
|
||||
case 27:
|
||||
/* ansi color code */
|
||||
ptr = convert_ansi(ptr, &fgcolor, &bgcolor, &flags);
|
||||
ptr = convert_ansi(window->theme == NULL ? current_theme :
|
||||
window->theme, ptr, &fgcolor, &bgcolor, &flags);
|
||||
break;
|
||||
case 4:
|
||||
/* user specific colors */
|
||||
|
@ -33,6 +33,8 @@ GSList *themes;
|
||||
THEME_REC *current_theme;
|
||||
GHashTable *default_formats;
|
||||
|
||||
static void theme_read(THEME_REC *theme, const char *path);
|
||||
|
||||
THEME_REC *theme_create(const char *path, const char *name)
|
||||
{
|
||||
THEME_REC *rec;
|
||||
@ -44,6 +46,7 @@ THEME_REC *theme_create(const char *path, const char *name)
|
||||
rec->path = g_strdup(path);
|
||||
rec->name = g_strdup(name);
|
||||
rec->modules = g_hash_table_new((GHashFunc) g_istr_hash, (GCompareFunc) g_istr_equal);
|
||||
themes = g_slist_append(themes, rec);
|
||||
signal_emit("theme created", 1, rec);
|
||||
|
||||
return rec;
|
||||
@ -64,12 +67,12 @@ static void theme_module_destroy(const char *key, MODULE_THEME_REC *rec)
|
||||
|
||||
void theme_destroy(THEME_REC *rec)
|
||||
{
|
||||
themes = g_slist_remove(themes, rec);
|
||||
|
||||
signal_emit("theme destroyed", 1, rec);
|
||||
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);
|
||||
if (rec->font != NULL) g_free(rec->font);
|
||||
g_free(rec->path);
|
||||
g_free(rec->name);
|
||||
g_free(rec);
|
||||
@ -152,6 +155,11 @@ static void theme_read_module(THEME_REC *theme, const char *module)
|
||||
config_close(config);
|
||||
}
|
||||
|
||||
static void themes_read_module(const char *module)
|
||||
{
|
||||
g_slist_foreach(themes, (GFunc) theme_read_module, (void *) module);
|
||||
}
|
||||
|
||||
static void theme_remove_module(THEME_REC *theme, const char *module)
|
||||
{
|
||||
MODULE_THEME_REC *rec;
|
||||
@ -163,15 +171,18 @@ static void theme_remove_module(THEME_REC *theme, const char *module)
|
||||
theme_module_destroy(module, rec);
|
||||
}
|
||||
|
||||
static void themes_remove_module(const char *module)
|
||||
{
|
||||
g_slist_foreach(themes, (GFunc) theme_remove_module, (void *) module);
|
||||
}
|
||||
|
||||
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);
|
||||
themes_read_module(module);
|
||||
}
|
||||
|
||||
void theme_unregister_module(const char *module)
|
||||
@ -184,8 +195,7 @@ void theme_unregister_module(const char *module)
|
||||
g_hash_table_remove(default_formats, key);
|
||||
g_free(key);
|
||||
|
||||
if (current_theme != NULL)
|
||||
theme_remove_module(current_theme, module);
|
||||
themes_remove_module(module);
|
||||
}
|
||||
|
||||
static THEME_REC *theme_find(const char *name)
|
||||
@ -202,6 +212,36 @@ static THEME_REC *theme_find(const char *name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
THEME_REC *theme_load(const char *name)
|
||||
{
|
||||
THEME_REC *theme;
|
||||
struct stat statbuf;
|
||||
char *fname;
|
||||
|
||||
theme = theme_find(name);
|
||||
if (theme != NULL) return theme;
|
||||
|
||||
/* check home dir */
|
||||
fname = g_strdup_printf("%s/.irssi/%s.theme", g_get_home_dir(), name);
|
||||
if (stat(fname, &statbuf) != 0) {
|
||||
/* check global config dir */
|
||||
g_free(fname);
|
||||
fname = g_strdup_printf(SYSCONFDIR"/irssi/%s.theme", name);
|
||||
if (stat(fname, &statbuf) != 0) {
|
||||
/* theme not found */
|
||||
g_free(fname);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
theme = theme_create(fname, name);
|
||||
theme_read(theme, theme->path);
|
||||
|
||||
g_free(fname);
|
||||
return theme;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Add all *.theme files from directory to themes */
|
||||
static void find_themes(gchar *path)
|
||||
{
|
||||
@ -228,11 +268,23 @@ static void find_themes(gchar *path)
|
||||
}
|
||||
closedir(dirp);
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
THEME_REC *theme;
|
||||
CONFIG_REC *config;
|
||||
} THEME_READ_REC;
|
||||
|
||||
static void theme_read_modules(const char *module, void *value,
|
||||
THEME_READ_REC *rec)
|
||||
{
|
||||
theme_read_formats(rec->config, rec->theme, module);
|
||||
}
|
||||
|
||||
static void theme_read(THEME_REC *theme, const char *path)
|
||||
{
|
||||
CONFIG_REC *config;
|
||||
char *value;
|
||||
THEME_READ_REC rec;
|
||||
|
||||
config = config_open(path, -1);
|
||||
if (config == NULL) {
|
||||
@ -242,23 +294,12 @@ static void theme_read(THEME_REC *theme, const char *path)
|
||||
}
|
||||
|
||||
config_parse(config);
|
||||
|
||||
/* default color */
|
||||
theme->default_color = config_get_int(config, NULL, "default_color", 15);
|
||||
/* get font */
|
||||
value = config_get_str(config, NULL, "font", NULL);
|
||||
theme->font = (value == NULL || *value == '\0') ? NULL : g_strdup(value);
|
||||
|
||||
/* get background pixmap */
|
||||
value = config_get_str(config, NULL, "bg_pixmap", NULL);
|
||||
theme->bg_pixmap = (value == NULL || *value == '\0') ? NULL : g_strdup(value);
|
||||
/* get background pixmap properties */
|
||||
if (config_get_bool(config, NULL, "bg_scrollable", FALSE))
|
||||
theme->flags |= THEME_FLAG_BG_SCROLLABLE;
|
||||
if (config_get_bool(config, NULL, "bg_scaled", TRUE))
|
||||
theme->flags |= THEME_FLAG_BG_SCALED;
|
||||
if (config_get_bool(config, NULL, "bg_shaded", FALSE))
|
||||
theme->flags |= THEME_FLAG_BG_SHADED;
|
||||
rec.theme = theme;
|
||||
rec.config = config;
|
||||
g_hash_table_foreach(default_formats,
|
||||
(GHFunc) theme_read_modules, &rec);
|
||||
config_close(config);
|
||||
}
|
||||
|
||||
@ -408,20 +449,23 @@ static void module_save(const char *module, MODULE_THEME_REC *rec, CONFIG_NODE *
|
||||
}
|
||||
}
|
||||
|
||||
/* save changed formats */
|
||||
static void cmd_save(void)
|
||||
static void theme_save(THEME_REC *theme)
|
||||
{
|
||||
CONFIG_REC *config;
|
||||
CONFIG_NODE *fnode;
|
||||
char *path;
|
||||
int ok;
|
||||
|
||||
config = config_open(current_theme->path, 0660);
|
||||
config = config_open(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);
|
||||
g_hash_table_foreach(theme->modules, (GHFunc) module_save, fnode);
|
||||
|
||||
ok = TRUE;
|
||||
path = g_strdup(theme->path);
|
||||
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
|
||||
@ -430,18 +474,33 @@ static void cmd_save(void)
|
||||
|
||||
/* 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);
|
||||
g_free(path);
|
||||
path = g_strdup_printf("%s/.irssi/%s", g_get_home_dir(),
|
||||
g_basename(theme->path));
|
||||
str = strrchr(path, '/');
|
||||
if (strncmp(theme->path, path, (int) (path-str)) != 0 &&
|
||||
config_write(config, str, 0660) == -1)
|
||||
ok = FALSE;
|
||||
}
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
ok ? IRCTXT_THEME_SAVED : IRCTXT_THEME_SAVE_FAILED,
|
||||
path, config_last_error(config));
|
||||
g_free(path);
|
||||
config_close(config);
|
||||
}
|
||||
|
||||
/* save changed formats */
|
||||
static void cmd_save(void)
|
||||
{
|
||||
GSList *tmp;
|
||||
|
||||
for (tmp = themes; tmp != NULL; tmp = tmp->next) {
|
||||
THEME_REC *theme = tmp->data;
|
||||
|
||||
theme_save(theme);
|
||||
}
|
||||
}
|
||||
|
||||
static void complete_format_list(THEME_SEARCH_REC *rec, const char *key, GList **list)
|
||||
{
|
||||
MODULE_THEME_REC *theme;
|
||||
@ -509,58 +568,76 @@ static void sig_complete_format(GList **list, WINDOW_REC *window,
|
||||
if (*list != NULL) signal_stop();
|
||||
}
|
||||
|
||||
void themes_init(void)
|
||||
static void read_settings(void)
|
||||
{
|
||||
THEME_REC *rec;
|
||||
GSList *tmp;
|
||||
const char *value;
|
||||
char *str;
|
||||
const char *theme;
|
||||
|
||||
default_formats = g_hash_table_new((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
|
||||
theme = settings_get_str("theme");
|
||||
if (strcmp(current_theme->name, theme) != 0) {
|
||||
rec = theme_load(theme);
|
||||
if (rec != NULL) current_theme = rec;
|
||||
}
|
||||
}
|
||||
|
||||
static void themes_read(void)
|
||||
{
|
||||
GSList *tmp;
|
||||
char *fname;
|
||||
|
||||
while (themes != NULL)
|
||||
theme_destroy(themes->data);
|
||||
|
||||
/* first there's default theme.. */
|
||||
str = g_strdup_printf("%s/.irssi/default.theme", g_get_home_dir());
|
||||
current_theme = theme_create(str, "default");
|
||||
current_theme = theme_load("default");
|
||||
if (current_theme == NULL) {
|
||||
fname = g_strdup_printf("%s/.irssi/default.theme",
|
||||
g_get_home_dir());
|
||||
current_theme = theme_create(fname, "default");
|
||||
current_theme->default_color = 15;
|
||||
themes = g_slist_append(NULL, current_theme);
|
||||
g_free(str);
|
||||
|
||||
/* read list of themes */
|
||||
str = g_strdup_printf("%s/.irssi", g_get_home_dir());
|
||||
find_themes(str);
|
||||
g_free(str);
|
||||
find_themes(SYSCONFDIR"/irssi");
|
||||
|
||||
/* read formats for all themes */
|
||||
for (tmp = themes; tmp != NULL; tmp = tmp->next) {
|
||||
rec = tmp->data;
|
||||
|
||||
theme_read(rec, rec->path);
|
||||
g_free(fname);
|
||||
}
|
||||
|
||||
/* find the current theme to use */
|
||||
value = settings_get_str("current_theme");
|
||||
/* update window theme structures */
|
||||
for (tmp = windows; tmp != NULL; tmp = tmp->next) {
|
||||
WINDOW_REC *rec = tmp->data;
|
||||
|
||||
rec = theme_find(value);
|
||||
if (rec != NULL) current_theme = rec;
|
||||
if (rec->theme_name != NULL)
|
||||
rec->theme = theme_load(rec->theme_name);
|
||||
}
|
||||
|
||||
read_settings();
|
||||
}
|
||||
|
||||
void themes_init(void)
|
||||
{
|
||||
settings_add_str("lookandfeel", "theme", "default");
|
||||
|
||||
default_formats = g_hash_table_new((GHashFunc) g_str_hash,
|
||||
(GCompareFunc) g_str_equal);
|
||||
|
||||
themes = NULL;
|
||||
themes_read();
|
||||
|
||||
command_bind("format", NULL, (SIGNAL_FUNC) cmd_format);
|
||||
command_bind("save", NULL, (SIGNAL_FUNC) cmd_save);
|
||||
signal_add("complete command format", (SIGNAL_FUNC) sig_complete_format);
|
||||
signal_add("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
signal_add("setup reread", (SIGNAL_FUNC) themes_read);
|
||||
|
||||
command_set_options("format", "delete reset");
|
||||
}
|
||||
|
||||
void themes_deinit(void)
|
||||
{
|
||||
/* free memory used by themes */
|
||||
g_slist_foreach(themes, (GFunc) theme_destroy, NULL);
|
||||
g_slist_free(themes);
|
||||
themes = NULL;
|
||||
while (themes != NULL)
|
||||
theme_destroy(themes->data);
|
||||
|
||||
g_hash_table_destroy(default_formats);
|
||||
|
||||
command_unbind("format", (SIGNAL_FUNC) cmd_format);
|
||||
command_unbind("save", (SIGNAL_FUNC) cmd_save);
|
||||
signal_remove("complete command format", (SIGNAL_FUNC) sig_complete_format);
|
||||
signal_remove("setup changed", (SIGNAL_FUNC) read_settings);
|
||||
signal_remove("setup reread", (SIGNAL_FUNC) themes_read);
|
||||
}
|
||||
|
@ -3,10 +3,6 @@
|
||||
|
||||
#include "printtext.h"
|
||||
|
||||
#define THEME_FLAG_BG_SCROLLABLE 0x0001
|
||||
#define THEME_FLAG_BG_SCALED 0x0002
|
||||
#define THEME_FLAG_BG_SHADED 0x0004
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
|
||||
@ -19,13 +15,9 @@ typedef struct {
|
||||
char *name;
|
||||
|
||||
int default_color;
|
||||
char *bg_pixmap;
|
||||
char *font;
|
||||
int flags;
|
||||
|
||||
GHashTable *modules;
|
||||
|
||||
gpointer gui_data;
|
||||
void *gui_data;
|
||||
} THEME_REC;
|
||||
|
||||
extern GSList *themes;
|
||||
@ -35,6 +27,8 @@ extern GHashTable *default_formats;
|
||||
THEME_REC *theme_create(const char *path, const char *name);
|
||||
void theme_destroy(THEME_REC *rec);
|
||||
|
||||
THEME_REC *theme_load(const char *name);
|
||||
|
||||
#define theme_register(formats) theme_register_module(MODULE_NAME, formats)
|
||||
#define theme_unregister() theme_unregister_module(MODULE_NAME)
|
||||
void theme_register_module(const char *module, FORMAT_REC *formats);
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include "levels.h"
|
||||
|
||||
#include "themes.h"
|
||||
#include "windows.h"
|
||||
#include "window-items.h"
|
||||
|
||||
@ -355,6 +356,19 @@ static void cmd_window_list(void)
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTCRAP, IRCTXT_WINDOWLIST_FOOTER);
|
||||
}
|
||||
|
||||
/* SYNTAX: WINDOW THEME <name> */
|
||||
static void cmd_window_theme(const char *data)
|
||||
{
|
||||
active_win->theme = theme_load(data);
|
||||
if (active_win->theme != NULL) {
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
IRCTXT_WINDOW_THEME_CHANGED, data);
|
||||
} else {
|
||||
printformat(NULL, NULL, MSGLEVEL_CLIENTNOTICE,
|
||||
IRCTXT_THEME_NOT_FOUND, data);
|
||||
}
|
||||
}
|
||||
|
||||
void window_commands_init(void)
|
||||
{
|
||||
command_bind("window", NULL, (SIGNAL_FUNC) cmd_window);
|
||||
@ -377,6 +391,7 @@ void window_commands_init(void)
|
||||
command_bind("window move left", NULL, (SIGNAL_FUNC) cmd_window_move_left);
|
||||
command_bind("window move right", NULL, (SIGNAL_FUNC) cmd_window_move_right);
|
||||
command_bind("window list", NULL, (SIGNAL_FUNC) cmd_window_list);
|
||||
command_bind("window theme", NULL, (SIGNAL_FUNC) cmd_window_theme);
|
||||
}
|
||||
|
||||
void window_commands_deinit(void)
|
||||
@ -401,4 +416,5 @@ void window_commands_deinit(void)
|
||||
command_unbind("window move left", (SIGNAL_FUNC) cmd_window_move_left);
|
||||
command_unbind("window move right", (SIGNAL_FUNC) cmd_window_move_right);
|
||||
command_unbind("window list", (SIGNAL_FUNC) cmd_window_list);
|
||||
command_unbind("window theme", (SIGNAL_FUNC) cmd_window_theme);
|
||||
}
|
||||
|
@ -48,7 +48,10 @@ typedef struct {
|
||||
time_t last_timestamp; /* When was last timestamp printed */
|
||||
time_t last_line; /* When was last line printed */
|
||||
|
||||
gpointer gui_data;
|
||||
char *theme_name; /* active theme in window, NULL = default */
|
||||
void *theme; /* THEME_REC */
|
||||
|
||||
void *gui_data;
|
||||
} WINDOW_REC;
|
||||
|
||||
extern GSList *windows;
|
||||
|
Loading…
Reference in New Issue
Block a user