Modified SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE list test case
[platform/core/api/system-settings.git] / src / system_settings_ringtones.c
1 /*
2  * system_settings_ringtones.c
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd.
5  *
6  * Contact: MyoungJune Park <mj2004.park@samsung.com>
7  *
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
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  *
20  */
21
22 #include <system_settings.h>
23 #include <system_settings_private.h>
24 #include "system_settings_ringtones.h"
25 #include "system_settings_json.h"
26
27 /*remove ext name */
28 char *get_filename_from_fullname(const char *fullname)
29 {
30         //retvm_if(fullname == NULL, NULL, "fullname == NULL");
31         if (fullname == NULL) return NULL;
32
33         char tmp[512];
34         snprintf(tmp, sizeof(tmp), "%s", fullname);
35
36         char *name = strrchr(tmp, '.');
37         if (name != NULL)
38                 *name = '\0';
39
40         return strdup((char*)tmp);
41 }
42
43 char *get_media_basename(const char *dir_path, const char *name)
44 {
45         //retv_if(isEmptyStr(dir_path) || isEmptyStr(name), NULL);
46         if (dir_path == NULL) return NULL;
47
48         char path[512] = {0, };
49         snprintf(path, sizeof(path), "%s/%s", dir_path, name);
50
51         metadata_extractor_h metadata = NULL;
52         char *title = NULL;
53         int ret = metadata_extractor_create(&metadata);
54         if (ret == METADATA_EXTRACTOR_ERROR_NONE && metadata) {
55                 ret = metadata_extractor_set_path(metadata, path);
56                 if (ret == METADATA_EXTRACTOR_ERROR_NONE) {
57                         ret = metadata_extractor_get_metadata(
58                                         metadata, METADATA_TITLE, &title);
59                         metadata_extractor_destroy(metadata);
60                         if (title)
61                                 /*return (char *)g_strdup(title);*/
62                                 return (char *)title;
63                         else
64                                 return strdup(name);
65                 } else {
66                         metadata_extractor_destroy(metadata);
67                         return strdup(name);
68                 }
69         } else {
70                 return strdup(name);
71         }
72 }
73
74 int get_filelist_from_dir_path(char *path, Eina_List **file_list)
75 {
76         SETTING_TRACE_BEGIN;
77         DIR *pDir = NULL;
78         struct dirent ent, *result;
79
80         if (path == NULL) {
81                 SETTING_TRACE("dir path is null");
82                 return -1;
83         }
84
85         if (file_list == NULL) {
86                 SETTING_TRACE("file_list is null");
87                 return -1;
88         }
89
90         pDir = opendir(path);
91
92         if (pDir == NULL)
93                 return -2;
94
95         while (readdir_r(pDir, &ent, &result) == 0) {
96                 if (result == NULL)
97                         break;
98
99                 fileNodeInfo *pNode = NULL;
100
101                 if (strncmp(ent.d_name, ".", 1) == 0
102                                 || strcmp(ent.d_name, "..") == 0)
103                         continue;
104
105                 if ((ent.d_type & DT_REG) == 0)
106                         continue;
107
108                 pNode = (fileNodeInfo *) malloc(sizeof(fileNodeInfo));
109                 if (pNode == NULL)
110                         continue;
111
112                 memset(pNode, 0, sizeof(fileNodeInfo));
113
114                 pNode->path = strdup(path);
115                 pNode->name = strdup(ent.d_name);
116                 pNode->media_name = get_media_basename(
117                                 pNode->path, pNode->name);
118
119                 *file_list = eina_list_append(*file_list, pNode);
120         }
121         closedir(pDir);
122         //SETTING_TRACE_END;
123
124         return 0;
125 }
126