initial upload for tizen 2.0 beta
[apps/home/gallery.git] / ug / ug-gallery-efl / src / ge-drm.c
1 /*
2   * Copyright 2012  Samsung Electronics Co., Ltd
3   *
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
7   *
8   *     http://www.tizenopensource.org/license
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 <sys/stat.h>
18 #include <fcntl.h>
19 #include "gallery-efl.h"
20 #include "ge-ui-util.h"
21 #include "ge-debug.h"
22 #include "ge-drm.h"
23
24 int ge_drm_get_permtype(int gitem_type)
25 {
26         switch (gitem_type) {
27         case MEDIA_CONTENT_TYPE_IMAGE:
28                 return DRM_PERMISSION_TYPE_DISPLAY;
29         case MEDIA_CONTENT_TYPE_VIDEO:
30                 return DRM_PERMISSION_TYPE_PLAY;
31         default:
32                 return -1;
33         }
34 }
35
36 Eina_Bool ge_drm_check_valid_ro(const char *file_path,
37                                 drm_permission_type_e permType)
38 {
39         GE_CHECK_FALSE(file_path);
40         ge_dbg("file_path: %s", file_path);
41         int ret = -1;
42
43         drm_license_status_e license_status = DRM_LICENSE_STATUS_UNDEFINED;
44         ret = drm_get_license_status(file_path, permType, &license_status);
45         if (DRM_RETURN_SUCCESS == ret &&
46             DRM_LICENSE_STATUS_VALID == license_status) {
47                 return EINA_TRUE;
48         } else {
49                 ge_dbg("No valid ro, return %d", license_status);
50                 return EINA_FALSE;
51         }
52 }
53
54 Eina_Bool ge_drm_is_drm_file(const char* file_path)
55 {
56         GE_CHECK_FALSE(file_path);
57         ge_dbg("file_path: %s.", file_path);
58
59         drm_bool_type_e is_drm_file = DRM_UNKNOWN;
60         if(drm_is_drm_file(file_path, &is_drm_file) != DRM_RETURN_SUCCESS) {
61                 ge_dbgE("drm_is_drm_file error");
62                 return EINA_FALSE;
63         }
64
65         if (DRM_TRUE == is_drm_file)
66                 return EINA_TRUE;
67         return EINA_FALSE;
68 }
69
70 char* ge_drm_get_file_path(void *item)
71 {
72         ge_item* gitem = (ge_item *)item;
73
74         if(!gitem || !gitem->item || !gitem->item->file_url)
75                 return NULL;
76         ge_dbg("filepath: %s", gitem->item->file_url);
77
78         if(ge_drm_is_drm_file(gitem->item->file_url))
79                 return strdup(GE_DEFAULT_THUMB_ICON);
80         else
81                 return strdup(gitem->item->file_url);
82 }
83