From 61b6decd76724aa133509192ea7cecf0781e05bf Mon Sep 17 00:00:00 2001 From: shibakaneki Date: Tue, 22 Nov 2011 14:34:17 +0100 Subject: [PATCH] Added the web item properties widget --- src/api/UBWidgetUniboardAPI.cpp | 18 +++++++ src/api/UBWidgetUniboardAPI.h | 10 ++++ src/board/UBBoardController.cpp | 4 ++ src/board/UBBoardController.h | 2 + src/board/UBBoardPaletteManager.h | 1 - src/board/UBLibraryController.h | 3 ++ src/core/UBApplication.cpp | 13 +++++ src/core/UBApplication.h | 1 + src/core/UBDownloadManager.cpp | 2 +- src/gui/UBLibItemProperties.cpp | 90 ++++++++++++++++++++++++------- src/gui/UBLibItemProperties.h | 5 +- src/gui/UBLibWebView.cpp | 23 ++++++-- src/gui/UBLibWebView.h | 5 ++ src/gui/UBLibraryWidget.cpp | 33 +++++++++--- src/gui/UBLibraryWidget.h | 3 ++ 15 files changed, 180 insertions(+), 33 deletions(-) diff --git a/src/api/UBWidgetUniboardAPI.cpp b/src/api/UBWidgetUniboardAPI.cpp index aceca0f2..e0bce653 100644 --- a/src/api/UBWidgetUniboardAPI.cpp +++ b/src/api/UBWidgetUniboardAPI.cpp @@ -15,6 +15,7 @@ #include "UBWidgetUniboardAPI.h" #include +#include #include "core/UB.h" #include "core/UBApplication.h" @@ -24,6 +25,7 @@ #include "board/UBBoardController.h" #include "board/UBDrawingController.h" +#include "board/UBBoardPaletteManager.h" #include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsWidgetItem.h" @@ -410,6 +412,22 @@ void UBWidgetUniboardAPI::response(bool correct) // TODO: Implement this method } +void UBWidgetUniboardAPI::sendFileMetadata(QString metaData) +{ + // Build the QMap of metadata and send it to application + QMap qmMetaDatas; + QDomDocument domDoc; + domDoc.setContent(metaData); + QDomElement rootElem = domDoc.documentElement(); + QDomNodeList children = rootElem.childNodes(); + for(int i=0; idisplayMetaData(qmMetaDatas); +} UBDocumentDatastoreAPI::UBDocumentDatastoreAPI(UBGraphicsW3CWidgetItem *graphicsWidget) : UBW3CWebStorage(graphicsWidget) diff --git a/src/api/UBWidgetUniboardAPI.h b/src/api/UBWidgetUniboardAPI.h index cb0df94a..aba494dc 100644 --- a/src/api/UBWidgetUniboardAPI.h +++ b/src/api/UBWidgetUniboardAPI.h @@ -224,6 +224,16 @@ class UBWidgetUniboardAPI : public QObject void returnStatus(const QString& method, const QString& status); void usedMethods(QStringList methods); void response(bool correct); + + /** + * Give the file metadata to Sankore. The format must be + * + * File Size + * 1024 + * + */ + void sendFileMetadata(QString metaData); + private: QString uuid(); diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 2d6f4ca5..d667508b 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -2028,3 +2028,7 @@ void UBBoardController::onDownloadModalFinished() } +void UBBoardController::displayMetaData(QMap metadatas) +{ + emit displayMetadata(metadatas); +} diff --git a/src/board/UBBoardController.h b/src/board/UBBoardController.h index 18283c8c..218130ab 100644 --- a/src/board/UBBoardController.h +++ b/src/board/UBBoardController.h @@ -148,6 +148,7 @@ class UBBoardController : public QObject void notifyCache(bool visible); void notifyPageChanged(); + void displayMetaData(QMap metadatas); public slots: void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0); @@ -218,6 +219,7 @@ class UBBoardController : public QObject void pageChanged(); void setDocOnPageNavigator(UBDocumentProxy* doc); void documentReorganized(int index); + void displayMetadata(QMap metadata); protected: void setupViews(); diff --git a/src/board/UBBoardPaletteManager.h b/src/board/UBBoardPaletteManager.h index 9cbbb119..4cba1d4a 100644 --- a/src/board/UBBoardPaletteManager.h +++ b/src/board/UBBoardPaletteManager.h @@ -66,7 +66,6 @@ class UBBoardPaletteManager : public QObject void startDownloads(); void stopDownloads(); - signals: void connectToDocController(); void signal_changeMode(eUBDockPaletteWidgetMode newMode); diff --git a/src/board/UBLibraryController.h b/src/board/UBLibraryController.h index c2055196..41c19568 100644 --- a/src/board/UBLibraryController.h +++ b/src/board/UBLibraryController.h @@ -63,6 +63,8 @@ public: void setMoveable(bool bState){mbMoveable = bState;} bool isDeletable() const {return mbDeletable;} void setDeletable(bool mState) {mbDeletable = mState;} + void setMetadata(QMap metadatas){mMetadata = metadatas;} + QMap metadatas(){return mMetadata;} private: eUBLibElementType mType; @@ -73,6 +75,7 @@ private: QString mExtension; bool mbMoveable; bool mbDeletable; + QMap mMetadata; }; class UBChainedLibElement diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 7b91387e..cf0b2d09 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -652,3 +652,16 @@ QString UBApplication::urlFromHtml(QString html) return url; } + +bool UBApplication::isFromWeb(QString url) +{ + bool res = true; + + if( url.startsWith("uniboardTool://") || + url.startsWith("file://") || + url.startsWith("/")){ + res = false; + } + + return res; +} diff --git a/src/core/UBApplication.h b/src/core/UBApplication.h index f58d2309..f67b5837 100644 --- a/src/core/UBApplication.h +++ b/src/core/UBApplication.h @@ -89,6 +89,7 @@ class UBApplication : public QtSingleApplication bool isVerbose() { return mIsVerbose;} void setVerbose(bool verbose){mIsVerbose = verbose;} static QString urlFromHtml(QString html); + static bool isFromWeb(QString url); signals: diff --git a/src/core/UBDownloadManager.cpp b/src/core/UBDownloadManager.cpp index b6eb0547..d4442f21 100644 --- a/src/core/UBDownloadManager.cpp +++ b/src/core/UBDownloadManager.cpp @@ -297,7 +297,7 @@ void UBDownloadManager::startFileDownload(sDownloadFileDesc desc) connect(http, SIGNAL(downloadFinished(int, bool, QUrl, QString, QByteArray, QPointF, QSize, bool)), this, SLOT(onDownloadFinished(int, bool, QUrl, QString, QByteArray, QPointF, QSize, bool))); // We send here the request and store its reply in order to be able to cancel it if needed - mReplies[desc.id] = http->get(QUrl(desc.url)); + mReplies[desc.id] = http->get(QUrl(desc.url), desc.pos, desc.size, desc.isBackground); } /** diff --git a/src/gui/UBLibItemProperties.cpp b/src/gui/UBLibItemProperties.cpp index a8cb3cb0..b37747ff 100644 --- a/src/gui/UBLibItemProperties.cpp +++ b/src/gui/UBLibItemProperties.cpp @@ -17,6 +17,7 @@ #include "UBLibItemProperties.h" #include "core/UBApplication.h" +#include "core/UBDownloadManager.h" #include "frameworks/UBFileSystemUtils.h" @@ -38,6 +39,7 @@ UBLibItemProperties::UBLibItemProperties(QWidget *parent, const char *name):QWid , mpThumbnail(NULL) , mpOrigPixmap(NULL) , mpElement(NULL) + , mpItem(NULL) { setObjectName(name); @@ -81,8 +83,11 @@ UBLibItemProperties::UBLibItemProperties(QWidget *parent, const char *name):QWid mpObjInfoLabel->setStyleSheet(QString("color: #888888; font-size : 18px; font-weight:bold;")); mpLayout->addWidget(mpObjInfoLabel, 0); - mpObjInfos = new QTextEdit(this); - mpObjInfos->setReadOnly(true); + mpObjInfos = new QTreeWidget(this); + mpObjInfos->setColumnCount(2); + mpObjInfos->header()->hide(); + mpObjInfos->setAlternatingRowColors(true); + mpObjInfos->setRootIsDecorated(false); mpObjInfos->setObjectName("DockPaletteWidgetBox"); mpObjInfos->setStyleSheet("background:white;"); mpLayout->addWidget(mpObjInfos, 1); @@ -173,8 +178,18 @@ void UBLibItemProperties::adaptSize() */ void UBLibItemProperties::onAddToPage() { - UBLibWidget* libWidget = dynamic_cast(parentWidget()->parentWidget()); - libWidget->libNavigator()->libraryWidget()->libraryController()->addItemToPage(mpElement); + if(UBApplication::isFromWeb(mpElement->path().toString())){ + sDownloadFileDesc desc; + desc.isBackground = false; + desc.modal = true; + desc.name = QFileInfo(mpElement->path().toString()).fileName(); + desc.url = mpElement->path().toString(); + UBDownloadManager::downloadManager()->addFileToDownload(desc); + + }else{ + UBLibWidget* libWidget = dynamic_cast(parentWidget()->parentWidget()); + libWidget->libNavigator()->libraryWidget()->libraryController()->addItemToPage(mpElement); + } } /** @@ -182,7 +197,14 @@ void UBLibItemProperties::onAddToPage() */ void UBLibItemProperties::onAddToLib() { - + if(UBApplication::isFromWeb(mpElement->path().toString())){ + sDownloadFileDesc desc; + desc.isBackground = false; + desc.modal = false; + desc.name = QFileInfo(mpElement->path().toString()).fileName(); + desc.url = mpElement->path().toString(); + UBDownloadManager::downloadManager()->addFileToDownload(desc); + } } /** @@ -190,8 +212,18 @@ void UBLibItemProperties::onAddToLib() */ void UBLibItemProperties::onSetAsBackground() { - UBLibWidget* libWidget = dynamic_cast(parentWidget()->parentWidget()); - libWidget->libNavigator()->libraryWidget()->libraryController()->setItemAsBackground(mpElement); + if(UBApplication::isFromWeb(mpElement->path().toString())){ + sDownloadFileDesc desc; + desc.isBackground = true; + desc.modal = true; + desc.name = QFileInfo(mpElement->path().toString()).fileName(); + desc.url = mpElement->path().toString(); + UBDownloadManager::downloadManager()->addFileToDownload(desc); + + }else{ + UBLibWidget* libWidget = dynamic_cast(parentWidget()->parentWidget()); + libWidget->libNavigator()->libraryWidget()->libraryController()->setItemAsBackground(mpElement); + } } /** @@ -210,20 +242,23 @@ void UBLibItemProperties::showElement(UBLibElement *elem) mpElement = elem; mpOrigPixmap = new QPixmap(QPixmap::fromImage(*elem->thumbnail())); mpThumbnail->setPixmap(QPixmap::fromImage(*elem->thumbnail()).scaledToWidth(THUMBNAIL_WIDTH)); - mpObjInfos->setText(elem->information()); + populateMetadata(); } - if(UBFileSystemUtils::mimeTypeFromFileName(elem->path().toLocalFile()).contains("image")) - { - // Show the Set as background button - mpAddToLibButton->hide(); - mpSetAsBackgroundButton->show(); - } - else - { - // TODO: if we are browsing ONLINE objects, we must show mpAddToLibButton ! - mpSetAsBackgroundButton->hide(); + if(UBApplication::isFromWeb(elem->path().toString())){ + mpAddToLibButton->show(); + if(elem->metadatas()["Type"].toLower().contains("image")){ + mpSetAsBackgroundButton->show(); + }else{ + mpSetAsBackgroundButton->hide(); + } + }else{ mpAddToLibButton->hide(); + if(UBFileSystemUtils::mimeTypeFromFileName(elem->path().toLocalFile()).contains("image")){ + mpSetAsBackgroundButton->show(); + }else{ + mpSetAsBackgroundButton->hide(); + } } } @@ -245,6 +280,25 @@ void UBLibItemProperties::showEvent(QShowEvent *event) adaptSize(); } +void UBLibItemProperties::populateMetadata() +{ + if(NULL != mpObjInfos){ + mpObjInfos->clear(); + QMap metas = mpElement->metadatas(); + QList lKeys = metas.keys(); + QList lValues = metas.values(); + + for(int i=0; i< metas.size(); i++){ + QStringList values; + values << lKeys.at(i); + values << lValues.at(i); + mpItem = new QTreeWidgetItem(values); + mpObjInfos->addTopLevelItem(mpItem); + } + mpObjInfos->resizeColumnToContents(0); + } +} + /** * \brief Constructor * @param parent as the parent widget diff --git a/src/gui/UBLibItemProperties.h b/src/gui/UBLibItemProperties.h index 3ec7976b..8f4be2f6 100644 --- a/src/gui/UBLibItemProperties.h +++ b/src/gui/UBLibItemProperties.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "board/UBLibraryController.h" @@ -61,6 +62,7 @@ private slots: private: void adaptSize(); + void populateMetadata(); QVBoxLayout* mpLayout; QHBoxLayout* mpButtonLayout; @@ -68,11 +70,12 @@ private: UBLibItemButton* mpAddToLibButton; UBLibItemButton* mpSetAsBackgroundButton; QLabel* mpObjInfoLabel; - QTextEdit* mpObjInfos; + QTreeWidget* mpObjInfos; QLabel* mpThumbnail; QPixmap* mpOrigPixmap; int maxThumbHeight; UBLibElement* mpElement; + QTreeWidgetItem* mpItem; }; diff --git a/src/gui/UBLibWebView.cpp b/src/gui/UBLibWebView.cpp index ebea433b..332c4e0a 100644 --- a/src/gui/UBLibWebView.cpp +++ b/src/gui/UBLibWebView.cpp @@ -1,6 +1,7 @@ #include #include "core/UBApplication.h" +#include "board/UBBoardController.h" #include "UBLibWebView.h" @@ -10,6 +11,7 @@ UBLibWebView::UBLibWebView(QWidget* parent, const char* name):QWidget(parent) , mpView(NULL) , mpWebSettings(NULL) , mpLayout(NULL) + , mpSankoreAPI(NULL) { setObjectName(name); @@ -21,6 +23,8 @@ UBLibWebView::UBLibWebView(QWidget* parent, const char* name):QWidget(parent) mpView = new QWebView(this); mpView->setObjectName("SearchEngineView"); + mpSankoreAPI = new UBWidgetUniboardAPI(UBApplication::boardController->activeScene()); + mpView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", mpSankoreAPI); mpWebSettings = QWebSettings::globalSettings(); mpWebSettings->setAttribute(QWebSettings::JavaEnabled, true); @@ -33,17 +37,21 @@ UBLibWebView::UBLibWebView(QWidget* parent, const char* name):QWidget(parent) mpWebSettings->setAttribute(QWebSettings::DnsPrefetchEnabled, true); mpLayout->addWidget(mpView); + + connect(mpView, SIGNAL(loadFinished(bool)), this, SLOT(onLoadFinished(bool))); } UBLibWebView::~UBLibWebView() { - if(NULL != mpView) - { + if(NULL != mpSankoreAPI){ + delete mpSankoreAPI; + mpSankoreAPI = NULL; + } + if(NULL != mpView){ delete mpView; mpView = NULL; } - if(NULL != mpLayout) - { + if(NULL != mpLayout){ delete mpLayout; mpLayout = NULL; } @@ -85,3 +93,10 @@ void UBLibWebView::setElement(UBLibElement *elem) mpView->load(QUrl::fromLocalFile(QString("%0/%1").arg(path).arg(qsWidgetName))); } } + +void UBLibWebView::onLoadFinished(bool ok) +{ + if(ok && NULL != mpSankoreAPI){ + mpView->page()->mainFrame()->addToJavaScriptWindowObject("sankore", mpSankoreAPI); + } +} diff --git a/src/gui/UBLibWebView.h b/src/gui/UBLibWebView.h index b661125f..3665f376 100644 --- a/src/gui/UBLibWebView.h +++ b/src/gui/UBLibWebView.h @@ -7,6 +7,7 @@ #include #include "board/UBLibraryController.h" +#include "api/UBWidgetUniboardAPI.h" class UBLibWebView : public QWidget { @@ -18,10 +19,14 @@ public: void setElement(UBLibElement* elem); +private slots: + void onLoadFinished(bool ok); + private: QWebView* mpView; QWebSettings* mpWebSettings; QVBoxLayout* mpLayout; + UBWidgetUniboardAPI* mpSankoreAPI; }; #endif // UBLIBWEBVIEW_H diff --git a/src/gui/UBLibraryWidget.cpp b/src/gui/UBLibraryWidget.cpp index 9ffc9db4..9c718b46 100644 --- a/src/gui/UBLibraryWidget.cpp +++ b/src/gui/UBLibraryWidget.cpp @@ -23,6 +23,7 @@ #include "board/UBBoardController.h" #include "board/UBLibraryController.h" +#include "board/UBBoardPaletteManager.h" #include "core/UBDownloadManager.h" @@ -41,6 +42,7 @@ UBLibraryWidget::UBLibraryWidget(QWidget *parent, const char *name):UBThumbnailW , mpCrntDir(NULL) , mpCrntElem(NULL) , mLibraryController(NULL) + , mpTmpElem(NULL) { setObjectName(name); setSpacing(5); @@ -52,21 +54,22 @@ UBLibraryWidget::UBLibraryWidget(QWidget *parent, const char *name):UBThumbnailW */ UBLibraryWidget::~UBLibraryWidget() { - if(NULL != mLibraryController) - { + if(NULL != mLibraryController){ delete mLibraryController; mLibraryController = NULL; } - if(NULL != mpCrntDir) - { + if(NULL != mpCrntDir){ delete mpCrntDir; mpCrntDir = NULL; - } - if(NULL != mpCrntElem) - { + } + if(NULL != mpCrntElem){ delete mpCrntElem; mpCrntElem = NULL; - } + } + if(NULL != mpTmpElem){ + delete mpTmpElem; + mpTmpElem = NULL; + } } /** @@ -86,6 +89,7 @@ void UBLibraryWidget::init() connect(this, SIGNAL(mouseClick(QGraphicsItem*,int)), this, SLOT(onItemClicked(QGraphicsItem*,int))); connect(this, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); connect(UBDownloadManager::downloadManager(), SIGNAL(addDownloadedFileToLibrary(bool,QUrl,QString,QByteArray)), this, SLOT(onAddDownloadedFileToLibrary(bool,QUrl,QString,QByteArray))); + connect(UBApplication::boardController, SIGNAL(displayMetadata(QMap)), this, SLOT(onDisplayMetadata(QMap))); } /** @@ -715,3 +719,16 @@ void UBLibraryWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl dir.rmdir("tmp"); // Due to Qt, the directoy will be removed only if it's empty :) } } + +void UBLibraryWidget::onDisplayMetadata(QMap metadatas) +{ + mpTmpElem = new UBLibElement(); + mpTmpElem->setMetadata(metadatas); + mpTmpElem->setPath(QUrl(metadatas["Url"])); + + // As the content comes from the web (and need a download), we will not display its thumbnail. + mpTmpElem->setThumbnail(QImage(":images/libpalette/notFound.png")); + + // Display the properties view + emit propertiesRequested(mpTmpElem); +} diff --git a/src/gui/UBLibraryWidget.h b/src/gui/UBLibraryWidget.h index c79319a1..8443abeb 100644 --- a/src/gui/UBLibraryWidget.h +++ b/src/gui/UBLibraryWidget.h @@ -73,6 +73,8 @@ protected: private slots: void onItemClicked(QGraphicsItem* pItem, int index); void onSelectionChanged(); + void onDisplayMetadata(QMap metadatas); + private: @@ -86,6 +88,7 @@ private: UBLibElement* mpCrntDir; UBLibElement* mpCrntElem; + UBLibElement* mpTmpElem; QList mCurrentElems; QList mOrigCurrentElems; QList mItems;