Clean code
[irreco.git] / irreco / src / core / irreco_theme_creator_dlg.c
blobf8ae906e1ba6f61bf395922638a69f73a0971f49
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)
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 void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme);
105 void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self);
106 void _set_edited_theme_details(IrrecoThemeCreatorDlg *self);
107 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
108 /* Construction & Destruction */
109 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
112 * @name Construction & Destruction
113 * @{
116 G_DEFINE_TYPE(IrrecoThemeCreatorDlg, irreco_theme_creator_dlg,
117 IRRECO_TYPE_INTERNAL_DLG)
119 static void irreco_theme_creator_dlg_constructed(GObject *object)
121 /* TODO: Add initialization code here */
123 IrrecoData *irreco_data;
124 IrrecoThemeCreatorDlg *self;
125 /*About widgets*/
126 GtkWidget *scrolled_table;
127 GtkWidget *table_about;
128 GtkWidget *label_author;
129 GtkWidget *label_name;
130 GtkWidget *frame_comments;
131 GtkWidget *scrolled_comments;
133 GtkWidget *preview_button_frame;
137 IRRECO_ENTER
139 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->constructed(object);
140 self = IRRECO_THEME_CREATOR_DLG(object);
141 irreco_data = irreco_internal_dlg_get_irreco_data(IRRECO_INTERNAL_DLG(self));
143 /* Construct dialog. */
144 gtk_window_set_title(GTK_WINDOW(self), _("Theme Creator "));
145 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
146 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
147 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
149 /*Buttons*/
150 self->cancel_button = gtk_dialog_add_button (GTK_DIALOG(self),
151 _("Cancel"),
152 GTK_RESPONSE_CANCEL);
153 self->save_button = gtk_dialog_add_button (GTK_DIALOG(self),
154 _("Save"),
155 GTK_RESPONSE_OK);
156 self->add_button = gtk_dialog_add_button (GTK_DIALOG(self),
157 _("Add"), GTK_RESPONSE_NONE);
158 self->edit_button = gtk_dialog_add_button (GTK_DIALOG(self),
159 _("Edit"),
160 GTK_RESPONSE_NONE);
161 self->delete_button = gtk_dialog_add_button (GTK_DIALOG(self),
162 _("Delete"),
163 GTK_RESPONSE_NONE);
165 /* Create widgets. */
166 self->notebook = gtk_notebook_new();
168 /* ABOUT*/
170 scrolled_table = gtk_scrolled_window_new(NULL, NULL);
171 table_about = gtk_table_new(7, 9, TRUE);
172 label_author = gtk_label_new(_("Author:"));
173 label_name = gtk_label_new(_("Name: "));
174 self->entry_author = gtk_entry_new();
175 self->entry_name = gtk_entry_new();
176 frame_comments = gtk_frame_new("");
177 scrolled_comments = gtk_scrolled_window_new(NULL, NULL);
178 self->textview_comments = gtk_text_view_new();
179 preview_button_frame = gtk_frame_new("");
180 self->preview_event_box = gtk_event_box_new();
181 self->preview_image = gtk_image_new();
182 gtk_image_set_from_file(GTK_IMAGE(self->preview_image), NULL);
183 self->hbox_backgrounds = gtk_hbox_new(FALSE, 2);
184 self->hbox_buttons = gtk_hbox_new(FALSE, 2);
186 /* equal to the text of the left-side */
187 gtk_misc_set_alignment(GTK_MISC(label_name), 0, 0.5);
188 gtk_misc_set_alignment(GTK_MISC(label_author), 0, 0.5);
191 /* Set frame text bold */
192 gtk_frame_set_label_widget(GTK_FRAME(frame_comments),
193 irreco_gtk_label_bold(
194 "Comments", 0, 0, 0, 0, 0, 0));
195 gtk_frame_set_label_widget(GTK_FRAME(preview_button_frame),
196 irreco_gtk_label_bold(
197 "Preview button", 0, 0, 0, 0, 0, 0));
199 /* Set table on the scrolled */
200 gtk_container_add(GTK_CONTAINER(scrolled_table),
201 table_about);
202 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_table),
203 GTK_POLICY_AUTOMATIC,
204 GTK_POLICY_AUTOMATIC);
206 /* Create Notebook tabs. */
208 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
209 irreco_gtk_align(GTK_WIDGET(scrolled_table),
210 0, 0, 1, 1, 8, 8, 8, 8),
211 gtk_label_new("About"));
212 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
213 irreco_gtk_align(GTK_WIDGET(self->hbox_buttons),
214 0, 0, 1, 1, 8, 8, 8, 8),
215 gtk_label_new("Buttons"));
216 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
217 irreco_gtk_align(GTK_WIDGET(
218 self->hbox_backgrounds),
219 0, 0, 1, 1, 8, 8, 8, 8),
220 gtk_label_new("Backgrounds"));
223 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox),
224 self->notebook);
227 /* Set widgets on the table_about */
229 gtk_table_set_row_spacings(GTK_TABLE(table_about), 6);
230 gtk_table_set_col_spacings(GTK_TABLE(table_about), 6);
232 gtk_table_attach_defaults(GTK_TABLE(table_about),
233 label_author, 0, 2, 0, 1);
234 gtk_table_attach_defaults(GTK_TABLE(table_about),
235 label_name, 0, 2, 1, 2);
236 gtk_table_attach_defaults(GTK_TABLE(table_about),
237 self->entry_author, 2, 9, 0, 1);
238 gtk_table_attach_defaults(GTK_TABLE(table_about),
239 self->entry_name, 2, 9, 1, 2);
240 gtk_table_attach_defaults(GTK_TABLE(table_about),
241 frame_comments, 0, 6, 2, 7);
242 gtk_table_attach_defaults(GTK_TABLE(table_about),
243 preview_button_frame, 6, 9, 2, 7);
246 /*ABOUT*/
247 /* set preview image*/
250 gtk_container_add(GTK_CONTAINER(preview_button_frame),
251 self->preview_event_box);
252 gtk_container_add(GTK_CONTAINER(self->preview_event_box),
253 self->preview_image);
255 /* textview */
257 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self->textview_comments),
258 GTK_WRAP_WORD_CHAR);
260 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_comments),
261 GTK_POLICY_NEVER,
262 GTK_POLICY_AUTOMATIC);
264 gtk_container_add(GTK_CONTAINER(frame_comments), scrolled_comments);
265 gtk_container_add(GTK_CONTAINER(scrolled_comments),
266 self->textview_comments);
268 /* Signal handlers. */
270 g_signal_connect(G_OBJECT(self->notebook), "switch-page",
271 G_CALLBACK(irreco_theme_creator_dlg_notebook_changed),
272 self);
274 g_signal_connect(G_OBJECT(self->preview_event_box),
275 "button-release-event",
276 G_CALLBACK(irreco_theme_creator_dlg_preview_image),
277 self);
279 g_signal_connect(G_OBJECT(self->add_button), "clicked",
280 G_CALLBACK(irreco_theme_creator_dlg_new_bg_button),
281 self);
282 g_signal_connect(G_OBJECT(self->edit_button), "clicked",
283 G_CALLBACK(irreco_theme_creator_dlg_edit_bg_button),
284 self);
285 g_signal_connect(G_OBJECT(self->delete_button), "clicked",
286 G_CALLBACK(irreco_theme_creator_dlg_delete_bg_button),
287 self);
290 gtk_widget_set_size_request(GTK_WIDGET(table_about), 696, 396);
293 gtk_widget_show_all(GTK_WIDGET(self));
294 IRRECO_RETURN
297 static void irreco_theme_creator_dlg_init(IrrecoThemeCreatorDlg *self)
299 IRRECO_ENTER
300 IRRECO_RETURN
303 static void irreco_theme_creator_dlg_finalize(GObject *object)
305 IrrecoThemeCreatorDlg *self;
306 IRRECO_ENTER
308 self = IRRECO_THEME_CREATOR_DLG(object);
310 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->finalize(object);
311 IRRECO_RETURN
314 static void
315 irreco_theme_creator_dlg_class_init(IrrecoThemeCreatorDlgClass *klass)
317 GObjectClass* object_class = G_OBJECT_CLASS (klass);
319 object_class->finalize = irreco_theme_creator_dlg_finalize;
320 object_class->constructed = irreco_theme_creator_dlg_constructed;
324 GtkWidget
325 *irreco_theme_creator_dlg_new(IrrecoData *irreco_data, GtkWindow *parent)
327 IrrecoThemeCreatorDlg *self;
329 IRRECO_ENTER
330 self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG,
331 "irreco-data", irreco_data,
332 NULL);
333 /*self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, NULL);*/
334 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
336 IRRECO_RETURN_PTR(self);
339 /** @} */
341 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
342 /* Private Functions */
343 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
345 * @name Private Functions
346 * @{
350 * Start a loader state machine if one is not running already.
352 static void _loader_start(IrrecoThemeCreatorDlg *self, GSourceFunc function)
354 IRRECO_ENTER
356 if (self->loader_func_id == 0) {
357 self->loader_func_id = g_idle_add((GSourceFunc)function, self);
360 IRRECO_RETURN
364 * Stop and cleanup loader if a loader is running.
366 static void _loader_stop(IrrecoThemeCreatorDlg *self)
368 IRRECO_ENTER
369 /*_hide_banner(self);*/
370 if (self->loader_func_id != 0) {
371 g_source_remove(self->loader_func_id);
372 self->loader_func_id = 0;
373 self->loader_state = 0;
375 IRRECO_RETURN
378 static gboolean
379 irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self,
380 gint page)
383 IRRECO_ENTER
384 IRRECO_PRINTF("Page_nro %d\n", page);
385 IRRECO_RETURN_BOOL(TRUE);
390 * Sets the theme details
393 void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme)
396 IRRECO_ENTER
398 gtk_entry_set_text(GTK_ENTRY(self->entry_name),
399 self->theme->name->str);
400 gtk_entry_set_text(GTK_ENTRY(self->entry_author),
401 self->theme->author->str);
403 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
404 self->textview_comments));
405 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self->buffer_comments),
406 self->theme->comment->str,
407 -1);
408 self->backgrounds = irreco_theme_creator_backgrounds_new(
409 GTK_WINDOW(self),
410 self->irreco_data,
411 self->theme);
412 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
413 self->irreco_data,
414 self->theme);
415 /* Set window title */
416 gtk_window_set_title(GTK_WINDOW(self), _("Theme Editor "));
419 _set_preview(self);
421 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
422 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
423 self->backgrounds);
426 IRRECO_RETURN
429 void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self)
431 IRRECO_ENTER
433 self->backgrounds = irreco_theme_creator_backgrounds_new(
434 GTK_WINDOW(self),
435 self->irreco_data,
436 self->theme);
437 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
438 self->irreco_data,
439 self->theme);
441 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
442 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
443 self->backgrounds);
444 IRRECO_RETURN
448 * Update shown preview image
450 static void _set_preview(IrrecoThemeCreatorDlg *self)
452 IRRECO_ENTER
454 /* if theme contains preview image, use it, else get first button */
455 if(self->preview_name) {
456 IRRECO_DEBUG("Preview set in dlg, using it\n");
457 } else if(strlen(self->theme->preview_button_name->str) != 0) {
458 gchar *strtblkey;
459 IRRECO_DEBUG("Preview set to theme, using it\n");
460 strtblkey = g_strdup_printf("%s/%s", self->theme->name->str,
461 self->theme->preview_button_name->str);
462 IRRECO_DEBUG("STRTBKEY: %s\n", strtblkey);
463 if(irreco_string_table_get(self->theme->buttons, strtblkey,
464 (gpointer *) &self->preview_button)) {
465 self->preview_name = self->preview_button->image_up->str;
466 } else {
467 IRRECO_DEBUG("Theme preview set wrong\n");
469 } else {
470 const gchar *key;
471 IRRECO_DEBUG("No preview set, using first button of theme\n");
472 irreco_string_table_index(self->theme->buttons, 0, &key,
473 (gpointer *) &self->preview_button);
474 if(self->preview_button) {
475 self->preview_name = self->preview_button->image_up->str;
478 gtk_image_set_from_file(GTK_IMAGE(self->preview_image),
479 self->preview_name);
480 IRRECO_RETURN
483 void _set_edited_theme_details(IrrecoThemeCreatorDlg *self)
485 GtkTextIter startiter;
486 GtkTextIter enditer;
487 const gchar *name = NULL;
488 const gchar *author = NULL;
489 gchar *comment = NULL;
491 IRRECO_ENTER
493 name = gtk_entry_get_text(GTK_ENTRY(self->entry_name));
494 author = gtk_entry_get_text(GTK_ENTRY(self->entry_author));
497 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
498 self->textview_comments));
500 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(self->buffer_comments),
501 &startiter);
502 gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(self->buffer_comments),
503 &enditer);
504 comment = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(
505 self->buffer_comments),
506 &startiter,
507 &enditer,
508 FALSE);
509 /* Check whether preview button set */
510 if (!self->preview_name) {
511 _set_preview(self);
513 irreco_theme_set(self->theme,
514 name,
515 NULL,
516 "user",
517 author,
518 comment,
519 self->preview_name,
520 NULL);
523 IRRECO_RETURN
526 gboolean
527 irreco_theme_creator_dlg_check_details(IrrecoThemeCreatorDlg *self)
530 gboolean rvalue = TRUE;
531 IRRECO_ENTER
532 /* check that there is at least one button */
533 if (!irreco_string_table_lenght(self->theme->buttons)) {
534 irreco_error_dlg(GTK_WINDOW(self),
535 "must be at least one button");
536 rvalue = FALSE;
537 } else if (strlen(gtk_entry_get_text(GTK_ENTRY(self->entry_name))) == 0) {
538 irreco_error_dlg(GTK_WINDOW(self),
539 "Name is missing");
540 rvalue = FALSE;
541 } else if (strlen(gtk_entry_get_text(GTK_ENTRY(self->entry_author))) == 0) {
542 irreco_error_dlg(GTK_WINDOW(self),
543 "Author is missing");
544 rvalue = FALSE;
547 IRRECO_RETURN_BOOL(rvalue);
549 /** @} */
551 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
552 /* Functions */
553 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
556 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
557 /* Public Functions */
558 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
559 gboolean
560 irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data,
561 IrrecoTheme *irreco_theme)
563 IrrecoThemeCreatorDlg *self;
564 gint response;
565 gboolean loop = TRUE;
566 gboolean rvalue = FALSE;
567 /*GtkTextIter startiter;
568 GtkTextIter enditer;*/
569 IRRECO_ENTER
571 self = (IrrecoThemeCreatorDlg*)irreco_theme_creator_dlg_new(irreco_data,
572 parent_window);
573 self->parent_window = GTK_WINDOW(self);
574 self->loader_func_id = 0;
575 self->irreco_data = irreco_data;
576 self->preview_name = NULL;
577 irreco_theme_print(irreco_theme);
578 self->theme = irreco_theme;
579 IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme);
580 IRRECO_DEBUG("Pointer: %p \n", (void*) irreco_theme);
582 /* Check whether the theme of a blank*/
583 if (irreco_string_table_lenght(irreco_theme->buttons) != 0) {
584 /* Sets the theme details */
585 _set_theme_details(self, irreco_theme);
586 } else {
587 /* create blank bg:s and buttons widgets */
588 _create_bg_and_button_widgets(self);
591 do {
592 response = gtk_dialog_run(GTK_DIALOG(self));
593 switch (response) {
594 case GTK_RESPONSE_OK:
596 self->loader_state = LOADER_STATE_INIT;
597 _loader_start(self, NULL);
598 /* Check theme details */
599 if (irreco_theme_creator_dlg_check_details(self)) {
600 /* Call set edited_theme_details functio */
601 _set_edited_theme_details(self);
603 /* Call ThemeSaveDlg */
604 if (irreco_theme_save_dlg_run(self->irreco_data,
605 irreco_theme, GTK_WINDOW(self))) {
606 rvalue = TRUE;
607 loop = FALSE;
608 } else {
609 rvalue = FALSE;
610 loop = TRUE;
612 } else {
613 rvalue = FALSE;
614 loop = TRUE;
616 break;
618 case GTK_RESPONSE_CANCEL:
619 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
620 _loader_stop(self);
622 loop = FALSE;
623 break;
625 default:
626 IRRECO_DEBUG("default\n");
627 break;
630 } while (loop);
632 gtk_widget_destroy(GTK_WIDGET(self));
634 IRRECO_RETURN_BOOL(rvalue);
637 static void
638 irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook,
639 GtkNotebookPage *page,
640 guint page_num,
641 IrrecoThemeCreatorDlg *self)
644 IRRECO_ENTER
646 switch (page_num){
648 case ABOUT:
649 gtk_widget_show(self->cancel_button);
650 gtk_widget_show(self->save_button);
651 gtk_widget_hide(self->add_button);
652 gtk_widget_hide(self->edit_button);
653 gtk_widget_hide(self->delete_button);
655 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
657 break;
658 case BUTTONS:
659 gtk_widget_hide(self->cancel_button);
660 gtk_widget_hide(self->save_button);
661 gtk_widget_show(self->add_button);
662 gtk_widget_show(self->edit_button);
663 gtk_widget_show(self->delete_button);
665 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
666 gtk_widget_show_all(GTK_WIDGET(self->buttons));
668 break;
669 case BACKGROUNDS:
670 gtk_widget_hide(self->cancel_button);
671 gtk_widget_hide(self->save_button);
672 gtk_widget_show(self->add_button);
673 gtk_widget_show(self->edit_button);
674 gtk_widget_show(self->delete_button);
676 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
677 gtk_widget_show_all(GTK_WIDGET(self->backgrounds));
679 break;
681 default:
682 IRRECO_DEBUG("default\n");
683 break;
685 IRRECO_RETURN
688 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
689 /* Events and Callbacks */
690 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
693 * @name Events and Callbacks
694 * @{
697 static void irreco_theme_creator_dlg_preview_image(GtkWidget *widget,
698 GdkEventButton *event,
699 IrrecoThemeCreatorDlg *self)
702 IrrecoThemeButton *preview_theme_button = NULL;
704 IRRECO_ENTER
705 if (self->theme != NULL) {
706 preview_theme_button = irreco_button_browser_dlg_run(
707 GTK_WINDOW(self),
708 self->irreco_data,
709 self->theme);
711 if(preview_theme_button) {
712 IRRECO_DEBUG("Set preview button to theme and self->\n");
714 self->preview_name = preview_theme_button->image_up->str;
715 self->preview_button = preview_theme_button;
716 _set_preview(self);
719 IRRECO_RETURN
722 /** @} */
725 *Create new background or button
728 static void irreco_theme_creator_dlg_new_bg_button(GtkButton *button,
729 IrrecoThemeCreatorDlg *self)
732 IRRECO_ENTER
733 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
734 self->notebook))==BACKGROUNDS) {
736 IrrecoThemeBg *new_bg = NULL;
737 new_bg = irreco_theme_bg_new();
739 if (irreco_background_creator_dlg_run(self->irreco_data,
740 self->theme,
741 GTK_WINDOW(self), new_bg)) {
742 irreco_string_table_add(self->theme->backgrounds,
743 new_bg->image_name->str,
744 new_bg);
745 irreco_theme_creator_backgrounds_refresh(
746 IRRECO_THEME_CREATOR_BACKGROUNDS(
747 self->backgrounds));
748 } else {
749 /*irreco_theme_bg_free(new_bg);*/
751 } else {
752 IrrecoThemeButton *new_button = NULL;
753 new_button = irreco_theme_button_new(NULL);
755 if (irreco_button_creator_dlg_run(self->irreco_data, self->theme,
756 GTK_WINDOW(self), new_button)) {
757 irreco_string_table_add(self->theme->buttons,
758 new_button->name->str,
759 new_button);
760 irreco_theme_creator_buttons_refresh(
761 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
762 } else {
763 /*irreco_theme_button_free(new_button);*/
767 IRRECO_RETURN
771 *Create edit background or button
774 static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button,
775 IrrecoThemeCreatorDlg *self)
777 IRRECO_ENTER
778 /* Check which page */
779 /* Edit bg */
780 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
781 self->notebook)) == BACKGROUNDS) {
783 IrrecoThemeBg *bg = NULL;
784 IrrecoThemeBg *new_bg = NULL;
785 IrrecoThemeBg *old_bg = NULL;
787 bg = irreco_theme_creator_backgrounds_get_selected_bg(
788 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
789 /* check whether the background image of the selected */
790 if (bg) {
791 new_bg = irreco_theme_bg_copy(bg);
793 IRRECO_PRINTF("Pointer: %p \n", (void*) self->theme);
795 if (irreco_background_creator_dlg_run(self->irreco_data,
796 self->theme,
797 GTK_WINDOW(self),
798 new_bg)) {
799 old_bg = irreco_theme_bg_copy(bg);
800 irreco_theme_bg_set(bg, new_bg->image_name->str,
801 new_bg->image_path->str);
803 irreco_theme_creator_backgrounds_refresh(
804 IRRECO_THEME_CREATOR_BACKGROUNDS(
805 self->backgrounds));
807 irreco_theme_bg_free(new_bg);
809 } else
811 IRRECO_DEBUG("the background is not selected\n");
813 /* Edit Button */
814 } else {
815 IrrecoThemeButton *button = NULL;
816 IrrecoThemeButton *new_button = NULL;
817 IrrecoThemeButton *old_button = NULL;
819 button = irreco_theme_creator_buttons_get_selected_button(
820 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
821 /* check whether the button image of the selected */
822 if (button) {
823 new_button = irreco_theme_button_copy(button);
825 if (irreco_button_creator_dlg_run(self->irreco_data,
826 self->theme,
827 GTK_WINDOW(self),
828 new_button)) {
829 old_button = irreco_theme_button_copy(button);
830 irreco_theme_button_print(new_button);
831 irreco_theme_button_set_from_button(button,
832 new_button);
834 irreco_theme_button_print(old_button);
835 irreco_theme_button_print(button);
837 irreco_theme_creator_buttons_refresh(
838 IRRECO_THEME_CREATOR_BUTTONS(
839 self->buttons));
843 irreco_theme_button_free(new_button);
844 } else {
845 IRRECO_DEBUG("the button is not selected\n");
848 IRRECO_RETURN
851 static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button,
852 IrrecoThemeCreatorDlg *self)
855 IRRECO_ENTER
858 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
859 self->notebook)) == BACKGROUNDS) {
860 IrrecoThemeBg *bg;
861 bg = irreco_theme_creator_backgrounds_get_selected_bg(
862 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
863 if (irreco_theme_creator_backgrounds_remove_selected(
864 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds))) {
865 irreco_string_table_remove((self->theme)->backgrounds,
866 bg->image_name->str);
868 } else {
869 IrrecoThemeButton *button;
870 button = irreco_theme_creator_buttons_get_selected_button(
871 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
872 if (irreco_theme_creator_buttons_remove_selected(
873 IRRECO_THEME_CREATOR_BUTTONS(self->buttons))) {
874 irreco_string_table_remove((self->theme)->buttons,
875 button->name->str);
880 IRRECO_RETURN