Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
6.2 KiB

  1. #ifndef _INC_DSKQUOTA_OWNERLST_H
  2. #define _INC_DSKQUOTA_OWNERLST_H
  3. #ifndef _INC_DSKQUOTA_STRCLASS_H
  4. # include "strclass.h"
  5. #endif
  6. #ifndef _INC_DSKQUOTA_CARRAY_H
  7. # include "carray.h"
  8. #endif
  9. #ifndef _INC_DSKQUOTA_H
  10. # include <dskquota.h>
  11. #endif
  12. //-----------------------------------------------------------------------------
  13. // The following classes are used in managing the list of files owned by
  14. // one or more users selected for deletion from within the details view.
  15. //
  16. // COwnerList - A list of "owner" objects. Each representing one of the
  17. // account selected for deletion from the details view.
  18. //
  19. // COwnerListEntry - A single entry in the COwnerList container. Each
  20. // entry contains a pointer to the IDiskQuotaUser inteface of the
  21. // file owner and an array of CStrings containing the names of the
  22. // files owned by that user. A blank filename is considered "deleted".
  23. //
  24. // COwnerListFile - A simple derivation from CPath that adds a 'directory'
  25. // boolean member. This allows us to easily handle the differences
  26. // between files and folders in the UI. For all intents and purposes,
  27. // instances of this class can be treated as a simple CPath object.
  28. //
  29. // COwnerListItemHandle - This is a simple class used to hide the encoding
  30. // of the owner index and file index in a listview LPARAM value. The
  31. // owner index is the index of the LV item's owner in the COwnerList
  32. // container. The file index is the index of the item's filename in the
  33. // owner's COwnerListEntry in the COwnerList container. Perfectly clear,
  34. // right? Each listview item's LPARAM contains enough information
  35. // (iOwner and iFile) to locate the owner and file information in the
  36. // COwnerList container. This encoding was done for efficiency reasons.
  37. // The encoding is currently 10 bits for iOwner (max of 1024) and 22
  38. // bits for iFile (max of 4 meg). These values can be adjusted if
  39. // the balance isn't quite right.
  40. //
  41. //
  42. class COwnerListFile : public CPath
  43. {
  44. public:
  45. COwnerListFile(void)
  46. : m_bDirectory(false) { }
  47. COwnerListFile(LPCTSTR pszFile, bool bDirectory)
  48. : CPath(pszFile),
  49. m_bDirectory(bDirectory) { }
  50. bool IsDirectory(void) const
  51. { return m_bDirectory; }
  52. private:
  53. bool m_bDirectory;
  54. };
  55. class COwnerListEntry
  56. {
  57. public:
  58. explicit COwnerListEntry(IDiskQuotaUser *pOwner);
  59. ~COwnerListEntry(void)
  60. { if (m_pOwner) m_pOwner->Release(); }
  61. IDiskQuotaUser* GetOwner(void) const
  62. { m_pOwner->AddRef(); return m_pOwner; }
  63. void GetOwnerName(CString *pstrOwner) const
  64. { *pstrOwner = m_strOwnerName; }
  65. int AddFile(LPCTSTR pszFile, bool bDirectory);
  66. void MarkFileDeleted(int iFile)
  67. { m_rgFiles[iFile].Empty(); }
  68. bool IsFileDeleted(int iFile) const
  69. { return !!m_rgFiles[iFile].IsEmpty(); }
  70. bool IsFileDirectory(int iFile) const
  71. { return m_rgFiles[iFile].IsDirectory(); }
  72. void GetFileName(int iFile, CPath *pstrFile) const
  73. { m_rgFiles[iFile].GetFileSpec(pstrFile); }
  74. void GetFolderName(int iFile, CPath *pstrFolder) const
  75. { m_rgFiles[iFile].GetPath(pstrFolder); }
  76. void GetFileFullPath(int iFile, CPath *pstrFullPath) const
  77. { *pstrFullPath = m_rgFiles[iFile]; }
  78. int FileCount(bool bIncludeDeleted = false);
  79. #if DBG
  80. void Dump(void) const;
  81. #endif
  82. private:
  83. IDiskQuotaUser *m_pOwner; // Ptr to owner object.
  84. CString m_strOwnerName; // Owner's name for display.
  85. CArray<COwnerListFile> m_rgFiles; // Filenames for display.
  86. //
  87. // Prevent copy. Array makes it too expensive.
  88. //
  89. COwnerListEntry(const COwnerListEntry& rhs);
  90. COwnerListEntry& operator = (const COwnerListEntry& rhs);
  91. };
  92. class COwnerList
  93. {
  94. public:
  95. COwnerList(void) { }
  96. ~COwnerList(void);
  97. int AddOwner(IDiskQuotaUser *pOwner);
  98. IDiskQuotaUser *GetOwner(int iOwner) const;
  99. void GetOwnerName(int iOwner, CString *pstrOwner) const
  100. { m_rgpOwners[iOwner]->GetOwnerName(pstrOwner); }
  101. int AddFile(int iOwner, LPCTSTR pszFile, bool bDirectory)
  102. { return m_rgpOwners[iOwner]->AddFile(pszFile, bDirectory); }
  103. void MarkFileDeleted(int iOwner, int iFile)
  104. { m_rgpOwners[iOwner]->MarkFileDeleted(iFile); }
  105. bool IsFileDeleted(int iOwner, int iFile) const
  106. { return m_rgpOwners[iOwner]->IsFileDeleted(iFile); }
  107. bool IsFileDirectory(int iOwner, int iFile) const
  108. { return m_rgpOwners[iOwner]->IsFileDirectory(iFile); }
  109. void GetFileName(int iOwner, int iFile, CPath *pstrFile) const
  110. { m_rgpOwners[iOwner]->GetFileName(iFile, pstrFile); }
  111. void GetFolderName(int iOwner, int iFile, CPath *pstrFolder) const
  112. { m_rgpOwners[iOwner]->GetFolderName(iFile, pstrFolder); }
  113. void GetFileFullPath(int iOwner, int iFile, CPath *pstrFullPath) const
  114. { m_rgpOwners[iOwner]->GetFileFullPath(iFile, pstrFullPath); }
  115. void Clear(void);
  116. int FileCount(int iOwner = -1, bool bIncludeDeleted = false) const;
  117. int OwnerCount(void) const
  118. { return m_rgpOwners.Count(); }
  119. #if DBG
  120. void Dump(void) const;
  121. #endif
  122. private:
  123. CArray<COwnerListEntry *> m_rgpOwners;
  124. //
  125. // Prevent copy.
  126. //
  127. COwnerList(const COwnerList& rhs);
  128. COwnerList& operator = (const COwnerList& rhs);
  129. };
  130. class COwnerListItemHandle
  131. {
  132. public:
  133. explicit COwnerListItemHandle(int iOwner = -1, int iFile = -1)
  134. : m_handle((iOwner & MASK) | ((iFile << SHIFT) & ~MASK)) { }
  135. COwnerListItemHandle(LPARAM lParam)
  136. : m_handle(lParam) { }
  137. operator LPARAM() const
  138. { return m_handle; }
  139. int OwnerIndex(void) const
  140. { return int(m_handle & MASK); }
  141. int FileIndex(void) const
  142. { return int((m_handle >> SHIFT) & (~MASK >> SHIFT)); }
  143. private:
  144. LPARAM m_handle;
  145. enum { MASK = 0x3FF, SHIFT = 10 };
  146. };
  147. #endif // _INC_DSKQUOTA_OWNERLST_H