2 * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <iniparser.h>
24 #include <Elementary.h>
27 #include <tzsh_quickpanel_service.h>
29 #include "preference.h"
31 #include "quickpanel-ui.h"
33 #define FILE_PREFERENCE DATADIR_RW"/preference.ini"
35 static const char *_default_preference_get(const char *key)
37 retif(key == NULL, NULL, "invalid parameter");
39 if (strcmp(key, PREF_BRIGHTNESS) == 0) {
41 } else if (strcmp(key, PREF_QUICKSETTING_ORDER) == 0){
42 return "wifi,gps,sound,rotate,bluetooth,mobile_data,assisitvelight,u_power_saving,wifi_hotspot,flightmode";
43 } else if (strcmp(key, PREF_QUICKSETTING_FEATURED_NUM) == 0){
45 } else if (strcmp(key, PREF_SHORTCUT_ENABLE) == 0){
47 } else if (strcmp(key, PREF_SHORTCUT_EARPHONE_ORDER) == 0){
48 return "org.tizen.music-player,org.tizen.videos,org.tizen.phone,srfxzv8GKR.YouTube,org.tizen.voicerecorder";
54 static inline int _key_validation_check(const char *key)
56 if (strcmp(key, PREF_BRIGHTNESS) == 0) {
58 } else if (strcmp(key, PREF_QUICKSETTING_ORDER) == 0){
60 } else if (strcmp(key, PREF_QUICKSETTING_FEATURED_NUM) == 0){
62 } else if (strcmp(key, PREF_SHORTCUT_ENABLE) == 0){
64 } else if (strcmp(key, PREF_SHORTCUT_EARPHONE_ORDER) == 0){
71 static inline int _is_file_exist(void)
74 if (access(FILE_PREFERENCE, O_RDWR) == 0) {
81 static void _default_file_create(void)
85 fp = fopen(FILE_PREFERENCE, "w");
86 retif(fp == NULL, , "fatal:failed to create preference file");
97 , PREF_BRIGHTNESS_KEY, _default_preference_get(PREF_BRIGHTNESS)
98 , PREF_QUICKSETTING_ORDER_KEY, _default_preference_get(PREF_QUICKSETTING_ORDER)
99 , PREF_QUICKSETTING_FEATURED_NUM_KEY, _default_preference_get(PREF_QUICKSETTING_FEATURED_NUM)
100 , PREF_SHORTCUT_ENABLE_KEY, _default_preference_get(PREF_SHORTCUT_ENABLE)
101 , PREF_SHORTCUT_EARPHONE_ORDER_KEY, _default_preference_get(PREF_SHORTCUT_EARPHONE_ORDER)
107 HAPI int quickpanel_preference_get(const char *key, char *value)
110 dictionary *ini = NULL;
111 const char *value_r = NULL;
112 retif(key == NULL, QP_FAIL, "Invalid parameter!");
113 retif(value == NULL, QP_FAIL, "Invalid parameter!");
115 ini = iniparser_load(FILE_PREFERENCE);
117 DBG("failed to load ini file");
118 _default_file_create();
119 value_r = _default_preference_get(key);
123 value_r = iniparser_getstr(ini, key);
124 if (value_r == NULL) {
125 value_r = _default_preference_get(key);
126 if (_key_validation_check(key) == 1) {
127 _default_file_create();
131 DBG("get:[%s]", value_r);
135 if (value_r != NULL) {
136 strcpy(value, value_r);
141 iniparser_freedict(ini);
147 HAPI const char *quickpanel_preference_default_get(const char *key)
149 retif(key == NULL, NULL, "Invalid parameter!");
151 return _default_preference_get(key);
154 HAPI int quickpanel_preference_set(const char *key, char *value)
158 dictionary *ini = NULL;
159 retif(key == NULL, QP_FAIL, "Invalid parameter!");
160 retif(value == NULL, QP_FAIL, "Invalid parameter!");
162 if (_is_file_exist() == 0) {
163 _default_file_create();
166 ini = iniparser_load(FILE_PREFERENCE);
167 retif(ini == NULL, QP_FAIL, "failed to load ini file");
169 if (iniparser_setstr(ini, (char *)key, value) == 0) {
172 ERR("failed to write %s=%s", key, value);
175 fp = fopen(FILE_PREFERENCE, "w");
177 iniparser_dump_ini(ini, fp);
181 iniparser_freedict(ini);