From 021617ee3ef6eb954b74ba4db3dbadf8fd2402ea Mon Sep 17 00:00:00 2001 From: Ilia Ryabokon Date: Fri, 17 Aug 2012 12:54:30 +0300 Subject: [PATCH] Sankore 942 Trap flash content --- src/board/UBBoardController.cpp | 26 ++++++++++++++++++-------- src/board/UBBoardController.h | 7 +++++-- src/board/UBFeaturesController.cpp | 19 ++++++++++++++++++- src/board/UBFeaturesController.h | 2 ++ src/gui/UBFeaturesWidget.cpp | 5 ++++- src/gui/UBFeaturesWidget.h | 5 ++++- 6 files changed, 51 insertions(+), 13 deletions(-) diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 525b7e5d..24581b06 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -53,6 +53,8 @@ #include "domain/UBPageSizeUndoCommand.h" #include "domain/UBGraphicsGroupContainerItem.h" #include "domain/UBItem.h" +#include "board/UBFeaturesController.h" +#include "gui/UBFeaturesWidget.h" #include "tools/UBToolsManager.h" @@ -897,7 +899,7 @@ void UBBoardController::groupButtonClicked() } } -void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const QSize& pSize, bool isBackground) +void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const QSize& pSize, bool isBackground, bool internalData) { qDebug() << "something has been dropped on the board! Url is: " << url.toString(); QString sUrl = url.toString(); @@ -922,7 +924,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const if (shouldLoadFileData) file.open(QIODevice::ReadOnly); - downloadFinished(true, url, contentType, file.readAll(), pPos, pSize, isBackground); + downloadFinished(true, url, contentType, file.readAll(), pPos, pSize, isBackground, internalData); if (shouldLoadFileData) file.close(); @@ -945,7 +947,9 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const } -UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground) +UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, + QByteArray pData, QPointF pPos, QSize pSize, + bool isBackground, bool internalData) { QString mimeType = pContentTypeHeader; @@ -1155,7 +1159,10 @@ UBItem *UBBoardController::downloadFinished(bool pSuccess, QUrl sourceUrl, QStri else size = mActiveScene->nominalSize() * .8; + Q_UNUSED(internalData) + QString widgetUrl = UBGraphicsW3CWidgetItem::createNPAPIWrapper(sUrl, mimeType, size); + emit npapiWidgetCreated(widgetUrl); if (widgetUrl.length() > 0) { @@ -1339,7 +1346,6 @@ void UBBoardController::setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, mActiveSceneIndex = index; setDocument(pDocumentProxy, forceReload); - updateSystemScaleFactor(); mControlView->setScene(mActiveScene); @@ -1668,13 +1674,11 @@ void UBBoardController::hide() UBApplication::mainWindow->actionLibrary->setChecked(false); } - void UBBoardController::show() { UBApplication::mainWindow->actionLibrary->setChecked(false); } - void UBBoardController::persistCurrentScene() { if(UBPersistenceManager::persistenceManager() @@ -1689,7 +1693,6 @@ void UBBoardController::persistCurrentScene() } } - void UBBoardController::updateSystemScaleFactor() { qreal newScaleFactor = 1.0; @@ -2100,9 +2103,16 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint int index = 0; + const UBFeaturesMimeData *internalMimeData = qobject_cast(pMimeData); + bool internalData = false; + if (internalMimeData) { + internalData = true; + } + foreach(const QUrl url, urls){ QPointF pos(pPos + QPointF(index * 15, index * 15)); - downloadURL(url, pos); + + downloadURL(url, pos, QSize(), false, internalData); index++; } diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index fbb6c3a4..8f100c73 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -189,8 +189,10 @@ class UBBoardController : public UBDocumentContainer void firstScene(); void lastScene(); void groupButtonClicked(); - void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false); - UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false); + void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0), const QSize& pSize = QSize(), bool isBackground = false, bool internalData = false); + UBItem *downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, + QByteArray pData, QPointF pPos, QSize pSize, + bool isBackground = false, bool internalData = false); void changeBackground(bool isDark, bool isCrossed); void setToolCursor(int tool); void showMessage(const QString& message, bool showSpinningWheel = false); @@ -236,6 +238,7 @@ class UBBoardController : public UBDocumentContainer void documentReorganized(int index); void displayMetadata(QMap metadata); void pageSelectionChanged(int index); + void npapiWidgetCreated(const QString &Url); protected: void setupViews(); diff --git a/src/board/UBFeaturesController.cpp b/src/board/UBFeaturesController.cpp index e2d7fa80..d5bbbcee 100644 --- a/src/board/UBFeaturesController.cpp +++ b/src/board/UBFeaturesController.cpp @@ -154,7 +154,9 @@ void UBFeaturesComputingThread::run() emit maxFilesCountEvaluated(fsCnt); emit scanStarted(); + curTime = QTime::currentTime(); scanAll(searchData, favoriteSet); + qDebug() << "Time on finishing" << curTime.msecsTo(QTime::currentTime()); emit scanFinished(); mMutex.lock(); @@ -303,6 +305,7 @@ UBFeaturesController::UBFeaturesController(QWidget *pParentWidget) : connect(&mCThread, SIGNAL(maxFilesCountEvaluated(int)), this, SIGNAL(maxFilesCountEvaluated(int))); connect(&mCThread, SIGNAL(scanCategory(QString)), this, SIGNAL(scanCategory(QString))); connect(&mCThread, SIGNAL(scanPath(QString)), this, SIGNAL(scanPath(QString))); + connect(UBApplication::boardController, SIGNAL(npapiWidgetCreated(QString)), this, SLOT(createNpApiFeature(QString))); QTimer::singleShot(0, this, SLOT(startThread())); } @@ -326,11 +329,20 @@ void UBFeaturesController::startThread() << QPair(mLibShapesDirectoryPath, shapesPath) << QPair(mLibInteractiveDirectoryPath, interactPath) << QPair(trashDirectoryPath, trashPath) - << QPair(mLibSearchDirectoryPath, rootPath + "/" + "Web search" ); + << QPair(mLibSearchDirectoryPath, rootPath + "/" + "Web search"); mCThread.compute(computingData, favoriteSet); } +void UBFeaturesController::createNpApiFeature(const QString &str) +{ + Q_ASSERT(QFileInfo(str).exists() && QFileInfo(str).isDir()); + + QString widgetName = QFileInfo(str).fileName(); + + featuresModel->addItem(UBFeature(QString(appPath+"/Web"), QImage(UBGraphicsWidgetItem::iconFilePath(QUrl::fromLocalFile(str))), widgetName, QUrl::fromLocalFile(str), FEATURE_INTERACTIVE)); +} + void UBFeaturesController::scanFS() { featuresList->clear(); @@ -502,6 +514,8 @@ UBFeatureElementType UBFeaturesController::fileTypeFromUrl(const QString &path) if ( mimeString.contains("application")) { if (mimeString.contains("application/search")) { fileType = FEATURE_SEARCH; + } else if (mimeString.contains("application/x-shockwave-flash")) { + fileType = FEATURE_FLASH; } else { fileType = FEATURE_INTERACTIVE; } @@ -530,6 +544,8 @@ QImage UBFeaturesController::getIcon(const QString &path, UBFeatureElementType p return QImage(UBGraphicsWidgetItem::iconFilePath(QUrl::fromLocalFile(path))); } else if (pFType == FEATURE_INTERNAL) { return QImage(UBToolsManager::manager()->iconFromToolId(path)); + } else if (pFType == FEATURE_FLASH) { + return QImage(":images/libpalette/FlashIcon.svg"); } else if (pFType == FEATURE_AUDIO) { return QImage(":images/libpalette/soundIcon.svg"); } else if (pFType == FEATURE_VIDEO) { @@ -802,6 +818,7 @@ void UBFeaturesController::searchStarted(const QString &pattern, QListView *pOnV curListModel = featuresProxyModel; } else if ( pattern.size() > 1 ) { + // featuresSearchModel->setFilterPrefix(currentElement.getFullVirtualPath()); featuresSearchModel->setFilterWildcard( "*" + pattern + "*" ); pOnView->setModel(featuresSearchModel ); featuresSearchModel->invalidate(); diff --git a/src/board/UBFeaturesController.h b/src/board/UBFeaturesController.h index 9a551363..6d57e5d4 100644 --- a/src/board/UBFeaturesController.h +++ b/src/board/UBFeaturesController.h @@ -78,6 +78,7 @@ enum UBFeatureElementType FEATURE_AUDIO, FEATURE_VIDEO, FEATURE_IMAGE, + FEATURE_FLASH, FEATURE_TRASH, FEATURE_FAVORITE, FEATURE_SEARCH, @@ -192,6 +193,7 @@ signals: private slots: void addNewFolder(QString name); void startThread(); + void createNpApiFeature(const QString &str); private: diff --git a/src/gui/UBFeaturesWidget.cpp b/src/gui/UBFeaturesWidget.cpp index d221950b..ccc52c11 100644 --- a/src/gui/UBFeaturesWidget.cpp +++ b/src/gui/UBFeaturesWidget.cpp @@ -1337,6 +1337,7 @@ Qt::ItemFlags UBFeaturesModel::flags( const QModelIndex &index ) const || item.getType() == FEATURE_AUDIO || item.getType() == FEATURE_VIDEO || item.getType() == FEATURE_IMAGE + || item.getType() == FEATURE_FLASH || item.getType() == FEATURE_INTERNAL || item.getType() == FEATURE_FOLDER) @@ -1387,7 +1388,9 @@ bool UBFeaturesSearchProxyModel::filterAcceptsRow( int sourceRow, const QModelIn || feature.getType() == FEATURE_VIDEO || feature.getType() == FEATURE_IMAGE; - return isFile && filterRegExp().exactMatch( feature.getName() ); + return isFile + && feature.getFullVirtualPath().contains(mFilterPrefix) + && filterRegExp().exactMatch( feature.getName() ); } bool UBFeaturesPathProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex & sourceParent )const diff --git a/src/gui/UBFeaturesWidget.h b/src/gui/UBFeaturesWidget.h index 5a1b987e..ba782a3a 100644 --- a/src/gui/UBFeaturesWidget.h +++ b/src/gui/UBFeaturesWidget.h @@ -394,10 +394,13 @@ class UBFeaturesSearchProxyModel : public QSortFilterProxyModel { Q_OBJECT public: - UBFeaturesSearchProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) {;} + UBFeaturesSearchProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent), mFilterPrefix() {;} virtual ~UBFeaturesSearchProxyModel() {} + void setFilterPrefix(const QString &newPrefix) {mFilterPrefix = newPrefix;} protected: virtual bool filterAcceptsRow ( int sourceRow, const QModelIndex & sourceParent ) const; +private: + QString mFilterPrefix; }; class UBFeaturesPathProxyModel : public QSortFilterProxyModel