wrt-plugins-tizen_0.4.23
[framework/web/wrt-plugins-tizen.git] / src / Notification / NotificationLine.cpp
1 //
2 // Tizen Web Device API
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 #include "NotificationLine.h"
19 #include <Commons/Exception.h>
20
21 namespace DeviceAPI {
22 namespace Notification {
23
24 NotificationLine::NotificationLine() :
25 m_notiHandle(NULL),
26 m_index(-1)
27 {
28         LoggerD("created by constructor");
29 }
30
31 NotificationLine::~NotificationLine()
32 {
33 }
34
35 NotificationLine::NotificationLine(notification_h noti, int index):
36 m_notiHandle(noti),
37 m_index(index)
38 {
39         LoggerD("create by notification");
40 }
41
42 NotificationLine::NotificationLine(notification_h noti, int index, std::string &info, std::string &subInfo):
43 m_info(info),
44 m_subInfo(subInfo),
45 m_notiHandle(noti),
46 m_index(index)
47 {
48         LoggerD("create by notification with data" );
49 }
50
51 std::string NotificationLine::getInformation() const
52 {
53         //return m_info;
54         if (m_notiHandle && m_index >= 0)
55         {
56                 LoggerD("index = " << m_index);
57                 int index = m_index;
58                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
59                 switch (index)
60                 {
61                         case 0:
62                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
63                                 break;
64                         case 1:
65                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
66                                 break;
67                         case 2:
68                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
69                                 break;
70                         default :
71                                 type = NOTIFICATION_TEXT_TYPE_NONE;
72                 }
73                 
74                 char *info = NULL;
75                         
76                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &info) != NOTIFICATION_ERROR_NONE)
77                 {
78                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification information error");
79                 }
80
81                 std::string strInfo;
82                 if (info)
83                         strInfo = info;         
84                 LoggerD(" info " << strInfo);
85
86                 return strInfo;
87         }
88         else
89         {
90                 return m_info;
91         }
92
93 }
94
95 void NotificationLine::setInformation(const std::string &info)
96 {
97         if (m_notiHandle && m_index >= 0)
98         {
99                 int idx = m_index;
100                 LoggerD(" index : " << idx);
101                 LoggerD(" info : " << info);
102                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
103                 
104                 switch (idx)
105                 {
106                         case 0:
107                                 type = NOTIFICATION_TEXT_TYPE_INFO_1;
108                                 break;
109                         case 1:
110                                 type = NOTIFICATION_TEXT_TYPE_INFO_2;
111                                 break;
112                         case 2:
113                                 type = NOTIFICATION_TEXT_TYPE_INFO_3;
114                                 break;
115                         default :
116                                 type = NOTIFICATION_TEXT_TYPE_NONE;
117                 }
118
119                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
120                 {
121                         if (getInformation().compare(info))
122                         {
123                                 if (notification_set_text(m_notiHandle, type, info.c_str(),
124                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
125                                 {
126                                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
127                                 }
128                                 setUpdatedFlag(true);
129                         }
130                 }
131         }
132         else
133         {
134                 m_info = info;
135         }
136 }
137
138 std::string NotificationLine::getSubInformation() const
139 {
140         //return m_subInfo;
141         if (m_notiHandle && m_index >= 0)
142         {
143                 int index = m_index;
144                 LoggerD(" index : " << index);
145
146                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
147                 switch (index)
148                 {
149                         case 0:
150                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
151                                 break;
152                         case 1:
153                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
154                                 break;
155                         case 2:
156                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
157                                 break;
158                         default :
159                                 type = NOTIFICATION_TEXT_TYPE_NONE;
160                 }
161                                 
162                 char *subInfo = NULL;
163                 
164                 if (NOTIFICATION_TEXT_TYPE_NONE != type && notification_get_text(m_notiHandle, type, &subInfo) != NOTIFICATION_ERROR_NONE)
165                 {
166                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "get notification sub information error");
167                 }
168
169                 std::string strSubInfo;
170                 if (subInfo)
171                         strSubInfo = subInfo;
172                 LoggerD(" sub info " << strSubInfo);
173                 return strSubInfo;
174
175         }
176         else
177         {
178                 return m_subInfo;
179         }
180 }
181
182 void NotificationLine::setSubInformation(const std::string &subInfo)
183 {
184         if (m_notiHandle && m_index >= 0)
185         {
186                 int idx = m_index;
187                 LoggerD(" index : " << idx);
188                 LoggerD(" input value : " << subInfo);
189                 notification_text_type_e type = NOTIFICATION_TEXT_TYPE_NONE; 
190                 
191                 switch (idx)
192                 {
193                         case 0:
194                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_1;
195                                 break;
196                         case 1:
197                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_2;
198                                 break;
199                         case 2:
200                                 type = NOTIFICATION_TEXT_TYPE_INFO_SUB_3;
201                                 break;
202                         default :
203                                 type = NOTIFICATION_TEXT_TYPE_NONE;
204                 }
205
206                 if ( type != NOTIFICATION_TEXT_TYPE_NONE)
207                 {
208                         if (getSubInformation().compare(subInfo))
209                         {
210                                 if (notification_set_text(m_notiHandle, type, subInfo.c_str(),
211                                         NULL, NOTIFICATION_VARIABLE_TYPE_NONE) != NOTIFICATION_ERROR_NONE)
212                                 {
213                                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "set notification sound error");
214                                 }
215                                 setUpdatedFlag(true);
216                         }
217                 }
218         }
219         else
220         {
221                 m_subInfo = subInfo;
222         }
223 }
224
225 void NotificationLine::setUpdatedFlag(bool flag)
226 {
227         m_updated = flag;
228 }
229
230 bool NotificationLine::getUpdatedFlag()
231 {
232         return m_updated; 
233 }
234
235 } // Notification
236 } // DeviceAPI