From 73cba944812079419e554daf0f3e70c19aa0942b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pekka=20Geh=C3=B6r?= Date: Tue, 9 Dec 2008 08:00:19 +0200 Subject: [PATCH] created new functions inside irreco_theme.c (irreco_theme_new_from_dir(), irreco_theme_read(), theme_new()) and edit irreco_theme_manager --- irreco/src/core/irreco_button_creator_dlg.c | 2 +- irreco/src/core/irreco_theme.c | 100 +++++++++++++++++++++++- irreco/src/core/irreco_theme.h | 4 + irreco/src/core/irreco_theme_creator_dlg.c | 115 ++++++++++++++++++---------- irreco/src/core/irreco_theme_manager.c | 47 ++++-------- irreco/src/core/irreco_theme_manager_dlg.c | 7 +- 6 files changed, 197 insertions(+), 78 deletions(-) diff --git a/irreco/src/core/irreco_button_creator_dlg.c b/irreco/src/core/irreco_button_creator_dlg.c index fa890aff..73c23b5e 100644 --- a/irreco/src/core/irreco_button_creator_dlg.c +++ b/irreco/src/core/irreco_button_creator_dlg.c @@ -687,7 +687,7 @@ static void _toggle_button_toggled(GtkToggleButton *togglebutton, IRRECO_RETURN } -/* +/** *Select button font format */ diff --git a/irreco/src/core/irreco_theme.c b/irreco/src/core/irreco_theme.c index 368f723f..e7f22155 100644 --- a/irreco/src/core/irreco_theme.c +++ b/irreco/src/core/irreco_theme.c @@ -38,6 +38,8 @@ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ void irreco_theme_read_button_keyfile_foreach(IrrecoDirForeachData * dir_data); void irreco_theme_read_bg_keyfile_foreach(IrrecoDirForeachData * dir_data); +void irreco_theme_read(IrrecoTheme *self, const gchar *dir); + /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Construction & Destruction */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ @@ -47,6 +49,34 @@ void irreco_theme_read_bg_keyfile_foreach(IrrecoDirForeachData * dir_data); * @{ */ +/** + * Create new theme + */ +IrrecoTheme *theme_new() +{ + IrrecoTheme *self; + IRRECO_ENTER + + self = g_slice_new0(IrrecoTheme); + + self->name = g_string_new(NULL); + self->path = g_string_new(NULL); + self->source = g_string_new(NULL); + self->author = g_string_new(NULL); + self->comment = g_string_new(NULL); + self->preview_button_name = g_string_new(NULL); + self->version = g_string_new(NULL); + self->backgrounds = irreco_string_table_new( + (GDestroyNotify)irreco_theme_bg_free, NULL); + self->buttons = irreco_string_table_new( + (GDestroyNotify)irreco_theme_button_free, NULL); + + + IRRECO_RETURN_PTR(self); +} + + + IrrecoTheme *irreco_theme_new(const char *name, const char *path, const char *source, const char *author, const char *comment, @@ -593,10 +623,7 @@ IrrecoTheme *irreco_theme_copy(IrrecoTheme *self) IRRECO_ENTER - new = irreco_theme_new(self->name->str, self->path->str, - self->source->str, self->author->str, - self->comment->str, self->preview_button_name->str, - self->version->str); + new = theme_new(); irreco_theme_set(new, self->name->str, self->path->str, self->source->str, self->author->str, @@ -623,6 +650,71 @@ IrrecoTheme *irreco_theme_copy(IrrecoTheme *self) IRRECO_RETURN_PTR(new); } +/** + * IrrecoTheme new from dir + */ + +IrrecoTheme *irreco_theme_new_from_dir(const gchar *dir) +{ + IrrecoTheme *self = NULL; + + IRRECO_ENTER + + self = theme_new(); + irreco_theme_read(self, dir); + IRRECO_RETURN_PTR(self); +} + +void irreco_theme_read(IrrecoTheme *self, const gchar *dir) +{ + IrrecoKeyFile *keyfile = NULL; + char *name = NULL; + char *source = NULL; + char *author = NULL; + char *comment = NULL; + char *preview_button = NULL; + char *version = NULL; + GString *conf = NULL; + IRRECO_ENTER + + conf = g_string_new(dir); + g_string_append_printf(conf, "/theme.conf"); + keyfile = irreco_keyfile_create(dir, + conf->str, + "theme"); + + /* Required fields. */ + irreco_keyfile_get_str(keyfile, "name", &name); + + /* Optional fields. */ + irreco_keyfile_get_str(keyfile, "source", &source); + irreco_keyfile_get_str(keyfile, "author", &author); + irreco_keyfile_get_str(keyfile, "comment", &comment); + irreco_keyfile_get_str(keyfile, "preview-button", &preview_button); + irreco_keyfile_get_str(keyfile, "version", &version); + + irreco_theme_set(self, name, dir, source, + author, comment, preview_button, version); + + irreco_theme_print(self); + IRRECO_PAUSE + + g_string_free(conf, TRUE); + if (keyfile != NULL) irreco_keyfile_destroy(keyfile); + if (name != NULL) g_free(name); + if (source != NULL) g_free(source); + if (author != NULL) g_free(author); + if (comment != NULL) g_free(comment); + if (preview_button != NULL) g_free(preview_button); + if (version != NULL) g_free(version); + + + + IRRECO_RETURN + +} + + /** @} */ diff --git a/irreco/src/core/irreco_theme.h b/irreco/src/core/irreco_theme.h index 590b1384..9b004d26 100644 --- a/irreco/src/core/irreco_theme.h +++ b/irreco/src/core/irreco_theme.h @@ -84,6 +84,7 @@ struct _IrrecoTheme /* Prototypes */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ +IrrecoTheme *theme_new(); IrrecoTheme *irreco_theme_new(const char *name, const char *path, const char *source, const char *author, const char *comment, @@ -110,6 +111,9 @@ void irreco_theme_set(IrrecoTheme *self, const char *name, const char *path, const char *version); void irreco_theme_check(IrrecoTheme *self); IrrecoTheme *irreco_theme_copy(IrrecoTheme *self); +IrrecoTheme *theme_new_from_dir(); +void irreco_theme_read(IrrecoTheme *self, const gchar *dir); +IrrecoTheme *irreco_theme_new_from_dir(const gchar *dir); #endif /* __IRRECO_THEME_H__ */ diff --git a/irreco/src/core/irreco_theme_creator_dlg.c b/irreco/src/core/irreco_theme_creator_dlg.c index 94e59585..1bb17777 100644 --- a/irreco/src/core/irreco_theme_creator_dlg.c +++ b/irreco/src/core/irreco_theme_creator_dlg.c @@ -100,6 +100,11 @@ static void _set_preview(IrrecoThemeCreatorDlg *self); static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button, IrrecoThemeCreatorDlg *self); + +void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme); +void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self); + + /* static void _set_banner(IrrecoThemeCreatorDlg *self, const gchar *text, @@ -437,8 +442,8 @@ irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data, gboolean loop = TRUE; gboolean rvalue = FALSE; - GtkTextIter startiter; - GtkTextIter enditer; + /*GtkTextIter startiter; + GtkTextIter enditer;*/ IRRECO_ENTER @@ -450,47 +455,17 @@ irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data, self->irreco_data = irreco_data; self->preview_name = NULL; - /* Sets the theme details */ + /* Check whether the theme of a blank*/ if(irreco_theme != NULL) { - - self->theme = irreco_theme; - gtk_entry_set_text(GTK_ENTRY(self->entry_name), - self->theme->name->str); - gtk_entry_set_text(GTK_ENTRY(self->entry_author), - self->theme->author->str); - - self->buffer_comments = gtk_text_view_get_buffer( - GTK_TEXT_VIEW(self->textview_comments)); - gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self->buffer_comments), - self->theme->comment->str, - -1); - self->backgrounds = irreco_theme_creator_backgrounds_new( - GTK_WINDOW(self), - self->irreco_data, - self->theme); - self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self), - self->irreco_data, self->theme); - - /* Set window title */ - gtk_window_set_title(GTK_WINDOW(self), _("Theme Editor ")); - - - _set_preview(self); + /* Sets the theme details */ + _set_theme_details(self, irreco_theme); } else { - self->backgrounds = irreco_theme_creator_backgrounds_new( - GTK_WINDOW(self), - self->irreco_data, - NULL); - self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self), - self->irreco_data, NULL); + /* create blank bg:s and buttons widgets */ + _create_bg_and_button_widgets(self); } - gtk_container_add(GTK_CONTAINER(self->hbox_buttons), - self->buttons); - gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds), - self->backgrounds); do { response = gtk_dialog_run(GTK_DIALOG(self)); @@ -500,6 +475,7 @@ irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data, self->loader_state = LOADER_STATE_INIT; _loader_start(self, NULL); +# if 0 irreco_theme_set_author(self->theme, gtk_entry_get_text( GTK_ENTRY(self->entry_author))); @@ -525,8 +501,7 @@ irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data, &enditer, FALSE)); - irreco_theme_update_keyfile(self->theme); - +# endif irreco_theme = irreco_theme_copy(self->theme); rvalue = TRUE; @@ -554,6 +529,68 @@ irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data, } /** + * Sets the theme details + */ + + +void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme) +{ + + IRRECO_ENTER + + self->theme = irreco_theme; + gtk_entry_set_text(GTK_ENTRY(self->entry_name), + self->theme->name->str); + gtk_entry_set_text(GTK_ENTRY(self->entry_author), + self->theme->author->str); + + self->buffer_comments = gtk_text_view_get_buffer( + GTK_TEXT_VIEW(self->textview_comments)); + gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self->buffer_comments), + self->theme->comment->str, + -1); + self->backgrounds = irreco_theme_creator_backgrounds_new( + GTK_WINDOW(self), + self->irreco_data, + self->theme); + self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self), + self->irreco_data, + self->theme); + + /* Set window title */ + gtk_window_set_title(GTK_WINDOW(self), _("Theme Editor ")); + + + _set_preview(self); + + gtk_container_add(GTK_CONTAINER(self->hbox_buttons), + self->buttons); + gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds), + self->backgrounds); + + + IRRECO_RETURN +} + +void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self) +{ + IRRECO_ENTER + self->backgrounds = irreco_theme_creator_backgrounds_new( + GTK_WINDOW(self), + self->irreco_data, + NULL); + self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self), + self->irreco_data, NULL); + + + gtk_container_add(GTK_CONTAINER(self->hbox_buttons), + self->buttons); + gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds), + self->backgrounds); + IRRECO_RETURN + +} +/** * Update shown preview image */ static void _set_preview(IrrecoThemeCreatorDlg *self) diff --git a/irreco/src/core/irreco_theme_manager.c b/irreco/src/core/irreco_theme_manager.c index f5161729..0222fa8e 100644 --- a/irreco/src/core/irreco_theme_manager.c +++ b/irreco/src/core/irreco_theme_manager.c @@ -91,22 +91,19 @@ void irreco_theme_manager_free(IrrecoThemeManager *self) void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData * dir_data) { - IrrecoThemeManager *self = (IrrecoThemeManager*) dir_data->user_data_1; - IrrecoTheme *theme; - IrrecoKeyFile *keyfile = NULL; - char *name = NULL; - char *source = NULL; - char *author = NULL; - char *comment = NULL; - char *preview_button = NULL; - char *version = NULL; - GString *conf = g_string_new(dir_data->filepath); + IrrecoTheme *theme = NULL; + IrrecoThemeManager *self = (IrrecoThemeManager*) dir_data->user_data_1; + char *name = NULL; + GString *conf = NULL; + IrrecoKeyFile *keyfile = NULL; IRRECO_ENTER + + conf = g_string_new(dir_data->filepath); g_string_append_printf(conf, "/theme.conf"); keyfile = irreco_keyfile_create(dir_data->filepath, conf->str, - "theme"); + "theme"); if (keyfile == NULL) goto end; /* Required fields. */ @@ -114,36 +111,20 @@ void irreco_theme_manager_read_file_foreach(IrrecoDirForeachData * dir_data) IRRECO_PRINTF("Could not read theme \"%s\"\n", dir_data->filename); goto end; - } - - /* Optional fields. */ - irreco_keyfile_get_str(keyfile, "source", &source); - irreco_keyfile_get_str(keyfile, "author", &author); - irreco_keyfile_get_str(keyfile, "comment", &comment); - irreco_keyfile_get_str(keyfile, "preview-button", &preview_button); - irreco_keyfile_get_str(keyfile, "version", &version); - + } + if (irreco_string_table_get(self->themes, name, (gpointer *) &theme)) { - irreco_theme_set(theme, name, dir_data->filepath, source, - author, comment, preview_button, version); + irreco_theme_read(theme, dir_data->filepath); } else { - theme = irreco_theme_new(name, dir_data->filepath, source, - author, comment, preview_button, version); + theme = irreco_theme_new_from_dir(dir_data->filepath); irreco_string_table_add(self->themes, theme->name->str, theme); } - - irreco_theme_print(theme); - end: g_string_free(conf, TRUE); if (keyfile != NULL) irreco_keyfile_destroy(keyfile); if (name != NULL) g_free(name); - if (source != NULL) g_free(source); - if (author != NULL) g_free(author); - if (comment != NULL) g_free(comment); - if (preview_button != NULL) g_free(preview_button); - if (version != NULL) g_free(version); - + + IRRECO_RETURN } diff --git a/irreco/src/core/irreco_theme_manager_dlg.c b/irreco/src/core/irreco_theme_manager_dlg.c index fda023e8..ecc80164 100644 --- a/irreco/src/core/irreco_theme_manager_dlg.c +++ b/irreco/src/core/irreco_theme_manager_dlg.c @@ -904,14 +904,19 @@ static void irreco_theme_manager_dlg_new_theme(GtkButton *button, /* Check which button */ if (g_str_equal("New", gtk_button_get_label(button))) { + IrrecoTheme *new_theme = NULL; + + new_theme = theme_new(); + irreco_theme_creator_dlg_run(GTK_WINDOW(self), - self->irreco_data, NULL); + self->irreco_data, new_theme); } else { IrrecoTheme *new_theme = NULL; + new_theme = irreco_theme_copy(self->theme); if (irreco_theme_creator_dlg_run(GTK_WINDOW(self), -- 2.11.4.GIT