2 * Copyright (c) 2013, TOYOTA MOTOR CORPORATION.
4 * This program is licensed under the terms and conditions of the
5 * Apache License, version 2.0. The full text of the Apache License is at
6 * http://www.apache.org/licenses/LICENSE-2.0
10 //==========================================================================
12 * @file CicoGKeyFileConfig
14 * @brief This file is implementation of CicoGKeyFileConfig class
16 //==========================================================================
19 #include "CicoGKeyFileConfig.h"
20 #include "CicoResourceConfig.h"
22 //==========================================================================
24 //==========================================================================
25 //--------------------------------------------------------------------------
27 * @brief CicoGKeyFileConfig::CicoGKeyFileConfig
30 //--------------------------------------------------------------------------
31 CicoGKeyFileConfig::CicoGKeyFileConfig()
36 //--------------------------------------------------------------------------
38 * @brief CicoGKeyFileConfig::CicoGKeyFileConfig
41 //--------------------------------------------------------------------------
42 CicoGKeyFileConfig::~CicoGKeyFileConfig()
44 if (NULL != m_gKeyFile) {
45 g_key_file_free(m_gKeyFile);
49 //--------------------------------------------------------------------------
51 * @brief CicoGKeyFileConfig::Initialize
52 * read and initialize for homescreen configuration
54 * @param[in] conf configuration file name
56 * @retval true success
59 //--------------------------------------------------------------------------
61 CicoGKeyFileConfig::Initialize(const char *conf)
64 char path[ICO_TEMP_BUF_SIZE];
67 if (NULL != m_gKeyFile) {
68 /*if initialize was done*/
72 m_gKeyFile = g_key_file_new();
74 filepath = g_string_new("test");
75 CicoResourceConfig::GetConfPath(path, sizeof(path));
76 g_string_printf(filepath, "%s/%s", path, conf);
77 if (!g_file_test(filepath->str, G_FILE_TEST_IS_REGULAR)) {
82 g_key_file_load_from_file(m_gKeyFile, filepath->str,
83 (GKeyFileFlags)(G_KEY_FILE_KEEP_COMMENTS |
84 G_KEY_FILE_KEEP_TRANSLATIONS),
87 ICO_WRN("%s: %s", filepath->str, error->message);
92 g_string_free(filepath, TRUE);
97 /*--------------------------------------------------------------------------*/
99 * @brief CicoGKeyFileConfig::ConfigGetInteger
100 * Return integer value in homescreen configuration file.
101 * If not exist,return defaultvlaue in params.
103 * @param[in] group_name configuration group name
104 * @param[in] key configuration name
105 * @param[in] default_value default value
106 * @return config integer
108 /*--------------------------------------------------------------------------*/
110 CicoGKeyFileConfig::ConfigGetInteger(const char *group_name, const char *key, int default_value)
112 GError *error = NULL;
114 if (m_gKeyFile == NULL) {
115 return default_value;
118 int value = g_key_file_get_integer(m_gKeyFile, group_name, key, &error);
120 ICO_WRN("%s", error->message);
122 return default_value;
127 /*--------------------------------------------------------------------------*/
129 * @brief CicoGKeyFileConfig::ConfigGetString
130 * Return string value in homescreen configuration file.
131 * If not exist,return defaultvlaue in params.
133 * @param[in] group_name configuration group name
134 * @param[in] key configuration name
135 * @param[in] default_value default value
136 * @return config string
138 /*--------------------------------------------------------------------------*/
140 CicoGKeyFileConfig::ConfigGetString(const char *group_name, const char *key,
141 const char *default_value)
143 GError *error = NULL;
145 if (m_gKeyFile == NULL) {
146 return default_value;
149 const char *value = g_key_file_get_string(m_gKeyFile, group_name, key,
152 ICO_WRN("%s", error->message);
154 return default_value;
158 // vim:set expandtab ts=4 sw=4: