VirtualBox

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

Last change on this file since 57667 was 57654, checked in by vboxsync, 9 years ago

DnD: Moved allocation of DNDDIRDROPPEDFILES into DnDDirDroppedFilesCreateAndOpen(Temp|Ex). Untested.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.4 KB
Line 
1/* $Id: DragAndDrop.h 57654 2015-09-08 13:16:17Z 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, uint32_t fFlags, PDNDDIRDROPPEDFILES *ppDir);
64int DnDDirDroppedFilesCreateAndOpenTemp(uint32_t fFlags, PDNDDIRDROPPEDFILES *ppDir);
65int DnDDirDroppedFilesClose(PDNDDIRDROPPEDFILES pDir, bool fRemove);
66void DnDDirDroppedFilesDestroy(PDNDDIRDROPPEDFILES pDir);
67const char *DnDDirDroppedFilesGetDirAbs(PDNDDIRDROPPEDFILES pDir);
68int DnDDirDroppedFilesRollback(PDNDDIRDROPPEDFILES pDir);
69
70bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax);
71bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
72
73int DnDPathSanitizeFilename(char *pszPath, size_t cbPath);
74int DnDPathSanitize(char *pszPath, size_t cbPath);
75
76/** No flags specified. */
77#define DNDURILIST_FLAGS_NONE 0
78/** Keep the original paths, don't convert paths to relative ones. */
79#define DNDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0)
80/** Resolve all symlinks. */
81#define DNDURILIST_FLAGS_RESOLVE_SYMLINKS RT_BIT(1)
82/** Keep the files + directory entries open while
83 * being in this list. */
84#define DNDURILIST_FLAGS_KEEP_OPEN RT_BIT(2)
85/** Lazy loading: Only enumerate sub directories when needed.
86 ** @todo Implement lazy loading. */
87#define DNDURILIST_FLAGS_LAZY RT_BIT(3)
88
89class DnDURIObject
90{
91public:
92
93 enum Type
94 {
95 Unknown = 0,
96 File,
97 Directory,
98 Type_32Bit_Hack = 0x7fffffff
99 };
100
101 enum Dest
102 {
103 Source = 0,
104 Target,
105 Dest_32Bit_Hack = 0x7fffffff
106 };
107
108 DnDURIObject(void);
109 DnDURIObject(Type type,
110 const RTCString &strSrcPath = "",
111 const RTCString &strDstPath = "",
112 uint32_t fMode = 0, uint64_t cbSize = 0);
113 virtual ~DnDURIObject(void);
114
115public:
116
117 const RTCString &GetSourcePath(void) const { return m_strSrcPath; }
118 const RTCString &GetDestPath(void) const { return m_strTgtPath; }
119 uint32_t GetMode(void) const { return m_fMode; }
120 uint64_t GetProcessed(void) const { return m_cbProcessed; }
121 uint64_t GetSize(void) const { return m_cbSize; }
122 Type GetType(void) const { return m_Type; }
123
124public:
125
126 int SetSize(uint64_t uSize) { m_cbSize = uSize; return VINF_SUCCESS; }
127
128public:
129
130 void Close(void);
131 bool IsComplete(void) const;
132 bool IsOpen(void) const;
133 int Open(Dest enmDest, uint64_t fOpen, uint32_t fMode = 0);
134 int OpenEx(const RTCString &strPath, Type enmType, Dest enmDest, uint64_t fOpen = 0, uint32_t fMode = 0, uint32_t fFlags = 0);
135 int Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
136 void Reset(void);
137 int Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten);
138
139public:
140
141 static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld = "", const RTCString &strBaseNew = "");
142
143protected:
144
145 void closeInternal(void);
146
147protected:
148
149 Type m_Type;
150 RTCString m_strSrcPath;
151 RTCString m_strTgtPath;
152 /** Object (file/directory) mode. */
153 uint32_t m_fMode;
154 /** Size (in bytes) to read/write. */
155 uint64_t m_cbSize;
156 /** Bytes processed reading/writing. */
157 uint64_t m_cbProcessed;
158
159 union
160 {
161 RTFILE m_hFile;
162 } u;
163};
164
165class DnDURIList
166{
167public:
168
169 DnDURIList(void);
170 virtual ~DnDURIList(void);
171
172public:
173
174 int AppendNativePath(const char *pszPath, uint32_t fFlags);
175 int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, uint32_t fFlags);
176 int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, uint32_t fFlags);
177 int AppendURIPath(const char *pszURI, uint32_t fFlags);
178 int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, uint32_t fFlags);
179 int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, uint32_t fFlags);
180
181 void Clear(void);
182 DnDURIObject *First(void) { return m_lstTree.first(); }
183 bool IsEmpty(void) const { return m_lstTree.isEmpty(); }
184 void RemoveFirst(void);
185 int RootFromURIData(const void *pvData, size_t cbData, uint32_t fFlags);
186 RTCString RootToString(const RTCString &strPathBase = "", const RTCString &strSeparator = "\r\n");
187 size_t RootCount(void) const { return m_lstRoot.size(); }
188 uint32_t TotalCount(void) const { return m_cTotal; }
189 size_t TotalBytes(void) const { return m_cbTotal; }
190
191protected:
192
193 int addEntry(const char *pcszSource, const char *pcszTarget, uint32_t fFlags);
194 int appendPathRecursive(const char *pcszSrcPath, const char *pcszDstPath, const char *pcszDstBase, size_t cchDstBase, uint32_t fFlags);
195
196protected:
197
198 /** List of all top-level file/directory entries.
199 * Note: All paths are kept internally as UNIX paths for
200 * easier conversion/handling! */
201 RTCList<RTCString> m_lstRoot;
202 /** List of all URI objects added. The list's content
203 * might vary depending on how the objects are being
204 * added (lazy or not). */
205 RTCList<DnDURIObject *> m_lstTree;
206 /** Total number of all URI objects. */
207 uint32_t m_cTotal; /** @todo Really needed? m_lstTree.size()? */
208 /** Total size of all URI objects, that is, the file
209 * size of all objects (in bytes). */
210 size_t m_cbTotal;
211};
212#endif /* ___VBox_GuestHost_DragAndDrop_h */
213
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