2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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.tizenopensource.org/license
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.
22 #include "MsgUtilStorage.h"
23 #include "MsgGconfWrapper.h"
27 #define GCONF_SUCCESS 1
29 MSG_GOBJECT_CLIENT_S* pClient = NULL;
33 bool bAutoReject = false;
34 bool bUnknownAutoReject = false;
37 /*==================================================================================================
39 ==================================================================================================*/
42 /*==================================================================================================
43 FUNCTION IMPLEMENTATION
44 ==================================================================================================*/
45 static void MsgVconfCB(keynode_t *key, void* data)
48 keyStr = vconf_keynode_get_name(key);
53 if (!strcmp(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL)) {
54 bAutoReject = vconf_keynode_get_bool(key);
55 MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, bAutoReject);
56 } else if (!strcmp(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL)) {
57 bUnknownAutoReject = vconf_keynode_get_bool(key);
58 MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, bUnknownAutoReject);
60 MSG_DEBUG("key did not match.");
64 msg_error_t MsgSettingSetString(const char *pKey, const char *pSetValue)
66 if (pKey == NULL || pSetValue == NULL)
68 MSG_DEBUG("IN Parameter is NULL");
69 return MSG_ERR_NULL_POINTER;
73 if (gconf_client_set_string((GConfClient*)pClient, pKey, pSetValue, NULL) != GCONF_SUCCESS)
74 return MSG_ERR_SET_SETTING;
76 if (vconf_set_str(pKey, pSetValue) != 0)
77 return MSG_ERR_SET_SETTING;
84 msg_error_t MsgSettingSetInt(const char *pKey, int nSetValue)
88 MSG_DEBUG("IN Parameter is NULL");
89 return MSG_ERR_NULL_POINTER;
93 if (gconf_client_set_int((GConfClient*)pClient, pKey, nSetValue, NULL) != GCONF_SUCCESS)
94 return MSG_ERR_SET_SETTING;
96 if (vconf_set_int(pKey, nSetValue) != 0)
97 return MSG_ERR_SET_SETTING;
104 msg_error_t MsgSettingSetBool(const char *pKey, bool bSetValue)
108 MSG_DEBUG("IN Parameter is NULL");
109 return MSG_ERR_NULL_POINTER;
113 if (gconf_client_set_bool((GConfClient*)pClient, pKey, bSetValue, NULL) != GCONF_SUCCESS)
114 return MSG_ERR_SET_SETTING;
116 if (vconf_set_bool(pKey, bSetValue) != 0)
117 return MSG_ERR_SET_SETTING;
124 char* MsgSettingGetString(const char *pKey)
128 MSG_DEBUG("IN Parameter is NULL");
133 return gconf_client_get_string((GConfClient*)pClient, pKey, NULL);
135 return vconf_get_str(pKey);
140 int MsgSettingGetInt(const char *pKey)
144 MSG_DEBUG("IN Parameter is NULL");
151 retVal = gconf_client_get_int((GConfClient*)pClient, pKey, NULL);
153 if (vconf_get_int(pKey, &retVal) < 0)
161 int MsgSettingGetBool(const char *pKey, bool *pVal)
165 MSG_DEBUG("IN Parameter is NULL");
169 int retVal = 0, param = 0;
172 *pVal = gconf_client_get_bool((GConfClient*)pClient, pKey, NULL);
174 if (vconf_get_bool(pKey, ¶m) < 0)
184 msg_error_t MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt)
188 MSG_DEBUG("smsCnt = %d, mmsCnt = %d ##", SmsCnt, MmsCnt);
190 // Set Msg Count into VConf
191 if (MsgSettingSetIndicator(SmsCnt, MmsCnt) != MSG_SUCCESS)
193 MSG_DEBUG("MsgSettingSetIndicator() FAILED");
194 return MSG_ERR_SET_SETTING;
197 if (SmsCnt == 0 && MmsCnt == 0)
199 MSG_DEBUG("No New Message.");
203 MSG_DEBUG("New Message.");
204 pm_change_state(LCD_NORMAL);
213 msg_error_t MsgSettingSetIndicator(int SmsCnt, int MmsCnt)
216 if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE, SmsCnt) != 0)
217 return MSG_ERR_SET_SETTING;
218 if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE, MmsCnt) != 0)
219 return MSG_ERR_SET_SETTING;
221 /* Not used currently.
222 int sumCnt = SmsCnt + MmsCnt;
224 if (MsgSettingSetInt(MSG_UNREAD_CNT, sumCnt) != 0)
225 return MSG_ERR_SET_SETTING;
232 bool MsgSettingGetAutoReject()
237 bool MsgSettingGetUnknownAutoReject()
239 return bUnknownAutoReject;
243 void MsgSettingRegVconfCB()
245 // Set default values.
246 MsgSettingGetBool(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, &bAutoReject);
247 MsgSettingGetBool(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, &bUnknownAutoReject);
249 if (vconf_notify_key_changed(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB, NULL) < 0) {
250 MSG_DEBUG("Fail to regist vconf CB with [%s]", VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL);
253 if (vconf_notify_key_changed(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB, NULL) < 0) {
254 MSG_DEBUG("Fail to regist vconf CB with [%s]", VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL);
258 void MsgSettingRemoveVconfCB()
260 if (vconf_ignore_key_changed(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB) < 0) {
261 MSG_DEBUG("Fail to regist vconf CB with [%s]", VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL);
264 if (vconf_ignore_key_changed(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB) < 0) {
265 MSG_DEBUG("Fail to regist vconf CB with [%s]", VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL);
269 void MsgSettingRegVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
271 if (vconf_notify_key_changed(pKey, pCb, NULL) < 0) {
272 MSG_DEBUG("Fail to regist vconf CB with [%s]", pKey);
274 MSG_DEBUG("Success to regist vconf CB with [%s]", pKey);