2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
4 * 2008 Joni Kokko (t5kojo01@students.oamk.fi)
5 * 2008 Harri Vattulainen (t5vaha01@students.oamk.fi)
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "irreco_theme_upload_dlg.h"
24 #include <hildon/hildon-color-button.h>
25 #include <hildon/hildon-file-chooser-dialog.h>
30 * @addtogroup IrrecoThemeUploadDlg
33 * Allow user to set theme settings and upload it.
40 * Source file of @ref IrrecoThemeUploadDlg.
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
47 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
49 #define IRRECO_THEME_UPLOAD_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH / 6)
50 #define IRRECO_THEME_UPLOAD_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT / 6)
54 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
56 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
57 static gboolean
_check_texts(IrrecoThemeUploadDlg
*self
);
61 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
62 /* Construction & Destruction */
63 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
66 * @name Construction & Destruction
70 G_DEFINE_TYPE(IrrecoThemeUploadDlg
, irreco_theme_upload_dlg
,
71 IRRECO_TYPE_INTERNAL_DLG
)
73 static void irreco_theme_upload_dlg_constructed(GObject
*object
)
75 IrrecoThemeUploadDlg
*self
;
82 G_OBJECT_CLASS(irreco_theme_upload_dlg_parent_class
)->constructed(object
);
83 self
= IRRECO_THEME_UPLOAD_DLG(object
);
85 /* Construct dialog. */
86 gtk_window_set_title(GTK_WINDOW(self
), _("Upload theme"));
87 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
88 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
89 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
90 gtk_dialog_add_buttons(GTK_DIALOG(self
),
91 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
92 GTK_STOCK_OK
, GTK_RESPONSE_OK
,
98 hbox_lr
= gtk_hbox_new(FALSE
, 0);
101 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
),
104 /* Radio button signals. */
105 /* TODO Connect preview view to somewhere */
106 /*g_signal_connect(G_OBJECT(self->radio_default), "toggled",
107 G_CALLBACK(_signal_type_toggled),
109 g_object_set_data(G_OBJECT(self->radio_default),
110 "IrrecoButtonLayoutBgType",
111 (gpointer) IRRECO_THEME_UPLOAD_DEFAULT);
112 g_signal_connect(G_OBJECT(self->radio_color), "toggled",
113 G_CALLBACK(_signal_type_toggled),
115 g_object_set_data(G_OBJECT(self->radio_color),
116 "IrrecoButtonLayoutBgType",
117 (gpointer) IRRECO_THEME_UPLOAD_COLOR);
118 g_signal_connect(G_OBJECT(self->radio_image), "toggled",
119 G_CALLBACK(_signal_type_toggled),
121 g_object_set_data(G_OBJECT(self->radio_image),
122 "IrrecoButtonLayoutBgType",
123 (gpointer) IRRECO_THEME_UPLOAD_IMAGE);*/
125 /* Button signals. */
126 /*g_signal_connect(G_OBJECT(button_image), "clicked",
127 G_CALLBACK(_signal_image_clicked),
129 g_signal_connect(G_OBJECT(self->color_button), "clicked",
130 G_CALLBACK(_signal_color_clicked),
132 g_signal_connect(G_OBJECT(preview_event_box), "button-release-event",
133 G_CALLBACK(_signal_preview_clicked),
136 /* Signal handler for theme_bg_browser*/
137 /*g_signal_connect(G_OBJECT(IRRECO_LISTBOX(
138 self->theme_bg_browser->images)->tree_selection),
140 G_CALLBACK(_signal_theme_image_selection_changed),
143 gtk_widget_show_all(GTK_WIDGET(self
));
147 static void irreco_theme_upload_dlg_init(IrrecoThemeUploadDlg
*self
)
150 self
->theme_name
= g_string_new(NULL
);
151 self
->author
= g_string_new(NULL
);
152 self
->comments
= g_string_new(NULL
);
156 static void irreco_theme_upload_dlg_finalize(GObject
*object
)
158 IrrecoThemeUploadDlg
*self
;
161 self
= IRRECO_THEME_UPLOAD_DLG(object
);
162 g_string_free(self
->theme_name
, TRUE
);
163 self
->theme_name
= NULL
;
164 g_string_free(self
->author
, TRUE
);
166 g_string_free(self
->comments
, TRUE
);
167 self
->comments
= NULL
;
169 G_OBJECT_CLASS(irreco_theme_upload_dlg_parent_class
)->finalize(object
);
173 static void irreco_theme_upload_dlg_class_init(IrrecoThemeUploadDlgClass
*klass
)
175 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
176 /* IrrecoDlgClass* parent_class = IRRECO_DLG_CLASS (klass); */
178 object_class
->finalize
= irreco_theme_upload_dlg_finalize
;
179 object_class
->constructed
= irreco_theme_upload_dlg_constructed
;
182 GtkWidget
*irreco_theme_upload_dlg_new(IrrecoData
*irreco_data
,
183 GtkWindow
*parent_window
)
185 IrrecoThemeUploadDlg
*self
;
188 self
= g_object_new(IRRECO_TYPE_THEME_UPLOAD_DLG
,
189 "irreco-data", irreco_data
,
191 irreco_dlg_set_parent(IRRECO_DLG(self
), parent_window
);
192 IRRECO_RETURN_PTR(self
);
197 * @todo Replace calls to irreco_theme_upload_dlg_create() with
198 * irreco_theme_upload_dlg_new().
200 IrrecoThemeUploadDlg
*irreco_theme_upload_dlg_create(IrrecoData
*irreco_data
,
201 GtkWindow
*parent_window
)
204 IRRECO_RETURN_PTR(irreco_theme_upload_dlg_new(
205 irreco_data
, parent_window
));
210 * @todo Replace calls to irreco_theme_upload_dlg_destroy() with
211 * gtk_widget_destroy().
213 void irreco_theme_upload_dlg_destroy(IrrecoThemeUploadDlg
* self
)
216 gtk_widget_destroy(GTK_WIDGET(self
));
224 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
225 /* Private Functions */
226 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
228 * @name Private Functions
231 static gboolean
_check_texts(IrrecoThemeUploadDlg
*self
)
234 /* TODO Check self->theme_name etc to be correct and whine if are not */
235 IRRECO_RETURN_BOOL(TRUE
);
241 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
242 /* Public Functions */
243 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
246 * Show dialog, and ask user for input.
248 /* TODO pass themename/theme instead of irreco_layout */
249 gboolean
irreco_theme_upload_dlg_run(IrrecoThemeUploadDlg
*self
,
250 IrrecoButtonLayout
*irreco_layout
)
255 self
->type
= irreco_button_layout_get_bg_type(irreco_layout
);
256 irreco_gstring_set(self
->filename
,
257 irreco_button_layout_get_bg_image(irreco_layout
));
258 hildon_color_button_set_color(
259 HILDON_COLOR_BUTTON(self
->color_button
),
260 irreco_button_layout_get_bg_color(irreco_layout
));
267 if (gtk_dialog_run(GTK_DIALOG(self
)) == GTK_RESPONSE_OK
) {
268 /* TODO Check text lengths at priv func */
269 if(!_check_texts(self
)) {
270 goto run_dialog_again
;
273 /* TODO Show login/reg dialog */
274 /* TODO If logged, theme_setpreview(theme, preview) */
275 /* TODO rip theme into pieces and toss 'em into func that shoves bits into soup */
276 /* +author, comments, loginname and passwdsha */
279 g_object_get(G_OBJECT(self->color_button),
280 "color", &color, NULL);
281 irreco_button_layout_set_bg_type(irreco_layout,
283 irreco_button_layout_set_bg_color(irreco_layout, color);
284 irreco_button_layout_set_bg_image(
285 irreco_layout, self->filename->str);
287 IRRECO_PRINTF("%i\n",
288 irreco_button_layout_get_bg_type(irreco_layout));
290 IRRECO_RETURN_BOOL(TRUE); */
292 IRRECO_RETURN_BOOL(FALSE
);
299 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
300 /* Events and Callbacks */
301 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
304 * @name Events and Callbacks
307 /* TODO Event for selecting preview image */