From 969706ae179a6ff9850399fec67dca603baa71aa Mon Sep 17 00:00:00 2001 From: Ivan Ilin Date: Thu, 12 Jan 2012 20:06:06 +0200 Subject: [PATCH] Dragndrop operations on w3cwidgets, some code cleaning unused files in file system --- src/adaptors/UBSvgSubsetAdaptor.cpp | 8 +- src/api/UBWidgetUniboardAPI.cpp | 21 +++- src/api/UBWidgetUniboardAPI.h | 25 ++--- src/board/UBBoardController.cpp | 6 +- src/board/UBBoardView.cpp | 149 ++++++++++++++++--------- src/board/UBBoardView.h | 5 + src/board/UBLibraryController.cpp | 2 +- src/core/UBApplication.cpp | 3 +- src/core/UBSettings.cpp | 1 + src/domain/UBGraphicsAudioItem.h | 6 + src/domain/UBGraphicsMediaItem.cpp | 14 +++ src/domain/UBGraphicsMediaItem.h | 4 + src/domain/UBGraphicsPDFItem.h | 2 + src/domain/UBGraphicsPixmapItem.h | 1 + src/domain/UBGraphicsProxyWidget.h | 2 + src/domain/UBGraphicsScene.cpp | 2 - src/domain/UBGraphicsTextItem.h | 2 + src/domain/UBGraphicsVideoItem.h | 6 + src/domain/UBGraphicsWidgetItem.cpp | 4 + src/domain/UBGraphicsWidgetItem.h | 2 + src/domain/UBItem.h | 1 + src/frameworks/UBCoreGraphicsScene.cpp | 17 +++ src/frameworks/UBFileSystemUtils.cpp | 22 ++++ src/frameworks/UBFileSystemUtils.h | 2 + src/gui/UBThumbnailWidget.cpp | 9 +- src/tools/UBGraphicsCurtainItem.h | 1 + 26 files changed, 228 insertions(+), 89 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index 6533e06a..cae29ac5 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1827,13 +1827,13 @@ UBGraphicsAudioItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::audioItemFromSvg() return 0; } - QString href = audioHref.toString(); + QString href = mDocumentPath + "/" + audioHref.toString(); //Claudio this is necessary to fix the absolute path added on Sankore 3.1 1.00.00 //The absoult path doesn't work when you want to share Sankore documents. if(!href.startsWith("audios/")){ int indexOfAudioDirectory = href.lastIndexOf("audios"); - href = href.right(href.length() - indexOfAudioDirectory); + href = mDocumentPath + "/" + href.right(href.length() - indexOfAudioDirectory); } UBGraphicsAudioItem* audioItem = new UBGraphicsAudioItem(href); @@ -1861,13 +1861,13 @@ UBGraphicsVideoItem* UBSvgSubsetAdaptor::UBSvgSubsetReader::videoItemFromSvg() return 0; } - QString href = videoHref.toString(); + QString href = mDocumentPath + "/" + videoHref.toString(); //Claudio this is necessary to fix the absolute path added on Sankore 3.1 1.00.00 //The absoult path doesn't work when you want to share Sankore documents. if(!href.startsWith("videos/")){ int indexOfAudioDirectory = href.lastIndexOf("videos"); - href = href.right(href.length() - indexOfAudioDirectory); + href = mDocumentPath + "/" + href.right(href.length() - indexOfAudioDirectory); } UBGraphicsVideoItem* videoItem = new UBGraphicsVideoItem(href); diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index 72a6c627..02859033 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -34,9 +34,12 @@ #include "adaptors/UBThumbnailAdaptor.h" #include "UBWidgetMessageAPI.h" +#include "frameworks/UBFileSystemUtils.h" #include "core/memcheck.h" +const QString objectsPath = "objects"; + UBWidgetUniboardAPI::UBWidgetUniboardAPI(UBGraphicsScene *pScene, UBGraphicsWidgetItem *widget) : QObject(pScene) , mScene(pScene) @@ -433,14 +436,20 @@ void UBWidgetUniboardAPI::enableDropOnWidget() mGraphicsWidget->setAcceptDrops(true); } -QString UBWidgetUniboardAPI::downloadUrl(QString objectUrl) +QString UBWidgetUniboardAPI::downloadUrl(const QString &objectUrl, const QString &extention) { - qDebug() << "UBWidgetUniboardAPI : " << objectUrl; + QString result; QUrl widgetUrl = mGraphicsWidget->widgetWebView()->widgetUrl(); - QString destFileName =widgetUrl.toString()+ "/objects/" + QUuid::createUuid().toString(); - QFile(objectUrl).copy(destFileName); - qDebug() << "destFileName : " << destFileName; - return destFileName.remove(widgetUrl.toString()); + 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; } diff --git a/src/api/UBWidgetUniboardAPI.h b/src/api/UBWidgetUniboardAPI.h index 5c8790e5..56188d03 100644 --- a/src/api/UBWidgetUniboardAPI.h +++ b/src/api/UBWidgetUniboardAPI.h @@ -27,26 +27,25 @@ class UBWidgetMessageAPI; class UBDatastoreAPI; class UBDocumentDatastoreAPI; - class UBWidgetUniboardAPI : public QObject { - Q_OBJECT; + Q_OBJECT /** * The number of pages in the current document */ - Q_PROPERTY(int pageCount READ pageCount SCRIPTABLE true); + Q_PROPERTY(int pageCount READ pageCount SCRIPTABLE true) /** * The page number of the current page */ - Q_PROPERTY(int currentPageNumber READ currentPageNumber SCRIPTABLE true); + Q_PROPERTY(int currentPageNumber READ currentPageNumber SCRIPTABLE true) /** * instance UUID, return a unique identifier for the widget, this value is guaranted to be unique * and constant for a widget, deprecated, use window.widget.uuid instead */ - Q_PROPERTY(QString uuid READ uuid SCRIPTABLE true); + Q_PROPERTY(QString uuid READ uuid SCRIPTABLE true) /** * Returns the language and eventually the country of this locale as a string of the form @@ -63,11 +62,11 @@ class UBWidgetUniboardAPI : public QObject * fr-FR * */ - Q_PROPERTY(QString lang READ lang SCRIPTABLE true); + Q_PROPERTY(QString lang READ lang SCRIPTABLE true) - Q_PROPERTY(QObject* messages READ messages SCRIPTABLE true); + Q_PROPERTY(QObject* messages READ messages SCRIPTABLE true) - Q_PROPERTY(QObject* datastore READ datastore SCRIPTABLE true); + Q_PROPERTY(QObject* datastore READ datastore SCRIPTABLE true) public: @@ -245,7 +244,7 @@ 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(QString objectUrl); + QString downloadUrl(const QString &objectUrl, const QString &extention = ""); private: @@ -272,13 +271,13 @@ class UBWidgetUniboardAPI : public QObject class UBDatastoreAPI : public QObject { - Q_OBJECT; + Q_OBJECT - Q_PROPERTY(QObject* document READ document SCRIPTABLE true); + Q_PROPERTY(QObject* document READ document SCRIPTABLE true) public: UBDatastoreAPI(UBGraphicsW3CWidgetItem *widget); - virtual ~UBDatastoreAPI(){}; + virtual ~UBDatastoreAPI(){;} QObject* document(); @@ -291,7 +290,7 @@ class UBDatastoreAPI : public QObject class UBDocumentDatastoreAPI : public UBW3CWebStorage { - Q_OBJECT; + Q_OBJECT public: UBDocumentDatastoreAPI(UBGraphicsW3CWidgetItem *graphicsWidget); diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index f96d2d99..d7fa305c 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -1221,7 +1221,7 @@ void UBBoardController::ClearUndoStack() while (itUniq.hasNext()) { QGraphicsItem* item = itUniq.next(); - UBGraphicsScene *scene = (UBGraphicsScene*)item->scene(); + UBGraphicsScene *scene = dynamic_cast(item->scene()); if(!scene) { mActiveScene->deleteItem(item); @@ -1365,15 +1365,13 @@ void UBBoardController::documentSceneChanged(UBDocumentProxy* pDocumentProxy, in } } - void UBBoardController::closing() { mIsClosing = true; - + ClearUndoStack(); lastWindowClosed(); } - void UBBoardController::lastWindowClosed() { if (!mCleanupDone) diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 8b02b856..2b65fdb0 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -15,6 +15,7 @@ #include "UBBoardView.h" #include +#include #include "UBDrawingController.h" @@ -48,6 +49,24 @@ #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"; + +//Xml tag names +const QString tMainSection = "mimedata"; +const QString tType = "type"; +const QString tPath = "path"; + UBBoardView::UBBoardView (UBBoardController* pController, QWidget* pParent) : QGraphicsView (pParent) , mController (pController) @@ -720,64 +739,93 @@ void UBBoardView::dragMoveEvent (QDragMoveEvent *event) UBGraphicsWidgetItem* graphicsWidget = dynamic_cast(graphicsItemAtPos); if (graphicsWidget && graphicsWidget->acceptDrops()){ - QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); - QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); - QApplication::sendEvent(graphicsWidget->widgetWebView(),&newEvent); - return; + if (isDropableData(event->mimeData())) { + QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); + QDragMoveEvent newEvent(newPoint, event->dropAction(), event->mimeData(), event->mouseButtons(), event->keyboardModifiers()); + QApplication::sendEvent(graphicsWidget->widgetWebView(),&newEvent); + } else { + event->ignore(); + } + } else { + event->acceptProposedAction(); } - - event->acceptProposedAction(); } -QList UBBoardView::processMimeData(const QMimeData* pMimeData) +QString UBBoardView::processMimeData(const QMimeData *pMimeData, UBGraphicsWidgetItem *widget) { - QList result; - if(pMimeData->hasHtml()) - { - QString qsHtml = pMimeData->html(); - result.append(QUrl(UBApplication::urlFromHtml(qsHtml))); - } + QString mimeXml; + QXmlStreamWriter writer(&mimeXml); + writer.setAutoFormatting(true); + writer.writeStartDocument(); + writer.writeStartElement(tMainSection); + + if (pMimeData->hasUrls()) { + QList urls = pMimeData->urls(); + + QString ext = fileExtention(urls.at(0).toLocalFile()); + if (ext.isNull()) { + qDebug() << "unknown file type"; + return QString(); + } + QString fileType = typeForExtention(ext); + if (fileType.isNull()) { + qDebug() << "unknown extention"; + return QString(); + } - if (pMimeData->hasUrls()) - { - result.append(pMimeData->urls()); - return result; - } + //writing type of element + writer.writeTextElement(tType, fileType); - if (pMimeData->hasImage()) - { - qWarning() << "Not supported yet"; - } + QString fileName = urls.at(0).toLocalFile(); + QString destName = widget->downloadUrl(fileName, ext); - if (pMimeData->hasText()) - { - if("" != pMimeData->text()){ - // Sometimes, it is possible to have an URL as text. we check here if it is the case - QString qsTmp = pMimeData->text().remove(QRegExp("[\\0]")); - if(qsTmp.startsWith("http")){ - result.append(QUrl(qsTmp)); - } - else{ - qWarning() << "what to do with this : " << pMimeData->text(); - //mActiveScene->addText(pMimeData->text(), pPos); - } - } - else{ -#ifdef Q_WS_MACX - // With Safari, in 95% of the drops, the mime datas are hidden in Apple Web Archive pasteboard type. - // This is due to the way Safari is working so we have to dig into the pasteboard in order to retrieve - // the data. - QString qsUrl = UBPlatformUtils::urlFromClipboard(); - if("" != qsUrl){ - // We finally got the url of the dropped ressource! Let's import it! - result.append(QUrl(qsUrl)); - } -#endif + if (destName.isNull()) { + qDebug() << "error at creating destination folder"; + return QString(); } + + //writing path to created object + writer.writeTextElement(tPath, destName); } + + writer.writeEndElement(); + writer.writeEndDocument(); + + return mimeXml; +} + +QString UBBoardView::fileExtention(const QString &filename) +{ + int pos = filename.lastIndexOf("."); + if (pos != -1) + return filename.right(filename.size() - pos); + else + return QString(); +} +QString UBBoardView::typeForExtention(const QString &extention) +{ + 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) +{ + if (pMimeData->hasUrls()) + if (!typeForExtention(fileExtention(pMimeData->urls().at(0).toLocalFile())).isNull()) + return true; + return false; +} void UBBoardView::dropEvent (QDropEvent *event) { @@ -785,21 +833,18 @@ void UBBoardView::dropEvent (QDropEvent *event) QGraphicsItem* graphicsItemAtPos = itemAt(event->pos().x(),event->pos().y()); UBGraphicsWidgetItem* graphicsWidget = dynamic_cast(graphicsItemAtPos); - bool acceptDrops(false); - if (graphicsWidget) { - acceptDrops = graphicsWidget->acceptDrops(); - graphicsWidget->setAcceptDrops(true); - } if (graphicsWidget && graphicsWidget->acceptDrops()){ // A new event is build to avoid problem related to different way to pass the mime type // A parsing is done to try to provide a mimeType with only urls. QMimeData mimeData; - mimeData.setData("Text",processMimeData(event->mimeData()).at(0).toString().toAscii()); + QString str = processMimeData(event->mimeData(), graphicsWidget); + mimeData.setData("text/plain", str.toAscii()); QPoint newPoint(graphicsWidget->mapFromScene(mapToScene(event->pos())).toPoint()); QDropEvent cleanedEvent(newPoint, event->dropAction(), &mimeData, event->mouseButtons(), event->keyboardModifiers()); QApplication::sendEvent(graphicsWidget->widgetWebView(),&cleanedEvent); cleanedEvent.acceptProposedAction(); event->acceptProposedAction(); + return; } if(!event->source() || dynamic_cast(event->source()) || dynamic_cast(event->source())) diff --git a/src/board/UBBoardView.h b/src/board/UBBoardView.h index 17532ded..a003cb85 100644 --- a/src/board/UBBoardView.h +++ b/src/board/UBBoardView.h @@ -22,6 +22,7 @@ class UBBoardController; class UBAppleWidget; class UBGraphicsScene; +class UBGraphicsWidgetItem; class UBBoardView : public QGraphicsView { @@ -87,6 +88,8 @@ class UBBoardView : public QGraphicsView } QList processMimeData(const QMimeData* pMimeData); + QString processMimeData(const QMimeData *pMimeData, UBGraphicsWidgetItem *widget); + bool isDropableData(const QMimeData *pMimeData); UBBoardController* mController; @@ -113,6 +116,8 @@ class UBBoardView : public QGraphicsView bool isAbsurdPoint(QPoint point); bool mVirtualKeyboardActive; + QString typeForExtention(const QString &extention); + QString fileExtention(const QString &filename); private slots: diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp index bd4b48b9..a3f56738 100644 --- a/src/board/UBLibraryController.cpp +++ b/src/board/UBLibraryController.cpp @@ -649,7 +649,7 @@ QRectF UBLibraryController::visibleSceneRect() void UBLibraryController::addImagesToCurrentPage(const QList& images) { - QPointF pos = visibleSceneRect().topLeft(); + QPointF pos = visibleSceneRect().center(); foreach(const QUrl url, images) { diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index b0f063f4..45c5a586 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -138,7 +138,8 @@ UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSing QTranslator *translator = new QTranslator(this); - translator->load(UBPlatformUtils::preferredTranslation()); +// translator->load(UBPlatformUtils::preferredTranslation()); + translator->load("/home/ilia/Sankore/Sankore-3.1/resources/i18n/sankore_ru.qm"); installTranslator(translator); diff --git a/src/core/UBSettings.cpp b/src/core/UBSettings.cpp index 0db96ae9..f6c300e5 100644 --- a/src/core/UBSettings.cpp +++ b/src/core/UBSettings.cpp @@ -362,6 +362,7 @@ void UBSettings::init() podcastPublishToIntranet = new UBSetting(this, "IntranetPodcast", "PublishToIntranet", false); intranetPodcastPublishingUrl = new UBSetting(this, "IntranetPodcast", "PublishingUrl", ""); intranetPodcastAuthor = new UBSetting(this, "IntranetPodcast", "Author", ""); + } diff --git a/src/domain/UBGraphicsAudioItem.h b/src/domain/UBGraphicsAudioItem.h index 337ba99d..438dfca7 100644 --- a/src/domain/UBGraphicsAudioItem.h +++ b/src/domain/UBGraphicsAudioItem.h @@ -19,6 +19,8 @@ #include "phonon/seekslider.h" #include "phonon/mediasource.h" #include "core/UB.h" +#include "core/UBApplication.h" +#include "board/UBBoardController.h" class UBGraphicsAudioItem : public UBGraphicsMediaItem { @@ -39,6 +41,10 @@ public: virtual UBItem* deepCopy () const; virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} + virtual void clearSource() + { + UBGraphicsMediaItem::clearSource(); + } private slots: diff --git a/src/domain/UBGraphicsMediaItem.cpp b/src/domain/UBGraphicsMediaItem.cpp index 44ccfa2a..d491b664 100644 --- a/src/domain/UBGraphicsMediaItem.cpp +++ b/src/domain/UBGraphicsMediaItem.cpp @@ -82,6 +82,20 @@ QVariant UBGraphicsMediaItem::itemChange(GraphicsItemChange change, const QVaria return UBGraphicsProxyWidget::itemChange(change, value); } +void UBGraphicsMediaItem::clearSource() +{ + QString path = mediaFileUrl().path(); + + //if path is absolute clean duplicated path string + if (!path.contains(UBApplication::boardController->activeDocument()->persistencePath())) + path = UBApplication::boardController->activeDocument()->persistencePath() + "/" + path; + + QFile f(path); + f.setPermissions(path, QFile::ReadOwner | QFile::WriteOwner); + f.remove(); + +} + void UBGraphicsMediaItem::toggleMute() { mMuted = !mMuted; diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index ed128fda..f31841bc 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -18,6 +18,8 @@ #include "UBGraphicsProxyWidget.h" #include #include +#include "core/UBApplication.h" +#include "board/UBBoardController.h" class UBGraphicsMediaItem : public UBGraphicsProxyWidget @@ -65,6 +67,8 @@ protected: virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value); + virtual void clearSource(); + Phonon::MediaObject *mMediaObject; Phonon::AudioOutput *mAudioOutput; diff --git a/src/domain/UBGraphicsPDFItem.h b/src/domain/UBGraphicsPDFItem.h index 426361cf..847290c6 100644 --- a/src/domain/UBGraphicsPDFItem.h +++ b/src/domain/UBGraphicsPDFItem.h @@ -50,6 +50,8 @@ class UBGraphicsPDFItem: public GraphicsPDFItem, public UBItem, public UBGraphic virtual UBGraphicsPixmapItem* toPixmapItem() const; virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} + virtual void clearSource(){;} + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/domain/UBGraphicsPixmapItem.h b/src/domain/UBGraphicsPixmapItem.h index 141710ae..56608ba1 100644 --- a/src/domain/UBGraphicsPixmapItem.h +++ b/src/domain/UBGraphicsPixmapItem.h @@ -50,6 +50,7 @@ class UBGraphicsPixmapItem : public QObject, public QGraphicsPixmapItem, public qreal opacity() const; virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} + virtual void clearSource(){;} protected: diff --git a/src/domain/UBGraphicsProxyWidget.h b/src/domain/UBGraphicsProxyWidget.h index 4f27e574..6faecb06 100644 --- a/src/domain/UBGraphicsProxyWidget.h +++ b/src/domain/UBGraphicsProxyWidget.h @@ -43,6 +43,8 @@ class UBGraphicsProxyWidget: public QGraphicsProxyWidget, public UBItem, public virtual UBGraphicsItemDelegate* Delegate() const { return mDelegate;} + virtual void clearSource(){;} + protected: virtual void mousePressEvent(QGraphicsSceneMouseEvent *event); diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp index 693c7d48..6887e397 100644 --- a/src/domain/UBGraphicsScene.cpp +++ b/src/domain/UBGraphicsScene.cpp @@ -1442,13 +1442,11 @@ void UBGraphicsScene::deselectAllItems() } } - bool UBGraphicsScene::isEmpty() const { return mItemCount == 0; } - QGraphicsItem* UBGraphicsScene::setAsBackgroundObject(QGraphicsItem* item, bool pAdaptTransformation, bool pExpand) { if (mBackgroundObject) diff --git a/src/domain/UBGraphicsTextItem.h b/src/domain/UBGraphicsTextItem.h index fd7c1a24..d60116f7 100644 --- a/src/domain/UBGraphicsTextItem.h +++ b/src/domain/UBGraphicsTextItem.h @@ -80,6 +80,8 @@ class UBGraphicsTextItem : public QGraphicsTextItem, public UBItem, public UBRes } virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} + virtual void clearSource(){;} + signals: void textUndoCommandAdded(UBGraphicsTextItem *textItem); diff --git a/src/domain/UBGraphicsVideoItem.h b/src/domain/UBGraphicsVideoItem.h index 52e8b0aa..b07ea584 100644 --- a/src/domain/UBGraphicsVideoItem.h +++ b/src/domain/UBGraphicsVideoItem.h @@ -18,6 +18,8 @@ #include #include "UBGraphicsMediaItem.h" #include "core/UB.h" +#include "core/UBApplication.h" +#include "board/UBBoardController.h" class UBGraphicsVideoItem : public UBGraphicsMediaItem { @@ -42,6 +44,10 @@ public: } virtual UBGraphicsItemDelegate *Delegate() const {return mDelegate;} + virtual void clearSource() + { + UBGraphicsMediaItem::clearSource(); + } public slots: void hasVideoChanged(bool hasVideo); diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index ca2d578f..4105e207 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -246,6 +246,10 @@ void UBGraphicsWidgetItem::removeScript() mWebKitWidget->page()->mainFrame()->evaluateJavaScript("if(widget && widget.onremove) { widget.onremove();}"); } } +QString UBGraphicsWidgetItem::downloadUrl(const QString &fileUrl, const QString &extention) +{ + return mUniboardAPI->downloadUrl(fileUrl, extention); +} UBGraphicsAppleWidgetItem::UBGraphicsAppleWidgetItem(const QUrl& pWidgetUrl, QGraphicsItem *parent) : UBGraphicsWidgetItem(parent) diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 37386df6..6b79244a 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -66,8 +66,10 @@ class UBGraphicsWidgetItem : public UBGraphicsProxyWidget virtual void remove(); void removeScript(); + QString downloadUrl(const QString &fileUrl, const QString &extention); + virtual void clearSource(){;} protected: diff --git a/src/domain/UBItem.h b/src/domain/UBItem.h index 7ae29988..9a318011 100644 --- a/src/domain/UBItem.h +++ b/src/domain/UBItem.h @@ -105,6 +105,7 @@ public: virtual void remove() = 0; + virtual void clearSource(){;} }; #endif // UBITEM_H diff --git a/src/frameworks/UBCoreGraphicsScene.cpp b/src/frameworks/UBCoreGraphicsScene.cpp index bcac6202..1c8d0cd9 100644 --- a/src/frameworks/UBCoreGraphicsScene.cpp +++ b/src/frameworks/UBCoreGraphicsScene.cpp @@ -16,6 +16,9 @@ #include "UBCoreGraphicsScene.h" #include "core/memcheck.h" +#include "domain/UBGraphicsAudioItem.h" +#include "domain/UBGraphicsVideoItem.h" +#include "domain/UBGraphicsMediaItem.h" UBCoreGraphicsScene::UBCoreGraphicsScene(QObject * parent) : QGraphicsScene ( parent ) @@ -58,6 +61,20 @@ bool UBCoreGraphicsScene::deleteItem(QGraphicsItem* item) { if(mItemsToDelete.contains(item)) { + UBGraphicsItem* item_casted = 0; + switch (item->type()) + { + case UBGraphicsAudioItem::Type: + item_casted = dynamic_cast(item); + break; + case UBGraphicsVideoItem::Type: + item_casted = dynamic_cast(item); + break; + } + + if (0 != item_casted) + item_casted->clearSource(); + mItemsToDelete.remove(item); delete item; return true; diff --git a/src/frameworks/UBFileSystemUtils.cpp b/src/frameworks/UBFileSystemUtils.cpp index 1cd8e27e..4dbe38c2 100644 --- a/src/frameworks/UBFileSystemUtils.cpp +++ b/src/frameworks/UBFileSystemUtils.cpp @@ -54,6 +54,28 @@ bool UBFileSystemUtils::isAZipFile(QString &filePath) return result; } +bool UBFileSystemUtils::copyFile(const QString &source, const QString &Destination, bool overwrite) +{ + if (!QFile::exists(source)) { + qDebug() << "file" << source << "does not present in fs"; + return false; + } + if (QFile::exists(Destination)) { + if (QFileInfo(Destination).isFile() && overwrite) { + QFile::remove(Destination); + } + } else { + int pos = Destination.lastIndexOf(QDir::separator()); + if (pos != -1) { + QString newpath = Destination.left(pos); + if (!QDir().mkpath(newpath)) { + qDebug() << "can't create a new path at " << newpath; + } + } + } + return QFile::copy(source, Destination); +} + QString UBFileSystemUtils::defaultTempDirPath() { return QDesktopServices::storageLocation(QDesktopServices::TempLocation) + "/" + defaultTempDirName(); diff --git a/src/frameworks/UBFileSystemUtils.h b/src/frameworks/UBFileSystemUtils.h index 4476ea95..1a496b52 100644 --- a/src/frameworks/UBFileSystemUtils.h +++ b/src/frameworks/UBFileSystemUtils.h @@ -65,6 +65,8 @@ class UBFileSystemUtils static bool isAZipFile(QString &filePath); + static bool copyFile(const QString &source, const QString &Destination, bool overwrite = false); + /** * Compress a source directory in a zip file. * @arg pDir the directory to add in zip diff --git a/src/gui/UBThumbnailWidget.cpp b/src/gui/UBThumbnailWidget.cpp index 93746dd3..e589300b 100644 --- a/src/gui/UBThumbnailWidget.cpp +++ b/src/gui/UBThumbnailWidget.cpp @@ -122,7 +122,7 @@ void UBThumbnailWidget::refreshScene() if (mLabelsItems.size() > 0) { QFontMetrics fm(mLabelsItems.at(0)->font()); - labelSpacing = UBSettings::thumbnailSpacing + fm.height(); // TODO UB 4.x where is 20 from ??? configure ?? compute based on mSpacing ?? JBA Is it the font height ? + labelSpacing = UBSettings::thumbnailSpacing + fm.height(); // TODO UB 4.x where is 20 from ??? configure ?? compute based on mSpacing ?? JBA Is it the font height? } nbColumns = qMax(nbColumns, 1); @@ -383,11 +383,8 @@ void UBThumbnailWidget::mouseReleaseEvent(QMouseEvent *event) deleteLasso(); QGraphicsView::mouseReleaseEvent(event); - if(elapsedTimeSincePress < STARTDRAGTIME) - { - if(!bSelectionInProgress) - emit mouseClick(itemAt(event->pos()), 0); - bSelectionInProgress = false; + if(elapsedTimeSincePress < STARTDRAGTIME) { + emit mouseClick(itemAt(event->pos()), 0); } } diff --git a/src/tools/UBGraphicsCurtainItem.h b/src/tools/UBGraphicsCurtainItem.h index 3b8fd57b..d05f946c 100644 --- a/src/tools/UBGraphicsCurtainItem.h +++ b/src/tools/UBGraphicsCurtainItem.h @@ -48,6 +48,7 @@ class UBGraphicsCurtainItem : public QObject, public QGraphicsRectItem, public U //TODO UB 4.x not nice ... void triggerRemovedSignal(); virtual UBGraphicsItemDelegate* Delegate() const {return mDelegate;} + virtual void clearSource(){}; signals: