Code

Add CMakeLists for the filters directory.
[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.h> // g_assert()
20 #include <glib/gmessages.h>
21 #include <glib/gstrfuncs.h>
22 #include <glib/gfileutils.h>
23 #include "path-prefix.h"
24 #include "inkscape.h"
25 #include "io/resource.h"
27 namespace Inkscape {
29 namespace IO {
31 namespace Resource {
33 Util::ptr_shared<char> get_path(Domain domain, Type type, char const *filename)
34 {
35     gchar *path=NULL;
36     switch (domain) {
37         case SYSTEM: {
38             gchar const* temp = 0;
39             switch (type) {
40                 case APPICONS: temp = INKSCAPE_APPICONDIR; break;
41                 case EXTENSIONS: temp = INKSCAPE_EXTENSIONDIR; break;
42                 case GRADIENTS: temp = INKSCAPE_GRADIENTSDIR; break;
43                 case ICONS: temp = INKSCAPE_PIXMAPDIR; break;
44                 case KEYS: temp = INKSCAPE_KEYSDIR; break;
45                 case MARKERS: temp = INKSCAPE_MARKERSDIR; break;
46                 case PALETTES: temp = INKSCAPE_PALETTESDIR; break;
47                 case PATTERNS: temp = INKSCAPE_PATTERNSDIR; break;
48                 case PLUGINS: temp = INKSCAPE_PLUGINDIR; break;
49                 case SCREENS: temp = INKSCAPE_SCREENSDIR; break;
50                 case TEMPLATES: temp = INKSCAPE_TEMPLATESDIR; break;
51                 case TUTORIALS: temp = INKSCAPE_TUTORIALSDIR; break;
52                 case UI: temp = INKSCAPE_UIDIR; break;
53                 default: g_assert_not_reached();
54             }
55             path = g_strdup(temp);
56         } break;
57         case CREATE: {
58             gchar const* temp = 0;
59             switch (type) {
60                 case GRADIENTS: temp = CREATE_GRADIENTSDIR; break;
61                 case PALETTES: temp = CREATE_PALETTESDIR; break;
62                 case PATTERNS: temp = CREATE_PATTERNSDIR; break;
63                 default: g_assert_not_reached();
64             }
65             path = g_strdup(temp);
66         } break;
67         case USER: {
68             char const *name=NULL;
69             switch (type) {
70                 case EXTENSIONS: name = "extensions"; break;
71                 case GRADIENTS: name = "gradients"; break;
72                 case ICONS: name = "icons"; break;
73                 case KEYS: name = "keys"; break;
74                 case MARKERS: name = "markers"; break;
75                 case PALETTES: name = "palettes"; break;
76                 case PATTERNS: name = "patterns"; break;
77                 case PLUGINS: name = "plugins"; break;
78                 case TEMPLATES: name = "templates"; break;
79                 default: return get_path(SYSTEM, type, filename);
80             }
81             path = profile_path(name);
82         } break;
83     }
85     if (filename) {
86         gchar *temp=g_build_filename(path, filename, NULL);
87         g_free(path);
88         path = temp;
89     }
91     Util::ptr_shared<char> result=Util::share_string(path);
92     g_free(path);
93     return result;
94 }
96 }
98 }
102 /*
103   Local Variables:
104   mode:c++
105   c-file-style:"stroustrup"
106   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
107   indent-tabs-mode:nil
108   fill-column:99
109   End:
110 */
111 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :