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