]> git.saurik.com Git - wxWidgets.git/blob - src/unix/stdpaths.cpp
fix DoSetSelection(): it did nothing when there was no old selection
[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 #ifndef WX_PRECOMP
30 #include "wx/app.h"
31 #endif //WX_PRECOMP
32
33 #include "wx/filename.h"
34
35 #include "wx/stdpaths.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 AppendAppName(GetInstallPrefix() + _T("/sys$share"));
79 }
80
81 wxString wxStandardPaths::GetLocalDataDir() const
82 {
83 return AppendAppName(_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 wxChar *lang,
98 ResourceCat category) const
99 {
100 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
101 }
102
103 #else // !__VMS
104
105 // ============================================================================
106 // wxStandardPaths implementation for Unix
107 // ============================================================================
108
109 wxString wxStandardPaths::GetInstallPrefix() const
110 {
111 if ( m_prefix.empty() )
112 {
113 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
114
115 #ifdef __LINUX__
116 // under Linux, we can try to infer the prefix from the location of the
117 // executable
118 char buf[4096];
119 int result = readlink("/proc/self/exe", buf, WXSIZEOF(buf) - sizeof(char));
120 if ( result != -1 )
121 {
122 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
123
124 const wxString exeStr(buf, wxConvLibc);
125
126 // consider that we're in the last "bin" subdirectory of our prefix
127 size_t pos = exeStr.rfind(wxT("/bin/"));
128 if ( pos != wxString::npos )
129 pathPtr->m_prefix.assign(exeStr, 0, pos);
130 }
131 #endif // __LINUX__
132
133 if ( m_prefix.empty() )
134 {
135 pathPtr->m_prefix = wxT("/usr/local");
136 }
137 }
138
139 return m_prefix;
140 }
141
142 // ----------------------------------------------------------------------------
143 // public functions
144 // ----------------------------------------------------------------------------
145
146 wxString wxStandardPaths::GetConfigDir() const
147 {
148 return _T("/etc");
149 }
150
151 wxString wxStandardPaths::GetDataDir() const
152 {
153 return AppendAppName(GetInstallPrefix() + _T("/share"));
154 }
155
156 wxString wxStandardPaths::GetLocalDataDir() const
157 {
158 return AppendAppName(_T("/etc"));
159 }
160
161 wxString wxStandardPaths::GetUserDataDir() const
162 {
163 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
164 }
165
166 wxString wxStandardPaths::GetPluginsDir() const
167 {
168 return AppendAppName(GetInstallPrefix() + _T("/lib"));
169 }
170
171 wxString
172 wxStandardPaths::GetLocalizedResourcesDir(const wxChar *lang,
173 ResourceCat category) const
174 {
175 if ( category != ResourceCat_Messages )
176 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
177
178 return GetInstallPrefix() + _T("/share/locale/") + lang + _T("/LC_MESSAGES");
179 }
180
181 #endif // __VMS/!__VMS
182
183 #endif // wxUSE_STDPATHS