Changeset 50593 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Feb 26, 2014 8:44:58 AM (11 years ago)
- svn:sync-xref-src-repo-rev:
- 92464
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDDrag.cpp
r50561 r50593 56 56 #endif 57 57 { 58 LogFlowFunc(("m_defAction=0x%x , m_actions=0x%x\n", m_defAction, m_actions));58 LogFlowFunc(("m_defAction=0x%x\n", m_defAction)); 59 59 LogFlowFunc(("Number of formats: %d\n", m_lstFormats.size())); 60 60 #ifdef DEBUG … … 69 69 70 70 int rc = VINF_SUCCESS; 71 try 71 #ifdef RT_OS_WINDOWS 72 UIDnDDropSource *pDropSource = new UIDnDDropSource(this /* pParent */); 73 UIDnDDataObject *pDataObject = new UIDnDDataObject(m_lstFormats, this /* pParent */); 74 75 DWORD dwOKEffects = DROPEFFECT_NONE; 76 if (m_actions) 72 77 { 73 #ifdef RT_OS_WINDOWS 74 UIDnDDropSource *pDropSource = new UIDnDDropSource(this /* pParent */); 75 UIDnDDataObject *pDataObject = new UIDnDDataObject(m_lstFormats, this /* pParent */); 78 if (m_actions & Qt::CopyAction) 79 dwOKEffects |= DROPEFFECT_COPY; 80 if (m_actions & Qt::MoveAction) 81 dwOKEffects |= DROPEFFECT_MOVE; 82 if (m_actions & Qt::LinkAction) 83 dwOKEffects |= DROPEFFECT_LINK; 84 } 76 85 77 DWORD dwOKEffects = DROPEFFECT_NONE; 78 if (m_actions) 79 { 80 if (m_actions & Qt::CopyAction) 81 dwOKEffects |= DROPEFFECT_COPY; 82 if (m_actions & Qt::MoveAction) 83 dwOKEffects |= DROPEFFECT_MOVE; 84 if (m_actions & Qt::LinkAction) 85 dwOKEffects |= DROPEFFECT_LINK; 86 } 86 DWORD dwEffect; 87 HRESULT hr = ::DoDragDrop(pDataObject, pDropSource, 88 dwOKEffects, &dwEffect); 89 LogFlowThisFunc(("DoDragDrop ended with hr=%Rhrc, dwEffect=%RI32\n", 90 hr, dwEffect)); 87 91 88 DWORD dwEffect; 89 HRESULT hr = ::DoDragDrop(pDataObject, pDropSource, 90 dwOKEffects, &dwEffect); 91 LogFlowThisFunc(("DoDragDrop ended with hr=%Rhrc, dwEffect=%RI32\n", 92 hr, dwEffect)); 92 if (pDropSource) 93 pDropSource->Release(); 94 if (pDataObject) 95 pDataObject->Release(); 96 #else 97 QDrag *pDrag = new QDrag(m_pParent); 93 98 94 if (pDropSource) 95 pDropSource->Release(); 96 if (pDataObject) 97 pDataObject->Release(); 98 #else 99 QDrag *pDrag = new QDrag(m_pParent); 99 /* pMData is transfered to the QDrag object, so no need for deletion. */ 100 pMData = new UIDnDMimeData(m_session, m_lstFormats, 101 m_defAction, m_actions, m_pParent); 100 102 101 /* pMData is transfered to the QDrag object, so no need for deletion. */102 pMData = new UIDnDMimeData(m_session, m_lstFormats,103 m_defAction, m_actions, m_pParent);103 /* Inform the MIME data object of any changes in the current action. */ 104 connect(pDrag, SIGNAL(actionChanged(Qt::DropAction)), 105 pMData, SLOT(sltDropActionChanged(Qt::DropAction))); 104 106 105 /* Inform this object that MIME data from the guest is available so that 106 * it can update the MIME data object accordingly. */ 107 connect(pMData, SIGNAL(sigDataAvailable(QString)), 108 this, SLOT(sltDataAvailable(QString)), Qt::DirectConnection); 107 /* Fire it up. 108 * 109 * On Windows this will start a modal operation using OLE's 110 * DoDragDrop() method, so this call will block until the DnD operation 111 * is finished. */ 112 pDrag->setMimeData(pMData); 113 Qt::DropAction dropAction = pDrag->exec(m_actions, m_defAction); 114 LogFlowFunc(("dropAction=%ld\n", UIDnDHandler::toVBoxDnDAction(dropAction))); 109 115 110 /* Inform the MIME data object of any changes in the current action. */ 111 connect(pDrag, SIGNAL(actionChanged(Qt::DropAction)), 112 pMData, SLOT(sltDropActionChanged(Qt::DropAction))); 113 114 /* Fire it up. 115 * 116 * On Windows this will start a modal operation using OLE's 117 * DoDragDrop() method, so this call will block until the DnD operation 118 * is finished. */ 119 pDrag->setMimeData(pMData); 120 Qt::DropAction dropAction = pDrag->exec(m_actions, m_defAction); 121 LogFlowFunc(("dropAction=%ld\n", UIDnDHandler::toVBoxDnDAction(dropAction))); 122 123 /* Note: The UIDnDMimeData object will not be not accessible here anymore, 124 * since QDrag had its ownership and deleted it after the (blocking) 125 * QDrag::exec() call. */ 116 /* Note: The UIDnDMimeData object will not be not accessible here anymore, 117 * since QDrag had its ownership and deleted it after the (blocking) 118 * QDrag::exec() call. */ 126 119 #endif /* !RT_OS_WINDOWS */ 127 }128 catch (std::bad_alloc)129 {130 rc = VERR_NO_MEMORY;131 }132 120 133 121 LogFlowFuncLeaveRC(rc); … … 135 123 } 136 124 137 int UIDnDDrag::RetrieveData(const QString &strMimeType,138 QVariant::Type vaType, QVariant &vaData)139 {140 LogFlowFunc(("Retrieving data as type=%s (variant type=%ld)\n",141 strMimeType.toAscii().constData(), vaType));142 143 int rc = VINF_SUCCESS;144 CGuest guest = m_session.GetConsole().GetGuest();145 146 /* Start getting the data from the guest. First inform the guest we147 * want the data in the specified MIME type. */148 CProgress progress = guest.DragGHDropped(strMimeType,149 UIDnDHandler::toVBoxDnDAction(m_defAction));150 if (guest.isOk())151 {152 msgCenter().showModalProgressDialog(progress,153 tr("Retrieving data ..."), ":/progress_dnd_gh_90px.png",154 m_pParent);155 if (!progress.GetCanceled())156 {157 rc = ( progress.isOk()158 && progress.GetResultCode() == 0)159 ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Fudge; do a GetResultCode() to rc translation. */160 161 if (RT_SUCCESS(rc))162 {163 /* After the data successfully arrived from the guest, we query it from Main. */164 QVector<uint8_t> vecData = guest.DragGHGetData();165 if (!vecData.isEmpty())166 {167 switch (vaType)168 {169 case QVariant::String:170 {171 vaData = QVariant(QString(reinterpret_cast<const char*>(vecData.constData())));172 break;173 }174 175 case QVariant::ByteArray:176 {177 QByteArray ba(reinterpret_cast<const char*>(vecData.constData()), vecData.size());178 vaData = QVariant(ba);179 break;180 }181 182 case QVariant::StringList:183 {184 QString strData = QString(reinterpret_cast<const char*>(vecData.constData()));185 QStringList lstString = strData.split("\r\n", QString::SkipEmptyParts);186 187 vaData = QVariant(lstString);188 break;189 }190 191 default:192 rc = VERR_NOT_SUPPORTED;193 break;194 }195 }196 else197 rc = VERR_NO_DATA;198 }199 else200 msgCenter().cannotDropData(progress, m_pParent);201 }202 else203 rc = VERR_CANCELLED;204 }205 else206 {207 msgCenter().cannotDropData(guest, m_pParent);208 rc = VERR_GENERAL_FAILURE; /** @todo Fudge; do a GetResultCode() to rc translation. */209 }210 211 LogFlowFuncLeaveRC(rc);212 return rc;213 }214 215 #ifndef RT_OS_WINDOWS216 void UIDnDDrag::sltDataAvailable(const QString &mimeType)217 {218 LogFlowFunc(("pMData=0x%p, mimeType=%s\n",219 pMData, mimeType.toAscii().constData()));220 221 if (pMData)222 pMData->setData(mimeType);223 }224 #endif225 226 125 #include "UIDnDDrag.moc" 227 126 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDDrag.h
r50460 r50593 56 56 QVariant::Type vaType, QVariant &vaData); 57 57 58 public slots:59 60 #ifndef RT_OS_WINDOWS61 void sltDataAvailable(const QString &mimetype);62 #endif63 64 58 private: 65 59 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDHandler.cpp
r50460 r50593 234 234 if (!lstFmtNative.isEmpty()) 235 235 { 236 try 237 { 238 UIDnDDrag *pDrag = new UIDnDDrag(session, lstFmtNative, 239 toQtDnDAction(defaultAction), 240 toQtDnDActions(vecActions), pParent); 241 rc = pDrag->DoDragDrop(); 242 243 delete pDrag; 244 } 245 catch (std::bad_alloc) 246 { 247 rc = VERR_NO_MEMORY; 248 } 236 UIDnDDrag *pDrag = new UIDnDDrag(session, lstFmtNative, 237 toQtDnDAction(defaultAction), 238 toQtDnDActions(vecActions), pParent); 239 rc = pDrag->DoDragDrop(); 240 241 delete pDrag; 249 242 } 250 243 else -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDMIMEData.cpp
r50460 r50593 40 40 UIDnDMimeData::UIDnDMimeData(CSession &session, QStringList formats, 41 41 Qt::DropAction defAction, Qt::DropActions actions, 42 UIDnDDrag*pParent)42 QWidget *pParent) 43 43 : m_pParent(pParent) 44 44 , m_session(session) … … 164 164 { 165 165 AssertPtr(m_pParent); 166 rc = m_pParent->RetrieveData(strMIMEType, type, m_data);166 rc = retrieveDataInternal(strMIMEType, type, m_data); 167 167 if (RT_SUCCESS(rc)) 168 168 { … … 178 178 LogFlowFunc(("Returning rc=%Rrc, m_enmState=%ld\n", 179 179 rc, m_enmState)); 180 return QMimeData::retrieveData(strMIMEType, type); 180 return m_data; 181 } 182 183 int UIDnDMimeData::retrieveDataInternal(const QString &strMimeType, 184 QVariant::Type vaType, QVariant &vaData) const 185 { 186 LogFlowFunc(("Retrieving data as type=%s (variant type=%ld)\n", 187 strMimeType.toAscii().constData(), vaType)); 188 189 int rc = VINF_SUCCESS; 190 CGuest guest = m_session.GetConsole().GetGuest(); 191 192 /* Start getting the data from the guest. First inform the guest we 193 * want the data in the specified MIME type. */ 194 CProgress progress = guest.DragGHDropped(strMimeType, 195 UIDnDHandler::toVBoxDnDAction(m_defAction)); 196 if (guest.isOk()) 197 { 198 msgCenter().showModalProgressDialog(progress, 199 tr("Retrieving data ..."), ":/progress_dnd_gh_90px.png", 200 m_pParent); 201 if (!progress.GetCanceled()) 202 { 203 rc = ( progress.isOk() 204 && progress.GetResultCode() == 0) 205 ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /** @todo Fudge; do a GetResultCode() to rc translation. */ 206 207 if (RT_SUCCESS(rc)) 208 { 209 /* After the data successfully arrived from the guest, we query it from Main. */ 210 QVector<uint8_t> vecData = guest.DragGHGetData(); 211 if (!vecData.isEmpty()) 212 { 213 switch (vaType) 214 { 215 case QVariant::String: 216 { 217 vaData = QVariant(QString(reinterpret_cast<const char*>(vecData.constData()))); 218 break; 219 } 220 221 case QVariant::ByteArray: 222 { 223 QByteArray ba(reinterpret_cast<const char*>(vecData.constData()), vecData.size()); 224 vaData = QVariant(ba); 225 break; 226 } 227 228 case QVariant::StringList: 229 { 230 QString strData = QString(reinterpret_cast<const char*>(vecData.constData())); 231 QStringList lstString = strData.split("\r\n", QString::SkipEmptyParts); 232 233 vaData = QVariant(lstString); 234 break; 235 } 236 237 default: 238 rc = VERR_NOT_SUPPORTED; 239 break; 240 } 241 } 242 else 243 rc = VERR_NO_DATA; 244 } 245 else 246 msgCenter().cannotDropData(progress, m_pParent); 247 } 248 else 249 rc = VERR_CANCELLED; 250 } 251 else 252 { 253 msgCenter().cannotDropData(guest, m_pParent); 254 rc = VERR_GENERAL_FAILURE; /** @todo Fudge; do a GetResultCode() to rc translation. */ 255 } 256 257 LogFlowFuncLeaveRC(rc); 258 return rc; 181 259 } 182 260 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIDnDMIMEData.h
r50460 r50593 51 51 * having retrieved the metadata from the guest yet. */ 52 52 Dragging = 0, 53 /** Guest sent over the (MIME) metadata so that the54 * host knows which DnD targets can be used. */55 MetaDataRetrieved,56 53 /** There has been a "dropped" action which indicates 57 54 * that the guest can continue sending more data (if any) … … 66 63 UIDnDMimeData(CSession &session, QStringList formats, 67 64 Qt::DropAction defAction, 68 Qt::DropActions actions, UIDnDDrag*pParent);65 Qt::DropActions actions, QWidget *pParent); 69 66 70 67 int setData(const QString &mimeType); … … 98 95 #endif 99 96 97 protected: 98 99 int retrieveDataInternal(const QString &strMimeType, QVariant::Type vaType, QVariant &vaData) const; 100 100 101 private: 101 102 102 UIDnDDrag*m_pParent;103 QWidget *m_pParent; 103 104 CSession m_session; 104 105 QStringList m_lstFormats;
Note:
See TracChangeset
for help on using the changeset viewer.