0169862c9bb787788ff44df0bf7da29f0d4a271f
[mafwsubrenderer] / libmafw-gst-renderer / mafw-gst-renderer-utils.c
1 /*
2  * This file is a part of MAFW
3  *
4  * Copyright (C) 2007, 2008, 2009 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Visa Smolander <visa.smolander@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <glib.h>
30
31 #include "mafw-gst-renderer-utils.h"
32
33 #undef  G_LOG_DOMAIN
34 #define G_LOG_DOMAIN "mafw-gst-renderer-utils"
35
36 /**
37  * convert_utf8:
38  * @src: string.
39  * @dst: location for utf8 version of @src.
40  *
41  * Tries to convert @src into UTF-8, placing it into @dst.
42  *
43  * Returns: TRUE on success.
44  */
45 gboolean convert_utf8(const gchar *src, gchar **dst)
46 {
47         GError *error;
48
49         if (!src)
50                 return FALSE;
51         if (g_utf8_validate(src, -1, NULL)) {
52                 *dst = g_strdup(src);
53                 return TRUE;
54         }
55         error = NULL;
56         *dst = g_locale_to_utf8(src, -1, NULL, NULL, &error);
57         if (error) {
58                 g_warning("utf8 conversion failed '%s' (%d: %s)",
59                           src, error->code, error->message);
60                 g_error_free(error);
61                 return FALSE;
62         }
63         return TRUE;
64 }
65
66 gboolean uri_is_playlist(const gchar *uri) {
67         /* TODO: Return if the uri is a playlist or not, using the mime type
68            instead of the file extension. */
69         if ((g_str_has_suffix(uri, ".pls")) ||
70             (g_str_has_suffix(uri, ".m3u")) ||
71             (g_str_has_suffix(uri, ".smil")) ||
72             (g_str_has_suffix(uri, ".smi")) ||
73             (g_str_has_suffix(uri, ".wpl")) ||
74             (g_str_has_suffix(uri, ".wax")) ||
75             (g_str_has_suffix(uri, ".uni")) ||
76             (g_str_has_suffix(uri, ".ram")) ||
77 /*          (g_str_has_suffix(uri, ".ra")) || */
78             (g_str_has_suffix(uri, ".asx")) ||
79             (g_str_has_suffix(uri, ".rpm")))
80                 {
81                         return TRUE;
82                 }
83         return FALSE;
84 }
85
86 /**
87  * uri_is_stream:
88  * @uri: the URI to be checked.
89  *
90  * Check if given URI is a stream (not a local resource).  To not depend on
91  * gnomevfs for this, we assume everything that doesn't start with "file://" is
92  * a stream.
93  *
94  * Returns: TRUE if the URI is not local.
95  */
96 gboolean uri_is_stream(const gchar *uri)
97 {
98         if (uri == NULL) {
99                 return FALSE;
100         } else {
101                 return !g_str_has_prefix(uri, "file://");
102         }
103 }
104
105 /* vi: set noexpandtab ts=8 sw=8 cino=t0,(0: */