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 "MsgNotificationWrapper.h"
24 #include "MsgGconfWrapper.h"
28 #define GCONF_SUCCESS 1
30 MSG_GOBJECT_CLIENT_S* pClient = NULL;
34 bool bAutoReject = false;
35 bool bUnknownAutoReject = false;
38 /*==================================================================================================
40 ==================================================================================================*/
41 #define MSG_UNREAD_CNT "db/badge/org.tizen.message"
44 /*==================================================================================================
45 FUNCTION IMPLEMENTATION
46 ==================================================================================================*/
47 static void MsgVconfCB(keynode_t *key, void* data)
50 keyStr = vconf_keynode_get_name(key);
55 if (!strcmp(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL)) {
56 bAutoReject = vconf_keynode_get_bool(key);
57 MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, bAutoReject);
58 } else if (!strcmp(keyStr, VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL)) {
59 bUnknownAutoReject = vconf_keynode_get_bool(key);
60 MSG_DEBUG("[%s] key CB called. set to [%d].", VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, bUnknownAutoReject);
62 MSG_DEBUG("key did not match.");
66 msg_error_t MsgSettingSetString(const char *pKey, const char *pSetValue)
68 if (pKey == NULL || pSetValue == NULL)
70 MSG_DEBUG("IN Parameter is NULL");
71 return MSG_ERR_NULL_POINTER;
75 if (gconf_client_set_string((GConfClient*)pClient, pKey, pSetValue, NULL) != GCONF_SUCCESS)
76 return MSG_ERR_SET_SETTING;
78 if (vconf_set_str(pKey, pSetValue) != 0)
79 return MSG_ERR_SET_SETTING;
86 msg_error_t MsgSettingSetInt(const char *pKey, int nSetValue)
90 MSG_DEBUG("IN Parameter is NULL");
91 return MSG_ERR_NULL_POINTER;
95 if (gconf_client_set_int((GConfClient*)pClient, pKey, nSetValue, NULL) != GCONF_SUCCESS)
96 return MSG_ERR_SET_SETTING;
98 if (vconf_set_int(pKey, nSetValue) != 0)
99 return MSG_ERR_SET_SETTING;
106 msg_error_t MsgSettingSetBool(const char *pKey, bool bSetValue)
110 MSG_DEBUG("IN Parameter is NULL");
111 return MSG_ERR_NULL_POINTER;
115 if (gconf_client_set_bool((GConfClient*)pClient, pKey, bSetValue, NULL) != GCONF_SUCCESS)
116 return MSG_ERR_SET_SETTING;
118 if (vconf_set_bool(pKey, bSetValue) != 0)
119 return MSG_ERR_SET_SETTING;
126 char* MsgSettingGetString(const char *pKey)
130 MSG_DEBUG("IN Parameter is NULL");
135 return gconf_client_get_string((GConfClient*)pClient, pKey, NULL);
137 return vconf_get_str(pKey);
142 int MsgSettingGetInt(const char *pKey)
146 MSG_DEBUG("IN Parameter is NULL");
153 retVal = gconf_client_get_int((GConfClient*)pClient, pKey, NULL);
155 if (vconf_get_int(pKey, &retVal) < 0)
163 int MsgSettingGetBool(const char *pKey, bool *pVal)
167 MSG_DEBUG("IN Parameter is NULL");
171 int retVal = 0, param = 0;
174 *pVal = gconf_client_get_bool((GConfClient*)pClient, pKey, NULL);
176 if (vconf_get_bool(pKey, ¶m) < 0)
185 void MsgChangePmState()
190 callStatus = MsgSettingGetInt(VCONFKEY_CALL_STATE);
191 MSG_DEBUG("Call Status = %d", callStatus);
193 if (callStatus > VCONFKEY_CALL_OFF && callStatus < VCONFKEY_CALL_STATE_MAX) {
194 MSG_DEBUG("Call is activated. Do not turn on the lcd.");
196 MSG_DEBUG("Call is activated. Turn on the lcd.");
197 pm_change_state(LCD_NORMAL);
203 msg_error_t MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt)
207 MSG_DEBUG("smsCnt = %d, mmsCnt = %d ##", SmsCnt, MmsCnt);
209 // Set Msg Count into VConf
210 if (MsgSettingSetIndicator(SmsCnt, MmsCnt) != MSG_SUCCESS)
212 MSG_DEBUG("MsgSettingSetIndicator() FAILED");
213 return MSG_ERR_SET_SETTING;
216 if (SmsCnt == 0 && MmsCnt == 0)
218 MSG_DEBUG("No New Message.");
222 MSG_DEBUG("New Message.");
232 msg_error_t MsgSettingSetIndicator(int SmsCnt, int MmsCnt)
235 if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE, SmsCnt) != 0)
236 return MSG_ERR_SET_SETTING;
237 if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE, MmsCnt) != 0)
238 return MSG_ERR_SET_SETTING;
240 int sumCnt = SmsCnt + MmsCnt;
242 // if (MsgSettingSetInt(MSG_UNREAD_CNT, sumCnt) != 0)
243 if (MsgInsertBadge(sumCnt) != MSG_SUCCESS)
244 return MSG_ERR_SET_SETTING;
250 bool MsgSettingGetAutoReject()
255 bool MsgSettingGetUnknownAutoReject()
257 return bUnknownAutoReject;
260 void MsgSettingRegVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
262 if (vconf_notify_key_changed(pKey, pCb, NULL) < 0) {
263 MSG_DEBUG("Fail to regist vconf CB with [%s]", pKey);
265 MSG_DEBUG("Success to regist vconf CB with [%s]", pKey);
269 void MsgSettingRemoveVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
271 if (vconf_ignore_key_changed(pKey, pCb) < 0) {
272 MSG_DEBUG("Fail to remove vconf CB with [%s]", pKey);
274 MSG_DEBUG("Success to remove vconf CB with [%s]", pKey);
279 void MsgSettingRegVconfCB()
281 // Set default values.
282 MsgSettingGetBool(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, &bAutoReject);
283 MsgSettingGetBool(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, &bUnknownAutoReject);
285 MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB);
286 MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB);
289 void MsgSettingRemoveVconfCB()
291 MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB);
292 MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB);