From: VMware, Inc <> Date: Mon, 26 Jul 2010 18:30:04 +0000 (-0700) Subject: Show folder icon when dragging directories X-Git-Tag: 2010.07.25-280253~79 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=02b667f6464aee172c0d22df4cc4dfc69524ef31;p=thirdparty%2Fopen-vm-tools.git Show folder icon when dragging directories When dragging a folder from the guest to the host we would show the wrong icon next to the cursor. The problem was that there was no way to tell if dragged object was a file or a folder. Fix was to incldue file attributes with the drag information. Note, this change only implements file attributes for Windows tools. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/dndGuest/dndFileList.cc b/open-vm-tools/lib/dndGuest/dndFileList.cc index bc0d8ceec..a2d8123c5 100644 --- a/open-vm-tools/lib/dndGuest/dndFileList.cc +++ b/open-vm-tools/lib/dndGuest/dndFileList.cc @@ -201,6 +201,38 @@ DnDFileList::AddFiles(const std::vector fullPathList, // IN: filena } +/* + *---------------------------------------------------------------------------- + * + * DnDFileList::AddFileAttributes -- + * + * Adds files attributes. + * + * Will not add attributes if the file list was created from a clipboard + * buffer. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------------- + */ + +void +DnDFileList::AddFileAttributes(const CPFileAttributes& attributes) // IN +{ + ASSERT(mFullPathsBinary.empty()); + + if (!mFullPathsBinary.empty()) { + return; + } + + mAttributeList.push_back(attributes); +} + + /* *---------------------------------------------------------------------------- * @@ -274,6 +306,30 @@ DnDFileList::GetRelPaths() const } +/* + *---------------------------------------------------------------------------- + * + * DnDFileList::GetFileAttributes -- + * + * Gets a vector containing file attributes. + * + * Results: + * File attributes. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------------- + */ + +std::vector +DnDFileList::GetFileAttributes() + const +{ + return mAttributeList; +} + + /* *---------------------------------------------------------------------------- * @@ -444,6 +500,45 @@ DnDFileList::FromCPClipboard(const void *buf, // IN: Source buffer } +/* + *---------------------------------------------------------------------------- + * + * DnDFileList::AttributesFromCPClipboard -- + * + * Loads the attribute list from a buffer, typically from CPClipboard. + * + * Results: + * None. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------------- + */ + +bool +DnDFileList::AttributesFromCPClipboard(const void *buf, // IN: Source buffer + size_t len) // IN: Buffer length +{ + const CPAttributeList *alist; + + ASSERT(buf); + ASSERT(len); + if (!buf || !len) { + return false; + } + + alist = reinterpret_cast(buf); + + mAttributeList.resize(alist->attributesLen); + for (uint32 i = 0; i < alist->attributesLen; i++) { + mAttributeList[i] = alist->attributeList[i]; + } + + return true; +} + + /* *---------------------------------------------------------------------------- * @@ -538,6 +633,45 @@ DnDFileList::ToUriClipboard(DynBuf *out) // OUT: Initialized output buffer } +/* + *---------------------------------------------------------------------------- + * + * DnDFileList::AttributesToCPClipboard -- + * + * Serializes attributes for CPClipboard in Attributes Format. + * + * Results: + * false on error, true on success. + * + * Side effects: + * None. + * + *---------------------------------------------------------------------------- + */ + +bool +DnDFileList::AttributesToCPClipboard(DynBuf *out) // IN + const +{ + CPAttributeList header; + + if (!out) { + return false; + } + + header.attributesLen = mAttributeList.size(); + + DynBuf_Append(out, &header, URI_ATTRIBUTES_LIST_HEADER_SIZE); + if (header.attributesLen > 0) { + DynBuf_Append(out, + &mAttributeList[0], + header.attributesLen * sizeof(CPFileAttributes)); + } + + return true; +} + + /* *---------------------------------------------------------------------------- * @@ -560,6 +694,7 @@ DnDFileList::Clear() mRelPaths.clear(); mFullPaths.clear(); mUriPaths.clear(); + mAttributeList.clear(); mFullPathsBinary.clear(); mFileSize = 0; } diff --git a/open-vm-tools/lib/include/dnd.h b/open-vm-tools/lib/include/dnd.h index 1af756e7a..ddf5d99f0 100644 --- a/open-vm-tools/lib/include/dnd.h +++ b/open-vm-tools/lib/include/dnd.h @@ -105,6 +105,7 @@ typedef enum CPFORMAT_FILELIST_URI, CPFORMAT_FILECONTENTS, CPFORMAT_IMG_PNG, + CPFORMAT_FILEATTRIBUTES, CPFORMAT_MAX, } DND_CPFORMAT; diff --git a/open-vm-tools/lib/include/dndClipboard.h b/open-vm-tools/lib/include/dndClipboard.h index 9fa390cfd..fb02a6cdc 100644 --- a/open-vm-tools/lib/include/dndClipboard.h +++ b/open-vm-tools/lib/include/dndClipboard.h @@ -73,6 +73,28 @@ UriFileList; #define URI_FILELIST_HEADER_SIZE (1* sizeof(uint64) + 1 * sizeof(uint32)) +typedef +#include "vmware_pack_begin.h" +struct CPFileAttributes { + // File, Directory, or link. See HgfsFileType. + uint64 fileType; + // Read, write, execute permissions. See File_GetFilePermissions(). + uint64 filePermissions; +} +#include "vmware_pack_end.h" +CPFileAttributes; + +typedef +#include "vmware_pack_begin.h" +struct CPAttributeList { + uint32 attributesLen; + CPFileAttributes attributeList[1]; +} +#include "vmware_pack_end.h" +CPAttributeList; + +#define URI_ATTRIBUTES_LIST_HEADER_SIZE (1* sizeof(uint32)) + /* Types which can be stored on the clipboard. */ /* * XXX diff --git a/open-vm-tools/lib/include/dndFileList.hh b/open-vm-tools/lib/include/dndFileList.hh index e43035026..9a81dcdc2 100644 --- a/open-vm-tools/lib/include/dndFileList.hh +++ b/open-vm-tools/lib/include/dndFileList.hh @@ -30,6 +30,7 @@ extern "C" { #include "vm_basic_types.h" +#include "dndClipboard.h" #include "dynbuf.h" } @@ -45,6 +46,7 @@ class DnDFileList { void AddFileUri(const std::string uriPath); void AddFiles(const std::vector fullPathList, const std::vector relPathList); + void AddFileAttributes(const CPFileAttributes& attributes); /* Copy paste/dndV2 V2 rpc */ void SetRelPathsStr(const std::string inpath); @@ -56,11 +58,14 @@ class DnDFileList { /* UI Local clipboard */ std::vector GetRelPaths() const; + std::vector GetFileAttributes() const; /* CPClipboard */ bool ToCPClipboard(DynBuf *out, bool local) const; bool ToUriClipboard(DynBuf *out) const; + bool AttributesToCPClipboard(DynBuf *out) const; bool FromCPClipboard(const void *buf, size_t len); + bool AttributesFromCPClipboard(const void *buf, size_t len); void Clear(); @@ -69,6 +74,7 @@ class DnDFileList { std::vector mRelPaths; std::vector mFullPaths; std::vector mUriPaths; + std::vector mAttributeList; std::string mFullPathsBinary; uint64 mFileSize; };