added routeDataItem to write on disk on only once the file. Pay attention that QDir("tmp") on windows doesn't works because we don't have the right for writing there.

preferencesAboutTextFull
Claudio Valerio 13 years ago
parent 1da0bb06ad
commit d7bd098f68
  1. 30
      src/board/UBLibraryController.cpp
  2. 3
      src/board/UBLibraryController.h
  3. 27
      src/gui/UBLibraryWidget.cpp

@ -105,11 +105,11 @@ void UBLibraryController::createDirectory(QUrl& pDirPath)
QDir().mkpath(pDirPath.toLocalFile());
}
void UBLibraryController::routeItem(QString& pItem, QString pMiddleDirectory)
QString UBLibraryController::getBaseDestinationForItem(QString& pItem)
{
QFileInfo itemToRoute(pItem);
QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(itemToRoute.fileName());
QString destination("");
QString mimetype = UBFileSystemUtils::mimeTypeFromFileName(pItem);
if(mimetype.contains("audio"))
destination = mAudioStandardDirectoryPath.toLocalFile();
@ -123,10 +123,30 @@ void UBLibraryController::routeItem(QString& pItem, QString pMiddleDirectory)
else
destination = mInteractiveUserDirectoryPath.toLocalFile();
}
else{
return;
return destination;
}
void UBLibraryController::routeDataItem(QString& pItem, QByteArray pData)
{
QString fileName = QFileInfo(pItem).fileName();
QString destination = getBaseDestinationForItem(pItem);
if(!destination.isEmpty()){
QString destinationPath = UBFileSystemUtils::normalizeFilePath(QString("%0/%1").arg(destination).arg(fileName));
QFile file(destinationPath);
if(file.open(QIODevice::WriteOnly)) {
file.write(pData);
file.close();
}
}
else
qWarning() << "no destination found for pItem " << pItem;
}
void UBLibraryController::routeItem(QString& pItem, QString pMiddleDirectory)
{
QFileInfo itemToRoute(pItem);
QString destination = getBaseDestinationForItem(pItem);
if(!destination.isEmpty()){
if(!pMiddleDirectory.isEmpty()){
destination = destination + "/" + pMiddleDirectory;

@ -123,7 +123,9 @@ class UBLibraryController : public QObject
void createNewFolder(QString name, UBLibElement* parentElem);
bool canItemsOnElementBeDeleted(UBLibElement *pElement);
void routeItem(QString& pItem, QString pMiddleDirectory = QString());
void routeDataItem(QString& pItem, QByteArray pData);
signals:
void dialogClosed(int state);
@ -175,6 +177,7 @@ class UBLibraryController : public QObject
UBBoardController *mBoardController;
int mLastItemOffsetIndex;
QString getBaseDestinationForItem(QString& pItem);
};

@ -698,19 +698,20 @@ void UBLibraryWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl
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 :)
// 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();
// }
QString urlString = sourceUrl.toString();
mLibraryController->routeDataItem(urlString, pData);
// dir.remove(qsFileName);
// dir.rmdir("tmp"); // Due to Qt, the directoy will be removed only if it's empty :)
}
}

Loading…
Cancel
Save