Clean code and added a few amendments (if()).
[irreco.git] / irreco / src / core / irreco_theme_creator_dlg.c
blob94e5958576fd8c26a319a308e8c96a77c87b675a
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * irreco - Ir Remote Control
4 * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com)
5 *
6 * irreco_theme_creator_dlg.c is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * irreco_theme_creator_dlg.c is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "irreco_theme_creator_dlg.h"
21 #include "irreco_button_browser_dlg.h"
22 #include "irreco_theme_creator_backgrounds.h"
23 #include "irreco_theme_creator_buttons.h"
24 #include "irreco_background_creator_dlg.h"
25 #include "irreco_button_creator_dlg.h"
26 #include <hildon/hildon-banner.h>
27 #include <hildon/hildon-color-button.h>
28 #include <hildon/hildon-file-chooser-dialog.h>
29 #include "irreco_theme_upload_dlg.h"
32 /**
33 * @addtogroup IrrecoThemeCreatorDlg
34 * @ingroup Irreco
37 * @{
40 /**
41 * @file
42 * Source file of @ref IrrecoThemeCreatorDlg.
44 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
45 /* Datatypes */
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 #define IRRECO_BUTTON_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 6)
49 #define IRRECO_BUTTON_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 6)
51 enum
53 DATA_COL,
54 TEXT_COL,
55 PIXBUF_COL,
56 N_COLUMNS
58 /** Notebook table */
59 enum
61 ABOUT,
62 BUTTONS,
63 BACKGROUNDS,
64 N_TABLES
66 /** Loader states. */
67 enum
69 LOADER_STATE_INIT,
70 LOADER_STATE_THEME,
71 LOADER_STATE_BUTTONS,
72 LOADER_STATE_BACKGROUNDS,
73 LOADER_STATE_END
76 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
77 /* Prototypes */
78 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
80 static void _loader_start(IrrecoThemeCreatorDlg *self, GSourceFunc function);
81 static void _loader_stop(IrrecoThemeCreatorDlg *self);
82 static void irreco_theme_creator_dlg_preview_image(GtkWidget *widget,
83 GdkEventButton *event,
84 IrrecoThemeCreatorDlg *self);
86 static void
87 irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook,
88 GtkNotebookPage *page,
89 guint page_num,
90 IrrecoThemeCreatorDlg *self);
92 static gboolean
93 irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self,
94 gint page);
95 static void irreco_theme_creator_dlg_new_bg_button(GtkButton *button,
96 IrrecoThemeCreatorDlg *self);
97 static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button,
98 IrrecoThemeCreatorDlg *self);
99 static void _set_preview(IrrecoThemeCreatorDlg *self);
101 static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button,
102 IrrecoThemeCreatorDlg *self);
104 static void _set_banner(IrrecoThemeCreatorDlg *self,
105 const gchar *text,
106 gdouble fraction);
107 static void _hide_banner(IrrecoThemeCreatorDlg *self);
109 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
110 /* Construction & Destruction */
111 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
114 * @name Construction & Destruction
115 * @{
118 G_DEFINE_TYPE(IrrecoThemeCreatorDlg, irreco_theme_creator_dlg,
119 IRRECO_TYPE_INTERNAL_DLG)
121 static void irreco_theme_creator_dlg_constructed(GObject *object)
123 /* TODO: Add initialization code here */
125 IrrecoData *irreco_data;
126 IrrecoThemeCreatorDlg *self;
127 /*About widgets*/
129 GtkWidget *table_about;
130 GtkWidget *label_author;
131 GtkWidget *label_name;
132 GtkWidget *frame_comments;
133 GtkWidget *scrolled_comments;
135 GtkWidget *preview_button_frame;
139 IRRECO_ENTER
141 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->constructed(object);
142 self = IRRECO_THEME_CREATOR_DLG(object);
143 irreco_data = irreco_internal_dlg_get_irreco_data(IRRECO_INTERNAL_DLG(self));
145 /* Construct dialog. */
146 gtk_window_set_title(GTK_WINDOW(self), _("Theme Creator "));
147 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
148 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
149 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
151 /*Buttons*/
152 self->cancel_button= gtk_dialog_add_button (GTK_DIALOG(self),
153 _("Cancel"),
154 GTK_RESPONSE_CANCEL);
155 self->save_button= gtk_dialog_add_button (GTK_DIALOG(self),
156 _("Save"),
157 GTK_RESPONSE_OK);
158 self->add_button= gtk_dialog_add_button (GTK_DIALOG(self),
159 _("Add"), GTK_RESPONSE_NONE);
160 self->edit_button= gtk_dialog_add_button (GTK_DIALOG(self),
161 _("Edit"),
162 GTK_RESPONSE_NONE);
163 self->delete_button= gtk_dialog_add_button (GTK_DIALOG(self),
164 _("Delete"),
165 GTK_RESPONSE_NONE);
168 /* Create widgets. */
169 self->notebook = gtk_notebook_new();
171 /* ABOUT*/
173 table_about = gtk_table_new(7, 9, TRUE);
174 label_author = gtk_label_new(_("Author:"));
175 label_name = gtk_label_new(_("Name: "));
176 self->entry_author = gtk_entry_new();
177 self->entry_name = gtk_entry_new();
178 frame_comments = gtk_frame_new("");
179 scrolled_comments = gtk_scrolled_window_new(NULL, NULL);
180 self->textview_comments = gtk_text_view_new();
181 preview_button_frame = gtk_frame_new("");
182 self->preview_event_box = gtk_event_box_new();
183 self->preview_image = gtk_image_new();
184 gtk_image_set_from_file(GTK_IMAGE(self->preview_image), NULL);
185 self->hbox_backgrounds = gtk_hbox_new(FALSE, 2);
186 self->hbox_buttons = gtk_hbox_new(FALSE, 2);
189 /* Set frame text bold */
190 gtk_frame_set_label_widget(GTK_FRAME(frame_comments),
191 irreco_gtk_label_bold(
192 "Comments", 0, 0, 0, 0, 0, 0));
193 gtk_frame_set_label_widget(GTK_FRAME(preview_button_frame),
194 irreco_gtk_label_bold(
195 "Preview button", 0, 0, 0, 0, 0, 0));
198 self->backgrounds = irreco_theme_creator_backgrounds_new(
199 GTK_WINDOW(self),
200 irreco_data,
201 NULL);
203 /* Create Notebook tabs. */
205 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
206 irreco_gtk_align(GTK_WIDGET(table_about),
207 0, 0, 1, 1, 8, 8, 8, 8),
208 gtk_label_new("About"));
209 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
210 irreco_gtk_align(GTK_WIDGET(self->hbox_buttons),
211 0, 0, 1, 1, 8, 8, 8, 8),
212 gtk_label_new("Buttons"));
213 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
214 irreco_gtk_align(GTK_WIDGET(
215 self->hbox_backgrounds),
216 0, 0, 1, 1, 8, 8, 8, 8),
217 gtk_label_new("Backgrounds"));
220 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox),
221 self->notebook);
224 /* Set widgets on the table_about */
226 gtk_table_set_row_spacings(GTK_TABLE(table_about), 6);
227 gtk_table_set_col_spacings(GTK_TABLE(table_about), 6);
229 gtk_table_attach_defaults(GTK_TABLE(table_about),
230 label_author, 0, 2, 0, 1);
231 gtk_table_attach_defaults(GTK_TABLE(table_about),
232 label_name, 0, 2, 1, 2);
233 gtk_table_attach_defaults(GTK_TABLE(table_about),
234 self->entry_author, 2, 9, 0, 1);
235 gtk_table_attach_defaults(GTK_TABLE(table_about),
236 self->entry_name, 2, 9, 1, 2);
237 gtk_table_attach_defaults(GTK_TABLE(table_about),
238 frame_comments, 0, 6, 2, 7);
239 gtk_table_attach_defaults(GTK_TABLE(table_about),
240 preview_button_frame, 6, 9, 2, 7);
243 /*ABOUT*/
244 /* set preview image*/
247 gtk_container_add(GTK_CONTAINER(preview_button_frame),
248 self->preview_event_box);
249 gtk_container_add(GTK_CONTAINER(self->preview_event_box),
250 self->preview_image);
252 /* textview */
254 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self->textview_comments),
255 GTK_WRAP_WORD_CHAR);
257 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_comments),
258 GTK_POLICY_NEVER,
259 GTK_POLICY_AUTOMATIC);
261 gtk_container_add(GTK_CONTAINER(frame_comments), scrolled_comments);
262 gtk_container_add(GTK_CONTAINER(scrolled_comments),
263 self->textview_comments);
265 /* Signal handlers. */
267 g_signal_connect(G_OBJECT(self->notebook), "switch-page",
268 G_CALLBACK(irreco_theme_creator_dlg_notebook_changed),
269 self);
271 g_signal_connect(G_OBJECT(self->preview_event_box),
272 "button-release-event",
273 G_CALLBACK(irreco_theme_creator_dlg_preview_image),
274 self);
276 g_signal_connect(G_OBJECT(self->add_button), "clicked",
277 G_CALLBACK(irreco_theme_creator_dlg_new_bg_button),
278 self);
279 g_signal_connect(G_OBJECT(self->edit_button), "clicked",
280 G_CALLBACK(irreco_theme_creator_dlg_edit_bg_button),
281 self);
282 g_signal_connect(G_OBJECT(self->delete_button), "clicked",
283 G_CALLBACK(irreco_theme_creator_dlg_delete_bg_button),
284 self);
286 gtk_widget_show_all(GTK_WIDGET(self));
288 IRRECO_RETURN
292 static void irreco_theme_creator_dlg_init(IrrecoThemeCreatorDlg *self)
294 IRRECO_ENTER
295 IRRECO_RETURN
298 static void irreco_theme_creator_dlg_finalize(GObject *object)
300 IrrecoThemeCreatorDlg *self;
301 IRRECO_ENTER
303 self = IRRECO_THEME_CREATOR_DLG(object);
305 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->finalize(object);
306 IRRECO_RETURN
311 static void
312 irreco_theme_creator_dlg_class_init(IrrecoThemeCreatorDlgClass *klass)
314 GObjectClass* object_class = G_OBJECT_CLASS (klass);
316 object_class->finalize = irreco_theme_creator_dlg_finalize;
317 object_class->constructed = irreco_theme_creator_dlg_constructed;
322 GtkWidget
323 *irreco_theme_creator_dlg_new(IrrecoData *irreco_data, GtkWindow *parent)
325 IrrecoThemeCreatorDlg *self;
327 IRRECO_ENTER
328 self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG,
329 "irreco-data", irreco_data,
330 NULL);
331 /*self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, NULL);*/
332 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
334 IRRECO_RETURN_PTR(self);
337 /** @} */
339 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
340 /* Private Functions */
341 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
343 * @name Private Functions
344 * @{
347 /*static void _set_banner(IrrecoThemeCreatorDlg *self,
348 const gchar *text,
349 gdouble fraction)
351 IRRECO_ENTER
353 if (self->banner == NULL) {
354 self->banner = hildon_banner_show_progress(
355 GTK_WIDGET(self), NULL, "");
358 hildon_banner_set_text(HILDON_BANNER(self->banner), text);
359 hildon_banner_set_fraction(HILDON_BANNER(self->banner), fraction);
361 IRRECO_RETURN
365 * Destroy banner, if it exists.
367 /*static void _hide_banner(IrrecoThemeCreatorDlg *self)
369 IRRECO_ENTER
371 if (self->banner) {
372 gtk_widget_destroy(self->banner);
373 self->banner = NULL;
376 IRRECO_RETURN
379 * Start a loader state machine if one is not running already.
381 static void _loader_start(IrrecoThemeCreatorDlg *self, GSourceFunc function)
383 IRRECO_ENTER
385 if (self->loader_func_id == 0) {
386 self->loader_func_id = g_idle_add((GSourceFunc)function, self);
389 IRRECO_RETURN
393 * Stop and cleanup loader if a loader is running.
395 static void _loader_stop(IrrecoThemeCreatorDlg *self)
397 IRRECO_ENTER
398 /*_hide_banner(self);*/
399 if (self->loader_func_id != 0) {
400 g_source_remove(self->loader_func_id);
401 self->loader_func_id = 0;
402 self->loader_state = 0;
404 IRRECO_RETURN
407 static gboolean
408 irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self,
409 gint page)
412 IRRECO_ENTER
414 IRRECO_PRINTF("Page_nro %d\n", page);
417 IRRECO_RETURN_BOOL(TRUE);
420 /** @} */
422 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
423 /* Functions */
424 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
427 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
428 /* Public Functions */
429 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
431 gboolean
432 irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data,
433 IrrecoTheme *irreco_theme)
435 IrrecoThemeCreatorDlg *self;
436 gint response;
437 gboolean loop = TRUE;
438 gboolean rvalue = FALSE;
440 GtkTextIter startiter;
441 GtkTextIter enditer;
444 IRRECO_ENTER
446 self = (IrrecoThemeCreatorDlg*)irreco_theme_creator_dlg_new(irreco_data,
447 parent_window);
448 self->parent_window = GTK_WINDOW(self);
449 self->loader_func_id = 0;
450 self->irreco_data = irreco_data;
451 self->preview_name = NULL;
453 /* Sets the theme details */
454 if(irreco_theme != NULL) {
456 self->theme = irreco_theme;
457 gtk_entry_set_text(GTK_ENTRY(self->entry_name),
458 self->theme->name->str);
459 gtk_entry_set_text(GTK_ENTRY(self->entry_author),
460 self->theme->author->str);
462 self->buffer_comments = gtk_text_view_get_buffer(
463 GTK_TEXT_VIEW(self->textview_comments));
464 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self->buffer_comments),
465 self->theme->comment->str,
466 -1);
467 self->backgrounds = irreco_theme_creator_backgrounds_new(
468 GTK_WINDOW(self),
469 self->irreco_data,
470 self->theme);
471 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
472 self->irreco_data, self->theme);
474 /* Set window title */
475 gtk_window_set_title(GTK_WINDOW(self), _("Theme Editor "));
478 _set_preview(self);
480 } else {
481 self->backgrounds = irreco_theme_creator_backgrounds_new(
482 GTK_WINDOW(self),
483 self->irreco_data,
484 NULL);
485 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
486 self->irreco_data, NULL);
490 gtk_container_add(GTK_CONTAINER(self->hbox_buttons),
491 self->buttons);
492 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
493 self->backgrounds);
495 do {
496 response = gtk_dialog_run(GTK_DIALOG(self));
497 switch (response) {
498 case GTK_RESPONSE_OK:
500 self->loader_state = LOADER_STATE_INIT;
501 _loader_start(self, NULL);
503 irreco_theme_set_author(self->theme, gtk_entry_get_text(
504 GTK_ENTRY(self->entry_author)));
506 irreco_theme_set_preview_button(self->theme,
507 self->preview_button->name->str);
510 /* Set new comments */
511 self->buffer_comments = gtk_text_view_get_buffer(
512 GTK_TEXT_VIEW(self->textview_comments));
514 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(
515 self->buffer_comments),
516 &startiter);
517 gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(
518 self->buffer_comments),
519 &enditer);
520 irreco_theme_set_comment(self->theme,
521 gtk_text_buffer_get_text(
522 GTK_TEXT_BUFFER(
523 self->buffer_comments),
524 &startiter,
525 &enditer,
526 FALSE));
528 irreco_theme_update_keyfile(self->theme);
530 irreco_theme = irreco_theme_copy(self->theme);
532 rvalue = TRUE;
533 loop = FALSE;
535 break;
537 case GTK_RESPONSE_CANCEL:
538 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
539 _loader_stop(self);
541 loop = FALSE;
542 break;
544 default:
545 IRRECO_DEBUG("default\n");
546 break;
549 } while (loop);
551 gtk_widget_destroy(GTK_WIDGET(self));
553 IRRECO_RETURN_BOOL(rvalue);
557 * Update shown preview image
559 static void _set_preview(IrrecoThemeCreatorDlg *self)
561 IRRECO_ENTER
563 /* if theme contains preview image, use it, else get first button */
564 if(self->preview_name) {
565 IRRECO_DEBUG("Preview set in dlg, using it\n");
566 } else if(strlen(self->theme->preview_button_name->str) != 0) {
567 gchar *strtblkey;
568 IRRECO_DEBUG("Preview set to theme, using it\n");
569 strtblkey = g_strdup_printf("%s/%s", self->theme->name->str,
570 self->theme->preview_button_name->str);
571 /*IRRECO_DEBUG("key: %s\n", strtblkey);*/
572 if(irreco_string_table_get(self->theme->buttons, strtblkey,
573 (gpointer *) &self->preview_button)) {
574 self->preview_name = self->preview_button->image_up->str;
575 } else {
576 IRRECO_DEBUG("Theme preview set wrong\n");
578 } else {
579 const gchar *key;
580 IRRECO_DEBUG("No preview set, using first button of theme\n");
581 irreco_string_table_index(self->theme->buttons, 0, &key,
582 (gpointer *) &self->preview_button);
583 if(self->preview_button) {
584 self->preview_name = self->preview_button->image_up->str;
588 gtk_image_set_from_file(GTK_IMAGE(self->preview_image),
589 self->preview_name);
591 gtk_widget_show_all(GTK_WIDGET(self));
593 IRRECO_RETURN
596 static void
597 irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook,
598 GtkNotebookPage *page,
599 guint page_num,
600 IrrecoThemeCreatorDlg *self)
603 IRRECO_ENTER
605 switch (page_num){
607 case ABOUT:
608 gtk_widget_show(self->cancel_button);
609 gtk_widget_show(self->save_button);
610 gtk_widget_hide(self->add_button);
611 gtk_widget_hide(self->edit_button);
612 gtk_widget_hide(self->delete_button);
614 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
616 break;
617 case BUTTONS:
618 gtk_widget_hide(self->cancel_button);
619 gtk_widget_hide(self->save_button);
620 gtk_widget_show(self->add_button);
621 gtk_widget_show(self->edit_button);
622 gtk_widget_show(self->delete_button);
624 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
625 gtk_widget_show_all(GTK_WIDGET(self->buttons));
627 break;
628 case BACKGROUNDS:
629 gtk_widget_hide(self->cancel_button);
630 gtk_widget_hide(self->save_button);
631 gtk_widget_show(self->add_button);
632 gtk_widget_show(self->edit_button);
633 gtk_widget_show(self->delete_button);
635 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
636 gtk_widget_show_all(GTK_WIDGET(self->backgrounds));
638 break;
640 default:
641 IRRECO_DEBUG("default\n");
642 break;
644 IRRECO_RETURN
648 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
649 /* Events and Callbacks */
650 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
653 * @name Events and Callbacks
654 * @{
657 static void irreco_theme_creator_dlg_preview_image(GtkWidget *widget,
658 GdkEventButton *event,
659 IrrecoThemeCreatorDlg *self)
662 IrrecoThemeButton *preview_theme_button = NULL;
664 IRRECO_ENTER
665 if (self->theme != NULL) {
666 preview_theme_button = irreco_button_browser_dlg_run(
667 GTK_WINDOW(self),
668 self->irreco_data,
669 self->theme);
671 if(preview_theme_button) {
672 IRRECO_DEBUG("Set preview button to theme and self->\n");
674 self->preview_name = preview_theme_button->image_up->str;
675 IRRECO_PRINTF("BUTTON:%s\n", self->preview_name);
678 self->preview_button = preview_theme_button;
679 _set_preview(self);
682 IRRECO_RETURN
685 /** @} */
689 *Create new background or button
692 static void irreco_theme_creator_dlg_new_bg_button(GtkButton *button,
693 IrrecoThemeCreatorDlg *self)
696 IRRECO_ENTER
697 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
698 self->notebook))==BACKGROUNDS) {
700 irreco_background_creator_dlg_run(self->irreco_data, NULL,
701 GTK_WINDOW(self), NULL);
703 } else {
705 irreco_button_creator_dlg_run(self->irreco_data, NULL,
706 GTK_WINDOW(self), NULL);
709 IRRECO_RETURN
713 *Create edit background or button
716 static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button,
717 IrrecoThemeCreatorDlg *self)
722 IRRECO_ENTER
723 /* Check which page */
724 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
725 self->notebook)) == BACKGROUNDS) {
727 IrrecoThemeBg *bg = NULL;
728 IrrecoThemeBg *new_bg = NULL;
730 bg = irreco_theme_creator_backgrounds_get_selected_bg(
731 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
733 /* check whether the background image of the selected */
734 if (bg) {
735 new_bg = irreco_theme_bg_copy(bg);
737 if (irreco_background_creator_dlg_run(self->irreco_data,
738 &self->theme,
739 GTK_WINDOW(self),
740 &new_bg)) {
741 irreco_theme_bg_set(bg, new_bg->image_name->str, new_bg->image_path->str);
742 irreco_theme_bg_free(new_bg);
744 irreco_theme_creator_backgrounds_refresh_list(
745 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
748 } else {
749 irreco_theme_bg_free(new_bg);
752 } else
754 IRRECO_DEBUG("the background is not selected\n");
760 } else {
761 IrrecoThemeButton *button = NULL;
762 IrrecoThemeButton *new_button = NULL;
764 button = irreco_theme_creator_buttons_get_selected_button(
765 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
767 /* check whether the button image of the selected */
768 if (button) {
769 new_button = irreco_theme_button_copy(button);
771 new_button = irreco_button_creator_dlg_run(self->irreco_data,
772 self->theme,
773 GTK_WINDOW(self),
774 new_button);
776 } else {
778 IRRECO_DEBUG("the button is not selected\n");
784 IRRECO_RETURN
788 static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button,
789 IrrecoThemeCreatorDlg *self)
792 IRRECO_ENTER
795 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
796 self->notebook)) == BACKGROUNDS) {
798 irreco_theme_creator_backgrounds_remove_selected(
799 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
802 } else {
803 irreco_theme_creator_buttons_remove_selected(
804 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
809 IRRECO_RETURN