diff options
Diffstat (limited to 'main/src/control/ivug-detail-info.c')
-rwxr-xr-x | main/src/control/ivug-detail-info.c | 703 |
1 files changed, 703 insertions, 0 deletions
diff --git a/main/src/control/ivug-detail-info.c b/main/src/control/ivug-detail-info.c new file mode 100755 index 0000000..d6f7f9f --- /dev/null +++ b/main/src/control/ivug-detail-info.c @@ -0,0 +1,703 @@ +/*
+ * 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 <drm_client.h> + +#include <runtime_info.h> + +#include <glib.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-drm.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); +} + + +/* + Should free returned value after use +*/ +static char * +_get_drm_availabile_string(drm_permission_type_e permissionType) +{ + switch(permissionType) + { + case DRM_PERMISSION_TYPE_ANY: + return strdup(IDS_ANY); + break; + + case DRM_PERMISSION_TYPE_PLAY: + return strdup(IDS_PLAY); + break; + + case DRM_PERMISSION_TYPE_COLLABORATIVE_PLAY: + return strdup(IDS_COLLABORATIVE_PLAY); + break; + + case DRM_PERMISSION_TYPE_DISPLAY: + return strdup(IDS_DISPLAY); + break; + + case DRM_PERMISSION_TYPE_EXECUTE: + return strdup(IDS_EXECUTE); + break; + + case DRM_PERMISSION_TYPE_PRINT: + return strdup(IDS_PRINT); + break; + + case DRM_PERMISSION_TYPE_EXPORT_COPY: + return strdup(IDS_COPY); + break; + + case DRM_PERMISSION_TYPE_EXPORT_MOVE: + return strdup(IDS_MOVE); + break; + + default: + return strdup(IDS_N_A); + break; + + } +} + +static char* +_get_icu_date(time_t mtime) +{ +#define UG_DATE_FORMAT_12 "yMMMdhms" +#define UG_DATE_FORMAT_24 "yMMMdHms" + + char* skeleton = NULL; + + bool hours_24 = false; + int ret = -1; + + ret = runtime_info_get_value_bool(RUNTIME_INFO_KEY_24HOUR_CLOCK_FORMAT_ENABLED, &hours_24); + if(ret != RUNTIME_INFO_ERROR_NONE) + { + MSG_DETAIL_ERROR("Cannot get 24 hours format"); + return NULL; + } + + if(hours_24 == true) + { + skeleton = UG_DATE_FORMAT_24; + } + else + { + skeleton = UG_DATE_FORMAT_12; + } + + 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 + + MSG_DETAIL_HIGH("Entered size = %d", size); + + char *tmp = (char *)calloc(1, sizeof(char)*(FILE_SIZE_LEN_MAX+1)); + if (tmp == NULL) + { + return NULL; + } + + if(size > (1<<30)) // GB + { + snprintf(tmp,FILE_SIZE_LEN_MAX,"%.1f GB", (double)size/(1<<30)); + } + else if(size > (1<<20)) // MB + { + snprintf(tmp,FILE_SIZE_LEN_MAX,"%.1f MB", (double)size/(1<<20)); + } + else if(size > (1<<10)) // KB + { + snprintf(tmp,FILE_SIZE_LEN_MAX,"%zu KB", size/(1<<10)); + } + else // Byte + { + snprintf(tmp,FILE_SIZE_LEN_MAX,"%zu B", size); + } + + MSG_DETAIL_HIGH("Result Size = %s", tmp); + 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) + { + /*Image type && !drm*/ + 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; + + case SLIDE_TYPE_STREAMING: + pFileInfo->file_type = IVUG_DETAIL_VIDEO_TYPE; + 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)); +} + +void _add_string(char *org, char *add_string) +{ + char *string = strdup(add_string); + if(org == NULL) + { + org = string; + } + else + { + org = g_strconcat(org, "/", string, NULL); + free(string); + } +} + +void +ivug_details_info_set_drm_info(ivug_file_info_t * const pFileInfo, const char *path) +{ +#define VALIDITY_SIZE 80 + +#define MOUNTH_COUNT 12 //used for drm file info, +#define DAY_COUNT 30 +#define HOUR_COUNT 24 +#define SECOND_COUNT 3600.0 + + ivug_retm_if(!pFileInfo, "data is NULL"); + ivug_retm_if(!path, "path is NULL"); + + pFileInfo->vendor = NULL; + pFileInfo->forwarding = NULL; + pFileInfo->available_uses = NULL; + pFileInfo->type = NULL; + + bool valid_ro = false; + + valid_ro = ivug_drm_has_valid_ro(path); + + if(false == valid_ro) + { + MSG_DETAIL_WARN("%s is not valid right object", path); + return ; + } + +// Get Vendor + pFileInfo->vendor = ivug_drm_get_drm_vendor_info(path); + + if ( pFileInfo->vendor == NULL ) + { + // Set default value. + pFileInfo->vendor = strdup(IDS_UNKNOWN); + } + +// Get forwarding + if ( ivug_drm_get_forwarding_info(path) == true ) + { + pFileInfo->forwarding = strdup(IDS_POSSIBLE); + } + else + { + pFileInfo->forwarding = strdup(IDS_IMPOSSIBLE); + } + +// Get Validity/Type/Available + + drm_constraint_info_s constraint_info; + int ret = -1; + int i = -1; + char *string = NULL; + char validity[VALIDITY_SIZE] = ""; + + for(i=DRM_PERMISSION_TYPE_NONE; i<=DRM_PERMISSION_TYPE_EXPORT_MOVE; i++) + { + memset(&constraint_info, 0x0, sizeof(drm_constraint_info_s)); + + ret = drm_get_constraint_info(path, i, &constraint_info); + if(ret != DRM_RETURN_SUCCESS) + { + MSG_IVUG_ERROR("drm_get_constraint_info Failed!!, perm_type=%d ret=0x%x", i, ret); + continue; + } + + string = _get_drm_availabile_string(i); + _add_string(pFileInfo->available_uses, string); + free(string); + + if(constraint_info.const_type.is_unlimited) + { + MSG_IVUG_HIGH("Unlimited:for permission=%d", i); + + _add_string(pFileInfo->type, IDS_UNLIMITED); + _add_string(pFileInfo->validity, IDS_UNLIMITED); + } + + if(constraint_info.const_type.is_accumulated){ + MSG_IVUG_HIGH("Accumulated Constraint is present"); + MSG_IVUG_HIGH("accumulated_original_seconds=%d", + constraint_info.accumulated_original_seconds); + MSG_IVUG_HIGH("accumulated_remaining_seconds=%d", + constraint_info.accumulated_remaining_seconds); + + _add_string(pFileInfo->type, IDS_ACCUMULATED_TIME); + snprintf(validity, sizeof(validity),"Total %.1f hours", + constraint_info.accumulated_remaining_seconds/SECOND_COUNT); + _add_string(pFileInfo->validity, validity); + } + + if(constraint_info.const_type.is_count){ + MSG_IVUG_HIGH("Count Constraint is present"); + MSG_IVUG_HIGH("original_count=%d", + constraint_info.original_count); + MSG_IVUG_HIGH("remaining_count=%d", + constraint_info.remaining_count); + + _add_string(pFileInfo->type, IDS_COUNT); + snprintf(validity, sizeof(validity),"%d left", constraint_info.remaining_count); + _add_string(pFileInfo->validity, validity); + } + + if(constraint_info.const_type.is_datetime){ + MSG_IVUG_HIGH("DATETIME Constraint is present"); + MSG_IVUG_HIGH("start_time:" + "Year=%d,Month=%d,Day=%d,Hour=%d, minute=%d, Second=%d", + constraint_info.start_time.tm_year, + constraint_info.start_time.tm_mon, + constraint_info.start_time.tm_mday, + constraint_info.start_time.tm_hour, + constraint_info.start_time.tm_min, + constraint_info.start_time.tm_sec); + + MSG_IVUG_HIGH("end_time:" + "Year=%d,Month=%d,Day=%d,Hour=%d, minute=%d, Second=%d", + constraint_info.end_time.tm_year, + constraint_info.end_time.tm_mon, + constraint_info.end_time.tm_mday, + constraint_info.end_time.tm_hour, + constraint_info.end_time.tm_min, + constraint_info.end_time.tm_sec); + + _add_string(pFileInfo->type, IDS_TIME); + snprintf(validity, sizeof(validity),"%d.%d.%d %d:%d ~ %d.%d.%d %d:%d:%d", + constraint_info.start_time.tm_mday, + constraint_info.start_time.tm_mon, + constraint_info.start_time.tm_year, + constraint_info.start_time.tm_hour, + constraint_info.start_time.tm_sec, + constraint_info.end_time.tm_mday, + constraint_info.end_time.tm_mon, + constraint_info.end_time.tm_year, + constraint_info.end_time.tm_hour, + constraint_info.end_time.tm_min, + constraint_info.end_time.tm_sec + ); + _add_string(pFileInfo->validity, validity); + } + + if(constraint_info.const_type.is_individual){ + MSG_IVUG_HIGH("INDIVIDUAL Constraint is present"); + MSG_IVUG_HIGH("individual_identity_type=%d " + "individual_id=%s", + constraint_info.individual_identity_type, + constraint_info.individual_id); + + _add_string(pFileInfo->type, IDS_INDIVIDUAL); + _add_string(pFileInfo->validity, IDS_INDIVIDUAL); + } + + if(constraint_info.const_type.is_interval){ + MSG_IVUG_HIGH("INTERVAL Constraint is present"); + MSG_IVUG_HIGH("interval_time:" + "Year=%d,Month=%d,Day=%d,Hour=%d, minute=%d, Second=%d", + constraint_info.interval_time.tm_year, + constraint_info.interval_time.tm_mon, + constraint_info.interval_time.tm_mday, + constraint_info.interval_time.tm_hour, + constraint_info.interval_time.tm_min, + constraint_info.interval_time.tm_sec); + + _add_string(pFileInfo->type, IDS_INTERVAL); + if(constraint_info.interval_time.tm_year == 0 + && constraint_info.interval_time.tm_mon == 0 + && constraint_info.interval_time.tm_mday == 0 + && constraint_info.interval_time.tm_hour == 0) + { + snprintf(validity, sizeof(validity),"Total %d miniutes", constraint_info.interval_time.tm_min); + } + else + { + snprintf(validity, sizeof(validity),"Total %d hours", + ((constraint_info.interval_time.tm_year*MOUNTH_COUNT + + constraint_info.interval_time.tm_mon)*DAY_COUNT + + constraint_info.interval_time.tm_mday)*HOUR_COUNT + + constraint_info.interval_time.tm_hour + ); + } + _add_string(pFileInfo->validity, validity); + } + + if(constraint_info.const_type.is_system){ + MSG_IVUG_HIGH("SYSTEM Constraint is present"); + MSG_IVUG_HIGH("system_identity_type=%d " + "system_id=%s", + constraint_info.system_identity_type, + constraint_info.system_id); + + _add_string(pFileInfo->type, IDS_SYSTEM); + _add_string(pFileInfo->validity, IDS_SYSTEM); + } + + if(constraint_info.const_type.is_timedcount){ + MSG_IVUG_HIGH("TIMED-COUNT Constraint is present"); + MSG_IVUG_HIGH("timed_original_count=%d", + constraint_info.timed_original_count); + + MSG_IVUG_HIGH("timed_remaining_count=%d", + constraint_info.timed_remaining_count); + + MSG_IVUG_HIGH("timed_count_timer=%d", + constraint_info.timed_count_timer); + + _add_string(pFileInfo->type, IDS_TIMED_COUNT); + snprintf(validity, sizeof(validity),"%d (%d sec)", + constraint_info.timed_remaining_count, + constraint_info.timed_count_timer + ); + _add_string(pFileInfo->validity, validity); + } + + MSG_IVUG_WARN("Undefined constraints"); + } + + return; +} + + |