2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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
8 * http://www.tizenopensource.org/license
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.
18 #include "ivug-detail-info.h"
21 #include <vconf-keys.h>
23 #include <appcore-efl.h>
24 #include <appcore-common.h>
26 #include <unicode/udat.h>
27 #include <unicode/ustring.h>
28 #include <unicode/uloc.h>
29 #include <unicode/ucal.h>
30 #include <unicode/udatpg.h>
31 #include <unicode/utmscale.h>
33 #include "ivug-details-view.h"
34 #include <libexif/exif-data.h>
36 #include "ivug-file-info.h"
41 #define DETAILS_DIR_PATH_LEN_MAX 4096
52 Shuld free returned value after use
55 _get_icu_time_string(const char *locale, const char *customSkeleton, const char *timezone, UDate date)
57 #define UG_ICU_ARR_LENGTH 256
59 IV_ASSERT(customSkeleton != NULL);
60 IV_ASSERT(timezone != NULL);
63 Copy a byte string encoded in the default codepage to a ustring.
64 Copies at most n characters. The result will be null terminated if the length of src is less than n. Performs a host byte to UChar conversion
66 UChar ucustomSkeleton[UG_ICU_ARR_LENGTH] = {0,};
68 if(u_uastrncpy(ucustomSkeleton, customSkeleton, UG_ICU_ARR_LENGTH) == NULL)
70 MSG_UTIL_ERROR("u_uastrncpy() error.");
74 UChar utimezone[UG_ICU_ARR_LENGTH] = {0,};
76 if ( u_uastrncpy(utimezone, timezone, UG_ICU_ARR_LENGTH) == NULL )
78 MSG_UTIL_ERROR("u_uastrncpy() error.");
82 UErrorCode status = U_ZERO_ERROR;
83 UDateTimePatternGenerator *generator;
84 UDateFormat *formatter;
86 UChar bestPattern[UG_ICU_ARR_LENGTH] = {0,};
87 UChar formatted[UG_ICU_ARR_LENGTH] = {0,};
88 char formattedString[UG_ICU_ARR_LENGTH] = {0,};
89 int32_t bestPatternLength, formattedLength;
91 ucal_setDefaultTimeZone(utimezone , &status);
93 if (U_FAILURE(status))
95 MSG_UTIL_ERROR("ucal_setDefaultTimeZone() is failed");
99 uloc_setDefault(getenv("LC_TIME"), &status);
101 if (U_FAILURE(status))
103 MSG_UTIL_ERROR("ucal_setDefaultTimeZone() is failed");
107 generator = udatpg_open(locale, &status);
108 if(generator == NULL)
113 bestPatternLength = udatpg_getBestPattern(generator, ucustomSkeleton, u_strlen(ucustomSkeleton), bestPattern, UG_ICU_ARR_LENGTH, &status);
114 if(bestPatternLength <= 0)
119 formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status);
125 formattedLength = udat_format(formatter, date, formatted, UG_ICU_ARR_LENGTH, NULL, &status);
126 if(formattedLength <= 0)
131 u_austrcpy(formattedString, formatted);
132 udatpg_close(generator);
133 udat_close(formatter);
135 if(strlen(formattedString) == 0)
140 return strdup(formattedString);
145 _get_icu_date(time_t mtime)
147 #define UG_DATE_FORMAT_12 "yMMMdhms"
148 #define UG_DATE_FORMAT_24 "yMMMdHms"
150 char* skeleton = NULL;
152 enum appcore_time_format timeformat;
154 int ret = appcore_get_timeformat(&timeformat);
157 MSG_DETAIL_ERROR("Cannot get timeformat.");
158 timeformat = APPCORE_TIME_FORMAT_12; // Default value.
162 if(timeformat == APPCORE_TIME_FORMAT_12)
164 skeleton = UG_DATE_FORMAT_12;
166 else if(timeformat == APPCORE_TIME_FORMAT_24)
168 skeleton = UG_DATE_FORMAT_24;
172 MSG_DETAIL_ERROR("Invalid time format : %d", timeformat);
173 skeleton = UG_DATE_FORMAT_12; // Default value.
176 char *locale = vconf_get_str(VCONFKEY_REGIONFORMAT); /* eg. en_US.UTF-8*/
179 MSG_DETAIL_ERROR("Cannot get region format.");
180 locale = "en_US.UTF-8"; // Default value.
183 char *timezone = NULL;
185 timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID); // eg Asia/Seoul
188 // TODO : How to get default time zone????
189 MSG_DETAIL_ERROR("Cannot get time zone");
193 MSG_DETAIL_HIGH("Locale:%s TimeZone:%s TimeFormat:%s", locale, skeleton, timezone);
195 char* datestr = NULL;
197 datestr = _get_icu_time_string(locale, skeleton, timezone, (UDate)mtime * 1000);
201 MSG_DETAIL_ERROR("Cannot get time string");
205 MSG_DETAIL_HIGH("ICU Date : %s", datestr);
214 _get_filesize_string(size_t size)
216 #define FILE_SIZE_LEN_MAX 64
217 #define BASIC_SIZE 1024 //used for file size check
221 unsigned long int lsize = (unsigned long int)size;
223 char *tmp = (char *)calloc(1, sizeof(char)*FILE_SIZE_LEN_MAX + 1);
229 while(size >= ( BASIC_SIZE ) )
236 float remain = ((float)lsize/BASIC_SIZE) - size;
238 if(count == SIZE_BYTE)
240 snprintf(tmp,FILE_SIZE_LEN_MAX,"%zu B", size);
242 else if(count == SIZE_KB)
244 snprintf(tmp,FILE_SIZE_LEN_MAX,"%zu KB", size);
246 else if(count == SIZE_MB)
248 // need another algorithm
249 snprintf(tmp,FILE_SIZE_LEN_MAX,"%.1f MB", size+remain);
251 else if(count == SIZE_GB)
253 snprintf(tmp,FILE_SIZE_LEN_MAX,"%.1f GB", size+remain);
256 MSG_DETAIL_HIGH("Size = %lu, OrigSize=%zu", lsize, size);
261 ivug_details_info_set_file_information(ivug_file_info_t * const pFileInfo, const char *path)
263 ivug_ret_if( NULL == pFileInfo );
264 ivug_ret_if( NULL == path );
267 pFileInfo->filepath = strdup(path);
271 if(stat(path,&statbuf) == -1)
273 MSG_DETAIL_ERROR("Cannot get stat()");
277 pFileInfo->size = statbuf.st_size;
278 pFileInfo->date = statbuf.st_mtime;
280 pFileInfo->create_date = _get_icu_date(pFileInfo->date);
282 if ( pFileInfo->create_date == NULL )
284 pFileInfo->create_date = strdup(IDS_N_A);
287 pFileInfo->file_ext = ivug_fileinfo_get_file_extension(path);
289 if ( pFileInfo->file_ext == NULL )
291 pFileInfo->file_ext = strdup(IDS_UNKNOWN);
294 pFileInfo->filesize = _get_filesize_string(pFileInfo->size);
296 MSG_DETAIL_HIGH("Basic Info : ext=%s size=%s", pFileInfo->file_ext, pFileInfo->filesize);
304 ivug_details_info_set_gps_info(ivug_file_info_t * const pFileInfo, const char *path)
306 #define UG_EXIF_ARR_LENGTH 255
308 ivug_retm_if(!pFileInfo, "data is NULL");
309 ivug_retm_if(!path, "path is NULL");
311 pFileInfo->longitude = calloc(1, sizeof(char)*UG_EXIF_ARR_LENGTH);
312 if(pFileInfo->longitude == NULL)
317 pFileInfo->latitude = calloc(1, sizeof(char)*UG_EXIF_ARR_LENGTH);
318 if(pFileInfo->latitude == NULL)
324 double longtitude = 0.0;
325 double latitude = 0.0;
329 if(pFileInfo->file_type == IVUG_DETAIL_IMAGE_TYPE) // this will be removed!!!!
331 bret = ivug_fileinfo_get_image_gps_info(path, &latitude, &longtitude);
333 else if(pFileInfo->file_type == IVUG_DETAIL_VIDEO_TYPE)
335 bret = ivug_fileinfo_get_video_gps_info(path, &latitude, &longtitude);
346 snprintf(pFileInfo->latitude, UG_EXIF_ARR_LENGTH, "%.5f", latitude);
350 snprintf(pFileInfo->latitude, UG_EXIF_ARR_LENGTH, "%s", IDS_UNKNOWN);
352 if(longtitude != 0.0)
354 snprintf(pFileInfo->longitude, UG_EXIF_ARR_LENGTH, "%.5f", longtitude);
358 snprintf(pFileInfo->longitude, UG_EXIF_ARR_LENGTH, "%s", IDS_UNKNOWN);
363 ivug_details_info_set_resolution(ivug_file_info_t * const pFileInfo, const char *path, int stype)
365 ivug_retm_if(!pFileInfo, "data is NULL");
366 ivug_retm_if(!path, "path is NULL");
368 MSG_DETAIL_HIGH("slide type is %d", stype);
370 pFileInfo->resolution = (char *)malloc(sizeof(char)*NOMAL_BUF+1);
371 if(pFileInfo->resolution == NULL)
375 memset(pFileInfo->resolution,0,(sizeof(char)* NOMAL_BUF + 1));
382 case SLIDE_TYPE_IMAGE:
383 pFileInfo->file_type = IVUG_DETAIL_IMAGE_TYPE;
385 if ( ivug_fileinfo_get_image_resolution(path, &width, &height) == false)
387 snprintf(pFileInfo->resolution, NOMAL_BUF, "%s", IDS_N_A);
391 snprintf(pFileInfo->resolution, NOMAL_BUF,"%dX%d", width, height);
397 case SLIDE_TYPE_VIDEO:
398 pFileInfo->file_type = IVUG_DETAIL_VIDEO_TYPE;
400 if ( ivug_fileinfo_get_video_resolution(path, &width, &height) == false)
402 snprintf(pFileInfo->resolution, NOMAL_BUF, "%s", IDS_N_A);
406 snprintf(pFileInfo->resolution, NOMAL_BUF,"%dX%d", width, height);
419 ivug_details_info_set_location(ivug_file_info_t * const pFileInfo, const char *path)
421 ivug_retm_if(!pFileInfo, "data is NULL");
422 ivug_retm_if(!path, "path is NULL");
424 pFileInfo->file_location = strdup(path);
428 ivug_details_info_set_filename(ivug_file_info_t * const pFileInfo, const char *path)
430 ivug_retm_if(!pFileInfo, "data is NULL");
431 ivug_retm_if(!path, "path is NULL");
434 pFileInfo->filename = ecore_file_strip_ext(ecore_file_file_get(path));