1 /** \file
2 * Inkscape::IO::Resource - simple resource API
3 *
4 * Copyright 2006 MenTaLguY <mental@rydia.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * See the file COPYING for details.
12 *
13 */
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif
19 #include <glib/gmessages.h>
20 #include <glib/gstrfuncs.h>
21 #include <glib/gfileutils.h>
22 #include "path-prefix.h"
23 #include "inkscape.h"
24 #include "io/resource.h"
26 namespace Inkscape {
28 namespace IO {
30 namespace Resource {
32 Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename)
33 {
34 gchar *path=NULL;
35 switch (domain) {
36 case SYSTEM: {
37 switch (type) {
38 case APPICONS: path = INKSCAPE_APPICONDIR; break;
39 case EXTENSIONS: path = INKSCAPE_EXTENSIONDIR; break;
40 case GRADIENTS: path = INKSCAPE_GRADIENTSDIR; break;
41 case ICONS: path = INKSCAPE_PIXMAPDIR; break;
42 case KEYS: path = INKSCAPE_KEYSDIR; break;
43 case MARKERS: path = INKSCAPE_MARKERSDIR; break;
44 case PALETTES: path = INKSCAPE_PALETTESDIR; break;
45 case PATTERNS: path = INKSCAPE_PATTERNSDIR; break;
46 case PLUGINS: path = INKSCAPE_PLUGINDIR; break;
47 case SCREENS: path = INKSCAPE_SCREENSDIR; break;
48 case TEMPLATES: path = INKSCAPE_TEMPLATESDIR; break;
49 case TUTORIALS: path = INKSCAPE_TUTORIALSDIR; break;
50 case UI: path = INKSCAPE_UIDIR; break;
51 default: g_assert_not_reached();
52 }
53 path = g_strdup(path);
54 } break;
55 case USER: {
56 char const *name=NULL;
57 switch (type) {
58 case EXTENSIONS: name = "extensions"; break;
59 case GRADIENTS: name = "gradients"; break;
60 case ICONS: name = "icons"; break;
61 case KEYS: name = "keys"; break;
62 case MARKERS: name = "markers"; break;
63 case PALETTES: name = "palettes"; break;
64 case PATTERNS: name = "patterns"; break;
65 case PLUGINS: name = "plugins"; break;
66 case TEMPLATES: name = "templates"; break;
67 default: return get_path(SYSTEM, type, filename);
68 }
69 path = profile_path(name);
70 } break;
71 }
73 if (filename) {
74 gchar *temp=g_build_filename(path, filename, NULL);
75 g_free(path);
76 path = temp;
77 }
79 Util::ptr_shared<char> result=Util::share_string(path);
80 g_free(path);
81 return result;
82 }
84 }
86 }
88 }
90 /*
91 Local Variables:
92 mode:c++
93 c-file-style:"stroustrup"
94 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
95 indent-tabs-mode:nil
96 fill-column:99
97 End:
98 */
99 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :