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
;
132 GtkWidget
*label_text_format_up
;
133 GtkWidget
*label_text_format_down
;
136 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->constructed(object
);
138 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
140 irreco_data
= irreco_internal_dlg_get_irreco_data(IRRECO_INTERNAL_DLG(self
));
142 /* Construct dialog. */
143 gtk_window_set_title(GTK_WINDOW(self
), _("Create a Button"));
144 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
145 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
146 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
149 self
->cancel_button
= gtk_dialog_add_button(GTK_DIALOG(self
),
151 GTK_RESPONSE_CANCEL
);
152 self
->add_button
= gtk_dialog_add_button(GTK_DIALOG(self
), _("Add"),
154 gtk_widget_set_sensitive(self
->add_button
, FALSE
);
157 /* Create widgets. */
158 self
->notebook
= gtk_notebook_new();
160 /* Create widgets. */
161 scrolled_table
= gtk_scrolled_window_new(NULL
, NULL
);
162 table
= gtk_table_new(7, 9, TRUE
);
163 label_name
= gtk_label_new(_("Name:"));
164 label_select_unpressed
= gtk_label_new(_("Unpressed:"));
165 label_select_pressed
= gtk_label_new(_("Pressed:"));
166 self
->event_box_pressed
= gtk_event_box_new();
167 event_box_unpressed
= gtk_event_box_new();
168 self
->combobox_name
= gtk_combo_box_entry_new_text();
169 frame_unpressed
= gtk_frame_new("");
170 frame_pressed
= gtk_frame_new("");
171 vbox_unpressed_preview
= gtk_vbox_new(FALSE
, 8);
172 vbox_pressed_preview
= gtk_vbox_new(FALSE
, 8);
173 self
->label_unpressed_size
= gtk_label_new("");
174 self
->label_pressed_size
= gtk_label_new("");
175 self
->preview_image_unpressed
= gtk_image_new();
176 self
->preview_image_pressed
= gtk_image_new();
177 self
->add_button_unpressed
= gtk_button_new_with_label(_("Select"));
178 self
->add_button_pressed
= gtk_button_new_with_label(_("Select"));
180 /* Create settings widgets*/
181 scrolled_table_settings
= gtk_scrolled_window_new(NULL
, NULL
);
182 table_settings
= gtk_table_new(7, 9, TRUE
);
183 label_allow_text
= gtk_label_new(_("AllowText:"));
184 label_text_format_up
= gtk_label_new(_("TextFormatUp:"));
185 label_text_format_down
= gtk_label_new(_("TextFormatDown:"));
186 self
->label_sample_text_format_up
= gtk_label_new(_("Sample1"));
187 self
->label_sample_text_format_down
= gtk_label_new(_("Sample2"));
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 label_size
= gtk_label_new(_("ButtonSize:"));
192 self
->allow_text
= gtk_toggle_button_new();
193 self
->text_format_up
= gtk_button_new_with_label(_("Select"));
194 self
->text_format_down
= gtk_button_new_with_label(_("Select"));
195 self
->text_padding
= gtk_spin_button_new_with_range(0, 20, 1);
196 self
->text_h_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
197 self
->text_v_align
= gtk_spin_button_new_with_range(0, 1, 0.1);;
198 self
->unbutton_size
= gtk_spin_button_new_with_range(2, 5, 0.1);
199 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 /* equal to the text of the left-side */
220 gtk_misc_set_alignment(GTK_MISC(label_name
), 0, 0.5);
221 gtk_misc_set_alignment(GTK_MISC(label_select_unpressed
), 0, 0.5);
222 gtk_misc_set_alignment(GTK_MISC(label_select_pressed
), 0, 0.5);
224 gtk_misc_set_alignment(GTK_MISC(label_allow_text
), 0, 0.5);
225 gtk_misc_set_alignment(GTK_MISC(label_text_format_up
), 0, 0.5);
226 gtk_misc_set_alignment(GTK_MISC(label_text_format_down
), 0, 0.5);
227 gtk_misc_set_alignment(GTK_MISC(self
->label_sample_text_format_up
), 0, 0.5);
228 gtk_misc_set_alignment(GTK_MISC(self
->label_sample_text_format_down
), 0, 0.5);
229 gtk_misc_set_alignment(GTK_MISC(label_text_padding
), 0, 0.5);
230 gtk_misc_set_alignment(GTK_MISC(label_text_h_align
), 0, 0.5);
231 gtk_misc_set_alignment(GTK_MISC(label_text_v_align
), 0, 0.5);
232 gtk_misc_set_alignment(GTK_MISC(label_size
), 0, 0.5);
234 /* Set table on the scrolled */
235 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
239 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_table
),
241 GTK_POLICY_AUTOMATIC
);
243 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
244 scrolled_table_settings
),
245 GTK_WIDGET(table_settings
));
247 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
248 scrolled_table_settings
),
250 GTK_POLICY_AUTOMATIC
);
252 /* Create Notebook tabs. */
254 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
255 irreco_gtk_align(GTK_WIDGET(scrolled_table
),
256 0, 0, 1, 1, 8, 8, 8, 8),
257 gtk_label_new("BUTTONS"));
258 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
259 irreco_gtk_align(GTK_WIDGET(
260 scrolled_table_settings
),
261 0, 0, 1, 1, 8, 8, 8, 8),
262 gtk_label_new("SETTINGS"));
264 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
),
267 /* Set widgets on the table */
269 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
270 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
272 gtk_table_attach_defaults(GTK_TABLE(table
), label_name
, 0, 3, 0, 1);
273 gtk_table_attach_defaults(GTK_TABLE(table
),
274 label_select_unpressed
, 0, 3, 1, 2);
275 gtk_table_attach_defaults(GTK_TABLE(table
),
276 label_select_pressed
, 0, 3, 2, 3);
277 gtk_table_attach_defaults(GTK_TABLE(table
),
278 self
->combobox_name
, 3, 9, 0, 1);
279 gtk_table_attach_defaults(GTK_TABLE(table
),
280 self
->add_button_unpressed
, 3, 9, 1, 2);
281 gtk_table_attach_defaults(GTK_TABLE(table
),
282 self
->add_button_pressed
, 3, 9, 2, 3);
283 gtk_table_attach_defaults(GTK_TABLE(table
),
284 frame_unpressed
, 0, 4, 3, 7);
285 gtk_table_attach_defaults(GTK_TABLE(table
), frame_pressed
, 5, 9, 3, 7);
286 /* Set widgets on the table_settings */
287 gtk_table_set_row_spacings(GTK_TABLE(table_settings
), 6);
288 gtk_table_set_col_spacings(GTK_TABLE(table_settings
), 6);
290 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
291 label_allow_text
, 0, 4, 0, 1);
292 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
293 label_text_format_up
, 0, 4, 1, 2);
294 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
295 label_text_format_down
, 0, 4, 2, 3);
296 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
297 self
->label_sample_text_format_up
, 4, 7, 1, 2);
298 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
299 self
->label_sample_text_format_down
, 4, 7, 2, 3);
300 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
301 label_text_padding
, 0, 4, 3, 4);
302 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
303 label_text_h_align
, 0, 4, 4, 5);
304 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
305 label_text_v_align
, 0, 4, 5, 6);
306 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
307 label_size
, 0, 4, 6, 7);
309 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
310 self
->allow_text
, 4, 9, 0, 1);
311 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
312 self
->text_format_up
, 7, 9, 1, 2);
313 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
314 self
->text_format_down
, 7, 9, 2, 3);
315 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
316 self
->text_padding
, 4, 9, 3, 4);
317 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
318 self
->text_h_align
, 4, 9, 4, 5);
319 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
320 self
->text_v_align
, 4, 9, 5, 6);
321 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
322 self
->unbutton_size
, 4, 6, 6, 7);
323 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
324 self
->button_size
, 7, 9, 6, 7);
325 /* set preview image*/
327 gtk_container_add(GTK_CONTAINER(frame_unpressed
), event_box_unpressed
);
328 gtk_container_add(GTK_CONTAINER(event_box_unpressed
),
329 vbox_unpressed_preview
);
330 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
331 self
->preview_image_unpressed
);
332 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
333 self
->label_unpressed_size
);
335 gtk_container_add(GTK_CONTAINER(frame_pressed
), self
->event_box_pressed
);
336 gtk_container_add(GTK_CONTAINER(self
->event_box_pressed
),
337 vbox_pressed_preview
);
338 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
339 self
->preview_image_pressed
);
340 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
341 self
->label_pressed_size
);
346 /*Added button list on combobox*/
347 fill_buttons_combobox(self
);
349 /* set default settings on tab */
350 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
352 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
), 5);
353 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
), 0.5);
354 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
), 0.5);
355 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->unbutton_size
), 10);
356 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->button_size
), 10);
358 /* Set button name */
359 gtk_widget_set_name(self
->text_format_up
, "unpressed");
360 gtk_widget_set_name(self
->text_format_down
, "pressed");
361 /* Button signals. */
362 g_signal_connect(G_OBJECT(self
->add_button_unpressed
), "clicked",
363 G_CALLBACK(_signal_image_clicked
), self
);
364 g_signal_connect(G_OBJECT(self
->add_button_pressed
), "clicked",
365 G_CALLBACK(_signal_image_clicked
), self
);
367 g_signal_connect(G_OBJECT(event_box_unpressed
), "button-release-event",
368 G_CALLBACK(_unpressed_event_signal_image_clicked
),
370 g_signal_connect(G_OBJECT(self
->event_box_pressed
),
371 "button-release-event",
372 G_CALLBACK(_pressed_event_signal_image_clicked
),
375 g_signal_connect(G_OBJECT(self
->allow_text
), "toggled",
376 G_CALLBACK(_toggle_button_toggled
), self
);
378 g_signal_connect(G_OBJECT(self
->text_format_up
), "clicked",
379 G_CALLBACK(_select_font_format
), self
);
380 g_signal_connect(G_OBJECT(self
->text_format_down
), "clicked",
381 G_CALLBACK(_select_font_format
), self
);
382 g_signal_connect(G_OBJECT(self
->unbutton_size
), "value-changed",
383 G_CALLBACK(_unbutton_size_changed
), self
);
384 g_signal_connect(G_OBJECT(self
->button_size
), "value-changed",
385 G_CALLBACK(_button_size_changed
), self
);
387 gtk_widget_set_size_request(GTK_WIDGET(self
), 696, 396);
388 gtk_widget_show_all(GTK_WIDGET(self
));
390 /* Hide Button size widgets */
391 gtk_widget_hide(label_size
);
392 gtk_widget_hide(self
->unbutton_size
);
393 gtk_widget_hide(self
->button_size
);
399 irreco_button_creator_dlg_init (IrrecoButtonCreatorDlg
*object
)
406 irreco_button_creator_dlg_finalize (GObject
*object
)
408 /* TODO: Add deinitalization code here */
410 IrrecoButtonCreatorDlg
*self
;
413 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
415 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->finalize(object
);
421 irreco_button_creator_dlg_class_init (IrrecoButtonCreatorDlgClass
*klass
)
423 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
425 object_class
->finalize
= irreco_button_creator_dlg_finalize
;
426 object_class
->constructed
= irreco_button_creator_dlg_constructed
;
430 *irreco_button_creator_dlg_new(IrrecoData
*irreco_data
, GtkWindow
*parent
)
432 IrrecoButtonCreatorDlg
*self
;
436 self
= g_object_new(IRRECO_TYPE_BUTTON_CREATOR_DLG
,
437 "irreco-data", irreco_data
, NULL
);
438 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
440 IRRECO_RETURN_PTR(self
);
445 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
446 /* Private Functions */
447 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
449 * @name Private Functions
454 *Fill combobox from file
456 static void fill_buttons_combobox(IrrecoButtonCreatorDlg
*self
)
459 GKeyFile
*button_list
;
463 GError
*error
= NULL
;
466 button_list
= g_key_file_new();
467 g_key_file_load_from_file(button_list
, BUTTON_LIST_DIR
,
468 G_KEY_FILE_NONE
, &error
);
470 keys
= g_key_file_get_keys(button_list
, "button-names", &length
,
473 for(i
=0; i
<length
; i
++){
474 gtk_combo_box_append_text(GTK_COMBO_BOX(self
->combobox_name
),
475 g_key_file_get_string(button_list
,
476 "button-names", keys
[i
], &error
));
479 g_key_file_free(button_list
);
480 if(keys
!= NULL
) g_free(keys
);
486 _unbutton_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_up
), self
,
497 g_string_free(image_path
, TRUE
);
501 _button_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
)
503 GString
*image_path
= g_string_new(self
->unpressed_path
->str
);
507 IRRECO_PRINTF("PATH: %s\n", self
->unpressed_path
->str
);
509 _draw_preview_image(GTK_BUTTON(self
->text_format_down
), self
,
512 g_string_free(image_path
, TRUE
);
517 * Draw preview with current image.
520 _draw_preview_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
,
523 GError
*error
= NULL
;
524 GdkPixbuf
*pixbuf
= NULL
;
525 GString
*size
= g_string_new(NULL
);
529 g_assert(self
!= NULL
);
530 /* compared with whichever image */
531 if (g_str_equal("pressed", gtk_widget_get_name(GTK_WIDGET(button
)))) {
532 gint button_width
= 0;
533 gint button_height
= 0;
534 GdkPixbuf
*pixbuf_size
= NULL
;
537 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
538 IRRECO_BUTTON_PREVIEW_WIDHT
,
539 IRRECO_BUTTON_PREVIEW_HEIGHT
,
541 /* set sensitive if image are selected */
542 gtk_widget_set_sensitive(self
->add_button
, TRUE
);
544 if (irreco_gerror_check_print(&error
)) {
545 IRRECO_RETURN_BOOL(FALSE
);
549 g_string_printf(self
->pressed_path
, "%s", image
);
550 gtk_widget_realize(GTK_WIDGET(self
->preview_image_pressed
));
551 gtk_image_set_from_pixbuf(GTK_IMAGE(self
->preview_image_pressed
),
554 /* Show image real size */
555 pixbuf_size
= gdk_pixbuf_new_from_file(image
, &error
);
556 button_width
= atoi(g_strdup_printf("%.0f",
557 (gdk_pixbuf_get_width(
559 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
560 self
->button_size
)))));
561 button_height
= atoi(g_strdup_printf("%.0f",
562 (gdk_pixbuf_get_height(
564 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
565 self
->button_size
))))));
567 if (pixbuf_size
!= NULL
) g_object_unref(G_OBJECT(pixbuf_size
));
569 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", button_width
),
570 g_strdup_printf("%d", button_height
));
572 gtk_label_set_text(GTK_LABEL(self
->label_pressed_size
),
576 gint button_width
= 0;
577 gint button_height
= 0;
578 GdkPixbuf
*pixbuf_size
= NULL
;
581 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
582 IRRECO_BUTTON_PREVIEW_WIDHT
,
583 IRRECO_BUTTON_PREVIEW_HEIGHT
,
585 if (irreco_gerror_check_print(&error
)) {
586 IRRECO_RETURN_BOOL(FALSE
);
589 gtk_widget_realize(GTK_WIDGET(self
->preview_image_unpressed
));
590 gtk_image_set_from_pixbuf(GTK_IMAGE(
591 self
->preview_image_unpressed
),
594 /* Show image real size */
595 pixbuf_size
= gdk_pixbuf_new_from_file(image
, &error
);
596 button_width
= atoi(g_strdup_printf("%.0f",
597 (gdk_pixbuf_get_width(
599 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
600 self
->unbutton_size
)))));
601 button_height
= atoi(g_strdup_printf("%.0f",
602 (gdk_pixbuf_get_height(
604 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
605 self
->unbutton_size
))))));
606 if (pixbuf_size
!= NULL
) g_object_unref(G_OBJECT(pixbuf_size
));
608 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", button_width
),
609 g_strdup_printf("%d", button_height
));
611 gtk_label_set_text(GTK_LABEL(self
->label_unpressed_size
),
613 g_string_printf(self
->unpressed_path
, "%s", image
);
615 /* Set button sensitive */
616 gtk_widget_set_sensitive(self
->add_button_pressed
, TRUE
);
617 gtk_widget_set_sensitive(self
->event_box_pressed
, TRUE
);
620 g_string_free(size
, TRUE
);
621 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
622 IRRECO_RETURN_BOOL(TRUE
);
625 static void _select_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
628 GtkWidget
*file_dlg
= NULL
;
629 gchar
*image_dir
= NULL
;
632 /* Create image select dialog. */
634 file_dlg
= hildon_file_chooser_dialog_new(GTK_WINDOW(self
),
635 GTK_FILE_CHOOSER_ACTION_OPEN
);
636 gtk_window_set_title(GTK_WINDOW(file_dlg
),_("Select button image"));
637 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_dlg
), TRUE
);
638 image_dir
= g_build_path("/", getenv("HOME"), "MyDocs/.images/", NULL
);
639 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_dlg
),
643 /* Loop until user cancels or we get a valid image. */
644 gtk_widget_show_all(GTK_WIDGET(file_dlg
));
645 while (gtk_dialog_run(GTK_DIALOG(file_dlg
)) == GTK_RESPONSE_OK
) {
647 filename
= gtk_file_chooser_get_filename(
648 GTK_FILE_CHOOSER(file_dlg
));
650 /* Attempt to display the image. */
651 if (_draw_preview_image(button
, self
, filename
)) {
652 irreco_gstring_set_and_free(self
->filename
, filename
);
658 gchar
*basename
= g_path_get_basename(filename
);
659 irreco_error_dlg_printf(GTK_WINDOW(file_dlg
),
660 _("Cannot open image \"%s\""),
662 IRRECO_PRINTF("Image invalid.\n");
669 gtk_widget_destroy(file_dlg
);
675 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
677 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
679 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
680 /* Public Functions */
681 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
683 gboolean
irreco_button_creator_dlg_run(IrrecoData
*irreco_data
,
684 IrrecoTheme
* irreco_theme
,
685 GtkWindow
*parent_window
,
686 IrrecoThemeButton
*button
)
688 IrrecoButtonCreatorDlg
*self
;
690 gboolean loop
= TRUE
;
691 gboolean rvalue
= FALSE
;
694 self
= (IrrecoButtonCreatorDlg
*)irreco_button_creator_dlg_new(
695 irreco_data
, parent_window
);
696 self
->irreco_data
= irreco_data
;
697 self
->theme
= irreco_theme
;
699 IRRECO_PRINTF("Button: %s\n", button
->name
->str
);
700 if (g_utf8_strlen(button
->name
->str
, 1) >0) {
701 /* Sets the button details */
702 _set_button_details(self
, irreco_theme
, button
);
706 response
= gtk_dialog_run(GTK_DIALOG(self
));
708 case GTK_RESPONSE_OK
:
710 _set_new_button_details(self
, button
);
712 irreco_theme_button_print(button
);
717 case GTK_RESPONSE_CANCEL
:
718 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
724 IRRECO_DEBUG("default\n");
730 gtk_widget_destroy(GTK_WIDGET(self
));
731 IRRECO_RETURN_BOOL(rvalue
);
736 _set_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoTheme
*irreco_theme
,
737 IrrecoThemeButton
*button
)
741 /* Set button information on table */
742 gtk_combo_box_prepend_text(GTK_COMBO_BOX(self
->combobox_name
),
744 gtk_combo_box_set_active(GTK_COMBO_BOX(self
->combobox_name
),
746 _draw_preview_image(GTK_BUTTON(self
->add_button_unpressed
),
748 button
->image_up
->str
);
749 _draw_preview_image(GTK_BUTTON(self
->add_button_pressed
),
751 button
->image_down
->str
);
752 if (button
->allow_text
) {
753 gtk_button_clicked(GTK_BUTTON(self
->allow_text
));
756 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
),
757 button
->text_padding
);
759 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
),
760 button
->text_h_align
);
761 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
),
762 button
->text_v_align
);
764 if (strlen(button
->text_format_up
->str
) > 0) {
766 _set_font_format(self
, button
->text_format_up
->str
,
767 gtk_label_get_text(GTK_LABEL(
768 self
->label_sample_text_format_up
)));
770 if (strlen(button
->text_format_down
->str
) > 0) {
772 _set_font_format(self
, button
->text_format_down
->str
,
773 gtk_label_get_text(GTK_LABEL(
774 self
->label_sample_text_format_down
)));
776 /* Set button label & windown title */
777 gtk_button_set_label(GTK_BUTTON(self
->add_button
), "Save");
778 gtk_window_set_title(GTK_WINDOW(self
), _("Edit Button"));
785 _set_new_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoThemeButton
*button
)
789 gchar
*style_name
= NULL
;
790 gboolean allow_text
= FALSE
;
791 gint text_padding
= 0;
792 gfloat text_h_align
= 0;
793 gfloat text_v_align
= 0;
796 style_name
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(
797 self
->combobox_name
));
798 allow_text
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
800 text_padding
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
801 self
->text_padding
));
802 text_h_align
= gtk_spin_button_get_value(GTK_SPIN_BUTTON(
803 self
->text_h_align
));
804 text_v_align
= gtk_spin_button_get_value(GTK_SPIN_BUTTON(
805 self
->text_v_align
));
807 irreco_theme_button_set(button
,
811 self
->unpressed_path
->str
,
812 self
->pressed_path
->str
,
813 self
->unpressed_format
,
814 self
->pressed_format
,
823 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
824 /* Events and Callbacks */
825 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
828 * @name Events and Callbacks
833 _signal_image_clicked(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
836 _select_image(button
, self
);
840 static void _unpressed_event_signal_image_clicked(GtkWidget
*widget
,
841 GdkEventButton
*event
,
842 IrrecoButtonCreatorDlg
*self
)
846 gtk_button_clicked(GTK_BUTTON(self
->add_button_unpressed
));
851 static void _pressed_event_signal_image_clicked(GtkWidget
*widget
,
852 GdkEventButton
*event
,
853 IrrecoButtonCreatorDlg
*self
)
857 gtk_button_clicked(GTK_BUTTON(self
->add_button_pressed
));
862 static void _toggle_button_toggled(GtkToggleButton
*togglebutton
,
863 IrrecoButtonCreatorDlg
*self
)
867 if (gtk_toggle_button_get_active(togglebutton
)) {
868 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "YES");
869 gtk_widget_set_sensitive(self
->text_format_up
, TRUE
);
870 gtk_widget_set_sensitive(self
->text_format_down
, TRUE
);
872 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
873 gtk_widget_set_sensitive(self
->text_format_up
, FALSE
);
874 gtk_widget_set_sensitive(self
->text_format_down
, FALSE
);
880 *Select button font format
883 static void _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
887 GString
*format
= g_string_new(NULL
);
888 const gchar
*span
= ">%s</span>";
892 dialog
= gtk_font_selection_dialog_new("Button font");
894 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
) {
896 font
= gtk_font_selection_dialog_get_font_name(
897 GTK_FONT_SELECTION_DIALOG(dialog
));
899 /*g_string_printf(format,
900 "<span foreground=\"%s\" font_desc=\"%s\" %s",
901 "red", font, span);*/
902 g_string_printf(format
,
903 "<span font_desc=\"%s\" %s", font
, span
);
906 if (strcmp("unpressed", gtk_widget_get_name(
907 GTK_WIDGET(button
))) == 0) {
908 self
->unpressed_format
= format
->str
;
909 _set_font_format(self
, format
->str
,
910 gtk_label_get_text(GTK_LABEL(
911 self
->label_sample_text_format_up
)));
913 self
->pressed_format
= format
->str
;
914 _set_font_format(self
, format
->str
,
915 gtk_label_get_text(GTK_LABEL(
916 self
->label_sample_text_format_down
)));
919 gtk_widget_destroy(GTK_WIDGET(dialog
));
925 * Set button text format
928 _set_font_format(IrrecoButtonCreatorDlg
*self
, const gchar
*button_format
,
934 GString
*format
= g_string_new(NULL
);
938 g_string_printf(format
, "%s", button_format
);
940 markup
= g_markup_printf_escaped(format
->str
, text
);
942 IRRECO_PRINTF("TEXT: %s\n", markup
);
944 if (strcmp(text
, gtk_label_get_text(GTK_LABEL(
945 self
->label_sample_text_format_up
))) == 0) {
946 gtk_label_set_markup(GTK_LABEL(self
->label_sample_text_format_up
),
950 gtk_label_set_markup(GTK_LABEL(self
->label_sample_text_format_down
),
954 if(markup
!= NULL
) g_free(markup
);
955 g_string_free(format
, TRUE
);