Mostly minor fixes up until version 0.8.10.
[irreco.git] / irreco / src / core / irreco_theme_creator_dlg.c
blob42f0007988acb03e6c4a1646b3c712ef1f09927a
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 */
122 IrrecoThemeCreatorDlg *self;
123 /*About widgets*/
124 GtkWidget *scrolled_table;
125 GtkWidget *table_about;
126 GtkWidget *label_author;
127 GtkWidget *label_name;
128 GtkWidget *frame_comments;
129 GtkWidget *scrolled_comments;
131 GtkWidget *preview_button_frame;
135 IRRECO_ENTER
137 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->constructed(object);
138 self = IRRECO_THEME_CREATOR_DLG(object);
139 /* Construct dialog. */
140 gtk_window_set_title(GTK_WINDOW(self), _("Create a Theme"));
141 gtk_window_set_modal(GTK_WINDOW(self), TRUE);
142 gtk_window_set_destroy_with_parent(GTK_WINDOW(self), TRUE);
143 gtk_dialog_set_has_separator(GTK_DIALOG(self), FALSE);
145 /*Buttons*/
146 self->save_button = gtk_dialog_add_button (GTK_DIALOG(self),
147 _("Save"),
148 GTK_RESPONSE_OK);
149 self->add_button = gtk_dialog_add_button (GTK_DIALOG(self),
150 _("Add"), GTK_RESPONSE_NONE);
151 self->edit_button = gtk_dialog_add_button (GTK_DIALOG(self),
152 _("Edit"),
153 GTK_RESPONSE_NONE);
154 self->delete_button = gtk_dialog_add_button (GTK_DIALOG(self),
155 _("Delete"),
156 GTK_RESPONSE_NONE);
158 /* Create widgets. */
159 self->notebook = gtk_notebook_new();
161 /* ABOUT*/
163 scrolled_table = gtk_scrolled_window_new(NULL, NULL);
164 table_about = gtk_table_new(7, 9, FALSE);
165 label_author = gtk_label_new(_("Author:"));
166 label_name = gtk_label_new(_("Name: "));
167 self->entry_author = gtk_entry_new();
168 self->entry_name = gtk_entry_new();
169 frame_comments = gtk_frame_new("");
170 scrolled_comments = gtk_scrolled_window_new(NULL, NULL);
171 self->textview_comments = gtk_text_view_new();
172 preview_button_frame = gtk_frame_new("");
173 self->preview_event_box = gtk_event_box_new();
174 self->preview_image = gtk_image_new();
175 gtk_image_set_from_file(GTK_IMAGE(self->preview_image), NULL);
176 self->hbox_backgrounds = gtk_hbox_new(FALSE, 2);
177 self->hbox_buttons = gtk_hbox_new(FALSE, 2);
179 /* equal to the text of the left-side */
180 gtk_misc_set_alignment(GTK_MISC(label_name), 0, 0.5);
181 gtk_misc_set_alignment(GTK_MISC(label_author), 0, 0.5);
184 /* Set frame text bold */
185 gtk_frame_set_label_widget(GTK_FRAME(frame_comments),
186 irreco_gtk_label_bold(
187 "Comments", 0, 0, 0, 0, 0, 0));
188 gtk_frame_set_label_widget(GTK_FRAME(preview_button_frame),
189 irreco_gtk_label_bold(
190 "Preview button", 0, 0, 0, 0, 0, 0));
192 /* Set table on the scrolled */
193 /*gtk_container_add(GTK_CONTAINER(scrolled_table),
194 table_about);*/
196 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
197 scrolled_table),
198 GTK_WIDGET(self->notebook));
200 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_table),
201 GTK_POLICY_NEVER,
202 GTK_POLICY_AUTOMATIC);
204 /* Create Notebook tabs. */
206 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
207 irreco_gtk_align(GTK_WIDGET(table_about),
208 0, 0, 1, 1, 8, 8, 8, 8),
209 gtk_label_new("About"));
210 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
211 irreco_gtk_align(GTK_WIDGET(self->hbox_buttons),
212 0, 0, 1, 1, 8, 8, 8, 8),
213 gtk_label_new("Buttons"));
214 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
215 irreco_gtk_align(GTK_WIDGET(
216 self->hbox_backgrounds),
217 0, 0, 1, 1, 8, 8, 8, 8),
218 gtk_label_new("Backgrounds"));
220 /*gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox),
221 scrolled_table);*/
223 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(self)->vbox),
224 scrolled_table,
225 TRUE,
226 TRUE,
229 /* Set widgets on the table_about */
231 gtk_table_set_row_spacings(GTK_TABLE(table_about), 6);
232 gtk_table_set_col_spacings(GTK_TABLE(table_about), 6);
234 gtk_table_attach_defaults(GTK_TABLE(table_about),
235 label_author, 0, 2, 0, 1);
236 gtk_table_attach_defaults(GTK_TABLE(table_about),
237 label_name, 0, 2, 1, 2);
238 gtk_table_attach_defaults(GTK_TABLE(table_about),
239 self->entry_author, 2, 9, 0, 1);
240 gtk_table_attach_defaults(GTK_TABLE(table_about),
241 self->entry_name, 2, 9, 1, 2);
242 /*gtk_table_attach_defaults(GTK_TABLE(table_about),
243 frame_comments, 0, 6, 2, 7);
244 gtk_table_attach_defaults(GTK_TABLE(table_about),
245 preview_button_frame, 6, 9, 2, 7);*/
246 gtk_table_attach(GTK_TABLE(table_about), frame_comments, 0, 6, 2, 7,
247 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
248 gtk_table_attach(GTK_TABLE(table_about), preview_button_frame, 6, 9, 2, 7,
249 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
251 /*ABOUT*/
252 /* set preview image*/
253 gtk_container_add(GTK_CONTAINER(preview_button_frame),
254 self->preview_event_box);
255 gtk_container_add(GTK_CONTAINER(self->preview_event_box),
256 self->preview_image);
258 /* TEXTVIEW */
259 /* set max size of frame */
260 gtk_widget_set(frame_comments,
261 "width-request",
262 370,
263 NULL);
264 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self->textview_comments),
265 GTK_WRAP_WORD_CHAR);
267 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_comments),
268 GTK_POLICY_NEVER,
269 GTK_POLICY_AUTOMATIC);
271 gtk_container_add(GTK_CONTAINER(frame_comments), scrolled_comments);
272 gtk_container_add(GTK_CONTAINER(scrolled_comments),
273 self->textview_comments);
275 /* Signal handlers. */
277 g_signal_connect(G_OBJECT(self->notebook), "switch-page",
278 G_CALLBACK(irreco_theme_creator_dlg_notebook_changed),
279 self);
281 g_signal_connect(G_OBJECT(self->preview_event_box),
282 "button-release-event",
283 G_CALLBACK(irreco_theme_creator_dlg_preview_image),
284 self);
286 g_signal_connect(G_OBJECT(self->add_button), "clicked",
287 G_CALLBACK(irreco_theme_creator_dlg_new_bg_button),
288 self);
289 g_signal_connect(G_OBJECT(self->edit_button), "clicked",
290 G_CALLBACK(irreco_theme_creator_dlg_edit_bg_button),
291 self);
292 g_signal_connect(G_OBJECT(self->delete_button), "clicked",
293 G_CALLBACK(irreco_theme_creator_dlg_delete_bg_button),
294 self);
295 gtk_window_set_default_size(GTK_WINDOW(self), 680, 355);
296 /*gtk_widget_set_size_request(GTK_WIDGET(self), 696, 396);*/
297 gtk_widget_show_all(GTK_WIDGET(self));
298 IRRECO_RETURN
301 static void irreco_theme_creator_dlg_init(IrrecoThemeCreatorDlg *self)
303 IRRECO_ENTER
304 IRRECO_RETURN
307 static void irreco_theme_creator_dlg_finalize(GObject *object)
309 IrrecoThemeCreatorDlg *self;
310 IRRECO_ENTER
312 self = IRRECO_THEME_CREATOR_DLG(object);
314 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->finalize(object);
315 IRRECO_RETURN
318 static void
319 irreco_theme_creator_dlg_class_init(IrrecoThemeCreatorDlgClass *klass)
321 GObjectClass* object_class = G_OBJECT_CLASS (klass);
323 object_class->finalize = irreco_theme_creator_dlg_finalize;
324 object_class->constructed = irreco_theme_creator_dlg_constructed;
328 GtkWidget
329 *irreco_theme_creator_dlg_new(IrrecoData *irreco_data, GtkWindow *parent)
331 IrrecoThemeCreatorDlg *self;
333 IRRECO_ENTER
334 self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG,
335 "irreco-data", irreco_data,
336 NULL);
337 /*self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, NULL);*/
338 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
340 IRRECO_RETURN_PTR(self);
343 /** @} */
345 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
346 /* Private Functions */
347 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
349 * @name Private Functions
350 * @{
354 * Start a loader state machine if one is not running already.
356 static void _loader_start(IrrecoThemeCreatorDlg *self, GSourceFunc function)
358 IRRECO_ENTER
360 if (self->loader_func_id == 0) {
361 self->loader_func_id = g_idle_add((GSourceFunc)function, self);
364 IRRECO_RETURN
368 * Stop and cleanup loader if a loader is running.
370 static void _loader_stop(IrrecoThemeCreatorDlg *self)
372 IRRECO_ENTER
373 /*_hide_banner(self);*/
374 if (self->loader_func_id != 0) {
375 g_source_remove(self->loader_func_id);
376 self->loader_func_id = 0;
377 self->loader_state = 0;
379 IRRECO_RETURN
382 static gboolean
383 irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self,
384 gint page)
387 IRRECO_ENTER
388 IRRECO_DEBUG("Page_nro %d\n", page);
389 IRRECO_RETURN_BOOL(TRUE);
394 * Sets the theme details
397 void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme)
400 IRRECO_ENTER
402 gtk_entry_set_text(GTK_ENTRY(self->entry_name),
403 self->theme->name->str);
404 gtk_entry_set_text(GTK_ENTRY(self->entry_author),
405 self->theme->author->str);
407 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
408 self->textview_comments));
409 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self->buffer_comments),
410 self->theme->comment->str,
411 -1);
412 self->backgrounds = irreco_theme_creator_backgrounds_new(
413 GTK_WINDOW(self),
414 self->irreco_data,
415 self->theme);
416 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
417 self->irreco_data,
418 self->theme);
419 /* Set window title */
420 gtk_window_set_title(GTK_WINDOW(self), _("Edit Theme"));
423 _set_preview(self);
425 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
426 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
427 self->backgrounds);
430 IRRECO_RETURN
433 void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self)
435 IRRECO_ENTER
437 self->backgrounds = irreco_theme_creator_backgrounds_new(
438 GTK_WINDOW(self),
439 self->irreco_data,
440 self->theme);
441 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
442 self->irreco_data,
443 self->theme);
445 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
446 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
447 self->backgrounds);
448 IRRECO_RETURN
452 * Update shown preview image
454 static void _set_preview(IrrecoThemeCreatorDlg *self)
456 IRRECO_ENTER
458 /* if theme contains preview image, use it, else get first button */
459 if(self->preview_name) {
460 IRRECO_DEBUG("Preview set in dlg, using it\n");
461 } else if(strlen(self->theme->preview_button_name->str) != 0) {
462 gchar *strtblkey;
463 IRRECO_DEBUG("Preview set to theme, using it\n");
464 strtblkey = g_strdup_printf("%s/%s", self->theme->name->str,
465 self->theme->preview_button_name->str);
466 IRRECO_DEBUG("STRTBKEY: %s\n", strtblkey);
467 if(irreco_string_table_get(self->theme->buttons, strtblkey,
468 (gpointer *) &self->preview_button)) {
469 self->preview_name = self->preview_button->image_up->str;
470 } else {
471 IRRECO_DEBUG("Theme preview set wrong\n");
473 } else {
474 const gchar *key;
475 IRRECO_DEBUG("No preview set, using first button of theme\n");
476 irreco_string_table_index(self->theme->buttons, 0, &key,
477 (gpointer *) &self->preview_button);
478 if(self->preview_button) {
479 self->preview_name = self->preview_button->image_up->str;
482 gtk_image_set_from_file(GTK_IMAGE(self->preview_image),
483 self->preview_name);
484 IRRECO_RETURN
487 void _set_edited_theme_details(IrrecoThemeCreatorDlg *self)
489 GtkTextIter startiter;
490 GtkTextIter enditer;
491 const gchar *name = NULL;
492 const gchar *author = NULL;
493 gchar *comment = NULL;
495 IRRECO_ENTER
497 name = gtk_entry_get_text(GTK_ENTRY(self->entry_name));
498 author = gtk_entry_get_text(GTK_ENTRY(self->entry_author));
501 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
502 self->textview_comments));
504 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(self->buffer_comments),
505 &startiter);
506 gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(self->buffer_comments),
507 &enditer);
508 comment = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(
509 self->buffer_comments),
510 &startiter,
511 &enditer,
512 FALSE);
513 /* Check whether preview button set */
514 if (self->preview_name == NULL) {
515 _set_preview(self);
517 irreco_theme_set(self->theme,
518 name,
519 NULL,
520 "user",
521 author,
522 comment,
523 self->preview_name,
524 NULL);
527 IRRECO_RETURN
530 gboolean
531 irreco_theme_creator_dlg_check_details(IrrecoThemeCreatorDlg *self)
534 gboolean rvalue = TRUE;
535 IRRECO_ENTER
536 /* check that there is at least one button */
537 if (!irreco_string_table_lenght(self->theme->buttons)) {
538 irreco_error_dlg(GTK_WINDOW(self),
539 "must be at least one button");
540 rvalue = FALSE;
541 } else if (strlen(gtk_entry_get_text(GTK_ENTRY(self->entry_name))) == 0) {
542 irreco_error_dlg(GTK_WINDOW(self),
543 "Name is missing");
544 rvalue = FALSE;
545 } else if (strlen(gtk_entry_get_text(GTK_ENTRY(self->entry_author))) == 0) {
546 irreco_error_dlg(GTK_WINDOW(self),
547 "Author is missing");
548 rvalue = FALSE;
551 IRRECO_RETURN_BOOL(rvalue);
553 /** @} */
555 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
556 /* Functions */
557 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
560 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
561 /* Public Functions */
562 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
563 gboolean
564 irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data,
565 IrrecoTheme *irreco_theme)
567 IrrecoThemeCreatorDlg *self;
568 gint response;
569 gboolean loop = TRUE;
570 gboolean rvalue = FALSE;
571 IRRECO_ENTER
573 self = (IrrecoThemeCreatorDlg*)irreco_theme_creator_dlg_new(irreco_data,
574 parent_window);
575 self->parent_window = GTK_WINDOW(self);
576 self->loader_func_id = 0;
577 self->irreco_data = irreco_data;
578 self->preview_name = NULL;
579 irreco_theme_print(irreco_theme);
580 self->theme = irreco_theme;
581 IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme);
582 IRRECO_DEBUG("Pointer: %p \n", (void*) irreco_theme);
584 /* Check whether the theme of a blank*/
585 if (irreco_string_table_lenght(irreco_theme->buttons) != 0) {
586 /* Sets the theme details */
587 _set_theme_details(self, irreco_theme);
588 } else {
589 /* create blank bg:s and buttons widgets */
590 _create_bg_and_button_widgets(self);
593 do {
594 response = gtk_dialog_run(GTK_DIALOG(self));
595 switch (response) {
596 case GTK_RESPONSE_OK:
598 self->loader_state = LOADER_STATE_INIT;
599 _loader_start(self, NULL);
600 /* Check theme details */
601 if (irreco_theme_creator_dlg_check_details(self)) {
602 /* Call set edited_theme_details functio */
603 _set_edited_theme_details(self);
605 /* Call ThemeSaveDlg */
606 if (irreco_theme_save_dlg_run(self->irreco_data,
607 irreco_theme, GTK_WINDOW(self))) {
608 rvalue = TRUE;
609 loop = FALSE;
610 } else {
611 rvalue = FALSE;
612 loop = TRUE;
614 } else {
615 rvalue = FALSE;
616 loop = TRUE;
618 break;
620 case GTK_RESPONSE_DELETE_EVENT:
621 IRRECO_DEBUG("GTK_RESPONSE_DELETE_EVENT\n");
622 _loader_stop(self);
624 loop = FALSE;
625 break;
627 default:
628 IRRECO_DEBUG("default\n");
629 break;
632 } while (loop);
634 gtk_widget_destroy(GTK_WIDGET(self));
636 IRRECO_RETURN_BOOL(rvalue);
639 static void
640 irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook,
641 GtkNotebookPage *page,
642 guint page_num,
643 IrrecoThemeCreatorDlg *self)
646 IRRECO_ENTER
648 switch (page_num){
650 case ABOUT:
651 /* gtk_widget_show(self->cancel_button);*/
652 gtk_widget_show(self->save_button);
653 gtk_widget_hide(self->add_button);
654 gtk_widget_hide(self->edit_button);
655 gtk_widget_hide(self->delete_button);
657 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
659 break;
660 case BUTTONS:
661 /* gtk_widget_hide(self->cancel_button);*/
662 gtk_widget_hide(self->save_button);
663 gtk_widget_show(self->add_button);
664 gtk_widget_show(self->edit_button);
665 gtk_widget_show(self->delete_button);
667 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
668 gtk_widget_show_all(GTK_WIDGET(self->buttons));
670 break;
671 case BACKGROUNDS:
672 /* gtk_widget_hide(self->cancel_button);*/
673 gtk_widget_hide(self->save_button);
674 gtk_widget_show(self->add_button);
675 gtk_widget_show(self->edit_button);
676 gtk_widget_show(self->delete_button);
678 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
679 gtk_widget_show_all(GTK_WIDGET(self->backgrounds));
681 break;
683 default:
684 IRRECO_DEBUG("default\n");
685 break;
687 IRRECO_RETURN
690 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
691 /* Events and Callbacks */
692 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
695 * @name Events and Callbacks
696 * @{
699 static void irreco_theme_creator_dlg_preview_image(GtkWidget *widget,
700 GdkEventButton *event,
701 IrrecoThemeCreatorDlg *self)
704 IrrecoThemeButton *preview_theme_button = NULL;
706 IRRECO_ENTER
707 if (self->theme != NULL) {
708 preview_theme_button = irreco_button_browser_dlg_run(
709 GTK_WINDOW(self),
710 self->irreco_data,
711 self->theme);
713 if(preview_theme_button) {
714 IRRECO_DEBUG("Set preview button to theme and self->\n");
716 self->preview_name = preview_theme_button->image_up->str;
717 self->preview_button = preview_theme_button;
718 _set_preview(self);
721 IRRECO_RETURN
724 /** @} */
727 *Create new background or button
730 static void irreco_theme_creator_dlg_new_bg_button(GtkButton *button,
731 IrrecoThemeCreatorDlg *self)
734 IRRECO_ENTER
735 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
736 self->notebook))==BACKGROUNDS) {
738 IrrecoThemeBg *new_bg = NULL;
739 new_bg = irreco_theme_bg_new();
741 if (irreco_background_creator_dlg_run(self->irreco_data,
742 self->theme,
743 GTK_WINDOW(self), new_bg)) {
744 irreco_string_table_add(self->theme->backgrounds,
745 new_bg->image_name->str,
746 new_bg);
747 irreco_theme_creator_backgrounds_refresh(
748 IRRECO_THEME_CREATOR_BACKGROUNDS(
749 self->backgrounds));
750 } else {
751 /*irreco_theme_bg_free(new_bg);*/
753 } else {
754 IrrecoThemeButton *new_button = NULL;
755 new_button = irreco_theme_button_new(NULL);
757 if (irreco_button_creator_dlg_run(self->irreco_data, self->theme,
758 GTK_WINDOW(self), new_button)) {
759 irreco_string_table_add(self->theme->buttons,
760 new_button->name->str,
761 new_button);
762 irreco_theme_creator_buttons_refresh(
763 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
764 } else {
765 /*irreco_theme_button_free(new_button);*/
768 IRRECO_RETURN
772 *Create edit background or button
775 static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button,
776 IrrecoThemeCreatorDlg *self)
778 IRRECO_ENTER
779 /* Check which page */
780 /* Edit bg */
781 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
782 self->notebook)) == BACKGROUNDS) {
784 IrrecoThemeBg *bg = NULL;
785 IrrecoThemeBg *new_bg = NULL;
786 IrrecoThemeBg *old_bg = NULL;
788 bg = irreco_theme_creator_backgrounds_get_selected_bg(
789 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
790 /* check whether the background image of the selected */
791 if (bg) {
792 new_bg = irreco_theme_bg_copy(bg);
794 IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme);
796 if (irreco_background_creator_dlg_run(self->irreco_data,
797 self->theme,
798 GTK_WINDOW(self),
799 new_bg)) {
800 old_bg = irreco_theme_bg_copy(bg);
801 irreco_theme_bg_set(bg, new_bg->image_name->str,
802 new_bg->image_path->str);
804 irreco_theme_creator_backgrounds_refresh(
805 IRRECO_THEME_CREATOR_BACKGROUNDS(
806 self->backgrounds));
808 irreco_theme_bg_free(new_bg);
810 } else
812 IRRECO_DEBUG("the background is not selected\n");
814 /* Edit Button */
815 } else {
816 IrrecoThemeButton *button = NULL;
817 IrrecoThemeButton *new_button = NULL;
818 IrrecoThemeButton *old_button = NULL;
820 button = irreco_theme_creator_buttons_get_selected_button(
821 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
822 /* check whether the button image of the selected */
823 if (button) {
824 new_button = irreco_theme_button_copy(button);
826 if (irreco_button_creator_dlg_run(self->irreco_data,
827 self->theme,
828 GTK_WINDOW(self),
829 new_button)) {
830 old_button = irreco_theme_button_copy(button);
831 irreco_theme_button_print(new_button);
832 irreco_theme_button_set_from_button(button,
833 new_button);
835 irreco_theme_button_print(old_button);
836 irreco_theme_button_print(button);
838 irreco_theme_creator_buttons_refresh(
839 IRRECO_THEME_CREATOR_BUTTONS(
840 self->buttons));
844 irreco_theme_button_free(new_button);
845 } else {
846 IRRECO_DEBUG("the button is not selected\n");
849 IRRECO_RETURN
852 static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button,
853 IrrecoThemeCreatorDlg *self)
855 IRRECO_ENTER
857 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
858 self->notebook)) == BACKGROUNDS) {
859 IrrecoThemeBg *bg;
860 bg = irreco_theme_creator_backgrounds_get_selected_bg(
861 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
863 if (bg !=NULL) {
864 if (irreco_theme_creator_backgrounds_remove_selected(
865 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds))) {
866 irreco_string_table_remove((self->theme)->backgrounds,
867 bg->image_name->str);
870 } else {
871 IrrecoThemeButton *button;
872 button = irreco_theme_creator_buttons_get_selected_button(
873 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
874 if (button !=NULL) {
875 if (irreco_theme_creator_buttons_remove_selected(
876 IRRECO_THEME_CREATOR_BUTTONS(self->buttons))) {
877 irreco_string_table_remove((self->theme)->buttons,
878 button->style_name->str);
881 self->preview_name = NULL;
882 g_string_printf(self->theme->preview_button_name, "%s", "");
886 IRRECO_RETURN