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/4)
51 #define IRRECO_BUTTON_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT/4)
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 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
85 /* Construction & Destruction */
86 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
89 * @name Construction & Destruction
93 G_DEFINE_TYPE (IrrecoButtonCreatorDlg
, irreco_button_creator_dlg
,
94 IRRECO_TYPE_INTERNAL_DLG
)
95 static void irreco_button_creator_dlg_constructed(GObject
*object
)
97 /* TODO: Add initialization code here */
99 IrrecoData
*irreco_data
;
100 IrrecoButtonCreatorDlg
*self
;
103 GtkWidget
*frame_unpressed
;
104 GtkWidget
*frame_pressed
;
105 GtkWidget
*label_name
;
106 GtkWidget
*label_select_unpressed
;
107 GtkWidget
*label_select_pressed
;
108 GtkWidget
*event_box_unpressed
;
111 GtkWidget
*table_settings
;
112 GtkWidget
*label_allow_text
;
114 GtkWidget
*label_text_format_down
;
115 GtkWidget
*label_text_padding
;
116 GtkWidget
*label_text_h_align
;
117 GtkWidget
*label_text_v_align
;
124 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->constructed(object
);
126 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
128 irreco_data
= irreco_internal_dlg_get_irreco_data(IRRECO_INTERNAL_DLG(self
));
130 /* Construct dialog. */
131 gtk_window_set_title(GTK_WINDOW(self
), _("Button Creator "));
132 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
133 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
134 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
137 self
->cancel_button
= gtk_dialog_add_button(GTK_DIALOG(self
),
139 GTK_RESPONSE_CANCEL
);
140 self
->add_button
= gtk_dialog_add_button(GTK_DIALOG(self
), _("Add"),
143 /* Create widgets. */
144 self
->notebook
= gtk_notebook_new();
146 /* Create widgets. */
148 table
= gtk_table_new(7, 9, TRUE
);
149 label_name
= gtk_label_new(_("Name:"));
150 label_select_unpressed
= gtk_label_new(_("Unpressed:"));
151 label_select_pressed
= gtk_label_new(_("Pressed:"));
152 self
->event_box_pressed
= gtk_event_box_new();
153 event_box_unpressed
= gtk_event_box_new();
154 self
->combobox_name
= gtk_combo_box_entry_new_text();
155 frame_unpressed
= gtk_frame_new("");
156 frame_pressed
= gtk_frame_new("");
157 self
->preview_image_unpressed
= gtk_image_new();
158 self
->preview_image_pressed
= gtk_image_new();
159 self
->add_button_unpressed
= gtk_button_new_with_label(_("Select"));
160 self
->add_button_pressed
= gtk_button_new_with_label(_("Select"));
162 table_settings
= gtk_table_new(7, 9, TRUE
);
163 label_allow_text
= gtk_label_new(_("allow-text:"));
164 self
->label_text_format_up
= gtk_label_new(_("text-format-up:"));
165 label_text_format_down
= gtk_label_new(_("text-format-down:"));
166 label_text_padding
= gtk_label_new(_("text:padding:"));
167 label_text_h_align
= gtk_label_new(_("text-h-align:"));
168 label_text_v_align
= gtk_label_new(_("text-v-align:"));
169 self
->allow_text
= gtk_toggle_button_new();
170 self
->text_format_up
= gtk_button_new_with_label(_("Select"));
171 self
->text_format_down
= gtk_button_new_with_label(_("Select"));
172 self
->text_padding
= gtk_spin_button_new_with_range(0, 10, 1);
173 self
->text_h_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
174 self
->text_v_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
177 /* set button name/sensitive */
178 gtk_widget_set_name(self
->add_button_unpressed
,"unpressed");
179 gtk_widget_set_name(self
->add_button_pressed
,"pressed");
181 gtk_widget_set_sensitive(self
->add_button_pressed
, FALSE
);
182 gtk_widget_set_sensitive(self
->event_box_pressed
, FALSE
);
183 /* Set frame text bold */
184 gtk_frame_set_label_widget(GTK_FRAME(frame_unpressed
),
185 irreco_gtk_label_bold(
186 "Unpressed", 0, 0, 0, 0, 0, 0));
187 gtk_frame_set_label_widget(GTK_FRAME(frame_pressed
),
188 irreco_gtk_label_bold(
189 "Pressed", 0, 0, 0, 0, 0, 0));
191 /* Create Notebook tabs. */
193 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
194 irreco_gtk_align(GTK_WIDGET(table
),
195 0, 0, 1, 1, 8, 8, 8, 8),
196 gtk_label_new("BUTTONS"));
197 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
198 irreco_gtk_align(GTK_WIDGET(table_settings
),
199 0, 0, 1, 1, 8, 8, 8, 8),
200 gtk_label_new("SETTINGS"));
202 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
),
205 /* Set widgets on the table */
207 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
208 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
210 gtk_table_attach_defaults(GTK_TABLE(table
), label_name
, 0, 3, 0, 1);
211 gtk_table_attach_defaults(GTK_TABLE(table
),
212 label_select_unpressed
, 0, 3, 1, 2);
213 gtk_table_attach_defaults(GTK_TABLE(table
),
214 label_select_pressed
, 0, 3, 2, 3);
215 gtk_table_attach_defaults(GTK_TABLE(table
),
216 self
->combobox_name
, 3, 9, 0, 1);
217 gtk_table_attach_defaults(GTK_TABLE(table
),
218 self
->add_button_unpressed
, 3, 9, 1, 2);
219 gtk_table_attach_defaults(GTK_TABLE(table
),
220 self
->add_button_pressed
, 3, 9, 2, 3);
221 gtk_table_attach_defaults(GTK_TABLE(table
),
222 frame_unpressed
, 0, 4, 3, 7);
223 gtk_table_attach_defaults(GTK_TABLE(table
), frame_pressed
, 5, 9, 3, 7);
224 /* Set widgets on the table_settings */
225 gtk_table_set_row_spacings(GTK_TABLE(table_settings
), 6);
226 gtk_table_set_col_spacings(GTK_TABLE(table_settings
), 6);
228 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
229 label_allow_text
, 0, 4, 0, 1);
230 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
231 self
->label_text_format_up
, 0, 4, 1, 2);
232 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
233 label_text_format_down
, 0, 4, 2, 3);
234 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
235 label_text_padding
, 0, 4, 3, 4);
236 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
237 label_text_h_align
, 0, 4, 4, 5);
238 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
239 label_text_v_align
, 0, 4, 5, 6);
241 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
242 self
->allow_text
, 4, 9, 0, 1);
243 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
244 self
->text_format_up
, 4, 9, 1, 2);
245 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
246 self
->text_format_down
, 4, 9, 2, 3);
247 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
248 self
->text_padding
, 4, 9, 3, 4);
249 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
250 self
->text_h_align
, 4, 9, 4, 5);
251 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
252 self
->text_v_align
, 4, 9, 5, 6);
253 /* set preview image*/
255 gtk_container_add(GTK_CONTAINER(frame_unpressed
), event_box_unpressed
);
256 gtk_container_add(GTK_CONTAINER(event_box_unpressed
),
257 self
->preview_image_unpressed
);
258 gtk_container_add(GTK_CONTAINER(frame_pressed
),
259 self
->event_box_pressed
);
260 gtk_container_add(GTK_CONTAINER(self
->event_box_pressed
),
261 self
->preview_image_pressed
);
262 /*Added button list on combobox*/
263 fill_buttons_combobox(self
);
265 /* set settings tab */
266 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
268 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
), 5);
269 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
), 0.5);
270 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
), 0.5);
274 /* Button signals. */
275 g_signal_connect(G_OBJECT(self
->add_button_unpressed
), "clicked",
276 G_CALLBACK(_signal_image_clicked
), self
);
277 g_signal_connect(G_OBJECT(self
->add_button_pressed
), "clicked",
278 G_CALLBACK(_signal_image_clicked
), self
);
280 g_signal_connect(G_OBJECT(event_box_unpressed
), "button-release-event",
281 G_CALLBACK(_unpressed_event_signal_image_clicked
),
283 g_signal_connect(G_OBJECT(self
->event_box_pressed
),
284 "button-release-event",
285 G_CALLBACK(_pressed_event_signal_image_clicked
),
288 g_signal_connect(G_OBJECT(self
->allow_text
), "toggled",
289 G_CALLBACK(_toggle_button_toggled
), self
);
291 g_signal_connect(G_OBJECT(self
->text_format_up
), "clicked",
292 G_CALLBACK(_select_font_format
), self
);
293 g_signal_connect(G_OBJECT(self
->text_format_down
), "clicked",
294 G_CALLBACK(_select_font_format
), self
);
296 gtk_widget_show_all(GTK_WIDGET(self
));
301 irreco_button_creator_dlg_init (IrrecoButtonCreatorDlg
*object
)
308 irreco_button_creator_dlg_finalize (GObject
*object
)
310 /* TODO: Add deinitalization code here */
312 IrrecoButtonCreatorDlg
*self
;
315 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
317 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->finalize(object
);
323 irreco_button_creator_dlg_class_init (IrrecoButtonCreatorDlgClass
*klass
)
325 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
327 object_class
->finalize
= irreco_button_creator_dlg_finalize
;
328 object_class
->constructed
= irreco_button_creator_dlg_constructed
;
332 *irreco_button_creator_dlg_new(IrrecoData
*irreco_data
, GtkWindow
*parent
)
334 IrrecoButtonCreatorDlg
*self
;
338 self
= g_object_new(IRRECO_TYPE_BUTTON_CREATOR_DLG
,
339 "irreco-data", irreco_data
, NULL
);
340 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
342 IRRECO_RETURN_PTR(self
);
346 * @todo Replace calls to irreco_background_creator_dlg_create() with
347 * irreco_background_creator_dlg_new().
349 IrrecoButtonCreatorDlg
350 *irreco_button_creator_dlg_create(IrrecoData
*irreco_data
,
351 GtkWindow
*parent_window
)
354 IRRECO_RETURN_PTR(irreco_button_creator_dlg_new(
355 irreco_data
, parent_window
));
360 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
361 /* Private Functions */
362 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
364 * @name Private Functions
367 static void fill_buttons_combobox(IrrecoButtonCreatorDlg
*self
)
370 GKeyFile
*button_list
;
374 GError
*error
= NULL
;
377 button_list
= g_key_file_new();
379 g_key_file_load_from_file(button_list
, BUTTON_LIST_DIR
,
380 G_KEY_FILE_NONE
, &error
);
382 keys
= g_key_file_get_keys(button_list
, "button-names", &length
,
385 for(i
=0; i
<length
; i
++){
386 gtk_combo_box_append_text(GTK_COMBO_BOX(self
->combobox_name
),
387 g_key_file_get_string(button_list
,
388 "button-names", keys
[i
], &error
));
391 g_key_file_free(button_list
);
392 if(keys
!= NULL
) g_free(keys
);
397 * Draw preview with current image.
400 _draw_preview_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
,
403 GError
*error
= NULL
;
404 GdkPixbuf
*pixbuf
= NULL
;
408 g_assert(self
!= NULL
);
410 /* compared with whichever image */
411 if (g_str_equal("pressed", gtk_widget_get_name(GTK_WIDGET(button
)))) {
413 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
414 IRRECO_BUTTON_PREVIEW_WIDHT
,
415 IRRECO_BUTTON_PREVIEW_HEIGHT
,
417 if (irreco_gerror_check_print(&error
)) {
418 IRRECO_RETURN_BOOL(FALSE
);
421 gtk_widget_realize(GTK_WIDGET(self
->preview_image_pressed
));
422 gtk_image_set_from_pixbuf(GTK_IMAGE(self
->preview_image_pressed
),
427 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
428 IRRECO_BUTTON_PREVIEW_WIDHT
,
429 IRRECO_BUTTON_PREVIEW_HEIGHT
,
431 if (irreco_gerror_check_print(&error
)) {
432 IRRECO_RETURN_BOOL(FALSE
);
435 gtk_widget_realize(GTK_WIDGET(self
->preview_image_unpressed
));
436 gtk_image_set_from_pixbuf(GTK_IMAGE(
437 self
->preview_image_unpressed
),
440 /* Set button sensitive */
441 gtk_widget_set_sensitive(self
->add_button_pressed
, TRUE
);
442 gtk_widget_set_sensitive(self
->event_box_pressed
, TRUE
);
445 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
447 IRRECO_RETURN_BOOL(TRUE
);
451 static void _select_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
454 GtkWidget
*file_dlg
= NULL
;
455 gchar
*image_dir
= NULL
;
458 /* Create image select dialog. */
460 file_dlg
= hildon_file_chooser_dialog_new(GTK_WINDOW(self
),
461 GTK_FILE_CHOOSER_ACTION_OPEN
);
462 gtk_window_set_title(GTK_WINDOW(file_dlg
),_("Select button image"));
463 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_dlg
), TRUE
);
464 image_dir
= g_build_path("/", getenv("HOME"), "MyDocs/.images/", NULL
);
465 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_dlg
),
469 /* Loop until user cancels or we get a valid image. */
470 gtk_widget_show_all(GTK_WIDGET(file_dlg
));
471 while (gtk_dialog_run(GTK_DIALOG(file_dlg
)) == GTK_RESPONSE_OK
) {
473 filename
= gtk_file_chooser_get_filename(
474 GTK_FILE_CHOOSER(file_dlg
));
476 /* Attempt to display the image. */
477 if (_draw_preview_image(button
, self
, filename
)) {
478 irreco_gstring_set_and_free(self
->filename
, filename
);
484 gchar
*basename
= g_path_get_basename(filename
);
485 irreco_error_dlg_printf(GTK_WINDOW(file_dlg
),
486 _("Cannot open image \"%s\""),
488 IRRECO_PRINTF("Image invalid.\n");
495 gtk_widget_destroy(file_dlg
);
502 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
504 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
507 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=
509 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
510 /* Public Functions */
511 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
513 gboolean
irreco_button_creator_dlg_run(IrrecoData
*irreco_data
,
514 GtkWindow
*parent_window
)
516 IrrecoButtonCreatorDlg
*self
;
518 gboolean loop
= TRUE
;
519 gboolean rvalue
= FALSE
;
523 self
= (IrrecoButtonCreatorDlg
*)irreco_button_creator_dlg_create(
524 irreco_data
, parent_window
);
527 response
= gtk_dialog_run(GTK_DIALOG(self
));
529 case GTK_RESPONSE_OK
:
531 self
->loader_state
= LOADER_STATE_INIT
;
535 case GTK_RESPONSE_CANCEL
:
536 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
540 /* case GTK_RESPONSE_CLOSE:
541 IRRECO_DEBUG("GTK_RESPONSE_CLOSE\n");
548 IRRECO_DEBUG("default\n");
554 gtk_widget_destroy(GTK_WIDGET(self
));
556 IRRECO_RETURN_BOOL(rvalue
);
558 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
559 /* Events and Callbacks */
560 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
563 * @name Events and Callbacks
568 _signal_image_clicked(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
571 _select_image(button
, self
);
575 static void _unpressed_event_signal_image_clicked(GtkWidget
*widget
,
576 GdkEventButton
*event
,
577 IrrecoButtonCreatorDlg
*self
)
581 gtk_button_clicked(GTK_BUTTON(self
->add_button_unpressed
));
586 static void _pressed_event_signal_image_clicked(GtkWidget
*widget
,
587 GdkEventButton
*event
,
588 IrrecoButtonCreatorDlg
*self
)
592 gtk_button_clicked(GTK_BUTTON(self
->add_button_pressed
));
598 static void _toggle_button_toggled(GtkToggleButton
*togglebutton
,
599 IrrecoButtonCreatorDlg
*self
)
603 if (gtk_toggle_button_get_active(togglebutton
)) {
604 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "YES");
606 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
612 *Select button font format
614 /*static void _select_font_format(IrrecoButtonCreatorDlg *self)
616 GtkWidget *font_dialog;
619 font_dialog = gtk_font_selection_dialog_new("Button font");
621 gtk_dialog_run(GTK_DIALOG(font_dialog));
624 font = gtk_font_selection_dialog_get_font (GTK_FONT_SELECTION_DIALOG(font_dialog));
631 static void _select_font_format(GtkButton *button, IrrecoButtonCreatorDlg *self)
633 GtkWidget *font_dlg = NULL;
638 font_dlg = hildon_font_selection_dialog_new(GTK_WINDOW(self),
639 "Select font format");
642 if (gtk_dialog_run(GTK_DIALOG(font_dlg)) == GTK_RESPONSE_OK) {
644 text = hildon_font_selection_dialog_get_preview_text
645 (HILDON_FONT_SELECTION_DIALOG(font_dlg));
650 IRRECO_PRINTF("TEXT: %s \n", text);
651 gtk_widget_destroy(font_dlg);
655 gtk_widget_destroy(font_dlg);
660 static void _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
663 HildonFontSelectionDialog
*dialog
= NULL
;
664 PangoFontDescription
*font
= NULL
;
666 gboolean bold
, italic
;
667 gchar
*family
= NULL
;
669 const gchar
*span
= ">%s</span>";
673 GString
*format
= g_string_new(NULL
);
678 font
= pango_font_description_new();
682 dialog
= HILDON_FONT_SELECTION_DIALOG(hildon_font_selection_dialog_new(
685 gtk_widget_show_all (GTK_WIDGET(dialog
));
686 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
) {
687 g_object_get(G_OBJECT(dialog
),
696 text
= pango_color_to_string(color
);
697 IRRECO_PRINTF("FONT: %s\n", text
);
699 g_string_printf(format
,
700 "<span foreground=\"%s\" font_desc=\"%s %d\" %s",
701 text
, family
, size
, span
);
704 g_string_printf(format
,
705 "<span foreground=\"%s\" font_desc=\"%s %s %d\" %s",
706 text
, family
, "Bold", size
, span
);
708 g_string_printf(format
,
709 "<span foreground=\"%s\" font_desc=\"%s %s %s %d\" %s",
710 text
, family
, "Bold", "Italic", size
, span
);
713 if (italic
&& !(bold
)) {
714 g_string_printf(format
,
715 "<span foreground=\"%s\" font_desc=\"%s %s %d\" %s",
716 text
, family
, "Italic", size
, span
);
719 markup
= g_markup_printf_escaped(format
->str
, "text-format-up:");
720 IRRECO_PRINTF("FONT: %s\n", markup
);
722 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_up
), markup
);
725 if(markup
!= NULL
) g_free(markup
);
726 if(text
!= NULL
) g_free(text
);
727 if(family
!= NULL
) g_free(family
);
728 g_string_free(format
, TRUE
);
730 pango_color_free(color
);
732 gtk_widget_destroy(GTK_WIDGET(dialog
));