diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index 9d8184f3..c62d06ff 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -470,36 +470,6 @@ void UBWidgetUniboardAPI::enableDropOnWidget() mGraphicsWidget->setAcceptDrops(true); } -QString UBWidgetUniboardAPI::downloadUrl(const QString &objectUrl, const QString &extention) -{ - QString result; - QUrl widgetUrl = mGraphicsWidget->getOwnFolder(); - QString destFileName =widgetUrl.toLocalFile() + "/objects/" + QUuid::createUuid().toString() + extention; - - if (UBFileSystemUtils::copyFile(objectUrl, destFileName)) { - result = destFileName.remove(widgetUrl.toLocalFile()); - } else { - qDebug() << "can't copy from " << widgetUrl << "to" << destFileName; - result = QString(); - } - - return result; -} -QString UBWidgetUniboardAPI::downloadWeb(const QString &objectUrl) -{ - // When we fall there, it means that we are dropping something from the web to the board - sDownloadFileDesc desc; - desc.dest = sDownloadFileDesc::graphicsWidget; - desc.modal = true; - desc.url = objectUrl; - desc.currentSize = 0; - desc.name = QFileInfo(objectUrl).fileName(); - desc.totalSize = 0; // The total size will be retrieved during the download - - registerIDWidget(UBDownloadManager::downloadManager()->addFileToDownload(desc)); - return QString(); -} - void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) { const QMimeData *pMimeData = event->mimeData(); @@ -541,7 +511,6 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) registerIDWidget(UBDownloadManager::downloadManager()->addFileToDownload(desc)); -// return; } } else if (pMimeData->hasUrls()) { //Local file processing @@ -554,7 +523,7 @@ void UBWidgetUniboardAPI::ProcessDropEvent(QDropEvent *event) contentType = UBFileSystemUtils::mimeTypeFromFileName(fileName); if (supportedTypeHeader(contentType)) { - destFileName = getObjDir() + QUuid::createUuid().toString() + extention; + destFileName = getObjDir() + QUuid::createUuid().toString() + "." + extention; if (!UBFileSystemUtils::copyFile(fileName, destFileName)) { qDebug() << "can't copy from" << fileName << "to" << destFileName; @@ -625,8 +594,8 @@ void UBWidgetUniboardAPI::onDownloadFinished(bool pSuccess, sDownloadFileDesc de destFile.close(); //To make js interpreter accept drop event we need to generate move event first. - QDragMoveEvent readmove(dropPoint, desc.dropActions, &dropMimeData, desc.dropMouseButtons, desc.dropModifiers); - QApplication::sendEvent(mGraphicsWidget->widgetWebView(),&readmove); + QDragMoveEvent pseudoMove(dropPoint, desc.dropActions, &dropMimeData, desc.dropMouseButtons, desc.dropModifiers); + QApplication::sendEvent(mGraphicsWidget->widgetWebView(),&pseudoMove); QDropEvent readyEvent(dropPoint, desc.dropActions, &dropMimeData, desc.dropMouseButtons, desc.dropModifiers); //sending event to destination either it had been downloaded or not @@ -680,6 +649,25 @@ bool UBWidgetUniboardAPI::takeIDWidget(int id) return false; } +bool UBWidgetUniboardAPI::isDropableData(const QMimeData *pMimeData) const +{ + QString fileName = QString(); + if (pMimeData->hasHtml()) { + fileName = UBApplication::urlFromHtml(pMimeData->html()); + if (fileName.isEmpty()) + return false; + } else if (pMimeData->hasUrls()) { + fileName = pMimeData->urls().at(0).toLocalFile(); + if (fileName.isEmpty()) + return false; + } + + if (supportedTypeHeader(UBFileSystemUtils::mimeTypeFromFileName(fileName))) + return true; + + return false; +} + UBDocumentDatastoreAPI::UBDocumentDatastoreAPI(UBGraphicsW3CWidgetItem *graphicsWidget) : UBW3CWebStorage(graphicsWidget) diff --git a/src/api/UBWidgetUniboardAPI.h b/src/api/UBWidgetUniboardAPI.h index 66731e87..ffa9cfa3 100644 --- a/src/api/UBWidgetUniboardAPI.h +++ b/src/api/UBWidgetUniboardAPI.h @@ -246,9 +246,8 @@ class UBWidgetUniboardAPI : public QObject * When an object is dropped on a widget, this one send us the informations to download it locally. * this method download the object on the widget directory and return the path of the downloaded object */ - QString downloadUrl(const QString &objectUrl, const QString &extention = ""); - QString downloadWeb(const QString &objectUrl); void ProcessDropEvent(QDropEvent *); + bool isDropableData(const QMimeData *pMimeData) const; private slots: void onDownloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData); @@ -257,6 +256,7 @@ private: inline void registerIDWidget(int id){webDownloadIds.append(id);} inline bool takeIDWidget(int id); + private: QString uuid(); diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 1cf8683d..2b2965f0 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -52,18 +52,6 @@ #include "core/memcheck.h" -//Known extentions for files, add if you know more supported -const QString audioExtentions = ".mp3.wma.ogg"; -const QString videoExtentions = ".avi.flv"; -const QString imageExtentions = ".png.jpg.tif.bmp.tga"; -const QString htmlExtentions = ".htm.html.xhtml"; - -//Allways use aliases instead of const char* itself -const QString imageAlias = "image"; -const QString videoAlias = "video"; -const QString audioAlias = "audio"; -const QString htmlAlias = "html"; - UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) : QGraphicsView (pParent) , mController (pController) @@ -724,11 +712,11 @@ UBBoardView::drawItems (QPainter *painter, int numItems, } } -void UBBoardView::dragEnterEvent (QDragEnterEvent *event) -{ - // TODO UB 4.x be smarter with drag accept code .... we cannot handle everything ... - event->acceptProposedAction (); -} +//void UBBoardView::dragEnterEvent (QDragEnterEvent *event) +//{ +// // TODO UB 4.x be smarter with drag accept code .... we cannot handle everything ... +// event->acceptProposedAction (); +//} void UBBoardView::dragMoveEvent (QDragMoveEvent *event) { @@ -738,7 +726,7 @@ void UBBoardView::dragMoveEvent (QDragMoveEvent *event) if (graphicsWidget) { if (graphicsWidget->acceptDrops()) { if (!mOkOnWidget) { - if (!isDropableData(event->mimeData())) { + if (!graphicsWidget->isDropableData(event->mimeData())) { mOkOnWidget = false; event->ignore(); return; @@ -759,48 +747,6 @@ void UBBoardView::dragMoveEvent (QDragMoveEvent *event) } } -QString UBBoardView::fileExtention(const QString &filename) const -{ - int pos = filename.lastIndexOf("."); - if (pos != -1) - return filename.right(filename.size() - pos); - else - return QString(); -} -QString UBBoardView::typeForExtention(const QString &extention) const -{ - if (extention.isEmpty()) - return QString(); - - QString result = QString(); - - if (audioExtentions.contains(extention)) { - result = audioAlias; - } else if (videoExtentions.contains(extention)) { - result = videoAlias; - } else if (imageExtentions.contains(extention)) { - result = imageAlias; -// } else if (htmlExtentions.contains(extention)) { -// result = htmlAlias; - } - - return result; -} -bool UBBoardView::isDropableData(const QMimeData *pMimeData) const -{ - if (pMimeData->hasHtml()) { - return true; - } - - if (pMimeData->hasUrls()) { - if (!typeForExtention(fileExtention(pMimeData->urls().at(0).toLocalFile())).isNull()) { - return true; - } - } - - return false; -} - void UBBoardView::dropEvent (QDropEvent *event) { mOkOnWidget = false; diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index 5353c711..0772d3f2 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -65,7 +65,7 @@ class UBBoardView : public QGraphicsView QGraphicsItem *items[], const QStyleOptionGraphicsItem options[]); - virtual void dragEnterEvent(QDragEnterEvent * event); +// virtual void dragEnterEvent(QDragEnterEvent * event); virtual void dropEvent(QDropEvent *event); virtual void dragMoveEvent(QDragMoveEvent *event); @@ -88,8 +88,6 @@ class UBBoardView : public QGraphicsView } QList processMimeData(const QMimeData* pMimeData); - QString processMimeData(const QMimeData *pMimeData, UBGraphicsWidgetItem *widget); - bool isDropableData(const QMimeData *pMimeData) const; UBBoardController* mController; @@ -118,9 +116,6 @@ class UBBoardView : public QGraphicsView bool mVirtualKeyboardActive; bool mOkOnWidget; - QString typeForExtention(const QString &extention) const; - QString fileExtention(const QString &filename) const; - private slots: void settingChanged(QVariant newValue); diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 08ac72b1..cf7524ec 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -278,18 +278,14 @@ void UBGraphicsWidgetItem::clearSource() UBFileSystemUtils::deleteFile(getSnapshotPath().toLocalFile()); } -QString UBGraphicsWidgetItem::downloadUrl(const QString &fileUrl, const QString &extention) -{ - return mUniboardAPI->downloadUrl(fileUrl, extention); -} -QString UBGraphicsWidgetItem::downloadWeb(const QString &fileUrl) -{ - return mUniboardAPI->downloadWeb(fileUrl); -} void UBGraphicsWidgetItem::processDropEvent(QDropEvent *event) { return mUniboardAPI->ProcessDropEvent(event); } +bool UBGraphicsWidgetItem::isDropableData(const QMimeData *data) const +{ + return mUniboardAPI->isDropableData(data); +} UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent) : UBGraphicsWidgetItem(parent) diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 9eba8d80..2b73b5bc 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -70,6 +70,7 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget QString downloadUrl(const QString &fileUrl, const QString &extention); QString downloadWeb(const QString &fileUrl); void processDropEvent(QDropEvent *event); + bool isDropableData(const QMimeData *data) const; virtual void setOwnFolder(const QUrl &newFolder) {ownFolder = newFolder;} virtual QUrl getOwnFolder() const {return ownFolder;}