From 452e9ab753f8fc25f500f2f8fd5d6bed14597c1e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Pekka=20Geh=C3=B6r?= Date: Wed, 17 Dec 2008 15:25:26 +0200 Subject: [PATCH] Clean code --- irreco/src/core/irreco_theme_creator_dlg.c | 276 ++++++++--------------------- irreco/src/core/irreco_theme_creator_dlg.h | 27 +-- 2 files changed, 86 insertions(+), 217 deletions(-) diff --git a/irreco/src/core/irreco_theme_creator_dlg.c b/irreco/src/core/irreco_theme_creator_dlg.c index b4a47461..a0c38393 100644 --- a/irreco/src/core/irreco_theme_creator_dlg.c +++ b/irreco/src/core/irreco_theme_creator_dlg.c @@ -2,17 +2,17 @@ /* * irreco - Ir Remote Control * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com) - * + * * irreco_theme_creator_dlg.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_dlg.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 . */ @@ -34,7 +34,7 @@ * @ingroup Irreco * * - * @{ + * @{ */ /** @@ -100,23 +100,17 @@ 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); -void _set_button_new_details(IrrecoThemeCreatorDlg *self, - IrrecoThemeButton *old_button, - IrrecoThemeButton *button); -void _set_bg_new_details(IrrecoThemeCreatorDlg *self, - IrrecoThemeBg *old_bg, - IrrecoThemeBg *bg); void _set_edited_theme_details(IrrecoThemeCreatorDlg *self); /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Construction & Destruction */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /** - * @name Construction & Destruction - * @{ + * @name Construction & Destruction + * @{ */ G_DEFINE_TYPE(IrrecoThemeCreatorDlg, irreco_theme_creator_dlg, @@ -125,20 +119,20 @@ G_DEFINE_TYPE(IrrecoThemeCreatorDlg, irreco_theme_creator_dlg, static void irreco_theme_creator_dlg_constructed(GObject *object) { /* TODO: Add initialization code here */ - + IrrecoData *irreco_data; IrrecoThemeCreatorDlg *self; /*About widgets*/ GtkWidget *table_about; GtkWidget *label_author; - GtkWidget *label_name; + GtkWidget *label_name; GtkWidget *frame_comments; GtkWidget *scrolled_comments; GtkWidget *preview_button_frame; - + IRRECO_ENTER @@ -151,7 +145,7 @@ static void irreco_theme_creator_dlg_constructed(GObject *object) gtk_window_set_modal(GTK_WINDOW(self), TRUE); gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE); gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE); - + /*Buttons*/ self->cancel_button = gtk_dialog_add_button (GTK_DIALOG(self), _("Cancel"), @@ -216,10 +210,10 @@ static void irreco_theme_creator_dlg_constructed(GObject *object) gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox), self->notebook); - - + + /* Set widgets on the table_about */ - + gtk_table_set_row_spacings(GTK_TABLE(table_about), 6); gtk_table_set_col_spacings(GTK_TABLE(table_about), 6); @@ -264,12 +258,12 @@ static void irreco_theme_creator_dlg_constructed(GObject *object) g_signal_connect(G_OBJECT(self->notebook), "switch-page", G_CALLBACK(irreco_theme_creator_dlg_notebook_changed), self); - + g_signal_connect(G_OBJECT(self->preview_event_box), "button-release-event", G_CALLBACK(irreco_theme_creator_dlg_preview_image), self); - + g_signal_connect(G_OBJECT(self->add_button), "clicked", G_CALLBACK(irreco_theme_creator_dlg_new_bg_button), self); @@ -279,9 +273,9 @@ static void irreco_theme_creator_dlg_constructed(GObject *object) g_signal_connect(G_OBJECT(self->delete_button), "clicked", G_CALLBACK(irreco_theme_creator_dlg_delete_bg_button), self); - + gtk_widget_show_all(GTK_WIDGET(self)); - IRRECO_RETURN + IRRECO_RETURN } @@ -321,7 +315,7 @@ GtkWidget IrrecoThemeCreatorDlg *self; IRRECO_ENTER - self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, + self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, "irreco-data", irreco_data, NULL); /*self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, NULL);*/ @@ -337,7 +331,7 @@ GtkWidget /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /** * @name Private Functions - * @{ + * @{ */ /** @@ -346,11 +340,11 @@ GtkWidget static void _loader_start(IrrecoThemeCreatorDlg *self, GSourceFunc function) { IRRECO_ENTER - + if (self->loader_func_id == 0) { self->loader_func_id = g_idle_add((GSourceFunc)function, self); } - + IRRECO_RETURN } @@ -373,7 +367,7 @@ static gboolean irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self, gint page) { - + IRRECO_ENTER IRRECO_PRINTF("Page_nro %d\n", page); IRRECO_RETURN_BOOL(TRUE); @@ -386,14 +380,14 @@ irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self, void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme) { - + IRRECO_ENTER 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), @@ -409,21 +403,21 @@ void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_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, @@ -479,16 +473,16 @@ void _set_edited_theme_details(IrrecoThemeCreatorDlg *self) GtkTextIter startiter; GtkTextIter enditer; IRRECO_ENTER - + self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW( self->textview_comments)); - + gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(self->buffer_comments), &startiter); gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(self->buffer_comments), - &enditer); - - + &enditer); + + irreco_theme_set(self->theme, gtk_entry_get_text(GTK_ENTRY(self->entry_name)), NULL, @@ -501,7 +495,7 @@ void _set_edited_theme_details(IrrecoThemeCreatorDlg *self) FALSE), self->preview_button->name->str, NULL); - + IRRECO_RETURN } @@ -518,7 +512,7 @@ void _set_edited_theme_details(IrrecoThemeCreatorDlg *self) gboolean irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data, IrrecoTheme *irreco_theme) -{ +{ IrrecoThemeCreatorDlg *self; gint response; gboolean loop = TRUE; @@ -556,16 +550,23 @@ irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data, _loader_start(self, NULL); /* Call set edited_theme_details functio */ _set_edited_theme_details(self); - - rvalue = TRUE; - loop = FALSE; + /* Call ThemeSaveDlg */ + if (irreco_theme_save_dlg_run(self->irreco_data, + irreco_theme, GTK_WINDOW(self))) { + rvalue = TRUE; + loop = FALSE; + + } else { + rvalue = FALSE; + loop = TRUE; + } break; case GTK_RESPONSE_CANCEL: IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n"); _loader_stop(self); - + loop = FALSE; break; @@ -593,7 +594,7 @@ irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook, IRRECO_ENTER switch (page_num){ - + case ABOUT: gtk_widget_show(self->cancel_button); gtk_widget_show(self->save_button); @@ -602,7 +603,7 @@ irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook, gtk_widget_hide(self->delete_button); irreco_theme_creator_dlg_display_theme_detail(self, page_num); - + break; case BUTTONS: gtk_widget_hide(self->cancel_button); @@ -626,7 +627,7 @@ irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook, gtk_widget_show_all(GTK_WIDGET(self->backgrounds)); break; - + default: IRRECO_DEBUG("default\n"); break; @@ -683,7 +684,7 @@ static void irreco_theme_creator_dlg_new_bg_button(GtkButton *button, IRRECO_ENTER if (gtk_notebook_get_current_page(GTK_NOTEBOOK( self->notebook))==BACKGROUNDS) { - + IrrecoThemeBg *new_bg = NULL; new_bg = irreco_theme_bg_new(); @@ -732,7 +733,7 @@ static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button, /* Edit bg */ if (gtk_notebook_get_current_page(GTK_NOTEBOOK( self->notebook)) == BACKGROUNDS) { - + IrrecoThemeBg *bg = NULL; IrrecoThemeBg *new_bg = NULL; IrrecoThemeBg *old_bg = NULL; @@ -742,9 +743,9 @@ static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button, /* check whether the background image of the selected */ if (bg) { new_bg = irreco_theme_bg_copy(bg); - + IRRECO_PRINTF("Pointer: %p \n", (void*) self->theme); - + if (irreco_background_creator_dlg_run(self->irreco_data, self->theme, GTK_WINDOW(self), @@ -752,16 +753,13 @@ static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button, old_bg = irreco_theme_bg_copy(bg); irreco_theme_bg_set(bg, new_bg->image_name->str, new_bg->image_path->str); - /* check whether the bg strings changed */ - _set_bg_new_details(self, old_bg, bg); - + irreco_theme_creator_backgrounds_refresh( IRRECO_THEME_CREATOR_BACKGROUNDS( self->backgrounds)); - } else { - } - + irreco_theme_bg_free(new_bg); + } else { IRRECO_DEBUG("the background is not selected\n"); @@ -771,168 +769,38 @@ static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button, IrrecoThemeButton *button = NULL; IrrecoThemeButton *new_button = NULL; IrrecoThemeButton *old_button = NULL; - + button = irreco_theme_creator_buttons_get_selected_button( IRRECO_THEME_CREATOR_BUTTONS(self->buttons)); /* check whether the button image of the selected */ if (button) { new_button = irreco_theme_button_copy(button); - + if (irreco_button_creator_dlg_run(self->irreco_data, self->theme, GTK_WINDOW(self), new_button)) { old_button = irreco_theme_button_copy(button); irreco_theme_button_print(new_button); - irreco_theme_button_set(button, - new_button->style_name->str, - new_button->name->str, - new_button->allow_text, - new_button->image_up->str, - new_button->image_down->str, - new_button->text_format_up->str, - new_button->text_format_down->str, - new_button->text_padding, - new_button->text_h_align, - new_button->text_v_align); - /* Check Button details and set again */ - _set_button_new_details(self, old_button, button); - - + irreco_theme_button_set_from_button(button, + new_button); + + irreco_theme_button_print(old_button); + irreco_theme_button_print(button); + irreco_theme_creator_buttons_refresh( IRRECO_THEME_CREATOR_BUTTONS( - self->buttons)); - /*irreco_theme_button_free(new_button);*/ - } else { - /*irreco_theme_button_free(new_button);*/ + self->buttons)); + } + + irreco_theme_button_free(new_button); } else { IRRECO_DEBUG("the button is not selected\n"); } } IRRECO_RETURN } -void _set_bg_new_details(IrrecoThemeCreatorDlg *self, - IrrecoThemeBg *old_bg, - IrrecoThemeBg *bg) -{ - - IRRECO_ENTER - if (!(g_str_equal(old_bg->image_name->str, bg->image_name->str))) { - irreco_string_table_change_key(self->theme->backgrounds, - old_bg->image_name->str, - bg->image_name->str); - } else { - IRRECO_DEBUG("BG_NAME is same"); - } - if (!(g_str_equal(old_bg->image_path->str, bg->image_path->str))) { - irreco_string_table_change_key(self->theme->backgrounds, - old_bg->image_path->str, - bg->image_path->str); - } else { - IRRECO_DEBUG("BG_PATH is same"); - } - - IRRECO_RETURN -} -void _set_button_new_details(IrrecoThemeCreatorDlg *self, - IrrecoThemeButton *old_button, - IrrecoThemeButton *button) -{ - - IRRECO_ENTER - if (!(g_str_equal(old_button->style_name->str, - button->style_name->str))) { - irreco_string_table_change_key(self->theme->buttons, - old_button->style_name->str, - button->style_name->str); - } else { - IRRECO_DEBUG("BUTTON_STYLE_NAME is the same\n"); - } - if (!(g_str_equal(old_button->name->str, button->name->str))) { - irreco_string_table_change_key(self->theme->buttons, - old_button->name->str, - button->name->str); - } else { - IRRECO_DEBUG("BUTTON_NAME is the same\n"); - } - if (!(g_str_equal(old_button->image_up->str, button->image_up->str))) { - irreco_string_table_change_key(self->theme->buttons, - old_button->image_up->str, - button->image_up->str); - } else { - IRRECO_DEBUG("String is the same\n"); - } - if (!(g_str_equal(old_button->image_down->str, - button->image_down->str))) { - irreco_string_table_change_key(self->theme->buttons, - old_button->image_down->str, - button->image_down->str); - } else { - IRRECO_DEBUG("String is the same\n"); - } - if (!(g_str_equal(old_button->text_format_up->str, - button->text_format_up->str))) { - irreco_string_table_change_key(self->theme->buttons, - old_button->text_format_up->str, - button->text_format_up->str); - } else { - IRRECO_DEBUG("String is the same\n"); - } - if (!(g_str_equal(old_button->text_format_up->str, - button->text_format_up->str))) { - irreco_string_table_change_key(self->theme->buttons, - old_button->text_format_up->str, - button->text_format_up->str); - } else { - IRRECO_DEBUG("String is the same\n"); - } - if (!(g_str_equal(old_button->text_format_down->str, - button->text_format_down->str))) { - irreco_string_table_change_key(self->theme->buttons, - old_button->text_format_down->str, - button->text_format_down->str); - } else { - IRRECO_DEBUG("String is the same\n"); - } - if (old_button->allow_text == button->allow_text) { - irreco_string_table_change_key(self->theme->buttons, - g_strdup_printf("%d", - old_button->allow_text), - g_strdup_printf("%d", - button->allow_text)); - } else { - IRRECO_DEBUG("Value is the same\n"); - } - if (old_button->text_padding == button->text_padding) { - irreco_string_table_change_key(self->theme->buttons, - g_strdup_printf("%d", - old_button->text_padding), - g_strdup_printf("%d", - button->text_padding)); - } else { - IRRECO_DEBUG("Value is the same\n"); - } - if (old_button->text_h_align == button->text_h_align) { - irreco_string_table_change_key(self->theme->buttons, - g_strdup_printf("%f", - old_button->text_h_align), - g_strdup_printf("%f", - button->text_h_align)); - } else { - IRRECO_DEBUG("Value is the same\n"); - } - if (old_button->text_v_align == button->text_v_align) { - irreco_string_table_change_key(self->theme->buttons, - g_strdup_printf("%f", - old_button->text_v_align), - g_strdup_printf("%f", - button->text_v_align)); - } else { - IRRECO_DEBUG("Value is the same\n"); - } - IRRECO_RETURN -} static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button, IrrecoThemeCreatorDlg *self) @@ -956,11 +824,11 @@ static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button, button = irreco_theme_creator_buttons_get_selected_button( IRRECO_THEME_CREATOR_BUTTONS(self->buttons)); if (irreco_theme_creator_buttons_remove_selected( - IRRECO_THEME_CREATOR_BUTTONS(self->buttons))) { + IRRECO_THEME_CREATOR_BUTTONS(self->buttons))) { irreco_string_table_remove((self->theme)->buttons, - button->name->str); + button->name->str); } - + } IRRECO_RETURN diff --git a/irreco/src/core/irreco_theme_creator_dlg.h b/irreco/src/core/irreco_theme_creator_dlg.h index cc9cb22e..46b37bd5 100644 --- a/irreco/src/core/irreco_theme_creator_dlg.h +++ b/irreco/src/core/irreco_theme_creator_dlg.h @@ -2,24 +2,24 @@ /* * irreco - Ir Remote Control * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com) - * + * * irreco_theme_creator_dlg.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_dlg.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 . */ /** * @addtogroup IrrecoThemeCreatorDlg - * @{ + * @{ */ /** @@ -33,7 +33,7 @@ /* * Make sure that typedefs are available before we include anything elese. * - * This makes sure that whatever other structures that depend on structures + * This makes sure that whatever other structures that depend on structures * defined in this file will compile OK recardles of header inclusion order. */ #ifndef __IRRECO_THEME_CREATOR_DLG_H_TYPEDEF__ @@ -64,7 +64,8 @@ typedef struct _IrrecoThemeCreatorDlg IrrecoThemeCreatorDlg; #include "irreco_button_browser_widget.h" #include "irreco_background_creator_dlg.h" #include "irreco_button_creator_dlg.h" -#include "irreco_theme_creator_backgrounds.h" +#include "irreco_theme_creator_backgrounds.h" +#include "irreco_theme_save_dlg.h" /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ /* Datatypes */ /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ @@ -79,13 +80,13 @@ struct _IrrecoThemeCreatorDlgClass struct _IrrecoThemeCreatorDlg { - + IrrecoInternalDlg parent_instance; GtkWindow *parent_window; IrrecoTheme *theme; IrrecoData *irreco_data; GtkWidget *notebook; - + /*Buttons*/ GtkWidget *cancel_button; GtkWidget *save_button; @@ -96,7 +97,7 @@ struct _IrrecoThemeCreatorDlg GString *filename; IrrecoThemeButton *preview_button; - + GtkWidget *theme_bg; /*ABOUT*/ @@ -107,17 +108,17 @@ struct _IrrecoThemeCreatorDlg GtkTextBuffer *buffer_comments; gchar *preview_name; GtkWidget *preview_event_box; - + /* BUTTONS */ - GtkWidget *buttons; + GtkWidget *buttons; GtkWidget *hbox_buttons; /* BACKGROUNDS */ GtkWidget *backgrounds; GtkWidget *hbox_backgrounds; - + gint loader_state; gint loader_func_id; - + }; -- 2.11.4.GIT