Code

1f6f8459c60b4738bdc37fb2ff67958565fda3d7
[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 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 CREATE: {
57             gchar const* temp = 0;
58             switch (type) {
59                 case GRADIENTS: temp = CREATE_GRADIENTSDIR; break;
60                 case PALETTES: temp = CREATE_PALETTESDIR; break;
61                 case PATTERNS: temp = CREATE_PATTERNSDIR; break;
62                 default: g_assert_not_reached();
63             }
64             path = g_strdup(temp);
65         } break;
66         case USER: {
67             char const *name=NULL;
68             switch (type) {
69                 case EXTENSIONS: name = "extensions"; break;
70                 case GRADIENTS: name = "gradients"; break;
71                 case ICONS: name = "icons"; break;
72                 case KEYS: name = "keys"; break;
73                 case MARKERS: name = "markers"; break;
74                 case PALETTES: name = "palettes"; break;
75                 case PATTERNS: name = "patterns"; break;
76                 case TEMPLATES: name = "templates"; break;
77                 default: return get_path(SYSTEM, type, filename);
78             }
79             path = profile_path(name);
80         } break;
81     }
83     if (filename) {
84         gchar *temp=g_build_filename(path, filename, NULL);
85         g_free(path);
86         path = temp;
87     }
89     Util::ptr_shared<char> result=Util::share_string(path);
90     g_free(path);
91     return result;
92 }
94 }
96 }
98 }
100 /*
101   Local Variables:
102   mode:c++
103   c-file-style:"stroustrup"
104   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
105   indent-tabs-mode:nil
106   fill-column:99
107   End:
108 */
109 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :