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