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