Finished the download manager support in the right palette

preferencesAboutTextFull
shibakaneki 13 years ago
parent d79f36eb9b
commit c508ec6adf
  1. 7
      src/board/UBBoardPaletteManager.cpp
  2. 2
      src/board/UBBoardPaletteManager.h
  3. 68
      src/core/UBDownloadManager.cpp
  4. 7
      src/core/UBDownloadManager.h
  5. 43
      src/gui/UBDownloadWidget.cpp
  6. 6
      src/gui/UBDownloadWidget.h

@ -83,6 +83,7 @@ UBBoardPaletteManager::UBBoardPaletteManager(QWidget* container, UBBoardControll
, mpTeacherBarWidget(NULL)
, mpDesktopLibWidget(NULL)
, mpDownloadWidget(NULL)
, mDownloadInProgress(false)
{
setupPalettes();
connectPalettes();
@ -1009,16 +1010,18 @@ void UBBoardPaletteManager::refreshPalettes()
void UBBoardPaletteManager::startDownloads()
{
if(!mpDownloadWidget->isVisible())
if(!mDownloadInProgress)
{
mDownloadInProgress = true;
mRightPalette->addTab(mpDownloadWidget);
}
}
void UBBoardPaletteManager::stopDownloads()
{
if(mpDownloadWidget->isVisible())
if(mDownloadInProgress)
{
mDownloadInProgress = false;
mRightPalette->removeTab(mpDownloadWidget->name());
}
}

@ -144,6 +144,8 @@ class UBBoardPaletteManager : public QObject
// lib widget!
UBLibWidget* mpDesktopLibWidget;
bool mDownloadInProgress;
private slots:
void changeBackground();

@ -86,10 +86,7 @@ void UBDownloadManager::addFileToDownload(sDownloadFileDesc desc)
updateDownloadOrder();
UBApplication::mainWindow->showDownloadWidget();
}
else
{
UBApplication::boardController->paletteManager()->startDownloads();
}
UBApplication::boardController->paletteManager()->startDownloads();
emit fileAddedToDownload();
}
@ -276,7 +273,7 @@ void UBDownloadManager::updateFileCurrentSize(int id, qint64 received, qint64 to
// Verify if all downloads are finished
if(mCrntDL.empty() && mPendingDL.empty())
{
emit allDownloadsFinished();
finishDownloads();
}
break;
@ -357,8 +354,7 @@ void UBDownloadManager::cancelDownloads()
checkIfModalRemains();
// Notify everyone that the downloads have been canceled.
emit cancelAllDownloads();
finishDownloads(true);
}
void UBDownloadManager::onDownloadError(int id)
@ -380,6 +376,64 @@ void UBDownloadManager::onDownloadError(int id)
}
}
void UBDownloadManager::finishDownloads(bool cancel)
{
UBApplication::boardController->paletteManager()->stopDownloads();
if(cancel){
emit cancelAllDownloads();
}
else{
emit allDownloadsFinished();
}
}
void UBDownloadManager::cancelDownload(int id)
{
// Stop the download
mReplies[id]->abort();
mReplies.remove(id);
// Remove the canceled download from the download lists
bool bFound = false;
for(int i=0; i<mCrntDL.size(); i++){
if(id == mCrntDL.at(i).id){
mCrntDL.remove(i);
bFound = true;
break;
}
}
if(!bFound){
for(int j=0; j<mPendingDL.size(); j++){
if(id == mPendingDL.at(j).id){
mPendingDL.remove(j);
bFound = true;
break;
}
}
}
// Free the download slot used by the finished file
for(int h=0; h<mDLAvailability.size();h++){
if(id == mDLAvailability.at(h)){
mDLAvailability.remove(h);
mDLAvailability.insert(h, -1);
break;
}
}
// Here we check if some modal downloads remain
checkIfModalRemains();
// Then we update the list of downloads
onUpdateDownloadLists();
// Verify if all downloads are finished
if(mCrntDL.empty() && mPendingDL.empty())
{
finishDownloads();
}
}
// ------------------------------------------------------------------------------
/**
* \brief Constructor

@ -63,11 +63,14 @@ 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();
void cancelDownload(int id);
static void destroy();
@ -88,14 +91,12 @@ private slots:
void onDownloadError(int id);
private:
UBDownloadManager(QObject* parent=0, const char* name="UBDownloadManager");
~UBDownloadManager();
void init();
void updateDownloadOrder();
void updateFileCurrentSize(int id, qint64 received=-1, qint64 total=-1);
void startFileDownload(sDownloadFileDesc desc);
void checkIfModalRemains();
void finishDownloads(bool cancel=false);
/** The current downloads */
QVector<sDownloadFileDesc> mCrntDL;

