]> git.saurik.com Git - wxWidgets.git/blob - src/unix/stdpaths.cpp
don't use negative sizes for row/column labels subwindows to avoid GTK warnings ...
[wxWidgets.git] / src / unix / stdpaths.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: unix/stdpaths.cpp
3 // Purpose: wxStandardPaths implementation for Unix & OpenVMS systems
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 2004-10-19
7 // RCS-ID: $Id$
8 // Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_STDPATHS
28
29 #include "wx/stdpaths.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/utils.h"
33 #endif //WX_PRECOMP
34
35 #include "wx/filename.h"
36
37 #if defined( __LINUX__ ) || defined( __VMS )
38 #include <unistd.h>
39 #endif
40
41 // ============================================================================
42 // common VMS/Unix part of wxStandardPaths implementation
43 // ============================================================================
44
45 void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
46 {
47 m_prefix = prefix;
48 }
49
50 wxString wxStandardPaths::GetUserConfigDir() const
51 {
52 return wxFileName::GetHomeDir();
53 }
54
55 // ============================================================================
56 // wxStandardPaths implementation for VMS
57 // ============================================================================
58
59 #ifdef __VMS
60
61 wxString wxStandardPaths::GetInstallPrefix() const
62 {
63 if ( m_prefix.empty() )
64 {
65 wx_const_cast(wxStandardPaths *, this)->m_prefix = wxT("/sys$system");
66 }
67
68 return m_prefix;
69 }
70
71 wxString wxStandardPaths::GetConfigDir() const
72 {
73 return _T("/sys$manager");
74 }
75
76 wxString wxStandardPaths::GetDataDir() const
77 {
78 return AppendAppInfo(GetInstallPrefix() + _T("/sys$share"));
79 }
80
81 wxString wxStandardPaths::GetLocalDataDir() const
82 {
83 return AppendAppInfo(_T("/sys$manager"));
84 }
85
86 wxString wxStandardPaths::GetUserDataDir() const
87 {
88 return wxFileName::GetHomeDir();
89 }
90
91 wxString wxStandardPaths::GetPluginsDir() const
92 {
93 return wxString(); // TODO: this is wrong, it should return something
94 }
95
96 wxString
97 wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
98 ResourceCat category) const
99 {
100 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
101 }
102
103 wxString wxStandardPaths::GetExecutablePath() const
104 {
105 return wxStandardPathsBase::GetExecutablePath();
106 }
107
108 #else // !__VMS
109
110 // ============================================================================
111 // wxStandardPaths implementation for Unix
112 // ============================================================================
113
114 wxString wxStandardPaths::GetExecutablePath() const
115 {
116 #ifdef __LINUX__
117 wxString exeStr;
118
119 char buf[4096];
120 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
121 if ( result != -1 )
122 {
123 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
124
125 // if the /proc/self/exe symlink has been dropped by the kernel for
126 // some reason, then readlink() could also return success but
127 // "(deleted)" as link destination...
128 if ( strcmp(buf, "(deleted)") != 0 )
129 exeStr = wxString(buf, wxConvLibc);
130 }
131
132 if ( exeStr.empty() )
133 {
134 // UPX-specific hack: when using UPX on linux, the kernel will drop the
135 // /proc/self/exe link; in this case we try to look for a special
136 // environment variable called " " which is created by UPX to save
137 // /proc/self/exe contents. See
138 // http://sf.net/tracker/?func=detail&atid=309863&aid=1565357&group_id=9863
139 // for more information about this issue.
140 wxGetEnv(wxT(" "), &exeStr);
141 }
142
143 if ( !exeStr.empty() )
144 return exeStr;
145 #endif // __LINUX__
146
147 return wxStandardPathsBase::GetExecutablePath();
148 }
149
150 void wxStandardPaths::DetectPrefix()
151 {
152 // we can try to infer the prefix from the location of the executable
153 wxString exeStr = GetExecutablePath();
154 if ( !exeStr.empty() )
155 {
156 // consider that we're in the last "bin" subdirectory of our prefix
157 size_t pos = exeStr.rfind(wxT("/bin/"));
158 if ( pos != wxString::npos )
159 m_prefix.assign(exeStr, 0, pos);
160 }
161
162 if ( m_prefix.empty() )
163 {
164 m_prefix = wxT("/usr/local");
165 }
166 }
167
168 wxString wxStandardPaths::GetInstallPrefix() const
169 {
170 if ( m_prefix.empty() )
171 {
172 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
173 pathPtr->DetectPrefix();
174 }
175
176 return m_prefix;
177 }
178
179 // ----------------------------------------------------------------------------
180 // public functions
181 // ----------------------------------------------------------------------------
182
183 wxString wxStandardPaths::GetConfigDir() const
184 {
185 return _T("/etc");
186 }
187
188 wxString wxStandardPaths::GetDataDir() const
189 {
190 return AppendAppInfo(GetInstallPrefix() + _T("/share"));
191 }
192
193 wxString wxStandardPaths::GetLocalDataDir() const
194 {
195 return AppendAppInfo(_T("/etc"));
196 }
197
198 wxString wxStandardPaths::GetUserDataDir() const
199 {
200 return AppendAppInfo(wxFileName::GetHomeDir() + _T("/."));
201 }
202
203 wxString wxStandardPaths::GetPluginsDir() const
204 {
205 return AppendAppInfo(GetInstallPrefix() + _T("/lib"));
206 }
207
208 wxString
209 wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
210 ResourceCat category) const
211 {
212 if ( category != ResourceCat_Messages )
213 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
214
215 return GetInstallPrefix() + _T("/share/locale/") + lang + _T("/LC_MESSAGES");
216 }
217
218 #endif // __VMS/!__VMS
219
220 #endif // wxUSE_STDPATHS