update tizen source
[framework/messaging/msg-service.git] / utils / MsgGconfWrapper.cpp
1 /*
2 *
3 * Copyright (c) 2000-2012 Samsung Electronics Co., Ltd. All Rights Reserved.
4 *
5 * This file is part of msg-service.
6 *
7 * Contact: Jaeyun Jeong <jyjeong@samsung.com>
8 *          Sangkoo Kim <sangkoo.kim@samsung.com>
9 *          Seunghwan Lee <sh.cat.lee@samsung.com>
10 *          SoonMin Jung <sm0415.jung@samsung.com>
11 *          Jae-Young Lee <jy4710.lee@samsung.com>
12 *          KeeBum Kim <keebum.kim@samsung.com>
13 *
14 * PROPRIETARY/CONFIDENTIAL
15 *
16 * This software is the confidential and proprietary information of
17 * SAMSUNG ELECTRONICS ("Confidential Information"). You shall not
18 * disclose such Confidential Information and shall use it only in
19 * accordance with the terms of the license agreement you entered
20 * into with SAMSUNG ELECTRONICS.
21 *
22 * SAMSUNG make no representations or warranties about the suitability
23 * of the software, either express or implied, including but not limited
24 * to the implied warranties of merchantability, fitness for a particular
25 * purpose, or non-infringement. SAMSUNG shall not be liable for any
26 * damages suffered by licensee as a result of using, modifying or
27 * distributing this software or its derivatives.
28 *
29 */
30
31 #include <stdio.h>
32
33 #include <pmapi.h>
34
35 #include "MsgDebug.h"
36 #include "MsgUtilStorage.h"
37 #include "MsgGconfWrapper.h"
38
39
40 /*==================================================================================================
41                                      DEFINES
42 ==================================================================================================*/
43 #define MSG_UNREAD_CNT          "db/badge/org.tizen.message"
44
45
46 /*==================================================================================================
47                                      FUNCTION IMPLEMENTATION
48 ==================================================================================================*/
49 MSG_ERROR_T MsgSettingSetString(const char *pKey, const char *pSetValue)
50 {
51         if (pKey == NULL || pSetValue == NULL)
52         {
53                 MSG_DEBUG("IN Parameter is NULL");
54                 return MSG_ERR_NULL_POINTER;
55         }
56
57         if (vconf_set_str(pKey, pSetValue) != 0)
58                 return MSG_ERR_SET_SETTING;
59
60         return MSG_SUCCESS;
61 }
62
63
64 MSG_ERROR_T MsgSettingSetInt(const char *pKey, int nSetValue)
65 {
66         if (pKey == NULL)
67         {
68                 MSG_DEBUG("IN Parameter is NULL");
69                 return MSG_ERR_NULL_POINTER;
70         }
71
72         if (vconf_set_int(pKey, nSetValue) != 0)
73                 return MSG_ERR_SET_SETTING;
74
75         return MSG_SUCCESS;
76 }
77
78
79 MSG_ERROR_T MsgSettingSetBool(const char *pKey, bool bSetValue)
80 {
81         if (pKey == NULL)
82         {
83                 MSG_DEBUG("IN Parameter is NULL");
84                 return MSG_ERR_NULL_POINTER;
85         }
86
87         if (vconf_set_bool(pKey, bSetValue) != 0)
88                 return MSG_ERR_SET_SETTING;
89
90         return MSG_SUCCESS;
91 }
92
93
94 char* MsgSettingGetString(const char *pKey)
95 {
96         if (pKey == NULL)
97         {
98                 MSG_DEBUG("IN Parameter is NULL");
99                 return NULL;
100         }
101
102         return vconf_get_str(pKey);
103 }
104
105
106 int MsgSettingGetInt(const char *pKey)
107 {
108         if (pKey == NULL)
109         {
110                 MSG_DEBUG("IN Parameter is NULL");
111                 return -1;
112         }
113
114         int retVal = 0;
115
116         if (vconf_get_int(pKey, &retVal) < 0)
117                 return -1;
118
119         return retVal;
120 }
121
122
123 int MsgSettingGetBool(const char *pKey, bool *pVal)
124 {
125         if (pKey == NULL)
126         {
127                 MSG_DEBUG("IN Parameter is NULL");
128                 return -1;
129         }
130
131         int retVal = 0, param = 0;
132
133         if (vconf_get_bool(pKey, &param) < 0)
134                 return -1;
135
136         *pVal = (bool)param;
137
138         return retVal;
139 }
140
141
142 MSG_ERROR_T MsgSettingHandleNewMsg(int SmsCnt, int MmsCnt)
143 {
144         MSG_BEGIN();
145
146         MSG_DEBUG("smsCnt = %d, mmsCnt = %d ##", SmsCnt, MmsCnt);
147
148         // Set Msg Count into VConf
149         if (MsgSettingSetIndicator(SmsCnt, MmsCnt) != MSG_SUCCESS)
150         {
151                 MSG_DEBUG("MsgSettingSetIndicator() FAILED");
152                 return MSG_ERR_SET_SETTING;
153         }
154
155         if (SmsCnt == 0 && MmsCnt == 0)
156         {
157                 MSG_DEBUG("No New Message.");
158         }
159         else
160         {
161                 MSG_DEBUG("New Message.");
162                 pm_change_state(LCD_NORMAL);
163         }
164
165         MSG_END();
166
167         return MSG_SUCCESS;
168 }
169
170
171 MSG_ERROR_T MsgSettingSetIndicator(int SmsCnt, int MmsCnt)
172 {
173
174         if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_SMS_STATE, SmsCnt) != 0)
175                 return MSG_ERR_SET_SETTING;
176         if (MsgSettingSetInt(VCONFKEY_MESSAGE_RECV_MMS_STATE, MmsCnt) != 0)
177                 return MSG_ERR_SET_SETTING;
178
179         int sumCnt = SmsCnt + MmsCnt;
180
181         if (MsgSettingSetInt(MSG_UNREAD_CNT, sumCnt) != 0)
182                 return MSG_ERR_SET_SETTING;
183
184         return MSG_SUCCESS;
185 }