@ -45,6 +45,11 @@ UBDownloadWidget::UBDownloadWidget(QWidget *parent, const char *name):QWidget(pa
mpTree = new QTreeWidget(this);
mpTree->setRootIsDecorated(false);
mpTree->setColumnCount(2);
mpTree->header()->setStretchLastSection(false);
mpTree->header()->setResizeMode(eItemColumn_Desc, QHeaderView::Stretch);
mpTree->header()->setResizeMode(eItemColumn_Close, QHeaderView::Custom);
mpTree->resizeColumnToContents(eItemColumn_Close);
mpTree->header()->close();
mpLayout->addWidget(mpTree, 1);
@ -59,6 +64,7 @@ UBDownloadWidget::UBDownloadWidget(QWidget *parent, const char *name):QWidget(pa
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()));
connect(mpTree, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(onItemClicked(QTreeWidgetItem*,int)));
}
/**
@ -111,13 +117,14 @@ void UBDownloadWidget::addCurrentDownloads()
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));
mpItem->setText(eItemColumn_Desc, actualDL.at(i).name);
mpItem->setData(eItemColumn_Desc, Qt::UserRole, QVariant(actualDL.at(i).id));
mpItem->setIcon(eItemColumn_Close, QIcon(":images/close.svg"));
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);
mpItem->setData(eItemColumn_Desc, Qt::UserRole, actualDL.at(i).currentSize);
mpItem->setData(eItemColumn_Desc, Qt::UserRole + 1, actualDL.at(i).totalSize);
mpItem->setData(eItemColumn_Desc, Qt::UserRole + 2, actualDL.at(i).id);
mpTree->addTopLevelItem(mpItem);
mpTree->setItemDelegateForRow(((i+1)*2)-1, &mProgressBarDelegate);
}
@ -129,12 +136,11 @@ void UBDownloadWidget::addCurrentDownloads()
void UBDownloadWidget::addPendingDownloads()
{
QVector<sDownloadFileDesc> pendingDL = UBDownloadManager::downloadManager()->pendingDownloads();
qDebug() << "Pending downloads size: " << pendingDL.size();
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));
mpItem->setText(eItemColumn_Desc, pendingDL.at(i).name);
mpItem->setData(eItemColumn_Desc, Qt::UserRole, QVariant(pendingDL.at(i).id));
mpTree->addTopLevelItem(mpItem);
}
}
@ -154,7 +160,7 @@ void UBDownloadWidget::onDownloadUpdated(int id, qint64 crnt, qint64 total)
{
for(int i=0; i< model->rowCount(); i++)
{
QModelIndex currentIndex = model->index(i, 0);
QModelIndex currentIndex = model->index(i, eItemColumn_Desc);
if(id == currentIndex.data(Qt::UserRole + 2))
{
// We found the right item, now we update the progress bar
@ -186,6 +192,21 @@ void UBDownloadWidget::onCancelClicked()
UBDownloadManager::downloadManager()->cancelDownloads();
}
/**
* \brief Handles the item click notification
* @param pItem as the item clicked
* @param col as the column containing the item clicked
*/
void UBDownloadWidget::onItemClicked(QTreeWidgetItem *pItem, int col)
{
if( eItemColumn_Close == col
&& "" != pItem->text(eItemColumn_Desc)){
// Stop the download of the clicked item and remove it from the list
UBDownloadManager::downloadManager()->cancelDownload(pItem->data(eItemColumn_Desc, Qt::UserRole).toInt());
}
}
// ---------------------------------------------------------------------------------------------
UBDownloadProgressDelegate::UBDownloadProgressDelegate(QObject *parent):QItemDelegate(parent)
{
@ -200,5 +221,7 @@ void UBDownloadProgressDelegate::paint(QPainter *painter, const QStyleOptionView
opt.maximum = index.data(Qt::UserRole + 1).toInt();
opt.progress = index.data(Qt::UserRole).toInt();
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &opt, painter, 0);
if(0 == index.column()){
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &opt, painter, 0);
}
}

@ -25,6 +25,11 @@
#include "core/UBDownloadManager.h"
typedef enum{
eItemColumn_Desc,
eItemColumn_Close
}eItemColumn;
class UBDownloadProgressDelegate : public QItemDelegate
{
Q_OBJECT
@ -47,6 +52,7 @@ private slots:
void onDownloadUpdated(int id, qint64 crnt, qint64 total);
void onDownloadFinished(int id);
void onCancelClicked();
void onItemClicked(QTreeWidgetItem* pItem, int col);
private:
void addCurrentDownloads();

Loading…
Cancel
Save