Fixed prevent issue
[apps/osp/Gallery.git] / src / GlAlbumInfo.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
9 //
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.
15 //
16
17 /**
18  * @file                GlAlbumInfo.cpp
19  * @brief               This is the implementation file for AlbumInfo class.
20  */
21
22 #include "GlAlbumInfo.h"
23 #include "GlTypes.h"
24
25 using namespace Tizen::Base;
26 using namespace Tizen::Base::Collection;
27 using namespace Tizen::Content;
28 using namespace Tizen::Graphics;
29
30 AlbumInfo::AlbumInfo(void)
31         : __pDirectoryFullPathList(null)
32         , __pContentIdList(null)
33         , __pFolderThumnailBitmap(null)
34 {
35 }
36
37 AlbumInfo::~AlbumInfo(void)
38 {
39         if (__pDirectoryFullPathList != null)
40         {
41                 delete __pDirectoryFullPathList;
42         }
43
44         if (__pContentIdList != null)
45         {
46                 delete __pContentIdList;
47         }
48
49         if (__pFolderThumnailBitmap != null)
50         {
51                 delete __pFolderThumnailBitmap;
52         }
53 }
54
55 String
56 AlbumInfo::GetAlbumName(void) const
57 {
58         String returnValue;
59         if ((__albumName != null) && (__albumName.GetLength() > 0))
60         {
61                 returnValue = __albumName;
62         }
63
64         return returnValue;
65 }
66
67 void
68 AlbumInfo::SetAlbumName(const String& albumName)
69 {
70         if (&albumName == null)
71         {
72                 __albumName = EMPTY_SPACE;
73         }
74         else
75         {
76                 __albumName = String(albumName);
77         }
78 }
79
80 String
81 AlbumInfo::GetDirectory(int index) const
82 {
83         String fullDirPath = *(static_cast<String*>(__pDirectoryFullPathList->GetAt(index)));
84         return fullDirPath;
85 }
86
87 IList*
88 AlbumInfo::GetDirectoryListN(void) const
89 {
90         if (__pDirectoryFullPathList == null)
91         {
92                 return null;
93         }
94
95         IList* pDirectoryFullPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
96
97         IEnumerator* pEnum = __pDirectoryFullPathList->GetEnumeratorN();
98         String* pItem = null;
99         while (pEnum->MoveNext() == E_SUCCESS)
100         {
101                 pItem = new (std::nothrow) String((static_cast<String*>(pEnum->GetCurrent()))->GetPointer());
102                 pDirectoryFullPathList->Add(pItem);
103         }
104         delete pEnum;
105
106         return pDirectoryFullPathList;
107 }
108
109 void
110 AlbumInfo::ClearDirectoryList(void)
111 {
112         if (__pDirectoryFullPathList != null)
113         {
114                 delete __pDirectoryFullPathList;
115         }
116
117         __pDirectoryFullPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
118 }
119
120 void
121 AlbumInfo::AppendDirectory(const String& directoryPath)
122 {
123         if (&directoryPath == null || directoryPath == EMPTY_SPACE)
124         {
125                 return;
126         }
127
128         if (__pDirectoryFullPathList == null)
129         {
130                 __pDirectoryFullPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
131         }
132
133         __pDirectoryFullPathList->Add(new (std::nothrow) String(directoryPath));
134 }
135
136 void
137 AlbumInfo::AppendDirectoryList(const ICollection& directoryList)
138 {
139         if (&directoryList == null || directoryList.GetCount() == 0)
140         {
141                 return;
142         }
143         if (__pDirectoryFullPathList == null)
144         {
145                 __pDirectoryFullPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
146         }
147         IEnumerator* pEnum = directoryList.GetEnumeratorN();
148         String* pItem = null;
149
150         while (pEnum->MoveNext() == E_SUCCESS)
151         {
152                 pItem = new (std::nothrow) String((static_cast<String*>(pEnum->GetCurrent()))->GetPointer());
153                 __pDirectoryFullPathList->Add(pItem);
154         }
155         delete pEnum;
156 }
157
158 int
159 AlbumInfo::GetDirectoryCount(void) const
160 {
161         if (__pDirectoryFullPathList == null)
162         {
163                 return 0;
164         }
165         else
166         {
167                 return __pDirectoryFullPathList->GetCount();
168         }
169 }
170
171 IList*
172 AlbumInfo::GetContentIdListN(void) const
173 {
174         if (__pContentIdList == null)
175         {
176                 return null;
177         }
178
179         IList* pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
180
181         IEnumerator* pEnum = __pContentIdList->GetEnumeratorN();
182         ContentId* pItem;
183         while (pEnum->MoveNext() == E_SUCCESS)
184         {
185                 pItem = new (std::nothrow) ContentId(*static_cast<ContentId*>(pEnum->GetCurrent()));
186                 pContentIdList->Add(pItem);
187         }
188         delete pEnum;
189
190         return pContentIdList;
191 }
192
193 ContentId
194 AlbumInfo::GetContentId(int index) const
195 {
196         ContentId contentId = *(static_cast<ContentId*>(__pContentIdList->GetAt(index)));
197         return contentId;
198 }
199
200 result
201 AlbumInfo::Construct(void)
202 {
203         __albumName = EMPTY_SPACE;
204         __pDirectoryFullPathList = new (std::nothrow) ArrayList(SingleObjectDeleter);
205         __pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
206         result r = E_SUCCESS;
207         if (GetLastResult() != E_SUCCESS || __pDirectoryFullPathList == null || __pContentIdList == null)
208         {
209                 delete __pDirectoryFullPathList;
210                 __pDirectoryFullPathList = null;
211                 delete __pContentIdList;
212                 __pContentIdList = null;
213                 r = E_FAILURE;
214         }
215
216         return r;
217 }
218
219 result
220 AlbumInfo::Construct(const String& albumName, ContentType contentType, const IList& directoryList,
221                 const IList& contentIdList)
222 {
223         if (&albumName == null)
224         {
225                 __albumName = EMPTY_SPACE;
226         }
227         else
228         {
229                 __albumName = albumName;
230         }
231
232         if (&directoryList == null)
233         {
234                 ClearDirectoryList();
235         }
236         else
237         {
238                 ClearDirectoryList();
239                 AppendDirectoryList(directoryList);
240         }
241
242         if (&contentIdList == null)
243         {
244                 ClearContentIdList();
245         }
246         else
247         {
248                 AppendContentIdList(contentIdList);
249         }
250
251         return E_SUCCESS;
252 }
253
254 result
255 AlbumInfo::Construct(const AlbumInfo& albumInfo)
256 {
257         if (&albumInfo == null)
258         {
259                 __albumName = EMPTY_SPACE;
260                 ClearDirectoryList();
261                 ClearContentIdList();
262                 return E_SUCCESS;
263         }
264         __albumName = albumInfo.GetAlbumName();
265
266         ClearDirectoryList();
267         IList* pDirList = albumInfo.GetDirectoryListN();
268         AppendDirectoryList(*pDirList);
269         delete pDirList;
270
271         ClearContentIdList();
272         IList* pContentIdList = albumInfo.GetContentIdListN();
273         AppendContentIdList(*pContentIdList);
274         delete pContentIdList;
275
276         return E_SUCCESS;
277 }
278
279 void
280 AlbumInfo::ClearContentIdList(void)
281 {
282         if (__pContentIdList != null)
283         {
284                 delete __pContentIdList;
285         }
286
287         __pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
288 }
289
290 void
291 AlbumInfo::AppendContentId(const ContentId& contentId)
292 {
293         if (&contentId == null)
294         {
295                 return;
296         }
297
298         if (__pContentIdList == null)
299         {
300                 __pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
301         }
302         ContentId* pItem = new (std::nothrow) ContentId(contentId);
303         __pContentIdList->Add(pItem);
304 }
305
306 void
307 AlbumInfo::AppendContentIdList(const ICollection& contentIdList)
308 {
309         if (&contentIdList == null || contentIdList.GetCount() == 0)
310         {
311                 return;
312         }
313
314         if (__pContentIdList == null)
315         {
316                 __pContentIdList = new (std::nothrow) ArrayList(SingleObjectDeleter);
317         }
318
319         IEnumerator* pEnum = contentIdList.GetEnumeratorN();
320         ContentId* pItem = null;
321
322         while (pEnum->MoveNext() == E_SUCCESS)
323         {
324                 pItem = new (std::nothrow) ContentId(*(static_cast<ContentId*>(pEnum->GetCurrent())));
325                 __pContentIdList->Add(pItem);
326         }
327         delete pEnum;
328 }
329
330 void
331 AlbumInfo::ClearAll(void)
332 {
333         if (__pDirectoryFullPathList != null)
334         {
335                 delete __pDirectoryFullPathList;
336                 __pDirectoryFullPathList = null;
337         }
338
339         if (__pContentIdList != null)
340         {
341                 delete __pContentIdList;
342                 __pContentIdList = null;
343         }
344 }
345
346 int
347 AlbumInfo::GetContentIdCount(void) const
348 {
349         if (__pContentIdList == null)
350         {
351                 return 0;
352         }
353         else
354         {
355                 return __pContentIdList->GetCount();
356         }
357 }
358
359 result
360 AlbumInfo::RemoveContentIdAt(const int index)
361 {
362         result r = E_SUCCESS;
363
364         if (__pContentIdList != null)
365         {
366                 r = __pContentIdList->RemoveAt(index, true);
367         }
368
369         return r;
370 }
371
372 void
373 AlbumInfo::SetFolderThumnailBitmap(Bitmap* pFolderThumnailBitmap)
374 {
375         __pFolderThumnailBitmap = pFolderThumnailBitmap;
376 }
377
378 Bitmap*
379 AlbumInfo::GetFolderThumnailBitmap(void) const
380 {
381         return __pFolderThumnailBitmap;
382 }
383
384 AlbumInfoType
385 AlbumInfo::GetAlbumInfoType(void) const
386 {
387         return ALBUM_INFO_TYPE_FOLDER;
388 }