]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/volume.cpp
clean-up and fix
[wxWidgets.git] / src / palmos / volume.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/volume.cpp
3 // Purpose: wxFSVolume - encapsulates system volume information
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by:
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_FSVOLUME
27
28 #ifndef WX_PRECOMP
29 #if wxUSE_GUI
30 #include "wx/icon.h"
31 #endif
32 #include "wx/intl.h"
33 #endif // WX_PRECOMP
34
35 #include "wx/arrstr.h"
36 #include "wx/volume.h"
37
38 #include <VFSMgr.h>
39 #include <PalmTypesCompatibility.h>
40
41 #if wxUSE_BASE
42
43 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
44 // Globals/Statics
45 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
46 static long s_cancelSearch = FALSE;
47
48 struct FileInfo
49 {
50 FileInfo(unsigned flag=0, wxFSVolumeKind type=wxFS_VOL_OTHER) :
51 m_flags(flag), m_type(type) {}
52
53 FileInfo(const FileInfo& other) { *this = other; }
54 FileInfo& operator=(const FileInfo& other)
55 {
56 m_flags = other.m_flags;
57 m_type = other.m_type;
58 return *this;
59 }
60
61 unsigned m_flags;
62 wxFSVolumeKind m_type;
63 };
64
65 WX_DECLARE_STRING_HASH_MAP(FileInfo, FileInfoMap);
66
67 // Cygwin bug (?) destructor for global s_fileInfo is called twice...
68 static FileInfoMap& GetFileInfoMap()
69 {
70 static FileInfoMap s_fileInfo(25);
71
72 return s_fileInfo;
73 }
74 #define s_fileInfo (GetFileInfoMap())
75
76 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77 // Local helper functions.
78 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
79
80 //=============================================================================
81 // Function: GetBasicFlags
82 // Purpose: Set basic flags, primarily wxFS_VOL_REMOTE and wxFS_VOL_REMOVABLE.
83 // Notes: - Local and mapped drives are mounted by definition. We have no
84 // way to determine mounted status of network drives, so assume that
85 // all drives are mounted, and let the caller decide otherwise.
86 // - Other flags are 'best guess' from type of drive. The system will
87 // not report the file attributes with any degree of accuracy.
88 //=============================================================================
89 static unsigned GetBasicFlags(const wxChar* filename)
90 {
91 unsigned flags = wxFS_VOL_MOUNTED;
92
93 return flags;
94 } // GetBasicFlags
95
96 //=============================================================================
97 // Function: FilteredAdd
98 // Purpose: Add a file to the list if it meets the filter requirement.
99 // Notes: - See GetBasicFlags for remarks about the Mounted flag.
100 //=============================================================================
101 static bool FilteredAdd(wxArrayString& list, const wxChar* filename,
102 unsigned flagsSet, unsigned flagsUnset)
103 {
104 return false;
105 } // FilteredAdd
106
107 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
108 // wxFSVolume
109 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
110
111 //=============================================================================
112 // Function: GetVolumes
113 // Purpose: Generate and return a list of all volumes (drives) available.
114 // Notes:
115 //=============================================================================
116 wxArrayString wxFSVolumeBase::GetVolumes(int flagsSet, int flagsUnset)
117 {
118 wxArrayString list;
119
120 UInt16 refNum;
121 UInt32 it = vfsIteratorStart;
122
123 while (it != vfsIteratorStop)
124 {
125 status_t err = VFSVolumeEnumerate(&refNum, &it);
126 if (err == errNone)
127 {
128 // manual: "Volume labels can be up to 255 characters long."
129 char label[256];
130 err = VFSVolumeGetLabel(refNum,label,256);
131 if (err == errNone)
132 {
133 list.Add(wxString::FromAscii(label));
134 }
135 }
136
137 if (err != errNone)
138 break;
139 }
140
141 return list;
142 } // GetVolumes
143
144 //=============================================================================
145 // Function: CancelSearch
146 // Purpose: Instruct an active search to stop.
147 // Notes: - This will only sensibly be called by a thread other than the one
148 // performing the search. This is the only thread-safe function
149 // provided by the class.
150 //=============================================================================
151 void wxFSVolumeBase::CancelSearch()
152 {
153 } // CancelSearch
154
155 //=============================================================================
156 // Function: constructor
157 // Purpose: default constructor
158 //=============================================================================
159 wxFSVolumeBase::wxFSVolumeBase()
160 {
161 } // wxVolume
162
163 //=============================================================================
164 // Function: constructor
165 // Purpose: constructor that calls Create
166 //=============================================================================
167 wxFSVolumeBase::wxFSVolumeBase(const wxString& name)
168 {
169 } // wxVolume
170
171 //=============================================================================
172 // Function: Create
173 // Purpose: Finds, logs in, etc. to the request volume.
174 //=============================================================================
175 bool wxFSVolumeBase::Create(const wxString& name)
176 {
177 return false;
178 } // Create
179
180 //=============================================================================
181 // Function: IsOk
182 // Purpose: returns true if the volume is legal.
183 // Notes: For fixed disks, it must exist. For removable disks, it must also
184 // be present. For Network Shares, it must also be logged in, etc.
185 //=============================================================================
186 bool wxFSVolumeBase::IsOk() const
187 {
188 return false;
189 } // IsOk
190
191 //=============================================================================
192 // Function: GetKind
193 // Purpose: Return the type of the volume.
194 //=============================================================================
195 wxFSVolumeKind wxFSVolumeBase::GetKind() const
196 {
197 return wxFS_VOL_OTHER;
198 }
199
200 //=============================================================================
201 // Function: GetFlags
202 // Purpose: Return the caches flags for this volume.
203 // Notes: - Returns -1 if no flags were cached.
204 //=============================================================================
205 int wxFSVolumeBase::GetFlags() const
206 {
207 return -1;
208 } // GetFlags
209
210 #endif // wxUSE_BASE
211
212 // ============================================================================
213 // wxFSVolume
214 // ============================================================================
215
216 #if wxUSE_GUI
217
218 void wxFSVolume::InitIcons()
219 {
220 }
221
222 //=============================================================================
223 // Function: GetIcon
224 // Purpose: return the requested icon.
225 //=============================================================================
226
227 wxIcon wxFSVolume::GetIcon(wxFSIconType type) const
228 {
229 return m_icons[type];
230 } // GetIcon
231
232 #endif // wxUSE_GUI
233
234 #endif // wxUSE_FSVOLUME
235