Names of downloaded content

preferencesAboutTextFull
Ilia Ryabokon 12 years ago
parent 9efb26953f
commit 65dfcec73d
  1. 139
      src/board/UBFeaturesController.cpp
  2. 5
      src/board/UBFeaturesController.h
  3. 2
      src/core/UBDownloadManager.cpp
  4. 2
      src/core/UBDownloadManager.h
  5. 11
      src/gui/UBFeaturesWidget.cpp
  6. 2
      src/gui/UBFeaturesWidget.h

@ -485,6 +485,71 @@ void UBFeaturesController::saveFavoriteList()
file.close();
}
QString UBFeaturesController::uniqNameForFeature(const UBFeature &feature, const QString &pName, const QString &pExtention) const
{
Q_ASSERT(featuresList);
QStringList resultList;
QString parentVirtualPath = feature.getFullVirtualPath();
QString resultName;
qDebug() << "start";
foreach (UBFeature curFeature, *featuresList) {
if (curFeature.getFullVirtualPath().startsWith(feature.getFullVirtualPath())) {
QString curResultName = curFeature.getFullVirtualPath();
if (!parentVirtualPath.endsWith("/")) {
parentVirtualPath.append("/");
}
//Cut virtual path prevfix
int i = curResultName.indexOf(feature.getFullVirtualPath());
if (i != -1) {
curResultName = curResultName.right(curFeature.getFullVirtualPath().count() - i - parentVirtualPath.count());
}
//if directory has children, emptying the name;
i = curResultName.indexOf("/");
if (i != -1) {
curResultName = "";
}
if (!curResultName.isEmpty()) {
resultList.append(curResultName);
}
qDebug() << curResultName;
}
}
if (!resultList.contains(pName + pExtention, Qt::CaseInsensitive)) {
resultName = pName + pExtention;
} else {
for (int i = 0; i < 16777215; i++) {
QString probeName = pName + "_" + QString::number(i) + pExtention;
if (!resultList.contains(probeName, Qt::CaseInsensitive)) {
resultName = probeName;
break;
}
}
}
qDebug() << "result name is " << resultName;
return resultName;
}
QString UBFeaturesController::adjustName(const QString &str)
{
if (str.isNull()) {
return QString();
}
QString resultStr = str;
QRegExp invalidSymbols("[\\/\\s\\:\\?\\*\\|\\<\\>\\\"]+");
return resultStr.replace(invalidSymbols, "_");
}
void UBFeaturesController::addToFavorite( const QUrl &path )
{
QString filePath = fileNameFromUrl( path );
@ -660,7 +725,6 @@ void UBFeaturesController::importImage( const QImage &image, const UBFeature &de
}
if ( !destination.getFullVirtualPath().startsWith( picturesElement.getFullVirtualPath(), Qt::CaseInsensitive ) )
{
dest = picturesElement;
@ -730,16 +794,20 @@ void UBFeaturesController::addItemAsBackground(const UBFeature &item)
UBFeature UBFeaturesController::getDestinationFeatureForUrl( const QUrl &url )
{
QString mimetype = UBFileSystemUtils::mimeTypeFromFileName( url.toString() );
return getDestinationFeatureForMimeType(mimetype);
}
if ( mimetype.contains("audio") )
UBFeature UBFeaturesController::getDestinationFeatureForMimeType(const QString &pMmimeType)
{
if ( pMmimeType.contains("audio") )
return audiosElement;
if ( mimetype.contains("video") )
if ( pMmimeType.contains("video") )
return moviesElement;
else if ( mimetype.contains("image") || mimetype.isEmpty())
else if ( pMmimeType.contains("image") || pMmimeType.isEmpty())
return picturesElement;
else if ( mimetype.contains("application") )
{
if ( mimetype.contains( "x-shockwave-flash") )
else if ( pMmimeType.contains("application") )
{
if ( pMmimeType.contains( "x-shockwave-flash") )
return flashElement;
else
return interactElement;
@ -747,48 +815,51 @@ UBFeature UBFeaturesController::getDestinationFeatureForUrl( const QUrl &url )
return UBFeature();
}
void UBFeaturesController::addDownloadedFile(const QUrl &sourceUrl, const QByteArray &pData)
void UBFeaturesController::addDownloadedFile(const QUrl &sourceUrl, const QByteArray &pData, const QString pContentSource, const QString pTitle)
{
UBFeature dest = getDestinationFeatureForUrl(sourceUrl);
UBFeature dest = getDestinationFeatureForMimeType(pContentSource);
//TODO:claudio check this
if (dest == UBFeature())
return;
QString fileName("");
QString filePath("");
QString fileName;
QString filePath;
if(UBFileSystemUtils::mimeTypeFromFileName( sourceUrl.toString() ).isEmpty()){
fileName = tr("ImportedImage") + "-" + QDateTime::currentDateTime().toString("dd-MM-yyyy hh-mm-ss")+ ".jpg";
filePath = dest.getFullPath().toLocalFile() + "/" + fileName;
QImage::fromData(pData).save(filePath);
//Audio item
if(dest == picturesElement) {
UBFeature downloadedFeature = UBFeature(dest.getFullVirtualPath() + "/" + fileName, getIcon( filePath, fileTypeFromUrl(filePath)),
fileName, QUrl::fromLocalFile(filePath), FEATURE_ITEM);
if (downloadedFeature != UBFeature()) {
featuresModel->addItem(downloadedFeature);
}
}
else{
fileName = QFileInfo( sourceUrl.toString() ).fileName();
filePath = dest.getFullPath().toLocalFile() + "/" + fileName;
QString UniqName = uniqNameForFeature(dest, adjustName(pTitle), ".jpg");
fileName = !UniqName.isNull()
? UniqName
: tr("ImportedImage") + "-" + QDateTime::currentDateTime().toString("dd-MM-yyyy hh-mm-ss")+ ".jpg";
QFile file( filePath );
if ( file.open(QIODevice::WriteOnly ))
{
file.write(pData);
file.close();
filePath = dest.getFullPath().toLocalFile() + "/" + fileName;
QImage::fromData(pData).save(filePath);
UBFeature downloadedFeature = UBFeature(dest.getFullVirtualPath() + "/" + fileName, getIcon( filePath, fileTypeFromUrl(filePath)),
fileName, QUrl::fromLocalFile(filePath), FEATURE_ITEM);
if (downloadedFeature != UBFeature()) {
featuresModel->addItem(downloadedFeature);
}
} else {
fileName = QFileInfo( sourceUrl.toString() ).fileName();
filePath = dest.getFullPath().toLocalFile() + "/" + fileName;
QFile file( filePath );
if ( file.open(QIODevice::WriteOnly ))
{
file.write(pData);
file.close();
UBFeature downloadedFeature = UBFeature(dest.getFullVirtualPath() + "/" + fileName, getIcon( filePath, fileTypeFromUrl(filePath)),
fileName, QUrl::fromLocalFile(filePath), FEATURE_ITEM);
if (downloadedFeature != UBFeature()) {
featuresModel->addItem(downloadedFeature);
}
}
}
}
}

@ -151,7 +151,7 @@ public:
void setCurrentElement( const UBFeature &elem ) {currentElement = elem;}
const UBFeature & getTrashElement () const { return trashElement; }
void addDownloadedFile( const QUrl &sourceUrl, const QByteArray &pData );
void addDownloadedFile( const QUrl &sourceUrl, const QByteArray &pData, const QString pContentSource, const QString pTitle );
UBFeature moveItemToFolder( const QUrl &url, const UBFeature &destination );
UBFeature copyItemToFolder( const QUrl &url, const UBFeature &destination );
@ -234,6 +234,8 @@ private:
//void addImageToCurrentPage( const QString &path );
void loadFavoriteList();
void saveFavoriteList();
QString uniqNameForFeature(const UBFeature &feature, const QString &pName = "Imported", const QString &pExtention = "") const;
QString adjustName(const QString &str);
QList <UBFeature> *featuresList;
@ -276,6 +278,7 @@ private:
public:
UBFeature trashElement;
UBFeature getDestinationFeatureForUrl( const QUrl &url );
UBFeature getDestinationFeatureForMimeType(const QString &pMmimeType);
};

@ -283,7 +283,7 @@ void UBDownloadManager::onDownloadFinished(int id, bool pSuccess, QUrl sourceUrl
}
else
{
emit addDownloadedFileToLibrary(pSuccess, sourceUrl, pContentTypeHeader, pData);
emit addDownloadedFileToLibrary(pSuccess, sourceUrl, pContentTypeHeader, pData, desc.name);
}
break;

@ -132,7 +132,7 @@ signals:
void downloadFinished(bool pSuccess, sDownloadFileDesc desc, QByteArray pData);
void downloadModalFinished();
void addDownloadedFileToBoard(bool pSuccess, QUrl sourceUrl, QUrl contentUrl, QString pContentTypeHeader, QByteArray pData, QPointF pPos, QSize pSize, bool isBackground);
void addDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData);
void addDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentTypeHeader, QByteArray pData, QString pTitle);
void cancelAllDownloads();
void allDownloadsFinished();

@ -67,8 +67,8 @@ UBFeaturesWidget::UBFeaturesWidget(QWidget *parent, const char *name)
connect(mActionBar, SIGNAL(rescanModel()), this, SLOT(rescanModel()));
connect(pathListView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(currentSelected(const QModelIndex &)));
connect(UBApplication::boardController, SIGNAL(displayMetadata(QMap<QString,QString>)), this, SLOT(onDisplayMetadata( QMap<QString,QString>)));
connect(UBDownloadManager::downloadManager(), SIGNAL( addDownloadedFileToLibrary( bool, QUrl, QString, QByteArray))
, this, SLOT(onAddDownloadedFileToLibrary(bool, QUrl, QString,QByteArray)));
connect(UBDownloadManager::downloadManager(), SIGNAL( addDownloadedFileToLibrary( bool, QUrl, QString, QByteArray, QString))
, this, SLOT(onAddDownloadedFileToLibrary(bool, QUrl, QString,QByteArray, QString)));
connect(centralWidget, SIGNAL(lockMainWidget(bool)), this, SLOT(lockIt(bool)));
connect(centralWidget, SIGNAL(createNewFolderSignal(QString)), controller, SLOT(addNewFolder(QString)));
connect(controller, SIGNAL(scanStarted()), centralWidget, SLOT(scanStarted()));
@ -299,12 +299,11 @@ void UBFeaturesWidget::onPreviewLoaded(int id, bool pSuccess, QUrl sourceUrl, QU
centralWidget->setPropertiesThumbnail(pix);
}
void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData)
void UBFeaturesWidget::onAddDownloadedFileToLibrary(bool pSuccess, QUrl sourceUrl, QString pContentHeader, QByteArray pData, QString pTitle)
{
Q_UNUSED(pContentHeader)
if (pSuccess) {
qDebug() << pData.length();
controller->addDownloadedFile(sourceUrl, pData);
controller->addDownloadedFile(sourceUrl, pData, pContentHeader, pTitle);
controller->refreshModels();
}
}
@ -1065,7 +1064,7 @@ void UBFeatureProperties::onAddToLib()
desc.isBackground = false;
desc.modal = false;
desc.dest = sDownloadFileDesc::library;
desc.name = QFileInfo( mpElement->getFullPath().toString()).fileName();
desc.name = mpElement->getMetadata().value("Title", QString());
qDebug() << desc.name;
desc.srcUrl = mpElement->getFullPath().toString();
qDebug() << desc.srcUrl;

@ -87,7 +87,7 @@ private slots:
void addToFavorite( const UBFeaturesMimeData *);
void removeFromFavorite( const UBFeaturesMimeData * );
void onDisplayMetadata( QMap<QString,QString> );
void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray);
void onAddDownloadedFileToLibrary(bool, QUrl, QString, QByteArray, QString pTitle);
void addElementsToFavorite();
void removeElementsFromFavorite();
void deleteSelectedElements();

Loading…
Cancel
Save