Apply ASSERT
[profile/tv/apps/native/filebrowser.git] / src / data / FileInfo.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 <stdlib.h>
18 #include <string.h>
19 #include "dbg.h"
20 #include "i18n.h"
21 #include "common.h"
22 #include <media_content.h>
23
24 #include "ExtNameInfo.h"
25 #include "FileInfo.h"
26
27
28 struct SFileInfo {
29         media_info_h handle;
30 };
31
32
33 bool CFileInfo::Create(void)
34 {
35         ASSERT(!m);
36
37         m = new SFileInfo;
38         ASSERT(m);
39
40         memset(m, 0, sizeof(SFileInfo));
41
42         if (!CExtNameInfo::Create(CExtNameInfo::CLASS_TYPE_FILE)) {
43                 delete m;
44                 m = NULL;
45                 return false;
46         }
47
48         return true;
49 }
50
51
52 void CFileInfo::Destroy(void)
53 {
54         ASSERT(m);
55
56         CExtNameInfo::Destroy();
57
58         delete m;
59         m = NULL;
60 }
61
62
63 groups gType(media_content_type_e type)
64 {
65         groups ret = E_GRP_OTHER;
66
67         switch (type) {
68         case MEDIA_CONTENT_TYPE_IMAGE:
69                 ret = E_GRP_PHOTO;
70                 break;
71
72         case MEDIA_CONTENT_TYPE_VIDEO:
73                 ret = E_GRP_VIDEO;
74                 break;
75         case MEDIA_CONTENT_TYPE_MUSIC:
76                 ret = E_GRP_MUSIC;
77                 break;
78         default:
79                 ret = E_GRP_OTHER;
80                 break;
81         }
82
83         return ret;
84 }
85
86
87 bool CFileInfo::Duplicate(CNameInfo* obj)
88 {
89         ASSERT(m);
90
91         if (!CExtNameInfo::Duplicate(obj))
92                 return false;
93
94         return true;
95 }
96
97
98 bool CFileInfo::SetLoadInfo(media_info_h handle)
99 {
100         ASSERT(m);
101
102         m->handle = handle;
103         return true;
104 }
105
106 bool CFileInfo::Load(void)
107 {
108         ASSERT(m);
109
110         bool ret = false;
111         do {
112                 char* str;
113                 if (media_info_get_media_id(m->handle, &str) != MEDIA_CONTENT_ERROR_NONE) {
114                         _ERR("media ID Fetch error");
115                         break;
116                 }
117                 SetId(str);
118                 free(str);
119
120                 if (media_info_get_title(m->handle, &str) != MEDIA_CONTENT_ERROR_NONE) {
121                         _ERR("media name Fetch error");
122                         break;
123                 }
124                 SetName(str);
125                 free(str);
126
127                 media_content_type_e ctype;
128                 if (media_info_get_media_type(m->handle, &ctype) != MEDIA_CONTENT_ERROR_NONE) {
129                         _ERR("media type Fetch error");
130                         break;
131                 }
132                 SetType(gType(ctype));
133
134                 TSize size;
135                 if (media_info_get_size(m->handle, &size) != MEDIA_CONTENT_ERROR_NONE) {
136                         _ERR("media size Fetch error");
137                         break;
138                 }
139                 SetSize(size);
140
141                 if (media_info_get_file_path(m->handle, &str) != MEDIA_CONTENT_ERROR_NONE) {
142                         _ERR("media file path Fetch error");
143                         break;
144                 }
145                 SetPath(str);
146                 free(str);
147
148                 if (media_info_get_thumbnail_path(m->handle, &str) != MEDIA_CONTENT_ERROR_NONE) {
149                         _ERR("media thumb Fetch error");
150                         break;
151                 }
152                 if(str == NULL)
153                 {
154                         _ERR("Fail to get string by media_info_get_thumbnail_path");
155                         //break;
156                 }
157                 else
158                 {
159                         SetThumbnailPath(str);
160                         free(str);
161                 }
162
163                 TTime time;
164                 if (media_info_get_modified_time(m->handle, &time) != MEDIA_CONTENT_ERROR_NONE) {
165                         _ERR("media mod time Fetch error");
166                         break;
167                 }
168                 SetModifiedTime(time);
169
170                 ret = true;
171         } while (0);
172
173         return ret;
174 }