/* $Id: DragAndDrop.h 55422 2015-04-24 13:52:33Z vboxsync $ */ /** @file * DnD: Shared functions between host and guest. */ /* * Copyright (C) 2014 Oracle Corporation * * This file is part of VirtualBox Open Source Edition (OSE), as * available from http://www.virtualbox.org. This file is free software; * you can redistribute it and/or modify it under the terms of the GNU * General Public License (GPL) as published by the Free Software * Foundation, in version 2 as it comes in the "COPYING" file of the * VirtualBox OSE distribution. VirtualBox OSE is distributed in the * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. * * The contents of this file may alternatively be used under the terms * of the Common Development and Distribution License Version 1.0 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the * VirtualBox OSE distribution, in which case the provisions of the * CDDL are applicable instead of those of the GPL. * * You may elect to license modified versions of this file under the * terms and conditions of either the GPL or the CDDL or both. */ #ifndef ___VBox_GuestHost_DragAndDrop_h #define ___VBox_GuestHost_DragAndDrop_h #include #include #include #include #include #include #include int DnDDirCreateDroppedFilesEx(const char *pszPath, char *pszDropDir, size_t cbDropDir); int DnDDirCreateDroppedFiles(char *pszDropDir, size_t cbDropDir); bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax); bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax); int DnDPathSanitizeFilename(char *pszPath, size_t cbPath); int DnDPathSanitize(char *pszPath, size_t cbPath); /** Keep the original paths, don't convert paths to relative ones. */ #define DNDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0) class DnDURIObject { public: enum Type { Unknown = 0, File, Directory }; enum Dest { Source = 0, Target }; DnDURIObject(void); DnDURIObject(Type type, const RTCString &strSrcPath = "", const RTCString &strDstPath = "", uint32_t fMode = 0, uint64_t cbSize = 0); virtual ~DnDURIObject(void); public: const RTCString &GetSourcePath(void) const { return m_strSrcPath; } const RTCString &GetDestPath(void) const { return m_strTgtPath; } uint64_t GetMode(void) const { return m_fMode; } uint64_t GetProcessed(void) const { return m_cbProcessed; } uint64_t GetSize(void) const { return m_cbSize; } Type GetType(void) const { return m_Type; } public: int SetSize(uint64_t uSize) { m_cbSize = uSize; return VINF_SUCCESS; } public: void Close(void); bool IsComplete(void) const; bool IsOpen(void) const; int Open(Dest enmDest, uint64_t fOpen); int OpenEx(const RTCString &strPath, Type enmType, Dest enmDest, uint64_t fMode = 0, uint32_t fFlags = 0); int Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead); int Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten); public: static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld = "", const RTCString &strBaseNew = ""); protected: void closeInternal(void); protected: Type m_Type; RTCString m_strSrcPath; RTCString m_strTgtPath; /** File mode. */ uint64_t m_fMode; /** Size (in bytes) to read/write. */ uint64_t m_cbSize; /** Bytes processed reading/writing. */ uint64_t m_cbProcessed; union { RTFILE m_hFile; } u; }; class DnDURIList { public: DnDURIList(void); virtual ~DnDURIList(void); public: int AppendNativePath(const char *pszPath, uint32_t fFlags); int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, uint32_t fFlags); int AppendNativePathsFromList(const RTCList &lstNativePaths, uint32_t fFlags); int AppendURIPath(const char *pszURI, uint32_t fFlags); int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, uint32_t fFlags); int AppendURIPathsFromList(const RTCList &lstURI, uint32_t fFlags); void Clear(void); DnDURIObject &First(void) { return m_lstTree.first(); } bool IsEmpty(void) { return m_lstTree.isEmpty(); } void RemoveFirst(void); int RootFromURIData(const void *pvData, size_t cbData, uint32_t fFlags); RTCString RootToString(const RTCString &strBasePath = "", const RTCString &strSeparator = "\r\n"); size_t RootCount(void) { return m_lstRoot.size(); } size_t TotalBytes(void) { return m_cbTotal; } protected: int appendPathRecursive(const char *pcszPath, size_t cbBaseLen, uint32_t fFlags); protected: /** List of all top-level file/directory entries. * Note: All paths are kept internally as UNIX paths for * easier conversion/handling! */ RTCList m_lstRoot; /** List of all URI objects added. */ RTCList m_lstTree; /** Total size of all URI objects, that is, the file * size of all objects (in bytes). */ size_t m_cbTotal; }; #endif /* ___VBox_GuestHost_DragAndDrop_h */