VirtualBox

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

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

DnD:

  • Overhauled "dropped files" directory + general file handling: Keep the directories/files open when doing the actual transfers (only protocol >= 2)
  • Unified "dropped files" directory creation/rollback handling for guest/host parts.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: DragAndDrop.h 55640 2015-05-04 12:38:57Z 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 transfer.
44 */
45typedef struct DNDDIRDROPPEDFILES
46{
47 /** Directory handle for drop directory. */
48 PRTDIR hDir;
49 /** Absolute path to drop directory. */
50 RTCString strPathAbs;
51 /** List for holding created directories in the case of a rollback. */
52 RTCList<RTCString> lstDirs;
53 /** List for holding created files in the case of a rollback. */
54 RTCList<RTCString> lstFiles;
55
56} DNDDIRDROPPEDFILES, *PDNDDIRDROPPEDFILES;
57
58int DnDDirDroppedAddFile(PDNDDIRDROPPEDFILES pDir, const char *pszFile);
59int DnDDirDroppedAddDir(PDNDDIRDROPPEDFILES pDir, const char *pszDir);
60int DnDDirDroppedFilesCreateAndOpenEx(const char *pszPath, PDNDDIRDROPPEDFILES pDir);
61int DnDDirDroppedFilesCreateAndOpenTemp(PDNDDIRDROPPEDFILES pDir);
62int DnDDirDroppedFilesClose(PDNDDIRDROPPEDFILES pDir, bool fRemove);
63const char *DnDDirDroppedFilesGetDirAbs(PDNDDIRDROPPEDFILES pDir);
64int DnDDirDroppedFilesRollback(PDNDDIRDROPPEDFILES pDir);
65
66bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax);
67bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
68
69int DnDPathSanitizeFilename(char *pszPath, size_t cbPath);
70int DnDPathSanitize(char *pszPath, size_t cbPath);
71
72/** Keep the original paths, don't convert paths to relative ones. */
73#define DNDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0)
74
75class DnDURIObject
76{
77public:
78
79 enum Type
80 {
81 Unknown = 0,
82 File,
83 Directory
84 };
85
86 enum Dest
87 {
88 Source = 0,
89 Target
90 };
91
92 DnDURIObject(void);
93 DnDURIObject(Type type,
94 const RTCString &strSrcPath = "",
95 const RTCString &strDstPath = "",
96 uint32_t fMode = 0, uint64_t cbSize = 0);
97 virtual ~DnDURIObject(void);
98
99public:
100
101 const RTCString &GetSourcePath(void) const { return m_strSrcPath; }
102 const RTCString &GetDestPath(void) const { return m_strTgtPath; }
103 uint32_t GetMode(void) const { return m_fMode; }
104 uint64_t GetProcessed(void) const { return m_cbProcessed; }
105 uint64_t GetSize(void) const { return m_cbSize; }
106 Type GetType(void) const { return m_Type; }
107
108public:
109
110 int SetSize(uint64_t uSize) { m_cbSize = uSize; return VINF_SUCCESS; }
111
112public:
113
114 void Close(void);
115 bool IsComplete(void) const;
116 bool IsOpen(void) const;
117 int Open(Dest enmDest, uint64_t fOpen, uint32_t fMode = 0);
118 int OpenEx(const RTCString &strPath, Type enmType, Dest enmDest, uint64_t fOpen = 0, uint32_t fMode = 0, uint32_t fFlags = 0);
119 int Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
120 void Reset(void);
121 int Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten);
122
123public:
124
125 static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld = "", const RTCString &strBaseNew = "");
126
127protected:
128
129 void closeInternal(void);
130
131protected:
132
133 Type m_Type;
134 RTCString m_strSrcPath;
135 RTCString m_strTgtPath;
136 /** Object (file/directory) mode. */
137 uint32_t m_fMode;
138 /** Size (in bytes) to read/write. */
139 uint64_t m_cbSize;
140 /** Bytes processed reading/writing. */
141 uint64_t m_cbProcessed;
142
143 union
144 {
145 RTFILE m_hFile;
146 } u;
147};
148
149class DnDURIList
150{
151public:
152
153 DnDURIList(void);
154 virtual ~DnDURIList(void);
155
156public:
157
158 int AppendNativePath(const char *pszPath, uint32_t fFlags);
159 int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, uint32_t fFlags);
160 int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, uint32_t fFlags);
161 int AppendURIPath(const char *pszURI, uint32_t fFlags);
162 int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, uint32_t fFlags);
163 int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, uint32_t fFlags);
164
165 void Clear(void);
166 DnDURIObject &First(void) { return m_lstTree.first(); }
167 bool IsEmpty(void) { return m_lstTree.isEmpty(); }
168 void RemoveFirst(void);
169 int RootFromURIData(const void *pvData, size_t cbData, uint32_t fFlags);
170 RTCString RootToString(const RTCString &strPathBase = "", const RTCString &strSeparator = "\r\n");
171 size_t RootCount(void) { return m_lstRoot.size(); }
172 uint32_t TotalCount(void) { return m_cTotal; }
173 size_t TotalBytes(void) { return m_cbTotal; }
174
175protected:
176
177 int appendPathRecursive(const char *pcszPath, size_t cbBaseLen, uint32_t fFlags);
178
179protected:
180
181 /** List of all top-level file/directory entries.
182 * Note: All paths are kept internally as UNIX paths for
183 * easier conversion/handling! */
184 RTCList<RTCString> m_lstRoot;
185 /** List of all URI objects added. */
186 RTCList<DnDURIObject> m_lstTree;
187 /** Total number of all URI objects. */
188 uint32_t m_cTotal;
189 /** Total size of all URI objects, that is, the file
190 * size of all objects (in bytes). */
191 size_t m_cbTotal;
192};
193#endif /* ___VBox_GuestHost_DragAndDrop_h */
194
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