1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * irreco_theme_save_dlg.c
4 * Copyright (C) 2008 Pekka Gehör (pegu6@msn.com)
6 * irreco_theme_save_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_theme_save_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_theme_save_dlg.h"
21 #include "irreco_theme_creator_backgrounds.h"
22 #include "irreco_theme_creator_dlg.h"
23 #include "irreco_theme_button.h"
24 #include <hildon/hildon-banner.h>
25 #include <hildon/hildon-color-button.h>
26 #include <hildon/hildon-file-chooser-dialog.h>
28 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
30 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
31 gboolean
_save_theme_to_dir(IrrecoThemeSaveDlg
*self
);
32 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
33 /* Construction & Destruction */
34 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 * @name Construction & Destruction
42 G_DEFINE_TYPE (IrrecoThemeSaveDlg
, irreco_theme_save_dlg
,
43 IRRECO_TYPE_INTERNAL_DLG
)
46 static void irreco_theme_save_dlg_constructed(GObject
*object
)
48 IrrecoThemeSaveDlg
*self
;
54 irreco_theme_save_dlg_parent_class
)->constructed(object
);
56 self
= IRRECO_THEME_SAVE_DLG(object
);
58 /* Construct dialog. */
59 gtk_window_set_title(GTK_WINDOW(self
), _("Theme Save"));
60 gtk_window_set_modal(GTK_WINDOW(self
), TRUE
);
61 gtk_window_set_destroy_with_parent(GTK_WINDOW(self
), TRUE
);
62 gtk_dialog_set_has_separator(GTK_DIALOG(self
), FALSE
);
65 gtk_dialog_add_buttons(GTK_DIALOG(self
),
66 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
67 GTK_STOCK_SAVE
, GTK_RESPONSE_OK
,
71 label
= gtk_label_new("Select save location");
73 self
->radio1
= gtk_radio_button_new_with_label (NULL
, "MMC1");
74 self
->radio2
= gtk_radio_button_new_with_label_from_widget(
76 self
->radio1
), "MMC2");
77 self
->radio3
= gtk_radio_button_new_with_label_from_widget(
79 self
->radio2
), "DEVICE");
81 gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(self
)->vbox
), label
);
83 gtk_box_pack_start_defaults(GTK_BOX(
84 GTK_DIALOG(self
)->vbox
),
87 g_mkdir("/media/mmc1/irreco", 0777);
89 if(!irreco_is_dir("/media/mmc1/irreco")) {
90 gtk_widget_set_sensitive(self
->radio1
, FALSE
);
91 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(self
->radio2
),
96 if(irreco_is_dir("/media/mmc2")) {
98 gtk_box_pack_start_defaults(GTK_BOX(
99 GTK_DIALOG(self
)->vbox
),
106 gtk_widget_show_all(GTK_WIDGET(self
));
111 irreco_theme_save_dlg_init (IrrecoThemeSaveDlg
*object
)
118 irreco_theme_save_dlg_finalize (GObject
*object
)
120 /* TODO: Add deinitalization code here */
121 IrrecoThemeSaveDlg
*self
;
124 self
= IRRECO_THEME_SAVE_DLG(object
);
125 G_OBJECT_CLASS (irreco_theme_save_dlg_parent_class
)->finalize (object
);
130 irreco_theme_save_dlg_class_init (IrrecoThemeSaveDlgClass
*klass
)
132 GObjectClass
* object_class
= G_OBJECT_CLASS (klass
);
133 object_class
->finalize
= irreco_theme_save_dlg_finalize
;
134 object_class
->constructed
= irreco_theme_save_dlg_constructed
;
138 irreco_theme_save_dlg_new(IrrecoData
*irreco_data
, GtkWindow
*parent
)
140 IrrecoThemeSaveDlg
*self
;
144 self
= g_object_new(IRRECO_TYPE_THEME_SAVE_DLG
,
145 "irreco-data", irreco_data
, NULL
);
146 irreco_dlg_set_parent(IRRECO_DLG(self
), parent
);
148 IRRECO_RETURN_PTR(self
);
152 irreco_theme_save_dlg_create(IrrecoData
*irreco_data
, GtkWindow
*parent_window
)
155 IRRECO_RETURN_PTR(irreco_theme_save_dlg_new(
156 irreco_data
, parent_window
));
161 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
162 /* Private Functions */
163 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
165 * @name Private Functions
169 gboolean
_save_theme_to_dir(IrrecoThemeSaveDlg
*self
)
171 gboolean rvalue
= FALSE
;
173 gchar
*folder
= NULL
;
174 IrrecoThemeManager
*theme_manager
= self
->irreco_data
->theme_manager
;
175 IrrecoTheme
*same_theme
= NULL
;
176 gint delete_mode
= 0;
177 gchar
*same_theme_folder
= NULL
;
178 GString
*message
= g_string_new(NULL
);
180 gchar
*redy_theme_name
;
183 /* Create Theme Folder */
184 theme_path
= g_string_new("");
185 theme_name
= g_string_new(self
->theme
->name
->str
);
187 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self
->radio1
))) {
188 folder
= "/media/mmc1/irreco/";
189 } else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(self
->radio2
))) {
190 folder
= "/media/mmc2/irreco/";
192 folder
= IRRECO_THEME_DIR
;
195 /* Call IrrecoThemeSave */
196 if(!irreco_is_dir(folder
)) {
197 g_mkdir(folder
, 0777);
202 /* parse the theme name */
203 g_string_ascii_down(theme_name
);
204 redy_theme_name
= g_strdup(theme_name
->str
);
205 g_strdelimit(redy_theme_name
, " ", '_');
206 g_strdelimit(redy_theme_name
, ",-|> <.", 'a');
207 g_string_printf(theme_path
, "%s%s", folder
, redy_theme_name
);
209 IRRECO_STRING_TABLE_FOREACH_DATA(theme_manager
->themes
,
210 IrrecoTheme
*, theme
)
212 if (g_str_equal(self
->theme
->name
->str
,
214 if (g_str_equal(theme
->source
->str
, "deb")) {
215 g_string_printf(message
,
216 _("The \"%s\" theme already exists.\n"
217 "Can't overwrite \"Built In themes\"\n"
218 "Please remove it first from the\n"
219 "Application Manager or change the name of the theme"),
221 irreco_error_dlg(GTK_WINDOW(self
),
228 /*Check theme folder path*/
229 else if (g_str_equal(theme_path
->str
,
230 g_strconcat(theme
->path
->str
, "/", NULL
))){
231 if (g_str_equal(theme
->source
->str
, "deb")) {
232 g_string_printf(message
,
233 _("This theme replaces \"%s\" theme.\n"
234 "Can't overwrite \"Built In themes\"\n"
235 "Please remove it first from the\n"
236 "Application Manager or change the name of the theme"),
239 irreco_error_dlg(GTK_WINDOW(self
),
244 same_theme_folder
= g_strdup(theme
->name
->str
);
246 IRRECO_STRING_TABLE_FOREACH_END
248 if (delete_mode
== 1) {
249 g_string_printf(message
,
250 _("The \"%s\" theme already exists.\n"
251 "Do you want to edit this theme?"),
252 same_theme
->name
->str
);
253 } else if (delete_mode
== 2) {
254 g_string_printf(message
,
255 _("This theme replaces \"%s\" theme.\n"
256 "Do you want to continue?"),
258 } else if (delete_mode
== 3) {
259 g_string_printf(message
,
260 _("This theme replaces themes\n"
261 "\"%s\" and \"%s\"\n"
262 "Do you want to continue?"),
263 same_theme
->name
->str
,
266 /* Check whether a theme folder already exists */
267 if (delete_mode
!= 0) {
269 if (!irreco_yes_no_dlg(
270 GTK_WINDOW(self
), message
->str
)) {
274 /* Check and remove theme folder*/
275 if (delete_mode
== 1 || delete_mode
== 3) {
277 rm_cmd
= g_strconcat("rm -r ",
278 "/media/mmc1/irreco/",
279 redy_theme_name
, NULL
);
280 if (irreco_is_dir(g_strconcat(
281 "/media/mmc1/irreco/",
282 redy_theme_name
, NULL
))) {
285 rm_cmd
= g_strconcat("rm -r ",
286 "/media/mmc2/irreco/",
287 redy_theme_name
, NULL
);
288 if (irreco_is_dir(g_strconcat(
289 "/media/mmc2/irreco/",
290 redy_theme_name
, NULL
))) {
295 if (delete_mode
== 2 || delete_mode
== 3) {
296 irreco_theme_manager_remove_theme(
297 self
->irreco_data
->theme_manager
,
299 g_free(same_theme_folder
);
304 g_mkdir(theme_path
->str
, 0777);
307 irreco_theme_save(self
->theme
, theme_path
->str
);
312 g_string_free(theme_name
, TRUE
);
313 g_string_free(message
, TRUE
);
314 g_string_free(theme_path
, TRUE
);
316 IRRECO_RETURN_BOOL(rvalue
);
321 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
323 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
326 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
327 /* Public Functions */
328 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
331 irreco_theme_save_dlg_run(IrrecoData
*irreco_data
, IrrecoTheme
*irreco_theme
,
332 GtkWindow
*parent_window
)
334 IrrecoThemeSaveDlg
*self
;
336 gboolean loop
= TRUE
;
337 gboolean rvalue
= FALSE
;
341 self
= (IrrecoThemeSaveDlg
*)irreco_theme_save_dlg_create(
342 irreco_data
, parent_window
);
343 self
->irreco_data
= irreco_data
;
344 self
->theme
= irreco_theme
;
347 response
= gtk_dialog_run(GTK_DIALOG(self
));
349 case GTK_RESPONSE_OK
:
351 if (_save_theme_to_dir(self
)) {
359 case GTK_RESPONSE_CANCEL
:
360 IRRECO_DEBUG("GTK_RESPONSE_CANCEL\n");
366 IRRECO_DEBUG("default\n");
372 gtk_widget_destroy(GTK_WIDGET(self
));
374 IRRECO_RETURN_BOOL(rvalue
);