Changeset 50305 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Feb 3, 2014 10:47:45 AM (11 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r50265 r50305 451 451 452 452 ifdef VBOX_WITH_DRAG_AND_DROP 453 VirtualBox_QT_MOCHDRS += \ 454 src/runtime/UIDnDHandler.h 453 455 ifdef VBOX_WITH_DRAG_AND_DROP_GH 454 456 VirtualBox_QT_MOCHDRS += \ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDHandler.cpp
r50278 r50305 23 23 #include <QStringList> 24 24 #include <QTimer> 25 #include <QUrl> 25 26 26 27 #ifdef LOG_GROUP … … 168 169 * Do guest -> host format conversion, if needed. 169 170 * On X11 this already maps to the Xdnd protocol. 170 ** @todo What about MacOS X Carbon Drag Manager?171 ** @todo What about the MacOS Carbon Drag Manager? Needs testing. 171 172 * 172 173 * See: https://www.iana.org/assignments/media-types/media-types.xhtml … … 176 177 for (int i = 0; i < vecFmtGuest.size(); i++) 177 178 { 178 const QString &strFmt = vecFmtGuest.at(i);179 const QString &strFmtGuest = vecFmtGuest.at(i); 179 180 LogFlowFunc(("\tFormat %d: %s\n", i, 180 strFmt .toAscii().constData()));181 strFmtGuest.toAscii().constData())); 181 182 #ifdef RT_OS_WINDOWS 182 if ( strFmt.contains("text", Qt::CaseInsensitive) 183 /* CF_TEXT */ 184 if ( strFmtGuest.contains("text/plain", Qt::CaseInsensitive) 183 185 && !lstFmtNative.contains("text/plain")) 184 186 { 185 187 lstFmtNative << "text/plain"; 186 188 } 189 /* CF_HDROP */ 190 else if ( strFmtGuest.contains("text/uri-list", Qt::CaseInsensitive) 191 && !lstFmtNative.contains("text/uri-list")) 192 { 193 lstFmtNative << "text/uri-list"; 194 } 187 195 #else 188 lstFmtNative << strFmt; 196 /* On non-Windows just do a 1:1 mapping. */ 197 lstFmtNative << strFmtGuest; 198 # ifdef RT_OS_MACOS 199 /** @todo Does the mapping apply here? Don't think so ... */ 200 # endif 189 201 #endif 190 202 } … … 204 216 205 217 /* pMData is transfered to the QDrag object, so no need for deletion. */ 206 UIDnDMimeData *pMData = new UIDnDMimeData(session, lstFmtNative,218 pMData = new UIDnDMimeData(session, lstFmtNative, 207 219 toQtDnDAction(defaultAction), 208 220 toQtDnDActions(vecActions), pParent); 221 222 /* Inform this object that MIME data from the guest is available so that 223 * it can update the MIME data object accordingly. */ 224 connect(pMData, SIGNAL(sigDataAvailable(QString)), 225 this, SLOT(sltDataAvailable(QString)), Qt::DirectConnection); 209 226 210 227 /* Inform the MIME data object of any changes in the current action. */ … … 218 235 * is finished. */ 219 236 pDrag->setMimeData(pMData); 220 pDrag->exec(toQtDnDActions(vecActions), toQtDnDAction(defaultAction)); 221 237 Qt::DropAction dropAction = 238 pDrag->exec(toQtDnDActions(vecActions), toQtDnDAction(defaultAction)); 239 LogFlowFunc(("dropAction=%ld\n", toVBoxDnDAction(dropAction))); 240 #ifdef RT_OS_WINDOWS 241 /* Since the QDrag::exec() call above was blocking on Windows, decide what 242 * to do now, e.g. if there was a "drop" action. 243 * 244 * Note: The UIDnDMimeData object will not be not accessible here anymore, 245 * since QDrag had its ownership and deleted it after the (blocking) 246 * QDrag::exec() call. */ 247 #endif 222 248 rc = VINF_SUCCESS; 223 249 } … … 310 336 } 311 337 338 void UIDnDHandler::sltDataAvailable(const QString &mimeType) 339 { 340 LogFlowFunc(("pMData=0x%p, mimeType=%s\n", 341 pMData, mimeType.toAscii().constData())); 342 343 if (pMData) 344 pMData->setData(mimeType); 345 } 346 312 347 #include "UIDnDHandler.moc" 313 348 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDHandler.h
r50265 r50305 24 24 #include "COMEnums.h" 25 25 26 /* Forward declarations .*/26 /* Forward declarations: */ 27 27 class QMimeData; 28 28 class CSession; 29 29 class CGuest; 30 class UIDnDMimeData; 30 31 31 /** @todo Check for making this a full static class when possible. */32 32 class UIDnDHandler: public QObject 33 33 { 34 Q_OBJECT; 35 34 36 public: 35 37 /* Singleton factory. */ … … 58 60 int dragGHPending(CSession &session, ulong screenId, QWidget *pParent = NULL); 59 61 62 public slots: 63 64 void sltDataAvailable(const QString &mimetype); 65 60 66 private: 61 67 static UIDnDHandler *m_pInstance; … … 70 76 static Qt::DropActions toQtDnDActions(const QVector<KDragAndDropAction> &vecActions); 71 77 78 UIDnDMimeData *pMData; 79 72 80 friend class UIDnDMimeData; 73 81 }; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDMIMEData.cpp
r50265 r50305 24 24 #include <QStringList> 25 25 #include <QTimer> 26 #include <QUrl> 26 27 27 28 #ifdef LOG_GROUP … … 107 108 QVariant::Type type) const 108 109 { 109 LogFlowFunc(("m_enmState=%d, mimeType=%s, type=%d\n", 110 m_enmState, mimeType.toStdString().c_str(), type)); 110 LogFlowFunc(("m_enmState=%d, mimeType=%s, type=%d (%s)\n", 111 m_enmState, mimeType.toStdString().c_str(), 112 type, QVariant::typeToName(type))); 111 113 112 114 bool fCanDrop = true; … … 132 134 * So just update our internal state to reflect the same as on other 133 135 * platforms. */ 134 m_enmState = Dropped;136 fCanDrop = true; 135 137 #else 136 138 /* Mouse button released? See eventFilter for more information. */ … … 139 141 #endif 140 142 141 #if defined (RT_OS_WINDOWS) || defined (RT_OS_MACOS)142 /* Special MIME handling. Later. */143 #endif144 145 143 /* Do we support the requested MIME type? */ 146 144 if ( fCanDrop … … 154 152 /* Supported types. See below in the switch statement. */ 155 153 if ( fCanDrop 156 && !( /* Regular text. */ 154 && !( 155 /* Plain text. */ 157 156 type == QVariant::String 158 157 /* Binary data. */ … … 170 169 LogFlowFunc(("Skipping request, m_enmState=%d ...\n", 171 170 m_enmState)); 172 return QVariant(); 173 } 174 175 CGuest guest = m_session.GetConsole().GetGuest(); 176 /* Start getting the data from the guest. First inform the guest we 177 * want the data in the specified MIME type. */ 178 CProgress progress = guest.DragGHDropped(mimeType, 179 UIDnDHandler::toVBoxDnDAction(m_defAction)); 180 if (guest.isOk()) 181 { 182 msgCenter().showModalProgressDialog(progress, 183 tr("Retrieving data ..."), ":/progress_dnd_gh_90px.png", 184 m_pParent); 185 if (!progress.GetCanceled()) 186 { 187 if ( progress.isOk() 188 && progress.GetResultCode() == 0) 189 { 190 /** @todo What about retrieving bigger files? Loop? */ 191 192 /* After the data successfully arrived from the guest, we query it from Main. */ 193 QVector<uint8_t> data = guest.DragGHGetData(); 194 if (!data.isEmpty()) 171 return QMimeData::retrieveData(mimeType, type); 172 } 173 174 if (m_enmState == Dragging) 175 { 176 int rc = VINF_SUCCESS; 177 178 CGuest guest = m_session.GetConsole().GetGuest(); 179 /* Start getting the data from the guest. First inform the guest we 180 * want the data in the specified MIME type. */ 181 CProgress progress = guest.DragGHDropped(mimeType, 182 UIDnDHandler::toVBoxDnDAction(m_defAction)); 183 if (guest.isOk()) 184 { 185 msgCenter().showModalProgressDialog(progress, 186 tr("Retrieving data ..."), ":/progress_dnd_gh_90px.png", 187 m_pParent); 188 if (!progress.GetCanceled()) 189 { 190 if ( progress.isOk() 191 && progress.GetResultCode() == 0) 195 192 { 196 switch (type) 193 /** @todo What about retrieving bigger files? Loop? */ 194 195 /* After the data successfully arrived from the guest, we query it from Main. */ 196 QVector<uint8_t> data = guest.DragGHGetData(); 197 if (!data.isEmpty()) 197 198 { 198 case QVariant::String:199 switch (type) 199 200 { 200 m_data = QVariant(QString(reinterpret_cast<const char*>(data.data()))); 201 break; 201 case QVariant::String: 202 { 203 m_data = QVariant(QString(reinterpret_cast<const char*>(data.data()))); 204 break; 205 } 206 207 case QVariant::ByteArray: 208 { 209 QByteArray ba(reinterpret_cast<const char*>(data.constData()), data.size()); 210 m_data = QVariant(ba); 211 break; 212 } 213 214 case QVariant::List: 215 { 216 QString strData = QString(reinterpret_cast<const char*>(data.data())); 217 QStringList lstString = strData.split("\r\n", QString::SkipEmptyParts); 218 219 m_data = QVariant(lstString); 220 break; 221 } 222 223 default: 224 AssertMsgFailed(("Should never happen, d'oh!\n")); 225 rc = VERR_NOT_SUPPORTED; 226 break; 202 227 } 203 204 case QVariant::ByteArray:205 {206 QByteArray ba(reinterpret_cast<const char*>(data.constData()), data.size());207 m_data = QVariant(ba);208 break;209 }210 211 case QVariant::List:212 {213 /** @todo Support URIs. */214 break;215 }216 217 default:218 AssertMsgFailed(("Should never happen, d'oh!\n"));219 break;220 228 } 229 /** @todo How often to retry on empty data received? */ 230 231 if (RT_SUCCESS(rc)) 232 emit sigDataAvailable(mimeType); 233 234 m_enmState = DataRetrieved; 221 235 } 222 /** @todo How often to retry on empty data received? */ 223 224 m_enmState = Finished; 236 else 237 msgCenter().cannotDropData(progress, m_pParent); 225 238 } 226 239 else 227 m sgCenter().cannotDropData(progress, m_pParent);240 m_enmState = Canceled; 228 241 } 229 242 else 230 m_enmState = Canceled; 231 } 232 else 233 msgCenter().cannotDropData(guest, m_pParent); 234 243 msgCenter().cannotDropData(guest, m_pParent); 244 } 245 246 //return QMimeData::retrieveData(mimeType, type); 235 247 return m_data; 236 248 } … … 288 300 #endif /* RT_OS_WINDOWS */ 289 301 302 int UIDnDMimeData::setData(const QString &mimeType) 303 { 304 LogFlowFunc(("mimeType=%s, dataType=%s\n", 305 mimeType.toAscii().constData(), m_data.typeName())); 306 307 int rc = VINF_SUCCESS; 308 309 switch (m_data.type()) 310 { 311 case QVariant::String: /* Plain text. */ 312 { 313 QMimeData::setText(m_data.toString()); 314 break; 315 } 316 317 case QVariant::ByteArray: /* Raw byte data. */ 318 { 319 QMimeData::setData(mimeType, m_data.toByteArray()); 320 break; 321 } 322 323 case QVariant::StringList: /* URI. */ 324 { 325 QList<QVariant> lstData = m_data.toList(); 326 QList<QUrl> lstURL; 327 for (int i = 0; i < lstData.size(); i++) 328 { 329 QString strURL = lstData.at(i).toString(); 330 LogFlowFunc(("\tURL: %s\n", 331 strURL.toAscii().constData())); 332 lstURL << QUrl(strURL.toAscii()); 333 } 334 LogFlowFunc(("Number of URLs: %d\n", lstURL.size())); 335 336 QMimeData::setUrls(f); 337 break; 338 } 339 340 default: 341 rc = VERR_NOT_SUPPORTED; 342 break; 343 } 344 345 LogFlowFuncLeaveRC(rc); 346 return rc; 347 } 348 349 #include "UIDnDMIMEData.moc" 350 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDMIMEData.h
r50265 r50305 46 46 { 47 47 Dragging = 0, 48 DataRetrieved, 48 49 Dropped, 49 Finished,50 50 Canceled 51 51 }; … … 56 56 Qt::DropAction defAction, 57 57 Qt::DropActions actions, QWidget *pParent); 58 59 int setData(const QString &mimeType); 58 60 59 61 public slots: … … 74 76 #endif 75 77 /** @} */ 78 79 signals: 80 81 void sigDataAvailable(const QString &mimeType) const; 76 82 77 83 private slots:
Note:
See TracChangeset
for help on using the changeset viewer.