Resolved some issues related to the drag and drop from an external browser on Mac

preferencesAboutTextFull
Didier 13 years ago
parent 408b16d123
commit 0a329e6602
  1. 11
      src/core/UBApplication.cpp
  2. 31
      src/gui/UBLibPathViewer.cpp
  3. 1
      src/gui/UBLibraryWidget.cpp

@ -643,15 +643,22 @@ QString UBApplication::globalStyleSheet()
QString UBApplication::urlFromHtml(QString html) QString UBApplication::urlFromHtml(QString html)
{ {
qDebug() << "HTML: " << html.remove(QRegExp("[\\0]"));
QString url; QString url;
QDomDocument domDoc; QDomDocument domDoc;
domDoc.setContent(html.remove(QRegExp("[\\0]"))); domDoc.setContent(html.remove(QRegExp("[\\0]")));
QDomElement rootElem = domDoc.documentElement(); QDomElement rootElem = domDoc.documentElement();
// QUICKFIX: Here we have to check rootElem. Sometimes it can be a <meta> tag
// In such a case we will not be able to retrieve the src value
if(rootElem.tagName().toLower().contains("meta")){
qDebug() << rootElem.firstChildElement().tagName();
// In that case we get the next element
url = rootElem.firstChildElement().attribute("src");
}else{
url = rootElem.attribute("src"); url = rootElem.attribute("src");
}
qDebug() << "The URL is: " << url;
return url; return url;
} }

@ -478,9 +478,8 @@ void UBPathScene::dropEvent(QGraphicsSceneDragDropEvent *event)
} }
bAccept = true; bAccept = true;
} }else if(NULL != pMimeData && pMimeData->hasUrls()){
else if(NULL != event->mimeData() && event->mimeData()->hasUrls()){ QList<QUrl> urls = pMimeData->urls();
QList<QUrl> urls = event->mimeData()->urls();
foreach(QUrl eachUrl, urls){ foreach(QUrl eachUrl, urls){
QString sUrl = eachUrl.toString(); QString sUrl = eachUrl.toString();
if(!sUrl.startsWith("uniboardTool://") && !sUrl.startsWith("file://") && !sUrl.startsWith("/")){ if(!sUrl.startsWith("uniboardTool://") && !sUrl.startsWith("file://") && !sUrl.startsWith("/")){
@ -503,11 +502,10 @@ void UBPathScene::dropEvent(QGraphicsSceneDragDropEvent *event)
} }
} }
bAccept = true; bAccept = true;
} }else if(NULL != pMimeData && pMimeData->hasText()){
else if(NULL != event->mimeData() && event->mimeData()->hasText()){
// The user can only drop an Url in this location so if the text is not an Url, // The user can only drop an Url in this location so if the text is not an Url,
// we discard it. // we discard it.
QString qsTxt = event->mimeData()->text().remove(QRegExp("[\\0]")); QString qsTxt = pMimeData->text().remove(QRegExp("[\\0]"));
if(qsTxt.startsWith("http")){ if(qsTxt.startsWith("http")){
// Show the download palette if it is hidden // Show the download palette if it is hidden
UBApplication::boardController->paletteManager()->startDownloads(); UBApplication::boardController->paletteManager()->startDownloads();
@ -524,6 +522,27 @@ void UBPathScene::dropEvent(QGraphicsSceneDragDropEvent *event)
UBDownloadManager::downloadManager()->addFileToDownload(desc); UBDownloadManager::downloadManager()->addFileToDownload(desc);
bAccept = true; bAccept = true;
} }
}else if(NULL != pMimeData && pMimeData->hasHtml()){
QString html = pMimeData->html();
QString url = UBApplication::urlFromHtml(html);
if("" != url)
{
bAccept = true;
// Show the download palette if it is hidden
UBApplication::boardController->paletteManager()->startDownloads();
// Add the dropped url to the download list
sDownloadFileDesc desc;
desc.currentSize = 0;
desc.id = 0;
desc.isBackground = false;
desc.modal = false;
desc.name = QFileInfo(url).fileName();
desc.totalSize = 0;
desc.url = url;
UBDownloadManager::downloadManager()->addFileToDownload(desc);
}
} }
if(bAccept){ if(bAccept){
event->accept(); event->accept();

@ -385,6 +385,7 @@ void UBLibraryWidget::dropEvent(QDropEvent *event)
else if (pMimeData->hasHtml()){ else if (pMimeData->hasHtml()){
qDebug() << "hasHtml"; qDebug() << "hasHtml";
QString html = pMimeData->html(); QString html = pMimeData->html();
qDebug() << html;
QString url = UBApplication::urlFromHtml(html); QString url = UBApplication::urlFromHtml(html);
if("" != url) if("" != url)
{ {

Loading…
Cancel
Save