diff --git a/resources/images/download_close.png b/resources/images/download_close.png new file mode 100644 index 00000000..5d09e3cb Binary files /dev/null and b/resources/images/download_close.png differ diff --git a/resources/images/download_open.png b/resources/images/download_open.png new file mode 100644 index 00000000..5af30ae9 Binary files /dev/null and b/resources/images/download_open.png differ diff --git a/resources/sankore.qrc b/resources/sankore.qrc index 02e3c32e..d71aadae 100644 --- a/resources/sankore.qrc +++ b/resources/sankore.qrc @@ -335,5 +335,7 @@ style.qss images/teacher_open_disabled.png images/libpalette/WebSearchCategory.svg + images/download_close.png + images/download_open.png diff --git a/resources/style.qss b/resources/style.qss index d905628e..cfa6b41c 100644 --- a/resources/style.qss +++ b/resources/style.qss @@ -3,7 +3,8 @@ QWidget#documentNavigator, QWidget#UBLibPathViewer, QWidget#UBTeacherStudentAction, QWidget#UBLibNavigatorWidget, -QWidget#UBLibItemProperties +QWidget#UBLibItemProperties, +QWidget#UBDownloadWidget { background: #EEEEEE; border-radius: 10px; diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp index 429f129b..9d8d1177 100644 --- a/src/board/UBBoardController.cpp +++ b/src/board/UBBoardController.cpp @@ -726,6 +726,7 @@ void UBBoardController::lastScene() void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const QSize& pSize, bool isBackground) { + qDebug() << "something has been dropped on the board! Url is: " << url.toString(); QString sUrl = url.toString(); if(sUrl.startsWith("uniboardTool://")) @@ -766,14 +767,7 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const desc.size = pSize; desc.isBackground = isBackground; - // INFO: DO NOT UNCOMMENT THE NEXT LINE! DEVELOPMENT IN PROGRESS UBDownloadManager::downloadManager()->addFileToDownload(desc); - -// UBHttpGet *http = new UBHttpGet(mActiveScene); -// showMessage(tr("Downloading content from %1").arg(url.toString()), true); -// connect(http, SIGNAL(downloadFinished(bool, QUrl, QString, QByteArray, QPointF, QSize, bool)), -// this, SLOT(downloadFinished(bool, QUrl, QString, QByteArray, QPointF, QSize, bool))); -// http->get(url, pPos, pSize, isBackground); } } diff --git a/src/board/UBBoardPaletteManager.cpp b/src/board/UBBoardPaletteManager.cpp index 314cfd39..4752491b 100644 --- a/src/board/UBBoardPaletteManager.cpp +++ b/src/board/UBBoardPaletteManager.cpp @@ -82,6 +82,7 @@ UBBoardPaletteManager::UBBoardPaletteManager(QWidget* container, UBBoardControll , mpCachePropWidget(NULL) , mpTeacherBarWidget(NULL) , mpDesktopLibWidget(NULL) + , mpDownloadWidget(NULL) { setupPalettes(); connectPalettes(); @@ -90,6 +91,11 @@ UBBoardPaletteManager::UBBoardPaletteManager(QWidget* container, UBBoardControll UBBoardPaletteManager::~UBBoardPaletteManager() { + if(NULL != mpDownloadWidget) + { + delete mpDownloadWidget; + mpDownloadWidget = NULL; + } if(NULL != mpTeacherBarWidget) { delete mpTeacherBarWidget; @@ -182,7 +188,9 @@ void UBBoardPaletteManager::setupDockPaletteWidgets() mpTeacherBarWidget->registerMode(eUBDockPaletteWidget_BOARD); // connect(this, SIGNAL(signal_changeMode(eUBDockPaletteWidgetMode)), mpTeacherBarWidget, SLOT(slot_changeMode(eUBDockPaletteWidgetMode))); - //------------------------------------------------// + mpDownloadWidget = new UBDockDownloadWidget(); + mpDownloadWidget->registerMode(eUBDockPaletteWidget_BOARD); + // Add the dock palettes mLeftPalette = new UBLeftPalette(mContainer); @@ -192,29 +200,24 @@ void UBBoardPaletteManager::setupDockPaletteWidgets() mLeftPalette->connectSignals(); - //------------------------------------------------// - mRightPalette = new UBRightPalette(mContainer); - // RIGHT palette widgets mRightPalette->registerWidget(mpLibWidget); mRightPalette->addTab(mpLibWidget); - - // ??? - mRightPalette->registerWidget(mpCachePropWidget); -// mRightPalette->addTab(mpCachePropWidget); - - // ??? + // The cache widget will be visible only if a cache is put on the page + mRightPalette->registerWidget(mpCachePropWidget); + // The teacher bar widget will always be there mRightPalette->registerWidget(mpTeacherBarWidget); mRightPalette->addTab(mpTeacherBarWidget); - + // The download widget will be part of the right palette but + // will become visible only when the first download starts + mRightPalette->registerWidget(mpDownloadWidget); mRightPalette->connectSignals(); - - //------------------------------------------------// - changeMode(eUBDockPaletteWidget_BOARD, true); - //------------------------------------------------// + // Hide the tabs that must be hidden + mRightPalette->removeTab(mpDownloadWidget->name()); + mRightPalette->removeTab(mpCachePropWidget->name()); // mLeftPalette->showTabWidget(0); // mRightPalette->showTabWidget(0); @@ -1003,3 +1006,19 @@ void UBBoardPaletteManager::refreshPalettes() mRightPalette->update(); mLeftPalette->update(); } + +void UBBoardPaletteManager::startDownloads() +{ + if(!mpDownloadWidget->isVisible()) + { + mRightPalette->addTab(mpDownloadWidget); + } +} + +void UBBoardPaletteManager::stopDownloads() +{ + if(mpDownloadWidget->isVisible()) + { + mRightPalette->removeTab(mpDownloadWidget->name()); + } +} diff --git a/src/board/UBBoardPaletteManager.h b/src/board/UBBoardPaletteManager.h index a151bab0..bfab2f8b 100644 --- a/src/board/UBBoardPaletteManager.h +++ b/src/board/UBBoardPaletteManager.h @@ -26,6 +26,7 @@ #include "gui/UBLibWidget.h" #include "gui/UBCachePropertiesWidget.h" #include "gui/UBTeacherBarWidget.h" +#include "gui/UBDockDownloadWidget.h" #include "core/UBApplicationController.h" @@ -62,6 +63,8 @@ class UBBoardPaletteManager : public QObject void processPalettersWidget(UBDockPalette *paletter, eUBDockPaletteWidgetMode mode); void changeMode(eUBDockPaletteWidgetMode newMode, bool isInit = false); + void startDownloads(); + void stopDownloads(); signals: @@ -134,7 +137,8 @@ class UBBoardPaletteManager : public QObject UBCachePropertiesWidget* mpCachePropWidget; /** The teacher bar widget */ UBTeacherBarWidget* mpTeacherBarWidget; - + /** The download widget */ + UBDockDownloadWidget* mpDownloadWidget; // HACK: here we duplicate the lib widget for the desktop mode // we MUST refactor the architecture in order to use only one // lib widget! diff --git a/src/board/UBLibraryController.cpp b/src/board/UBLibraryController.cpp index d6663ded..3288c5bd 100644 --- a/src/board/UBLibraryController.cpp +++ b/src/board/UBLibraryController.cpp @@ -110,6 +110,7 @@ void UBLibraryController::createDirectory(QUrl& pDirPath) void UBLibraryController::routeItem(QString& pItem, QString pMiddleDirectory) { + qDebug() << "routeItem: " << pItem; QFileInfo itemToRoute(pItem); QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(itemToRoute.fileName()); QString destination(""); diff --git a/src/core/UBDownloadManager.cpp b/src/core/UBDownloadManager.cpp index dc0595d1..36700b77 100644 --- a/src/core/UBDownloadManager.cpp +++ b/src/core/UBDownloadManager.cpp @@ -251,6 +251,13 @@ void UBDownloadManager::updateFileCurrentSize(int id, qint64 received, qint64 to onUpdateDownloadLists(); emit downloadFinished(id); + + // Verify if all downloads are finished + if(mCrntDL.empty() && mPendingDL.empty()) + { + emit allDownloadsFinished(); + } + break; } diff --git a/src/core/UBDownloadManager.h b/src/core/UBDownloadManager.h index 8cda63ce..dcbbcc2d 100644 --- a/src/core/UBDownloadManager.h +++ b/src/core/UBDownloadManager.h @@ -79,6 +79,7 @@ signals: void downloadModalFinished(); void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); void cancelAllDownloads(); + void allDownloadsFinished(); private slots: void onUpdateDownloadLists(); diff --git a/src/gui/UBDockDownloadWidget.cpp b/src/gui/UBDockDownloadWidget.cpp new file mode 100644 index 00000000..5f373b9d --- /dev/null +++ b/src/gui/UBDockDownloadWidget.cpp @@ -0,0 +1,49 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include "UBDockDownloadWidget.h" +#include "core/UBApplication.h" + +UBDockDownloadWidget::UBDockDownloadWidget(QWidget *parent, const char *name):UBDockPaletteWidget(parent, name) + , mpLayout(NULL) + , mpDLWidget(NULL) +{ + mName = "DownloadWidget"; + + setAttribute(Qt::WA_StyledBackground, true); + setStyleSheet(UBApplication::globalStyleSheet()); + + mIconToLeft = QPixmap(":images/download_open.png"); + mIconToRight = QPixmap(":images/download_close.png"); + + mpLayout = new QVBoxLayout(this); + setLayout(mpLayout); + + mpDLWidget = new UBDownloadWidget(this); + mpLayout->addWidget(mpDLWidget); +} + +UBDockDownloadWidget::~UBDockDownloadWidget() +{ + if(NULL != mpDLWidget) + { + delete mpDLWidget; + mpDLWidget = NULL; + } + if(NULL != mpLayout) + { + delete mpLayout; + mpLayout = NULL; + } +} diff --git a/src/gui/UBDockDownloadWidget.h b/src/gui/UBDockDownloadWidget.h new file mode 100644 index 00000000..80c50d17 --- /dev/null +++ b/src/gui/UBDockDownloadWidget.h @@ -0,0 +1,36 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef UBDOCKDOWNLOADWIDGET_H +#define UBDOCKDOWNLOADWIDGET_H + +#include +#include + +#include "UBDockPaletteWidget.h" +#include "UBDownloadWidget.h" + +class UBDockDownloadWidget : public UBDockPaletteWidget +{ + Q_OBJECT +public: + UBDockDownloadWidget(QWidget* parent=0, const char* name="UBDockDownloadWidget"); + ~UBDockDownloadWidget(); + +private: + QVBoxLayout* mpLayout; + UBDownloadWidget* mpDLWidget; +}; + +#endif // UBDOCKDOWNLOADWIDGET_H diff --git a/src/gui/UBDownloadWidget.cpp b/src/gui/UBDownloadWidget.cpp index 1fd126da..1a954a53 100644 --- a/src/gui/UBDownloadWidget.cpp +++ b/src/gui/UBDownloadWidget.cpp @@ -49,6 +49,7 @@ UBDownloadWidget::UBDownloadWidget(QWidget *parent, const char *name):QWidget(pa mpBttnLayout = new QHBoxLayout(); mpBttnLayout->addStretch(1); mpCancelBttn = new QPushButton(tr("Cancel"), this); + mpCancelBttn->setObjectName("DockPaletteWidgetButton"); mpBttnLayout->addWidget(mpCancelBttn, 0); mpLayout->addLayout(mpBttnLayout); @@ -175,6 +176,7 @@ void UBDownloadWidget::onDownloadUpdated(int id, qint64 crnt, qint64 total) */ void UBDownloadWidget::onDownloadFinished(int id) { + Q_UNUSED(id); // Refresh the file's list onFileAddedToDownload(); } diff --git a/src/gui/UBLibPathViewer.cpp b/src/gui/UBLibPathViewer.cpp index 79a532b2..d66cb4be 100644 --- a/src/gui/UBLibPathViewer.cpp +++ b/src/gui/UBLibPathViewer.cpp @@ -21,6 +21,8 @@ #include "board/UBBoardController.h" #include "core/memcheck.h" +#include "core/UBDownloadManager.h" +#include "board/UBBoardPaletteManager.h" /** * \brief Constructor @@ -367,7 +369,7 @@ void UBFolderPath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) UBPathScene::UBPathScene(QWidget* parent):QGraphicsScene(parent) { - + connect(UBDownloadManager::downloadManager(), SIGNAL(allDownloadsFinished()), this, SLOT(onAllDownloadsFinished())); } UBPathScene::~UBPathScene() @@ -457,7 +459,7 @@ void UBPathScene::dropEvent(QGraphicsSceneDragDropEvent *event) { const QMimeData* pMimeData = event->mimeData(); - if(0 == QString::compare(event->source()->metaObject()->className(), "UBLibraryWidget")) + if(NULL != event->source() && 0 == QString::compare(event->source()->metaObject()->className(), "UBLibraryWidget")) { UBLibElement* pTargetElement = elementFromPos(event->scenePos()); if(NULL != pTargetElement) @@ -480,6 +482,33 @@ void UBPathScene::dropEvent(QGraphicsSceneDragDropEvent *event) event->accept(); } + else if(NULL != event->mimeData() && event->mimeData()->hasUrls()) + { + QList urls = event->mimeData()->urls(); + foreach(QUrl eachUrl, urls) + { + QString sUrl = eachUrl.toString(); + if(!sUrl.startsWith("uniboardTool://") && !sUrl.startsWith("file://") && !sUrl.startsWith("/")) + { + // The dropped URL comes from the web + qDebug() << "Dropped url: " << sUrl; + + // Show the download palette if it is hidden + UBApplication::boardController->paletteManager()->startDownloads(); + + // Add the dropped url to the download list + sDownloadFileDesc desc; + desc.currentSize = 0; + desc.id = 0; + desc.isBackground = false; + desc.modal = false; + desc.name = QFileInfo(sUrl).fileName(); + desc.totalSize = 0; + desc.url = sUrl; + UBDownloadManager::downloadManager()->addFileToDownload(desc); + } + } + } else { event->ignore(); @@ -507,3 +536,9 @@ UBLibElement* UBPathScene::elementFromPos(QPointF p) return pElem; } + +void UBPathScene::onAllDownloadsFinished() +{ + // Hide the download tab + UBApplication::boardController->paletteManager()->stopDownloads(); +} diff --git a/src/gui/UBLibPathViewer.h b/src/gui/UBLibPathViewer.h index ab7083d5..ee002e98 100644 --- a/src/gui/UBLibPathViewer.h +++ b/src/gui/UBLibPathViewer.h @@ -59,6 +59,9 @@ protected: void dragMoveEvent(QGraphicsSceneDragDropEvent *event); void dropEvent(QGraphicsSceneDragDropEvent *event); +private slots: + void onAllDownloadsFinished(); + private: UBLibElement* elementFromPos(QPointF p); /** The drag start position */ diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 1ea89a32..1e65ca8f 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -45,7 +45,8 @@ HEADERS += src/gui/UBThumbnailView.h \ src/gui/UBCachePropertiesWidget.h \ src/gui/UBTeacherBarWidget.h \ src/gui/UBLibWebView.h \ - src/gui/UBDownloadWidget.h + src/gui/UBDownloadWidget.h \ + src/gui/UBDockDownloadWidget.h SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBFloatingPalette.cpp \ @@ -93,7 +94,8 @@ SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBCachePropertiesWidget.cpp \ src/gui/UBTeacherBarWidget.cpp \ src/gui/UBLibWebView.cpp \ - src/gui/UBDownloadWidget.cpp + src/gui/UBDownloadWidget.cpp \ + src/gui/UBDockDownloadWidget.cpp win32 {