added wxUSE_STDPATHS
[wxWidgets.git] / src / unix / stdpaths.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: unix/stdpaths.cpp
3 // Purpose: wxStandardPaths implementation for Unix 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 #ifdef __LINUX__
38 #include <unistd.h>
39 #endif
40
41 // ============================================================================
42 // wxStandardPaths implementation
43 // ============================================================================
44
45 // ----------------------------------------------------------------------------
46 // prefix management
47 // ----------------------------------------------------------------------------
48
49 void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
50 {
51 m_prefix = prefix;
52 }
53
54 wxString wxStandardPaths::GetInstallPrefix() const
55 {
56 if ( m_prefix.empty() )
57 {
58 wxStandardPaths *self = wx_const_cast(wxStandardPaths *, this);
59
60 #ifdef __LINUX__
61 // under Linux, we can get location of the executable
62 char buf[4096];
63 if ( readlink("/proc/self/exe", buf, WXSIZEOF(buf)) != -1 )
64 {
65 wxString exe(buf, wxConvLibc);
66
67 // consider that we're in the last "bin" subdirectory of our prefix
68 wxString basename(wxString(wxTheApp->argv[0]).AfterLast(_T('/')));
69 size_t pos = exe.find(_T("/bin/") + basename);
70 if ( pos != wxString::npos )
71 {
72 self->m_prefix.assign(exe, 0, pos);
73 }
74 }
75
76 if ( m_prefix.empty() )
77 #endif // __LINUX__
78 {
79 self->m_prefix = _T("/usr/local");
80 }
81 }
82
83 return m_prefix;
84 }
85
86 // ----------------------------------------------------------------------------
87 // public functions
88 // ----------------------------------------------------------------------------
89
90 wxString wxStandardPaths::GetConfigDir() const
91 {
92 return _T("/etc");
93 }
94
95 wxString wxStandardPaths::GetUserConfigDir() const
96 {
97 return wxFileName::GetHomeDir();
98 }
99
100 wxString wxStandardPaths::GetDataDir() const
101 {
102 return AppendAppName(GetInstallPrefix() + _T("/share"));
103 }
104
105 wxString wxStandardPaths::GetLocalDataDir() const
106 {
107 return AppendAppName(_T("/etc"));
108 }
109
110 wxString wxStandardPaths::GetUserDataDir() const
111 {
112 return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
113 }
114
115 wxString wxStandardPaths::GetPluginsDir() const
116 {
117 return wxString();
118 }
119
120 #endif // wxUSE_STDPATHS