VirtualBox

source: vbox/trunk/include/VBox/GuestHost/DragAndDrop.h@ 56954

Last change on this file since 56954 was 56909, checked in by vboxsync, 10 years ago

DnD: Changed DnDURIList's allocation scheme for stored DnDURIObject objects.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.2 KB
Line 
1/* $Id: DragAndDrop.h 56909 2015-07-10 06:09:14Z vboxsync $ */
2/** @file
3 * DnD: Shared functions between host and guest.
4 */
5
6/*
7 * Copyright (C) 2014-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef ___VBox_GuestHost_DragAndDrop_h
28#define ___VBox_GuestHost_DragAndDrop_h
29
30#include <iprt/assert.h>
31#include <iprt/cdefs.h>
32#include <iprt/dir.h>
33#include <iprt/err.h>
34#include <iprt/file.h>
35#include <iprt/types.h>
36
37#include <iprt/cpp/list.h>
38#include <iprt/cpp/ministring.h>
39
40/**
41 * Structure for maintaining a "dropped files" directory
42 * on the host or guest. This will contain all received files & directories
43 * for a single drag and drop operation.
44 */
45typedef struct DNDDIRDROPPEDFILES
46{
47 /** Directory handle for drop directory. */
48 PRTDIR hDir;
49 /** Flag indicating whether the drop directory
50 * has been opened for processing or not. */
51 bool fOpen;
52 /** Absolute path to drop directory. */
53 RTCString strPathAbs;
54 /** List for holding created directories in the case of a rollback. */
55 RTCList<RTCString> lstDirs;
56 /** List for holding created files in the case of a rollback. */
57 RTCList<RTCString> lstFiles;
58
59} DNDDIRDROPPEDFILES, *PDNDDIRDROPPEDFILES;
60
61int DnDDirDroppedAddFile(PDNDDIRDROPPEDFILES pDir, const char *pszFile);
62int DnDDirDroppedAddDir(PDNDDIRDROPPEDFILES pDir, const char *pszDir);
63int DnDDirDroppedFilesCreateAndOpenEx(const char *pszPath, PDNDDIRDROPPEDFILES pDir);
64int DnDDirDroppedFilesCreateAndOpenTemp(PDNDDIRDROPPEDFILES pDir);
65int DnDDirDroppedFilesClose(PDNDDIRDROPPEDFILES pDir, bool fRemove);
66const char *DnDDirDroppedFilesGetDirAbs(PDNDDIRDROPPEDFILES pDir);
67int DnDDirDroppedFilesRollback(PDNDDIRDROPPEDFILES pDir);
68
69bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax);
70bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
71
72int DnDPathSanitizeFilename(char *pszPath, size_t cbPath);
73int DnDPathSanitize(char *pszPath, size_t cbPath);
74
75/** Keep the original paths, don't convert paths to relative ones. */
76#define DNDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0)
77/** Resolve all symlinks. */
78#define DNDURILIST_FLAGS_RESOLVE_SYMLINKS RT_BIT(1)
79/** Keep the files + directory entries open while
80 * being in this list. */
81#define DNDURILIST_FLAGS_KEEP_OPEN RT_BIT(2)
82/** Lazy loading: Only enumerate sub directories when needed.
83 ** @todo Implement lazy loading. */
84#define DNDURILIST_FLAGS_LAZY RT_BIT(3)
85
86class DnDURIObject
87{
88public:
89
90 enum Type
91 {
92 Unknown = 0,
93 File,
94 Directory,
95 Type_32Bit_Hack = 0x7fffffff
96 };
97
98 enum Dest
99 {
100 Source = 0,
101 Target,
102 Dest_32Bit_Hack = 0x7fffffff
103 };
104
105 DnDURIObject(void);
106 DnDURIObject(Type type,
107 const RTCString &strSrcPath = "",
108 const RTCString &strDstPath = "",
109 uint32_t fMode = 0, uint64_t cbSize = 0);
110 virtual ~DnDURIObject(void);
111
112public:
113
114 const RTCString &GetSourcePath(void) const { return m_strSrcPath; }
115 const RTCString &GetDestPath(void) const { return m_strTgtPath; }
116 uint32_t GetMode(void) const { return m_fMode; }
117 uint64_t GetProcessed(void) const { return m_cbProcessed; }
118 uint64_t GetSize(void) const { return m_cbSize; }
119 Type GetType(void) const { return m_Type; }
120
121public:
122
123 int SetSize(uint64_t uSize) { m_cbSize = uSize; return VINF_SUCCESS; }
124
125public:
126
127 void Close(void);
128 bool IsComplete(void) const;
129 bool IsOpen(void) const;
130 int Open(Dest enmDest, uint64_t fOpen, uint32_t fMode = 0);
131 int OpenEx(const RTCString &strPath, Type enmType, Dest enmDest, uint64_t fOpen = 0, uint32_t fMode = 0, uint32_t fFlags = 0);
132 int Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
133 void Reset(void);
134 int Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten);
135
136public:
137
138 static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld = "", const RTCString &strBaseNew = "");
139
140protected:
141
142 void closeInternal(void);
143
144protected:
145
146 Type m_Type;
147 RTCString m_strSrcPath;
148 RTCString m_strTgtPath;
149 /** Object (file/directory) mode. */
150 uint32_t m_fMode;
151 /** Size (in bytes) to read/write. */
152 uint64_t m_cbSize;
153 /** Bytes processed reading/writing. */
154 uint64_t m_cbProcessed;
155
156 union
157 {
158 RTFILE m_hFile;
159 } u;
160};
161
162class DnDURIList
163{
164public:
165
166 DnDURIList(void);
167 virtual ~DnDURIList(void);
168
169public:
170
171 int AppendNativePath(const char *pszPath, uint32_t fFlags);
172 int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, uint32_t fFlags);
173 int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, uint32_t fFlags);
174 int AppendURIPath(const char *pszURI, uint32_t fFlags);
175 int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, uint32_t fFlags);
176 int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, uint32_t fFlags);
177
178 void Clear(void);
179 DnDURIObject *First(void) { return m_lstTree.first(); }
180 bool IsEmpty(void) const { return m_lstTree.isEmpty(); }
181 void RemoveFirst(void);
182 int RootFromURIData(const void *pvData, size_t cbData, uint32_t fFlags);
183 RTCString RootToString(const RTCString &strPathBase = "", const RTCString &strSeparator = "\r\n");
184 size_t RootCount(void) const { return m_lstRoot.size(); }
185 uint32_t TotalCount(void) const { return m_cTotal; }
186 size_t TotalBytes(void) const { return m_cbTotal; }
187
188protected:
189
190 int addEntry(const char *pcszSource, const char *pcszTarget, uint32_t fFlags);
191 int appendPathRecursive(const char *pcszSrcPath, const char *pcszDstPath, const char *pcszDstBase, size_t cchDstBase, uint32_t fFlags);
192
193protected:
194
195 /** List of all top-level file/directory entries.
196 * Note: All paths are kept internally as UNIX paths for
197 * easier conversion/handling! */
198 RTCList<RTCString> m_lstRoot;
199 /** List of all URI objects added. The list's content
200 * might vary depending on how the objects are being
201 * added (lazy or not). */
202 RTCList<DnDURIObject *> m_lstTree;
203 /** Total number of all URI objects. */
204 uint32_t m_cTotal; /** @todo Really needed? m_lstTree.size()? */
205 /** Total size of all URI objects, that is, the file
206 * size of all objects (in bytes). */
207 size_t m_cbTotal;
208};
209#endif /* ___VBox_GuestHost_DragAndDrop_h */
210
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette