equal to the label text of the left-side
[irreco.git] / irreco / src / core / irreco_theme_creator_dlg.c
blob400d26b25ea1880bb0b85f3a3ad5dcc73d8acff1
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*/
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 table_about = gtk_table_new(7, 9, TRUE);
171 label_author = gtk_label_new(_("Author:"));
172 label_name = gtk_label_new(_("Name: "));
173 self->entry_author = gtk_entry_new();
174 self->entry_name = gtk_entry_new();
175 frame_comments = gtk_frame_new("");
176 scrolled_comments = gtk_scrolled_window_new(NULL, NULL);
177 self->textview_comments = gtk_text_view_new();
178 preview_button_frame = gtk_frame_new("");
179 self->preview_event_box = gtk_event_box_new();
180 self->preview_image = gtk_image_new();
181 gtk_image_set_from_file(GTK_IMAGE(self->preview_image), NULL);
182 self->hbox_backgrounds = gtk_hbox_new(FALSE, 2);
183 self->hbox_buttons = gtk_hbox_new(FALSE, 2);
185 /* equal to the text of the left-side */
186 gtk_misc_set_alignment(GTK_MISC(label_name), 0, 0.5);
187 gtk_misc_set_alignment(GTK_MISC(label_author), 0, 0.5);
190 /* Set frame text bold */
191 gtk_frame_set_label_widget(GTK_FRAME(frame_comments),
192 irreco_gtk_label_bold(
193 "Comments", 0, 0, 0, 0, 0, 0));
194 gtk_frame_set_label_widget(GTK_FRAME(preview_button_frame),
195 irreco_gtk_label_bold(
196 "Preview button", 0, 0, 0, 0, 0, 0));
198 /* Create Notebook tabs. */
200 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
201 irreco_gtk_align(GTK_WIDGET(table_about),
202 0, 0, 1, 1, 8, 8, 8, 8),
203 gtk_label_new("About"));
204 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
205 irreco_gtk_align(GTK_WIDGET(self->hbox_buttons),
206 0, 0, 1, 1, 8, 8, 8, 8),
207 gtk_label_new("Buttons"));
208 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
209 irreco_gtk_align(GTK_WIDGET(
210 self->hbox_backgrounds),
211 0, 0, 1, 1, 8, 8, 8, 8),
212 gtk_label_new("Backgrounds"));
215 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox),
216 self->notebook);
219 /* Set widgets on the table_about */
221 gtk_table_set_row_spacings(GTK_TABLE(table_about), 6);
222 gtk_table_set_col_spacings(GTK_TABLE(table_about), 6);
224 gtk_table_attach_defaults(GTK_TABLE(table_about),
225 label_author, 0, 2, 0, 1);
226 gtk_table_attach_defaults(GTK_TABLE(table_about),
227 label_name, 0, 2, 1, 2);
228 gtk_table_attach_defaults(GTK_TABLE(table_about),
229 self->entry_author, 2, 9, 0, 1);
230 gtk_table_attach_defaults(GTK_TABLE(table_about),
231 self->entry_name, 2, 9, 1, 2);
232 gtk_table_attach_defaults(GTK_TABLE(table_about),
233 frame_comments, 0, 6, 2, 7);
234 gtk_table_attach_defaults(GTK_TABLE(table_about),
235 preview_button_frame, 6, 9, 2, 7);
238 /*ABOUT*/
239 /* set preview image*/
242 gtk_container_add(GTK_CONTAINER(preview_button_frame),
243 self->preview_event_box);
244 gtk_container_add(GTK_CONTAINER(self->preview_event_box),
245 self->preview_image);
247 /* textview */
249 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self->textview_comments),
250 GTK_WRAP_WORD_CHAR);
252 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_comments),
253 GTK_POLICY_NEVER,
254 GTK_POLICY_AUTOMATIC);
256 gtk_container_add(GTK_CONTAINER(frame_comments), scrolled_comments);
257 gtk_container_add(GTK_CONTAINER(scrolled_comments),
258 self->textview_comments);
260 /* Signal handlers. */
262 g_signal_connect(G_OBJECT(self->notebook), "switch-page",
263 G_CALLBACK(irreco_theme_creator_dlg_notebook_changed),
264 self);
266 g_signal_connect(G_OBJECT(self->preview_event_box),
267 "button-release-event",
268 G_CALLBACK(irreco_theme_creator_dlg_preview_image),
269 self);
271 g_signal_connect(G_OBJECT(self->add_button), "clicked",
272 G_CALLBACK(irreco_theme_creator_dlg_new_bg_button),
273 self);
274 g_signal_connect(G_OBJECT(self->edit_button), "clicked",
275 G_CALLBACK(irreco_theme_creator_dlg_edit_bg_button),
276 self);
277 g_signal_connect(G_OBJECT(self->delete_button), "clicked",
278 G_CALLBACK(irreco_theme_creator_dlg_delete_bg_button),
279 self);
281 gtk_widget_show_all(GTK_WIDGET(self));
282 IRRECO_RETURN
286 static void irreco_theme_creator_dlg_init(IrrecoThemeCreatorDlg *self)
288 IRRECO_ENTER
289 IRRECO_RETURN
292 static void irreco_theme_creator_dlg_finalize(GObject *object)
294 IrrecoThemeCreatorDlg *self;
295 IRRECO_ENTER
297 self = IRRECO_THEME_CREATOR_DLG(object);
299 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->finalize(object);
300 IRRECO_RETURN
305 static void
306 irreco_theme_creator_dlg_class_init(IrrecoThemeCreatorDlgClass *klass)
308 GObjectClass* object_class = G_OBJECT_CLASS (klass);
310 object_class->finalize = irreco_theme_creator_dlg_finalize;
311 object_class->constructed = irreco_theme_creator_dlg_constructed;
316 GtkWidget
317 *irreco_theme_creator_dlg_new(IrrecoData *irreco_data, GtkWindow *parent)
319 IrrecoThemeCreatorDlg *self;
321 IRRECO_ENTER
322 self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG,
323 "irreco-data", irreco_data,
324 NULL);
325 /*self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, NULL);*/
326 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
328 IRRECO_RETURN_PTR(self);
331 /** @} */
333 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
334 /* Private Functions */
335 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
337 * @name Private Functions
338 * @{
342 * Start a loader state machine if one is not running already.
344 static void _loader_start(IrrecoThemeCreatorDlg *self, GSourceFunc function)
346 IRRECO_ENTER
348 if (self->loader_func_id == 0) {
349 self->loader_func_id = g_idle_add((GSourceFunc)function, self);
352 IRRECO_RETURN
356 * Stop and cleanup loader if a loader is running.
358 static void _loader_stop(IrrecoThemeCreatorDlg *self)
360 IRRECO_ENTER
361 /*_hide_banner(self);*/
362 if (self->loader_func_id != 0) {
363 g_source_remove(self->loader_func_id);
364 self->loader_func_id = 0;
365 self->loader_state = 0;
367 IRRECO_RETURN
370 static gboolean
371 irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self,
372 gint page)
375 IRRECO_ENTER
376 IRRECO_PRINTF("Page_nro %d\n", page);
377 IRRECO_RETURN_BOOL(TRUE);
382 * Sets the theme details
385 void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme)
388 IRRECO_ENTER
390 gtk_entry_set_text(GTK_ENTRY(self->entry_name),
391 self->theme->name->str);
392 gtk_entry_set_text(GTK_ENTRY(self->entry_author),
393 self->theme->author->str);
395 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
396 self->textview_comments));
397 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self->buffer_comments),
398 self->theme->comment->str,
399 -1);
400 self->backgrounds = irreco_theme_creator_backgrounds_new(
401 GTK_WINDOW(self),
402 self->irreco_data,
403 self->theme);
404 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
405 self->irreco_data,
406 self->theme);
407 /* Set window title */
408 gtk_window_set_title(GTK_WINDOW(self), _("Theme Editor "));
411 _set_preview(self);
413 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
414 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
415 self->backgrounds);
418 IRRECO_RETURN
421 void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self)
423 IRRECO_ENTER
425 self->backgrounds = irreco_theme_creator_backgrounds_new(
426 GTK_WINDOW(self),
427 self->irreco_data,
428 self->theme);
429 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
430 self->irreco_data,
431 self->theme);
433 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
434 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
435 self->backgrounds);
436 IRRECO_RETURN
440 * Update shown preview image
442 static void _set_preview(IrrecoThemeCreatorDlg *self)
444 IRRECO_ENTER
446 /* if theme contains preview image, use it, else get first button */
447 if(self->preview_name) {
448 IRRECO_DEBUG("Preview set in dlg, using it\n");
449 } else if(strlen(self->theme->preview_button_name->str) != 0) {
450 gchar *strtblkey;
451 IRRECO_DEBUG("Preview set to theme, using it\n");
452 strtblkey = g_strdup_printf("%s/%s", self->theme->name->str,
453 self->theme->preview_button_name->str);
454 /*IRRECO_DEBUG("key: %s\n", strtblkey);*/
455 if(irreco_string_table_get(self->theme->buttons, strtblkey,
456 (gpointer *) &self->preview_button)) {
457 self->preview_name = self->preview_button->image_up->str;
458 } else {
459 IRRECO_DEBUG("Theme preview set wrong\n");
461 } else {
462 const gchar *key;
463 IRRECO_DEBUG("No preview set, using first button of theme\n");
464 irreco_string_table_index(self->theme->buttons, 0, &key,
465 (gpointer *) &self->preview_button);
466 if(self->preview_button) {
467 self->preview_name = self->preview_button->image_up->str;
470 gtk_image_set_from_file(GTK_IMAGE(self->preview_image),
471 self->preview_name);
472 IRRECO_RETURN
475 void _set_edited_theme_details(IrrecoThemeCreatorDlg *self)
477 GtkTextIter startiter;
478 GtkTextIter enditer;
479 IRRECO_ENTER
481 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
482 self->textview_comments));
484 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(self->buffer_comments),
485 &startiter);
486 gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(self->buffer_comments),
487 &enditer);
490 irreco_theme_set(self->theme,
491 gtk_entry_get_text(GTK_ENTRY(self->entry_name)),
492 NULL,
493 "user",
494 gtk_entry_get_text(GTK_ENTRY(self->entry_author)),
495 gtk_text_buffer_get_text(GTK_TEXT_BUFFER(
496 self->buffer_comments),
497 &startiter,
498 &enditer,
499 FALSE),
500 self->preview_button->name->str,
501 NULL);
503 IRRECO_RETURN
506 /** @} */
508 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
509 /* Functions */
510 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
513 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
514 /* Public Functions */
515 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
516 gboolean
517 irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data,
518 IrrecoTheme *irreco_theme)
520 IrrecoThemeCreatorDlg *self;
521 gint response;
522 gboolean loop = TRUE;
523 gboolean rvalue = FALSE;
524 /*GtkTextIter startiter;
525 GtkTextIter enditer;*/
526 IRRECO_ENTER
528 self = (IrrecoThemeCreatorDlg*)irreco_theme_creator_dlg_new(irreco_data,
529 parent_window);
530 self->parent_window = GTK_WINDOW(self);
531 self->loader_func_id = 0;
532 self->irreco_data = irreco_data;
533 self->preview_name = NULL;
534 irreco_theme_print(irreco_theme);
535 self->theme = irreco_theme;
536 IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme);
537 IRRECO_DEBUG("Pointer: %p \n", (void*) irreco_theme);
539 /* Check whether the theme of a blank*/
540 if (irreco_string_table_lenght(irreco_theme->buttons) != 0) {
541 /* Sets the theme details */
542 _set_theme_details(self, irreco_theme);
543 } else {
544 /* create blank bg:s and buttons widgets */
545 _create_bg_and_button_widgets(self);
548 do {
549 response = gtk_dialog_run(GTK_DIALOG(self));
550 switch (response) {
551 case GTK_RESPONSE_OK:
553 self->loader_state = LOADER_STATE_INIT;
554 _loader_start(self, NULL);
555 /* Call set edited_theme_details functio */
556 _set_edited_theme_details(self);
558 /* Call ThemeSaveDlg */
559 if (irreco_theme_save_dlg_run(self->irreco_data,
560 irreco_theme, GTK_WINDOW(self))) {
561 rvalue = TRUE;
562 loop = FALSE;
564 } else {
565 rvalue = FALSE;
566 loop = TRUE;
568 break;
570 case GTK_RESPONSE_CANCEL:
571 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
572 _loader_stop(self);
574 loop = FALSE;
575 break;
577 default:
578 IRRECO_DEBUG("default\n");
579 break;
582 } while (loop);
584 gtk_widget_destroy(GTK_WIDGET(self));
586 IRRECO_RETURN_BOOL(rvalue);
591 static void
592 irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook,
593 GtkNotebookPage *page,
594 guint page_num,
595 IrrecoThemeCreatorDlg *self)
598 IRRECO_ENTER
600 switch (page_num){
602 case ABOUT:
603 gtk_widget_show(self->cancel_button);
604 gtk_widget_show(self->save_button);
605 gtk_widget_hide(self->add_button);
606 gtk_widget_hide(self->edit_button);
607 gtk_widget_hide(self->delete_button);
609 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
611 break;
612 case BUTTONS:
613 gtk_widget_hide(self->cancel_button);
614 gtk_widget_hide(self->save_button);
615 gtk_widget_show(self->add_button);
616 gtk_widget_show(self->edit_button);
617 gtk_widget_show(self->delete_button);
619 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
620 gtk_widget_show_all(GTK_WIDGET(self->buttons));
622 break;
623 case BACKGROUNDS:
624 gtk_widget_hide(self->cancel_button);
625 gtk_widget_hide(self->save_button);
626 gtk_widget_show(self->add_button);
627 gtk_widget_show(self->edit_button);
628 gtk_widget_show(self->delete_button);
630 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
631 gtk_widget_show_all(GTK_WIDGET(self->backgrounds));
633 break;
635 default:
636 IRRECO_DEBUG("default\n");
637 break;
639 IRRECO_RETURN
643 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
644 /* Events and Callbacks */
645 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
648 * @name Events and Callbacks
649 * @{
652 static void irreco_theme_creator_dlg_preview_image(GtkWidget *widget,
653 GdkEventButton *event,
654 IrrecoThemeCreatorDlg *self)
657 IrrecoThemeButton *preview_theme_button = NULL;
659 IRRECO_ENTER
660 if (self->theme != NULL) {
661 preview_theme_button = irreco_button_browser_dlg_run(
662 GTK_WINDOW(self),
663 self->irreco_data,
664 self->theme);
666 if(preview_theme_button) {
667 IRRECO_DEBUG("Set preview button to theme and self->\n");
669 self->preview_name = preview_theme_button->image_up->str;
670 self->preview_button = preview_theme_button;
671 _set_preview(self);
674 IRRECO_RETURN
677 /** @} */
681 *Create new background or button
684 static void irreco_theme_creator_dlg_new_bg_button(GtkButton *button,
685 IrrecoThemeCreatorDlg *self)
688 IRRECO_ENTER
689 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
690 self->notebook))==BACKGROUNDS) {
692 IrrecoThemeBg *new_bg = NULL;
693 new_bg = irreco_theme_bg_new();
695 if (irreco_background_creator_dlg_run(self->irreco_data,
696 self->theme,
697 GTK_WINDOW(self), new_bg)) {
698 irreco_string_table_add(self->theme->backgrounds,
699 new_bg->image_name->str,
700 new_bg);
701 irreco_theme_creator_backgrounds_refresh(
702 IRRECO_THEME_CREATOR_BACKGROUNDS(
703 self->backgrounds));
704 /*irreco_theme_bg_free(new_bg);*/
705 } else {
706 /*irreco_theme_bg_free(new_bg);*/
708 } else {
709 IrrecoThemeButton *new_button = NULL;
710 new_button = irreco_theme_button_new(NULL);
712 if (irreco_button_creator_dlg_run(self->irreco_data, self->theme,
713 GTK_WINDOW(self), new_button)) {
714 irreco_string_table_add(self->theme->buttons,
715 new_button->name->str,
716 new_button);
717 irreco_theme_creator_buttons_refresh(
718 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
719 /*irreco_theme_button_free(new_button);*/
720 } else {
721 /*irreco_theme_button_free(new_button);*/
725 IRRECO_RETURN
729 *Create edit background or button
732 static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button,
733 IrrecoThemeCreatorDlg *self)
735 IRRECO_ENTER
736 /* Check which page */
737 /* Edit bg */
738 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
739 self->notebook)) == BACKGROUNDS) {
741 IrrecoThemeBg *bg = NULL;
742 IrrecoThemeBg *new_bg = NULL;
743 IrrecoThemeBg *old_bg = NULL;
745 bg = irreco_theme_creator_backgrounds_get_selected_bg(
746 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
747 /* check whether the background image of the selected */
748 if (bg) {
749 new_bg = irreco_theme_bg_copy(bg);
751 IRRECO_PRINTF("Pointer: %p \n", (void*) self->theme);
753 if (irreco_background_creator_dlg_run(self->irreco_data,
754 self->theme,
755 GTK_WINDOW(self),
756 new_bg)) {
757 old_bg = irreco_theme_bg_copy(bg);
758 irreco_theme_bg_set(bg, new_bg->image_name->str,
759 new_bg->image_path->str);
761 irreco_theme_creator_backgrounds_refresh(
762 IRRECO_THEME_CREATOR_BACKGROUNDS(
763 self->backgrounds));
765 irreco_theme_bg_free(new_bg);
767 } else
769 IRRECO_DEBUG("the background is not selected\n");
771 /* Edit Button */
772 } else {
773 IrrecoThemeButton *button = NULL;
774 IrrecoThemeButton *new_button = NULL;
775 IrrecoThemeButton *old_button = NULL;
777 button = irreco_theme_creator_buttons_get_selected_button(
778 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
779 /* check whether the button image of the selected */
780 if (button) {
781 new_button = irreco_theme_button_copy(button);
783 if (irreco_button_creator_dlg_run(self->irreco_data,
784 self->theme,
785 GTK_WINDOW(self),
786 new_button)) {
787 old_button = irreco_theme_button_copy(button);
788 irreco_theme_button_print(new_button);
789 irreco_theme_button_set_from_button(button,
790 new_button);
792 irreco_theme_button_print(old_button);
793 irreco_theme_button_print(button);
795 irreco_theme_creator_buttons_refresh(
796 IRRECO_THEME_CREATOR_BUTTONS(
797 self->buttons));
801 irreco_theme_button_free(new_button);
802 } else {
803 IRRECO_DEBUG("the button is not selected\n");
806 IRRECO_RETURN
809 static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button,
810 IrrecoThemeCreatorDlg *self)
813 IRRECO_ENTER
816 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
817 self->notebook)) == BACKGROUNDS) {
818 IrrecoThemeBg *bg;
819 bg = irreco_theme_creator_backgrounds_get_selected_bg(
820 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
821 if (irreco_theme_creator_backgrounds_remove_selected(
822 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds))) {
823 irreco_string_table_remove((self->theme)->backgrounds,
824 bg->image_name->str);
826 } else {
827 IrrecoThemeButton *button;
828 button = irreco_theme_creator_buttons_get_selected_button(
829 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
830 if (irreco_theme_creator_buttons_remove_selected(
831 IRRECO_THEME_CREATOR_BUTTONS(self->buttons))) {
832 irreco_string_table_remove((self->theme)->buttons,
833 button->name->str);
838 IRRECO_RETURN