From 70db49550f2f8ce014297539dcc84aabdcbe9139 Mon Sep 17 00:00:00 2001 From: Aleksei Kanash Date: Thu, 17 May 2012 13:13:48 +0300 Subject: [PATCH] Fix to Sankore 636. Now copyes of video and audio items stops in the sate tomes when stops original items. Generating of missing thumbnails no more crashes Sankore. Improved performance of navigating between pages. --- src/adaptors/UBSvgSubsetAdaptor.cpp | 4 +- src/adaptors/UBThumbnailAdaptor.cpp | 110 ++++++++++------------------ src/adaptors/UBThumbnailAdaptor.h | 1 + src/domain/UBGraphicsAudioItem.cpp | 2 + src/domain/UBGraphicsVideoItem.cpp | 2 + 5 files changed, 45 insertions(+), 74 deletions(-) diff --git a/src/adaptors/UBSvgSubsetAdaptor.cpp b/src/adaptors/UBSvgSubsetAdaptor.cpp index baf2fb87..286d148d 100644 --- a/src/adaptors/UBSvgSubsetAdaptor.cpp +++ b/src/adaptors/UBSvgSubsetAdaptor.cpp @@ -1961,7 +1961,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::audioItemToLinkedAudio(UBGraphicsAud mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "position", QString("%1").arg(pos)); } - QString audioFileHref = audioItem->mediaFileUrl().toString(); + QString audioFileHref = audioItem->mediaFileUrl().toLocalFile(); mXmlWriter.writeAttribute(nsXLink, "href", audioFileHref); mXmlWriter.writeEndElement(); } @@ -1986,7 +1986,7 @@ void UBSvgSubsetAdaptor::UBSvgSubsetWriter::videoItemToLinkedVideo(UBGraphicsVid mXmlWriter.writeAttribute(UBSettings::uniboardDocumentNamespaceUri, "position", QString("%1").arg(pos)); } - QString videoFileHref = videoItem->mediaFileUrl().toString(); + QString videoFileHref = videoItem->mediaFileUrl().toLocalFile(); mXmlWriter.writeAttribute(nsXLink, "href", videoFileHref); mXmlWriter.writeEndElement(); } diff --git a/src/adaptors/UBThumbnailAdaptor.cpp b/src/adaptors/UBThumbnailAdaptor.cpp index 69de0876..2432f89c 100644 --- a/src/adaptors/UBThumbnailAdaptor.cpp +++ b/src/adaptors/UBThumbnailAdaptor.cpp @@ -33,29 +33,23 @@ #include "core/memcheck.h" -QList UBThumbnailAdaptor::load(UBDocumentProxy* proxy) +void UBThumbnailAdaptor::generateMissingThumbnails(UBDocumentProxy* proxy) { - QList thumbnails; - - if (!proxy || proxy->persistencePath().isEmpty()) - return thumbnails; - - //compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails - int existingPageCount = proxy->pageCount(); - QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", existingPageCount); - QFile thumbFile(thumbFileName); - - if (!thumbFile.exists()) + for (int iPageNo = 0; iPageNo < existingPageCount; ++iPageNo) { - bool displayMessage = (existingPageCount > 5); + QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", iPageNo); - int thumbCount = 0; + QFile thumbFile(thumbFileName); - for(int i = 0 ; i < existingPageCount; i++) + if (!thumbFile.exists()) { - UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, i); + bool displayMessage = (existingPageCount > 5); + + int thumbCount = 0; + + UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, iPageNo); if (scene) { @@ -64,24 +58,25 @@ QList UBThumbnailAdaptor::load(UBDocumentProxy* proxy) if (displayMessage && thumbCount == 1) UBApplication::showMessage(tr("Generating preview thumbnails ...")); - persistScene(proxy->persistencePath(), scene, i); + persistScene(proxy->persistencePath(), scene, iPageNo); } - else{ - if(i==0){ - // we are working a document without zero page but on a system that enable it - // we have to create an empty zero scene - scene = new UBGraphicsScene(proxy); - UBSvgSubsetAdaptor::persistScene(proxy,scene,0); - persistScene(proxy->persistencePath(),scene,i); - thumbCount++; - } - } - } - if (displayMessage && thumbCount > 0) - UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount)); + if (displayMessage && thumbCount > 0) + UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount)); + } } +} + +QList UBThumbnailAdaptor::load(UBDocumentProxy* proxy) +{ + QList thumbnails; + + if (!proxy || proxy->persistencePath().isEmpty()) + return thumbnails; + + //compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails + generateMissingThumbnails(proxy); //end compatibility with older format @@ -113,56 +108,27 @@ QPixmap UBThumbnailAdaptor::load(UBDocumentProxy* proxy, int index) { int existingPageCount = proxy->pageCount(); - if (!proxy || proxy->persistencePath().size() == 0 || index < 0 || index >= existingPageCount) + if (!proxy || proxy->persistencePath().size() == 0 || index < 0 || index > existingPageCount) return QPixmap(); //compatibility with older formats (<= 4.0.b.2.0) : generate missing thumbnails - - QString thumbFileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", existingPageCount); - - QFile thumbFile(thumbFileName); - - if (!thumbFile.exists()) - { - bool displayMessage = (existingPageCount > 5); - - int thumbCount = 0; - - for(int i = 0 ; i < existingPageCount; i++) - { - UBGraphicsScene* scene = UBSvgSubsetAdaptor::loadScene(proxy, i); - - if (scene) - { - thumbCount++; - - if (displayMessage && thumbCount == 1) - UBApplication::showMessage(tr("Generating preview thumbnails ...")); - - persistScene(proxy->persistencePath(), scene, i); - } - } - - if (displayMessage && thumbCount > 0) - UBApplication::showMessage(tr("%1 thumbnails generated ...").arg(thumbCount)); - - } + generateMissingThumbnails(proxy); //end compatibility with older format - QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", index); + QString fileName = proxy->persistencePath() + UBFileSystemUtils::digitFileFormat("/page%1.thumbnail.jpg", index); - QFile file(fileName); - if (file.exists()) - { - QPixmap pix; - //Warning. Works only with modified Qt + QFile file(fileName); + if (file.exists()) + { + QPixmap pix; + //Warning. Works only with modified Qt #ifdef Q_WS_X11 - pix.load(fileName, 0, Qt::AutoColor); + pix.load(fileName, 0, Qt::AutoColor); #else - pix.load(fileName, 0, Qt::AutoColor, false); + pix.load(fileName, 0, Qt::AutoColor, false); #endif - return pix; - } - return QPixmap(); + return pix; + } + return QPixmap(); } void UBThumbnailAdaptor::persistScene(const QString& pDocPath, UBGraphicsScene* pScene, int pageIndex, bool overrideModified) diff --git a/src/adaptors/UBThumbnailAdaptor.h b/src/adaptors/UBThumbnailAdaptor.h index 68352102..75011f2d 100644 --- a/src/adaptors/UBThumbnailAdaptor.h +++ b/src/adaptors/UBThumbnailAdaptor.h @@ -29,6 +29,7 @@ private: UBThumbnailAdaptor() {} public: static void persistScene(const QString& pDocPath, UBGraphicsScene* pScene, int pageIndex, bool overrideModified = false); + static void generateMissingThumbnails(UBDocumentProxy* proxy); static QList load(UBDocumentProxy* proxy); static QPixmap load(UBDocumentProxy* proxy, int index); diff --git a/src/domain/UBGraphicsAudioItem.cpp b/src/domain/UBGraphicsAudioItem.cpp index f2d1ab45..b43271bf 100644 --- a/src/domain/UBGraphicsAudioItem.cpp +++ b/src/domain/UBGraphicsAudioItem.cpp @@ -96,6 +96,8 @@ UBItem* UBGraphicsAudioItem::deepCopy() const UBGraphicsAudioItem *copy = new UBGraphicsAudioItem(audioUrl, parentItem()); + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), copy, SLOT(activeSceneChanged())); + copy->setPos(this->pos()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true); diff --git a/src/domain/UBGraphicsVideoItem.cpp b/src/domain/UBGraphicsVideoItem.cpp index 7ef73f8d..40461a7f 100644 --- a/src/domain/UBGraphicsVideoItem.cpp +++ b/src/domain/UBGraphicsVideoItem.cpp @@ -69,6 +69,8 @@ UBItem* UBGraphicsVideoItem::deepCopy() const UBGraphicsVideoItem *copy = new UBGraphicsVideoItem(videoUrl, parentItem()); + connect(UBApplication::boardController, SIGNAL(activeSceneChanged()), copy, SLOT(activeSceneChanged())); + copy->setPos(this->pos()); copy->setTransform(this->transform()); copy->setFlag(QGraphicsItem::ItemIsMovable, true);