diff options
author | Jisung Ahn <jcastle.ahn@samsung.com> | 2012-08-21 21:33:06 +0900 |
---|---|---|
committer | Jisung Ahn <jcastle.ahn@samsung.com> | 2012-08-21 21:48:17 +0900 |
commit | a914248a31229bb81ed4ede970ca23e2490e0387 (patch) | |
tree | 8e3d763e83861131c778b442b3333496be1b23b7 /main/src/view/ivug-detail-info.c | |
parent | 8b42d4bb33943903b7160bb963bf7e7c6824e9ef (diff) | |
download | ug-image-viewer-efl-a914248a31229bb81ed4ede970ca23e2490e0387.tar.gz ug-image-viewer-efl-a914248a31229bb81ed4ede970ca23e2490e0387.tar.bz2 ug-image-viewer-efl-a914248a31229bb81ed4ede970ca23e2490e0387.zip |
initial upload
Change-Id: Ie9df15e2a3ce6a47e65f48aa0cfb43c2622b74d7
Diffstat (limited to 'main/src/view/ivug-detail-info.c')
-rwxr-xr-x | main/src/view/ivug-detail-info.c | 437 |
1 files changed, 0 insertions, 437 deletions
diff --git a/main/src/view/ivug-detail-info.c b/main/src/view/ivug-detail-info.c deleted file mode 100755 index 77061e3..0000000 --- a/main/src/view/ivug-detail-info.c +++ /dev/null @@ -1,437 +0,0 @@ -/* - * Copyright 2012 Samsung Electronics Co., Ltd - * - * Licensed under the Flora License, Version 1.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.tizenopensource.org/license - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -#include "ivug-detail-info.h" - -#include <vconf.h> -#include <vconf-keys.h> - -#include <appcore-efl.h> -#include <appcore-common.h> - -#include <unicode/udat.h> -#include <unicode/ustring.h> -#include <unicode/uloc.h> -#include <unicode/ucal.h> -#include <unicode/udatpg.h> -#include <unicode/utmscale.h> - -#include "ivug-details-view.h" -#include <libexif/exif-data.h> - -#include "ivug-file-info.h" - - -#define NOMAL_BUF 128 - -#define DETAILS_DIR_PATH_LEN_MAX 4096 - -enum IVUG_SIZE_TYPE -{ - SIZE_BYTE = 0, - SIZE_KB, - SIZE_MB, - SIZE_GB -}; - -/* - Shuld free returned value after use -*/ -static char* -_get_icu_time_string(const char *locale, const char *customSkeleton, const char *timezone, UDate date) -{ -#define UG_ICU_ARR_LENGTH 256 - - IV_ASSERT(customSkeleton != NULL); - IV_ASSERT(timezone != NULL); - - /* - Copy a byte string encoded in the default codepage to a ustring. - 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 - */ - UChar ucustomSkeleton[UG_ICU_ARR_LENGTH] = {0,}; - - if(u_uastrncpy(ucustomSkeleton, customSkeleton, UG_ICU_ARR_LENGTH) == NULL) - { - MSG_UTIL_ERROR("u_uastrncpy() error."); - return NULL; - } - - UChar utimezone[UG_ICU_ARR_LENGTH] = {0,}; - - if ( u_uastrncpy(utimezone, timezone, UG_ICU_ARR_LENGTH) == NULL ) - { - MSG_UTIL_ERROR("u_uastrncpy() error."); - return NULL; - } - - UErrorCode status = U_ZERO_ERROR; - UDateTimePatternGenerator *generator; - UDateFormat *formatter; - - UChar bestPattern[UG_ICU_ARR_LENGTH] = {0,}; - UChar formatted[UG_ICU_ARR_LENGTH] = {0,}; - char formattedString[UG_ICU_ARR_LENGTH] = {0,}; - int32_t bestPatternLength, formattedLength; - - ucal_setDefaultTimeZone(utimezone , &status); - - if (U_FAILURE(status)) - { - MSG_UTIL_ERROR("ucal_setDefaultTimeZone() is failed"); - return NULL; - } - - uloc_setDefault(getenv("LC_TIME"), &status); - - if (U_FAILURE(status)) - { - MSG_UTIL_ERROR("ucal_setDefaultTimeZone() is failed"); - return NULL; - } - - generator = udatpg_open(locale, &status); - if(generator == NULL) - { - return NULL; - } - - bestPatternLength = udatpg_getBestPattern(generator, ucustomSkeleton, u_strlen(ucustomSkeleton), bestPattern, UG_ICU_ARR_LENGTH, &status); - if(bestPatternLength <= 0) - { - return NULL; - } - - formatter = udat_open(UDAT_IGNORE, UDAT_IGNORE, locale, NULL, -1, bestPattern, -1, &status); - if(formatter == 0) - { - return NULL; - } - - formattedLength = udat_format(formatter, date, formatted, UG_ICU_ARR_LENGTH, NULL, &status); - if(formattedLength <= 0) - { - return NULL; - } - - u_austrcpy(formattedString, formatted); - udatpg_close(generator); - udat_close(formatter); - - if(strlen(formattedString) == 0) - { - return NULL; - } - - return strdup(formattedString); -} - - -static char* -_get_icu_date(time_t mtime) -{ -#define UG_DATE_FORMAT_12 "yMMMdhms" -#define UG_DATE_FORMAT_24 "yMMMdHms" - - char* skeleton = NULL; - - enum appcore_time_format timeformat; - - int ret = appcore_get_timeformat(&timeformat); - if(ret == -1) - { - MSG_DETAIL_ERROR("Cannot get timeformat."); - timeformat = APPCORE_TIME_FORMAT_12; // Default value. -// Go through - } - - if(timeformat == APPCORE_TIME_FORMAT_12) - { - skeleton = UG_DATE_FORMAT_12; - } - else if(timeformat == APPCORE_TIME_FORMAT_24) - { - skeleton = UG_DATE_FORMAT_24; - } - else - { - MSG_DETAIL_ERROR("Invalid time format : %d", timeformat); - skeleton = UG_DATE_FORMAT_12; // Default value. - } - - char *locale = vconf_get_str(VCONFKEY_REGIONFORMAT); /* eg. en_US.UTF-8*/ - if(locale == NULL) - { - MSG_DETAIL_ERROR("Cannot get region format."); - locale = "en_US.UTF-8"; // Default value. - } - - char *timezone = NULL; - - timezone = vconf_get_str(VCONFKEY_SETAPPL_TIMEZONE_ID); // eg Asia/Seoul - if(timezone == NULL) - { -// TODO : How to get default time zone???? - MSG_DETAIL_ERROR("Cannot get time zone"); - return NULL; - } - - MSG_DETAIL_HIGH("Locale:%s TimeZone:%s TimeFormat:%s", locale, skeleton, timezone); - - char* datestr = NULL; - - datestr = _get_icu_time_string(locale, skeleton, timezone, (UDate)mtime * 1000); - - if(datestr == NULL) - { - MSG_DETAIL_ERROR("Cannot get time string"); - return NULL; - } - - MSG_DETAIL_HIGH("ICU Date : %s", datestr); - return datestr; - -} - - - - -static char * -_get_filesize_string(size_t size) -{ -#define FILE_SIZE_LEN_MAX 64 -#define BASIC_SIZE 1024 //used for file size check - - int count = 0; - - unsigned long int lsize = (unsigned long int)size; - - char *tmp = (char *)calloc(1, sizeof(char)*FILE_SIZE_LEN_MAX + 1); - if ( tmp == NULL) - { - return NULL; - } - - while(size >= ( BASIC_SIZE ) ) - { - lsize = size; - size /= BASIC_SIZE; - count++; - } - - float remain = ((float)lsize/BASIC_SIZE) - size; - - if(count == SIZE_BYTE) - { - snprintf(tmp,FILE_SIZE_LEN_MAX,"%zu B", size); - } - else if(count == SIZE_KB) - { - snprintf(tmp,FILE_SIZE_LEN_MAX,"%zu KB", size); - } - else if(count == SIZE_MB) - { - // need another algorithm - snprintf(tmp,FILE_SIZE_LEN_MAX,"%.1f MB", size+remain); - } - else if(count == SIZE_GB) - { - snprintf(tmp,FILE_SIZE_LEN_MAX,"%.1f GB", size+remain); - } - - MSG_DETAIL_HIGH("Size = %lu, OrigSize=%zu", lsize, size); - return tmp; -} - -void -ivug_details_info_set_file_information(ivug_file_info_t * const pFileInfo, const char *path) -{ - ivug_ret_if( NULL == pFileInfo ); - ivug_ret_if( NULL == path ); - -/*** get file path*/ - pFileInfo->filepath = strdup(path); - - struct stat statbuf; - - if(stat(path,&statbuf) == -1) - { - MSG_DETAIL_ERROR("Cannot get stat()"); - return ; - } - - pFileInfo->size = statbuf.st_size; - pFileInfo->date = statbuf.st_mtime; - - pFileInfo->create_date = _get_icu_date(pFileInfo->date); - - if ( pFileInfo->create_date == NULL ) - { - pFileInfo->create_date = strdup(IDS_N_A); - } - - pFileInfo->file_ext = ivug_fileinfo_get_file_extension(path); - - if ( pFileInfo->file_ext == NULL ) - { - pFileInfo->file_ext = strdup(IDS_UNKNOWN); - } - - pFileInfo->filesize = _get_filesize_string(pFileInfo->size); - - MSG_DETAIL_HIGH("Basic Info : ext=%s size=%s", pFileInfo->file_ext, pFileInfo->filesize); - - return ; - -} - - -void -ivug_details_info_set_gps_info(ivug_file_info_t * const pFileInfo, const char *path) -{ -#define UG_EXIF_ARR_LENGTH 255 - - ivug_retm_if(!pFileInfo, "data is NULL"); - ivug_retm_if(!path, "path is NULL"); - - pFileInfo->longitude = calloc(1, sizeof(char)*UG_EXIF_ARR_LENGTH); - if(pFileInfo->longitude == NULL) - { - return; - } - - pFileInfo->latitude = calloc(1, sizeof(char)*UG_EXIF_ARR_LENGTH); - if(pFileInfo->latitude == NULL) - { - return; - } - - - double longtitude = 0.0; - double latitude = 0.0; - - bool bret = false; - - if(pFileInfo->file_type == IVUG_DETAIL_IMAGE_TYPE) // this will be removed!!!! - { - bret = ivug_fileinfo_get_image_gps_info(path, &latitude, &longtitude); - } - else if(pFileInfo->file_type == IVUG_DETAIL_VIDEO_TYPE) - { - bret = ivug_fileinfo_get_video_gps_info(path, &latitude, &longtitude); - } - - if ( bret == false) - { - latitude = 0; - longtitude = 0; - } - - if(latitude != 0.0) - { - snprintf(pFileInfo->latitude, UG_EXIF_ARR_LENGTH, "%.5f", latitude); - } - else - { - snprintf(pFileInfo->latitude, UG_EXIF_ARR_LENGTH, "%s", IDS_UNKNOWN); - } - if(longtitude != 0.0) - { - snprintf(pFileInfo->longitude, UG_EXIF_ARR_LENGTH, "%.5f", longtitude); - } - else - { - snprintf(pFileInfo->longitude, UG_EXIF_ARR_LENGTH, "%s", IDS_UNKNOWN); - } -} - -void -ivug_details_info_set_resolution(ivug_file_info_t * const pFileInfo, const char *path, int stype) -{ - ivug_retm_if(!pFileInfo, "data is NULL"); - ivug_retm_if(!path, "path is NULL"); - - MSG_DETAIL_HIGH("slide type is %d", stype); - - pFileInfo->resolution = (char *)malloc(sizeof(char)*NOMAL_BUF+1); - if(pFileInfo->resolution == NULL) - { - return ; - } - memset(pFileInfo->resolution,0,(sizeof(char)* NOMAL_BUF + 1)); - - - int width, height; - - switch(stype) - { - case SLIDE_TYPE_IMAGE: - pFileInfo->file_type = IVUG_DETAIL_IMAGE_TYPE; - - if ( ivug_fileinfo_get_image_resolution(path, &width, &height) == false) - { - snprintf(pFileInfo->resolution, NOMAL_BUF, "%s", IDS_N_A); - } - else - { - snprintf(pFileInfo->resolution, NOMAL_BUF,"%dX%d", width, height); - } - - break; - - /* Video type */ - case SLIDE_TYPE_VIDEO: - pFileInfo->file_type = IVUG_DETAIL_VIDEO_TYPE; - - if ( ivug_fileinfo_get_video_resolution(path, &width, &height) == false) - { - snprintf(pFileInfo->resolution, NOMAL_BUF, "%s", IDS_N_A); - } - else - { - snprintf(pFileInfo->resolution, NOMAL_BUF,"%dX%d", width, height); - } - - break; - - default: - break; - - } - -} - -void -ivug_details_info_set_location(ivug_file_info_t * const pFileInfo, const char *path) -{ - ivug_retm_if(!pFileInfo, "data is NULL"); - ivug_retm_if(!path, "path is NULL"); - - pFileInfo->file_location = strdup(path); -} - -void -ivug_details_info_set_filename(ivug_file_info_t * const pFileInfo, const char *path) -{ - ivug_retm_if(!pFileInfo, "data is NULL"); - ivug_retm_if(!path, "path is NULL"); - - /** get file name */ - pFileInfo->filename = ecore_file_strip_ext(ecore_file_file_get(path)); -} - - |