clean code and changed version nro.
[irreco.git] / irreco / src / core / irreco_theme_creator_dlg.c
blob9315b369eeb5255e93ade52c95a03e8b93c17855
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->cancel_button = gtk_dialog_add_button (GTK_DIALOG(self),
147 _("Cancel"),
148 GTK_RESPONSE_CANCEL);
149 self->save_button = gtk_dialog_add_button (GTK_DIALOG(self),
150 _("Save"),
151 GTK_RESPONSE_OK);
152 self->add_button = gtk_dialog_add_button (GTK_DIALOG(self),
153 _("Add"), GTK_RESPONSE_NONE);
154 self->edit_button = gtk_dialog_add_button (GTK_DIALOG(self),
155 _("Edit"),
156 GTK_RESPONSE_NONE);
157 self->delete_button = gtk_dialog_add_button (GTK_DIALOG(self),
158 _("Delete"),
159 GTK_RESPONSE_NONE);
161 /* Create widgets. */
162 self->notebook = gtk_notebook_new();
164 /* ABOUT*/
166 scrolled_table = gtk_scrolled_window_new(NULL, NULL);
167 table_about = gtk_table_new(7, 9, FALSE);
168 label_author = gtk_label_new(_("Author:"));
169 label_name = gtk_label_new(_("Name: "));
170 self->entry_author = gtk_entry_new();
171 self->entry_name = gtk_entry_new();
172 frame_comments = gtk_frame_new("");
173 scrolled_comments = gtk_scrolled_window_new(NULL, NULL);
174 self->textview_comments = gtk_text_view_new();
175 preview_button_frame = gtk_frame_new("");
176 self->preview_event_box = gtk_event_box_new();
177 self->preview_image = gtk_image_new();
178 gtk_image_set_from_file(GTK_IMAGE(self->preview_image), NULL);
179 self->hbox_backgrounds = gtk_hbox_new(FALSE, 2);
180 self->hbox_buttons = gtk_hbox_new(FALSE, 2);
182 /* equal to the text of the left-side */
183 gtk_misc_set_alignment(GTK_MISC(label_name), 0, 0.5);
184 gtk_misc_set_alignment(GTK_MISC(label_author), 0, 0.5);
187 /* Set frame text bold */
188 gtk_frame_set_label_widget(GTK_FRAME(frame_comments),
189 irreco_gtk_label_bold(
190 "Comments", 0, 0, 0, 0, 0, 0));
191 gtk_frame_set_label_widget(GTK_FRAME(preview_button_frame),
192 irreco_gtk_label_bold(
193 "Preview button", 0, 0, 0, 0, 0, 0));
195 /* Set table on the scrolled */
196 /*gtk_container_add(GTK_CONTAINER(scrolled_table),
197 table_about);*/
199 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
200 scrolled_table),
201 GTK_WIDGET(self->notebook));
203 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_table),
204 GTK_POLICY_NEVER,
205 GTK_POLICY_AUTOMATIC);
207 /* Create Notebook tabs. */
209 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
210 irreco_gtk_align(GTK_WIDGET(table_about),
211 0, 0, 1, 1, 8, 8, 8, 8),
212 gtk_label_new("About"));
213 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
214 irreco_gtk_align(GTK_WIDGET(self->hbox_buttons),
215 0, 0, 1, 1, 8, 8, 8, 8),
216 gtk_label_new("Buttons"));
217 gtk_notebook_append_page(GTK_NOTEBOOK(self->notebook),
218 irreco_gtk_align(GTK_WIDGET(
219 self->hbox_backgrounds),
220 0, 0, 1, 1, 8, 8, 8, 8),
221 gtk_label_new("Backgrounds"));
223 /*gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self)->vbox),
224 scrolled_table);*/
226 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(self)->vbox),
227 scrolled_table,
228 TRUE,
229 TRUE,
232 /* Set widgets on the table_about */
234 gtk_table_set_row_spacings(GTK_TABLE(table_about), 6);
235 gtk_table_set_col_spacings(GTK_TABLE(table_about), 6);
237 gtk_table_attach_defaults(GTK_TABLE(table_about),
238 label_author, 0, 2, 0, 1);
239 gtk_table_attach_defaults(GTK_TABLE(table_about),
240 label_name, 0, 2, 1, 2);
241 gtk_table_attach_defaults(GTK_TABLE(table_about),
242 self->entry_author, 2, 9, 0, 1);
243 gtk_table_attach_defaults(GTK_TABLE(table_about),
244 self->entry_name, 2, 9, 1, 2);
245 /*gtk_table_attach_defaults(GTK_TABLE(table_about),
246 frame_comments, 0, 6, 2, 7);
247 gtk_table_attach_defaults(GTK_TABLE(table_about),
248 preview_button_frame, 6, 9, 2, 7);*/
249 gtk_table_attach(GTK_TABLE(table_about), frame_comments, 0, 6, 2, 7,
250 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
251 gtk_table_attach(GTK_TABLE(table_about), preview_button_frame, 6, 9, 2, 7,
252 GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);
254 /*ABOUT*/
255 /* set preview image*/
256 gtk_container_add(GTK_CONTAINER(preview_button_frame),
257 self->preview_event_box);
258 gtk_container_add(GTK_CONTAINER(self->preview_event_box),
259 self->preview_image);
261 /* TEXTVIEW */
262 /* set max size of frame */
263 gtk_widget_set(frame_comments,
264 "width-request",
265 370,
266 NULL);
267 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(self->textview_comments),
268 GTK_WRAP_WORD_CHAR);
270 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_comments),
271 GTK_POLICY_NEVER,
272 GTK_POLICY_AUTOMATIC);
274 gtk_container_add(GTK_CONTAINER(frame_comments), scrolled_comments);
275 gtk_container_add(GTK_CONTAINER(scrolled_comments),
276 self->textview_comments);
278 /* Signal handlers. */
280 g_signal_connect(G_OBJECT(self->notebook), "switch-page",
281 G_CALLBACK(irreco_theme_creator_dlg_notebook_changed),
282 self);
284 g_signal_connect(G_OBJECT(self->preview_event_box),
285 "button-release-event",
286 G_CALLBACK(irreco_theme_creator_dlg_preview_image),
287 self);
289 g_signal_connect(G_OBJECT(self->add_button), "clicked",
290 G_CALLBACK(irreco_theme_creator_dlg_new_bg_button),
291 self);
292 g_signal_connect(G_OBJECT(self->edit_button), "clicked",
293 G_CALLBACK(irreco_theme_creator_dlg_edit_bg_button),
294 self);
295 g_signal_connect(G_OBJECT(self->delete_button), "clicked",
296 G_CALLBACK(irreco_theme_creator_dlg_delete_bg_button),
297 self);
298 gtk_window_set_default_size(GTK_WINDOW(self), 680, 396);
299 /*gtk_widget_set_size_request(GTK_WIDGET(self), 696, 396);*/
300 gtk_widget_show_all(GTK_WIDGET(self));
301 IRRECO_RETURN
304 static void irreco_theme_creator_dlg_init(IrrecoThemeCreatorDlg *self)
306 IRRECO_ENTER
307 IRRECO_RETURN
310 static void irreco_theme_creator_dlg_finalize(GObject *object)
312 IrrecoThemeCreatorDlg *self;
313 IRRECO_ENTER
315 self = IRRECO_THEME_CREATOR_DLG(object);
317 G_OBJECT_CLASS(irreco_theme_creator_dlg_parent_class)->finalize(object);
318 IRRECO_RETURN
321 static void
322 irreco_theme_creator_dlg_class_init(IrrecoThemeCreatorDlgClass *klass)
324 GObjectClass* object_class = G_OBJECT_CLASS (klass);
326 object_class->finalize = irreco_theme_creator_dlg_finalize;
327 object_class->constructed = irreco_theme_creator_dlg_constructed;
331 GtkWidget
332 *irreco_theme_creator_dlg_new(IrrecoData *irreco_data, GtkWindow *parent)
334 IrrecoThemeCreatorDlg *self;
336 IRRECO_ENTER
337 self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG,
338 "irreco-data", irreco_data,
339 NULL);
340 /*self = g_object_new(IRRECO_TYPE_THEME_CREATOR_DLG, NULL);*/
341 irreco_dlg_set_parent(IRRECO_DLG(self), parent);
343 IRRECO_RETURN_PTR(self);
346 /** @} */
348 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
349 /* Private Functions */
350 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
352 * @name Private Functions
353 * @{
357 * Start a loader state machine if one is not running already.
359 static void _loader_start(IrrecoThemeCreatorDlg *self, GSourceFunc function)
361 IRRECO_ENTER
363 if (self->loader_func_id == 0) {
364 self->loader_func_id = g_idle_add((GSourceFunc)function, self);
367 IRRECO_RETURN
371 * Stop and cleanup loader if a loader is running.
373 static void _loader_stop(IrrecoThemeCreatorDlg *self)
375 IRRECO_ENTER
376 /*_hide_banner(self);*/
377 if (self->loader_func_id != 0) {
378 g_source_remove(self->loader_func_id);
379 self->loader_func_id = 0;
380 self->loader_state = 0;
382 IRRECO_RETURN
385 static gboolean
386 irreco_theme_creator_dlg_display_theme_detail(IrrecoThemeCreatorDlg *self,
387 gint page)
390 IRRECO_ENTER
391 IRRECO_DEBUG("Page_nro %d\n", page);
392 IRRECO_RETURN_BOOL(TRUE);
397 * Sets the theme details
400 void _set_theme_details(IrrecoThemeCreatorDlg *self, IrrecoTheme *irreco_theme)
403 IRRECO_ENTER
405 gtk_entry_set_text(GTK_ENTRY(self->entry_name),
406 self->theme->name->str);
407 gtk_entry_set_text(GTK_ENTRY(self->entry_author),
408 self->theme->author->str);
410 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
411 self->textview_comments));
412 gtk_text_buffer_set_text(GTK_TEXT_BUFFER(self->buffer_comments),
413 self->theme->comment->str,
414 -1);
415 self->backgrounds = irreco_theme_creator_backgrounds_new(
416 GTK_WINDOW(self),
417 self->irreco_data,
418 self->theme);
419 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
420 self->irreco_data,
421 self->theme);
422 /* Set window title */
423 gtk_window_set_title(GTK_WINDOW(self), _("Edit Theme"));
426 _set_preview(self);
428 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
429 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
430 self->backgrounds);
433 IRRECO_RETURN
436 void _create_bg_and_button_widgets(IrrecoThemeCreatorDlg *self)
438 IRRECO_ENTER
440 self->backgrounds = irreco_theme_creator_backgrounds_new(
441 GTK_WINDOW(self),
442 self->irreco_data,
443 self->theme);
444 self->buttons = irreco_theme_creator_buttons_new(GTK_WINDOW(self),
445 self->irreco_data,
446 self->theme);
448 gtk_container_add(GTK_CONTAINER(self->hbox_buttons), self->buttons);
449 gtk_container_add(GTK_CONTAINER(self->hbox_backgrounds),
450 self->backgrounds);
451 IRRECO_RETURN
455 * Update shown preview image
457 static void _set_preview(IrrecoThemeCreatorDlg *self)
459 IRRECO_ENTER
461 /* if theme contains preview image, use it, else get first button */
462 if(self->preview_name) {
463 IRRECO_DEBUG("Preview set in dlg, using it\n");
464 } else if(strlen(self->theme->preview_button_name->str) != 0) {
465 gchar *strtblkey;
466 IRRECO_DEBUG("Preview set to theme, using it\n");
467 strtblkey = g_strdup_printf("%s/%s", self->theme->name->str,
468 self->theme->preview_button_name->str);
469 IRRECO_DEBUG("STRTBKEY: %s\n", strtblkey);
470 if(irreco_string_table_get(self->theme->buttons, strtblkey,
471 (gpointer *) &self->preview_button)) {
472 self->preview_name = self->preview_button->image_up->str;
473 } else {
474 IRRECO_DEBUG("Theme preview set wrong\n");
476 } else {
477 const gchar *key;
478 IRRECO_DEBUG("No preview set, using first button of theme\n");
479 irreco_string_table_index(self->theme->buttons, 0, &key,
480 (gpointer *) &self->preview_button);
481 if(self->preview_button) {
482 self->preview_name = self->preview_button->image_up->str;
485 gtk_image_set_from_file(GTK_IMAGE(self->preview_image),
486 self->preview_name);
487 IRRECO_RETURN
490 void _set_edited_theme_details(IrrecoThemeCreatorDlg *self)
492 GtkTextIter startiter;
493 GtkTextIter enditer;
494 const gchar *name = NULL;
495 const gchar *author = NULL;
496 gchar *comment = NULL;
498 IRRECO_ENTER
500 name = gtk_entry_get_text(GTK_ENTRY(self->entry_name));
501 author = gtk_entry_get_text(GTK_ENTRY(self->entry_author));
504 self->buffer_comments = gtk_text_view_get_buffer(GTK_TEXT_VIEW(
505 self->textview_comments));
507 gtk_text_buffer_get_start_iter(GTK_TEXT_BUFFER(self->buffer_comments),
508 &startiter);
509 gtk_text_buffer_get_end_iter(GTK_TEXT_BUFFER(self->buffer_comments),
510 &enditer);
511 comment = gtk_text_buffer_get_text(GTK_TEXT_BUFFER(
512 self->buffer_comments),
513 &startiter,
514 &enditer,
515 FALSE);
516 /* Check whether preview button set */
517 if (self->preview_name == NULL) {
518 _set_preview(self);
520 irreco_theme_set(self->theme,
521 name,
522 NULL,
523 "user",
524 author,
525 comment,
526 self->preview_name,
527 NULL);
530 IRRECO_RETURN
533 gboolean
534 irreco_theme_creator_dlg_check_details(IrrecoThemeCreatorDlg *self)
537 gboolean rvalue = TRUE;
538 IRRECO_ENTER
539 /* check that there is at least one button */
540 if (!irreco_string_table_lenght(self->theme->buttons)) {
541 irreco_error_dlg(GTK_WINDOW(self),
542 "must be at least one button");
543 rvalue = FALSE;
544 } else if (strlen(gtk_entry_get_text(GTK_ENTRY(self->entry_name))) == 0) {
545 irreco_error_dlg(GTK_WINDOW(self),
546 "Name is missing");
547 rvalue = FALSE;
548 } else if (strlen(gtk_entry_get_text(GTK_ENTRY(self->entry_author))) == 0) {
549 irreco_error_dlg(GTK_WINDOW(self),
550 "Author is missing");
551 rvalue = FALSE;
554 IRRECO_RETURN_BOOL(rvalue);
556 /** @} */
558 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
559 /* Functions */
560 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
563 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
564 /* Public Functions */
565 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
566 gboolean
567 irreco_theme_creator_dlg_run(GtkWindow *parent_window, IrrecoData *irreco_data,
568 IrrecoTheme *irreco_theme)
570 IrrecoThemeCreatorDlg *self;
571 gint response;
572 gboolean loop = TRUE;
573 gboolean rvalue = FALSE;
574 IRRECO_ENTER
576 self = (IrrecoThemeCreatorDlg*)irreco_theme_creator_dlg_new(irreco_data,
577 parent_window);
578 self->parent_window = GTK_WINDOW(self);
579 self->loader_func_id = 0;
580 self->irreco_data = irreco_data;
581 self->preview_name = NULL;
582 irreco_theme_print(irreco_theme);
583 self->theme = irreco_theme;
584 IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme);
585 IRRECO_DEBUG("Pointer: %p \n", (void*) irreco_theme);
587 /* Check whether the theme of a blank*/
588 if (irreco_string_table_lenght(irreco_theme->buttons) != 0) {
589 /* Sets the theme details */
590 _set_theme_details(self, irreco_theme);
591 } else {
592 /* create blank bg:s and buttons widgets */
593 _create_bg_and_button_widgets(self);
596 do {
597 response = gtk_dialog_run(GTK_DIALOG(self));
598 switch (response) {
599 case GTK_RESPONSE_OK:
601 self->loader_state = LOADER_STATE_INIT;
602 _loader_start(self, NULL);
603 /* Check theme details */
604 if (irreco_theme_creator_dlg_check_details(self)) {
605 /* Call set edited_theme_details functio */
606 _set_edited_theme_details(self);
608 /* Call ThemeSaveDlg */
609 if (irreco_theme_save_dlg_run(self->irreco_data,
610 irreco_theme, GTK_WINDOW(self))) {
611 rvalue = TRUE;
612 loop = FALSE;
613 } else {
614 rvalue = FALSE;
615 loop = TRUE;
617 } else {
618 rvalue = FALSE;
619 loop = TRUE;
621 break;
623 case GTK_RESPONSE_CANCEL:
624 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
625 _loader_stop(self);
627 loop = FALSE;
628 break;
630 default:
631 IRRECO_DEBUG("default\n");
632 break;
635 } while (loop);
637 gtk_widget_destroy(GTK_WIDGET(self));
639 IRRECO_RETURN_BOOL(rvalue);
642 static void
643 irreco_theme_creator_dlg_notebook_changed(GtkNotebook *notebook,
644 GtkNotebookPage *page,
645 guint page_num,
646 IrrecoThemeCreatorDlg *self)
649 IRRECO_ENTER
651 switch (page_num){
653 case ABOUT:
654 gtk_widget_show(self->cancel_button);
655 gtk_widget_show(self->save_button);
656 gtk_widget_hide(self->add_button);
657 gtk_widget_hide(self->edit_button);
658 gtk_widget_hide(self->delete_button);
660 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
662 break;
663 case BUTTONS:
664 gtk_widget_hide(self->cancel_button);
665 gtk_widget_hide(self->save_button);
666 gtk_widget_show(self->add_button);
667 gtk_widget_show(self->edit_button);
668 gtk_widget_show(self->delete_button);
670 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
671 gtk_widget_show_all(GTK_WIDGET(self->buttons));
673 break;
674 case BACKGROUNDS:
675 gtk_widget_hide(self->cancel_button);
676 gtk_widget_hide(self->save_button);
677 gtk_widget_show(self->add_button);
678 gtk_widget_show(self->edit_button);
679 gtk_widget_show(self->delete_button);
681 irreco_theme_creator_dlg_display_theme_detail(self, page_num);
682 gtk_widget_show_all(GTK_WIDGET(self->backgrounds));
684 break;
686 default:
687 IRRECO_DEBUG("default\n");
688 break;
690 IRRECO_RETURN
693 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
694 /* Events and Callbacks */
695 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
698 * @name Events and Callbacks
699 * @{
702 static void irreco_theme_creator_dlg_preview_image(GtkWidget *widget,
703 GdkEventButton *event,
704 IrrecoThemeCreatorDlg *self)
707 IrrecoThemeButton *preview_theme_button = NULL;
709 IRRECO_ENTER
710 if (self->theme != NULL) {
711 preview_theme_button = irreco_button_browser_dlg_run(
712 GTK_WINDOW(self),
713 self->irreco_data,
714 self->theme);
716 if(preview_theme_button) {
717 IRRECO_DEBUG("Set preview button to theme and self->\n");
719 self->preview_name = preview_theme_button->image_up->str;
720 self->preview_button = preview_theme_button;
721 _set_preview(self);
724 IRRECO_RETURN
727 /** @} */
730 *Create new background or button
733 static void irreco_theme_creator_dlg_new_bg_button(GtkButton *button,
734 IrrecoThemeCreatorDlg *self)
737 IRRECO_ENTER
738 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
739 self->notebook))==BACKGROUNDS) {
741 IrrecoThemeBg *new_bg = NULL;
742 new_bg = irreco_theme_bg_new();
744 if (irreco_background_creator_dlg_run(self->irreco_data,
745 self->theme,
746 GTK_WINDOW(self), new_bg)) {
747 irreco_string_table_add(self->theme->backgrounds,
748 new_bg->image_name->str,
749 new_bg);
750 irreco_theme_creator_backgrounds_refresh(
751 IRRECO_THEME_CREATOR_BACKGROUNDS(
752 self->backgrounds));
753 } else {
754 /*irreco_theme_bg_free(new_bg);*/
756 } else {
757 IrrecoThemeButton *new_button = NULL;
758 new_button = irreco_theme_button_new(NULL);
760 if (irreco_button_creator_dlg_run(self->irreco_data, self->theme,
761 GTK_WINDOW(self), new_button)) {
762 irreco_string_table_add(self->theme->buttons,
763 new_button->name->str,
764 new_button);
765 irreco_theme_creator_buttons_refresh(
766 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
767 } else {
768 /*irreco_theme_button_free(new_button);*/
771 IRRECO_RETURN
775 *Create edit background or button
778 static void irreco_theme_creator_dlg_edit_bg_button(GtkButton *button,
779 IrrecoThemeCreatorDlg *self)
781 IRRECO_ENTER
782 /* Check which page */
783 /* Edit bg */
784 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
785 self->notebook)) == BACKGROUNDS) {
787 IrrecoThemeBg *bg = NULL;
788 IrrecoThemeBg *new_bg = NULL;
789 IrrecoThemeBg *old_bg = NULL;
791 bg = irreco_theme_creator_backgrounds_get_selected_bg(
792 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
793 /* check whether the background image of the selected */
794 if (bg) {
795 new_bg = irreco_theme_bg_copy(bg);
797 IRRECO_DEBUG("Pointer: %p \n", (void*) self->theme);
799 if (irreco_background_creator_dlg_run(self->irreco_data,
800 self->theme,
801 GTK_WINDOW(self),
802 new_bg)) {
803 old_bg = irreco_theme_bg_copy(bg);
804 irreco_theme_bg_set(bg, new_bg->image_name->str,
805 new_bg->image_path->str);
807 irreco_theme_creator_backgrounds_refresh(
808 IRRECO_THEME_CREATOR_BACKGROUNDS(
809 self->backgrounds));
811 irreco_theme_bg_free(new_bg);
813 } else
815 IRRECO_DEBUG("the background is not selected\n");
817 /* Edit Button */
818 } else {
819 IrrecoThemeButton *button = NULL;
820 IrrecoThemeButton *new_button = NULL;
821 IrrecoThemeButton *old_button = NULL;
823 button = irreco_theme_creator_buttons_get_selected_button(
824 IRRECO_THEME_CREATOR_BUTTONS(self->buttons));
825 /* check whether the button image of the selected */
826 if (button) {
827 new_button = irreco_theme_button_copy(button);
829 if (irreco_button_creator_dlg_run(self->irreco_data,
830 self->theme,
831 GTK_WINDOW(self),
832 new_button)) {
833 old_button = irreco_theme_button_copy(button);
834 irreco_theme_button_print(new_button);
835 irreco_theme_button_set_from_button(button,
836 new_button);
838 irreco_theme_button_print(old_button);
839 irreco_theme_button_print(button);
841 irreco_theme_creator_buttons_refresh(
842 IRRECO_THEME_CREATOR_BUTTONS(
843 self->buttons));
847 irreco_theme_button_free(new_button);
848 } else {
849 IRRECO_DEBUG("the button is not selected\n");
852 IRRECO_RETURN
855 static void irreco_theme_creator_dlg_delete_bg_button(GtkButton *button,
856 IrrecoThemeCreatorDlg *self)
858 IRRECO_ENTER
860 if (gtk_notebook_get_current_page(GTK_NOTEBOOK(
861 self->notebook)) == BACKGROUNDS) {
862 IrrecoThemeBg *bg;
863 bg = irreco_theme_creator_backgrounds_get_selected_bg(
864 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds));
865 if (irreco_theme_creator_backgrounds_remove_selected(
866 IRRECO_THEME_CREATOR_BACKGROUNDS(self->backgrounds))) {
867 irreco_string_table_remove((self->theme)->backgrounds,
868 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 (irreco_theme_creator_buttons_remove_selected(
875 IRRECO_THEME_CREATOR_BUTTONS(self->buttons))) {
876 irreco_string_table_remove((self->theme)->buttons,
877 button->style_name->str);
879 self->preview_name = NULL;
880 g_string_printf(self->theme->preview_button_name, "%s", "");
884 IRRECO_RETURN