Code

ae9097868db4d52fce22048b585feb66336a67f3
[inkscape.git] / src / io / resource.cpp
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             gchar const* temp = 0;
38             switch (type) {
39                 case APPICONS: temp = INKSCAPE_APPICONDIR; break;
40                 case EXTENSIONS: temp = INKSCAPE_EXTENSIONDIR; break;
41                 case GRADIENTS: temp = INKSCAPE_GRADIENTSDIR; break;
42                 case ICONS: temp = INKSCAPE_PIXMAPDIR; break;
43                 case KEYS: temp = INKSCAPE_KEYSDIR; break;
44                 case MARKERS: temp = INKSCAPE_MARKERSDIR; break;
45                 case PALETTES: temp = INKSCAPE_PALETTESDIR; break;
46                 case PATTERNS: temp = INKSCAPE_PATTERNSDIR; break;
47                 case PLUGINS: temp = INKSCAPE_PLUGINDIR; break;
48                 case SCREENS: temp = INKSCAPE_SCREENSDIR; break;
49                 case TEMPLATES: temp = INKSCAPE_TEMPLATESDIR; break;
50                 case TUTORIALS: temp = INKSCAPE_TUTORIALSDIR; break;
51                 case UI: temp = INKSCAPE_UIDIR; break;
52                 default: g_assert_not_reached();
53             }
54             path = g_strdup(temp);
55         } break;
56         case USER: {
57             char const *name=NULL;
58             switch (type) {
59                 case EXTENSIONS: name = "extensions"; break;
60                 case GRADIENTS: name = "gradients"; break;
61                 case ICONS: name = "icons"; break;
62                 case KEYS: name = "keys"; break;
63                 case MARKERS: name = "markers"; break;
64                 case PALETTES: name = "palettes"; break;
65                 case PATTERNS: name = "patterns"; break;
66                 case PLUGINS: name = "plugins"; break;
67                 case TEMPLATES: name = "templates"; break;
68                 default: return get_path(SYSTEM, type, filename);
69             }
70             path = profile_path(name);
71         } break;
72     }
74     if (filename) {
75         gchar *temp=g_build_filename(path, filename, NULL);
76         g_free(path);
77         path = temp;
78     }
80     Util::ptr_shared<char> result=Util::share_string(path);
81     g_free(path);
82     return result;
83 }
85 }
87 }
89 }
91 /*
92   Local Variables:
93   mode:c++
94   c-file-style:"stroustrup"
95   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
96   indent-tabs-mode:nil
97   fill-column:99
98   End:
99 */
100 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :