VirtualBox

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

Last change on this file since 78345 was 78036, checked in by vboxsync, 6 years ago

DnD/GuestHost: Attribute DnDURIObject::m_fIsOpen is not used anymore, removed.

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