2009-03-13 18:43:16 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2009 The Music Player Daemon Project
|
|
|
|
* http://www.musicpd.org
|
2004-02-24 00:41:20 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-02-24 00:41:20 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "path.h"
|
|
|
|
#include "conf.h"
|
|
|
|
|
2008-10-15 19:36:30 +02:00
|
|
|
#include <glib.h>
|
|
|
|
|
2009-02-20 12:31:00 +01:00
|
|
|
#include <assert.h>
|
2008-12-29 17:28:32 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
2008-12-29 17:32:53 +01:00
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "path"
|
|
|
|
|
2008-11-05 18:21:52 +01:00
|
|
|
static char *fs_charset;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2009-01-08 21:20:46 +01:00
|
|
|
char *
|
|
|
|
fs_charset_to_utf8(const char *path_fs)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-01-08 21:20:46 +01:00
|
|
|
return g_convert(path_fs, -1,
|
|
|
|
"utf-8", fs_charset,
|
|
|
|
NULL, NULL, NULL);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2009-01-08 21:20:46 +01:00
|
|
|
char *
|
|
|
|
utf8_to_fs_charset(const char *path_utf8)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-10-15 19:36:30 +02:00
|
|
|
gchar *p;
|
|
|
|
|
2009-01-08 21:20:46 +01:00
|
|
|
p = g_convert(path_utf8, -1,
|
2008-11-20 17:48:11 +01:00
|
|
|
fs_charset, "utf-8",
|
2009-01-04 19:50:22 +01:00
|
|
|
NULL, NULL, NULL);
|
|
|
|
if (p == NULL)
|
2008-10-15 19:36:30 +02:00
|
|
|
/* fall back to UTF-8 */
|
2009-01-08 21:20:46 +01:00
|
|
|
p = g_strdup(path_utf8);
|
2008-10-15 19:36:30 +02:00
|
|
|
|
2009-01-08 21:20:46 +01:00
|
|
|
return p;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2009-02-20 14:49:57 +01:00
|
|
|
static void
|
|
|
|
path_set_fs_charset(const char *charset)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-02-20 12:31:00 +01:00
|
|
|
char *test;
|
|
|
|
|
|
|
|
assert(charset != NULL);
|
|
|
|
|
|
|
|
/* convert a space to ensure that the charset is valid */
|
|
|
|
test = g_convert(" ", 1, charset, "UTF-8", NULL, NULL, NULL);
|
|
|
|
if (test == NULL)
|
|
|
|
g_error("invalid filesystem charset: %s", charset);
|
|
|
|
g_free(test);
|
|
|
|
|
2008-11-05 18:21:52 +01:00
|
|
|
g_free(fs_charset);
|
|
|
|
fs_charset = g_strdup(charset);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-12-29 17:32:53 +01:00
|
|
|
g_debug("path_set_fs_charset: fs charset is: %s", fs_charset);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-11-05 18:21:52 +01:00
|
|
|
const char *path_get_fs_charset(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-11-05 18:21:52 +01:00
|
|
|
return fs_charset;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2008-11-05 18:21:52 +01:00
|
|
|
void path_global_init(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-11-05 18:26:45 +01:00
|
|
|
const char *charset = NULL;
|
2005-03-06 20:00:58 +01:00
|
|
|
|
2009-01-25 16:00:51 +01:00
|
|
|
charset = config_get_string(CONF_FS_CHARSET, NULL);
|
|
|
|
if (charset == NULL) {
|
2008-11-05 18:25:57 +01:00
|
|
|
const gchar **encodings;
|
|
|
|
g_get_filename_charsets(&encodings);
|
|
|
|
|
|
|
|
if (encodings[0] != NULL && *encodings[0] != '\0')
|
2008-11-05 18:26:45 +01:00
|
|
|
charset = encodings[0];
|
2007-02-18 01:42:22 +01:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (charset) {
|
2008-11-05 18:21:52 +01:00
|
|
|
path_set_fs_charset(charset);
|
2006-07-20 18:02:40 +02:00
|
|
|
} else {
|
2008-12-29 17:32:53 +01:00
|
|
|
g_message("setting filesystem charset to ISO-8859-1");
|
2008-11-05 18:21:52 +01:00
|
|
|
path_set_fs_charset("ISO-8859-1");
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-05 18:21:52 +01:00
|
|
|
void path_global_finish(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-11-05 18:21:52 +01:00
|
|
|
g_free(fs_charset);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|