From ea1f5a830b2d8e2e5743c23ab9c34cc01d31b1e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pekka=20Geh=C3=B6r?= Date: Fri, 19 Dec 2008 11:11:08 +0200 Subject: [PATCH] Changed if and while loops to IRRECO_STRING_TABLE_FOREACH_DATA --- irreco/src/core/irreco_theme_creator_backgrounds.c | 57 ++++------- irreco/src/core/irreco_theme_creator_buttons.c | 107 +++++++++------------ 2 files changed, 62 insertions(+), 102 deletions(-) diff --git a/irreco/src/core/irreco_theme_creator_backgrounds.c b/irreco/src/core/irreco_theme_creator_backgrounds.c index d2c0c1fb..b66c8085 100644 --- a/irreco/src/core/irreco_theme_creator_backgrounds.c +++ b/irreco/src/core/irreco_theme_creator_backgrounds.c @@ -317,62 +317,41 @@ irreco_theme_creator_backgrounds_refresh(IrrecoThemeCreatorBackgrounds *self) IrrecoData *irreco_data = NULL; IrrecoThemeManager *manager = NULL; GtkTreeIter iter; - gint theme_bg_count; - const gchar *image_name; IrrecoTheme *theme; - gint i=0; - IRRECO_ENTER + gtk_list_store_clear(self->store_backgrounds); irreco_data = self->irreco_data; manager = irreco_data->theme_manager; theme = self->theme; - IRRECO_DEBUG("Pointer: %p \n", (void*) theme); - IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme); - IRRECO_DEBUG("Pointer: %p \n", (void*) theme->backgrounds); - - theme_bg_count = irreco_string_table_lenght(theme->backgrounds); - if (theme_bg_count > 0) { - while(theme_bg_count > 0) { - IrrecoThemeBg *background_image; - - irreco_string_table_index(theme->backgrounds, i, - &image_name, - (gpointer *) - &background_image); + IRRECO_STRING_TABLE_FOREACH_DATA(theme->backgrounds, + IrrecoThemeBg *, background) - irreco_theme_bg_print(background_image); - pixbuf = gdk_pixbuf_new_from_file_at_scale( - background_image->image_path->str, + irreco_theme_bg_print(background); + pixbuf = gdk_pixbuf_new_from_file_at_scale( + background->image_path->str, IRRECO_BACKGROUNDS_PREVIEW_WIDHT, IRRECO_BACKGROUNDS_PREVIEW_HEIGHT, GDK_INTERP_NEAREST, &error); - if (irreco_gerror_check_print(&error)) { + if (irreco_gerror_check_print(&error)) { IRRECO_RETURN - } - gtk_list_store_append(self->store_backgrounds, - &iter); - gtk_list_store_set(self->store_backgrounds, - &iter, DATA_COL, - background_image, PIXBUF_COL, - pixbuf, TEXT_COL, - background_image->image_name->str, - -1); - - gtk_tree_view_columns_autosize(GTK_TREE_VIEW( - self->view_backgrounds)); - - theme_bg_count -=1; - i++; } + gtk_list_store_append(self->store_backgrounds, + &iter); + gtk_list_store_set(self->store_backgrounds, + &iter, DATA_COL, + background, PIXBUF_COL, + pixbuf, TEXT_COL, + background->image_name->str, + -1); - } else { + gtk_tree_view_columns_autosize(GTK_TREE_VIEW( + self->view_backgrounds)); - } + IRRECO_STRING_TABLE_FOREACH_END - /*if (image_name != NULL) g_free(image_name);*/ if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); IRRECO_RETURN diff --git a/irreco/src/core/irreco_theme_creator_buttons.c b/irreco/src/core/irreco_theme_creator_buttons.c index 7bb0dff7..54def425 100644 --- a/irreco/src/core/irreco_theme_creator_buttons.c +++ b/irreco/src/core/irreco_theme_creator_buttons.c @@ -2,17 +2,17 @@ /* * irreco - Ir Remote Control * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com) - * + * * irreco_theme_creator_buttons.c 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 3 of the License, or * (at your option) any later version. - * + * * irreco_theme_creator_buttons.c 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, see . */ @@ -100,7 +100,7 @@ static void irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons *self) { /* TODO: Add initialization code here */ - + IRRECO_ENTER gtk_box_set_spacing(GTK_BOX(self), 1); @@ -117,7 +117,7 @@ irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons *self) /*BUTTONS COLUMNS*/ gtk_tree_view_set_model(GTK_TREE_VIEW(self->view_buttons), - GTK_TREE_MODEL(self->store_buttons)); + GTK_TREE_MODEL(self->store_buttons)); g_object_unref(self->store_buttons); /* Create pixbuf column. */ @@ -127,7 +127,7 @@ irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons *self) "pixbuf", UNPIXBUF_COL, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(self->view_buttons), self->column_buttons); - + self->renderer_buttons = gtk_cell_renderer_pixbuf_new(); self->column_buttons = gtk_tree_view_column_new_with_attributes( "Pressed ", @@ -157,8 +157,8 @@ irreco_theme_creator_buttons_init (IrrecoThemeCreatorButtons *self) self->tree_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW( self->view_buttons)); gtk_tree_selection_set_mode(self->tree_selection, GTK_SELECTION_SINGLE); - - + + /* Signal handlers. */ g_signal_connect(G_OBJECT(self->tree_selection), "changed", @@ -178,7 +178,7 @@ GtkWidget* irreco_theme_creator_buttons_new(GtkWindow *parent, self = g_object_new(IRRECO_TYPE_THEME_CREATOR_BUTTONS, "irreco-data", irreco_data, NULL); - + irreco_theme_creator_buttons_set_parent_window(self, parent); self->parent_window = GTK_WINDOW(parent); self->irreco_data = irreco_data; @@ -226,76 +226,57 @@ irreco_theme_creator_buttons_refresh(IrrecoThemeCreatorButtons *self) GError *error = NULL; IrrecoData *irreco_data = NULL; IrrecoThemeManager *manager = NULL; - gint i=0; - gint theme_button_count; - const gchar *image_name; IrrecoTheme *theme; GtkTreeIter iter; IRRECO_ENTER - gtk_list_store_clear(self->store_buttons); + gtk_list_store_clear(self->store_buttons); irreco_data = self->irreco_data; manager = irreco_data->theme_manager; theme = self->theme; - theme_button_count = irreco_string_table_lenght(theme->buttons); - - if (theme_button_count > 0) { - while(theme_button_count > 0) { - - IrrecoThemeButton *button_image; - - irreco_string_table_index(theme->buttons, i, - &image_name, - (gpointer *) - &button_image); - /*unpixbuf = gdk_pixbuf_new_from_file( - button_image->image_up->str, - &error);*/ - - unpixbuf = gdk_pixbuf_new_from_file_at_scale( - button_image->image_up->str, - IRRECO_BUTTON_PREVIEW_WIDHT, - IRRECO_BUTTON_PREVIEW_HEIGHT, - GDK_INTERP_NEAREST, &error); - - - if (irreco_gerror_check_print(&error)) { - IRRECO_RETURN - } - /*pixbuf = gdk_pixbuf_new_from_file( - button_image->image_down->str, - &error);*/ - pixbuf = gdk_pixbuf_new_from_file_at_scale( - button_image->image_down->str, + + IRRECO_STRING_TABLE_FOREACH_DATA(theme->buttons, + IrrecoThemeButton *, button) + + irreco_theme_button_print(button); + + + unpixbuf = gdk_pixbuf_new_from_file_at_scale( + button->image_up->str, + IRRECO_BUTTON_PREVIEW_WIDHT, + IRRECO_BUTTON_PREVIEW_HEIGHT, + GDK_INTERP_NEAREST, &error); + + + if (irreco_gerror_check_print(&error)) { + IRRECO_RETURN + } + + pixbuf = gdk_pixbuf_new_from_file_at_scale( + button->image_down->str, IRRECO_BUTTON_PREVIEW_WIDHT, IRRECO_BUTTON_PREVIEW_HEIGHT, GDK_INTERP_NEAREST, &error); - if (irreco_gerror_check_print(&error)) { - IRRECO_RETURN - } + if (irreco_gerror_check_print(&error)) { + IRRECO_RETURN + } - gtk_list_store_append(self->store_buttons, &iter); + gtk_list_store_append(self->store_buttons, &iter); - gtk_list_store_set(self->store_buttons, &iter, - DATA_COL, button_image, - UNPIXBUF_COL, unpixbuf, - PIXBUF_COL, pixbuf, - TEXT_COL, - button_image->name->str, -1); + gtk_list_store_set(self->store_buttons, &iter, + DATA_COL, button, + UNPIXBUF_COL, unpixbuf, + PIXBUF_COL, pixbuf, + TEXT_COL, + button->name->str, -1); + IRRECO_STRING_TABLE_FOREACH_END - theme_button_count -=1; - i++; - } - - } else { - - } if (unpixbuf != NULL) g_object_unref(G_OBJECT(unpixbuf)); if (pixbuf != NULL) g_object_unref(G_OBJECT(pixbuf)); - + IRRECO_RETURN } @@ -309,7 +290,7 @@ static void _image_selection_changed(GtkTreeSelection * selection, gint *path_indices = NULL; IRRECO_ENTER - + /* Get currect selection, if set. */ selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(self->view_buttons)); @@ -324,7 +305,7 @@ static void _image_selection_changed(GtkTreeSelection * selection, DATA_COL, &self->current_button, -1); } - + IRRECO_RETURN } -- 2.11.4.GIT