From 8d4be60b9ed5f42cfe4fda50606d7b6de009af36 Mon Sep 17 00:00:00 2001 From: Claudio Valerio Date: Thu, 25 Jul 2013 16:48:10 +0200 Subject: [PATCH] good behavior horror code --- src/core/UBPersistenceManager.cpp | 74 +++++++++++++++++++++++++++++ src/domain/UBGraphicsMediaItem.h | 2 + src/domain/UBGraphicsWidgetItem.cpp | 1 + src/domain/UBGraphicsWidgetItem.h | 1 + 4 files changed, 78 insertions(+) diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp index f36b657c..8d432d80 100644 --- a/src/core/UBPersistenceManager.cpp +++ b/src/core/UBPersistenceManager.cpp @@ -40,6 +40,11 @@ #include "adaptors/UBThumbnailAdaptor.h" #include "adaptors/UBMetadataDcSubsetAdaptor.h" +#include "domain/UBGraphicsMediaItem.h" +#include "domain/UBGraphicsWidgetItem.h" +#include "domain/UBGraphicsPixmapItem.h" +#include "domain/UBGraphicsSvgItem.h" + #include "board/UBBoardController.h" #include "board/UBBoardPaletteManager.h" @@ -469,6 +474,8 @@ void UBPersistenceManager::deleteDocumentScenes(UBDocumentProxy* proxy, const QL } + + void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int index) { checkIfDocumentRepositoryExists(); @@ -485,6 +492,73 @@ void UBPersistenceManager::duplicateDocumentScene(UBDocumentProxy* proxy, int in copyPage(proxy, index , index + 1); + + //TODO: write a proper way to handle object on disk + UBGraphicsScene *scene = loadDocumentScene(proxy, index + 1); + + foreach(QGraphicsItem* item, scene->items()) + { + UBGraphicsMediaItem *mediaItem = qgraphicsitem_cast (item); + + if (mediaItem){ + QString source = mediaItem->mediaFileUrl().toLocalFile(); + QString destination = source; + QUuid newUuid = QUuid::createUuid(); + QString fileName = QFileInfo(source).completeBaseName(); + destination = destination.replace(fileName,newUuid.toString()); + Q_ASSERT(QFile::copy(source,destination)); + mediaItem->mediaFileUrl(QUrl::fromLocalFile(destination)); + continue; + } + + UBGraphicsWidgetItem* widget = qgraphicsitem_cast(item); + if(widget){ + QUuid newUUid = QUuid::createUuid(); + QString newUUidString = newUUid.toString().remove("{").remove("}"); + QString actualUuidString = widget->uuid().toString().remove("{").remove("}"); + qDebug() << actualUuidString; + + QString widgetSourcePath = proxy->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/{" + actualUuidString + "}.wgt"; + QString screenshotSourcePath = proxy->persistencePath() + "/" + UBPersistenceManager::widgetDirectory + "/" + actualUuidString + ".png"; + + QString widgetDestinationPath = widgetSourcePath; + widgetDestinationPath = widgetDestinationPath.replace(actualUuidString,newUUidString); + QString screenshotDestinationPath = screenshotSourcePath; + screenshotDestinationPath = screenshotDestinationPath.replace(actualUuidString,newUUidString); + + + qDebug() << "widgetSourcePath " << widgetSourcePath; + qDebug() << "widgetDestinationPath " << widgetDestinationPath; + qDebug() << "screenshotSourcePath " << screenshotSourcePath; + qDebug() << "screenshotDestinationPath " << screenshotDestinationPath; + + Q_ASSERT(UBFileSystemUtils::copyDir(widgetSourcePath,widgetDestinationPath)); + Q_ASSERT(QFile::copy(screenshotSourcePath,screenshotDestinationPath)); + + widget->setUuid(newUUid); + + widget->widgetUrl(QUrl::fromLocalFile(widgetDestinationPath)); + + continue; + } + + UBGraphicsPixmapItem* pixmapItem = qgraphicsitem_cast(item); + if(pixmapItem){ + pixmapItem->setUuid(QUuid::createUuid()); + continue; + } + + UBGraphicsSvgItem* svgItem = qgraphicsitem_cast(item); + if(svgItem){ + svgItem->setUuid(QUuid::createUuid()); + continue; + } + + } + scene->setModified(true); + + persistDocumentScene(proxy,scene, index + 1); + proxy->incPageCount(); emit documentSceneCreated(proxy, index + 1); diff --git a/src/domain/UBGraphicsMediaItem.h b/src/domain/UBGraphicsMediaItem.h index f69516fe..2ab8b9c7 100644 --- a/src/domain/UBGraphicsMediaItem.h +++ b/src/domain/UBGraphicsMediaItem.h @@ -57,6 +57,8 @@ public: return mMediaFileUrl; } + virtual void mediaFileUrl(QUrl url){mMediaFileUrl=url;} + Phonon::MediaObject* mediaObject() const { return mMediaObject; diff --git a/src/domain/UBGraphicsWidgetItem.cpp b/src/domain/UBGraphicsWidgetItem.cpp index 5d3a9929..204def5f 100644 --- a/src/domain/UBGraphicsWidgetItem.cpp +++ b/src/domain/UBGraphicsWidgetItem.cpp @@ -149,6 +149,7 @@ QUrl UBGraphicsWidgetItem::widgetUrl() { return mWidgetUrl; } + QString UBGraphicsWidgetItem::mainHtmlFileName() { return mMainHtmlFileName; diff --git a/src/domain/UBGraphicsWidgetItem.h b/src/domain/UBGraphicsWidgetItem.h index 344f05cf..502d2aa2 100644 --- a/src/domain/UBGraphicsWidgetItem.h +++ b/src/domain/UBGraphicsWidgetItem.h @@ -69,6 +69,7 @@ class UBGraphicsWidgetItem : public QGraphicsWebView, public UBItem, public UBRe QUrl mainHtml(); void loadMainHtml(); QUrl widgetUrl(); + void widgetUrl(QUrl url) { mWidgetUrl = url; } QString mainHtmlFileName(); bool canBeContent();