]> git.saurik.com Git - wxWidgets.git/blob - src/osx/core/stdpaths_cf.cpp
Set missing Language: headers in PO files.
[wxWidgets.git] / src / osx / core / stdpaths_cf.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/core/stdpaths_cf.cpp
3 // Purpose: wxStandardPaths implementation for CoreFoundation systems
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2004-10-27
7 // Copyright: (c) 2004 David Elliott <dfe@cox.net>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #include "wx/wxprec.h"
20
21 #if wxUSE_STDPATHS
22
23 #ifndef WX_PRECOMP
24 #include "wx/intl.h"
25 #endif //ndef WX_PRECOMP
26
27 #include "wx/stdpaths.h"
28 #include "wx/filename.h"
29 #ifdef __WXMAC__
30 #include "wx/osx/private.h"
31 #endif
32 #include "wx/osx/core/cfstring.h"
33
34 #include <CoreFoundation/CFBundle.h>
35 #include <CoreFoundation/CFURL.h>
36
37 #define kDefaultPathStyle kCFURLPOSIXPathStyle
38
39 // ============================================================================
40 // implementation
41 // ============================================================================
42
43 // ----------------------------------------------------------------------------
44 // wxStandardPathsCF ctors/dtor
45 // ----------------------------------------------------------------------------
46
47 wxStandardPathsCF::wxStandardPathsCF()
48 : m_bundle(CFBundleGetMainBundle())
49 {
50 CFRetain(m_bundle);
51 }
52
53 wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle)
54 : m_bundle(bundle)
55 {
56 CFRetain(m_bundle);
57 }
58
59 wxStandardPathsCF::~wxStandardPathsCF()
60 {
61 CFRelease(m_bundle);
62 }
63
64 // ----------------------------------------------------------------------------
65 // wxStandardPathsCF Mac-specific methods
66 // ----------------------------------------------------------------------------
67
68 void wxStandardPathsCF::SetBundle(wxCFBundleRef bundle)
69 {
70 CFRetain(bundle);
71 CFRelease(m_bundle);
72 m_bundle = bundle;
73 }
74
75 // ----------------------------------------------------------------------------
76 // generic functions in terms of which the other ones are implemented
77 // ----------------------------------------------------------------------------
78
79 static wxString BundleRelativeURLToPath(CFURLRef relativeURL)
80 {
81 CFURLRef absoluteURL = CFURLCopyAbsoluteURL(relativeURL);
82 wxCHECK_MSG(absoluteURL, wxEmptyString, wxT("Failed to resolve relative URL to absolute URL"));
83 CFStringRef cfStrPath = CFURLCopyFileSystemPath(absoluteURL,kDefaultPathStyle);
84 CFRelease(absoluteURL);
85 return wxCFStringRef::AsStringWithNormalizationFormC(cfStrPath);
86 }
87
88 wxString wxStandardPathsCF::GetFromFunc(wxCFURLRef (*func)(wxCFBundleRef)) const
89 {
90 wxCHECK_MSG(m_bundle, wxEmptyString,
91 wxT("wxStandardPaths for CoreFoundation only works with bundled apps"));
92 CFURLRef relativeURL = (*func)(m_bundle);
93 wxCHECK_MSG(relativeURL, wxEmptyString, wxT("Couldn't get URL"));
94 wxString ret(BundleRelativeURLToPath(relativeURL));
95 CFRelease(relativeURL);
96 return ret;
97 }
98
99 wxString wxStandardPathsCF::GetDocumentsDir() const
100 {
101 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
102 return wxMacFindFolderNoSeparator
103 (
104 kUserDomain,
105 kDocumentsFolderType,
106 kCreateFolder
107 );
108 #else
109 return wxFileName::GetHomeDir() + wxT("/Documents");
110 #endif
111 }
112
113 // ----------------------------------------------------------------------------
114 // wxStandardPathsCF public API
115 // ----------------------------------------------------------------------------
116
117 wxString wxStandardPathsCF::GetConfigDir() const
118 {
119 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
120 return wxMacFindFolderNoSeparator((short)kLocalDomain, kPreferencesFolderType, kCreateFolder);
121 #else
122 return wxT("/Library/Preferences");
123 #endif
124 }
125
126 wxString wxStandardPathsCF::GetUserConfigDir() const
127 {
128 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
129 return wxMacFindFolderNoSeparator((short)kUserDomain, kPreferencesFolderType, kCreateFolder);
130 #else
131 return wxFileName::GetHomeDir() + wxT("/Library/Preferences");
132 #endif
133 }
134
135 wxString wxStandardPathsCF::GetDataDir() const
136 {
137 return GetFromFunc(CFBundleCopySharedSupportURL);
138 }
139
140 wxString wxStandardPathsCF::GetExecutablePath() const
141 {
142 #ifdef __WXMAC__
143 return GetFromFunc(CFBundleCopyExecutableURL);
144 #else
145 return wxStandardPathsBase::GetExecutablePath();
146 #endif
147 }
148
149 wxString wxStandardPathsCF::GetLocalDataDir() const
150 {
151 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
152 return AppendAppInfo(wxMacFindFolderNoSeparator((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder));
153 #else
154 return AppendAppInfo(wxT("/Library/Application Support"));
155 #endif
156 }
157
158 wxString wxStandardPathsCF::GetUserDataDir() const
159 {
160 #if defined( __WXMAC__ ) && wxOSX_USE_CARBON
161 return AppendAppInfo(wxMacFindFolderNoSeparator((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder));
162 #else
163 return AppendAppInfo(wxFileName::GetHomeDir() + wxT("/Library/Application Support"));
164 #endif
165 }
166
167 wxString wxStandardPathsCF::GetPluginsDir() const
168 {
169 return GetFromFunc(CFBundleCopyBuiltInPlugInsURL);
170 }
171
172 wxString wxStandardPathsCF::GetResourcesDir() const
173 {
174 return GetFromFunc(CFBundleCopyResourcesDirectoryURL);
175 }
176
177 wxString
178 wxStandardPathsCF::GetLocalizedResourcesDir(const wxString& lang,
179 ResourceCat category) const
180 {
181 return wxStandardPathsBase::
182 GetLocalizedResourcesDir(lang, category) + wxT(".lproj");
183 }
184
185 #endif // wxUSE_STDPATHS