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
);
173 irreco_theme_bg_print(self
);
176 if(keyfile
!= NULL
) irreco_keyfile_destroy(keyfile
);
177 if(name
!= NULL
) g_free(name
);
178 if(image
!= NULL
) g_free(image
);
184 * Save bg to theme folder
186 gboolean
irreco_theme_bg_save(IrrecoThemeBg
*self
, const gchar
*path
)
188 gboolean rvalue
= FALSE
;
189 GString
*keyfile_path
;
200 keyfile
= g_key_file_new();
201 image_name
= g_string_new(NULL
);
202 image_path
= g_string_new(path
);
203 keyfile_path
= g_string_new(path
);
204 folder
= g_string_new(self
->image_name
->str
);
206 g_string_ascii_down(folder
);
207 folder_name
= g_strdup(folder
->str
);
208 g_strdelimit(folder_name
, " ", '_');
209 /*g_strdelimit(folder_name, "-|> <.", "a");*/
210 g_string_printf(folder
, "%s", folder_name
);
212 g_string_append_printf(image_path
, "/%s", folder_name
);
213 g_string_append_printf(keyfile_path
, "/%s", folder_name
);
215 IRRECO_DEBUG("mkdir %s\n",image_path
->str
);
216 g_mkdir(image_path
->str
, 0777);
219 type
= g_strrstr(self
->image_path
->str
, ".");
220 g_string_printf(image_name
, "%s%s", "image", type
);
221 g_string_append_printf(image_path
, "/%s%s", "image", type
);
223 /* Copy image to bg folder */
225 cp_cmd
= g_strconcat("cp -f ", self
->image_path
->str
, " ",
226 image_path
->str
, NULL
);
229 /* Create keyfile and save it to folder*/
230 irreco_gkeyfile_set_string(keyfile
, "theme-bg" , "name",
231 self
->image_name
->str
);
232 irreco_gkeyfile_set_string(keyfile
, "theme-bg", "image", image_name
->str
);
233 g_string_append_printf(keyfile_path
, "/bg.conf");
234 irreco_write_keyfile(keyfile
, keyfile_path
->str
);
236 /* No error occured. */
241 g_string_free(image_name
, TRUE
);
242 g_key_file_free(keyfile
);
243 g_string_free(keyfile_path
, TRUE
);
244 g_string_free(image_path
, TRUE
);
246 IRRECO_RETURN_BOOL(rvalue
);
251 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
252 /* Events and Callbacks */
253 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/