2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.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);
61 } else if (!strcmp(keyStr, VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER)) {
62 int contactDisplayOrder = vconf_keynode_get_int(key);
63 MSG_DEBUG("[%s] key CB called. Apply [%d]", VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, contactDisplayOrder);
64 MsgStoRefreshConversationDisplayName();
66 MSG_DEBUG("key did not match.");
70 msg_error_t MsgSettingSetString(const char *pKey, const char *pSetValue)
72 if (pKey == NULL || pSetValue == NULL)
74 MSG_DEBUG("IN Parameter is NULL");
75 return MSG_ERR_NULL_POINTER;
79 if (gconf_client_set_string((GConfClient*)pClient, pKey, pSetValue, NULL) != GCONF_SUCCESS)
80 return MSG_ERR_SET_SETTING;
82 if (vconf_set_str(pKey, pSetValue) != 0)
83 return MSG_ERR_SET_SETTING;
90 msg_error_t MsgSettingSetInt(const char *pKey, int nSetValue)
94 MSG_DEBUG("IN Parameter is NULL");
95 return MSG_ERR_NULL_POINTER;
99 if (gconf_client_set_int((GConfClient*)pClient, pKey, nSetValue, NULL) != GCONF_SUCCESS)
100 return MSG_ERR_SET_SETTING;
102 if (vconf_set_int(pKey, nSetValue) != 0)
103 return MSG_ERR_SET_SETTING;
110 msg_error_t MsgSettingSetBool(const char *pKey, bool bSetValue)
114 MSG_DEBUG("IN Parameter is NULL");
115 return MSG_ERR_NULL_POINTER;
119 if (gconf_client_set_bool((GConfClient*)pClient, pKey, bSetValue, NULL) != GCONF_SUCCESS)
120 return MSG_ERR_SET_SETTING;
122 if (vconf_set_bool(pKey, bSetValue) != 0)
123 return MSG_ERR_SET_SETTING;
130 char* MsgSettingGetString(const char *pKey)
134 MSG_DEBUG("IN Parameter is NULL");
139 return gconf_client_get_string((GConfClient*)pClient, pKey, NULL);
141 return vconf_get_str(pKey);
146 int MsgSettingGetInt(const char *pKey)
150 MSG_DEBUG("IN Parameter is NULL");
157 retVal = gconf_client_get_int((GConfClient*)pClient, pKey, NULL);
159 if (vconf_get_int(pKey, &retVal) < 0)
167 int MsgSettingGetBool(const char *pKey, bool *pVal)
171 MSG_DEBUG("IN Parameter is NULL");
175 int retVal = 0, param = 0;
178 *pVal = gconf_client_get_bool((GConfClient*)pClient, pKey, NULL);
180 if (vconf_get_bool(pKey, ¶m) < 0)
189 void MsgChangePmState()
194 callStatus = MsgSettingGetInt(VCONFKEY_CALL_STATE);
195 MSG_DEBUG("Call Status = %d", callStatus);
197 if (callStatus > VCONFKEY_CALL_OFF && callStatus < VCONFKEY_CALL_STATE_MAX) {
198 MSG_DEBUG("Call is activated. Do not turn on the lcd.");
200 MSG_DEBUG("Call is activated. Turn on the lcd.");
201 pm_change_state(LCD_NORMAL);
207 msg_error_t MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt)
211 MSG_DEBUG("smsCnt = %d, mmsCnt = %d ##", SmsCnt, MmsCnt);
213 // Set Msg Count into VConf
214 if (MsgSettingSetIndicator(SmsCnt, MmsCnt) != MSG_SUCCESS)
216 MSG_DEBUG("MsgSettingSetIndicator() FAILED");
217 return MSG_ERR_SET_SETTING;
220 if (SmsCnt == 0 && MmsCnt == 0)
222 MSG_DEBUG("No New Message.");
226 MSG_DEBUG("New Message.");
236 msg_error_t MsgSettingSetIndicator(int SmsCnt, int MmsCnt)
239 if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE, SmsCnt) != 0)
240 return MSG_ERR_SET_SETTING;
241 if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE, MmsCnt) != 0)
242 return MSG_ERR_SET_SETTING;
244 int sumCnt = SmsCnt + MmsCnt;
246 // if (MsgSettingSetInt(MSG_UNREAD_CNT, sumCnt) != 0)
247 if (MsgInsertBadge(sumCnt) != MSG_SUCCESS)
248 return MSG_ERR_SET_SETTING;
254 bool MsgSettingGetAutoReject()
259 bool MsgSettingGetUnknownAutoReject()
261 return bUnknownAutoReject;
264 void MsgSettingRegVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
266 if (vconf_notify_key_changed(pKey, pCb, NULL) < 0) {
267 MSG_DEBUG("Fail to regist vconf CB with [%s]", pKey);
269 MSG_DEBUG("Success to regist vconf CB with [%s]", pKey);
273 void MsgSettingRemoveVconfCBCommon(const char *pKey, _vconf_change_cb pCb)
275 if (vconf_ignore_key_changed(pKey, pCb) < 0) {
276 MSG_DEBUG("Fail to remove vconf CB with [%s]", pKey);
278 MSG_DEBUG("Success to remove vconf CB with [%s]", pKey);
283 void MsgSettingRegVconfCB()
285 // Set default values.
286 MsgSettingGetBool(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, &bAutoReject);
287 MsgSettingGetBool(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, &bUnknownAutoReject);
289 MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB);
290 MsgSettingRegVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB);
291 MsgSettingRegVconfCBCommon(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, MsgVconfCB);
294 void MsgSettingRemoveVconfCB()
296 MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_BOOL, MsgVconfCB);
297 MsgSettingRemoveVconfCBCommon(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, MsgVconfCB);
298 MsgSettingRemoveVconfCBCommon(VCONFKEY_CONTACTS_SVC_NAME_DISPLAY_ORDER, MsgVconfCB);