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
);
84 static void _set_font_format(IrrecoButtonCreatorDlg
*self
, const gchar
*button_format
,
86 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
87 /* Construction & Destruction */
88 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
91 * @name Construction & Destruction
95 G_DEFINE_TYPE (IrrecoButtonCreatorDlg
, irreco_button_creator_dlg
,
96 IRRECO_TYPE_INTERNAL_DLG
)
97 static void irreco_button_creator_dlg_constructed(GObject
*object
)
99 /* TODO: Add initialization code here */
101 IrrecoData
*irreco_data
;
102 IrrecoButtonCreatorDlg
*self
;
105 GtkWidget
*frame_unpressed
;
106 GtkWidget
*frame_pressed
;
107 GtkWidget
*label_name
;
108 GtkWidget
*label_select_unpressed
;
109 GtkWidget
*label_select_pressed
;
110 GtkWidget
*event_box_unpressed
;
111 GtkWidget
*vbox_unpressed_preview
;
112 GtkWidget
*vbox_pressed_preview
;
116 GtkWidget
*table_settings
;
117 GtkWidget
*label_allow_text
;
119 GtkWidget
*label_text_padding
;
120 GtkWidget
*label_text_h_align
;
121 GtkWidget
*label_text_v_align
;
128 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->constructed(object
);
130 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
132 irreco_data
= irreco_internal_dlg_get_irreco_data(IRRECO_INTERNAL_DLG(self
));
134 /* Construct dialog. */
135 gtk_window_set_title(GTK_WINDOW(self
), _("Button Creator "));
136 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
137 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
138 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
141 self
->cancel_button
= gtk_dialog_add_button(GTK_DIALOG(self
),
143 GTK_RESPONSE_CANCEL
);
144 self
->add_button
= gtk_dialog_add_button(GTK_DIALOG(self
), _("Add"),
147 /* Create widgets. */
148 self
->notebook
= gtk_notebook_new();
150 /* Create widgets. */
152 table
= gtk_table_new(7, 9, TRUE
);
153 label_name
= gtk_label_new(_ ("Name: "));
154 label_select_unpressed
= gtk_label_new(_("Unpressed: "));
155 label_select_pressed
= gtk_label_new(_ ("Pressed: "));
156 self
->event_box_pressed
= gtk_event_box_new();
157 event_box_unpressed
= gtk_event_box_new();
158 self
->combobox_name
= gtk_combo_box_entry_new_text();
159 frame_unpressed
= gtk_frame_new("");
160 frame_pressed
= gtk_frame_new("");
161 vbox_unpressed_preview
= gtk_vbox_new(FALSE
, 8);
162 vbox_pressed_preview
= gtk_vbox_new(FALSE
, 8);
163 self
->label_unpressed_size
= gtk_label_new("");
164 self
->label_pressed_size
= gtk_label_new("");
165 self
->preview_image_unpressed
= gtk_image_new();
166 self
->preview_image_pressed
= gtk_image_new();
167 self
->add_button_unpressed
= gtk_button_new_with_label(_("Select"));
168 self
->add_button_pressed
= gtk_button_new_with_label(_("Select"));
170 table_settings
= gtk_table_new(7, 9, TRUE
);
171 label_allow_text
= gtk_label_new(_("AllowText:"));
172 self
->label_text_format_up
= gtk_label_new(_("TextFormatUp:"));
173 self
->label_text_format_down
= gtk_label_new(_("TextFormatDown:"));
174 label_text_padding
= gtk_label_new(_("Text:Padding:"));
175 label_text_h_align
= gtk_label_new(_("TextHAlign:"));
176 label_text_v_align
= gtk_label_new(_("TextVAlign:"));
177 self
->allow_text
= gtk_toggle_button_new();
178 self
->text_format_up
= gtk_button_new_with_label(_("Select"));
179 self
->text_format_down
= gtk_button_new_with_label(_("Select"));
180 self
->text_padding
= gtk_spin_button_new_with_range(0, 20, 1);
181 self
->text_h_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
182 self
->text_v_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
185 /* set button name/sensitive */
186 gtk_widget_set_name(self
->add_button_unpressed
,"unpressed");
187 gtk_widget_set_name(self
->add_button_pressed
,"pressed");
189 gtk_widget_set_sensitive(self
->add_button_pressed
, FALSE
);
190 gtk_widget_set_sensitive(self
->event_box_pressed
, FALSE
);
191 gtk_widget_set_sensitive(self
->text_format_up
, FALSE
);
192 gtk_widget_set_sensitive(self
->text_format_down
, FALSE
);
193 /* Set frame text bold */
194 gtk_frame_set_label_widget(GTK_FRAME(frame_unpressed
),
195 irreco_gtk_label_bold(
196 "Unpressed", 0, 0, 0, 0, 0, 0));
197 gtk_frame_set_label_widget(GTK_FRAME(frame_pressed
),
198 irreco_gtk_label_bold(
199 "Pressed", 0, 0, 0, 0, 0, 0));
201 /* Create Notebook tabs. */
203 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
204 irreco_gtk_align(GTK_WIDGET(table
),
205 0, 0, 1, 1, 8, 8, 8, 8),
206 gtk_label_new("BUTTONS"));
207 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
208 irreco_gtk_align(GTK_WIDGET(table_settings
),
209 0, 0, 1, 1, 8, 8, 8, 8),
210 gtk_label_new("SETTINGS"));
212 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
),
215 /* Set widgets on the table */
217 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
218 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
220 gtk_table_attach_defaults(GTK_TABLE(table
), label_name
, 0, 3, 0, 1);
221 gtk_table_attach_defaults(GTK_TABLE(table
),
222 label_select_unpressed
, 0, 3, 1, 2);
223 gtk_table_attach_defaults(GTK_TABLE(table
),
224 label_select_pressed
, 0, 3, 2, 3);
225 gtk_table_attach_defaults(GTK_TABLE(table
),
226 self
->combobox_name
, 3, 9, 0, 1);
227 gtk_table_attach_defaults(GTK_TABLE(table
),
228 self
->add_button_unpressed
, 3, 9, 1, 2);
229 gtk_table_attach_defaults(GTK_TABLE(table
),
230 self
->add_button_pressed
, 3, 9, 2, 3);
231 gtk_table_attach_defaults(GTK_TABLE(table
),
232 frame_unpressed
, 0, 4, 3, 7);
233 gtk_table_attach_defaults(GTK_TABLE(table
), frame_pressed
, 5, 9, 3, 7);
234 /* Set widgets on the table_settings */
235 gtk_table_set_row_spacings(GTK_TABLE(table_settings
), 6);
236 gtk_table_set_col_spacings(GTK_TABLE(table_settings
), 6);
238 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
239 label_allow_text
, 0, 4, 0, 1);
240 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
241 self
->label_text_format_up
, 0, 4, 1, 2);
242 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
243 self
->label_text_format_down
, 0, 4, 2, 3);
244 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
245 label_text_padding
, 0, 4, 3, 4);
246 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
247 label_text_h_align
, 0, 4, 4, 5);
248 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
249 label_text_v_align
, 0, 4, 5, 6);
251 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
252 self
->allow_text
, 4, 9, 0, 1);
253 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
254 self
->text_format_up
, 4, 9, 1, 2);
255 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
256 self
->text_format_down
, 4, 9, 2, 3);
257 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
258 self
->text_padding
, 4, 9, 3, 4);
259 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
260 self
->text_h_align
, 4, 9, 4, 5);
261 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
262 self
->text_v_align
, 4, 9, 5, 6);
263 /* set preview image*/
265 gtk_container_add(GTK_CONTAINER(frame_unpressed
), event_box_unpressed
);
266 gtk_container_add(GTK_CONTAINER(event_box_unpressed
),
267 vbox_unpressed_preview
);
268 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
269 self
->preview_image_unpressed
);
270 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
271 self
->label_unpressed_size
);
273 gtk_container_add(GTK_CONTAINER(frame_pressed
), self
->event_box_pressed
);
274 gtk_container_add(GTK_CONTAINER(self
->event_box_pressed
),
275 vbox_pressed_preview
);
276 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
277 self
->preview_image_pressed
);
278 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
279 self
->label_pressed_size
);
284 /*Added button list on combobox*/
285 fill_buttons_combobox(self
);
287 /* set default settings on tab */
288 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
290 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
), 5);
291 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
), 0.5);
292 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
), 0.5);
294 /* Set button name */
295 gtk_widget_set_name(self
->text_format_up
, "unpressed");
296 gtk_widget_set_name(self
->text_format_down
, "pressed");
298 /* Button signals. */
299 g_signal_connect(G_OBJECT(self
->add_button_unpressed
), "clicked",
300 G_CALLBACK(_signal_image_clicked
), self
);
301 g_signal_connect(G_OBJECT(self
->add_button_pressed
), "clicked",
302 G_CALLBACK(_signal_image_clicked
), self
);
304 g_signal_connect(G_OBJECT(event_box_unpressed
), "button-release-event",
305 G_CALLBACK(_unpressed_event_signal_image_clicked
),
307 g_signal_connect(G_OBJECT(self
->event_box_pressed
),
308 "button-release-event",
309 G_CALLBACK(_pressed_event_signal_image_clicked
),
312 g_signal_connect(G_OBJECT(self
->allow_text
), "toggled",
313 G_CALLBACK(_toggle_button_toggled
), self
);
315 g_signal_connect(G_OBJECT(self
->text_format_up
), "clicked",
316 G_CALLBACK(_select_font_format
), self
);
317 g_signal_connect(G_OBJECT(self
->text_format_down
), "clicked",
318 G_CALLBACK(_select_font_format
), self
);
320 gtk_widget_show_all(GTK_WIDGET(self
));
325 irreco_button_creator_dlg_init (IrrecoButtonCreatorDlg
*object
)
332 irreco_button_creator_dlg_finalize (GObject
*object
)
334 /* TODO: Add deinitalization code here */
336 IrrecoButtonCreatorDlg
*self
;
339 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
341 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->finalize(object
);
347 irreco_button_creator_dlg_class_init (IrrecoButtonCreatorDlgClass
*klass
)
349 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
351 object_class
->finalize
= irreco_button_creator_dlg_finalize
;
352 object_class
->constructed
= irreco_button_creator_dlg_constructed
;
356 *irreco_button_creator_dlg_new(IrrecoData
*irreco_data
, GtkWindow
*parent
)
358 IrrecoButtonCreatorDlg
*self
;
362 self
= g_object_new(IRRECO_TYPE_BUTTON_CREATOR_DLG
,
363 "irreco-data", irreco_data
, NULL
);
364 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
366 IRRECO_RETURN_PTR(self
);
371 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
372 /* Private Functions */
373 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
375 * @name Private Functions
380 *Fill combobox from file
382 static void fill_buttons_combobox(IrrecoButtonCreatorDlg
*self
)
385 GKeyFile
*button_list
;
389 GError
*error
= NULL
;
392 button_list
= g_key_file_new();
393 g_key_file_load_from_file(button_list
, BUTTON_LIST_DIR
,
394 G_KEY_FILE_NONE
, &error
);
396 keys
= g_key_file_get_keys(button_list
, "button-names", &length
,
399 for(i
=0; i
<length
; i
++){
400 gtk_combo_box_append_text(GTK_COMBO_BOX(self
->combobox_name
),
401 g_key_file_get_string(button_list
,
402 "button-names", keys
[i
], &error
));
405 g_key_file_free(button_list
);
406 if(keys
!= NULL
) g_free(keys
);
411 * Draw preview with current image.
414 _draw_preview_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
,
417 GError
*error
= NULL
;
418 GdkPixbuf
*pixbuf
= NULL
;
419 GString
*size
= g_string_new(NULL
);
423 g_assert(self
!= NULL
);
425 /* compared with whichever image */
426 if (g_str_equal("pressed", gtk_widget_get_name(GTK_WIDGET(button
)))) {
428 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
429 IRRECO_BUTTON_PREVIEW_WIDHT
,
430 IRRECO_BUTTON_PREVIEW_HEIGHT
,
432 if (irreco_gerror_check_print(&error
)) {
433 IRRECO_RETURN_BOOL(FALSE
);
437 gtk_widget_realize(GTK_WIDGET(self
->preview_image_pressed
));
438 gtk_image_set_from_pixbuf(GTK_IMAGE(self
->preview_image_pressed
),
441 /* Show image real size */
442 g_string_printf(size
, "%sx%s", g_strdup_printf("%d",
443 gdk_pixbuf_get_width(
444 gdk_pixbuf_new_from_file(image
, &error
))),
445 g_strdup_printf("%d", gdk_pixbuf_get_height(
446 gdk_pixbuf_new_from_file(image
, &error
))));
447 gtk_label_set_text(GTK_LABEL(self
->label_pressed_size
),
452 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
453 IRRECO_BUTTON_PREVIEW_WIDHT
,
454 IRRECO_BUTTON_PREVIEW_HEIGHT
,
456 if (irreco_gerror_check_print(&error
)) {
457 IRRECO_RETURN_BOOL(FALSE
);
461 gtk_widget_realize(GTK_WIDGET(self
->preview_image_unpressed
));
462 gtk_image_set_from_pixbuf(GTK_IMAGE(
463 self
->preview_image_unpressed
),
466 /* Show image real size */
467 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", gdk_pixbuf_get_width(
468 gdk_pixbuf_new_from_file(image
, &error
))),
469 g_strdup_printf("%d", gdk_pixbuf_get_height(
470 gdk_pixbuf_new_from_file(image
, &error
))));
471 gtk_label_set_text(GTK_LABEL(self
->label_unpressed_size
), size
->str
);
473 /* Set button sensitive */
474 gtk_widget_set_sensitive(self
->add_button_pressed
, TRUE
);
475 gtk_widget_set_sensitive(self
->event_box_pressed
, TRUE
);
478 g_string_free(size
, TRUE
);
479 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
481 IRRECO_RETURN_BOOL(TRUE
);
485 static void _select_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
488 GtkWidget
*file_dlg
= NULL
;
489 gchar
*image_dir
= NULL
;
492 /* Create image select dialog. */
494 file_dlg
= hildon_file_chooser_dialog_new(GTK_WINDOW(self
),
495 GTK_FILE_CHOOSER_ACTION_OPEN
);
496 gtk_window_set_title(GTK_WINDOW(file_dlg
),_("Select button image"));
497 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_dlg
), TRUE
);
498 image_dir
= g_build_path("/", getenv("HOME"), "MyDocs/.images/", NULL
);
499 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_dlg
),
503 /* Loop until user cancels or we get a valid image. */
504 gtk_widget_show_all(GTK_WIDGET(file_dlg
));
505 while (gtk_dialog_run(GTK_DIALOG(file_dlg
)) == GTK_RESPONSE_OK
) {
507 filename
= gtk_file_chooser_get_filename(
508 GTK_FILE_CHOOSER(file_dlg
));
510 /* Attempt to display the image. */
511 if (_draw_preview_image(button
, self
, filename
)) {
512 irreco_gstring_set_and_free(self
->filename
, filename
);
518 gchar
*basename
= g_path_get_basename(filename
);
519 irreco_error_dlg_printf(GTK_WINDOW(file_dlg
),
520 _("Cannot open image \"%s\""),
522 IRRECO_PRINTF("Image invalid.\n");
529 gtk_widget_destroy(file_dlg
);
536 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
538 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
540 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
541 /* Public Functions */
542 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
544 IrrecoThemeButton
*irreco_button_creator_dlg_run(IrrecoData
*irreco_data
,
545 IrrecoTheme
* irreco_theme
,
546 GtkWindow
*parent_window
,
547 IrrecoThemeButton
*button
)
549 IrrecoButtonCreatorDlg
*self
;
551 gboolean loop
= TRUE
;
555 self
= (IrrecoButtonCreatorDlg
*)irreco_button_creator_dlg_new(
556 irreco_data
, parent_window
);
557 self
->irreco_data
= irreco_data
;
560 if(irreco_theme
!= NULL
) {
561 self
->theme
= irreco_theme
;
563 irreco_theme_button_print(button
);
565 /* Set button information on table */
566 gtk_combo_box_prepend_text(GTK_COMBO_BOX(self
->combobox_name
),
568 gtk_combo_box_set_active(GTK_COMBO_BOX(self
->combobox_name
),
570 _draw_preview_image(GTK_BUTTON(self
->add_button_unpressed
),
572 button
->image_up
->str
);
573 _draw_preview_image(GTK_BUTTON(self
->add_button_pressed
),
575 button
->image_down
->str
);
576 if (button
->allow_text
) {
577 gtk_button_clicked(GTK_BUTTON(self
->allow_text
));
580 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
),
581 button
->text_padding
);
583 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
),
584 button
->text_h_align
);
585 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
),
586 button
->text_v_align
);
588 if (strlen(button
->text_format_up
->str
) > 0) {
590 _set_font_format(self
, button
->text_format_up
->str
,
591 gtk_label_get_text(GTK_LABEL(self
->label_text_format_up
)));
594 if (strlen(button
->text_format_down
->str
) > 0) {
596 _set_font_format(self
, button
->text_format_down
->str
,
597 gtk_label_get_text(GTK_LABEL(self
->label_text_format_down
)));
600 /* Set button label & windown title */
601 gtk_button_set_label(GTK_BUTTON(self
->add_button
), "Save");
602 gtk_window_set_title(GTK_WINDOW(self
), _("Button Editor "));
608 response
= gtk_dialog_run(GTK_DIALOG(self
));
610 case GTK_RESPONSE_OK
:
612 /*self->loader_state = LOADER_STATE_INIT;*/
617 case GTK_RESPONSE_CANCEL
:
618 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
623 IRRECO_DEBUG("default\n");
629 gtk_widget_destroy(GTK_WIDGET(self
));
631 IRRECO_RETURN_PTR(button
);
633 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
634 /* Events and Callbacks */
635 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
638 * @name Events and Callbacks
643 _signal_image_clicked(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
646 _select_image(button
, self
);
650 static void _unpressed_event_signal_image_clicked(GtkWidget
*widget
,
651 GdkEventButton
*event
,
652 IrrecoButtonCreatorDlg
*self
)
656 gtk_button_clicked(GTK_BUTTON(self
->add_button_unpressed
));
661 static void _pressed_event_signal_image_clicked(GtkWidget
*widget
,
662 GdkEventButton
*event
,
663 IrrecoButtonCreatorDlg
*self
)
667 gtk_button_clicked(GTK_BUTTON(self
->add_button_pressed
));
673 static void _toggle_button_toggled(GtkToggleButton
*togglebutton
,
674 IrrecoButtonCreatorDlg
*self
)
678 if (gtk_toggle_button_get_active(togglebutton
)) {
679 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "YES");
680 gtk_widget_set_sensitive(self
->text_format_up
, TRUE
);
681 gtk_widget_set_sensitive(self
->text_format_down
, TRUE
);
683 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
684 gtk_widget_set_sensitive(self
->text_format_up
, FALSE
);
685 gtk_widget_set_sensitive(self
->text_format_down
, FALSE
);
691 *Select button font format
694 static void _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
698 GString
*format
= g_string_new(NULL
);
699 const gchar
*span
= ">%s</span>";
703 dialog
= gtk_font_selection_dialog_new("Button font");
705 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
) {
707 font
= gtk_font_selection_dialog_get_font_name(
708 GTK_FONT_SELECTION_DIALOG(dialog
));
711 g_string_printf(format
,
712 "<span foreground=\"%s\" font_desc=\"%s\" %s",
716 IRRECO_PRINTF("FONT: %s\n", font
);
718 IRRECO_PRINTF("BUTTON: %s\n", gtk_widget_get_name(GTK_WIDGET(button
)));
721 if (strcmp("unpressed", gtk_widget_get_name(GTK_WIDGET(button
))) == 0) {
723 _set_font_format(self
, format
->str
,
724 gtk_label_get_text(GTK_LABEL(self
->label_text_format_up
)));
728 _set_font_format(self
, format
->str
,
729 gtk_label_get_text(GTK_LABEL(self
->label_text_format_down
)));
736 gtk_widget_destroy(GTK_WIDGET(dialog
));
743 static void _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
746 HildonFontSelectionDialog
*dialog
= NULL
;
747 PangoFontDescription
*font
= NULL
;
749 gboolean bold
, italic
;
750 gchar
*family
= NULL
;
752 const gchar
*span
= ">%s</span>";
756 GString
*format
= g_string_new(NULL
);
761 font
= pango_font_description_new();
765 dialog
= HILDON_FONT_SELECTION_DIALOG(hildon_font_selection_dialog_new(
768 gtk_widget_show_all (GTK_WIDGET(dialog
));
769 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
) {
770 g_object_get(G_OBJECT(dialog
),
778 color_string
[0] = '#';
779 sprintf(&color_string
[1], "%.2X", color
->red
/256);
780 sprintf(&color_string
[3], "%.2X", color
->green
/256);
781 sprintf(&color_string
[5], "%.2X", color
->blue
/256);
784 pango_font_description_set_family(font
, family
);
785 pango_font_description_set_size(font
, size
* PANGO_SCALE
);
787 pango_font_description_set_weight(font
, PANGO_WEIGHT_BOLD
);
789 pango_font_description_set_weight(font
, PANGO_WEIGHT_NORMAL
);
792 pango_font_description_set_style(font
, PANGO_STYLE_ITALIC
);
794 pango_font_description_set_style(font
, PANGO_STYLE_NORMAL
);
796 IRRECO_PRINTF("PANGO: %s\n", pango_font_description_to_string(font
));
798 text
= pango_color_to_string(color
);
799 IRRECO_PRINTF("FONT: %s\n", text
);
801 g_string_printf(format
,
802 "<span foreground=\"%s\" font_desc=\"%s %d\" %s",
803 color_string
, family
, size
, span
);
806 g_string_printf(format
,
807 "<span foreground=\"%s\" font_desc=\"%s %s %d\" %s",
808 text
, family
, "Bold", size
, span
);
810 g_string_printf(format
,
811 "<span foreground=\"%s\" font_desc=\"%s %s %s %d\" %s",
812 text
, family
, "Bold", "Italic", size
, span
);
815 if (italic
&& !(bold
)) {
816 g_string_printf(format
,
817 "<span foreground=\"%s\" font_desc=\"%s %s %d\" %s",
818 text
, family
, "Italic", size
, span
);
821 markup
= g_markup_printf_escaped(format
->str
, "text-format-up:");
822 IRRECO_PRINTF("FONT: %s\n", markup
);
824 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_up
), markup
);
826 value
= g_strdup_printf ("%u,%u,%u",
832 IRRECO_PRINTF("FONT: %s\n", color_string
);
834 IRRECO_PRINTF("FONT: %s\n", value
);
839 if(markup
!= NULL
) g_free(markup
);
840 if(text
!= NULL
) g_free(text
);
841 if(family
!= NULL
) g_free(family
);
842 g_string_free(format
, TRUE
);
844 pango_color_free(color
);
846 gtk_widget_destroy(GTK_WIDGET(dialog
));
852 * Set button text format
854 static void _set_font_format(IrrecoButtonCreatorDlg
*self
, const gchar
*button_format
,
860 GString
*format
= g_string_new(NULL
);
864 g_string_printf(format
, "%s", button_format
);
866 markup
= g_markup_printf_escaped(format
->str
, text
);
868 IRRECO_PRINTF("TEXT: %s\n", markup
);
870 if (strcmp(text
, gtk_label_get_text(GTK_LABEL(
871 self
->label_text_format_up
))) == 0) {
872 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_up
),
876 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_down
),
880 if(markup
!= NULL
) g_free(markup
);
881 g_string_free(format
, TRUE
);