volume.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/volume.h
  3. // Purpose: wxFSVolume - encapsulates system volume information
  4. // Author: George Policello
  5. // Modified by:
  6. // Created: 28 Jan 02
  7. // Copyright: (c) 2002 George Policello
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. // ----------------------------------------------------------------------------
  11. // wxFSVolume represents a volume/drive in a file system
  12. // ----------------------------------------------------------------------------
  13. #ifndef _WX_FSVOLUME_H_
  14. #define _WX_FSVOLUME_H_
  15. #include "wx/defs.h"
  16. #if wxUSE_FSVOLUME
  17. #include "wx/arrstr.h"
  18. // the volume flags
  19. enum wxFSVolumeFlags
  20. {
  21. // is the volume mounted?
  22. wxFS_VOL_MOUNTED = 0x0001,
  23. // is the volume removable (floppy, CD, ...)?
  24. wxFS_VOL_REMOVABLE = 0x0002,
  25. // read only? (otherwise read write)
  26. wxFS_VOL_READONLY = 0x0004,
  27. // network resources
  28. wxFS_VOL_REMOTE = 0x0008
  29. };
  30. // the volume types
  31. enum wxFSVolumeKind
  32. {
  33. wxFS_VOL_FLOPPY,
  34. wxFS_VOL_DISK,
  35. wxFS_VOL_CDROM,
  36. wxFS_VOL_DVDROM,
  37. wxFS_VOL_NETWORK,
  38. wxFS_VOL_OTHER,
  39. wxFS_VOL_MAX
  40. };
  41. class WXDLLIMPEXP_BASE wxFSVolumeBase
  42. {
  43. public:
  44. // return the array containing the names of the volumes
  45. //
  46. // only the volumes with the flags such that
  47. // (flags & flagsSet) == flagsSet && !(flags & flagsUnset)
  48. // are returned (by default, all mounted ones)
  49. static wxArrayString GetVolumes(int flagsSet = wxFS_VOL_MOUNTED,
  50. int flagsUnset = 0);
  51. // stop execution of GetVolumes() called previously (should be called from
  52. // another thread, of course)
  53. static void CancelSearch();
  54. // create the volume object with this name (should be one of those returned
  55. // by GetVolumes()).
  56. wxFSVolumeBase();
  57. wxFSVolumeBase(const wxString& name);
  58. bool Create(const wxString& name);
  59. // accessors
  60. // ---------
  61. // is this a valid volume?
  62. bool IsOk() const;
  63. // kind of this volume?
  64. wxFSVolumeKind GetKind() const;
  65. // flags of this volume?
  66. int GetFlags() const;
  67. // can we write to this volume?
  68. bool IsWritable() const { return !(GetFlags() & wxFS_VOL_READONLY); }
  69. // get the name of the volume and the name which should be displayed to the
  70. // user
  71. wxString GetName() const { return m_volName; }
  72. wxString GetDisplayName() const { return m_dispName; }
  73. // TODO: operatios (Mount(), Unmount(), Eject(), ...)?
  74. protected:
  75. // the internal volume name
  76. wxString m_volName;
  77. // the volume name as it is displayed to the user
  78. wxString m_dispName;
  79. // have we been initialized correctly?
  80. bool m_isOk;
  81. };
  82. #if wxUSE_GUI
  83. #include "wx/icon.h"
  84. #include "wx/iconbndl.h" // only for wxIconArray
  85. enum wxFSIconType
  86. {
  87. wxFS_VOL_ICO_SMALL = 0,
  88. wxFS_VOL_ICO_LARGE,
  89. wxFS_VOL_ICO_SEL_SMALL,
  90. wxFS_VOL_ICO_SEL_LARGE,
  91. wxFS_VOL_ICO_MAX
  92. };
  93. // wxFSVolume adds GetIcon() to wxFSVolumeBase
  94. class WXDLLIMPEXP_CORE wxFSVolume : public wxFSVolumeBase
  95. {
  96. public:
  97. wxFSVolume() : wxFSVolumeBase() { InitIcons(); }
  98. wxFSVolume(const wxString& name) : wxFSVolumeBase(name) { InitIcons(); }
  99. wxIcon GetIcon(wxFSIconType type) const;
  100. private:
  101. void InitIcons();
  102. // the different icons for this volume (created on demand)
  103. wxIconArray m_icons;
  104. };
  105. #else // !wxUSE_GUI
  106. // wxFSVolume is the same thing as wxFSVolume in wxBase
  107. typedef wxFSVolumeBase wxFSVolume;
  108. #endif // wxUSE_GUI/!wxUSE_GUI
  109. #endif // wxUSE_FSVOLUME
  110. #endif // _WX_FSVOLUME_H_