VirtualBox

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

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

DnD: Rollback handling, bugfixes, cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: DragAndDrop.h 55556 2015-04-30 14:27:39Z vboxsync $ */
2/** @file
3 * DnD: Shared functions between host and guest.
4 */
5
6/*
7 * Copyright (C) 2014 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/err.h>
33#include <iprt/file.h>
34#include <iprt/types.h>
35
36#include <iprt/cpp/list.h>
37#include <iprt/cpp/ministring.h>
38
39int DnDDirCreateDroppedFilesEx(const char *pszPath, char *pszDropDir, size_t cbDropDir);
40int DnDDirCreateDroppedFiles(char *pszDropDir, size_t cbDropDir);
41
42bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax);
43bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
44
45int DnDPathSanitizeFilename(char *pszPath, size_t cbPath);
46int DnDPathSanitize(char *pszPath, size_t cbPath);
47
48/** Keep the original paths, don't convert paths to relative ones. */
49#define DNDURILIST_FLAGS_ABSOLUTE_PATHS RT_BIT(0)
50
51class DnDURIObject
52{
53public:
54
55 enum Type
56 {
57 Unknown = 0,
58 File,
59 Directory
60 };
61
62 enum Dest
63 {
64 Source = 0,
65 Target
66 };
67
68 DnDURIObject(void);
69 DnDURIObject(Type type,
70 const RTCString &strSrcPath = "",
71 const RTCString &strDstPath = "",
72 uint32_t fMode = 0, uint64_t cbSize = 0);
73 virtual ~DnDURIObject(void);
74
75public:
76
77 const RTCString &GetSourcePath(void) const { return m_strSrcPath; }
78 const RTCString &GetDestPath(void) const { return m_strTgtPath; }
79 uint32_t GetMode(void) const { return m_fCreationMode; }
80 uint64_t GetProcessed(void) const { return m_cbProcessed; }
81 uint64_t GetSize(void) const { return m_cbSize; }
82 Type GetType(void) const { return m_Type; }
83
84public:
85
86 int SetSize(uint64_t uSize) { m_cbSize = uSize; return VINF_SUCCESS; }
87
88public:
89
90 void Close(void);
91 bool IsComplete(void) const;
92 bool IsOpen(void) const;
93 int Open(Dest enmDest, uint64_t fOpen);
94 int OpenEx(const RTCString &strPath, Type enmType, Dest enmDest, uint64_t fMode = 0, uint32_t fFlags = 0);
95 int Read(void *pvBuf, size_t cbBuf, uint32_t *pcbRead);
96 void Reset(void);
97 int Write(const void *pvBuf, size_t cbBuf, uint32_t *pcbWritten);
98
99public:
100
101 static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld = "", const RTCString &strBaseNew = "");
102
103protected:
104
105 void closeInternal(void);
106
107protected:
108
109 Type m_Type;
110 RTCString m_strSrcPath;
111 RTCString m_strTgtPath;
112 /** File creation mode. */
113 uint32_t m_fCreationMode;
114 /** Size (in bytes) to read/write. */
115 uint64_t m_cbSize;
116 /** Bytes processed reading/writing. */
117 uint64_t m_cbProcessed;
118
119 union
120 {
121 RTFILE m_hFile;
122 } u;
123};
124
125class DnDURIList
126{
127public:
128
129 DnDURIList(void);
130 virtual ~DnDURIList(void);
131
132public:
133
134 int AppendNativePath(const char *pszPath, uint32_t fFlags);
135 int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, uint32_t fFlags);
136 int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, uint32_t fFlags);
137 int AppendURIPath(const char *pszURI, uint32_t fFlags);
138 int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, uint32_t fFlags);
139 int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, uint32_t fFlags);
140
141 void Clear(void);
142 DnDURIObject &First(void) { return m_lstTree.first(); }
143 bool IsEmpty(void) { return m_lstTree.isEmpty(); }
144 void RemoveFirst(void);
145 int RootFromURIData(const void *pvData, size_t cbData, uint32_t fFlags);
146 RTCString RootToString(const RTCString &strBasePath = "", const RTCString &strSeparator = "\r\n");
147 size_t RootCount(void) { return m_lstRoot.size(); }
148 uint32_t TotalCount(void) { return m_cTotal; }
149 size_t TotalBytes(void) { return m_cbTotal; }
150
151protected:
152
153 int appendPathRecursive(const char *pcszPath, size_t cbBaseLen, uint32_t fFlags);
154
155protected:
156
157 /** List of all top-level file/directory entries.
158 * Note: All paths are kept internally as UNIX paths for
159 * easier conversion/handling! */
160 RTCList<RTCString> m_lstRoot;
161 /** List of all URI objects added. */
162 RTCList<DnDURIObject> m_lstTree;
163 /** Total number of all URI objects. */
164 uint32_t m_cTotal;
165 /** Total size of all URI objects, that is, the file
166 * size of all objects (in bytes). */
167 size_t m_cbTotal;
168};
169#endif /* ___VBox_GuestHost_DragAndDrop_h */
170
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