Fix build error due to changing app-common
[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 <cstdlib>
18 #include <cstring>
19 #include "dbg.h"
20 #include <AppCommon.h>
21 #include "common.h"
22 #include "FileInfo.h"
23
24
25 struct SFileInfo {
26         media_info_h handle;
27 };
28
29
30 bool CFileInfo::Create(void)
31 {
32         if (m)
33                 return false;
34
35         m = new SFileInfo;
36         if (!m)
37                 return false;
38
39         memset(m, 0, sizeof(SFileInfo));
40
41         if (!CExtNameInfo::Create(CExtNameInfo::CLASS_TYPE_FILE)) {
42                 delete m;
43                 m = NULL;
44                 return false;
45         }
46
47         return true;
48 }
49
50
51 void CFileInfo::Destroy(void)
52 {
53         if (!m)
54                 return;
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         if (!m)
90                 return false;
91
92         if (!CExtNameInfo::Duplicate(obj))
93                 return false;
94
95         return true;
96 }
97
98
99 bool CFileInfo::SetLoadInfo(media_info_h handle)
100 {
101         if (!m)
102                 return false;
103
104         m->handle = handle;
105         return true;
106 }
107
108 bool CFileInfo::Load(void)
109 {
110         if (!m)
111                 return false;
112
113         bool ret = false;
114         do {
115                 char* str;
116                 if (media_info_get_media_id(m->handle, &str) != MEDIA_CONTENT_ERROR_NONE) {
117                         _ERR("media ID Fetch error");
118                         break;
119                 }
120                 SetId(str);
121                 free(str);
122
123                 if (media_info_get_title(m->handle, &str) != MEDIA_CONTENT_ERROR_NONE) {
124                         _ERR("media name Fetch error");
125                         break;
126                 }
127                 SetName(str);
128                 free(str);
129
130                 media_content_type_e ctype;
131                 if (media_info_get_media_type(m->handle, &ctype) != MEDIA_CONTENT_ERROR_NONE) {
132                         _ERR("media type Fetch error");
133                         break;
134                 }
135                 SetType(gType(ctype));
136
137                 TSize size;
138                 if (media_info_get_size(m->handle, &size) != MEDIA_CONTENT_ERROR_NONE) {
139                         _ERR("media size Fetch error");
140                         break;
141                 }
142                 SetSize(size);
143
144                 if (media_info_get_file_path(m->handle, &str) != MEDIA_CONTENT_ERROR_NONE) {
145                         _ERR("media file path Fetch error");
146                         break;
147                 }
148                 SetPath(str);
149                 free(str);
150
151                 if (media_info_get_thumbnail_path(m->handle, &str) != MEDIA_CONTENT_ERROR_NONE) {
152                         _ERR("media thumb Fetch error");
153                         break;
154                 }
155                 if(str == NULL)
156                 {
157                         _ERR("Fail to get string by media_info_get_thumbnail_path");
158                         //break;
159                 }
160                 else
161                 {
162                         SetThumbnailPath(str);
163                         free(str);
164                 }
165
166                 TTime time;
167                 if (media_info_get_modified_time(m->handle, &time) != MEDIA_CONTENT_ERROR_NONE) {
168                         _ERR("media mod time Fetch error");
169                         break;
170                 }
171                 SetModifiedTime(time);
172
173                 ret = true;
174         } while (0);
175
176         return ret;
177 }