mirror of
https://github.com/irssi/irssi.git
synced 2024-12-04 14:46:39 -05:00
/RELOADing broken theme file doesn't crash irssi anymore.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@2880 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
parent
0b12cfe47b
commit
38ce412a5d
@ -50,6 +50,7 @@ THEME_REC *theme_create(const char *path, const char *name)
|
|||||||
g_return_val_if_fail(name != NULL, NULL);
|
g_return_val_if_fail(name != NULL, NULL);
|
||||||
|
|
||||||
rec = g_new0(THEME_REC, 1);
|
rec = g_new0(THEME_REC, 1);
|
||||||
|
rec->refcount = 1;
|
||||||
rec->path = g_strdup(path);
|
rec->path = g_strdup(path);
|
||||||
rec->name = g_strdup(name);
|
rec->name = g_strdup(name);
|
||||||
rec->abstracts = g_hash_table_new((GHashFunc) g_str_hash,
|
rec->abstracts = g_hash_table_new((GHashFunc) g_str_hash,
|
||||||
@ -83,12 +84,8 @@ static void theme_module_destroy(const char *key, MODULE_THEME_REC *rec)
|
|||||||
g_free(rec);
|
g_free(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
void theme_destroy(THEME_REC *rec)
|
static void theme_real_destroy(THEME_REC *rec)
|
||||||
{
|
{
|
||||||
themes = g_slist_remove(themes, rec);
|
|
||||||
|
|
||||||
signal_emit("theme destroyed", 1, rec);
|
|
||||||
|
|
||||||
g_hash_table_foreach(rec->abstracts, (GHFunc) theme_abstract_destroy, NULL);
|
g_hash_table_foreach(rec->abstracts, (GHFunc) theme_abstract_destroy, NULL);
|
||||||
g_hash_table_destroy(rec->abstracts);
|
g_hash_table_destroy(rec->abstracts);
|
||||||
g_hash_table_foreach(rec->modules, (GHFunc) theme_module_destroy, NULL);
|
g_hash_table_foreach(rec->modules, (GHFunc) theme_module_destroy, NULL);
|
||||||
@ -102,6 +99,20 @@ void theme_destroy(THEME_REC *rec)
|
|||||||
g_free(rec);
|
g_free(rec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void theme_unref(THEME_REC *rec)
|
||||||
|
{
|
||||||
|
if (--rec->refcount == 0)
|
||||||
|
theme_real_destroy(rec);
|
||||||
|
}
|
||||||
|
|
||||||
|
void theme_destroy(THEME_REC *rec)
|
||||||
|
{
|
||||||
|
themes = g_slist_remove(themes, rec);
|
||||||
|
signal_emit("theme destroyed", 1, rec);
|
||||||
|
|
||||||
|
theme_unref(rec);
|
||||||
|
}
|
||||||
|
|
||||||
static char *theme_replace_expand(THEME_REC *theme, int index,
|
static char *theme_replace_expand(THEME_REC *theme, int index,
|
||||||
char default_fg, char default_bg,
|
char default_fg, char default_bg,
|
||||||
char *last_fg, char *last_bg,
|
char *last_fg, char *last_bg,
|
||||||
@ -1207,10 +1218,20 @@ static void read_settings(void)
|
|||||||
|
|
||||||
static void themes_read(void)
|
static void themes_read(void)
|
||||||
{
|
{
|
||||||
|
GSList *refs;
|
||||||
char *fname;
|
char *fname;
|
||||||
|
|
||||||
while (themes != NULL)
|
/* increase every theme's refcount, and destroy them. this way if
|
||||||
theme_destroy(themes->data);
|
we want to use the theme before it's reloaded we don't crash. */
|
||||||
|
refs = NULL;
|
||||||
|
while (themes != NULL) {
|
||||||
|
THEME_REC *theme = themes->data;
|
||||||
|
|
||||||
|
refs = g_slist_prepend(refs, theme);
|
||||||
|
|
||||||
|
theme->refcount++;
|
||||||
|
theme_destroy(theme);
|
||||||
|
}
|
||||||
|
|
||||||
/* first there's default theme.. */
|
/* first there's default theme.. */
|
||||||
current_theme = theme_load("default");
|
current_theme = theme_load("default");
|
||||||
@ -1223,7 +1244,12 @@ static void themes_read(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
window_themes_update();
|
window_themes_update();
|
||||||
change_theme(settings_get_str("theme"), FALSE);
|
change_theme(settings_get_str("theme"), FALSE);
|
||||||
|
|
||||||
|
while (refs != NULL) {
|
||||||
|
theme_unref(refs->data);
|
||||||
|
refs = g_slist_remove(refs, refs->data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void themes_init(void)
|
void themes_init(void)
|
||||||
|
@ -11,6 +11,8 @@ typedef struct {
|
|||||||
} MODULE_THEME_REC;
|
} MODULE_THEME_REC;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
int refcount;
|
||||||
|
|
||||||
char *path;
|
char *path;
|
||||||
char *name;
|
char *name;
|
||||||
time_t last_modify;
|
time_t last_modify;
|
||||||
|
Loading…
Reference in New Issue
Block a user