2 * irreco - Ir Remote Control
3 * Copyright (C) 2008 Joni Kokko (t5kojo01@students.oamk.fi)
4 * Pekka Gehör (pegu6@msn.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "irreco_theme_bg.h"
24 * @addtogroup IrrecoThemeBg
27 * Contains information of background.
34 * Source file of @ref IrrecoThemeBg.
37 #define IRRECO_BACKGROUNDS_PREVIEW_WIDHT (IRRECO_SCREEN_WIDTH)
38 #define IRRECO_BACKGROUNDS_PREVIEW_HEIGHT (IRRECO_SCREEN_HEIGHT)
39 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
43 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
44 /* Construction & Destruction */
45 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
48 * @name Construction & Destruction
52 IrrecoThemeBg
*irreco_theme_bg_new()
57 self
= g_slice_new0(IrrecoThemeBg
);
59 self
->image_name
= g_string_new("");
60 self
->image_path
= g_string_new("");
62 IRRECO_RETURN_PTR(self
);
65 void irreco_theme_bg_free(IrrecoThemeBg
*self
)
69 g_assert(self
!= NULL
);
71 g_string_free(self
->image_name
, TRUE
);
72 self
->image_name
= NULL
;
74 g_string_free(self
->image_path
, TRUE
);
75 self
->image_path
= NULL
;
77 g_slice_free(IrrecoThemeBg
, self
);
85 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
86 /* Private Functions */
87 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
89 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
90 /* Public Functions */
91 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
94 * @name Public Functions
98 void irreco_theme_bg_set(IrrecoThemeBg
*self
,
99 const char *image_name
,
100 const char *image_path
)
104 g_string_printf(self
->image_name
, "%s", image_name
);
105 g_string_printf(self
->image_path
, "%s", image_path
);
110 void irreco_theme_bg_print(IrrecoThemeBg
*self
)
114 IRRECO_DEBUG("--------------------------------------------\n");
115 IRRECO_DEBUG("Background-image: %s\n", self
->image_name
->str
);
116 IRRECO_DEBUG("Background-image_path: %s\n", self
->image_path
->str
);
117 IRRECO_DEBUG("--------------------------------------------\n");
122 IrrecoThemeBg
*irreco_theme_bg_copy(IrrecoThemeBg
*self
)
124 IrrecoThemeBg
*new = NULL
;
127 new = irreco_theme_bg_new();
128 irreco_theme_bg_set(new, self
->image_name
->str
, self
->image_path
->str
);
129 IRRECO_RETURN_PTR(new);
133 * IrrecoThemeBg new from dir
136 IrrecoThemeBg
*irreco_theme_bg_new_from_dir(const gchar
*dir
)
138 IrrecoThemeBg
*self
= NULL
;
142 self
= irreco_theme_bg_new();
143 irreco_theme_bg_read(self
, dir
);
144 IRRECO_RETURN_PTR(self
);
147 void irreco_theme_bg_read(IrrecoThemeBg
*self
, const gchar
*dir
)
150 IrrecoKeyFile
*keyfile
;
153 GString
*conf
= NULL
;
156 conf
= g_string_new(dir
);
157 g_string_append_printf(conf
, "/bg.conf");
158 keyfile
= irreco_keyfile_create(dir
,
161 if (keyfile
== NULL
) goto end
;
162 /* Required fields. */
163 if (!irreco_keyfile_get_str(keyfile
, "name", &name
) ||
164 !irreco_keyfile_get_path(keyfile
, "image", &image
)) {
165 IRRECO_PRINTF("Could not read style from group \"%s\"\n",
170 irreco_theme_bg_set(self
, name
, image
);
171 irreco_theme_bg_print(self
);
174 if(keyfile
!= NULL
) irreco_keyfile_destroy(keyfile
);
175 if(name
!= NULL
) g_free(name
);
176 if(image
!= NULL
) g_free(image
);
182 * Save bg to theme folder
184 gboolean
irreco_theme_bg_save(IrrecoThemeBg
*self
, const gchar
*path
)
186 gboolean rvalue
= FALSE
;
187 GString
*keyfile_path
;
197 keyfile
= g_key_file_new();
198 image_name
= g_string_new(NULL
);
199 image_path
= g_string_new(path
);
200 keyfile_path
= g_string_new(path
);
201 folder
= g_string_new(self
->image_name
->str
);
203 g_string_ascii_down(folder
);
204 folder_name
= g_strdup(folder
->str
);
205 g_strdelimit(folder_name
, " ", '_');
206 g_strdelimit(folder_name
, "-|> <.", 'a');
207 g_string_printf(folder
, "%s", folder_name
);
209 g_string_append_printf(image_path
, "/%s", folder_name
);
210 g_string_append_printf(keyfile_path
, "/%s", folder_name
);
212 IRRECO_DEBUG("mkdir %s\n",image_path
->str
);
213 g_mkdir(image_path
->str
, 0777);
216 type
= g_strrstr(self
->image_path
->str
, ".");
217 g_string_printf(image_name
, "%s%s", "image", type
);
218 g_string_append_printf(image_path
, "/%s%s", "image", type
);
220 /* Copy image to bg folder */
221 cp_cmd
= g_strconcat("cp -f '", self
->image_path
->str
, "' '",
222 image_path
->str
,"'", NULL
);
225 /* Create keyfile and save it to folder*/
226 irreco_gkeyfile_set_string(keyfile
, "theme-bg" , "name",
227 self
->image_name
->str
);
228 irreco_gkeyfile_set_string(keyfile
, "theme-bg", "image", image_name
->str
);
229 g_string_append_printf(keyfile_path
, "/bg.conf");
230 irreco_write_keyfile(keyfile
, keyfile_path
->str
);
232 /* No error occured. */
237 g_string_free(image_name
, TRUE
);
238 g_key_file_free(keyfile
);
239 g_string_free(keyfile_path
, TRUE
);
240 g_string_free(image_path
, TRUE
);
242 IRRECO_RETURN_BOOL(rvalue
);
247 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
248 /* Events and Callbacks */
249 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/