2 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
26 #include "menu_db_util.h"
29 static int __match_content_with_regex(const char *content, regex_t *regex_preg)
31 if (regexec(regex_preg, content, 0, NULL, 0) == 0)
37 API int aul_get_mime_from_content(const char *content, char *mimetype,
41 regex_tbl *miregex_tbl = NULL;
46 if ((miregex_tbl = miregex_get_regex_table()) == NULL) {
47 _E("load miregex_table fail");
52 if (__match_content_with_regex(content,
53 &(miregex_tbl->regex_preg))) {
54 founded = miregex_tbl->mimetype;
55 SECURE_LOGD("content %s => mimetype %s", content, founded);
58 miregex_tbl = miregex_tbl->next;
62 snprintf(mimetype, len, "%s", founded);
64 /* TODO : should to try to extract from share mime info's data*/
71 API int aul_get_mime_description(const char *mimetype, char *desc, int len)
73 regex_tbl *miregex_tbl = NULL;
79 if ((miregex_tbl = miregex_get_regex_table()) == NULL) {
80 _E("load miregex_table fail");
85 if (strcmp(miregex_tbl->mimetype, mimetype) == 0) {
86 founded = miregex_tbl->desc;
87 _D("mimetype %s => desc %s", mimetype, founded);
90 miregex_tbl = miregex_tbl->next;
94 snprintf(desc, len, "%s", founded);
96 /* TODO : should to try to extract from share mime info's comment */
103 API int aul_get_mime_extension(const char *mimetype, char *ext, int len)
105 const char **extlist;
107 const char *unaliased_mimetype;
109 if (mimetype == NULL || ext == NULL || len <= 0)
112 unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype);
113 if (unaliased_mimetype == NULL)
116 extlist = xdg_mime_get_file_names_from_mime_type(unaliased_mimetype);
120 if (extlist[0] == NULL)
124 while (*extlist != NULL) {
125 if (*(extlist + 1) == NULL) {
126 snprintf(&ext[totlen], len - totlen, "%s", *extlist);
129 snprintf(&ext[totlen], len - totlen, "%s,", *extlist);
130 if (strlen(*extlist) > len - totlen - 1)
132 totlen += strlen(*extlist) + 1;
140 API int aul_get_mime_icon(const char *mimetype, char *iconname, int len)
143 const char *unaliased_mimetype;
145 if (mimetype == NULL || iconname == NULL || len <= 0)
148 unaliased_mimetype = xdg_mime_unalias_mime_type(mimetype);
149 if (unaliased_mimetype == NULL)
152 icon = xdg_mime_get_icon(unaliased_mimetype);
154 icon = xdg_mime_get_generic_icon(unaliased_mimetype);
157 snprintf(iconname, len, "%s", icon);
163 API int aul_get_mime_from_file(const char *filename, char *mimetype, int len)
166 if (filename == NULL)
169 if (access(filename, F_OK) != 0)
172 mime = xdg_mime_get_mime_type_for_file(filename, 0);
173 if (strcmp(mime, "application/octet-stream") == 0)
174 mime = xdg_mime_get_mime_type_from_file_name(filename);
176 snprintf(mimetype, len, "%s", mime);
180 API int aul_set_defapp_with_mime(const char *mimetype, const char *defapp)
186 API int aul_get_defapp_from_mime(const char *mimetype, char *defapp, int len)
192 API int aul_open_content(const char *content)
198 API int aul_open_file_with_mimetype(const char *filename,
199 const char *mimetype)
205 API int aul_open_file(const char *filename)