Added some optimization for the drag and drop from Safari: user cannot drop something with missing mimedata

preferencesAboutTextFull
shibakaneki 13 years ago
parent 109794e421
commit 6e80911b95
  1. 6
      src/board/UBBoardController.cpp
  2. 37
      src/gui/UBLibraryWidget.cpp

@ -1846,7 +1846,7 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
QString qsHtml = pMimeData->html(); QString qsHtml = pMimeData->html();
QString url = UBApplication::urlFromHtml(qsHtml); QString url = UBApplication::urlFromHtml(qsHtml);
if(!("" == url)) if("" != url)
{ {
downloadURL(url, pPos); downloadURL(url, pPos);
return; return;
@ -1883,7 +1883,9 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
if (pMimeData->hasText()) if (pMimeData->hasText())
{ {
mActiveScene->addText(pMimeData->text(), pPos); if("" != pMimeData->text()){
mActiveScene->addText(pMimeData->text(), pPos);
}
} }
} }

@ -348,19 +348,16 @@ void UBLibraryWidget::dropEvent(QDropEvent *event)
} }
} }
} }
else else{
{
bool bDropAccepted = false; bool bDropAccepted = false;
// We must check the URLs first because an image dropped from the web can contains the image datas, as well as the URLs // We must check the URLs first because an image dropped from the web can contains the image datas, as well as the URLs
// and if we want to display the download widget in order to make the user wait for the end of the download, we need // and if we want to display the download widget in order to make the user wait for the end of the download, we need
// to check the URLs first! // to check the URLs first!
if (pMimeData->hasUrls()) if (pMimeData->hasUrls()){
{
qDebug() << "hasUrls"; qDebug() << "hasUrls";
QList<QUrl> urlList = pMimeData->urls(); QList<QUrl> urlList = pMimeData->urls();
for (int i = 0; i < urlList.size() && i < 32; ++i) for (int i = 0; i < urlList.size() && i < 32; ++i){
{
QString filePath; QString filePath;
#ifdef Q_WS_MACX #ifdef Q_WS_MACX
filePath = QUrl(urlList.at(i)).toString(); filePath = QUrl(urlList.at(i)).toString();
@ -374,8 +371,7 @@ void UBLibraryWidget::dropEvent(QDropEvent *event)
// When an HTML is present, it means that we dropped something from the web. Normally, the HTML contains the element // When an HTML is present, it means that we dropped something from the web. Normally, the HTML contains the element
// of the webpage and has a 'src' attribute containing the URL of the web ressource. Here we are looking for this // of the webpage and has a 'src' attribute containing the URL of the web ressource. Here we are looking for this
// 'src' attribute, get its value and download the ressource from this URL. // 'src' attribute, get its value and download the ressource from this URL.
else if (pMimeData->hasHtml()) else if (pMimeData->hasHtml()){
{
qDebug() << "hasHtml"; qDebug() << "hasHtml";
QString html = pMimeData->html(); QString html = pMimeData->html();
QString url = UBApplication::urlFromHtml(html); QString url = UBApplication::urlFromHtml(html);
@ -385,33 +381,34 @@ void UBLibraryWidget::dropEvent(QDropEvent *event)
bDropAccepted = true; bDropAccepted = true;
} }
} }
else if (pMimeData->hasText()) else if (pMimeData->hasText()){
{
// On linux external dragged element are considered as text; // On linux external dragged element are considered as text;
qDebug() << "hasText: " << pMimeData->text(); qDebug() << "hasText: " << pMimeData->text();
QString filePath = QUrl(pMimeData->text()).toLocalFile(); QString filePath = QUrl(pMimeData->text()).toLocalFile();
mLibraryController->importItemOnLibrary(filePath); if("" != filePath){
bDropAccepted = true; mLibraryController->importItemOnLibrary(filePath);
bDropAccepted = true;
}
} }
else if (pMimeData->hasImage()) else if (pMimeData->hasImage()){
{
qDebug() << "hasImage"; qDebug() << "hasImage";
QImage image = qvariant_cast<QImage>(pMimeData->imageData()); QImage image = qvariant_cast<QImage>(pMimeData->imageData());
mLibraryController->importImageOnLibrary(image); mLibraryController->importImageOnLibrary(image);
bDropAccepted = true; bDropAccepted = true;
} }
else else{
{
qWarning() << "Cannot import data"; qWarning() << "Cannot import data";
} }
if(bDropAccepted) if(bDropAccepted){
{
onRefreshCurrentFolder(); onRefreshCurrentFolder();
#ifdef Q_WS_MACX
event->acceptProposedAction();
#else
event->accept(); event->accept();
#endif
} }
else else{
{
event->ignore(); event->ignore();
} }
} }

Loading…
Cancel
Save