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
;
113 GtkWidget
*scrolled_table
;
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
;
128 GtkWidget
*scrolled_table_settings
;
129 GtkWidget
*label_text_padding
;
130 GtkWidget
*label_text_h_align
;
131 GtkWidget
*label_text_v_align
;
134 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->constructed(object
);
136 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
138 irreco_data
= irreco_internal_dlg_get_irreco_data(IRRECO_INTERNAL_DLG(self
));
140 /* Construct dialog. */
141 gtk_window_set_title(GTK_WINDOW(self
), _("Button Creator "));
142 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
143 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
144 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
147 self
->cancel_button
= gtk_dialog_add_button(GTK_DIALOG(self
),
149 GTK_RESPONSE_CANCEL
);
150 self
->add_button
= gtk_dialog_add_button(GTK_DIALOG(self
), _("Add"),
152 gtk_widget_set_sensitive(self
->add_button
, FALSE
);
155 /* Create widgets. */
156 self
->notebook
= gtk_notebook_new();
158 /* Create widgets. */
159 scrolled_table
= gtk_scrolled_window_new(NULL
, NULL
);
160 table
= gtk_table_new(7, 9, TRUE
);
161 label_name
= gtk_label_new(_("Name:"));
162 label_select_unpressed
= gtk_label_new(_("Unpressed:"));
163 label_select_pressed
= gtk_label_new(_("Pressed:"));
164 self
->event_box_pressed
= gtk_event_box_new();
165 event_box_unpressed
= gtk_event_box_new();
166 self
->combobox_name
= gtk_combo_box_entry_new_text();
167 frame_unpressed
= gtk_frame_new("");
168 frame_pressed
= gtk_frame_new("");
169 vbox_unpressed_preview
= gtk_vbox_new(FALSE
, 8);
170 vbox_pressed_preview
= gtk_vbox_new(FALSE
, 8);
171 self
->label_unpressed_size
= gtk_label_new("");
172 self
->label_pressed_size
= gtk_label_new("");
173 self
->preview_image_unpressed
= gtk_image_new();
174 self
->preview_image_pressed
= gtk_image_new();
175 self
->add_button_unpressed
= gtk_button_new_with_label(_("Select"));
176 self
->add_button_pressed
= gtk_button_new_with_label(_("Select"));
178 /* Create settings widgets*/
179 scrolled_table_settings
= gtk_scrolled_window_new(NULL
, NULL
);
180 table_settings
= gtk_table_new(7, 9, TRUE
);
181 label_allow_text
= gtk_label_new(_("AllowText:"));
182 self
->label_text_format_up
= gtk_label_new(_("TextFormatUp:"));
183 self
->label_text_format_down
= gtk_label_new(_("TextFormatDown:"));
184 label_text_padding
= gtk_label_new(_("Text:Padding:"));
185 label_text_h_align
= gtk_label_new(_("TextHAlign:"));
186 label_text_v_align
= gtk_label_new(_("TextVAlign:"));
187 label_size
= gtk_label_new(_("ButtonSize:"));
188 self
->allow_text
= gtk_toggle_button_new();
189 self
->text_format_up
= gtk_button_new_with_label(_("Select"));
190 self
->text_format_down
= gtk_button_new_with_label(_("Select"));
191 self
->text_padding
= gtk_spin_button_new_with_range(0, 20, 1);
192 self
->text_h_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
193 self
->text_v_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
194 self
->unbutton_size
= gtk_spin_button_new_with_range(2, 5, 0.1);
195 self
->button_size
= gtk_spin_button_new_with_range(2, 5, 0.1);
196 self
->unpressed_path
= g_string_new(NULL
);
197 self
->pressed_path
= g_string_new(NULL
);
199 /* set button name/sensitive */
200 gtk_widget_set_name(self
->add_button_unpressed
,"unpressed");
201 gtk_widget_set_name(self
->add_button_pressed
,"pressed");
203 gtk_widget_set_sensitive(self
->add_button_pressed
, FALSE
);
204 gtk_widget_set_sensitive(self
->event_box_pressed
, FALSE
);
205 gtk_widget_set_sensitive(self
->text_format_up
, FALSE
);
206 gtk_widget_set_sensitive(self
->text_format_down
, FALSE
);
207 /* Set frame text bold */
208 gtk_frame_set_label_widget(GTK_FRAME(frame_unpressed
),
209 irreco_gtk_label_bold(
210 "Unpressed", 0, 0, 0, 0, 0, 0));
211 gtk_frame_set_label_widget(GTK_FRAME(frame_pressed
),
212 irreco_gtk_label_bold(
213 "Pressed", 0, 0, 0, 0, 0, 0));
215 /* equal to the text of the left-side */
216 gtk_misc_set_alignment(GTK_MISC(label_name
), 0, 0.5);
217 gtk_misc_set_alignment(GTK_MISC(label_select_unpressed
), 0, 0.5);
218 gtk_misc_set_alignment(GTK_MISC(label_select_pressed
), 0, 0.5);
220 gtk_misc_set_alignment(GTK_MISC(label_allow_text
), 0, 0.5);
221 gtk_misc_set_alignment(GTK_MISC(self
->label_text_format_up
), 0, 0.5);
222 gtk_misc_set_alignment(GTK_MISC(self
->label_text_format_down
), 0, 0.5);
223 gtk_misc_set_alignment(GTK_MISC(label_text_padding
), 0, 0.5);
224 gtk_misc_set_alignment(GTK_MISC(label_text_h_align
), 0, 0.5);
225 gtk_misc_set_alignment(GTK_MISC(label_text_v_align
), 0, 0.5);
226 gtk_misc_set_alignment(GTK_MISC(label_size
), 0, 0.5);
228 /* Set table on the scrolled */
229 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
233 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_table
),
235 GTK_POLICY_AUTOMATIC
);
237 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
238 scrolled_table_settings
),
239 GTK_WIDGET(table_settings
));
241 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
242 scrolled_table_settings
),
244 GTK_POLICY_AUTOMATIC
);
246 /* Create Notebook tabs. */
248 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
249 irreco_gtk_align(GTK_WIDGET(scrolled_table
),
250 0, 0, 1, 1, 8, 8, 8, 8),
251 gtk_label_new("BUTTONS"));
252 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
253 irreco_gtk_align(GTK_WIDGET(
254 scrolled_table_settings
),
255 0, 0, 1, 1, 8, 8, 8, 8),
256 gtk_label_new("SETTINGS"));
258 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
),
261 /* Set widgets on the table */
263 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
264 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
266 gtk_table_attach_defaults(GTK_TABLE(table
), label_name
, 0, 3, 0, 1);
267 gtk_table_attach_defaults(GTK_TABLE(table
),
268 label_select_unpressed
, 0, 3, 1, 2);
269 gtk_table_attach_defaults(GTK_TABLE(table
),
270 label_select_pressed
, 0, 3, 2, 3);
271 gtk_table_attach_defaults(GTK_TABLE(table
),
272 self
->combobox_name
, 3, 9, 0, 1);
273 gtk_table_attach_defaults(GTK_TABLE(table
),
274 self
->add_button_unpressed
, 3, 9, 1, 2);
275 gtk_table_attach_defaults(GTK_TABLE(table
),
276 self
->add_button_pressed
, 3, 9, 2, 3);
277 gtk_table_attach_defaults(GTK_TABLE(table
),
278 frame_unpressed
, 0, 4, 3, 7);
279 gtk_table_attach_defaults(GTK_TABLE(table
), frame_pressed
, 5, 9, 3, 7);
280 /* Set widgets on the table_settings */
281 gtk_table_set_row_spacings(GTK_TABLE(table_settings
), 6);
282 gtk_table_set_col_spacings(GTK_TABLE(table_settings
), 6);
284 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
285 label_allow_text
, 0, 4, 0, 1);
286 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
287 self
->label_text_format_up
, 0, 4, 1, 2);
288 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
289 self
->label_text_format_down
, 0, 4, 2, 3);
290 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
291 label_text_padding
, 0, 4, 3, 4);
292 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
293 label_text_h_align
, 0, 4, 4, 5);
294 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
295 label_text_v_align
, 0, 4, 5, 6);
296 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
297 label_size
, 0, 4, 6, 7);
299 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
300 self
->allow_text
, 4, 9, 0, 1);
301 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
302 self
->text_format_up
, 4, 9, 1, 2);
303 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
304 self
->text_format_down
, 4, 9, 2, 3);
305 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
306 self
->text_padding
, 4, 9, 3, 4);
307 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
308 self
->text_h_align
, 4, 9, 4, 5);
309 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
310 self
->text_v_align
, 4, 9, 5, 6);
311 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
312 self
->unbutton_size
, 4, 6, 6, 7);
313 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
314 self
->button_size
, 7, 9, 6, 7);
315 /* set preview image*/
317 gtk_container_add(GTK_CONTAINER(frame_unpressed
), event_box_unpressed
);
318 gtk_container_add(GTK_CONTAINER(event_box_unpressed
),
319 vbox_unpressed_preview
);
320 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
321 self
->preview_image_unpressed
);
322 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
323 self
->label_unpressed_size
);
325 gtk_container_add(GTK_CONTAINER(frame_pressed
), self
->event_box_pressed
);
326 gtk_container_add(GTK_CONTAINER(self
->event_box_pressed
),
327 vbox_pressed_preview
);
328 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
329 self
->preview_image_pressed
);
330 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
331 self
->label_pressed_size
);
336 /*Added button list on combobox*/
337 fill_buttons_combobox(self
);
339 /* set default settings on tab */
340 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
342 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
), 5);
343 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
), 0.5);
344 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
), 0.5);
345 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->unbutton_size
), 10);
346 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->button_size
), 10);
348 /* Set button name */
349 gtk_widget_set_name(self
->text_format_up
, "unpressed");
350 gtk_widget_set_name(self
->text_format_down
, "pressed");
351 /* Button signals. */
352 g_signal_connect(G_OBJECT(self
->add_button_unpressed
), "clicked",
353 G_CALLBACK(_signal_image_clicked
), self
);
354 g_signal_connect(G_OBJECT(self
->add_button_pressed
), "clicked",
355 G_CALLBACK(_signal_image_clicked
), self
);
357 g_signal_connect(G_OBJECT(event_box_unpressed
), "button-release-event",
358 G_CALLBACK(_unpressed_event_signal_image_clicked
),
360 g_signal_connect(G_OBJECT(self
->event_box_pressed
),
361 "button-release-event",
362 G_CALLBACK(_pressed_event_signal_image_clicked
),
365 g_signal_connect(G_OBJECT(self
->allow_text
), "toggled",
366 G_CALLBACK(_toggle_button_toggled
), self
);
368 g_signal_connect(G_OBJECT(self
->text_format_up
), "clicked",
369 G_CALLBACK(_select_font_format
), self
);
370 g_signal_connect(G_OBJECT(self
->text_format_down
), "clicked",
371 G_CALLBACK(_select_font_format
), self
);
372 g_signal_connect(G_OBJECT(self
->unbutton_size
), "value-changed",
373 G_CALLBACK(_unbutton_size_changed
), self
);
374 g_signal_connect(G_OBJECT(self
->button_size
), "value-changed",
375 G_CALLBACK(_button_size_changed
), self
);
377 gtk_widget_set_size_request(GTK_WIDGET(self
), 696, 396);
378 gtk_widget_show_all(GTK_WIDGET(self
));
384 irreco_button_creator_dlg_init (IrrecoButtonCreatorDlg
*object
)
391 irreco_button_creator_dlg_finalize (GObject
*object
)
393 /* TODO: Add deinitalization code here */
395 IrrecoButtonCreatorDlg
*self
;
398 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
400 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->finalize(object
);
406 irreco_button_creator_dlg_class_init (IrrecoButtonCreatorDlgClass
*klass
)
408 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
410 object_class
->finalize
= irreco_button_creator_dlg_finalize
;
411 object_class
->constructed
= irreco_button_creator_dlg_constructed
;
415 *irreco_button_creator_dlg_new(IrrecoData
*irreco_data
, GtkWindow
*parent
)
417 IrrecoButtonCreatorDlg
*self
;
421 self
= g_object_new(IRRECO_TYPE_BUTTON_CREATOR_DLG
,
422 "irreco-data", irreco_data
, NULL
);
423 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
425 IRRECO_RETURN_PTR(self
);
430 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
431 /* Private Functions */
432 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
434 * @name Private Functions
439 *Fill combobox from file
441 static void fill_buttons_combobox(IrrecoButtonCreatorDlg
*self
)
444 GKeyFile
*button_list
;
448 GError
*error
= NULL
;
451 button_list
= g_key_file_new();
452 g_key_file_load_from_file(button_list
, BUTTON_LIST_DIR
,
453 G_KEY_FILE_NONE
, &error
);
455 keys
= g_key_file_get_keys(button_list
, "button-names", &length
,
458 for(i
=0; i
<length
; i
++){
459 gtk_combo_box_append_text(GTK_COMBO_BOX(self
->combobox_name
),
460 g_key_file_get_string(button_list
,
461 "button-names", keys
[i
], &error
));
464 g_key_file_free(button_list
);
465 if(keys
!= NULL
) g_free(keys
);
471 _unbutton_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
)
473 GString
*image_path
= g_string_new(self
->unpressed_path
->str
);
477 IRRECO_PRINTF("PATH: %s\n", self
->unpressed_path
->str
);
479 _draw_preview_image(GTK_BUTTON(self
->text_format_up
), self
,
482 g_string_free(image_path
, TRUE
);
486 _button_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
)
488 GString
*image_path
= g_string_new(self
->unpressed_path
->str
);
492 IRRECO_PRINTF("PATH: %s\n", self
->unpressed_path
->str
);
494 _draw_preview_image(GTK_BUTTON(self
->text_format_down
), self
,
497 g_string_free(image_path
, TRUE
);
502 * Draw preview with current image.
505 _draw_preview_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
,
508 GError
*error
= NULL
;
509 GdkPixbuf
*pixbuf
= NULL
;
510 GString
*size
= g_string_new(NULL
);
514 g_assert(self
!= NULL
);
515 /* compared with whichever image */
516 if (g_str_equal("pressed", gtk_widget_get_name(GTK_WIDGET(button
)))) {
517 gint button_width
= 0;
518 gint button_height
= 0;
519 GdkPixbuf
*pixbuf_size
= NULL
;
522 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
523 IRRECO_BUTTON_PREVIEW_WIDHT
,
524 IRRECO_BUTTON_PREVIEW_HEIGHT
,
526 /* set sensitive if image are selected */
527 gtk_widget_set_sensitive(self
->add_button
, TRUE
);
529 if (irreco_gerror_check_print(&error
)) {
530 IRRECO_RETURN_BOOL(FALSE
);
534 g_string_printf(self
->pressed_path
, "%s", image
);
535 gtk_widget_realize(GTK_WIDGET(self
->preview_image_pressed
));
536 gtk_image_set_from_pixbuf(GTK_IMAGE(self
->preview_image_pressed
),
539 /* Show image real size */
540 pixbuf_size
= gdk_pixbuf_new_from_file(image
, &error
);
541 button_width
= atoi(g_strdup_printf("%.0f",
542 (gdk_pixbuf_get_width(
544 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
545 self
->button_size
)))));
546 button_height
= atoi(g_strdup_printf("%.0f",
547 (gdk_pixbuf_get_height(
549 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
550 self
->button_size
))))));
552 if (pixbuf_size
!= NULL
) g_object_unref(G_OBJECT(pixbuf_size
));
554 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", button_width
),
555 g_strdup_printf("%d", button_height
));
557 gtk_label_set_text(GTK_LABEL(self
->label_pressed_size
),
561 gint button_width
= 0;
562 gint button_height
= 0;
563 GdkPixbuf
*pixbuf_size
= NULL
;
566 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
567 IRRECO_BUTTON_PREVIEW_WIDHT
,
568 IRRECO_BUTTON_PREVIEW_HEIGHT
,
570 if (irreco_gerror_check_print(&error
)) {
571 IRRECO_RETURN_BOOL(FALSE
);
574 gtk_widget_realize(GTK_WIDGET(self
->preview_image_unpressed
));
575 gtk_image_set_from_pixbuf(GTK_IMAGE(
576 self
->preview_image_unpressed
),
579 /* Show image real size */
580 pixbuf_size
= gdk_pixbuf_new_from_file(image
, &error
);
581 button_width
= atoi(g_strdup_printf("%.0f",
582 (gdk_pixbuf_get_width(
584 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
585 self
->unbutton_size
)))));
586 button_height
= atoi(g_strdup_printf("%.0f",
587 (gdk_pixbuf_get_height(
589 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
590 self
->unbutton_size
))))));
591 if (pixbuf_size
!= NULL
) g_object_unref(G_OBJECT(pixbuf_size
));
593 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", button_width
),
594 g_strdup_printf("%d", button_height
));
596 gtk_label_set_text(GTK_LABEL(self
->label_unpressed_size
),
598 g_string_printf(self
->unpressed_path
, "%s", image
);
600 /* Set button sensitive */
601 gtk_widget_set_sensitive(self
->add_button_pressed
, TRUE
);
602 gtk_widget_set_sensitive(self
->event_box_pressed
, TRUE
);
605 g_string_free(size
, TRUE
);
606 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
607 IRRECO_RETURN_BOOL(TRUE
);
610 static void _select_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
613 GtkWidget
*file_dlg
= NULL
;
614 gchar
*image_dir
= NULL
;
617 /* Create image select dialog. */
619 file_dlg
= hildon_file_chooser_dialog_new(GTK_WINDOW(self
),
620 GTK_FILE_CHOOSER_ACTION_OPEN
);
621 gtk_window_set_title(GTK_WINDOW(file_dlg
),_("Select button image"));
622 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_dlg
), TRUE
);
623 image_dir
= g_build_path("/", getenv("HOME"), "MyDocs/.images/", NULL
);
624 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_dlg
),
628 /* Loop until user cancels or we get a valid image. */
629 gtk_widget_show_all(GTK_WIDGET(file_dlg
));
630 while (gtk_dialog_run(GTK_DIALOG(file_dlg
)) == GTK_RESPONSE_OK
) {
632 filename
= gtk_file_chooser_get_filename(
633 GTK_FILE_CHOOSER(file_dlg
));
635 /* Attempt to display the image. */
636 if (_draw_preview_image(button
, self
, filename
)) {
637 irreco_gstring_set_and_free(self
->filename
, filename
);
643 gchar
*basename
= g_path_get_basename(filename
);
644 irreco_error_dlg_printf(GTK_WINDOW(file_dlg
),
645 _("Cannot open image \"%s\""),
647 IRRECO_PRINTF("Image invalid.\n");
654 gtk_widget_destroy(file_dlg
);
660 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
662 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
664 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
665 /* Public Functions */
666 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
668 gboolean
irreco_button_creator_dlg_run(IrrecoData
*irreco_data
,
669 IrrecoTheme
* irreco_theme
,
670 GtkWindow
*parent_window
,
671 IrrecoThemeButton
*button
)
673 IrrecoButtonCreatorDlg
*self
;
675 gboolean loop
= TRUE
;
676 gboolean rvalue
= FALSE
;
679 self
= (IrrecoButtonCreatorDlg
*)irreco_button_creator_dlg_new(
680 irreco_data
, parent_window
);
681 self
->irreco_data
= irreco_data
;
682 self
->theme
= irreco_theme
;
684 IRRECO_PRINTF("Button: %s\n", button
->name
->str
);
685 if (g_utf8_strlen(button
->name
->str
, 1) >0) {
686 /* Sets the button details */
687 _set_button_details(self
, irreco_theme
, button
);
691 response
= gtk_dialog_run(GTK_DIALOG(self
));
693 case GTK_RESPONSE_OK
:
695 _set_new_button_details(self
, button
);
697 irreco_theme_button_print(button
);
702 case GTK_RESPONSE_CANCEL
:
703 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
709 IRRECO_DEBUG("default\n");
715 gtk_widget_destroy(GTK_WIDGET(self
));
716 IRRECO_RETURN_BOOL(rvalue
);
721 _set_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoTheme
*irreco_theme
,
722 IrrecoThemeButton
*button
)
726 /* Set button information on table */
727 gtk_combo_box_prepend_text(GTK_COMBO_BOX(self
->combobox_name
),
729 gtk_combo_box_set_active(GTK_COMBO_BOX(self
->combobox_name
),
731 _draw_preview_image(GTK_BUTTON(self
->add_button_unpressed
),
733 button
->image_up
->str
);
734 _draw_preview_image(GTK_BUTTON(self
->add_button_pressed
),
736 button
->image_down
->str
);
737 if (button
->allow_text
) {
738 gtk_button_clicked(GTK_BUTTON(self
->allow_text
));
741 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
),
742 button
->text_padding
);
744 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
),
745 button
->text_h_align
);
746 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
),
747 button
->text_v_align
);
749 if (strlen(button
->text_format_up
->str
) > 0) {
751 _set_font_format(self
, button
->text_format_up
->str
,
752 gtk_label_get_text(GTK_LABEL(
753 self
->label_text_format_up
)));
755 if (strlen(button
->text_format_down
->str
) > 0) {
757 _set_font_format(self
, button
->text_format_down
->str
,
758 gtk_label_get_text(GTK_LABEL(
759 self
->label_text_format_down
)));
761 /* Set button label & windown title */
762 gtk_button_set_label(GTK_BUTTON(self
->add_button
), "Save");
763 gtk_window_set_title(GTK_WINDOW(self
), _("Button Editor "));
770 _set_new_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoThemeButton
*button
)
774 gchar
*style_name
= NULL
;
775 gboolean allow_text
= FALSE
;
776 gint text_padding
= 0;
777 gfloat text_h_align
= 0;
778 gfloat text_v_align
= 0;
781 style_name
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(
782 self
->combobox_name
));
783 allow_text
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
785 text_padding
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
786 self
->text_padding
));
787 text_h_align
= gtk_spin_button_get_value(GTK_SPIN_BUTTON(
788 self
->text_h_align
));
789 text_v_align
= gtk_spin_button_get_value(GTK_SPIN_BUTTON(
790 self
->text_v_align
));
792 irreco_theme_button_set(button
,
796 self
->unpressed_path
->str
,
797 self
->pressed_path
->str
,
798 self
->unpressed_format
,
799 self
->pressed_format
,
808 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
809 /* Events and Callbacks */
810 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
813 * @name Events and Callbacks
818 _signal_image_clicked(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
821 _select_image(button
, self
);
825 static void _unpressed_event_signal_image_clicked(GtkWidget
*widget
,
826 GdkEventButton
*event
,
827 IrrecoButtonCreatorDlg
*self
)
831 gtk_button_clicked(GTK_BUTTON(self
->add_button_unpressed
));
836 static void _pressed_event_signal_image_clicked(GtkWidget
*widget
,
837 GdkEventButton
*event
,
838 IrrecoButtonCreatorDlg
*self
)
842 gtk_button_clicked(GTK_BUTTON(self
->add_button_pressed
));
847 static void _toggle_button_toggled(GtkToggleButton
*togglebutton
,
848 IrrecoButtonCreatorDlg
*self
)
852 if (gtk_toggle_button_get_active(togglebutton
)) {
853 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "YES");
854 gtk_widget_set_sensitive(self
->text_format_up
, TRUE
);
855 gtk_widget_set_sensitive(self
->text_format_down
, TRUE
);
857 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
858 gtk_widget_set_sensitive(self
->text_format_up
, FALSE
);
859 gtk_widget_set_sensitive(self
->text_format_down
, FALSE
);
865 *Select button font format
868 static void _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
872 GString
*format
= g_string_new(NULL
);
873 const gchar
*span
= ">%s</span>";
877 dialog
= gtk_font_selection_dialog_new("Button font");
879 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
) {
881 font
= gtk_font_selection_dialog_get_font_name(
882 GTK_FONT_SELECTION_DIALOG(dialog
));
884 /*g_string_printf(format,
885 "<span foreground=\"%s\" font_desc=\"%s\" %s",
886 "red", font, span);*/
887 g_string_printf(format
,
888 "<span font_desc=\"%s\" %s", font
, span
);
891 if (strcmp("unpressed", gtk_widget_get_name(
892 GTK_WIDGET(button
))) == 0) {
893 self
->unpressed_format
= format
->str
;
894 _set_font_format(self
, format
->str
,
895 gtk_label_get_text(GTK_LABEL(
896 self
->label_text_format_up
)));
898 self
->pressed_format
= format
->str
;
899 _set_font_format(self
, format
->str
,
900 gtk_label_get_text(GTK_LABEL(
901 self
->label_text_format_down
)));
904 gtk_widget_destroy(GTK_WIDGET(dialog
));
910 * Set button text format
913 _set_font_format(IrrecoButtonCreatorDlg
*self
, const gchar
*button_format
,
919 GString
*format
= g_string_new(NULL
);
923 g_string_printf(format
, "%s", button_format
);
925 markup
= g_markup_printf_escaped(format
->str
, text
);
927 IRRECO_PRINTF("TEXT: %s\n", markup
);
929 if (strcmp(text
, gtk_label_get_text(GTK_LABEL(
930 self
->label_text_format_up
))) == 0) {
931 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_up
),
935 gtk_label_set_markup(GTK_LABEL(self
->label_text_format_down
),
939 if(markup
!= NULL
) g_free(markup
);
940 g_string_free(format
, TRUE
);