diff options
| author | MenTaLguY <mental@rydia.net> | 2006-04-06 03:34:45 +0000 |
|---|---|---|
| committer | mental <mental@users.sourceforge.net> | 2006-04-06 03:34:45 +0000 |
| commit | b22dc68676d864d120525654758fb4154ca74b29 (patch) | |
| tree | ede47dcd34bcbc490f51314f11ad538f669f9421 /src/io/resource.cpp | |
| parent | new language zh_TW (diff) | |
| download | inkscape-b22dc68676d864d120525654758fb4154ca74b29.tar.gz inkscape-b22dc68676d864d120525654758fb4154ca74b29.zip | |
introduce uniform resource path API to replace copy-and-pasted hacks
(bzr r436)
Diffstat (limited to 'src/io/resource.cpp')
| -rw-r--r-- | src/io/resource.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/io/resource.cpp b/src/io/resource.cpp new file mode 100644 index 000000000..fc5eb6723 --- /dev/null +++ b/src/io/resource.cpp @@ -0,0 +1,99 @@ +/** \file + * Inkscape::IO::Resource - simple resource API + * + * Copyright 2006 MenTaLguY <mental@rydia.net> + * + * 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. + * + * See the file COPYING for details. + * + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <glib/gmessages.h> +#include <glib/gstrfuncs.h> +#include <glib/gfileutils.h> +#include "path-prefix.h" +#include "inkscape.h" +#include "io/resource.h" + +namespace Inkscape { + +namespace IO { + +namespace Resource { + +Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename) +{ + gchar *path=NULL; + switch (domain) { + case SYSTEM: { + switch (type) { + case APPICONS: path = INKSCAPE_APPICONDIR; break; + case EXTENSIONS: path = INKSCAPE_EXTENSIONDIR; break; + case GRADIENTS: path = INKSCAPE_GRADIENTSDIR; break; + case ICONS: path = INKSCAPE_PIXMAPDIR; break; + case KEYS: path = INKSCAPE_KEYSDIR; break; + case MARKERS: path = INKSCAPE_MARKERSDIR; break; + case PALETTES: path = INKSCAPE_PALETTESDIR; break; + case PATTERNS: path = INKSCAPE_PATTERNSDIR; break; + case PLUGINS: path = INKSCAPE_PLUGINDIR; break; + case SCREENS: path = INKSCAPE_SCREENSDIR; break; + case TEMPLATES: path = INKSCAPE_TEMPLATESDIR; break; + case TUTORIALS: path = INKSCAPE_TUTORIALSDIR; break; + case UI: path = INKSCAPE_UIDIR; break; + default: g_assert_not_reached(); + } + path = g_strdup(path); + } break; + case USER: { + char const *name=NULL; + switch (type) { + case EXTENSIONS: name = "extensions"; break; + case GRADIENTS: name = "gradients"; break; + case ICONS: name = "icons"; break; + case KEYS: name = "keys"; break; + case MARKERS: name = "markers"; break; + case PALETTES: name = "palettes"; break; + case PATTERNS: name = "patterns"; break; + case PLUGINS: name = "plugins"; break; + case TEMPLATES: name = "templates"; break; + default: return get_path(SYSTEM, type, filename); + } + path = profile_path(name); + } break; + } + + if (filename) { + gchar *temp=g_build_filename(path, filename, NULL); + g_free(path); + path = temp; + } + + Util::ptr_shared<char> result=Util::share_string(path); + g_free(path); + return result; +} + +} + +} + +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
