Commit 61b6decd authored by shibakaneki's avatar shibakaneki

Added the web item properties widget

parent 4860f7d1
......@@ -15,6 +15,7 @@
#include "UBWidgetUniboardAPI.h"
#include <QWebView>
#include <QDomDocument>
#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<QString, QString> qmMetaDatas;
QDomDocument domDoc;
domDoc.setContent(metaData);
QDomElement rootElem = domDoc.documentElement();
QDomNodeList children = rootElem.childNodes();
for(int i=0; i<children.size(); i++){
QDomNode dataNode = children.at(i);
QDomElement keyElem = dataNode.firstChildElement("key");
QDomElement valueElem = dataNode.firstChildElement("value");
qmMetaDatas[keyElem.text()] = valueElem.text();
}
UBApplication::boardController->displayMetaData(qmMetaDatas);
}
UBDocumentDatastoreAPI::UBDocumentDatastoreAPI(UBGraphicsW3CWidgetItem *graphicsWidget)
: UBW3CWebStorage(graphicsWidget)
......
......@@ -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
* <metbadata>
* <key>File Size</<key>
* <value>1024</value>
* </metadata>
*/
void sendFileMetadata(QString metaData);
private:
QString uuid();
......
......@@ -2028,3 +2028,7 @@ void UBBoardController::onDownloadModalFinished()
}
void UBBoardController::displayMetaData(QMap<QString, QString> metadatas)
{
emit displayMetadata(metadatas);
}
......@@ -148,6 +148,7 @@ class UBBoardController : public QObject
void notifyCache(bool visible);
void notifyPageChanged();
void displayMetaData(QMap<QString, QString> 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<QString, QString> metadata);
protected:
void setupViews();
......
......@@ -66,7 +66,6 @@ class UBBoardPaletteManager : public QObject
void startDownloads();
void stopDownloads();
signals:
void connectToDocController();
void signal_changeMode(eUBDockPaletteWidgetMode newMode);
......
......@@ -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<QString, QString> metadatas){mMetadata = metadatas;}
QMap<QString, QString> metadatas(){return mMetadata;}
private:
eUBLibElementType mType;
......@@ -73,6 +75,7 @@ private:
QString mExtension;
bool mbMoveable;
bool mbDeletable;
QMap<QString, QString> mMetadata;
};
class UBChainedLibElement
......
......@@ -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;
}
......@@ -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:
......
......@@ -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);
}
/**
......
......@@ -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<UBLibWidget*>(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<UBLibWidget*>(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<UBLibWidget*>(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<UBLibWidget*>(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<QString, QString> metas = mpElement->metadatas();
QList<QString> lKeys = metas.keys();
QList<QString> 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
......
......@@ -25,6 +25,7 @@
#include <QToolButton>
#include <QAction>
#include <QShowEvent>
#include <QTreeWidget>
#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;
};
......
#include <QDomDocument>
#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);
}
}
......@@ -7,6 +7,7 @@
#include <QVBoxLayout>
#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
......@@ -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<QString,QString>)), this, SLOT(onDisplayMetadata(QMap<QString,QString>)));
}
/**
......@@ -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<QString, QString> 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);
}
......@@ -73,6 +73,8 @@ protected:
private slots:
void onItemClicked(QGraphicsItem* pItem, int index);
void onSelectionChanged();
void onDisplayMetadata(QMap<QString,QString> metadatas);
private:
......@@ -86,6 +88,7 @@ private:
UBLibElement* mpCrntDir;
UBLibElement* mpCrntElem;
UBLibElement* mpTmpElem;
QList<UBLibElement*> mCurrentElems;
QList<UBLibElement*> mOrigCurrentElems;
QList<QGraphicsItem*> mItems;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment