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 "/media/mmc2/irreco/.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 IrrecoButtonCreatorDlg
*self
;
112 GtkWidget
*scrolled_table
;
114 GtkWidget
*frame_unpressed
;
115 GtkWidget
*frame_pressed
;
116 GtkWidget
*label_name
;
117 GtkWidget
*label_select_unpressed
;
118 GtkWidget
*label_select_pressed
;
119 GtkWidget
*event_box_unpressed
;
120 GtkWidget
*vbox_unpressed_preview
;
121 GtkWidget
*vbox_pressed_preview
;
122 GtkWidget
*label_size
;
125 GtkWidget
*table_settings
;
126 GtkWidget
*label_allow_text
;
127 GtkWidget
*scrolled_table_settings
;
128 GtkWidget
*label_text_padding
;
129 GtkWidget
*label_text_h_align
;
130 GtkWidget
*label_text_v_align
;
131 GtkWidget
*label_text_format_up
;
132 GtkWidget
*label_text_format_down
;
135 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->constructed(object
);
137 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
138 /* Construct dialog. */
139 gtk_window_set_title(GTK_WINDOW(self
), _("Create a Button"));
140 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
141 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
142 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
145 self
->cancel_button
= gtk_dialog_add_button(GTK_DIALOG(self
),
147 GTK_RESPONSE_CANCEL
);
148 self
->add_button
= gtk_dialog_add_button(GTK_DIALOG(self
), _("Add"),
150 gtk_widget_set_sensitive(self
->add_button
, FALSE
);
153 /* Create widgets. */
154 self
->notebook
= gtk_notebook_new();
156 /* Create widgets. */
157 scrolled_table
= gtk_scrolled_window_new(NULL
, NULL
);
158 table
= gtk_table_new(7, 9, TRUE
);
159 label_name
= gtk_label_new(_("Name:"));
160 label_select_unpressed
= gtk_label_new(_("Unpressed:"));
161 label_select_pressed
= gtk_label_new(_("Pressed:"));
162 self
->event_box_pressed
= gtk_event_box_new();
163 event_box_unpressed
= gtk_event_box_new();
164 self
->combobox_name
= gtk_combo_box_entry_new_text();
165 frame_unpressed
= gtk_frame_new("");
166 frame_pressed
= gtk_frame_new("");
167 vbox_unpressed_preview
= gtk_vbox_new(FALSE
, 8);
168 vbox_pressed_preview
= gtk_vbox_new(FALSE
, 8);
169 self
->label_unpressed_size
= gtk_label_new("");
170 self
->label_pressed_size
= gtk_label_new("");
171 self
->preview_image_unpressed
= gtk_image_new();
172 self
->preview_image_pressed
= gtk_image_new();
173 self
->add_button_unpressed
= gtk_button_new_with_label(_("Select"));
174 self
->add_button_pressed
= gtk_button_new_with_label(_("Select"));
176 /* Create settings widgets*/
177 scrolled_table_settings
= gtk_scrolled_window_new(NULL
, NULL
);
178 table_settings
= gtk_table_new(7, 9, TRUE
);
179 label_allow_text
= gtk_label_new(_("AllowText:"));
180 label_text_format_up
= gtk_label_new(_("TextFormatUp:"));
181 label_text_format_down
= gtk_label_new(_("TextFormatDown:"));
182 self
->label_sample_text_format_up
= gtk_label_new(_("Sample1"));
183 self
->label_sample_text_format_down
= gtk_label_new(_("Sample2"));
184 label_text_padding
= gtk_label_new(_("TextPadding:"));
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(label_text_format_up
), 0, 0.5);
222 gtk_misc_set_alignment(GTK_MISC(label_text_format_down
), 0, 0.5);
223 gtk_misc_set_alignment(GTK_MISC(self
->label_sample_text_format_up
), 0, 0.5);
224 gtk_misc_set_alignment(GTK_MISC(self
->label_sample_text_format_down
), 0, 0.5);
225 gtk_misc_set_alignment(GTK_MISC(label_text_padding
), 0, 0.5);
226 gtk_misc_set_alignment(GTK_MISC(label_text_h_align
), 0, 0.5);
227 gtk_misc_set_alignment(GTK_MISC(label_text_v_align
), 0, 0.5);
228 gtk_misc_set_alignment(GTK_MISC(label_size
), 0, 0.5);
230 /* Set table on the scrolled */
231 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
235 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_table
),
237 GTK_POLICY_AUTOMATIC
);
239 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(
240 scrolled_table_settings
),
241 GTK_WIDGET(table_settings
));
243 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(
244 scrolled_table_settings
),
246 GTK_POLICY_AUTOMATIC
);
248 /* Create Notebook tabs. */
250 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
251 irreco_gtk_align(GTK_WIDGET(scrolled_table
),
252 0, 0, 1, 1, 8, 8, 8, 8),
253 gtk_label_new("Button"));
254 gtk_notebook_append_page(GTK_NOTEBOOK(self
->notebook
),
255 irreco_gtk_align(GTK_WIDGET(
256 scrolled_table_settings
),
257 0, 0, 1, 1, 8, 8, 8, 8),
258 gtk_label_new("Settings"));
260 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
),
263 /* Set widgets on the table */
265 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
266 gtk_table_set_col_spacings(GTK_TABLE(table
), 6);
268 gtk_table_attach_defaults(GTK_TABLE(table
), label_name
, 0, 3, 0, 1);
269 gtk_table_attach_defaults(GTK_TABLE(table
),
270 label_select_unpressed
, 0, 3, 1, 2);
271 gtk_table_attach_defaults(GTK_TABLE(table
),
272 label_select_pressed
, 0, 3, 2, 3);
273 gtk_table_attach_defaults(GTK_TABLE(table
),
274 self
->combobox_name
, 3, 9, 0, 1);
275 gtk_table_attach_defaults(GTK_TABLE(table
),
276 self
->add_button_unpressed
, 3, 9, 1, 2);
277 gtk_table_attach_defaults(GTK_TABLE(table
),
278 self
->add_button_pressed
, 3, 9, 2, 3);
279 gtk_table_attach_defaults(GTK_TABLE(table
),
280 frame_unpressed
, 0, 4, 3, 7);
281 gtk_table_attach_defaults(GTK_TABLE(table
), frame_pressed
, 5, 9, 3, 7);
282 /* Set widgets on the table_settings */
283 gtk_table_set_row_spacings(GTK_TABLE(table_settings
), 6);
284 gtk_table_set_col_spacings(GTK_TABLE(table_settings
), 6);
286 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
287 label_allow_text
, 0, 4, 0, 1);
288 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
289 label_text_format_up
, 0, 4, 1, 2);
290 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
291 label_text_format_down
, 0, 4, 2, 3);
292 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
293 self
->label_sample_text_format_up
, 4, 7, 1, 2);
294 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
295 self
->label_sample_text_format_down
, 4, 7, 2, 3);
296 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
297 label_text_padding
, 0, 4, 3, 4);
298 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
299 label_text_h_align
, 0, 4, 4, 5);
300 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
301 label_text_v_align
, 0, 4, 5, 6);
302 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
303 label_size
, 0, 4, 6, 7);
305 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
306 self
->allow_text
, 4, 9, 0, 1);
307 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
308 self
->text_format_up
, 7, 9, 1, 2);
309 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
310 self
->text_format_down
, 7, 9, 2, 3);
311 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
312 self
->text_padding
, 4, 9, 3, 4);
313 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
314 self
->text_h_align
, 4, 9, 4, 5);
315 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
316 self
->text_v_align
, 4, 9, 5, 6);
317 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
318 self
->unbutton_size
, 4, 6, 6, 7);
319 gtk_table_attach_defaults(GTK_TABLE(table_settings
),
320 self
->button_size
, 7, 9, 6, 7);
321 /* set preview image*/
323 gtk_container_add(GTK_CONTAINER(frame_unpressed
), event_box_unpressed
);
324 gtk_container_add(GTK_CONTAINER(event_box_unpressed
),
325 vbox_unpressed_preview
);
326 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
327 self
->preview_image_unpressed
);
328 gtk_container_add(GTK_CONTAINER(vbox_unpressed_preview
),
329 self
->label_unpressed_size
);
331 gtk_container_add(GTK_CONTAINER(frame_pressed
), self
->event_box_pressed
);
332 gtk_container_add(GTK_CONTAINER(self
->event_box_pressed
),
333 vbox_pressed_preview
);
334 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
335 self
->preview_image_pressed
);
336 gtk_container_add(GTK_CONTAINER(vbox_pressed_preview
),
337 self
->label_pressed_size
);
342 /*Added button list on combobox*/
343 fill_buttons_combobox(self
);
345 /* set default settings on tab */
346 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
348 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
), 5);
349 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
), 0.5);
350 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
), 0.5);
351 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->unbutton_size
), 10);
352 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->button_size
), 10);
354 /* Set button name */
355 gtk_widget_set_name(self
->text_format_up
, "unpressed");
356 gtk_widget_set_name(self
->text_format_down
, "pressed");
357 /* Button signals. */
358 g_signal_connect(G_OBJECT(self
->add_button_unpressed
), "clicked",
359 G_CALLBACK(_signal_image_clicked
), self
);
360 g_signal_connect(G_OBJECT(self
->add_button_pressed
), "clicked",
361 G_CALLBACK(_signal_image_clicked
), self
);
363 g_signal_connect(G_OBJECT(event_box_unpressed
), "button-release-event",
364 G_CALLBACK(_unpressed_event_signal_image_clicked
),
366 g_signal_connect(G_OBJECT(self
->event_box_pressed
),
367 "button-release-event",
368 G_CALLBACK(_pressed_event_signal_image_clicked
),
371 g_signal_connect(G_OBJECT(self
->allow_text
), "toggled",
372 G_CALLBACK(_toggle_button_toggled
), self
);
374 g_signal_connect(G_OBJECT(self
->text_format_up
), "clicked",
375 G_CALLBACK(_select_font_format
), self
);
376 g_signal_connect(G_OBJECT(self
->text_format_down
), "clicked",
377 G_CALLBACK(_select_font_format
), self
);
378 g_signal_connect(G_OBJECT(self
->unbutton_size
), "value-changed",
379 G_CALLBACK(_unbutton_size_changed
), self
);
380 g_signal_connect(G_OBJECT(self
->button_size
), "value-changed",
381 G_CALLBACK(_button_size_changed
), self
);
383 gtk_widget_set_size_request(GTK_WIDGET(self
), 696, 396);
384 gtk_widget_show_all(GTK_WIDGET(self
));
386 /* Hide Button size widgets */
387 gtk_widget_hide(label_size
);
388 gtk_widget_hide(self
->unbutton_size
);
389 gtk_widget_hide(self
->button_size
);
395 irreco_button_creator_dlg_init (IrrecoButtonCreatorDlg
*object
)
402 irreco_button_creator_dlg_finalize (GObject
*object
)
404 /* TODO: Add deinitalization code here */
406 IrrecoButtonCreatorDlg
*self
;
409 self
= IRRECO_BUTTON_CREATOR_DLG(object
);
411 G_OBJECT_CLASS(irreco_button_creator_dlg_parent_class
)->finalize(object
);
417 irreco_button_creator_dlg_class_init (IrrecoButtonCreatorDlgClass
*klass
)
419 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
421 object_class
->finalize
= irreco_button_creator_dlg_finalize
;
422 object_class
->constructed
= irreco_button_creator_dlg_constructed
;
426 *irreco_button_creator_dlg_new(IrrecoData
*irreco_data
, GtkWindow
*parent
)
428 IrrecoButtonCreatorDlg
*self
;
432 self
= g_object_new(IRRECO_TYPE_BUTTON_CREATOR_DLG
,
433 "irreco-data", irreco_data
, NULL
);
434 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
436 IRRECO_RETURN_PTR(self
);
441 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
442 /* Private Functions */
443 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
445 * @name Private Functions
450 *Fill combobox from file
452 static void fill_buttons_combobox(IrrecoButtonCreatorDlg
*self
)
455 GKeyFile
*button_list
;
459 GError
*error
= NULL
;
462 button_list
= g_key_file_new();
463 g_key_file_load_from_file(button_list
, BUTTON_LIST_DIR
,
464 G_KEY_FILE_NONE
, &error
);
465 keys
= g_key_file_get_keys(button_list
, "button-names", &length
,
467 for(i
=0; i
<length
; i
++){
468 gtk_combo_box_append_text(GTK_COMBO_BOX(self
->combobox_name
),
469 g_key_file_get_string(button_list
,
470 "button-names", keys
[i
], &error
));
473 g_key_file_free(button_list
);
474 if(keys
!= NULL
) g_free(keys
);
480 _unbutton_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
)
482 GString
*image_path
= g_string_new(self
->unpressed_path
->str
);
486 IRRECO_PRINTF("PATH: %s\n", self
->unpressed_path
->str
);
488 _draw_preview_image(GTK_BUTTON(self
->text_format_up
), self
,
491 g_string_free(image_path
, TRUE
);
495 _button_size_changed(GtkSpinButton
*spinbutton
, IrrecoButtonCreatorDlg
*self
)
497 GString
*image_path
= g_string_new(self
->unpressed_path
->str
);
501 IRRECO_PRINTF("PATH: %s\n", self
->unpressed_path
->str
);
503 _draw_preview_image(GTK_BUTTON(self
->text_format_down
), self
,
506 g_string_free(image_path
, TRUE
);
511 * Draw preview with current image.
514 _draw_preview_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
,
517 GError
*error
= NULL
;
518 GdkPixbuf
*pixbuf
= NULL
;
519 GString
*size
= g_string_new(NULL
);
523 g_assert(self
!= NULL
);
524 /* compared with whichever image */
525 if (g_str_equal("pressed", gtk_widget_get_name(GTK_WIDGET(button
)))) {
526 gint button_width
= 0;
527 gint button_height
= 0;
528 GdkPixbuf
*pixbuf_size
= NULL
;
531 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
532 IRRECO_BUTTON_PREVIEW_WIDHT
,
533 IRRECO_BUTTON_PREVIEW_HEIGHT
,
535 /* set sensitive if image are selected */
536 gtk_widget_set_sensitive(self
->add_button
, TRUE
);
538 if (irreco_gerror_check_print(&error
)) {
539 IRRECO_RETURN_BOOL(FALSE
);
543 g_string_printf(self
->pressed_path
, "%s", image
);
544 gtk_widget_realize(GTK_WIDGET(self
->preview_image_pressed
));
545 gtk_image_set_from_pixbuf(GTK_IMAGE(self
->preview_image_pressed
),
548 /* Show image real size */
549 pixbuf_size
= gdk_pixbuf_new_from_file(image
, &error
);
550 button_width
= atoi(g_strdup_printf("%.0f",
551 (gdk_pixbuf_get_width(
553 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
554 self
->button_size
)))));
555 button_height
= atoi(g_strdup_printf("%.0f",
556 (gdk_pixbuf_get_height(
558 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
559 self
->button_size
))))));
561 if (pixbuf_size
!= NULL
) g_object_unref(G_OBJECT(pixbuf_size
));
563 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", button_width
),
564 g_strdup_printf("%d", button_height
));
566 gtk_label_set_text(GTK_LABEL(self
->label_pressed_size
),
570 gint button_width
= 0;
571 gint button_height
= 0;
572 GdkPixbuf
*pixbuf_size
= NULL
;
575 pixbuf
= gdk_pixbuf_new_from_file_at_scale(image
,
576 IRRECO_BUTTON_PREVIEW_WIDHT
,
577 IRRECO_BUTTON_PREVIEW_HEIGHT
,
579 if (irreco_gerror_check_print(&error
)) {
580 IRRECO_RETURN_BOOL(FALSE
);
583 gtk_widget_realize(GTK_WIDGET(self
->preview_image_unpressed
));
584 gtk_image_set_from_pixbuf(GTK_IMAGE(
585 self
->preview_image_unpressed
),
588 /* Show image real size */
589 pixbuf_size
= gdk_pixbuf_new_from_file(image
, &error
);
590 button_width
= atoi(g_strdup_printf("%.0f",
591 (gdk_pixbuf_get_width(
593 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
594 self
->unbutton_size
)))));
595 button_height
= atoi(g_strdup_printf("%.0f",
596 (gdk_pixbuf_get_height(
598 (6-gtk_spin_button_get_value(GTK_SPIN_BUTTON(
599 self
->unbutton_size
))))));
600 if (pixbuf_size
!= NULL
) g_object_unref(G_OBJECT(pixbuf_size
));
602 g_string_printf(size
, "%sx%s", g_strdup_printf("%d", button_width
),
603 g_strdup_printf("%d", button_height
));
605 gtk_label_set_text(GTK_LABEL(self
->label_unpressed_size
),
607 g_string_printf(self
->unpressed_path
, "%s", image
);
609 /* Set button sensitive */
610 gtk_widget_set_sensitive(self
->add_button_pressed
, TRUE
);
611 gtk_widget_set_sensitive(self
->event_box_pressed
, TRUE
);
614 g_string_free(size
, TRUE
);
615 if (pixbuf
!= NULL
) g_object_unref(G_OBJECT(pixbuf
));
616 IRRECO_RETURN_BOOL(TRUE
);
619 static void _select_image(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
622 GtkWidget
*file_dlg
= NULL
;
623 gchar
*image_dir
= NULL
;
626 /* Create image select dialog. */
628 file_dlg
= hildon_file_chooser_dialog_new(GTK_WINDOW(self
),
629 GTK_FILE_CHOOSER_ACTION_OPEN
);
630 gtk_window_set_title(GTK_WINDOW(file_dlg
),_("Select button image"));
631 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(file_dlg
), TRUE
);
632 image_dir
= g_build_path("/", getenv("HOME"), "MyDocs/.images/", NULL
);
633 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(file_dlg
),
637 /* Loop until user cancels or we get a valid image. */
638 gtk_widget_show_all(GTK_WIDGET(file_dlg
));
639 while (gtk_dialog_run(GTK_DIALOG(file_dlg
)) == GTK_RESPONSE_OK
) {
641 filename
= gtk_file_chooser_get_filename(
642 GTK_FILE_CHOOSER(file_dlg
));
644 /* Attempt to display the image. */
645 if (_draw_preview_image(button
, self
, filename
)) {
646 irreco_gstring_set_and_free(self
->filename
, filename
);
652 gchar
*basename
= g_path_get_basename(filename
);
653 irreco_error_dlg_printf(GTK_WINDOW(file_dlg
),
654 _("Cannot open image \"%s\""),
656 IRRECO_PRINTF("Image invalid.\n");
663 gtk_widget_destroy(file_dlg
);
669 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
671 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
673 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
674 /* Public Functions */
675 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
677 gboolean
irreco_button_creator_dlg_run(IrrecoData
*irreco_data
,
678 IrrecoTheme
* irreco_theme
,
679 GtkWindow
*parent_window
,
680 IrrecoThemeButton
*button
)
682 IrrecoButtonCreatorDlg
*self
;
684 gboolean loop
= TRUE
;
685 gboolean rvalue
= FALSE
;
688 self
= (IrrecoButtonCreatorDlg
*)irreco_button_creator_dlg_new(
689 irreco_data
, parent_window
);
690 self
->irreco_data
= irreco_data
;
691 self
->theme
= irreco_theme
;
693 IRRECO_DEBUG("Button: %s\n", button
->name
->str
);
694 if (g_utf8_strlen(button
->name
->str
, 1) >0) {
695 /* Sets the button details */
696 _set_button_details(self
, irreco_theme
, button
);
700 response
= gtk_dialog_run(GTK_DIALOG(self
));
702 case GTK_RESPONSE_OK
:
704 _set_new_button_details(self
, button
);
706 irreco_theme_button_print(button
);
711 case GTK_RESPONSE_CANCEL
:
712 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
718 IRRECO_DEBUG("default\n");
724 gtk_widget_destroy(GTK_WIDGET(self
));
725 IRRECO_RETURN_BOOL(rvalue
);
730 _set_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoTheme
*irreco_theme
,
731 IrrecoThemeButton
*button
)
735 /* Set button information on table */
736 gtk_combo_box_prepend_text(GTK_COMBO_BOX(self
->combobox_name
),
738 gtk_combo_box_set_active(GTK_COMBO_BOX(self
->combobox_name
),
740 _draw_preview_image(GTK_BUTTON(self
->add_button_unpressed
),
742 button
->image_up
->str
);
743 _draw_preview_image(GTK_BUTTON(self
->add_button_pressed
),
745 button
->image_down
->str
);
746 if (button
->allow_text
) {
747 gtk_button_clicked(GTK_BUTTON(self
->allow_text
));
750 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_padding
),
751 button
->text_padding
);
753 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_h_align
),
754 button
->text_h_align
);
755 gtk_spin_button_set_value(GTK_SPIN_BUTTON(self
->text_v_align
),
756 button
->text_v_align
);
758 if (strlen(button
->text_format_up
->str
) > 0) {
760 _set_font_format(self
, button
->text_format_up
->str
,
761 gtk_label_get_text(GTK_LABEL(
762 self
->label_sample_text_format_up
)));
764 if (strlen(button
->text_format_down
->str
) > 0) {
766 _set_font_format(self
, button
->text_format_down
->str
,
767 gtk_label_get_text(GTK_LABEL(
768 self
->label_sample_text_format_down
)));
770 /* Set button label & windown title */
771 gtk_button_set_label(GTK_BUTTON(self
->add_button
), "Save");
772 gtk_window_set_title(GTK_WINDOW(self
), _("Edit Button"));
779 _set_new_button_details(IrrecoButtonCreatorDlg
*self
, IrrecoThemeButton
*button
)
783 gchar
*style_name
= NULL
;
784 gboolean allow_text
= FALSE
;
785 gint text_padding
= 0;
786 gfloat text_h_align
= 0;
787 gfloat text_v_align
= 0;
790 style_name
= gtk_combo_box_get_active_text(GTK_COMBO_BOX(
791 self
->combobox_name
));
792 allow_text
= gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
794 text_padding
= gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(
795 self
->text_padding
));
796 text_h_align
= gtk_spin_button_get_value(GTK_SPIN_BUTTON(
797 self
->text_h_align
));
798 text_v_align
= gtk_spin_button_get_value(GTK_SPIN_BUTTON(
799 self
->text_v_align
));
801 irreco_theme_button_set(button
,
805 self
->unpressed_path
->str
,
806 self
->pressed_path
->str
,
807 self
->unpressed_format
,
808 self
->pressed_format
,
817 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
818 /* Events and Callbacks */
819 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
822 * @name Events and Callbacks
827 _signal_image_clicked(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
830 _select_image(button
, self
);
834 static void _unpressed_event_signal_image_clicked(GtkWidget
*widget
,
835 GdkEventButton
*event
,
836 IrrecoButtonCreatorDlg
*self
)
840 gtk_button_clicked(GTK_BUTTON(self
->add_button_unpressed
));
845 static void _pressed_event_signal_image_clicked(GtkWidget
*widget
,
846 GdkEventButton
*event
,
847 IrrecoButtonCreatorDlg
*self
)
851 gtk_button_clicked(GTK_BUTTON(self
->add_button_pressed
));
856 static void _toggle_button_toggled(GtkToggleButton
*togglebutton
,
857 IrrecoButtonCreatorDlg
*self
)
861 if (gtk_toggle_button_get_active(togglebutton
)) {
862 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "YES");
863 gtk_widget_set_sensitive(self
->text_format_up
, TRUE
);
864 gtk_widget_set_sensitive(self
->text_format_down
, TRUE
);
866 gtk_button_set_label(GTK_BUTTON(self
->allow_text
), "NO");
867 gtk_widget_set_sensitive(self
->text_format_up
, FALSE
);
868 gtk_widget_set_sensitive(self
->text_format_down
, FALSE
);
874 *Select button font format
877 static void _select_font_format(GtkButton
*button
, IrrecoButtonCreatorDlg
*self
)
881 GString
*format
= g_string_new(NULL
);
882 const gchar
*span
= ">%s</span>";
886 dialog
= gtk_font_selection_dialog_new("Button font");
888 if (gtk_dialog_run (GTK_DIALOG (dialog
)) == GTK_RESPONSE_OK
) {
890 font
= gtk_font_selection_dialog_get_font_name(
891 GTK_FONT_SELECTION_DIALOG(dialog
));
893 /*g_string_printf(format,
894 "<span foreground=\"%s\" font_desc=\"%s\" %s",
895 "red", font, span);*/
896 g_string_printf(format
,
897 "<span font_desc=\"%s\" %s", font
, span
);
900 if (strcmp("unpressed", gtk_widget_get_name(
901 GTK_WIDGET(button
))) == 0) {
902 self
->unpressed_format
= format
->str
;
903 _set_font_format(self
, format
->str
,
904 gtk_label_get_text(GTK_LABEL(
905 self
->label_sample_text_format_up
)));
907 self
->pressed_format
= format
->str
;
908 _set_font_format(self
, format
->str
,
909 gtk_label_get_text(GTK_LABEL(
910 self
->label_sample_text_format_down
)));
913 gtk_widget_destroy(GTK_WIDGET(dialog
));
919 * Set button text format
922 _set_font_format(IrrecoButtonCreatorDlg
*self
, const gchar
*button_format
,
928 GString
*format
= g_string_new(NULL
);
932 g_string_printf(format
, "%s", button_format
);
934 markup
= g_markup_printf_escaped(format
->str
, text
);
936 IRRECO_PRINTF("TEXT: %s\n", markup
);
938 if (strcmp(text
, gtk_label_get_text(GTK_LABEL(
939 self
->label_sample_text_format_up
))) == 0) {
940 gtk_label_set_markup(GTK_LABEL(self
->label_sample_text_format_up
),
944 gtk_label_set_markup(GTK_LABEL(self
->label_sample_text_format_down
),
948 if(markup
!= NULL
) g_free(markup
);
949 g_string_free(format
, TRUE
);