Update privilege string, PackageAppInfo for wgt
[platform/framework/native/appfw.git] / src / app / FApp_NotificationMessageImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FApp_NotificationMessageImpl.cpp
20  * @brief               This is the placeholder for _NotificationMessageImpl class.
21  */
22
23 #include <FBaseBoolean.h>
24 #include <FBaseInteger.h>
25 #include <FBaseSysLog.h>
26 #include <FIoFile.h>
27 #include <FAppNotificationManager.h>
28 #include <FAppNotificationMessage.h>
29
30 #include <FBaseInternalTypes.h>
31 #include "FApp_NotificationMessageImpl.h"
32
33
34 using namespace Tizen::Base;
35 using namespace Tizen::Io;
36
37 namespace Tizen { namespace App
38 {
39
40 _NotificationMessageImpl::_NotificationMessageImpl(bool appBinding)
41         : __appBinding(true)
42         , __badgeNumber(-1)
43         , __badgeOffset(0)
44         , __progressValue(-1)
45         , __activityType(ONGOING_ACTIVITY_TYPE_TEXT)
46 {
47 }
48
49 _NotificationMessageImpl::_NotificationMessageImpl(const _NotificationMessageImpl& notificationMessage)
50         : __appBinding(notificationMessage.__appBinding)
51         , __badgeNumber(notificationMessage.__badgeNumber)
52         , __badgeOffset(notificationMessage.__badgeOffset)
53         , __progressValue(notificationMessage.__progressValue)
54         , __activityType(notificationMessage.__activityType)
55         , __alertText(notificationMessage.__alertText)
56         , __appMessage(notificationMessage.__appMessage)
57         , __titleText(notificationMessage.__titleText)
58         , __iconFilePath(notificationMessage.__iconFilePath)
59         , __soundFilePath(notificationMessage.__soundFilePath)
60 {
61 }
62
63 _NotificationMessageImpl::~_NotificationMessageImpl()
64 {
65 }
66
67 _NotificationMessageImpl&
68 _NotificationMessageImpl::operator =(const _NotificationMessageImpl& notificationMessage)
69 {
70         if (this != &notificationMessage)
71         {
72                 __appBinding = notificationMessage.__appBinding;
73                 __badgeNumber = notificationMessage.__badgeNumber;
74                 __badgeOffset = notificationMessage.__badgeOffset;
75                 __progressValue = notificationMessage.__progressValue;
76                 __activityType = notificationMessage.__activityType;
77                 __alertText = notificationMessage.__alertText;
78                 __appMessage = notificationMessage.__appMessage;
79                 __titleText = notificationMessage.__titleText;
80                 __iconFilePath = notificationMessage.__iconFilePath;
81                 __soundFilePath = notificationMessage.__soundFilePath;
82         }
83         return *this;
84 }
85
86 bool
87 _NotificationMessageImpl::Equals(const Object& rhs) const
88 {
89         const NotificationMessage* pMsg = dynamic_cast<const NotificationMessage*>(&rhs);
90         if (pMsg == null)
91         {
92                 return false;
93         }
94
95         const _NotificationMessageImpl* pMsgImpl = pMsg->__pNotificationMessageImpl;
96         if (pMsgImpl == this)
97         {
98                 return true;
99         }
100
101         if (__appBinding != pMsgImpl->__appBinding)
102         {
103                 return false;
104         }
105
106         if (__badgeNumber != pMsgImpl->__badgeNumber)
107         {
108                 return false;
109         }
110
111         if (__badgeOffset != pMsgImpl->__badgeOffset)
112         {
113                 return false;
114         }
115
116         if (__progressValue != pMsgImpl->__progressValue)
117         {
118                 return false;
119         }
120
121         if (__activityType != pMsgImpl->__activityType)
122         {
123                 return false;
124         }
125
126         if (GetHashCode() != pMsgImpl->GetHashCode())
127         {
128                 return false;
129         }
130
131         if (__alertText != pMsgImpl->__alertText)
132         {
133                 return false;
134         }
135
136         if (__appMessage != pMsgImpl->__appMessage)
137         {
138                 return false;
139         }
140
141         if (__titleText != pMsgImpl->__titleText)
142         {
143                 return false;
144         }
145
146         if (__iconFilePath != pMsgImpl->__iconFilePath)
147         {
148                 return false;
149         }
150
151         if (__soundFilePath != __soundFilePath)
152         {
153                 return false;
154         }
155
156         return true;
157 }
158
159 int
160 _NotificationMessageImpl::GetHashCode(void) const
161 {
162         return Boolean(__appBinding).GetHashCode()
163                 ^ Integer(__badgeNumber).GetHashCode()
164                 ^ Integer(__badgeOffset).GetHashCode()
165                 ^ Integer(__progressValue).GetHashCode()
166                 ^ Integer(__activityType).GetHashCode()
167                 ^ __alertText.GetHashCode()
168                 ^ __appMessage.GetHashCode()
169                 ^ __titleText.GetHashCode()
170                 ^ __iconFilePath.GetHashCode()
171                 ^ __soundFilePath.GetHashCode();
172 }
173
174 int
175 _NotificationMessageImpl::GetBadgeNumber(void) const
176 {
177         return __badgeNumber;
178 }
179
180 result
181 _NotificationMessageImpl::SetBadgeNumber(int badgeNumber)
182 {
183         result r = E_SUCCESS;
184         SysTryReturnResult(NID_APP, badgeNumber >= 0 && badgeNumber <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
185                                           "BadgeNumber is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
186
187         __badgeOffset = 0;
188         __badgeNumber = badgeNumber;
189         return r;
190 }
191
192 int
193 _NotificationMessageImpl::GetBadgeOffset() const
194 {
195         return __badgeOffset;
196 }
197
198 result
199 _NotificationMessageImpl::SetBadgeOffset(int badgeOffset)
200 {
201         result r = E_SUCCESS;
202         SysTryReturnResult(NID_APP, badgeOffset >= 0 && badgeOffset <= MAX_NOTIFICATION_BADGE_NUMBER, E_INVALID_ARG,
203                                           "BadgeOffset is less than 0 or greater than MAX_NOTIFICATION_BADGE_NUMBER.");
204
205         __badgeNumber = -1;
206         __badgeOffset = badgeOffset;
207         return r;
208 }
209
210 String
211 _NotificationMessageImpl::GetAlertText() const
212 {
213         return __alertText;
214 }
215
216 result
217 _NotificationMessageImpl::SetAlertText(const String& alertText)
218 {
219         result r = E_SUCCESS;
220         SysTryReturnResult(NID_APP, alertText.GetLength() > 0 && alertText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
221                                                   "AlertText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
222
223         __alertText = alertText;
224         return r;
225 }
226
227 String
228 _NotificationMessageImpl::GetAppMessage() const
229 {
230         return __appMessage;
231 }
232
233
234 result
235 _NotificationMessageImpl::SetAppMessage(const String& appMessage)
236 {
237         result r = E_SUCCESS;
238         SysTryReturnResult(NID_APP, appMessage.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
239                                                           "AppMessage is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
240         SysTryReturnResult(NID_APP, __appBinding, E_INVALID_OPERATION,
241                                                   "The Notification instance is not bound to Application");
242
243         __appMessage = appMessage;
244         return r;
245 }
246
247 String
248 _NotificationMessageImpl::GetTitleText() const
249 {
250         return __titleText;
251 }
252
253 result
254 _NotificationMessageImpl::SetTitleText(const String& titleText)
255 {
256         result r = E_SUCCESS;
257         SysTryReturnResult(NID_APP, titleText.GetLength() <= MAX_NOTIFICATION_MESSAGE_LENGTH, E_INVALID_ARG,
258                                                                   "TitleText is greater than MAX_NOTIFICATION_MESSAGE_LENGTH.");
259         __titleText = titleText;
260         return r;
261 }
262
263 String
264 _NotificationMessageImpl::GetIconFilePath() const
265 {
266         return __iconFilePath;
267 }
268
269 result
270 _NotificationMessageImpl::SetIconFilePath(const String& iconFilePath)
271 {
272         result r = E_SUCCESS;
273         bool isExist = false;
274
275         isExist = File::IsFileExist(iconFilePath);
276         SysTryReturnResult(NID_APP, isExist, E_INVALID_ARG,"The Specified File is Invalid");
277
278         __iconFilePath = iconFilePath;
279         return r;
280 }
281
282 String
283 _NotificationMessageImpl::GetSoundFilePath() const
284 {
285         return __soundFilePath;
286 }
287
288 result
289 _NotificationMessageImpl::SetSoundFilePath(const String& soundFilePath)
290 {
291         result r = E_SUCCESS;
292         bool isExist = false;
293
294         isExist = File::IsFileExist(soundFilePath);
295         SysTryReturnResult(NID_APP, isExist, E_INVALID_ARG,"The Specified File is Invalid");
296
297         __soundFilePath = soundFilePath;
298         return r;
299 }
300
301 OngoingActivityType
302 _NotificationMessageImpl::GetOngoingActivityType() const
303 {
304         return __activityType;
305 }
306
307 result
308 _NotificationMessageImpl::SetOngoingActivityType(OngoingActivityType activityType)
309 {
310         result r = E_SUCCESS;
311
312         // to prevent weired gcc optimization for enum type
313         int type = static_cast<int>(activityType);
314
315         switch (type)
316         {
317         case ONGOING_ACTIVITY_TYPE_TEXT:
318                 break;
319         case ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE:
320                 SysTryReturnResult(NID_APP, __progressValue == -1 || (__progressValue >= 0 && __progressValue <= 100), E_INVALID_STATE, "Incompatible progress value %d.", __progressValue);
321                 break;
322         case ONGOING_ACTIVITY_TYPE_PROGRESS_BYTE:
323                 break;
324         default:
325                 SetLastResult(E_INVALID_STATE);
326                 SysLogException(NID_APP, E_INVALID_STATE, "Invalid activity type %d.", type);
327                 return E_INVALID_STATE;
328         }
329
330         __activityType = activityType;
331         return r;
332 }
333
334 int
335 _NotificationMessageImpl::GetOngoingActivityProgressValue() const
336 {
337         return __progressValue;
338 }
339
340 result
341 _NotificationMessageImpl::SetOngoingActivityProgressValue(int progressValue)
342 {
343         result r = E_SUCCESS;
344         SysTryReturnResult(NID_APP, progressValue >= 0, E_INVALID_ARG,"The progress value is less than 0");
345
346         // use int type instead of OngoingActivityType to evade weired gcc optimization
347         int activitytype = static_cast<int>(GetOngoingActivityType());
348         SysTryReturnResult(NID_APP, activitytype > ONGOING_ACTIVITY_TYPE_TEXT && activitytype <= ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE,
349                         E_INVALID_STATE,"Invalid activity Type %d.", activitytype);
350
351         if (activitytype == ONGOING_ACTIVITY_TYPE_PROGRESS_PERCENTAGE)
352         {
353                 SysTryReturnResult(NID_APP, progressValue <= 100, E_INVALID_ARG,"Invalid Progress value");
354         }
355         __progressValue = progressValue;
356         return r;
357 }
358
359 bool
360 _NotificationMessageImpl::IsAppBinding()const
361 {
362         return __appBinding;
363 }
364
365 };
366 };    // Tizen::App