diff --git a/persistancelayer.cpp b/persistancelayer.cpp index 226eba46c2b431ced3788f4ccb75550e17902e70..822d3e27a0490ae38d7ee47e5f845c3b3a4cdafb 100755 --- a/persistancelayer.cpp +++ b/persistancelayer.cpp @@ -491,263 +491,6 @@ void PersistanceLayer::setUserData( const QString &pUser, const QString &pPass ) } } -QString PersistanceLayer::addFileToTemp( const QString &pUrl, const QString &pPath ) -{ - QFile file( pPath ); - QStringList urlSegments = pUrl.split( '/' ); - QString folder; - - if ( urlSegments.length() ) { - folder = urlSegments.at( urlSegments.length() - 2 ); - } else { - folder = pUrl; - } - - QString newFilePath = QStandardPaths::writableLocation( QStandardPaths::TempLocation ); - - newFilePath += '/' + folder; - createFolder( newFilePath ); - - if ( !newFilePath.length() ) { - newFilePath = pPath; - } else { - QDir folderPath( newFilePath ); - - if ( !folderPath.exists() ) { - if ( !folderPath.mkpath( newFilePath ) ) { - qWarning() << "failed creating folder: " << newFilePath; - } - } - - newFilePath += '/' + pPath.split( '/' ).last(); - qDebug() << "old path: " << pPath; - qDebug() << "new path: " << newFilePath; - - if ( pPath != newFilePath ) { - QFile destFile( newFilePath ); - - if ( destFile.exists() ) { - qDebug() << "file already exists: " << newFilePath << "deleting"; - - if ( !destFile.remove() ) { - qWarning() << destFile.errorString(); - } - } - - if ( !file.rename( newFilePath ) ) { - qWarning() << file.errorString(); - } else { - //QFile fileOrig( path ); - - // if ( fileOrig.exists() ) { - // if ( !fileOrig.remove() ) { - // qWarning() << fileOrig.errorString(); - // } - // } - addFileCacheEntry( pUrl, newFilePath ); - return newFilePath; - } - } - } - - addFileCacheEntry( pUrl, pPath ); - return newFilePath; -} - -QString PersistanceLayer::addFileToDocuments( const QString &pUrl, const QString &pPath ) -{ - QFile file( pPath ); - QString newFilePath = QStandardPaths::writableLocation( QStandardPaths::DocumentsLocation ); - - if ( !newFilePath.length() ) { - newFilePath = pPath; - } else { - QString realname = file.fileName().split( "/" ).last(); - QDir dbPath( newFilePath ); - - if ( !dbPath.exists() ) { - if ( !dbPath.mkpath( newFilePath ) ) { - qWarning() << "failed to create folder: " << newFilePath; - } - } - - newFilePath += +"/" + realname; - QFile destFile( newFilePath ); - - if ( destFile.exists() ) { - if ( !destFile.remove() ) { - qWarning() << destFile.errorString(); - } - } - - if ( !file.rename( newFilePath ) ) { - qWarning() << file.errorString(); - } else { - QFile fileOrig( pPath ); - - // if ( fileOrig.exists() ) { - // if ( !fileOrig.remove() ) { - // qWarning() << fileOrig.errorString(); - // } - // } - addFileCacheEntry( pUrl, newFilePath ); - return newFilePath; - - } - - } - - return newFilePath; -} - -QString PersistanceLayer::addFileToMusics( const QString &pUrl, const QString &pPath ) -{ - QFile file( pPath ); - QString newFilePath = QStandardPaths::writableLocation( QStandardPaths::MusicLocation ); - - if ( !newFilePath.length() ) { - newFilePath = pPath; - } else { - QString realname = file.fileName().split( "/" ).last(); - QDir dbPath( newFilePath ); - - if ( !dbPath.exists() ) { - if ( !dbPath.mkdir( newFilePath ) ) { - qWarning() << "failed to create folder: " << newFilePath; - } - } - - newFilePath += +'/' + realname; - QFile destFile( newFilePath ); - - if ( destFile.exists() ) { - if ( !destFile.remove() ) { - qWarning() << destFile.errorString(); - } - } - - if ( !file.rename( newFilePath ) ) { - qWarning() << file.errorString(); - } else { - QFile fileOrig( pPath ); - - // if ( fileOrig.exists() ) { - // if ( !fileOrig.remove() ) { - // qWarning() << fileOrig.errorString(); - // } - // } - addFileCacheEntry( pUrl, newFilePath ); - return newFilePath; - - } - - } - - return newFilePath; -} - -QString PersistanceLayer::addFileToVideos( const QString &pUrl, const QString &pPath ) -{ - QFile file( pPath ); - QString newFilePath = QStandardPaths::writableLocation( QStandardPaths::MoviesLocation ); - - if ( !newFilePath.length() ) { - newFilePath = pPath; - } else { - QString realname = file.fileName().split( '/' ).last(); - QDir dbPath( newFilePath ); - - if ( !dbPath.exists() ) { - if ( !dbPath.mkdir( newFilePath ) ) { - qWarning() << "failed to create folder: " << newFilePath; - } - } - - newFilePath += +'/' + realname; - - QFile destFile( newFilePath ); - - if ( destFile.exists() ) { - if ( !destFile.remove() ) { - qWarning() << destFile.errorString(); - } - } - - if ( !file.rename( newFilePath ) ) { - qWarning() << file.errorString(); - } else { - QFile fileOrig( pPath ); - - // if ( fileOrig.exists() ) { - // if ( !fileOrig.remove() ) { - // qWarning() << fileOrig.errorString(); - // } - // } - addFileCacheEntry( pUrl, newFilePath ); - return newFilePath; - - } - - } - - return newFilePath; -} - -QString PersistanceLayer::addFileToImages( const QString &pUrl, const QString &pPath ) -{ - QFile file( pPath ); - QString newFilePath = QStandardPaths::writableLocation( QStandardPaths::PicturesLocation ); - - if ( !newFilePath.length() ) { - newFilePath = pPath; - } else { - QString realname = file.fileName().split( "/" ).last(); - QDir dbPath( newFilePath ); - - if ( !dbPath.exists() ) { - if ( !dbPath.mkdir( newFilePath ) ) { - qWarning() << "failed to create folder: " << newFilePath; - } - } - - newFilePath += +'/' + realname; - QFile destFile( newFilePath ); - - if ( destFile.exists() ) { - if ( !destFile.remove() ) { - qWarning() << destFile.errorString(); - } - } - - if ( !file.rename( newFilePath ) ) { - qWarning() << file.errorString(); - } else { - QFile fileOrig( pPath ); - - // if ( fileOrig.exists() ) { - // if ( !fileOrig.remove() ) { - // qWarning() << fileOrig.errorString(); - // } - // } - addFileCacheEntry( pUrl, newFilePath ); - return newFilePath; - - } - - } - - return newFilePath; -} - -void PersistanceLayer::createFolder( const QString &pPath ) -{ - QDir temp; - - if ( !temp.mkpath( pPath ) ) { - qWarning() << "failed to create folder: " << pPath; - } -} - void PersistanceLayer::setUserId( const QString &pUserId ) { QSqlQuery querySetUserId; diff --git a/persistancelayer.h b/persistancelayer.h index b197bc82d38448129aa4aff357c93914d85e0587..693955377521a1254a9e2d648e088c2bdc7a128d 100755 --- a/persistancelayer.h +++ b/persistancelayer.h @@ -53,12 +53,6 @@ class PersistanceLayer : public QObject public: - QString addFileToTemp( const QString &pUrl, const QString &pPath ); - QString addFileToDocuments( const QString &pUrl, const QString &pPath ); - QString addFileToMusics( const QString &pUrl, const QString &pPath ); - QString addFileToVideos( const QString &pUrl, const QString &pPath ); - QString addFileToImages( const QString &pUrl, const QString &pPath ); - void createFolder( const QString &pPath ); void setUserId( const QString & ); QString getUserName();