Added _set_edited_theme_details function.
[irreco.git] / irreco / src / core / irreco_theme_creator_dlg.c
blobb4a4746130672641b71f6dbfae5ab71eb0e7319e
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 void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme);
105 void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self);
106 void _set_button_new_details(IrrecoThemeCreatorDlg *self,
107 IrrecoThemeButton *old_button,
108 IrrecoThemeButton *button);
109 void _set_bg_new_details(IrrecoThemeCreatorDlg *self,
110 IrrecoThemeBg *old_bg,
111 IrrecoThemeBg *bg);
112 void _set_edited_theme_details(IrrecoThemeCreatorDlg *self);
113 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
114 /* Construction & Destruction */
115 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
118 * @name Construction & Destruction
119 * @{
122 G_DEFINE_TYPE(IrrecoThemeCreatorDlg, irreco_theme_creator_dlg,
123 IRRECO_TYPE_INTERNAL_DLG)
125 static void irreco_theme_creator_dlg_constructed(GObject *object)
127 /* TODO: Add initialization code here */
129 IrrecoData *irreco_data;
130 IrrecoThemeCreatorDlg *self;
131 /*About widgets*/
133 GtkWidget *table_about;
134 GtkWidget *label_author;
135 GtkWidget *label_name;
136 GtkWidget *frame_comments;
137 GtkWidget *scrolled_comments;
139 GtkWidget *preview_button_frame;
143 IRRECO_ENTER
145 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->constructed(object);
146 self = IRRECO_THEME_CREATOR_DLG(object);
147 irreco_data = irreco_internal_dlg_get_irreco_data(IRRECO_INTERNAL_DLG(self));
149 /* Construct dialog. */
150 gtk_window_set_title(GTK_WINDOW(self), _("Theme Creator "));
151 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
152 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
153 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
155 /*Buttons*/
156 self->cancel_button = gtk_dialog_add_button (GTK_DIALOG(self),
157 _("Cancel"),
158 GTK_RESPONSE_CANCEL);
159 self->save_button = gtk_dialog_add_button (GTK_DIALOG(self),
160 _("Save"),
161 GTK_RESPONSE_OK);
162 self->add_button = gtk_dialog_add_button (GTK_DIALOG(self),
163 _("Add"), GTK_RESPONSE_NONE);
164 self->edit_button = gtk_dialog_add_button (GTK_DIALOG(self),
165 _("Edit"),
166 GTK_RESPONSE_NONE);
167 self->delete_button = gtk_dialog_add_button (GTK_DIALOG(self),
168 _("Delete"),
169 GTK_RESPONSE_NONE);
171 /* Create widgets. */
172 self->notebook = gtk_notebook_new();
174 /* ABOUT*/
176 table_about = gtk_table_new(7, 9, TRUE);
177 label_author = gtk_label_new(_("Author:"));
178 label_name = gtk_label_new(_("Name: "));
179 self->entry_author = gtk_entry_new();
180 self->entry_name = gtk_entry_new();
181 frame_comments = gtk_frame_new("");
182 scrolled_comments = gtk_scrolled_window_new(NULL, NULL);
183 self->textview_comments = gtk_text_view_new();
184 preview_button_frame = gtk_frame_new("");
185 self->preview_event_box = gtk_event_box_new();
186 self->preview_image = gtk_image_new();
187 gtk_image_set_from_file(GTK_IMAGE(self->preview_image), NULL);
188 self->hbox_backgrounds = gtk_hbox_new(FALSE, 2);
189 self->hbox_buttons = gtk_hbox_new(FALSE, 2);
192 /* Set frame text bold */
193 gtk_frame_set_label_widget(GTK_FRAME(frame_comments),
194 irreco_gtk_label_bold(
195 "Comments", 0, 0, 0, 0, 0, 0));
196 gtk_frame_set_label_widget(GTK_FRAME(preview_button_frame),
197 irreco_gtk_label_bold(
198 "Preview button", 0, 0, 0, 0, 0, 0));
200 /* Create Notebook tabs. */
202 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
203 irreco_gtk_align(GTK_WIDGET(table_about),
204 0, 0, 1, 1, 8, 8, 8, 8),
205 gtk_label_new("About"));
206 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
207 irreco_gtk_align(GTK_WIDGET(self->hbox_buttons),
208 0, 0, 1, 1, 8, 8, 8, 8),
209 gtk_label_new("Buttons"));
210 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
211 irreco_gtk_align(GTK_WIDGET(
212 self->hbox_backgrounds),
213 0, 0, 1, 1, 8, 8, 8, 8),
214 gtk_label_new("Backgrounds"));
217 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox),
218 self->notebook);
221 /* Set widgets on the table_about */
223 gtk_table_set_row_spacings(GTK_TABLE(table_about), 6);
224 gtk_table_set_col_spacings(GTK_TABLE(table_about), 6);
226 gtk_table_attach_defaults(GTK_TABLE(table_about),
227 label_author, 0, 2, 0, 1);
228 gtk_table_attach_defaults(GTK_TABLE(table_about),
229 label_name, 0, 2, 1, 2);
230 gtk_table_attach_defaults(GTK_TABLE(table_about),
231 self->entry_author, 2, 9, 0, 1);
232 gtk_table_attach_defaults(GTK_TABLE(table_about),
233 self->entry_name, 2, 9, 1, 2);
234 gtk_table_attach_defaults(GTK_TABLE(table_about),
235 frame_comments, 0, 6, 2, 7);
236 gtk_table_attach_defaults(GTK_TABLE(table_about),
237 preview_button_frame, 6, 9, 2, 7);
240 /*ABOUT*/
241 /* set preview image*/
244 gtk_container_add(GTK_CONTAINER(preview_button_frame),
245 self->preview_event_box);
246 gtk_container_add(GTK_CONTAINER(self->preview_event_box),
247 self->preview_image);
249 /* textview */
251 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self->textview_comments),
252 GTK_WRAP_WORD_CHAR);
254 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_comments),
255 GTK_POLICY_NEVER,
256 GTK_POLICY_AUTOMATIC);
258 gtk_container_add(GTK_CONTAINER(frame_comments), scrolled_comments);
259 gtk_container_add(GTK_CONTAINER(scrolled_comments),
260 self->textview_comments);
262 /* Signal handlers. */
264 g_signal_connect(G_OBJECT(self->notebook), "switch-page",
265 G_CALLBACK(irreco_theme_creator_dlg_notebook_changed),
266 self);
268 g_signal_connect(G_OBJECT(self->preview_event_box),
269 "button-release-event",
270 G_CALLBACK(irreco_theme_creator_dlg_preview_image),
271 self);
273 g_signal_connect(G_OBJECT(self->add_button), "clicked",
274 G_CALLBACK(irreco_theme_creator_dlg_new_bg_button),
275 self);
276 g_signal_connect(G_OBJECT(self->edit_button), "clicked",
277 G_CALLBACK(irreco_theme_creator_dlg_edit_bg_button),
278 self);
279 g_signal_connect(G_OBJECT(self->delete_button), "clicked",
280 G_CALLBACK(irreco_theme_creator_dlg_delete_bg_button),
281 self);
283 gtk_widget_show_all(GTK_WIDGET(self));
284 IRRECO_RETURN
288 static void irreco_theme_creator_dlg_init(IrrecoThemeCreatorDlg *self)
290 IRRECO_ENTER
291 IRRECO_RETURN
294 static void irreco_theme_creator_dlg_finalize(GObject *object)
296 IrrecoThemeCreatorDlg *self;
297 IRRECO_ENTER
299 self = IRRECO_THEME_CREATOR_DLG(object);
301 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->finalize(object);
302 IRRECO_RETURN
307 static void
308 irreco_theme_creator_dlg_class_init(IrrecoThemeCreatorDlgClass *klass)
310 GObjectClass* object_class = G_OBJECT_CLASS (klass);
312 object_class->finalize = irreco_theme_creator_dlg_finalize;
313 object_class->constructed = irreco_theme_creator_dlg_constructed;
318 GtkWidget
319 *irreco_theme_creator_dlg_new(IrrecoData *irreco_data, GtkWindow *parent)
321 IrrecoThemeCreatorDlg *self;
323 IRRECO_ENTER
324 self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG,
325 "irreco-data", irreco_data,
326 NULL);
327 /*self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, NULL);*/
328 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
330 IRRECO_RETURN_PTR(self);
333 /** @} */
335 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
336 /* Private Functions */
337 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
339 * @name Private Functions
340 * @{
344 * Start a loader state machine if one is not running already.
346 static void _loader_start(IrrecoThemeCreatorDlg *self, GSourceFunc function)
348 IRRECO_ENTER
350 if (self->loader_func_id == 0) {
351 self->loader_func_id = g_idle_add((GSourceFunc)function, self);
354 IRRECO_RETURN
358 * Stop and cleanup loader if a loader is running.
360 static void _loader_stop(IrrecoThemeCreatorDlg *self)
362 IRRECO_ENTER
363 /*_hide_banner(self);*/
364 if (self->loader_func_id != 0) {
365 g_source_remove(self->loader_func_id);
366 self->loader_func_id = 0;
367 self->loader_state = 0;
369 IRRECO_RETURN
372 static gboolean
373 irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self,
374 gint page)
377 IRRECO_ENTER
378 IRRECO_PRINTF("Page_nro %d\n", page);
379 IRRECO_RETURN_BOOL(TRUE);
384 * Sets the theme details
387 void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme)
390 IRRECO_ENTER
392 gtk_entry_set_text(GTK_ENTRY(self->entry_name),
393 self->theme->name->str);
394 gtk_entry_set_text(GTK_ENTRY(self->entry_author),
395 self->theme->author->str);
397 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
398 self->textview_comments));
399 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self->buffer_comments),
400 self->theme->comment->str,
401 -1);
402 self->backgrounds = irreco_theme_creator_backgrounds_new(
403 GTK_WINDOW(self),
404 self->irreco_data,
405 self->theme);
406 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
407 self->irreco_data,
408 self->theme);
409 /* Set window title */
410 gtk_window_set_title(GTK_WINDOW(self), _("Theme Editor "));
413 _set_preview(self);
415 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
416 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
417 self->backgrounds);
420 IRRECO_RETURN
423 void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self)
425 IRRECO_ENTER
427 self->backgrounds = irreco_theme_creator_backgrounds_new(
428 GTK_WINDOW(self),
429 self->irreco_data,
430 self->theme);
431 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
432 self->irreco_data,
433 self->theme);
435 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
436 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
437 self->backgrounds);
438 IRRECO_RETURN
442 * Update shown preview image
444 static void _set_preview(IrrecoThemeCreatorDlg *self)
446 IRRECO_ENTER
448 /* if theme contains preview image, use it, else get first button */
449 if(self->preview_name) {
450 IRRECO_DEBUG("Preview set in dlg, using it\n");
451 } else if(strlen(self->theme->preview_button_name->str) != 0) {
452 gchar *strtblkey;
453 IRRECO_DEBUG("Preview set to theme, using it\n");
454 strtblkey = g_strdup_printf("%s/%s", self->theme->name->str,
455 self->theme->preview_button_name->str);
456 /*IRRECO_DEBUG("key: %s\n", strtblkey);*/
457 if(irreco_string_table_get(self->theme->buttons, strtblkey,
458 (gpointer *) &self->preview_button)) {
459 self->preview_name = self->preview_button->image_up->str;
460 } else {
461 IRRECO_DEBUG("Theme preview set wrong\n");
463 } else {
464 const gchar *key;
465 IRRECO_DEBUG("No preview set, using first button of theme\n");
466 irreco_string_table_index(self->theme->buttons, 0, &key,
467 (gpointer *) &self->preview_button);
468 if(self->preview_button) {
469 self->preview_name = self->preview_button->image_up->str;
472 gtk_image_set_from_file(GTK_IMAGE(self->preview_image),
473 self->preview_name);
474 IRRECO_RETURN
477 void _set_edited_theme_details(IrrecoThemeCreatorDlg *self)
479 GtkTextIter startiter;
480 GtkTextIter enditer;
481 IRRECO_ENTER
483 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
484 self->textview_comments));
486 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(self->buffer_comments),
487 &startiter);
488 gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(self->buffer_comments),
489 &enditer);
492 irreco_theme_set(self->theme,
493 gtk_entry_get_text(GTK_ENTRY(self->entry_name)),
494 NULL,
495 "user",
496 gtk_entry_get_text(GTK_ENTRY(self->entry_author)),
497 gtk_text_buffer_get_text(GTK_TEXT_BUFFER(
498 self->buffer_comments),
499 &startiter,
500 &enditer,
501 FALSE),
502 self->preview_button->name->str,
503 NULL);
505 IRRECO_RETURN
508 /** @} */
510 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
511 /* Functions */
512 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
515 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
516 /* Public Functions */
517 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
518 gboolean
519 irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data,
520 IrrecoTheme *irreco_theme)
522 IrrecoThemeCreatorDlg *self;
523 gint response;
524 gboolean loop = TRUE;
525 gboolean rvalue = FALSE;
526 /*GtkTextIter startiter;
527 GtkTextIter enditer;*/
528 IRRECO_ENTER
530 self = (IrrecoThemeCreatorDlg*)irreco_theme_creator_dlg_new(irreco_data,
531 parent_window);
532 self->parent_window = GTK_WINDOW(self);
533 self->loader_func_id = 0;
534 self->irreco_data = irreco_data;
535 self->preview_name = NULL;
536 irreco_theme_print(irreco_theme);
537 self->theme = irreco_theme;
538 IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme);
539 IRRECO_DEBUG("Pointer: %p \n", (void*) irreco_theme);
541 /* Check whether the theme of a blank*/
542 if (irreco_string_table_lenght(irreco_theme->buttons) != 0) {
543 /* Sets the theme details */
544 _set_theme_details(self, irreco_theme);
545 } else {
546 /* create blank bg:s and buttons widgets */
547 _create_bg_and_button_widgets(self);
550 do {
551 response = gtk_dialog_run(GTK_DIALOG(self));
552 switch (response) {
553 case GTK_RESPONSE_OK:
555 self->loader_state = LOADER_STATE_INIT;
556 _loader_start(self, NULL);
557 /* Call set edited_theme_details functio */
558 _set_edited_theme_details(self);
560 rvalue = TRUE;
561 loop = FALSE;
563 break;
565 case GTK_RESPONSE_CANCEL:
566 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
567 _loader_stop(self);
569 loop = FALSE;
570 break;
572 default:
573 IRRECO_DEBUG("default\n");
574 break;
577 } while (loop);
579 gtk_widget_destroy(GTK_WIDGET(self));
581 IRRECO_RETURN_BOOL(rvalue);
586 static void
587 irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook,
588 GtkNotebookPage *page,
589 guint page_num,
590 IrrecoThemeCreatorDlg *self)
593 IRRECO_ENTER
595 switch (page_num){
597 case ABOUT:
598 gtk_widget_show(self->cancel_button);
599 gtk_widget_show(self->save_button);
600 gtk_widget_hide(self->add_button);
601 gtk_widget_hide(self->edit_button);
602 gtk_widget_hide(self->delete_button);
604 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
606 break;
607 case BUTTONS:
608 gtk_widget_hide(self->cancel_button);
609 gtk_widget_hide(self->save_button);
610 gtk_widget_show(self->add_button);
611 gtk_widget_show(self->edit_button);
612 gtk_widget_show(self->delete_button);
614 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
615 gtk_widget_show_all(GTK_WIDGET(self->buttons));
617 break;
618 case BACKGROUNDS:
619 gtk_widget_hide(self->cancel_button);
620 gtk_widget_hide(self->save_button);
621 gtk_widget_show(self->add_button);
622 gtk_widget_show(self->edit_button);
623 gtk_widget_show(self->delete_button);
625 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
626 gtk_widget_show_all(GTK_WIDGET(self->backgrounds));
628 break;
630 default:
631 IRRECO_DEBUG("default\n");
632 break;
634 IRRECO_RETURN
638 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
639 /* Events and Callbacks */
640 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
643 * @name Events and Callbacks
644 * @{
647 static void irreco_theme_creator_dlg_preview_image(GtkWidget *widget,
648 GdkEventButton *event,
649 IrrecoThemeCreatorDlg *self)
652 IrrecoThemeButton *preview_theme_button = NULL;
654 IRRECO_ENTER
655 if (self->theme != NULL) {
656 preview_theme_button = irreco_button_browser_dlg_run(
657 GTK_WINDOW(self),
658 self->irreco_data,
659 self->theme);
661 if(preview_theme_button) {
662 IRRECO_DEBUG("Set preview button to theme and self->\n");
664 self->preview_name = preview_theme_button->image_up->str;
665 self->preview_button = preview_theme_button;
666 _set_preview(self);
669 IRRECO_RETURN
672 /** @} */
676 *Create new background or button
679 static void irreco_theme_creator_dlg_new_bg_button(GtkButton *button,
680 IrrecoThemeCreatorDlg *self)
683 IRRECO_ENTER
684 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
685 self->notebook))==BACKGROUNDS) {
687 IrrecoThemeBg *new_bg = NULL;
688 new_bg = irreco_theme_bg_new();
690 if (irreco_background_creator_dlg_run(self->irreco_data,
691 self->theme,
692 GTK_WINDOW(self), new_bg)) {
693 irreco_string_table_add(self->theme->backgrounds,
694 new_bg->image_name->str,
695 new_bg);
696 irreco_theme_creator_backgrounds_refresh(
697 IRRECO_THEME_CREATOR_BACKGROUNDS(
698 self->backgrounds));
699 /*irreco_theme_bg_free(new_bg);*/
700 } else {
701 /*irreco_theme_bg_free(new_bg);*/
703 } else {
704 IrrecoThemeButton *new_button = NULL;
705 new_button = irreco_theme_button_new(NULL);
707 if (irreco_button_creator_dlg_run(self->irreco_data, self->theme,
708 GTK_WINDOW(self), new_button)) {
709 irreco_string_table_add(self->theme->buttons,
710 new_button->name->str,
711 new_button);
712 irreco_theme_creator_buttons_refresh(
713 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
714 /*irreco_theme_button_free(new_button);*/
715 } else {
716 /*irreco_theme_button_free(new_button);*/
720 IRRECO_RETURN
724 *Create edit background or button
727 static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button,
728 IrrecoThemeCreatorDlg *self)
730 IRRECO_ENTER
731 /* Check which page */
732 /* Edit bg */
733 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
734 self->notebook)) == BACKGROUNDS) {
736 IrrecoThemeBg *bg = NULL;
737 IrrecoThemeBg *new_bg = NULL;
738 IrrecoThemeBg *old_bg = NULL;
740 bg = irreco_theme_creator_backgrounds_get_selected_bg(
741 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
742 /* check whether the background image of the selected */
743 if (bg) {
744 new_bg = irreco_theme_bg_copy(bg);
746 IRRECO_PRINTF("Pointer: %p \n", (void*) self->theme);
748 if (irreco_background_creator_dlg_run(self->irreco_data,
749 self->theme,
750 GTK_WINDOW(self),
751 new_bg)) {
752 old_bg = irreco_theme_bg_copy(bg);
753 irreco_theme_bg_set(bg, new_bg->image_name->str,
754 new_bg->image_path->str);
755 /* check whether the bg strings changed */
756 _set_bg_new_details(self, old_bg, bg);
758 irreco_theme_creator_backgrounds_refresh(
759 IRRECO_THEME_CREATOR_BACKGROUNDS(
760 self->backgrounds));
761 } else {
765 } else
767 IRRECO_DEBUG("the background is not selected\n");
769 /* Edit Button */
770 } else {
771 IrrecoThemeButton *button = NULL;
772 IrrecoThemeButton *new_button = NULL;
773 IrrecoThemeButton *old_button = NULL;
775 button = irreco_theme_creator_buttons_get_selected_button(
776 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
777 /* check whether the button image of the selected */
778 if (button) {
779 new_button = irreco_theme_button_copy(button);
781 if (irreco_button_creator_dlg_run(self->irreco_data,
782 self->theme,
783 GTK_WINDOW(self),
784 new_button)) {
785 old_button = irreco_theme_button_copy(button);
786 irreco_theme_button_print(new_button);
787 irreco_theme_button_set(button,
788 new_button->style_name->str,
789 new_button->name->str,
790 new_button->allow_text,
791 new_button->image_up->str,
792 new_button->image_down->str,
793 new_button->text_format_up->str,
794 new_button->text_format_down->str,
795 new_button->text_padding,
796 new_button->text_h_align,
797 new_button->text_v_align);
798 /* Check Button details and set again */
799 _set_button_new_details(self, old_button, button);
802 irreco_theme_creator_buttons_refresh(
803 IRRECO_THEME_CREATOR_BUTTONS(
804 self->buttons));
805 /*irreco_theme_button_free(new_button);*/
806 } else {
807 /*irreco_theme_button_free(new_button);*/
809 } else {
810 IRRECO_DEBUG("the button is not selected\n");
813 IRRECO_RETURN
815 void _set_bg_new_details(IrrecoThemeCreatorDlg *self,
816 IrrecoThemeBg *old_bg,
817 IrrecoThemeBg *bg)
820 IRRECO_ENTER
821 if (!(g_str_equal(old_bg->image_name->str, bg->image_name->str))) {
822 irreco_string_table_change_key(self->theme->backgrounds,
823 old_bg->image_name->str,
824 bg->image_name->str);
825 } else {
826 IRRECO_DEBUG("BG_NAME is same");
828 if (!(g_str_equal(old_bg->image_path->str, bg->image_path->str))) {
829 irreco_string_table_change_key(self->theme->backgrounds,
830 old_bg->image_path->str,
831 bg->image_path->str);
832 } else {
833 IRRECO_DEBUG("BG_PATH is same");
836 IRRECO_RETURN
838 void _set_button_new_details(IrrecoThemeCreatorDlg *self,
839 IrrecoThemeButton *old_button,
840 IrrecoThemeButton *button)
843 IRRECO_ENTER
844 if (!(g_str_equal(old_button->style_name->str,
845 button->style_name->str))) {
846 irreco_string_table_change_key(self->theme->buttons,
847 old_button->style_name->str,
848 button->style_name->str);
849 } else {
850 IRRECO_DEBUG("BUTTON_STYLE_NAME is the same\n");
852 if (!(g_str_equal(old_button->name->str, button->name->str))) {
853 irreco_string_table_change_key(self->theme->buttons,
854 old_button->name->str,
855 button->name->str);
856 } else {
857 IRRECO_DEBUG("BUTTON_NAME is the same\n");
859 if (!(g_str_equal(old_button->image_up->str, button->image_up->str))) {
860 irreco_string_table_change_key(self->theme->buttons,
861 old_button->image_up->str,
862 button->image_up->str);
863 } else {
864 IRRECO_DEBUG("String is the same\n");
866 if (!(g_str_equal(old_button->image_down->str,
867 button->image_down->str))) {
868 irreco_string_table_change_key(self->theme->buttons,
869 old_button->image_down->str,
870 button->image_down->str);
871 } else {
872 IRRECO_DEBUG("String is the same\n");
874 if (!(g_str_equal(old_button->text_format_up->str,
875 button->text_format_up->str))) {
876 irreco_string_table_change_key(self->theme->buttons,
877 old_button->text_format_up->str,
878 button->text_format_up->str);
879 } else {
880 IRRECO_DEBUG("String is the same\n");
882 if (!(g_str_equal(old_button->text_format_up->str,
883 button->text_format_up->str))) {
884 irreco_string_table_change_key(self->theme->buttons,
885 old_button->text_format_up->str,
886 button->text_format_up->str);
887 } else {
888 IRRECO_DEBUG("String is the same\n");
890 if (!(g_str_equal(old_button->text_format_down->str,
891 button->text_format_down->str))) {
892 irreco_string_table_change_key(self->theme->buttons,
893 old_button->text_format_down->str,
894 button->text_format_down->str);
895 } else {
896 IRRECO_DEBUG("String is the same\n");
898 if (old_button->allow_text == button->allow_text) {
899 irreco_string_table_change_key(self->theme->buttons,
900 g_strdup_printf("%d",
901 old_button->allow_text),
902 g_strdup_printf("%d",
903 button->allow_text));
904 } else {
905 IRRECO_DEBUG("Value is the same\n");
907 if (old_button->text_padding == button->text_padding) {
908 irreco_string_table_change_key(self->theme->buttons,
909 g_strdup_printf("%d",
910 old_button->text_padding),
911 g_strdup_printf("%d",
912 button->text_padding));
913 } else {
914 IRRECO_DEBUG("Value is the same\n");
916 if (old_button->text_h_align == button->text_h_align) {
917 irreco_string_table_change_key(self->theme->buttons,
918 g_strdup_printf("%f",
919 old_button->text_h_align),
920 g_strdup_printf("%f",
921 button->text_h_align));
922 } else {
923 IRRECO_DEBUG("Value is the same\n");
925 if (old_button->text_v_align == button->text_v_align) {
926 irreco_string_table_change_key(self->theme->buttons,
927 g_strdup_printf("%f",
928 old_button->text_v_align),
929 g_strdup_printf("%f",
930 button->text_v_align));
931 } else {
932 IRRECO_DEBUG("Value is the same\n");
934 IRRECO_RETURN
937 static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button,
938 IrrecoThemeCreatorDlg *self)
941 IRRECO_ENTER
944 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
945 self->notebook)) == BACKGROUNDS) {
946 IrrecoThemeBg *bg;
947 bg = irreco_theme_creator_backgrounds_get_selected_bg(
948 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
949 if (irreco_theme_creator_backgrounds_remove_selected(
950 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds))) {
951 irreco_string_table_remove((self->theme)->backgrounds,
952 bg->image_name->str);
954 } else {
955 IrrecoThemeButton *button;
956 button = irreco_theme_creator_buttons_get_selected_button(
957 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
958 if (irreco_theme_creator_buttons_remove_selected(
959 IRRECO_THEME_CREATOR_BUTTONS(self->buttons))) {
960 irreco_string_table_remove((self->theme)->buttons,
961 button->name->str);
966 IRRECO_RETURN