QString Playlist::convertPath(QString filename){ QString filepath; QUrl url(filename); filepath = url.toLocalFile(); QDir file; filepath = file.toNativeSeparators(filepath); return filepath; }
QString MediaStorageDlg::getFolder() { QFileDialog dlg(this); dlg.setFileMode(QFileDialog::DirectoryOnly); if(!dlg.exec()) return QString(); QDir dir = dlg.directory(); return dir.toNativeSeparators(dir.absolutePath()); }
// Move image to a project path "img" // @input: // - QString - unempty full image file path // @output: // - empty QString - can't move image // - same QString - image is already in project folder // - new unempty QString - copied image path QString ImgFilesService::MoveImageToProject(const QString &t_imgPath) { if ( true == t_imgPath.isEmpty() ) { qDebug() << "MoveImageToProject(): Error - invalid arguments"; QString empty; return empty; } if ( false == CheckImgExist(t_imgPath) ) { qDebug() << "MoveImageToProject(): Error - nothing to move"; QString empty; return empty; } // Images have to be stored in directory PROJECT_IMG_PATH QDir directory; QString pathToImgDir = directory.currentPath(); pathToImgDir.append(PROJECT_IMG_PATH); pathToImgDir = directory.toNativeSeparators(pathToImgDir); directory.mkpath(pathToImgDir); QString imgToMove; imgToMove = directory.toNativeSeparators(t_imgPath); // We should check if user choosed image from PROJECT_IMG_PATH if ( true == imgToMove.startsWith(pathToImgDir) ) { qDebug() << "File" << imgToMove << "is already in project"; return t_imgPath; } QFileInfo imgCopyInfo(imgToMove); QString imgCopyPath; for (int i = 0; imgCopyInfo.exists(); i++) { imgCopyInfo.setFile(imgToMove); imgCopyPath = pathToImgDir + imgCopyInfo.baseName(); if ( 0 == i ) { imgCopyPath += QString(".%1").arg(imgCopyInfo.completeSuffix()); } else { imgCopyPath += QString("_%1.%2").arg(i).arg(imgCopyInfo.completeSuffix()); } imgCopyInfo.setFile(imgCopyPath); } bool fileCopiedSuccessfully = QFile::copy(imgToMove, imgCopyPath); if ( false == fileCopiedSuccessfully ) { qDebug() << "MoveImgToProjectPath(): error - cant copy file" << imgToMove; QString empty; return empty; } return imgCopyPath; }