4 * Copyright (C) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
7 * DoHyung Hong <don.hong@samsung.com>
8 * SeokYeon Hwang <syeon.hwang@samsung.com>
9 * Hyunjun Son <hj79.son@samsung.com>
10 * SangJin Kim <sangjin3.kim@samsung.com>
11 * MunKyu Im <munkyu.im@samsung.com>
12 * KiTae Kim <kt920.kim@samsung.com>
13 * JinHyung Jo <jinhyung.jo@samsung.com>
14 * SungMin Ha <sungmin82.ha@samsung.com>
15 * JiHye Kim <jihye1128.kim@samsung.com>
16 * GiWoong Kim <giwoong.kim@samsung.com>
17 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
18 * DongKyun Yun <dk77.yun@samsung.com>
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License
22 * as published by the Free Software Foundation; either version 2
23 * of the License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
43 @brief miscellaneous functions used in ISE
49 #include <glib/gstdio.h>
60 //DEFAULT_DEBUG_CHANNEL(tizen);
61 MULTI_DEBUG_CHANNEL(tizen, utils);
63 static GHashTable *windows_hash = NULL; /* hash table to get widow and widget of Emulator */
67 @brief hash intialization
69 GHashTable *window_hash_init (void)
71 windows_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, NULL);
77 @brief add window widget to hash
79 void add_window (GtkWidget *win, gint window_id)
81 g_hash_table_insert (windows_hash, GINT_TO_POINTER (window_id), win);
86 @brief search window widget by using window id as a key
87 @return matched window widget
89 GtkWidget *get_window (gint window_id)
91 GtkWidget *win = (GtkWidget *) g_hash_table_lookup (windows_hash, GINT_TO_POINTER (window_id));
99 void window_hash_destroy (void)
101 g_hash_table_destroy (windows_hash);
106 @brief add widget to hash
107 @param window_id: ID of widget
108 @param widget_name: widget name
109 @param widget: widget to add in hash
111 void add_widget (gint window_id, gchar * widget_name, GtkWidget * widget)
114 WARN("Parent window not exist!\n");
118 GtkWidget *parent = get_window (window_id);
120 WARN("Parent window not exist!\n");
124 g_object_set_data_full (G_OBJECT (parent), widget_name, g_object_ref (widget), (GDestroyNotify) g_object_unref);
129 @brief get widget from hash
130 @param window_id: ID of widget
131 @param widget_name: widget name to search in hash
132 @return widget: widget to matched widget_name
134 GtkWidget *get_widget (gint window_id, gchar *widget_name)
138 parent = get_window (window_id);
140 WARN( "Parent window not exist!\n");
144 GtkWidget *w = (GtkWidget *) g_object_get_data (G_OBJECT (parent), widget_name);
146 INFO( "Widget(%s) not found!\n", widget_name);
155 * @brief set config integer value in config.ini file
156 * @return fail(-1), success(0)
159 int set_config_type(gchar *filepath, const gchar *group, const gchar *field, const int type)
162 GError *error = NULL;
165 keyfile = g_key_file_new();
166 if (!g_key_file_load_from_file(keyfile, filepath, G_KEY_FILE_KEEP_COMMENTS, &error)) {
167 INFO( "loading key file form %s is failed.\n", filepath);
171 g_key_file_set_integer(keyfile, group, field, type);
173 gchar *data = g_key_file_to_data(keyfile, &length, &error);
175 g_print("in set_config_type\n");
176 g_print("%s", error->message);
177 g_clear_error(&error);
181 length = strlen(data);
182 g_file_set_contents(filepath, data, length, &error);
184 g_print("in set_cofig_type after g_file_set_contetns\n");
185 g_print("%s", error->message);
186 g_clear_error(&error);
189 g_chmod(filepath, 0666);
192 g_key_file_free(keyfile);
199 * @brief delete group in targetlist.ini file
200 * @return fail(-1), success(0)
203 int del_config_group(gchar *filepath, const gchar *group)
206 GError *error = NULL;
209 keyfile = g_key_file_new();
210 if (!g_key_file_load_from_file(keyfile, filepath, G_KEY_FILE_KEEP_COMMENTS, &error)) {
211 INFO( "loading key file form %s is failed.\n", filepath);
215 if(!g_key_file_remove_group(keyfile, group, &error)){
216 ERR( "fail to remove this key. group name : %s\n", group);
220 gchar *data = g_key_file_to_data(keyfile, &length, &error);
222 g_print("in set_config_type\n");
223 g_print("%s", error->message);
224 g_clear_error(&error);
228 length = strlen(data);
229 g_file_set_contents(filepath, data, length, &error);
231 g_print("in set_config_value after g_file_set_contents\n");
232 g_print("%s", error->message);
233 g_clear_error(&error);
237 g_key_file_free(keyfile);
244 * @brief see if target_name is group
245 * @return true / false
248 gboolean is_group(const gchar *target_name)
250 char **target_groups = NULL;
253 char *filepath = get_targetlist_filepath();
255 target_groups = get_virtual_target_groups(filepath, &group_num);
257 for(i = 0; i < group_num; i++)
259 if(strcmp(target_groups[i], target_name) == 0)
268 * @brief get group name of specific target name
272 char *get_group_name(gchar *filepath, const gchar *field)
276 char **target_groups = NULL;
280 keyfile = g_key_file_new();
281 if (!g_key_file_load_from_file(keyfile, filepath, G_KEY_FILE_KEEP_COMMENTS, &err)) {
282 INFO( "loading key file form %s is failed.\n", filepath);
286 target_groups = get_virtual_target_groups(filepath, &group_num);
288 for(i = 0; i < group_num; i++)
290 if(!g_key_file_has_key(keyfile, target_groups[i], field, &err))
291 INFO("%s is not in %s\n", target_groups[i], field);
294 g_key_file_free(keyfile);
295 return target_groups[i];
299 INFO("there is no group include %s\n", field);
300 g_key_file_free(keyfile);
308 * @brief delete target name key in targetlist.ini file
309 * @return fail(-1), success(0)
312 int del_config_key(gchar *filepath, const gchar *group, const gchar *field)
315 GError *error = NULL;
318 keyfile = g_key_file_new();
319 if (!g_key_file_load_from_file(keyfile, filepath, G_KEY_FILE_KEEP_COMMENTS, &error)) {
320 INFO( "loading key file form %s is failed.\n", filepath);
324 if(!g_key_file_remove_key(keyfile, group, field, &error)){
325 ERR( "fail to remove this key. [group: %s , key: %s]\n", group, field);
329 gchar *data = g_key_file_to_data(keyfile, &length, &error);
331 g_print("in set_config_type\n");
332 g_print("%s", error->message);
333 g_clear_error(&error);
337 length = strlen(data);
338 g_file_set_contents(filepath, data, length, &error);
340 g_print("in set_config_value after g_file_set_contents\n");
341 g_print("%s", error->message);
342 g_clear_error(&error);
346 g_key_file_free(keyfile);
354 * @brief set config characters value in config.ini file
355 * @return fail(-1), success(0)
358 int set_config_value(gchar *filepath, const gchar *group, const gchar *field, const gchar *value)
361 GError *error = NULL;
365 keyfile = g_key_file_new();
367 if (!g_key_file_load_from_file(keyfile, filepath, G_KEY_FILE_KEEP_COMMENTS, &error)) {
368 WARN( "loading key file form %s is failed.\n", filepath);
369 file_status = is_exist_file(filepath);
370 if(file_status == -1 || file_status == FILE_NOT_EXISTS)
372 char *message = g_strdup_printf("File does not exist\n\n"
373 " - [%s]", filepath);
374 show_message("Error", message);
380 g_key_file_set_value(keyfile, group, field, value);
382 gchar *data = g_key_file_to_data(keyfile, &length, &error);
384 g_print("in set_config_type\n");
385 g_print("%s", error->message);
386 g_clear_error(&error);
390 length = strlen(data);
391 g_file_set_contents(filepath, data, length, &error);
393 g_print("in set_config_value after g_file_set_contents\n");
394 g_print("%s", error->message);
395 g_clear_error(&error);
399 g_key_file_free(keyfile);
406 * @brief get config integer type from config.ini file
407 * @return fail(0), success(type)
410 int get_config_type(gchar *filepath, const gchar *group, const gchar *field)
413 GError *error = NULL;
416 keyfile = g_key_file_new();
418 if (!g_key_file_load_from_file(keyfile, filepath, G_KEY_FILE_KEEP_COMMENTS, &error)) {
419 ERR("loading key file from %s is failed\n", filepath );
423 type = g_key_file_get_integer(keyfile, group, field, &error);
425 g_key_file_free(keyfile);
431 * @brief get config characters value from config.ini file
432 * @return fail(0), success(value)
435 char *get_config_value(gchar *filepath, const gchar *group, const gchar *field)
438 GError *error = NULL;
441 keyfile = g_key_file_new();
443 if (!g_key_file_load_from_file(keyfile, filepath, G_KEY_FILE_KEEP_COMMENTS, &error)) {
444 ERR("loading key file form %s is failed\n", filepath );
448 value = g_key_file_get_value(keyfile, group, field, NULL);
450 if (!value || strlen(value) == 0) {
456 g_key_file_free(keyfile);
462 @brief convert string to lower case string
463 @param string string to covert
467 strlwr (char *string)
472 *string = (char) tolower (*string);