Supported drag and drop in the library from Firefox and Chrome

preferencesAboutTextFull
shibakaneki 13 years ago
parent 0898bc5381
commit 6fa9930b49
  1. 20
      src/board/UBLibraryController.cpp
  2. 2
      src/board/UBLibraryController.h
  3. 5
      src/core/UBApplication.cpp
  4. 10
      src/core/UBDownloadManager.cpp
  5. 1
      src/core/UBDownloadManager.h
  6. 33
      src/gui/UBLibraryWidget.cpp
  7. 2
      src/gui/UBLibraryWidget.h
  8. 1
      src/network/UBNetworkAccessManager.cpp

@ -23,6 +23,7 @@
#include "core/UBSettings.h" #include "core/UBSettings.h"
#include "core/UBSetting.h" #include "core/UBSetting.h"
#include "core/UBApplicationController.h" #include "core/UBApplicationController.h"
#include "core/UBDownloadManager.h"
#include "domain/UBAbstractWidget.h" #include "domain/UBAbstractWidget.h"
#include "domain/UBGraphicsScene.h" #include "domain/UBGraphicsScene.h"
@ -110,7 +111,6 @@ void UBLibraryController::createDirectory(QUrl& pDirPath)
void UBLibraryController::routeItem(QString& pItem, QString pMiddleDirectory) void UBLibraryController::routeItem(QString& pItem, QString pMiddleDirectory)
{ {
qDebug() << "routeItem: " << pItem;
QFileInfo itemToRoute(pItem); QFileInfo itemToRoute(pItem);
QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(itemToRoute.fileName()); QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(itemToRoute.fileName());
QString destination(""); QString destination("");
@ -138,6 +138,7 @@ void UBLibraryController::routeItem(QString& pItem, QString pMiddleDirectory)
createDirectory(url); createDirectory(url);
} }
destination = UBFileSystemUtils::normalizeFilePath(destination + "/" + itemToRoute.fileName()); destination = UBFileSystemUtils::normalizeFilePath(destination + "/" + itemToRoute.fileName());
QFile::copy(pItem, destination); QFile::copy(pItem, destination);
} }
} }
@ -187,8 +188,25 @@ void UBLibraryController::importItemOnLibrary(QString& pItemString)
} }
} }
else{ else{
if(pItemString.startsWith("uniboardTool://") || pItemString.startsWith("file://") || pItemString.startsWith("/"))
{
// The user dropped a local file
routeItem(pItemString); routeItem(pItemString);
} }
else
{
// The user dropped a file from the web. We must download it.
sDownloadFileDesc desc;
desc.currentSize = 0;
desc.id = 0;
desc.isBackground = false;
desc.modal = false;
desc.name = QFileInfo(pItemString).fileName();
desc.totalSize = 0;
desc.url = pItemString;
UBDownloadManager::downloadManager()->addFileToDownload(desc);
}
}
} }

@ -120,6 +120,7 @@ class UBLibraryController : public QObject
void createNewFolder(QString name, UBLibElement* parentElem); void createNewFolder(QString name, UBLibElement* parentElem);
bool canItemsOnElementBeDeleted(UBLibElement *pElement); bool canItemsOnElementBeDeleted(UBLibElement *pElement);
void routeItem(QString& pItem, QString pMiddleDirectory = QString());
signals: signals:
void dialogClosed(int state); void dialogClosed(int state);
@ -153,7 +154,6 @@ class UBLibraryController : public QObject
QList<UBLibElement*> addVirtualElementsForItemPath(const QString& pPath); QList<UBLibElement*> addVirtualElementsForItemPath(const QString& pPath);
void createInternalWidgetItems(); void createInternalWidgetItems();
void routeItem(QString& pItem, QString pMiddleDirectory = QString());
void createDirectory(QUrl& pDirPath); void createDirectory(QUrl& pDirPath);
QUrl mAudioStandardDirectoryPath; QUrl mAudioStandardDirectoryPath;

@ -633,15 +633,14 @@ QString UBApplication::globalStyleSheet()
QString UBApplication::urlFromHtml(QString html) QString UBApplication::urlFromHtml(QString html)
{ {
qDebug() << "HTML: " << html.remove(QRegExp("[\\0]"));
QString url; QString url;
QDomDocument domDoc; QDomDocument domDoc;
domDoc.setContent(html); domDoc.setContent(html.remove(QRegExp("[\\0]")));
QDomElement rootElem = domDoc.documentElement(); QDomElement rootElem = domDoc.documentElement();
url = rootElem.attribute("src"); url = rootElem.attribute("src");
qDebug() << url;
return url; return url;
} }

