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