VirtualBox

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

Last change on this file since 74869 was 74715, checked in by vboxsync, 6 years ago

DnD/URIList: Added support for handling UNC paths.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 KB
Line 
1/* $Id: DragAndDrop.h 74715 2018-10-09 11:56:08Z vboxsync $ */
2/** @file
3 * DnD: Shared functions between host and guest.
4 */
5
6/*
7 * Copyright (C) 2014-2018 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/** DnDURIDroppedFiles flags. */
41typedef uint32_t DNDURIDROPPEDFILEFLAGS;
42
43/** No flags specified. */
44#define DNDURIDROPPEDFILE_FLAGS_NONE 0
45
46/**
47 * Class for maintaining a "dropped files" directory
48 * on the host or guest. This will contain all received files & directories
49 * for a single drag and drop operation.
50 *
51 * In case of a failed drag and drop operation this class can also
52 * perform a gentle rollback if required.
53 */
54class DnDDroppedFiles
55{
56
57public:
58
59 DnDDroppedFiles(void);
60 DnDDroppedFiles(const char *pszPath, DNDURIDROPPEDFILEFLAGS fFlags = DNDURIDROPPEDFILE_FLAGS_NONE);
61 virtual ~DnDDroppedFiles(void);
62
63public:
64
65 int AddFile(const char *pszFile);
66 int AddDir(const char *pszDir);
67 int Close(void);
68 bool IsOpen(void) const;
69 int OpenEx(const char *pszPath, DNDURIDROPPEDFILEFLAGS fFlags = DNDURIDROPPEDFILE_FLAGS_NONE);
70 int OpenTemp(DNDURIDROPPEDFILEFLAGS fFlags = DNDURIDROPPEDFILE_FLAGS_NONE);
71 const char *GetDirAbs(void) const;
72 int Reopen(void);
73 int Reset(bool fDeleteContent);
74 int Rollback(void);
75
76protected:
77
78 int closeInternal(void);
79
80protected:
81
82 /** Open flags. */
83 uint32_t m_fOpen;
84 /** Directory handle for drop directory. */
85 RTDIR m_hDir;
86 /** Absolute path to drop directory. */
87 RTCString m_strPathAbs;
88 /** List for holding created directories in the case of a rollback. */
89 RTCList<RTCString> m_lstDirs;
90 /** List for holding created files in the case of a rollback. */
91 RTCList<RTCString> m_lstFiles;
92};
93
94bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax);
95bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
96
97int DnDPathSanitizeFilename(char *pszPath, size_t cbPath);
98int DnDPathSanitize(char *pszPath, size_t cbPath);
99
100/** DnDURIObject flags. */
101typedef uint32_t DNDURIOBJECTFLAGS;
102
103/** No flags specified. */
104#define DNDURIOBJECT_FLAGS_NONE 0
105
106/** Mask of all valid DnD URI object flags. */
107#define DNDURIOBJECT_FLAGS_VALID_MASK UINT32_C(0x0)
108
109/**
110 * Class for handling DnD URI objects.
111 * This class abstracts the access and handling objects when performing DnD actions.
112 */
113class DnDURIObject
114{
115public:
116
117 /**
118 * Enumeration for specifying an URI object type.
119 */
120 enum Type
121 {
122 /** Unknown type, do not use. */
123 Type_Unknown = 0,
124 /** Object is a file. */
125 Type_File,
126 /** Object is a directory. */
127 Type_Directory,
128 /** The usual 32-bit hack. */
129 Type_32Bit_Hack = 0x7fffffff
130 };
131
132 /**
133 * Enumeration for specifying an URI object view
134 * for representing its data accordingly.
135 */
136 enum View
137 {
138 /** Unknown view, do not use. */
139 View_Unknown = 0,
140 /** Handle data from the source point of view. */
141 View_Source,
142 /** Handle data from the destination point of view. */
143 View_Target,
144 /** The usual 32-bit hack. */
145 View_Dest_32Bit_Hack = 0x7fffffff
146 };
147
148 DnDURIObject(void);
149 DnDURIObject(Type type,
150 const RTCString &strSrcPathAbs = "",
151 const RTCString &strDstPathAbs = "");
152 virtual ~DnDURIObject(void);
153
154public:
155
156 /**
157 * Returns the given absolute source path of the object.
158 *
159 * @return Absolute source path of the object.
160 */
161 const RTCString &GetSourcePathAbs(void) const { return m_strSrcPathAbs; }
162
163 /**
164 * Returns the given, absolute destination path of the object.
165 *
166 * @return Absolute destination path of the object.
167 */
168 const RTCString &GetDestPathAbs(void) const { return m_strTgtPathAbs; }
169
170 RTFMODE GetMode(void) const;
171
172 uint64_t GetProcessed(void) const;
173
174 uint64_t GetSize(void) const;
175
176 /**
177 * Returns the object's type.
178 *
179 * @return The object's type.
180 */
181 Type GetType(void) const { return m_enmType; }
182
183 /**
184 * Returns the object's view.
185 *
186 * @return The object's view.
187 */
188 View GetView(void) const { return m_enmView; }
189
190public:
191
192 int SetSize(uint64_t cbSize);
193
194public:
195
196 void Close(void);
197 bool IsComplete(void) const;
198 bool IsOpen(void) const;
199 int Open(View enmView, uint64_t fOpen, RTFMODE fMode = 0);
200 int OpenEx(const RTCString &strPath, View enmView, uint64_t fOpen = 0, RTFMODE fMode = 0, DNDURIOBJECTFLAGS = DNDURIOBJECT_FLAGS_NONE);
201 int QueryInfo(View enmView);
202 int Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
203 void Reset(void);
204 int Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten);
205
206public:
207
208 static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld = "", const RTCString &strBaseNew = "");
209
210protected:
211
212 void closeInternal(void);
213 int queryInfoInternal(View enmView);
214
215protected:
216
217 /** The object's type. */
218 Type m_enmType;
219 /** The object's view. */
220 View m_enmView;
221 /** Absolute path (base) for the source. */
222 RTCString m_strSrcPathAbs;
223 /** Absolute path (base) for the target. */
224 RTCString m_strTgtPathAbs;
225 /** Whether the object is in "opened" state. */
226 bool m_fIsOpen;
227
228 /** Union containing data depending on the object's type. */
229 union
230 {
231 /** Structure containing members for objects that
232 * are files. */
233 struct
234 {
235 /** File handle. */
236 RTFILE hFile;
237 /** File system object information of this file. */
238 RTFSOBJINFO objInfo;
239 /** Bytes to proces for reading/writing. */
240 uint64_t cbToProcess;
241 /** Bytes processed reading/writing. */
242 uint64_t cbProcessed;
243 } File;
244 struct
245 {
246 /** Directory handle. */
247 RTDIR hDir;
248 /** File system object information of this directory. */
249 RTFSOBJINFO objInfo;
250 } Dir;
251 } u;
252};
253
254/** DnDURIList flags. */
255typedef uint32_t DNDURILISTFLAGS;
256
257/** No flags specified. */
258#define DNDURILIST_FLAGS_NONE 0
259/** Keep the original paths, don't convert paths to relative ones. */
260#define DNDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0)
261/** Resolve all symlinks. */
262#define DNDURILIST_FLAGS_RESOLVE_SYMLINKS RT_BIT(1)
263/** Keep the files + directory entries open while
264 * being in this list. */
265#define DNDURILIST_FLAGS_KEEP_OPEN RT_BIT(2)
266/** Lazy loading: Only enumerate sub directories when needed.
267 ** @todo Implement lazy loading. */
268#define DNDURILIST_FLAGS_LAZY RT_BIT(3)
269
270/** Mask of all valid DnD URI list flags. */
271#define DNDURILIST_FLAGS_VALID_MASK UINT32_C(0xF)
272
273class DnDURIList
274{
275public:
276
277 DnDURIList(void);
278 virtual ~DnDURIList(void);
279
280public:
281
282 int AppendNativePath(const char *pszPath, DNDURILISTFLAGS fFlags);
283 int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, DNDURILISTFLAGS fFlags);
284 int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, DNDURILISTFLAGS fFlags);
285 int AppendURIPath(const char *pszURI, DNDURILISTFLAGS fFlags);
286 int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, DNDURILISTFLAGS fFlags);
287 int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, DNDURILISTFLAGS fFlags);
288
289 void Clear(void);
290 DnDURIObject *First(void) { return m_lstTree.first(); }
291 bool IsEmpty(void) const { return m_lstTree.isEmpty(); }
292 void RemoveFirst(void);
293 int SetFromURIData(const void *pvData, size_t cbData, DNDURILISTFLAGS fFlags);
294
295 RTCString GetRootEntries(const RTCString &strPathBase = "", const RTCString &strSeparator = "\r\n") const;
296 uint64_t GetRootCount(void) const { return m_lstRoot.size(); }
297 uint64_t GetTotalCount(void) const { return m_cTotal; }
298 uint64_t GetTotalBytes(void) const { return m_cbTotal; }
299
300protected:
301
302 int addEntry(const char *pcszSource, const char *pcszTarget, DNDURILISTFLAGS fFlags);
303 int appendPathRecursive(const char *pcszSrcPath, const char *pcszDstPath, const char *pcszDstBase, size_t cchDstBase, DNDURILISTFLAGS fFlags);
304
305protected:
306
307 /** List of all top-level file/directory entries.
308 * Note: All paths are kept internally as UNIX paths for
309 * easier conversion/handling! */
310 RTCList<RTCString> m_lstRoot;
311 /** List of all URI objects added. The list's content
312 * might vary depending on how the objects are being
313 * added (lazy or not). */
314 RTCList<DnDURIObject *> m_lstTree;
315 /** Total number of all URI objects. */
316 uint64_t m_cTotal;
317 /** Total size of all URI objects, that is, the file
318 * size of all objects (in bytes).
319 * Note: Do *not* size_t here, as we also want to support large files
320 * on 32-bit guests. */
321 uint64_t m_cbTotal;
322};
323
324#endif /* !___VBox_GuestHost_DragAndDrop_h */
325
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