Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / FUi_ClipboardImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 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                FUi_ClipboardImpl.cpp
20  * @brief               This is the implementation file for the _ClipboardImpl class.
21  */
22
23 #include <FUiClipboard.h>
24 #include <FUiClipboardItem.h>
25 #include <FUiIClipboardPopupEventListener.h>
26 #include <FBaseColLinkedList.h>
27 #include <FBaseResult.h>
28 #include <FBaseSysLog.h>
29 #include "FUi_ClipboardImpl.h"
30 #include "FUi_Clipboard.h"
31 #include "FUi_ClipboardItemImpl.h"
32 #include "FUi_ClipboardItem.h"
33
34 using namespace Tizen::Base::Collection;
35
36 namespace Tizen { namespace Ui
37 {
38
39 _ClipboardImpl*
40 _ClipboardImpl::CreateInstanceN(void)
41 {
42         _ClipboardImpl* pClipboardImpl = new (std::nothrow) _ClipboardImpl;
43         SysTryReturn(NID_UI, pClipboardImpl, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
44
45         SetLastResult(E_SUCCESS);
46
47         return pClipboardImpl;
48 }
49
50 _ClipboardImpl::~_ClipboardImpl(void)
51 {
52 }
53
54 _Clipboard*
55 _ClipboardImpl::GetCore(void)
56 {
57         return _Clipboard::GetInstance();
58 }
59
60 const _Clipboard*
61 _ClipboardImpl::GetCore(void) const
62 {
63         return _Clipboard::GetInstance();
64 }
65
66 result
67 _ClipboardImpl::CopyItem(const _ClipboardItemImpl& item)
68 {
69         SysAssert(GetCore());
70
71         result r = GetCore()->CopyItem(item.GetCore());
72
73         if ((r == E_INVALID_ARG) || (r == E_SYSTEM))
74         {
75                 SysLogException(NID_UI, r, "[%s] Propagating.", GetErrorMessage(r));
76         }
77         else if (r != E_SUCCESS)
78         {
79                 r = E_SYSTEM;
80                 SysLogException(NID_UI, r, "[E_SYSTEM] A system error occurred.");
81         }
82
83         return r;
84 }
85
86 Tizen::Base::Collection::IList*
87 _ClipboardImpl::RetrieveItemsN(unsigned long dataTypes)
88 {
89         SysTryReturn(NID_UI, IsValidDataType(dataTypes), null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The item of the specified data types is not found.");
90         SysAssert(GetCore());
91
92         // Get items from _Clipboard.
93         IList* pRetrievedList = GetCore()->RetrieveItemsN(dataTypes);
94         result r = GetLastResult();
95
96         if ((r == E_OBJ_NOT_FOUND) || (r == E_OUT_OF_MEMORY) || (r == E_SYSTEM))
97         {
98                 SysLogException(NID_UI, r, "[%s] Propagating.", GetErrorMessage(r));
99                 return null;
100         }
101
102         SysTryReturn(NID_UI, r == E_SUCCESS, null, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
103
104         IEnumerator* pEnumerator = null;
105         _ClipboardItem* pItemCore = null;
106         ClipboardItem* pItem = null;
107
108         // Make lists.
109         LinkedList* pList = new (std::nothrow) LinkedList;
110         SysTryCatch(NID_UI, pList, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
111
112         pEnumerator = pRetrievedList->GetEnumeratorN();
113         r = GetLastResult();
114         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
115
116         while (pEnumerator->MoveNext() == E_SUCCESS)
117         {
118                 // [ToDo] Use a template list.
119                 pItemCore = dynamic_cast<_ClipboardItem*>(pEnumerator->GetCurrent());
120                 if (pItemCore)
121                 {
122                         pItem = new (std::nothrow) ClipboardItem;
123                         SysTryCatch(NID_UI, pItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
124
125                         r = pItem->Construct(pItemCore->GetDataType(), *(pItemCore->GetData()));
126                         if (r != E_SUCCESS)
127                         {
128                                 delete pItem;
129                                 SysLogException(NID_UI, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
130                                 goto CATCH;
131                         }
132
133                         r = pList->Add(*pItem);
134                         if (r != E_SUCCESS)
135                         {
136                                 delete pItem;
137                                 SysLogException(NID_UI, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
138                                 goto CATCH;
139                         }
140                 }
141         }
142
143         delete pEnumerator;
144
145         pRetrievedList->RemoveAll(true);
146         delete pRetrievedList;
147
148         SetLastResult(E_SUCCESS);
149
150         return pList;
151
152 CATCH:
153         pRetrievedList->RemoveAll(true);
154         delete pRetrievedList;
155
156         if (pList)
157         {
158                 pList->RemoveAll(true);
159                 delete pList;
160         }
161
162         if (pEnumerator)
163         {
164                 delete pEnumerator;
165         }
166
167         return null;
168 }
169
170 _ClipboardItemImpl*
171 _ClipboardImpl::RetrieveLatestItemN(unsigned long dataTypes)
172 {
173         SysTryReturn(NID_UI, IsValidDataType(dataTypes), null, E_OBJ_NOT_FOUND, "[E_OBJ_NOT_FOUND] The item of the specified data types is not found.");
174         SysAssert(GetCore());
175
176         const _ClipboardItem* pItemCore = GetCore()->RetrieveLatestItemN(dataTypes);
177         result r = GetLastResult();
178
179         ClipboardItem* pItem = null;
180         _ClipboardItemImpl* pItemImpl = null;
181
182         if ((r == E_OBJ_NOT_FOUND) || (r == E_OUT_OF_MEMORY) || (r == E_SYSTEM))
183         {
184                 SysLogException(NID_UI, r, "[%s] Propagating.", GetErrorMessage(r));
185                 goto CATCH;
186         }
187         else if (r != E_SUCCESS)
188         {
189                 SysLogException(NID_UI, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
190                 goto CATCH;
191         }
192
193         pItem = new (std::nothrow) ClipboardItem;
194         SysTryCatch(NID_UI, pItem, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory is insufficient.");
195
196         r = pItem->Construct(pItemCore->GetDataType(), *(pItemCore->GetData()));
197         SysTryCatch(NID_UI, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error occurred.");
198
199         delete pItemCore;
200
201         pItemImpl = _ClipboardItemImpl::GetInstance(*pItem);
202
203         SetLastResult(E_SUCCESS);
204
205         return pItemImpl;
206
207 CATCH:
208         if (pItemCore)
209         {
210                 delete pItemCore;
211         }
212
213         if (pItem)
214         {
215                 delete pItem;
216         }
217
218         return null;
219 }
220
221 result
222 _ClipboardImpl::ShowPopup(unsigned long dataTypes, const IClipboardPopupEventListener& listener)
223 {
224         SysTryReturn(NID_UI, IsValidDataType(dataTypes), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
225         SysTryReturn(NID_UI, GetCore(), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
226
227         result r = GetCore()->ShowPopup(dataTypes, listener);
228
229         if ((r == E_INVALID_OPERATION) || (r == E_SYSTEM))
230         {
231                 SysLogException(NID_UI, r, "[%s] Propagating.", GetErrorMessage(r));
232         }
233         else if (r != E_SUCCESS)
234         {
235                 r = E_SYSTEM;
236                 SysLogException(NID_UI, r, "[E_SYSTEM] A system error occurred.");
237         }
238
239         return r;
240 }
241
242 result
243 _ClipboardImpl::HidePopup(void)
244 {
245         SysTryReturn(NID_UI, GetCore(), E_SYSTEM, E_SYSTEM, "[E_SYSTEM] A system error occurred.");
246
247         result r = GetCore()->HidePopup();
248
249         if ((r == E_INVALID_OPERATION) || (r == E_SYSTEM))
250         {
251                 SysLogException(NID_UI, r, "[%s] Propagating.", GetErrorMessage(r));
252         }
253         else if (r != E_SUCCESS)
254         {
255                 r = E_SYSTEM;
256                 SysLogException(NID_UI, r, "[E_SYSTEM] A system error occurred.");
257         }
258
259         return r;
260 }
261
262 bool
263 _ClipboardImpl::IsPopupVisible(void)
264 {
265         if (GetCore() == null)
266         {
267                 return false;
268         }
269
270         return GetCore()->IsPopupVisible();
271 }
272
273 _ClipboardImpl*
274 _ClipboardImpl::GetInstance(Clipboard& clipboard)
275 {
276         return clipboard.__pClipboardImpl;
277 }
278
279 const _ClipboardImpl*
280 _ClipboardImpl::GetInstance(const Clipboard& clipboard)
281 {
282         return clipboard.__pClipboardImpl;
283 }
284
285 bool
286 _ClipboardImpl::IsValidDataType(unsigned long dataTypes)
287 {
288         return ((CLIPBOARD_DATA_TYPE_TEXT & dataTypes) ||
289                 (CLIPBOARD_DATA_TYPE_HTML & dataTypes) ||
290                 (CLIPBOARD_DATA_TYPE_IMAGE & dataTypes) ||
291                 (CLIPBOARD_DATA_TYPE_VIDEO & dataTypes) ||
292                 (CLIPBOARD_DATA_TYPE_AUDIO & dataTypes));
293 }
294
295 _ClipboardImpl::_ClipboardImpl(void)
296 {
297 }
298
299 }} // Tizen::Ui