]> git.saurik.com Git - wxWidgets.git/blame - src/unix/stdpaths.cpp
use SubclassWin() insteaf of just wxAssociateWinWithHandle() to make sure we generate...
[wxWidgets.git] / src / unix / stdpaths.cpp
CommitLineData
c320b3e3
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: unix/stdpaths.cpp
a98ce49a 3// Purpose: wxStandardPaths implementation for Unix & OpenVMS systems
c320b3e3
VZ
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
07158944
VZ
27#if wxUSE_STDPATHS
28
c320b3e3
VZ
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
a98ce49a 37#if defined( __LINUX__ ) || defined( __VMS )
c320b3e3
VZ
38 #include <unistd.h>
39#endif
40
41// ============================================================================
d3b9c627 42// common VMS/Unix part of wxStandardPaths implementation
c320b3e3
VZ
43// ============================================================================
44
c320b3e3
VZ
45void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
46{
47 m_prefix = prefix;
48}
49
d3b9c627
VZ
50wxString wxStandardPaths::GetUserConfigDir() const
51{
52 return wxFileName::GetHomeDir();
53}
54
d3b9c627
VZ
55// ============================================================================
56// wxStandardPaths implementation for VMS
57// ============================================================================
58
59#ifdef __VMS
60
61wxString wxStandardPaths::GetInstallPrefix() const
62{
63 if ( m_prefix.empty() )
64 {
65 wx_const_cast(wxStandardPaths *, this)->m_prefix = wxT("/sys$system");
66 }
cc4d9903
VZ
67
68 return m_prefix;
d3b9c627
VZ
69}
70
71wxString wxStandardPaths::GetConfigDir() const
72{
73 return _T("/sys$manager");
74}
75
76wxString wxStandardPaths::GetDataDir() const
77{
78 return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
79}
80
81wxString wxStandardPaths::GetLocalDataDir() const
82{
83 return AppendAppName(_T("/sys$manager"));
84}
85
86wxString wxStandardPaths::GetUserDataDir() const
87{
88 return wxFileName::GetHomeDir();
89}
90
cc4d9903
VZ
91wxString wxStandardPaths::GetPluginsDir() const
92{
93 return wxString(); // TODO: this is wrong, it should return something
94}
95
3af9f2de
VZ
96wxString
97wxStandardPaths::GetLocalizedResourcesDir(const wxChar *lang,
98 ResourceCat category) const
99{
100 return wxStandardPathsBase::GetLocalizedResourcesDir(lang, category);
101}
102
d3b9c627
VZ
103#else // !__VMS
104
105// ============================================================================
106// wxStandardPaths implementation for Unix
107// ============================================================================
108
c320b3e3
VZ
109wxString wxStandardPaths::GetInstallPrefix() const
110{
d5437b85 111 if ( m_prefix.empty() )
c320b3e3 112 {
74ebd406 113 wxStandardPaths *pathPtr = wx_const_cast(wxStandardPaths *, this);
c320b3e3
VZ
114
115#ifdef __LINUX__
d5437b85
VZ
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 )
c320b3e3 121 {
d5437b85
VZ
122 buf[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
123
300ff33d 124 const wxString exeStr(buf, wxConvLibc);
c39e7599 125
c320b3e3 126 // consider that we're in the last "bin" subdirectory of our prefix
300ff33d 127 size_t pos = exeStr.rfind(wxT("/bin/"));
d5437b85
VZ
128 if ( pos != wxString::npos )
129 pathPtr->m_prefix.assign(exeStr, 0, pos);
c320b3e3 130 }
c320b3e3 131#endif // __LINUX__
74ebd406 132
d5437b85 133 if ( m_prefix.empty() )
c320b3e3 134 {
d5437b85 135 pathPtr->m_prefix = wxT("/usr/local");
c320b3e3
VZ
136 }
137 }
138
139 return m_prefix;
140}
141
142// ----------------------------------------------------------------------------
143// public functions
144// ----------------------------------------------------------------------------
145
146wxString wxStandardPaths::GetConfigDir() const
147{
a98ce49a 148 return _T("/etc");
c320b3e3
VZ
149}
150
151wxString wxStandardPaths::GetDataDir() const
152{
a98ce49a 153 return AppendAppName(GetInstallPrefix() + _T("/share"));
c320b3e3
VZ
154}
155
156wxString wxStandardPaths::GetLocalDataDir() const
157{
a98ce49a 158 return AppendAppName(_T("/etc"));
c320b3e3
VZ
159}
160
161wxString wxStandardPaths::GetUserDataDir() const
162{
a98ce49a 163 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
c320b3e3
VZ
164}
165
cc4d9903
VZ
166wxString wxStandardPaths::GetPluginsDir() const
167{
168 return AppendAppName(GetInstallPrefix() + _T("/lib"));
169}
170
3af9f2de
VZ
171wxString
172wxStandardPaths::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
d3b9c627 181#endif // __VMS/!__VMS
c320b3e3 182
07158944 183#endif // wxUSE_STDPATHS