Merge branch 'master' of github.com:Sankore/Sankore-3.1

preferencesAboutTextFull
Ivan Ilin 13 years ago
commit 5fbb43d432
  1. 9
      src/board/UBBoardController.cpp
  2. 7
      src/board/UBBoardPaletteManager.cpp
  3. 2
      src/board/UBBoardPaletteManager.h
  4. 68
      src/core/UBDownloadManager.cpp
  5. 7
      src/core/UBDownloadManager.h
  6. 43
      src/gui/UBDownloadWidget.cpp
  7. 6
      src/gui/UBDownloadWidget.h
  8. 52
      src/gui/UBLibPathViewer.cpp

@ -1884,7 +1884,14 @@ void UBBoardController::processMimeData(const QMimeData* pMimeData, const QPoint
if (pMimeData->hasText())
{
if("" != pMimeData->text()){
mActiveScene->addText(pMimeData->text(), pPos);
// Sometimes, it is possible to have an URL as text. we check here if it is the case
QString qsTmp = pMimeData->text().remove(QRegExp("[\\0]"));
if(qsTmp.startsWith("http")){
downloadURL(QUrl(qsTmp), pPos);
}
else{
mActiveScene->addText(pMimeData->text(), pPos);
}
}
else{
#ifdef Q_WS_MACX

@ -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();

@ -457,39 +457,33 @@ void UBPathScene::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
void UBPathScene::dropEvent(QGraphicsSceneDragDropEvent *event)
{
bool bAccept = false;
const QMimeData* pMimeData = event->mimeData();
if(NULL != event->source() && 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)
{
if(eUBLibElementType_Folder == pTargetElement->type())
{
if(NULL != pTargetElement){
if(eUBLibElementType_Folder == pTargetElement->type()){
// The drag comes from this application, we have now to get the list of UBLibElements*
QList<QString> qlDroppedElems;
foreach(QUrl url, pMimeData->urls())
qlDroppedElems << url.toString();
if(!qlDroppedElems.empty())
{
if(!qlDroppedElems.empty()){
// Send a signal with the target dir and the list of ublibelement*
emit elementsDropped(qlDroppedElems, pTargetElement);
}
}
}
event->accept();
bAccept = true;
}
else if(NULL != event->mimeData() && event->mimeData()->hasUrls())
{
else if(NULL != event->mimeData() && event->mimeData()->hasUrls()){
QList<QUrl> urls = event->mimeData()->urls();
foreach(QUrl eachUrl, urls)
{
foreach(QUrl eachUrl, urls){
QString sUrl = eachUrl.toString();
if(!sUrl.startsWith("uniboardTool://") && !sUrl.startsWith("file://") && !sUrl.startsWith("/"))
{
if(!sUrl.startsWith("uniboardTool://") && !sUrl.startsWith("file://") && !sUrl.startsWith("/")){
// The dropped URL comes from the web
qDebug() << "Dropped url: " << sUrl;
@ -508,9 +502,33 @@ void UBPathScene::dropEvent(QGraphicsSceneDragDropEvent *event)
UBDownloadManager::downloadManager()->addFileToDownload(desc);
}
}
bAccept = true;
}
else
{
else if(NULL != event->mimeData() && event->mimeData()->hasText()){
// The user can only drop an Url in this location so if the text is not an Url,
// we discard it.
QString qsTxt = event->mimeData()->text().remove(QRegExp("[\\0]"));
if(qsTxt.startsWith("http")){
// 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(qsTxt).fileName();
desc.totalSize = 0;
desc.url = qsTxt;
UBDownloadManager::downloadManager()->addFileToDownload(desc);
bAccept = true;
}
}
if(bAccept){
event->accept();
}
else{
event->ignore();
}
}

Loading…
Cancel
Save