From 0cd15a38c3cd1b9a1f33d39d125ebe3aa3d0d60a Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Fri, 11 Nov 2011 10:22:49 +0100 Subject: [PATCH] Added a frist drag and drop support from Safari --- src/board/UBLibraryController.cpp | 3 +++ src/gui/UBDownloadWidget.cpp | 5 ---- src/gui/UBLibraryWidget.cpp | 40 ++++++++++++++++++++----------- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp index 1326b458..c271f042 100644 --- a/src/board/UBLibraryController.cpp +++ b/src/board/UBLibraryController.cpp @@ -149,6 +149,9 @@ void UBLibraryController::importImageOnLibrary(QImage& pImage) QDateTime now = QDateTime::currentDateTime(); QString filePath = mPicturesStandardDirectoryPath.toLocalFile() + "/" + tr("ImportedImage") + "-" + now.toString("dd-MM-yyyy hh-mm-ss") + ".png"; filePath = UBFileSystemUtils::normalizeFilePath(filePath); + + qDebug() << "Importing image file from: " << filePath; + pImage.save(filePath); UBApplication::showMessage(tr("Added 1 Image to Library")); } diff --git a/src/gui/UBDownloadWidget.cpp b/src/gui/UBDownloadWidget.cpp index 22661566..566e21a4 100644 --- a/src/gui/UBDownloadWidget.cpp +++ b/src/gui/UBDownloadWidget.cpp @@ -66,11 +66,6 @@ UBDownloadWidget::UBDownloadWidget(QWidget *parent, const char *name):QWidget(pa */ UBDownloadWidget::~UBDownloadWidget() { - if(NULL != mpItem) - { - delete mpItem; - mpItem = NULL; - } if(NULL != mpCancelBttn) { delete mpCancelBttn; diff --git a/src/gui/UBLibraryWidget.cpp b/src/gui/UBLibraryWidget.cpp index 6da8f76e..72fa4cc2 100644 --- a/src/gui/UBLibraryWidget.cpp +++ b/src/gui/UBLibraryWidget.cpp @@ -351,13 +351,29 @@ void UBLibraryWidget::dropEvent(QDropEvent *event) else { bool bDropAccepted = false; - if (pMimeData->hasImage()) + + // 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 + // to check the URLs first! + if (pMimeData->hasUrls()) { - qDebug() << "hasImage"; - QImage image = qvariant_cast(pMimeData->imageData()); - mLibraryController->importImageOnLibrary(image); - bDropAccepted = true; + qDebug() << "hasUrls"; + QList urlList = pMimeData->urls(); + for (int i = 0; i < urlList.size() && i < 32; ++i) + { + QString filePath; +#ifdef Q_WS_MACX + filePath = QUrl(urlList.at(i)).toString(); +#else + filePath = QUrl(urlList.at(i).path()).toLocalFile(); +#endif + mLibraryController->importItemOnLibrary(filePath); + bDropAccepted = true; + } } + // 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 + // 'src' attribute, get its value and download the ressource from this URL. else if (pMimeData->hasHtml()) { qDebug() << "hasHtml"; @@ -377,16 +393,12 @@ void UBLibraryWidget::dropEvent(QDropEvent *event) mLibraryController->importItemOnLibrary(filePath); bDropAccepted = true; } - else if (pMimeData->hasUrls()) + else if (pMimeData->hasImage()) { - qDebug() << "hasUrls"; - QList urlList = pMimeData->urls(); - for (int i = 0; i < urlList.size() && i < 32; ++i) - { - QString filePath = QUrl(urlList.at(i).path()).toLocalFile(); - mLibraryController->importItemOnLibrary(filePath); - bDropAccepted = true; - } + qDebug() << "hasImage"; + QImage image = qvariant_cast(pMimeData->imageData()); + mLibraryController->importImageOnLibrary(image); + bDropAccepted = true; } else {