1 | /* $Id: UIDnDHandler.h 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIDnDHandler class declaration..
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2011-2024 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | #ifndef FEQT_INCLUDED_SRC_runtime_UIDnDHandler_h
|
---|
29 | #define FEQT_INCLUDED_SRC_runtime_UIDnDHandler_h
|
---|
30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
31 | # pragma once
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | /* Qt includes: */
|
---|
35 | #include <QMimeData>
|
---|
36 | #include <QMutex>
|
---|
37 | #include <QStringList>
|
---|
38 |
|
---|
39 | /* COM includes: */
|
---|
40 | #include "CDnDTarget.h"
|
---|
41 | #include "CDnDSource.h"
|
---|
42 |
|
---|
43 | /* Forward declarations: */
|
---|
44 | class QMimeData;
|
---|
45 |
|
---|
46 | class UIDnDMIMEData;
|
---|
47 | class UIMachine;
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Main class for implementing Drag'n'Drop in the frontend.
|
---|
51 | */
|
---|
52 | class UIDnDHandler: public QObject
|
---|
53 | {
|
---|
54 | Q_OBJECT;
|
---|
55 |
|
---|
56 | public:
|
---|
57 |
|
---|
58 | UIDnDHandler(UIMachine *pMachine, QWidget *pParent);
|
---|
59 | virtual ~UIDnDHandler(void);
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Drag and drop data set from the source.
|
---|
63 | */
|
---|
64 | typedef struct UIDnDDataSource
|
---|
65 | {
|
---|
66 | /** List of formats supported by the source. */
|
---|
67 | QStringList lstFormats;
|
---|
68 | /** List of allowed drop actions from the source. */
|
---|
69 | QVector<KDnDAction> vecActions;
|
---|
70 | /** Default drop action from the source. */
|
---|
71 | KDnDAction defaultAction;
|
---|
72 |
|
---|
73 | } UIDnDDataSource;
|
---|
74 |
|
---|
75 | int init(void);
|
---|
76 | void reset(void);
|
---|
77 |
|
---|
78 | /* Frontend -> Target. */
|
---|
79 | Qt::DropAction dragEnter(ulong screenId, int x, int y, Qt::DropAction proposedAction, Qt::DropActions possibleActions, const QMimeData *pMimeData);
|
---|
80 | Qt::DropAction dragMove (ulong screenId, int x, int y, Qt::DropAction proposedAction, Qt::DropActions possibleActions, const QMimeData *pMimeData);
|
---|
81 | Qt::DropAction dragDrop (ulong screenId, int x, int y, Qt::DropAction proposedAction, Qt::DropActions possibleActions, const QMimeData *pMimeData);
|
---|
82 | void dragLeave(ulong screenId);
|
---|
83 |
|
---|
84 | /* Source -> Frontend. */
|
---|
85 | int dragCheckPending(ulong screenId);
|
---|
86 | int dragStart(ulong screenId);
|
---|
87 | int dragStop(ulong screenID);
|
---|
88 |
|
---|
89 | /* Data access. */
|
---|
90 | int retrieveData(Qt::DropAction dropAction, const QString &strMIMEType, QVector<uint8_t> &vecData);
|
---|
91 | int retrieveData(Qt::DropAction dropAction, const QString &strMIMEType, QMetaType::Type vaType, QVariant &vaData);
|
---|
92 |
|
---|
93 | public:
|
---|
94 |
|
---|
95 | static KDnDAction toVBoxDnDAction(Qt::DropAction action);
|
---|
96 | static QVector<KDnDAction> toVBoxDnDActions(Qt::DropActions actions);
|
---|
97 | static Qt::DropAction toQtDnDAction(KDnDAction action);
|
---|
98 | static Qt::DropActions toQtDnDActions(const QVector<KDnDAction> &vecActions);
|
---|
99 |
|
---|
100 | public slots:
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * Called by UIDnDMIMEData (Linux, OS X, Solaris) to start retrieving the actual data
|
---|
104 | * from the guest. This function will block and show a modal progress dialog until
|
---|
105 | * the data transfer is complete.
|
---|
106 | *
|
---|
107 | * @return IPRT status code.
|
---|
108 | * @param dropAction Drop action to perform.
|
---|
109 | * @param strMIMEType MIME data type.
|
---|
110 | * @param vaType Qt's variant type of the MIME data.
|
---|
111 | * @param vaData Reference to QVariant where to store the retrieved data.
|
---|
112 | */
|
---|
113 | int sltGetData(Qt::DropAction dropAction, const QString &strMIMEType, QMetaType::Type vaType, QVariant &vaData);
|
---|
114 |
|
---|
115 | protected:
|
---|
116 |
|
---|
117 | #ifdef DEBUG
|
---|
118 | static void debugOutputQt(QtMsgType type, const char *pszMsg);
|
---|
119 | #endif
|
---|
120 |
|
---|
121 | protected:
|
---|
122 |
|
---|
123 | int dragStartInternal(const QStringList &lstFormats, Qt::DropAction defAction, Qt::DropActions actions);
|
---|
124 | int retrieveDataInternal(Qt::DropAction dropAction, const QString &strMIMEType, QVector<uint8_t> &vecData);
|
---|
125 |
|
---|
126 | protected:
|
---|
127 |
|
---|
128 | #ifdef RT_OS_WINDOWS
|
---|
129 | static int getProcessIntegrityLevel(DWORD *pdwIntegrityLevel);
|
---|
130 | #endif
|
---|
131 |
|
---|
132 | protected:
|
---|
133 |
|
---|
134 | /** Pointer to machine UI. */
|
---|
135 | UIMachine *m_pMachine;
|
---|
136 | /** Pointer to parent widget. */
|
---|
137 | QWidget *m_pParent;
|
---|
138 | /** Drag and drop source instance. */
|
---|
139 | CDnDSource m_dndSource;
|
---|
140 | /** Drag and drop target instance. */
|
---|
141 | CDnDTarget m_dndTarget;
|
---|
142 | /** Current data from the source (if any).
|
---|
143 | * At the momenet we only support one source at a time. */
|
---|
144 | UIDnDDataSource m_dataSource;
|
---|
145 | /** Flag indicating whether data has been retrieved from
|
---|
146 | * the guest already or not. */
|
---|
147 | bool m_fDataRetrieved;
|
---|
148 | QMutex m_ReadLock;
|
---|
149 | QMutex m_WriteLock;
|
---|
150 | /** Data received from the guest. */
|
---|
151 | QVector<uint8_t> m_vecData;
|
---|
152 |
|
---|
153 | #ifdef RT_OS_WINDOWS
|
---|
154 | /** Process integrity level we're running with. Needed for UIPI detection + logging.
|
---|
155 | * Set to 0 if not set yet or unavailable. */
|
---|
156 | DWORD m_dwIntegrityLevel;
|
---|
157 | #else /* !RT_OS_WINDOWS */
|
---|
158 | /** Pointer to MIMEData instance used for handling
|
---|
159 | * own MIME times on non-Windows host OSes. */
|
---|
160 | UIDnDMIMEData *m_pMIMEData;
|
---|
161 | friend class UIDnDMIMEData;
|
---|
162 | #endif /* RT_OS_WINDOWS */
|
---|
163 | };
|
---|
164 | #endif /* !FEQT_INCLUDED_SRC_runtime_UIDnDHandler_h */
|
---|
165 |
|
---|