1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * irreco - Ir Remote Control
4 * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com)
6 * irreco_button_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_button_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_button_creator_dlg.h"
21 #include "irreco_theme_creator_backgrounds.h"
22 #include "irreco_theme_creator_dlg.h"
23 #include <hildon/hildon-banner.h>
24 #include <hildon/hildon-color-button.h>
25 #include <hildon/hildon-file-chooser-dialog.h>
26 #include <hildon/hildon-font-selection-dialog.h>
27 #include <hildon/hildon-program.h>
28 #include <hildon/hildon-color-chooser.h>
29 #include <hildon/hildon-color-chooser-dialog.h>
35 * @addtogroup IrrecoButtonCreatorDlg
44 * Source file of @ref IrrecoButtonCreatorDlg.
46 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
50 #define IRRECO_BUTTON_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH/5)
51 #define IRRECO_BUTTON_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT/5)
52 #define BUTTON_LIST_DIR "/home/pekka/git/irreco/irreco/src/core/button_list.conf"
59 LOADER_STATE_BACKGROUNDS
,
64 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
66 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
68 _signal_image_clicked(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
);
70 _unpressed_event_signal_image_clicked(GtkWidget
*widget
, GdkEventButton
*event
,
71 IrrecoButtonCreatorDlg
*self
);
73 _pressed_event_signal_image_clicked(GtkWidget
*widget
, GdkEventButton
*event
,
74 IrrecoButtonCreatorDlg
*self
);
75 static gboolean
_draw_preview_image(GtkButton
*button
,
76 IrrecoButtonCreatorDlg
*self
,
78 static void _toggle_button_toggled(GtkToggleButton
*togglebutton
,
79 IrrecoButtonCreatorDlg
*self
);
80 static void fill_buttons_combobox(IrrecoButtonCreatorDlg
*self
);
82 _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
);
85 _set_font_format(IrrecoButtonCreatorDlg
*self
, const gchar
*button_format
,
88 _set_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoTheme
*irreco_theme
,
89 IrrecoThemeButton
*button
);
91 _unbutton_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
);
93 _button_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
);
95 _set_new_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoThemeButton
*button
);
96 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
97 /* Construction & Destruction */
98 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
101 * @name Construction & Destruction
105 G_DEFINE_TYPE (IrrecoButtonCreatorDlg
, irreco_button_creator_dlg
,
106 IRRECO_TYPE_INTERNAL_DLG
)
107 static void irreco_button_creator_dlg_constructed(GObject
*object
)
109 /* TODO: Add initialization code here */
111 IrrecoData
*irreco_data
;
112 IrrecoButtonCreatorDlg
*self
;
115 GtkWidget
*frame_unpressed
;
116 GtkWidget
*frame_pressed
;
117 GtkWidget
*label_name
;
118 GtkWidget
*label_select_unpressed
;
119 GtkWidget
*label_select_pressed
;
120 GtkWidget
*event_box_unpressed
;
121 GtkWidget
*vbox_unpressed_preview
;
122 GtkWidget
*vbox_pressed_preview
;
123 GtkWidget
*label_size
;
126 GtkWidget
*table_settings
;
127 GtkWidget
*label_allow_text
;
129 GtkWidget
*label_text_padding
;
130 GtkWidget
*label_text_h_align
;
131 GtkWidget
*label_text_v_align
;
138 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->constructed(object
);
140 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
142 irreco_data
= irreco_internal_dlg_get_irreco_data(IRRECO_INTERNAL_DLG(self
));
144 /* Construct dialog. */
145 gtk_window_set_title(GTK_WINDOW(self
), _("Button Creator "));
146 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
147 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
148 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
151 self
->cancel_button
= gtk_dialog_add_button(GTK_DIALOG(self
),
153 GTK_RESPONSE_CANCEL
);
154 self
->add_button
= gtk_dialog_add_button(GTK_DIALOG(self
), _("Add"),
156 gtk_widget_set_sensitive(self
->add_button
, FALSE
);
159 /* Create widgets. */
160 self
->notebook
= gtk_notebook_new();
162 /* Create widgets. */
164 table
= gtk_table_new(7, 9, TRUE
);
165 label_name
= gtk_label_new(_ ("Name: "));
166 label_select_unpressed
= gtk_label_new(_("Unpressed: "));
167 label_select_pressed
= gtk_label_new(_ ("Pressed: "));
168 self
->event_box_pressed
= gtk_event_box_new();
169 event_box_unpressed
= gtk_event_box_new();
170 self
->combobox_name
= gtk_combo_box_entry_new_text();
171 frame_unpressed
= gtk_frame_new("");
172 frame_pressed
= gtk_frame_new("");
173 vbox_unpressed_preview
= gtk_vbox_new(FALSE
, 8);
174 vbox_pressed_preview
= gtk_vbox_new(FALSE
, 8);
175 self
->label_unpressed_size
= gtk_label_new("");
176 self
->label_pressed_size
= gtk_label_new("");
177 self
->preview_image_unpressed
= gtk_image_new();
178 self
->preview_image_pressed
= gtk_image_new();
179 self
->add_button_unpressed
= gtk_button_new_with_label(_("Select"));
180 self
->add_button_pressed
= gtk_button_new_with_label(_("Select"));
181 label_size
= gtk_label_new(_("ButtonSize:"));
184 table_settings
= gtk_table_new(7, 9, TRUE
);
185 label_allow_text
= gtk_label_new(_("AllowText:"));
186 self
->label_text_format_up
= gtk_label_new(_("TextFormatUp:"));
187 self
->label_text_format_down
= gtk_label_new(_("TextFormatDown:"));
188 label_text_padding
= gtk_label_new(_("Text:Padding:"));
189 label_text_h_align
= gtk_label_new(_("TextHAlign:"));
190 label_text_v_align
= gtk_label_new(_("TextVAlign:"));
191 self
->allow_text
= gtk_toggle_button_new();
192 self
->text_format_up
= gtk_button_new_with_label(_("Select"));
193 self
->text_format_down
= gtk_button_new_with_label(_("Select"));
194 self
->text_padding
= gtk_spin_button_new_with_range(0, 20, 1);
195 self
->text_h_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
196 self
->text_v_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
197 self
->unbutton_size
= gtk_spin_button_new_with_range(2, 5, 0.1);
198 self
->button_size
= gtk_spin_button_new_with_range(2, 5, 0.1);
200 self
->unpressed_path
= g_string_new(NULL
);
201 self
->pressed_path
= g_string_new(NULL
);
203 /* set button name/sensitive */
204 gtk_widget_set_name(self
->add_button_unpressed
,"unpressed");
205 gtk_widget_set_name(self
->add_button_pressed
,"pressed");
207 gtk_widget_set_sensitive(self
->add_button_pressed
, FALSE
);
208 gtk_widget_set_sensitive(self
->event_box_pressed
, FALSE
);
209 gtk_widget_set_sensitive(self
->text_format_up
, FALSE
);
210 gtk_widget_set_sensitive(self
->text_format_down
, FALSE
);
211 /* Set frame text bold */
212 gtk_frame_set_label_widget(GTK_FRAME(frame_unpressed
),
213 irreco_gtk_label_bold(
214 "Unpressed", 0, 0, 0, 0, 0, 0));
215 gtk_frame_set_label_widget(GTK_FRAME(frame_pressed
),
216 irreco_gtk_label_bold(
217 "Pressed", 0, 0, 0, 0, 0, 0));
219 /* Create Notebook tabs. */
221 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
222 irreco_gtk_align(GTK_WIDGET(table
),
223 0, 0, 1, 1, 8, 8, 8, 8),
224 gtk_label_new("BUTTONS"));
225 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
226 irreco_gtk_align(GTK_WIDGET(table_settings
),
227 0, 0, 1, 1, 8, 8, 8, 8),
228 gtk_label_new("SETTINGS"));
230 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
),
233 /* Set widgets on the table */
235 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
236 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
238 gtk_table_attach_defaults(GTK_TABLE(table
), label_name
, 0, 3, 0, 1);
239 gtk_table_attach_defaults(GTK_TABLE(table
),
240 label_select_unpressed
, 0, 3, 1, 2);
241 gtk_table_attach_defaults(GTK_TABLE(table
),
242 label_select_pressed
, 0, 3, 2, 3);
243 gtk_table_attach_defaults(GTK_TABLE(table
),
244 self
->combobox_name
, 3, 9, 0, 1);
245 gtk_table_attach_defaults(GTK_TABLE(table
),
246 self
->add_button_unpressed
, 3, 9, 1, 2);
247 gtk_table_attach_defaults(GTK_TABLE(table
),
248 self
->add_button_pressed
, 3, 9, 2, 3);
249 gtk_table_attach_defaults(GTK_TABLE(table
),
250 frame_unpressed
, 0, 4, 3, 7);
251 gtk_table_attach_defaults(GTK_TABLE(table
), frame_pressed
, 5, 9, 3, 7);
252 /* Set widgets on the table_settings */
253 gtk_table_set_row_spacings(GTK_TABLE(table_settings
), 6);
254 gtk_table_set_col_spacings(GTK_TABLE(table_settings
), 6);
256 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
257 label_allow_text
, 0, 4, 0, 1);
258 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
259 self
->label_text_format_up
, 0, 4, 1, 2);
260 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
261 self
->label_text_format_down
, 0, 4, 2, 3);
262 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
263 label_text_padding
, 0, 4, 3, 4);
264 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
265 label_text_h_align
, 0, 4, 4, 5);
266 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
267 label_text_v_align
, 0, 4, 5, 6);
268 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
269 label_size
, 0, 4, 6, 7);
271 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
272 self
->allow_text
, 4, 9, 0, 1);
273 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
274 self
->text_format_up
, 4, 9, 1, 2);
275 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
276 self
->text_format_down
, 4, 9, 2, 3);
277 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
278 self
->text_padding
, 4, 9, 3, 4);
279 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
280 self
->text_h_align
, 4, 9, 4, 5);
281 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
282 self
->text_v_align
, 4, 9, 5, 6);
283 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
284 self
->unbutton_size
, 4, 6, 6, 7);
285 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
286 self
->button_size
, 7, 9, 6, 7);
287 /* set preview image*/
289 gtk_container_add(GTK_CONTAINER(frame_unpressed
), event_box_unpressed
);
290 gtk_container_add(GTK_CONTAINER(event_box_unpressed
),
291 vbox_unpressed_preview
);
292 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
293 self
->preview_image_unpressed
);
294 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
295 self
->label_unpressed_size
);
297 gtk_container_add(GTK_CONTAINER(frame_pressed
), self
->event_box_pressed
);
298 gtk_container_add(GTK_CONTAINER(self
->event_box_pressed
),
299 vbox_pressed_preview
);
300 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
301 self
->preview_image_pressed
);
302 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
303 self
->label_pressed_size
);
308 /*Added button list on combobox*/
309 fill_buttons_combobox(self
);
311 /* set default settings on tab */
312 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
314 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
), 5);
315 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
), 0.5);
316 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
), 0.5);
317 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->unbutton_size
), 10);
318 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->button_size
), 10);
320 /* Set button name */
321 gtk_widget_set_name(self
->text_format_up
, "unpressed");
322 gtk_widget_set_name(self
->text_format_down
, "pressed");
323 /* Button signals. */
324 g_signal_connect(G_OBJECT(self
->add_button_unpressed
), "clicked",
325 G_CALLBACK(_signal_image_clicked
), self
);
326 g_signal_connect(G_OBJECT(self
->add_button_pressed
), "clicked",
327 G_CALLBACK(_signal_image_clicked
), self
);
329 g_signal_connect(G_OBJECT(event_box_unpressed
), "button-release-event",
330 G_CALLBACK(_unpressed_event_signal_image_clicked
),
332 g_signal_connect(G_OBJECT(self
->event_box_pressed
),
333 "button-release-event",
334 G_CALLBACK(_pressed_event_signal_image_clicked
),
337 g_signal_connect(G_OBJECT(self
->allow_text
), "toggled",
338 G_CALLBACK(_toggle_button_toggled
), self
);
340 g_signal_connect(G_OBJECT(self
->text_format_up
), "clicked",
341 G_CALLBACK(_select_font_format
), self
);
342 g_signal_connect(G_OBJECT(self
->text_format_down
), "clicked",
343 G_CALLBACK(_select_font_format
), self
);
344 g_signal_connect(G_OBJECT(self
->unbutton_size
), "value-changed",
345 G_CALLBACK(_unbutton_size_changed
), self
);
346 g_signal_connect(G_OBJECT(self
->button_size
), "value-changed",
347 G_CALLBACK(_button_size_changed
), self
);
348 gtk_widget_show_all(GTK_WIDGET(self
));
353 irreco_button_creator_dlg_init (IrrecoButtonCreatorDlg
*object
)
360 irreco_button_creator_dlg_finalize (GObject
*object
)
362 /* TODO: Add deinitalization code here */
364 IrrecoButtonCreatorDlg
*self
;
367 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
369 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->finalize(object
);
375 irreco_button_creator_dlg_class_init (IrrecoButtonCreatorDlgClass
*klass
)
377 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
379 object_class
->finalize
= irreco_button_creator_dlg_finalize
;
380 object_class
->constructed
= irreco_button_creator_dlg_constructed
;
384 *irreco_button_creator_dlg_new(IrrecoData
*irreco_data
, GtkWindow
*parent
)
386 IrrecoButtonCreatorDlg
*self
;
390 self
= g_object_new(IRRECO_TYPE_BUTTON_CREATOR_DLG
,
391 "irreco-data", irreco_data
, NULL
);
392 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
394 IRRECO_RETURN_PTR(self
);
399 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
400 /* Private Functions */
401 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
403 * @name Private Functions
408 *Fill combobox from file
410 static void fill_buttons_combobox(IrrecoButtonCreatorDlg
*self
)
413 GKeyFile
*button_list
;
417 GError
*error
= NULL
;
420 button_list
= g_key_file_new();
421 g_key_file_load_from_file(button_list
, BUTTON_LIST_DIR
,
422 G_KEY_FILE_NONE
, &error
);
424 keys
= g_key_file_get_keys(button_list
, "button-names", &length
,
427 for(i
=0; i
<length
; i
++){
428 gtk_combo_box_append_text(GTK_COMBO_BOX(self
->combobox_name
),
429 g_key_file_get_string(button_list
,
430 "button-names", keys
[i
], &error
));
433 g_key_file_free(button_list
);
434 if(keys
!= NULL
) g_free(keys
);
440 _unbutton_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
)
442 GString
*image_path
= g_string_new(self
->unpressed_path
->str
);
446 IRRECO_PRINTF("PATH: %s\n", self
->unpressed_path
->str
);
448 _draw_preview_image(GTK_BUTTON(self
->text_format_up
), self
,
451 g_string_free(image_path
, TRUE
);
455 _button_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
)
457 GString
*image_path
= g_string_new(self
->unpressed_path
->str
);
461 IRRECO_PRINTF("PATH: %s\n", self
->unpressed_path
->str
);
463 _draw_preview_image(GTK_BUTTON(self
->text_format_down
), self
,
466 g_string_free(image_path
, TRUE
);
471 * Draw preview with current image.
474 _draw_preview_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
,
477 GError
*error
= NULL
;
478 GdkPixbuf
*pixbuf
= NULL
;
479 GString
*size
= g_string_new(NULL
);
483 g_assert(self
!= NULL
);
484 /* compared with whichever image */
485 if (g_str_equal("pressed", gtk_widget_get_name(GTK_WIDGET(button
)))) {
486 gint button_width
= 0;
487 gint button_height
= 0;
488 GdkPixbuf
*pixbuf_size
= NULL
;
491 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
492 IRRECO_BUTTON_PREVIEW_WIDHT
,
493 IRRECO_BUTTON_PREVIEW_HEIGHT
,
495 /* set sensitive if image are selected */
496 gtk_widget_set_sensitive(self
->add_button
, TRUE
);
498 if (irreco_gerror_check_print(&error
)) {
499 IRRECO_RETURN_BOOL(FALSE
);
503 g_string_printf(self
->pressed_path
, "%s", image
);
504 gtk_widget_realize(GTK_WIDGET(self
->preview_image_pressed
));
505 gtk_image_set_from_pixbuf(GTK_IMAGE(self
->preview_image_pressed
),
508 /* Show image real size */
509 pixbuf_size
= gdk_pixbuf_new_from_file(image
, &error
);
510 button_width
= atoi(g_strdup_printf("%.0f",
511 (gdk_pixbuf_get_width(
513 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
514 self
->button_size
)))));
515 button_height
= atoi(g_strdup_printf("%.0f",
516 (gdk_pixbuf_get_height(
518 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
519 self
->button_size
))))));
521 if (pixbuf_size
!= NULL
) g_object_unref(G_OBJECT(pixbuf_size
));
523 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", button_width
),
524 g_strdup_printf("%d", button_height
));
526 gtk_label_set_text(GTK_LABEL(self
->label_pressed_size
),
530 gint button_width
= 0;
531 gint button_height
= 0;
532 GdkPixbuf
*pixbuf_size
= NULL
;
535 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
536 IRRECO_BUTTON_PREVIEW_WIDHT
,
537 IRRECO_BUTTON_PREVIEW_HEIGHT
,
539 if (irreco_gerror_check_print(&error
)) {
540 IRRECO_RETURN_BOOL(FALSE
);
543 gtk_widget_realize(GTK_WIDGET(self
->preview_image_unpressed
));
544 gtk_image_set_from_pixbuf(GTK_IMAGE(
545 self
->preview_image_unpressed
),
548 /* Show image real size */
549 pixbuf_size
= gdk_pixbuf_new_from_file(image
, &error
);
550 button_width
= atoi(g_strdup_printf("%.0f",
551 (gdk_pixbuf_get_width(
553 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
554 self
->unbutton_size
)))));
555 button_height
= atoi(g_strdup_printf("%.0f",
556 (gdk_pixbuf_get_height(
558 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
559 self
->unbutton_size
))))));
560 if (pixbuf_size
!= NULL
) g_object_unref(G_OBJECT(pixbuf_size
));
562 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", button_width
),
563 g_strdup_printf("%d", button_height
));
565 gtk_label_set_text(GTK_LABEL(self
->label_unpressed_size
),
567 g_string_printf(self
->unpressed_path
, "%s", image
);
569 /* Set button sensitive */
570 gtk_widget_set_sensitive(self
->add_button_pressed
, TRUE
);
571 gtk_widget_set_sensitive(self
->event_box_pressed
, TRUE
);
574 g_string_free(size
, TRUE
);
575 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
576 IRRECO_RETURN_BOOL(TRUE
);
580 static void _select_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
583 GtkWidget
*file_dlg
= NULL
;
584 gchar
*image_dir
= NULL
;
587 /* Create image select dialog. */
589 file_dlg
= hildon_file_chooser_dialog_new(GTK_WINDOW(self
),
590 GTK_FILE_CHOOSER_ACTION_OPEN
);
591 gtk_window_set_title(GTK_WINDOW(file_dlg
),_("Select button image"));
592 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_dlg
), TRUE
);
593 image_dir
= g_build_path("/", getenv("HOME"), "MyDocs/.images/", NULL
);
594 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_dlg
),
598 /* Loop until user cancels or we get a valid image. */
599 gtk_widget_show_all(GTK_WIDGET(file_dlg
));
600 while (gtk_dialog_run(GTK_DIALOG(file_dlg
)) == GTK_RESPONSE_OK
) {
602 filename
= gtk_file_chooser_get_filename(
603 GTK_FILE_CHOOSER(file_dlg
));
605 /* Attempt to display the image. */
606 if (_draw_preview_image(button
, self
, filename
)) {
607 irreco_gstring_set_and_free(self
->filename
, filename
);
613 gchar
*basename
= g_path_get_basename(filename
);
614 irreco_error_dlg_printf(GTK_WINDOW(file_dlg
),
615 _("Cannot open image \"%s\""),
617 IRRECO_PRINTF("Image invalid.\n");
624 gtk_widget_destroy(file_dlg
);
631 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
633 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
635 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
636 /* Public Functions */
637 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
639 gboolean
irreco_button_creator_dlg_run(IrrecoData
*irreco_data
,
640 IrrecoTheme
* irreco_theme
,
641 GtkWindow
*parent_window
,
642 IrrecoThemeButton
*button
)
644 IrrecoButtonCreatorDlg
*self
;
646 gboolean loop
= TRUE
;
647 gboolean rvalue
= FALSE
;
650 self
= (IrrecoButtonCreatorDlg
*)irreco_button_creator_dlg_new(
651 irreco_data
, parent_window
);
652 self
->irreco_data
= irreco_data
;
653 self
->theme
= irreco_theme
;
655 IRRECO_PRINTF("Button: %s\n", button
->name
->str
);
656 if (g_utf8_strlen(button
->name
->str
, 1) >0) {
657 /* Sets the button details */
658 _set_button_details(self
, irreco_theme
, button
);
662 response
= gtk_dialog_run(GTK_DIALOG(self
));
664 case GTK_RESPONSE_OK
:
666 _set_new_button_details(self
, button
);
668 irreco_theme_button_print(button
);
673 case GTK_RESPONSE_CANCEL
:
674 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
680 IRRECO_DEBUG("default\n");
686 gtk_widget_destroy(GTK_WIDGET(self
));
687 IRRECO_RETURN_BOOL(rvalue
);
692 _set_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoTheme
*irreco_theme
,
693 IrrecoThemeButton
*button
)
697 /* Set button information on table */
698 gtk_combo_box_prepend_text(GTK_COMBO_BOX(self
->combobox_name
),
700 gtk_combo_box_set_active(GTK_COMBO_BOX(self
->combobox_name
),
702 _draw_preview_image(GTK_BUTTON(self
->add_button_unpressed
),
704 button
->image_up
->str
);
705 _draw_preview_image(GTK_BUTTON(self
->add_button_pressed
),
707 button
->image_down
->str
);
708 if (button
->allow_text
) {
709 gtk_button_clicked(GTK_BUTTON(self
->allow_text
));
712 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
),
713 button
->text_padding
);
715 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
),
716 button
->text_h_align
);
717 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
),
718 button
->text_v_align
);
720 if (strlen(button
->text_format_up
->str
) > 0) {
722 _set_font_format(self
, button
->text_format_up
->str
,
723 gtk_label_get_text(GTK_LABEL(
724 self
->label_text_format_up
)));
726 if (strlen(button
->text_format_down
->str
) > 0) {
728 _set_font_format(self
, button
->text_format_down
->str
,
729 gtk_label_get_text(GTK_LABEL(
730 self
->label_text_format_down
)));
732 /* Set button label & windown title */
733 gtk_button_set_label(GTK_BUTTON(self
->add_button
), "Save");
734 gtk_window_set_title(GTK_WINDOW(self
), _("Button Editor "));
741 _set_new_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoThemeButton
*button
)
745 gchar
*style_name
= NULL
;
746 gboolean allow_text
= FALSE
;
747 gint text_padding
= 0;
748 gfloat text_h_align
= 0;
749 gfloat text_v_align
= 0;
752 style_name
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(
753 self
->combobox_name
));
754 allow_text
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
756 text_padding
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
757 self
->text_padding
));
758 text_h_align
= gtk_spin_button_get_value(GTK_SPIN_BUTTON(
759 self
->text_h_align
));
760 text_v_align
= gtk_spin_button_get_value(GTK_SPIN_BUTTON(
761 self
->text_v_align
));
763 irreco_theme_button_set(button
,
767 self
->unpressed_path
->str
,
768 self
->pressed_path
->str
,
769 self
->unpressed_format
,
770 self
->pressed_format
,
779 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
780 /* Events and Callbacks */
781 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
784 * @name Events and Callbacks
789 _signal_image_clicked(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
792 _select_image(button
, self
);
796 static void _unpressed_event_signal_image_clicked(GtkWidget
*widget
,
797 GdkEventButton
*event
,
798 IrrecoButtonCreatorDlg
*self
)
802 gtk_button_clicked(GTK_BUTTON(self
->add_button_unpressed
));
807 static void _pressed_event_signal_image_clicked(GtkWidget
*widget
,
808 GdkEventButton
*event
,
809 IrrecoButtonCreatorDlg
*self
)
813 gtk_button_clicked(GTK_BUTTON(self
->add_button_pressed
));
819 static void _toggle_button_toggled(GtkToggleButton
*togglebutton
,
820 IrrecoButtonCreatorDlg
*self
)
824 if (gtk_toggle_button_get_active(togglebutton
)) {
825 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "YES");
826 gtk_widget_set_sensitive(self
->text_format_up
, TRUE
);
827 gtk_widget_set_sensitive(self
->text_format_down
, TRUE
);
829 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
830 gtk_widget_set_sensitive(self
->text_format_up
, FALSE
);
831 gtk_widget_set_sensitive(self
->text_format_down
, FALSE
);
837 *Select button font format
840 static void _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
844 GString
*format
= g_string_new(NULL
);
845 const gchar
*span
= ">%s</span>";
849 dialog
= gtk_font_selection_dialog_new("Button font");
851 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
) {
853 font
= gtk_font_selection_dialog_get_font_name(
854 GTK_FONT_SELECTION_DIALOG(dialog
));
856 /*g_string_printf(format,
857 "<span foreground=\"%s\" font_desc=\"%s\" %s",
858 "red", font, span);*/
859 g_string_printf(format
,
860 "<span font_desc=\"%s\" %s", font
, span
);
863 if (strcmp("unpressed", gtk_widget_get_name(
864 GTK_WIDGET(button
))) == 0) {
865 self
->unpressed_format
= format
->str
;
866 _set_font_format(self
, format
->str
,
867 gtk_label_get_text(GTK_LABEL(
868 self
->label_text_format_up
)));
870 self
->pressed_format
= format
->str
;
871 _set_font_format(self
, format
->str
,
872 gtk_label_get_text(GTK_LABEL(
873 self
->label_text_format_down
)));
876 gtk_widget_destroy(GTK_WIDGET(dialog
));
882 static void _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
885 HildonFontSelectionDialog
*dialog
= NULL
;
886 PangoFontDescription
*font
= NULL
;
888 gboolean bold
, italic
;
889 gchar
*family
= NULL
;
891 const gchar
*span
= ">%s</span>";
895 GString
*format
= g_string_new(NULL
);
900 font
= pango_font_description_new();
904 dialog
= HILDON_FONT_SELECTION_DIALOG(hildon_font_selection_dialog_new(
907 gtk_widget_show_all (GTK_WIDGET(dialog
));
908 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
) {
909 g_object_get(G_OBJECT(dialog
),
917 color_string
[0] = '#';
918 sprintf(&color_string
[1], "%.2X", color
->red
/256);
919 sprintf(&color_string
[3], "%.2X", color
->green
/256);
920 sprintf(&color_string
[5], "%.2X", color
->blue
/256);
923 pango_font_description_set_family(font
, family
);
924 pango_font_description_set_size(font
, size
* PANGO_SCALE
);
926 pango_font_description_set_weight(font
, PANGO_WEIGHT_BOLD
);
928 pango_font_description_set_weight(font
, PANGO_WEIGHT_NORMAL
);
931 pango_font_description_set_style(font
, PANGO_STYLE_ITALIC
);
933 pango_font_description_set_style(font
, PANGO_STYLE_NORMAL
);
935 IRRECO_PRINTF("PANGO: %s\n", pango_font_description_to_string(font
));
937 text
= pango_color_to_string(color
);
938 IRRECO_PRINTF("FONT: %s\n", text
);
940 g_string_printf(format
,
941 "<span foreground=\"%s\" font_desc=\"%s %d\" %s",
942 color_string
, family
, size
, span
);
945 g_string_printf(format
,
946 "<span foreground=\"%s\" font_desc=\"%s %s %d\" %s",
947 text
, family
, "Bold", size
, span
);
949 g_string_printf(format
,
950 "<span foreground=\"%s\" font_desc=\"%s %s %s %d\" %s",
951 text
, family
, "Bold", "Italic", size
, span
);
954 if (italic
&& !(bold
)) {
955 g_string_printf(format
,
956 "<span foreground=\"%s\" font_desc=\"%s %s %d\" %s",
957 text
, family
, "Italic", size
, span
);
960 markup
= g_markup_printf_escaped(format
->str
, "text-format-up:");
961 IRRECO_PRINTF("FONT: %s\n", markup
);
963 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_up
), markup
);
965 value
= g_strdup_printf ("%u,%u,%u",
971 IRRECO_PRINTF("FONT: %s\n", color_string
);
973 IRRECO_PRINTF("FONT: %s\n", value
);
978 if(markup
!= NULL
) g_free(markup
);
979 if(text
!= NULL
) g_free(text
);
980 if(family
!= NULL
) g_free(family
);
981 g_string_free(format
, TRUE
);
983 pango_color_free(color
);
985 gtk_widget_destroy(GTK_WIDGET(dialog
));
991 * Set button text format
993 static void _set_font_format(IrrecoButtonCreatorDlg
*self
, const gchar
*button_format
,
999 GString
*format
= g_string_new(NULL
);
1003 g_string_printf(format
, "%s", button_format
);
1005 markup
= g_markup_printf_escaped(format
->str
, text
);
1007 IRRECO_PRINTF("TEXT: %s\n", markup
);
1009 if (strcmp(text
, gtk_label_get_text(GTK_LABEL(
1010 self
->label_text_format_up
))) == 0) {
1011 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_up
),
1015 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_down
),
1019 if(markup
!= NULL
) g_free(markup
);
1020 g_string_free(format
, TRUE
);