Commit af5b99cf authored by shibakaneki's avatar shibakaneki

New version od the download manager coded

parent 2f9367c3
......@@ -19,7 +19,7 @@ QWidget#UBLibWebView
QWebView#SearchEngineView
{
background:#EEEEEE;
background:white;
}
QColorDialog
......
......@@ -27,6 +27,7 @@
#include "core/UBApplicationController.h"
#include "core/UBDocumentManager.h"
#include "core/UBMimeData.h"
#include "core/UBDownloadManager.h"
#include "network/UBHttpGet.h"
......@@ -128,6 +129,9 @@ void UBBoardController::init()
connect(UBApplication::app(), SIGNAL(lastWindowClosed())
, this, SLOT(lastWindowClosed()));
connect(UBDownloadManager::downloadManager(), SIGNAL(downloadModalFinished()), this, SLOT(onDownloadModalFinished()));
connect(UBDownloadManager::downloadManager(), SIGNAL(addDownloadedFileToBoard(bool,QUrl,QString,QByteArray,QPointF,QSize,bool)), this, SLOT(downloadFinished(bool,QUrl,QString,QByteArray,QPointF,QSize,bool)));
UBDocumentProxy* doc = UBPersistenceManager::persistenceManager()->createDocument();
setActiveDocumentScene(doc);
......@@ -751,13 +755,24 @@ void UBBoardController::downloadURL(const QUrl& url, const QPointF& pPos, const
}
else
{
UBHttpGet *http = new UBHttpGet(mActiveScene);
// When we fall there, it means that we are dropping something from the web to the board
sDownloadFileDesc desc;
desc.modal = true;
desc.url = url.toString();
desc.currentSize = 0;
desc.name = QFileInfo(url.toString()).fileName();
desc.totalSize = 0; // The total size will be retrieved during the download
desc.pos = pPos;
desc.size = pSize;
desc.isBackground = isBackground;
showMessage(tr("Downloading content from %1").arg(url.toString()), true);
// 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);
}
}
......@@ -1980,5 +1995,8 @@ void UBBoardController::notifyPageChanged()
emit pageChanged();
}
void UBBoardController::onDownloadModalFinished()
{
}
......@@ -49,15 +49,12 @@ class UBBoardController : public QObject
void init();
void setupLayout();
UBDocumentProxy* activeDocument() const;
UBGraphicsScene* activeScene() const;
int activeSceneIndex() const;
QSize displayViewport();
QSize controlViewport();
QRectF controlGeometry();
void closing();
UBDocumentProxy* activeDocument()
......@@ -137,21 +134,13 @@ class UBBoardController : public QObject
{
return mSystemScaleFactor;
}
qreal currentZoom();
void persistCurrentScene();
void showNewVersionAvailable(bool automatic, const UBVersion &installedVersion, const UBSoftwareUpdate &softwareUpdate);
void setBoxing(QRect displayRect);
void setToolbarTexts();
static QUrl expandWidgetToTempDir(const QByteArray& pZipedData, const QString& pExtension = QString("wgt"));
void setPageSize(QSize newSize);
UBBoardPaletteManager *paletteManager()
{
return mPaletteManager;
......@@ -161,102 +150,68 @@ class UBBoardController : public QObject
void notifyPageChanged();
public slots:
void setActiveDocumentScene(UBDocumentProxy* pDocumentProxy, int pSceneIndex = 0);
void showDocumentsDialog();
void showKeyboard(bool show);
void togglePodcast(bool checked);
void blackout();
void addScene();
void addScene(UBDocumentProxy* proxy, int sceneIndex, bool replaceActiveIfEmpty = false);
void addScene(UBGraphicsScene* scene, bool replaceActiveIfEmpty = false);
void duplicateScene();
void importPage();
void clearScene();
void clearSceneItems();
void clearSceneAnnotation();
void zoomIn(QPointF scenePoint = QPointF(0,0));
void zoomOut(QPointF scenePoint = QPointF(0,0));
void zoomRestore();
void centerRestore();
void centerOn(QPointF scenePoint = QPointF(0,0));
void zoom(const qreal ratio, QPointF scenePoint);
void handScroll(qreal dx, qreal dy);
void previousScene();
void nextScene();
void firstScene();
void lastScene();
void downloadURL(const QUrl& url, const QPointF& pPos = QPointF(0.0, 0.0),
const QSize& pSize = QSize(), bool isBackground = false);
void 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);
void downloadFinished(bool pSuccess, QUrl sourceUrl, QString pHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground = false);
void changeBackground(bool isDark, bool isCrossed);
void setToolCursor(int tool);
void showMessage(const QString& message, bool showSpinningWheel);
void hideMessage();
void setDisabled(bool disable);
void setColorIndex(int pColorIndex);
UBToolWidget* addTool(const QUrl& toolUrl, QPointF scenePos);
UBToolWidget* addTool(const QUrl& toolUrl);
void removeTool(UBToolWidget* toolWidget);
void hide();
void show();
void setWidePageSize(bool checked);
void setRegularPageSize(bool checked);
void stylusToolChanged(int tool);
void grabScene(const QRectF& pSceneRect);
void controlViewHidden();
void controlViewShown();
UBGraphicsVideoItem* addVideo(const QUrl& pUrl, bool startPlay, const QPointF& pos);
UBGraphicsAudioItem* addAudio(const QUrl& pUrl, bool startPlay, const QPointF& pos);
void cut();
void copy();
void paste();
void processMimeData(const QMimeData* pMimeData, const QPointF& pPos);
void moveGraphicsWidgetToControlView(UBGraphicsWidgetItem* graphicWidget);
void moveToolWidgetToScene(UBToolWidget* toolWidget);
void addItem();
signals:
void activeSceneWillBePersisted();
void activeSceneWillChange();
void activeSceneChanged();
void activeDocumentChanged();
void zoomChanged(qreal pZoomFactor);
void systemScaleFactorChanged(qreal pSystemScaleFactor);
void penColorChanged();
void controlViewportChanged();
void backgroundChanged();
void cacheEnabled();
void cacheDisabled();
......@@ -265,82 +220,56 @@ class UBBoardController : public QObject
void documentReorganized(int index);
protected:
void setupViews();
void setupToolbar();
void connectToolbar();
void initToolbarTexts();
void updateActionStates();
void updateSystemScaleFactor();
QString truncate(QString text, int maxWidth);
protected slots:
void selectionChanged();
void undoRedoStateChange(bool canUndo);
void documentSceneChanged(UBDocumentProxy* proxy, int pIndex);
private:
void updatePageSizeState();
void saveViewState();
void adjustDisplayViews();
UBMainWindow *mMainWindow;
UBDocumentProxy* mActiveDocument;
UBGraphicsScene* mActiveScene;
int mActiveSceneIndex;
UBBoardPaletteManager *mPaletteManager;
UBSoftwareUpdateDialog *mSoftwareUpdateDialog;
UBMessageWindow *mMessageWindow;
UBBoardView *mControlView;
UBBoardView *mDisplayView;
QWidget *mControlContainer;
QHBoxLayout *mControlLayout;
qreal mZoomFactor;
bool mIsClosing;
QColor mPenColorOnDarkBackground;
QColor mPenColorOnLightBackground;
QColor mMarkerColorOnDarkBackground;
QColor mMarkerColorOnLightBackground;
QList<UBToolWidget*> mTools;
qreal mSystemScaleFactor;
void updatePageSizeState();
void saveViewState();
void adjustDisplayViews();
bool mCleanupDone;
QMap<QAction*, QPair<QString, QString> > mActionTexts;
private slots:
void stylusToolDoubleClicked(int tool);
void boardViewResized(QResizeEvent* event);
void documentWillBeDeleted(UBDocumentProxy* pProxy);
void updateBackgroundActionsState(bool isDark, bool isCrossed);
void updateBackgroundState();
void colorPaletteChanged();
void libraryDialogClosed(int ret);
void lastWindowClosed();
void onDownloadModalFinished();
};
......
......@@ -726,11 +726,12 @@ UBBoardView::dragMoveEvent (QDragMoveEvent *event)
void
UBBoardView::dropEvent (QDropEvent *event)
{
if(!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source()))
{
qDebug() << event->source();
if(!event->source() || dynamic_cast<UBThumbnailWidget *>(event->source()) || dynamic_cast<QWebView*>(event->source()))
{
mController->processMimeData (event->mimeData (), mapToScene (event->pos ()));
event->acceptProposedAction ();
}
}
}
void
......
This diff is collapsed.
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOWNLOADMANAGER_H
#define UBDOWNLOADMANAGER_H
#include <QObject>
#include <QString>
#include <QVector>
#include <QMutex>
#include "UBDownloadThread.h"
#include "network/UBHttpGet.h"
#define SIMULTANEOUS_DOWNLOAD 2 // Maximum 5 because of QNetworkAccessManager limitation!!!
typedef struct
{
QString name;
int id;
int totalSize;
int currentSize;
QString url;
bool modal;
QPointF pos; // For board drop only
QSize size; // For board drop only
bool isBackground; // For board drop only
}sDownloadFileDesc;
class UBDownloadHttpFile : public UBHttpGet
{
Q_OBJECT
public:
UBDownloadHttpFile(int fileId, QObject* parent=0);
~UBDownloadHttpFile();
signals:
void downloadProgress(int id, qint64 current,qint64 total);
void downloadFinished(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
private slots:
void onDownloadFinished(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void onDownloadProgress(qint64 bytesReceived, qint64 bytesTotal);
private:
int mId;
};
class UBDownloadManager : public QObject
{
Q_OBJECT
public:
UBDownloadManager(QObject* parent=0, const char* name="UBDownloadManager");
~UBDownloadManager();
static UBDownloadManager* downloadManager();
void addFileToDownload(sDownloadFileDesc desc);
QVector<sDownloadFileDesc> currentDownloads();
QVector<sDownloadFileDesc> pendingDownloads();
void cancelDownloads();
signals:
void fileAddedToDownload();
void downloadUpdated(int id, qint64 crnt, qint64 total);
void downloadFinished(int id);
void downloadModalFinished();
void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void cancelAllDownloads();
private slots:
void onUpdateDownloadLists();
void onDownloadProgress(int id, qint64 received, qint64 total);
void onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
private:
void init();
void updateDownloadOrder();
void updateFileCurrentSize(int id, qint64 received=-1, qint64 total=-1);
void startFileDownload(sDownloadFileDesc desc);
void checkIfModalRemains();
/** The current downloads */
QVector<sDownloadFileDesc> mCrntDL;
/** The pending downloads */
QVector<sDownloadFileDesc> mPendingDL;
/** Pending download mutex */
QMutex mMutex;
/** The last file ID */
int mLastID;
/** The current download availability (-1 = free, otherwise the file ID is recorded)*/
QVector<int> mDLAvailability;
};
#endif // UBDOWNLOADMANAGER_H
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QNetworkProxy>
#include <QNetworkDiskCache>
#include "core/UBSettings.h"
#include "UBDownloadThread.h"
/**
* \brief Constructor
* @param parent as the parent object
* @param name as the object name
*/
UBDownloadThread::UBDownloadThread(QObject *parent, const char *name):QThread(parent)
, mbRun(false)
,mpReply(NULL)
{
setObjectName(name);
}
/**
* \brief Destructor
*/
UBDownloadThread::~UBDownloadThread()
{
if(NULL != mpReply)
{
delete mpReply;
mpReply = NULL;
}
}
/**
* \brief Run the thread
*/
void UBDownloadThread::run()
{
qDebug() << mUrl;
// We start the download
QNetworkAccessManager* pNam = new QNetworkAccessManager();
mpReply = pNam->get(QNetworkRequest(QUrl(mUrl)));
qDebug() << " -- Http GET reply ---------------------- ";
qDebug() << mpReply->readAll();
qDebug() << " ---------------------------------------- ";
connect(mpReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64,qint64)));
connect(mpReply, SIGNAL(finished()), this, SLOT(onDownloadFinished()));
while(mbRun)
{
// Wait here until the end of the download
sleep(100);
}
disconnect(mpReply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(onDownloadProgress(qint64,qint64)));
disconnect(mpReply, SIGNAL(finished()), this, SLOT(onDownloadFinished()));
if(NULL != mpReply)
{
delete mpReply;
mpReply = NULL;
}
}
/**
* \brief Stop the current download
*/
void UBDownloadThread::stopDownload()
{
mbRun = false;
}
/**
* \brief Start the download
*/
void UBDownloadThread::startDownload(int id, QString url)
{
mID = id;
mUrl = url;
mbRun = true;
start();
}
/**
* \brief Notify the download progression
* @param received as the number of bytes received
* @param total as the total number of bytes of the file
*/
void UBDownloadThread::onDownloadProgress(qint64 received, qint64 total)
{
qDebug() << received << " on " << total;
emit downloadProgress(mID, received, total);
}
/**
* \brief Notify the end of the download
*/
void UBDownloadThread::onDownloadFinished()
{
emit downloadFinised(mID);
}
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOWNLOADTHREAD_H
#define UBDOWNLOADTHREAD_H
#include <QThread>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
class UBDownloadThread : public QThread
{
Q_OBJECT
public:
UBDownloadThread(QObject* parent=0, const char* name="UBDownloadThread");
~UBDownloadThread();
void stopDownload();
void startDownload(int id, QString url);
signals:
void downloadFinised(int id);
void downloadProgress(int id, qint64 current, qint64 total);
protected:
virtual void run();
private slots:
void onDownloadProgress(qint64 received, qint64 total);
void onDownloadFinished();
private:
/** Flag used to stop the thread */
bool mbRun;
/** The downloaded file id */
int mID;
/** The downloaded file url */
QString mUrl;
/** The network access manager */
QNetworkAccessManager* mpNam;
/** The network reply */
QNetworkReply* mpReply;
};
#endif // UBDOWNLOADTHREAD_H
......@@ -306,8 +306,6 @@ void UBPersistenceManager::deleteDocument(UBDocumentProxy* pDocumentProxy)
emit documentWillBeDeleted(pDocumentProxy);
qDebug() << "Deleting document" << pDocumentProxy->persistencePath();
UBFileSystemUtils::deleteDir(pDocumentProxy->persistencePath());
documentProxies.removeAll(QPointer<UBDocumentProxy>(pDocumentProxy));
......@@ -619,8 +617,6 @@ void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy,
QDir dir(pDocumentProxy->persistencePath());
dir.mkpath(pDocumentProxy->persistencePath());
qDebug() << "saving page" << pSceneIndex + 1 << pDocumentProxy->persistencePath();
if (pDocumentProxy->isModified())
UBMetadataDcSubsetAdaptor::persist(pDocumentProxy);
......
......@@ -10,7 +10,9 @@ HEADERS += src/core/UB.h \
src/core/UBIdleTimer.h \
src/core/UBDisplayManager.h \
src/core/UBDocumentManager.h \
src/core/UBApplicationController.h
src/core/UBApplicationController.h \
src/core/UBDownloadManager.h \
src/core/UBDownloadThread.h
SOURCES += src/core/main.cpp \
src/core/UBApplication.cpp \
......@@ -23,6 +25,8 @@ SOURCES += src/core/main.cpp \
src/core/UBIdleTimer.cpp \
src/core/UBDisplayManager.cpp \
src/core/UBDocumentManager.cpp \
src/core/UBApplicationController.cpp
src/core/UBApplicationController.cpp \
src/core/UBDownloadManager.cpp \
src/core/UBDownloadThread.cpp
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <QDebug>
#include <QHeaderView>
#include <QStyleOptionProgressBarV2>
#include <QApplication>
#include "UBDownloadWidget.h"
#include "core/UBApplication.h"
/**
* \brief Constructor
* @param parent as the parent widget
* @param name as the widget object name
*/
UBDownloadWidget::UBDownloadWidget(QWidget *parent, const char *name):QWidget(parent)
, mpLayout(NULL)
, mpBttnLayout(NULL)
, mpTree(NULL)
, mpCancelBttn(NULL)
, mpItem(NULL)
{
setObjectName(name);
setWindowTitle(tr("Downloading files"));
setAttribute(Qt::WA_StyledBackground, true);
setStyleSheet(UBApplication::globalStyleSheet());
resize(400, 300);
mpLayout = new QVBoxLayout(this);
setLayout(mpLayout);
mpTree = new QTreeWidget(this);
mpTree->setRootIsDecorated(false);
mpTree->header()->close();
mpLayout->addWidget(mpTree, 1);
mpBttnLayout = new QHBoxLayout();
mpBttnLayout->addStretch(1);
mpCancelBttn = new QPushButton(tr("Cancel"), this);
mpBttnLayout->addWidget(mpCancelBttn, 0);
mpLayout->addLayout(mpBttnLayout);
connect(UBDownloadManager::downloadManager(), SIGNAL(fileAddedToDownload()), this, SLOT(onFileAddedToDownload()));
connect(UBDownloadManager::downloadManager(), SIGNAL(downloadUpdated(int,qint64,qint64)), this, SLOT(onDownloadUpdated(int,qint64,qint64)));
connect(UBDownloadManager::downloadManager(), SIGNAL(downloadFinished(int)), this, SLOT(onDownloadFinished(int)));
connect(mpCancelBttn, SIGNAL(clicked()), this, SLOT(onCancelClicked()));
}
/**
* \brief Destructor
*/
UBDownloadWidget::~UBDownloadWidget()
{
if(NULL != mpItem)
{
delete mpItem;
mpItem = NULL;
}
if(NULL != mpCancelBttn)
{
delete mpCancelBttn;
mpCancelBttn = NULL;
}
if(NULL != mpTree)
{
delete mpTree;
mpTree = NULL;
}
if(NULL != mpBttnLayout)
{
delete mpBttnLayout;
mpBttnLayout = NULL;
}
if(NULL != mpLayout)
{
delete mpLayout;
mpLayout = NULL;
}
}
/**
* \brief Refresh the tree of downloaded files
*/
void UBDownloadWidget::onFileAddedToDownload()
{
if(NULL != mpTree)
{
mpTree->clear();
addCurrentDownloads();
addPendingDownloads();
}
}
/**
* \brief Add the current downloads
*/
void UBDownloadWidget::addCurrentDownloads()
{
QVector<sDownloadFileDesc> actualDL = UBDownloadManager::downloadManager()->currentDownloads();
for(int i=0; i<actualDL.size();i++)
{
mpItem = new QTreeWidgetItem(mpTree);
mpItem->setText(0, actualDL.at(i).name);
mpItem->setData(0, Qt::UserRole, QVariant(actualDL.at(i).id));
mpTree->addTopLevelItem(mpItem);
mpItem = new QTreeWidgetItem(mpTree);
mpItem->setData(0, Qt::UserRole, actualDL.at(i).currentSize);
mpItem->setData(0, Qt::UserRole + 1, actualDL.at(i).totalSize);
mpItem->setData(0, Qt::UserRole + 2, actualDL.at(i).id);
mpTree->addTopLevelItem(mpItem);
mpTree->setItemDelegateForRow(((i+1)*2)-1, &mProgressBarDelegate);
}
}
/**
* \brief Add the pending downloads
*/
void UBDownloadWidget::addPendingDownloads()
{
QVector<sDownloadFileDesc> pendingDL = UBDownloadManager::downloadManager()->pendingDownloads();
for(int i=0; i<pendingDL.size(); i++)
{
mpItem = new QTreeWidgetItem(mpTree);
mpItem->setText(0, pendingDL.at(i).name);
mpItem->setData(0, Qt::UserRole, QVariant(pendingDL.at(i).id));
mpTree->addTopLevelItem(mpItem);
}
}
/**
* \brief Update the progress bar
* @param id as the downloaded file id
* @param crnt as the current transfered size
* @param total as the total size of the file
*/
void UBDownloadWidget::onDownloadUpdated(int id, qint64 crnt, qint64 total)
{
if(NULL != mpTree)
{
QAbstractItemModel* model = mpTree->model();
if(NULL != model)
{
for(int i=0; i< model->rowCount(); i++)
{
QModelIndex currentIndex = model->index(i, 0);
if(id == currentIndex.data(Qt::UserRole + 2))
{
// We found the right item, now we update the progress bar
model->setData(currentIndex, crnt, Qt::UserRole);
model->setData(currentIndex, total, Qt::UserRole + 1);
break;
}
}
}
}
}
/**
* \brief Handles the download finish notification
* @param id as the downloaded file id
*/
void UBDownloadWidget::onDownloadFinished(int id)
{
// Refresh the file's list
onFileAddedToDownload();
}
/**
* \brief Handles the Cancel button action
*/
void UBDownloadWidget::onCancelClicked()
{
}
// ---------------------------------------------------------------------------------------------
UBDownloadProgressDelegate::UBDownloadProgressDelegate(QObject *parent):QItemDelegate(parent)
{
}
void UBDownloadProgressDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionProgressBarV2 opt;
opt.rect = option.rect;
opt.minimum = 0;
opt.maximum = index.data(Qt::UserRole + 1).toInt();
opt.progress = index.data(Qt::UserRole).toInt();
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &opt, painter, 0);
}
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef UBDOWNLOADWIDGET_H
#define UBDOWNLOADWIDGET_H
#include <QWidget>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QItemDelegate>
#include "core/UBDownloadManager.h"
class UBDownloadProgressDelegate : public QItemDelegate
{
Q_OBJECT
public:
UBDownloadProgressDelegate(QObject* parent=0);
protected:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
class UBDownloadWidget : public QWidget
{
Q_OBJECT
public:
UBDownloadWidget(QWidget* parent=0, const char* name="UBDownloadWidget");
~UBDownloadWidget();
private slots:
void onFileAddedToDownload();
void onDownloadUpdated(int id, qint64 crnt, qint64 total);
void onDownloadFinished(int id);
void onCancelClicked();
private:
void addCurrentDownloads();
void addPendingDownloads();
/** The general layout of this widget */
QVBoxLayout* mpLayout;
/** The button layout */
QHBoxLayout* mpBttnLayout;
/** The treeview that will display the files list */
QTreeWidget* mpTree;
/** The 'Cancel' button */
QPushButton* mpCancelBttn;
/** A temporary tree widget item */
QTreeWidgetItem* mpItem;
/** The delegate that will draw the progressbars */
UBDownloadProgressDelegate mProgressBarDelegate;
};
#endif // UBDOWNLOADWIDGET_H
......@@ -19,7 +19,6 @@ UBLibWebView::UBLibWebView(QWidget* parent, const char* name):QWidget(parent)
mpView = new QWebView(this);
mpView->setObjectName("SearchEngineView");
//mpView->setStyleSheet(QString("background-color:white;"));
mpWebSettings = QWebSettings::globalSettings();
mpWebSettings->setAttribute(QWebSettings::JavaEnabled, true);
......
......@@ -27,9 +27,12 @@ UBMainWindow::UBMainWindow(QWidget *parent, Qt::WindowFlags flags)
, mBoardWidget(0)
, mWebWidget(0)
, mDocumentsWidget(0)
, mpDownloadWidget(NULL)
{
Ui::MainWindow::setupUi(this);
mpDownloadWidget = new UBDownloadWidget();
mpDownloadWidget->setWindowModality(Qt::ApplicationModal);
//Setting tooltip colors staticly, since they look not quite well on different color themes
QPalette toolTipPalette;
......@@ -55,7 +58,11 @@ UBMainWindow::UBMainWindow(QWidget *parent, Qt::WindowFlags flags)
UBMainWindow::~UBMainWindow()
{
// NOOP
if(NULL != mpDownloadWidget)
{
delete mpDownloadWidget;
mpDownloadWidget = NULL;
}
}
void UBMainWindow::addBoardWidget(QWidget *pWidget)
......@@ -77,7 +84,6 @@ void UBMainWindow::switchToBoardWidget()
void UBMainWindow::addWebWidget(QWidget *pWidget)
{
qDebug() << "add to StackedLayout size height: " << pWidget->height() << " width: " << pWidget->width();
if (!mWebWidget)
{
mWebWidget = pWidget;
......@@ -182,3 +188,18 @@ void UBMainWindow::information(QString windowTitle, QString text)
oneButtonMessageBox(windowTitle, text, QMessageBox::Information);
}
void UBMainWindow::showDownloadWidget()
{
if(NULL != mpDownloadWidget)
{
mpDownloadWidget->show();
}
}
void UBMainWindow::hideDownloadWidget()
{
if(NULL != mpDownloadWidget)
{
mpDownloadWidget->hide();
}
}
......@@ -21,6 +21,7 @@
#include <QWidget>
#include <QWebView>
#include <QMessageBox>
#include "UBDownloadWidget.h"
class QStackedLayout;
......@@ -47,6 +48,9 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow
void warning(QString windowTitle, QString text);
void information(QString windowTitle, QString text);
void showDownloadWidget();
void hideDownloadWidget();
signals:
void closeEvent_Signal( QCloseEvent *event );
......@@ -70,6 +74,9 @@ class UBMainWindow : public QMainWindow, public Ui::MainWindow
QWidget *mBoardWidget;
QWidget *mWebWidget;
QWidget *mDocumentsWidget;
private:
UBDownloadWidget* mpDownloadWidget;
};
#endif /* UBMAINWINDOW_H_ */
......@@ -44,7 +44,8 @@ HEADERS += src/gui/UBThumbnailView.h \
src/gui/UBMagnifer.h \
src/gui/UBCachePropertiesWidget.h \
src/gui/UBTeacherBarWidget.h \
src/gui/UBLibWebView.h
src/gui/UBLibWebView.h \
src/gui/UBDownloadWidget.h
SOURCES += src/gui/UBThumbnailView.cpp \
src/gui/UBFloatingPalette.cpp \
......@@ -91,7 +92,8 @@ SOURCES += src/gui/UBThumbnailView.cpp \
src/gui/UBMagnifer.cpp \
src/gui/UBCachePropertiesWidget.cpp \
src/gui/UBTeacherBarWidget.cpp \
src/gui/UBLibWebView.cpp
src/gui/UBLibWebView.cpp \
src/gui/UBDownloadWidget.cpp
win32 {
......
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