1 | /* $Id: DragAndDrop.h 51211 2014-05-08 07:44:14Z 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 |
|
---|
39 | int DnDDirCreateDroppedFilesEx(const char *pszPath, char *pszDropDir, size_t cbDropDir);
|
---|
40 | int DnDDirCreateDroppedFiles(char *pszDropDir, size_t cbDropDir);
|
---|
41 |
|
---|
42 | bool DnDMIMEHasFileURLs(const char *pcszFormat, size_t cchFormatMax);
|
---|
43 | bool DnDMIMENeedsDropDir(const char *pcszFormat, size_t cchFormatMax);
|
---|
44 |
|
---|
45 | int DnDPathSanitizeFilename(char *pszPath, size_t cbPath);
|
---|
46 | int 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 |
|
---|
51 | class DnDURIObject
|
---|
52 | {
|
---|
53 | public:
|
---|
54 |
|
---|
55 | enum Type
|
---|
56 | {
|
---|
57 | Unknown = 0,
|
---|
58 | File,
|
---|
59 | Directory
|
---|
60 | };
|
---|
61 |
|
---|
62 | DnDURIObject(Type type,
|
---|
63 | const RTCString &strSrcPath,
|
---|
64 | const RTCString &strDstPath,
|
---|
65 | uint32_t fMode, uint64_t cbSize);
|
---|
66 | virtual ~DnDURIObject(void);
|
---|
67 |
|
---|
68 | public:
|
---|
69 |
|
---|
70 | const RTCString &GetSourcePath(void) const { return m_strSrcPath; }
|
---|
71 | const RTCString &GetDestPath(void) const { return m_strDstPath; }
|
---|
72 | uint32_t GetMode(void) const { return m_fMode; }
|
---|
73 | uint64_t GetSize(void) const { return m_cbSize; }
|
---|
74 | Type GetType(void) const { return m_Type; }
|
---|
75 |
|
---|
76 | public:
|
---|
77 |
|
---|
78 | bool IsComplete(void) const;
|
---|
79 | static int RebaseURIPath(RTCString &strPath, const RTCString &strBaseOld, const RTCString &strBaseNew);
|
---|
80 | int Read(void *pvBuf, uint32_t cbToRead, uint32_t *pcbRead);
|
---|
81 |
|
---|
82 | protected:
|
---|
83 |
|
---|
84 | void closeInternal(void);
|
---|
85 |
|
---|
86 | protected:
|
---|
87 |
|
---|
88 | Type m_Type;
|
---|
89 | RTCString m_strSrcPath;
|
---|
90 | RTCString m_strDstPath;
|
---|
91 | uint32_t m_fMode;
|
---|
92 | /** Size (in bytes) to read/write. */
|
---|
93 | uint64_t m_cbSize;
|
---|
94 | /** Bytes processed reading/writing. */
|
---|
95 | uint64_t m_cbProcessed;
|
---|
96 |
|
---|
97 | union
|
---|
98 | {
|
---|
99 | RTFILE m_hFile;
|
---|
100 | } u;
|
---|
101 | };
|
---|
102 |
|
---|
103 | class DnDURIList
|
---|
104 | {
|
---|
105 | public:
|
---|
106 |
|
---|
107 | DnDURIList(void);
|
---|
108 | virtual ~DnDURIList(void);
|
---|
109 |
|
---|
110 | public:
|
---|
111 |
|
---|
112 | int AppendNativePath(const char *pszPath, uint32_t fFlags);
|
---|
113 | int AppendNativePathsFromList(const char *pszNativePaths, size_t cbNativePaths, uint32_t fFlags);
|
---|
114 | int AppendNativePathsFromList(const RTCList<RTCString> &lstNativePaths, uint32_t fFlags);
|
---|
115 | int AppendURIPath(const char *pszURI, uint32_t fFlags);
|
---|
116 | int AppendURIPathsFromList(const char *pszURIPaths, size_t cbURIPaths, uint32_t fFlags);
|
---|
117 | int AppendURIPathsFromList(const RTCList<RTCString> &lstURI, uint32_t fFlags);
|
---|
118 |
|
---|
119 | void Clear(void);
|
---|
120 | DnDURIObject &First(void) { return m_lstTree.first(); }
|
---|
121 | bool IsEmpty(void) { return m_lstTree.isEmpty(); }
|
---|
122 | void RemoveFirst(void);
|
---|
123 | int RootFromURIData(const void *pvData, size_t cbData, uint32_t fFlags);
|
---|
124 | RTCString RootToString(const RTCString &strBasePath = "", const RTCString &strSeparator = "\r\n");
|
---|
125 | size_t RootCount(void) { return m_lstRoot.size(); }
|
---|
126 | size_t TotalBytes(void) { return m_cbTotal; }
|
---|
127 |
|
---|
128 | protected:
|
---|
129 |
|
---|
130 | int appendPathRecursive(const char *pcszPath, size_t cbBaseLen, uint32_t fFlags);
|
---|
131 |
|
---|
132 | protected:
|
---|
133 |
|
---|
134 | /** List of all top-level file/directory entries.
|
---|
135 | * Note: All paths are kept internally as UNIX paths for
|
---|
136 | * easier conversion/handling! */
|
---|
137 | RTCList<RTCString> m_lstRoot;
|
---|
138 | /** List of all URI objects added. */
|
---|
139 | RTCList<DnDURIObject> m_lstTree;
|
---|
140 | /** Total size of all URI objects, that is, the file
|
---|
141 | * size of all objects (in bytes). */
|
---|
142 | size_t m_cbTotal;
|
---|
143 | };
|
---|
144 | #endif /* ___VBox_GuestHost_DragAndDrop_h */
|
---|
145 |
|
---|