@ -15,6 +15,8 @@
#include "UBDownloadManager.h" #include "UBDownloadManager.h"
#include "core/UBApplication.h" #include "core/UBApplication.h"
#include "gui/UBMainWindow.h" #include "gui/UBMainWindow.h"
#include "board/UBBoardController.h"
#include "board/UBBoardPaletteManager.h"
/** The unique instance of the download manager */ /** The unique instance of the download manager */
static UBDownloadManager* pInstance = NULL; static UBDownloadManager* pInstance = NULL;
@ -73,6 +75,10 @@ void UBDownloadManager::addFileToDownload(sDownloadFileDesc desc)
updateDownloadOrder(); updateDownloadOrder();
UBApplication::mainWindow->showDownloadWidget(); UBApplication::mainWindow->showDownloadWidget();
} }
else
{
UBApplication::boardController->paletteManager()->startDownloads();
}
emit fileAddedToDownload(); emit fileAddedToDownload();
} }
@ -190,6 +196,10 @@ void UBDownloadManager::onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl
// The downloaded file is modal so we must put it on the board // The downloaded file is modal so we must put it on the board
emit addDownloadedFileToBoard(pSuccess, sourceUrl, pContentTypeHeader, pData, pPos, pSize, isBackground); emit addDownloadedFileToBoard(pSuccess, sourceUrl, pContentTypeHeader, pData, pPos, pSize, isBackground);
} }
else
{
emit addDownloadedFileToLibrary(pSuccess, sourceUrl, pContentTypeHeader, pData);
}
break; break;
} }
} }

@ -78,6 +78,7 @@ signals:
void downloadFinished(int id); void downloadFinished(int id);
void downloadModalFinished(); void downloadModalFinished();
void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground); void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void addDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData);
void cancelAllDownloads(); void cancelAllDownloads();
void allDownloadsFinished(); void allDownloadsFinished();

@ -14,6 +14,7 @@
*/ */
#include <QList> #include <QList>
#include <QFileInfo> #include <QFileInfo>
#include <QDir>
#include "UBLibraryWidget.h" #include "UBLibraryWidget.h"
#include "core/UBSettings.h" #include "core/UBSettings.h"
@ -24,6 +25,7 @@
#include "board/UBLibraryController.h" #include "board/UBLibraryController.h"
#include "core/memcheck.h" #include "core/memcheck.h"
#include "core/UBDownloadManager.h"
#include "frameworks/UBFileSystemUtils.h" #include "frameworks/UBFileSystemUtils.h"
@ -87,6 +89,7 @@ void UBLibraryWidget::init()
connect(this, SIGNAL(mouseClick(QGraphicsItem*,int)), this, SLOT(onItemClicked(QGraphicsItem*,int))); connect(this, SIGNAL(mouseClick(QGraphicsItem*,int)), this, SLOT(onItemClicked(QGraphicsItem*,int)));
connect(this, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged())); connect(this, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
connect(UBDownloadManager::downloadManager(), SIGNAL(addDownloadedFileToLibrary(bool,QUrl,QString,QByteArray)), this, SLOT(onAddDownloadedFileToLibrary(bool,QUrl,QString,QByteArray)));
} }
/** /**
@ -362,7 +365,14 @@ void UBLibraryWidget::dropEvent(QDropEvent *event)
} }
else if (pMimeData->hasHtml()) else if (pMimeData->hasHtml())
{ {
qDebug() << "hasHtml Unsupported yet"; qDebug() << "hasHtml";
QString html = pMimeData->html();
QString url = UBApplication::urlFromHtml(html);
if("" != url)
{
mLibraryController->importItemOnLibrary(url);
bDropAccepted = true;
}
} }
else if (pMimeData->hasText()) else if (pMimeData->hasText())
{ {
@ -666,3 +676,24 @@ void UBNewFolderDlg::text_Edited(const QString &newText)
QToolTip::showText(mpLineEdit->mapToGlobal(QPoint()), "A file name can`t contain any of the following characters:\r\n"+illegalCharList); QToolTip::showText(mpLineEdit->mapToGlobal(QPoint()), "A file name can`t contain any of the following characters:\r\n"+illegalCharList);
} }
} }
void UBLibraryWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData)
{
Q_UNUSED(pContentHeader);
if(pSuccess)
{
QDir dir;
dir.mkdir("tmp");
QString qsFileName = QFileInfo(sourceUrl.toString()).fileName();
QString qsFilePath = UBFileSystemUtils::normalizeFilePath(QString("tmp/%0").arg(qsFileName));
QFile f(qsFilePath);
if(f.open(QIODevice::WriteOnly))
{
f.write(pData);
f.close();
}
mLibraryController->routeItem(qsFilePath);
dir.remove(qsFileName);
dir.rmdir("tmp"); // Due to Qt, the directoy will be removed only if it's empty :)
}
}

@ -55,6 +55,8 @@ public slots:
void onSearchElement(QString elem); void onSearchElement(QString elem);
void onNewFolderToCreate(); void onNewFolderToCreate();
void onDropMe(const QMimeData* _data); void onDropMe(const QMimeData* _data);
void onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData);
signals: signals:
void navigBarUpdate(UBLibElement* pElem); void navigBarUpdate(UBLibElement* pElem);
void itemsSelected(QList<UBLibElement*> elemList, bool inTrash); void itemsSelected(QList<UBLibElement*> elemList, bool inTrash);

@ -84,7 +84,6 @@ QNetworkReply* UBNetworkAccessManager::createRequest(Operation op, const QNetwor
QNetworkReply *UBNetworkAccessManager::get(const QNetworkRequest &request) QNetworkReply *UBNetworkAccessManager::get(const QNetworkRequest &request)
{ {
qDebug() << "request url: " << request.url();
QTime loadStartTime; QTime loadStartTime;
loadStartTime.start(); loadStartTime.start();
QNetworkReply *networkReply = QNetworkAccessManager::get(request); QNetworkReply *networkReply = QNetworkAccessManager::get(request);

Loading…
Cancel
Save