summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile_Eina.am3
-rw-r--r--src/lib/efreet/efreet.c78
-rw-r--r--src/lib/eina/eina_internal.h3
-rw-r--r--src/lib/eina/eina_vpath.c1
-rw-r--r--src/lib/eina/eina_vpath_xdg.c83
5 files changed, 89 insertions, 79 deletions
diff --git a/src/Makefile_Eina.am b/src/Makefile_Eina.am
index 997c526..965bff3 100644
--- a/src/Makefile_Eina.am
+++ b/src/Makefile_Eina.am
@@ -185,7 +185,8 @@ lib/eina/eina_bezier.c \
185lib/eina/eina_safepointer.c \ 185lib/eina/eina_safepointer.c \
186lib/eina/eina_freeq.c \ 186lib/eina/eina_freeq.c \
187lib/eina/eina_slstr.c \ 187lib/eina/eina_slstr.c \
188lib/eina/eina_vpath.c 188lib/eina/eina_vpath.c \
189lib/eina/eina_vpath_xdg.c
189 190
190 191
191if HAVE_WIN32 192if HAVE_WIN32
diff --git a/src/lib/efreet/efreet.c b/src/lib/efreet/efreet.c
index d17e1da..091899f 100644
--- a/src/lib/efreet/efreet.c
+++ b/src/lib/efreet/efreet.c
@@ -10,8 +10,6 @@
10#include <Ecore.h> 10#include <Ecore.h>
11#include <Ecore_File.h> 11#include <Ecore_File.h>
12 12
13#include "eina_internal.h"
14
15/* define macros and variable for using the eina logging system */ 13/* define macros and variable for using the eina logging system */
16#define EFREET_MODULE_LOG_DOM /* no logging in this file */ 14#define EFREET_MODULE_LOG_DOM /* no logging in this file */
17 15
@@ -38,79 +36,6 @@ static uid_t ruid;
38static uid_t rgid; 36static uid_t rgid;
39#endif 37#endif
40 38
41static void
42_efreet_efreet_app_interface_set(void)
43{
44 char buf[PATH_MAX];
45 char *s;
46 const char *home;
47 Eina_Vpath_Interface_User user;
48
49 home = eina_vpath_resolve("(:home:)/");
50
51 memset(&user, 0, sizeof(Eina_Vpath_Interface_User));
52
53# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
54# define ENV_HOME_SET(_env, _dir, _meta) \
55 if ((getuid() != geteuid()) || (!(s = getenv(_env)))) { \
56 snprintf(buf, sizeof(buf), "%s/"_dir, home); \
57 s = buf; \
58 } \
59 (&user)->_meta = s;
60#else
61# define ENV_HOME_SET(_env, _dir, _meta) \
62 if (!(s = getenv(_env))) { \
63 snprintf(buf, sizeof(buf), "%s/"_dir, home); \
64 s = buf; \
65 } \
66 (&user)->_meta = s;
67#endif
68 // $XDG_DESKTOP_DIR="$HOME/Desktop"
69 ENV_HOME_SET("XDG_DESKTOP_DIR", "Desktop", desktop);
70 // $XDG_DOCUMENTS_DIR="$HOME/Documents"
71 ENV_HOME_SET("XDG_DOCUMENTS_DIR", "Documents", documents);
72 // $XDG_DOWNLOAD_DIR="$HOME/Downloads"
73 ENV_HOME_SET("XDG_DOWNLOAD_DIR", "Downloads", downloads);
74 // $XDG_MUSIC_DIR="$HOME/Music"
75 ENV_HOME_SET("XDG_MUSIC_DIR", "Music", music);
76 // $XDG_PICTURES_DIR="$HOME/Pictures"
77 ENV_HOME_SET("XDG_PICTURES_DIR", "Pictures", pictures);
78 // $XDG_PUBLICSHARE_DIR="$HOME/Public"
79 ENV_HOME_SET("XDG_PUBLIC_DIR", "Public", pub);
80 // $XDG_TEMPLATES_DIR="$HOME/.Templates"
81 ENV_HOME_SET("XDG_TEMPLATES_DIR", ".Templates", templates);
82 // $XDG_VIDEOS_DIR="$HOME/Videos"
83 ENV_HOME_SET("XDG_VIDEOS_DIR", "Videos", videos);
84 // $XDG_DATA_HOME defines the base directory relative to which user
85 // specific data files should be stored. If $XDG_DATA_HOME is either
86 // not set or empty, a default equal to $HOME/.local/share should be
87 // used.
88 ENV_HOME_SET("XDG_DATA_HOME", ".local/share", data);
89 ENV_HOME_SET("XDG_TMP_HOME", ".local/tmp", tmp);
90 // $XDG_CONFIG_HOME defines the base directory relative to which user
91 // specific configuration files should be stored. If $XDG_CONFIG_HOME
92 // is either not set or empty, a default equal to $HOME/.config should
93 // be used.
94 ENV_HOME_SET("XDG_CONFIG_HOME", ".config", config);
95 // $XDG_CACHE_HOME defines the base directory relative to which
96 // user specific non-essential data files should be stored. If
97 // $XDG_CACHE_HOME is either not set or empty, a default equal to
98 // $HOME/.cache should be used.
99 ENV_HOME_SET("XDG_CACHE_HOME", ".cache", cache);
100
101#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
102 if ((getuid() != geteuid()) || (!(s = getenv("XDG_RUNTIME_DIR"))))
103#else
104 if (!(s = getenv("XDG_RUNTIME_DIR")))
105#endif
106 user.run = NULL;
107 else
108 user.run = s;
109
110 eina_vpath_interface_user_set(&user);
111}
112
113
114EAPI int 39EAPI int
115efreet_init(void) 40efreet_init(void)
116{ 41{
@@ -145,9 +70,6 @@ efreet_init(void)
145 if (!ecore_file_init()) 70 if (!ecore_file_init())
146 goto shutdown_ecore; 71 goto shutdown_ecore;
147 72
148 //this needs to be early initializied efreet itself is using vpaths
149 _efreet_efreet_app_interface_set();
150
151 if (!efreet_base_init()) 73 if (!efreet_base_init())
152 goto shutdown_ecore_file; 74 goto shutdown_ecore_file;
153 75
diff --git a/src/lib/eina/eina_internal.h b/src/lib/eina/eina_internal.h
index 9fea25b..9ae14df 100644
--- a/src/lib/eina/eina_internal.h
+++ b/src/lib/eina/eina_internal.h
@@ -99,6 +99,9 @@ EAPI void eina_vpath_interface_app_set(const char *app_name, Eina_Prefix *p);
99 */ 99 */
100EAPI void eina_vpath_interface_user_set(Eina_Vpath_Interface_User *user); 100EAPI void eina_vpath_interface_user_set(Eina_Vpath_Interface_User *user);
101 101
102
103void eina_xdg_env_init(void);
104
102#undef EAPI 105#undef EAPI
103#define EAPI 106#define EAPI
104 107
diff --git a/src/lib/eina/eina_vpath.c b/src/lib/eina/eina_vpath.c
index bc7c4d0..b1b6af5 100644
--- a/src/lib/eina/eina_vpath.c
+++ b/src/lib/eina/eina_vpath.c
@@ -175,6 +175,7 @@ eina_vpath_init(void)
175 vpath_data = eina_hash_string_superfast_new((Eina_Free_Cb)eina_stringshare_del); 175 vpath_data = eina_hash_string_superfast_new((Eina_Free_Cb)eina_stringshare_del);
176 176
177 _eina_vpath_interface_sys_init(); 177 _eina_vpath_interface_sys_init();
178 eina_xdg_env_init();
178 179
179 _eina_vpath_log_dom = eina_log_domain_register("vpath", "cyan"); 180 _eina_vpath_log_dom = eina_log_domain_register("vpath", "cyan");
180 return EINA_TRUE; 181 return EINA_TRUE;
diff --git a/src/lib/eina/eina_vpath_xdg.c b/src/lib/eina/eina_vpath_xdg.c
new file mode 100644
index 0000000..6a1d4d8
--- /dev/null
+++ b/src/lib/eina/eina_vpath_xdg.c
@@ -0,0 +1,83 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <sys/types.h>
6#include <pwd.h>
7
8#include <Eina.h>
9
10#include "eina_internal.h"
11#include "eina_private.h"
12
13void
14eina_xdg_env_init(void)
15{
16 char buf[PATH_MAX];
17 char *s;
18 const char *home;
19 Eina_Vpath_Interface_User user;
20
21 home = eina_vpath_resolve("(:home:)/");
22
23 memset(&user, 0, sizeof(Eina_Vpath_Interface_User));
24
25# if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
26# define ENV_HOME_SET(_env, _dir, _meta) \
27 if ((getuid() != geteuid()) || (!(s = getenv(_env)))) { \
28 snprintf(buf, sizeof(buf), "%s/"_dir, home); \
29 s = buf; \
30 } \
31 (&user)->_meta = s;
32#else
33# define ENV_HOME_SET(_env, _dir, _meta) \
34 if (!(s = getenv(_env))) { \
35 snprintf(buf, sizeof(buf), "%s/"_dir, home); \
36 s = buf; \
37 } \
38 (&user)->_meta = s;
39#endif
40 // $XDG_DESKTOP_DIR="$HOME/Desktop"
41 ENV_HOME_SET("XDG_DESKTOP_DIR", "Desktop", desktop);
42 // $XDG_DOCUMENTS_DIR="$HOME/Documents"
43 ENV_HOME_SET("XDG_DOCUMENTS_DIR", "Documents", documents);
44 // $XDG_DOWNLOAD_DIR="$HOME/Downloads"
45 ENV_HOME_SET("XDG_DOWNLOAD_DIR", "Downloads", downloads);
46 // $XDG_MUSIC_DIR="$HOME/Music"
47 ENV_HOME_SET("XDG_MUSIC_DIR", "Music", music);
48 // $XDG_PICTURES_DIR="$HOME/Pictures"
49 ENV_HOME_SET("XDG_PICTURES_DIR", "Pictures", pictures);
50 // $XDG_PUBLICSHARE_DIR="$HOME/Public"
51 ENV_HOME_SET("XDG_PUBLIC_DIR", "Public", pub);
52 // $XDG_TEMPLATES_DIR="$HOME/.Templates"
53 ENV_HOME_SET("XDG_TEMPLATES_DIR", ".Templates", templates);
54 // $XDG_VIDEOS_DIR="$HOME/Videos"
55 ENV_HOME_SET("XDG_VIDEOS_DIR", "Videos", videos);
56 // $XDG_DATA_HOME defines the base directory relative to which user
57 // specific data files should be stored. If $XDG_DATA_HOME is either
58 // not set or empty, a default equal to $HOME/.local/share should be
59 // used.
60 ENV_HOME_SET("XDG_DATA_HOME", ".local/share", data);
61 ENV_HOME_SET("XDG_TMP_HOME", ".local/tmp", tmp);
62 // $XDG_CONFIG_HOME defines the base directory relative to which user
63 // specific configuration files should be stored. If $XDG_CONFIG_HOME
64 // is either not set or empty, a default equal to $HOME/.config should
65 // be used.
66 ENV_HOME_SET("XDG_CONFIG_HOME", ".config", config);
67 // $XDG_CACHE_HOME defines the base directory relative to which
68 // user specific non-essential data files should be stored. If
69 // $XDG_CACHE_HOME is either not set or empty, a default equal to
70 // $HOME/.cache should be used.
71 ENV_HOME_SET("XDG_CACHE_HOME", ".cache", cache);
72
73#if defined(HAVE_GETUID) && defined(HAVE_GETEUID)
74 if ((getuid() != geteuid()) || (!(s = getenv("XDG_RUNTIME_DIR"))))
75#else
76 if (!(s = getenv("XDG_RUNTIME_DIR")))
77#endif
78 user.run = NULL;
79 else
80 user.run = s;
81
82 eina_vpath_interface_user_set(&user);
83}