dbg.h file is removed.
[profile/tv/apps/native/filebrowser.git] / src / data / DirectoryInfo.cpp
1 /*
2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 #include <cstdlib>
18 #include <cstring>
19
20 #include <AppCommon.h>
21 #include "common.h"
22 #include "DirectoryInfo.h"
23
24
25 struct SDirectoryInfo {
26         int nCount;
27
28         filter_h filter;
29         media_folder_h folder;
30 };
31
32
33 bool CDirectoryInfo::Create(CNameInfo::EClassType type)
34 {
35         if (m)
36                 return false;
37
38         m = new SDirectoryInfo;
39         if (!m)
40                 return false;
41
42         if (!CExtNameInfo::Create(CLASS_TYPE_DIRECTORY)) {
43                 delete m;
44                 m = NULL;
45                 return false;
46         }
47
48         return true;
49 }
50
51
52 void CDirectoryInfo::Destroy(void)
53 {
54         if (!m)
55                 return;
56
57         CExtNameInfo::Destroy();
58
59         delete m;
60         m = NULL;
61 }
62
63
64 bool CDirectoryInfo::SetCount(int nCount)
65 {
66         if (!m)
67                 return false;
68
69         m->nCount = nCount;
70
71         return true;
72 }
73
74
75 int CDirectoryInfo::Count(void)
76 {
77         if (!m)
78                 return 0;
79
80         return m->nCount;
81 }
82
83
84 bool CDirectoryInfo::Duplicate(CNameInfo *obj)
85 {
86         if (!m)
87                 return false;
88
89         CDirectoryInfo *dst = (CDirectoryInfo*)obj;
90
91         if (!CExtNameInfo::Duplicate(obj))
92                 return false;
93
94         if (!SetCount(dst->Count()))
95                 return false;
96
97         return true;
98 }
99
100
101 static bool gFolderSize(media_info_h media_h, void *dt)
102 {
103         long long unsigned int size;
104         long long unsigned int *total_size;
105
106         if (!dt)
107                 return false;
108
109         total_size = (long long unsigned int *)dt;
110
111         if (media_info_get_size(media_h, &size) == MEDIA_CONTENT_ERROR_NONE)
112                 *total_size = *total_size + size;
113
114         return true;
115 }
116
117
118 bool CDirectoryInfo::SetLoadInfo(filter_h filter, media_folder_h folder)
119 {
120         if (!m)
121                 return false;
122
123         m->filter = filter;
124         m->folder = folder;
125
126         return true;
127 }
128
129
130 bool CDirectoryInfo::Load(void)
131 {
132         if (!m)
133                 return false;
134
135         int r;
136         bool ret = false;
137         do {
138                 char* str;
139                 r = media_folder_get_name(m->folder, &str);
140                 if (r != MEDIA_CONTENT_ERROR_NONE) {
141                         _ERR("Media folder get name failed");
142                         break;
143                 }
144                 SetName(str);
145                 free(str);
146
147                 r = media_folder_get_path(m->folder, &str);
148                 if (r != MEDIA_CONTENT_ERROR_NONE) {
149                         _ERR("Media folder get path failed");
150                         break;
151                 }
152                 SetPath(str);
153                 free(str);
154
155                 r = media_folder_get_folder_id(m->folder, &str);
156                 if (r != MEDIA_CONTENT_ERROR_NONE) {
157                         _ERR("Media folder get id failed");
158                         break;
159                 }
160                 SetId(str);
161                 free(str);
162
163                 int count = 0;
164                 r = media_folder_get_media_count_from_db(Id(), m->filter, &count);
165                 if (r != MEDIA_CONTENT_ERROR_NONE) {
166                         _ERR("Media folder get id failed");
167                         break;
168                 }
169                 SetCount(count);
170
171                 SetType(E_GRP_FOLDER);
172
173                 TTime time;
174                 r = media_folder_get_modified_time(m->folder, &time);
175                 if (r != MEDIA_CONTENT_ERROR_NONE) {
176                         _ERR("Media folder get mod time failed");
177                         break;
178                 }
179                 SetModifiedTime(time);
180
181                 TSize size;
182                 r = media_folder_foreach_media_from_db(Id(), m->filter, gFolderSize, &size);
183                 if (r != MEDIA_CONTENT_ERROR_NONE) {
184                         _ERR("Media folder get size failed");
185                         break;
186                 }
187
188                 SetSize(size);
189
190                 ret = true;
191         } while (0);
192
193         return ret;
194 }