4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Hyunjun Ko <zzoon.ko@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
22 #include "media-thumbnail.h"
23 #include "media-thumb-debug.h"
24 #include "media-thumb-util.h"
25 #include "media-thumb-internal.h"
26 #include "media-thumb-ipc.h"
27 #include "media-thumb-db.h"
30 #include <media-svc.h>
32 int thumbnail_request_from_db(const char *origin_path, char *thumb_path, int max_length)
35 int need_update_db = 0;
36 media_thumb_info thumb_info;
38 if (origin_path == NULL || thumb_path == NULL) {
39 thumb_err("Invalid parameter");
40 return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
44 (origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
45 thumb_err("Original path(%s) doesn't exist.", origin_path);
46 return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
49 if (max_length <= 0) {
50 thumb_err("Length is invalid");
51 return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
55 store_type = _media_thumb_get_store_type_by_path(origin_path);
57 if ((store_type != THUMB_PHONE) && (store_type != THUMB_MMC)) {
58 thumb_err("origin path(%s) is invalid", origin_path);
59 return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
62 thumb_err("Path : %s", origin_path);
66 err = _media_thumb_get_thumb_from_db(origin_path, thumb_path, max_length, &need_update_db);
69 return MEDIA_THUMB_ERROR_NONE;
72 /* Request for thumb file to the daemon "Thumbnail generator" */
73 err = _media_thumb_request(THUMB_REQUEST_DB, MEDIA_THUMB_LARGE, origin_path, thumb_path, max_length, &thumb_info);
75 thumb_err("_media_thumb_request failed : %d", err);
80 /* Need to update DB once generating thumb is done */
82 err = _media_thumb_update_db(origin_path, thumb_path, thumb_info.origin_width, thumb_info.origin_height);
84 thumb_err("_media_thumb_update_db failed : %d", err);
89 return MEDIA_THUMB_ERROR_NONE;
92 int thumbnail_request_save_to_file(const char *origin_path, media_thumb_type thumb_type, const char *thumb_path)
96 if (origin_path == NULL || thumb_path == NULL) {
97 thumb_err("Invalid parameter");
98 return MEDIA_THUMB_ERROR_INVALID_PARAMETER;
101 media_thumb_info thumb_info;
102 char tmp_thumb_path[MAX_PATH_SIZE] = {0,};
104 strncpy(tmp_thumb_path, thumb_path, sizeof(tmp_thumb_path));
106 /* Request for thumb file to the daemon "Thumbnail generator" */
107 err = _media_thumb_request(THUMB_REQUEST_SAVE, thumb_type, origin_path, tmp_thumb_path, sizeof(tmp_thumb_path), &thumb_info);
109 thumb_err("_media_thumb_request failed : %d", err);
113 return MEDIA_THUMB_ERROR_NONE;