src/writely/WriterUI.cpp
/**
 * Rename an folder and return the folder info.
 * An empty QVariant is returned if there's an error
 */
Rename an folder and return the folder info.
An empty QVariant is returned if there's an error
Rename an folder and return the folder info . An empty QVariant is returned if there ' s an error
QVariantMap WriterUI::renameFolder( QString relativeFolderPath, QString newName ) {
    QString destPath = documentsFolderPath() + relativeFolderPath;
    qDebug() << "WriterUI::renameFolder" << destPath << " -> " << newName;
    QFileInfo folderInfo(destPath);
    QDir folder(destPath);
    if (!folder.exists()) return QVariantMap();
    QDir parentFolder(destPath);
    parentFolder.cdUp();
    qDebug() << "parentFolder" << parentFolder.path();
    int counter = 0;
    while (true) {
        QString folderName = genFolderPath(parentFolder.path(), counter, newName);
        QDir newFolder(folderName);
        if (!newFolder.exists())
            break;
        counter ++;
    }
    QString newFolderName = genFolderPath(parentFolder.path(), counter, newName);
    if ( !folder.rename( destPath, newFolderName ) )
        return QVariantMap();
    QFileInfo info(newFolderName);
    if ( !info.exists() )
        return QVariantMap();
    QVariantMap entry;
    entry["type"] = "folder";
    entry["relativePath"] = relativePath( info.filePath() );
    loadFileInfo( entry, info );
    qDebug() << "WriterUI::renameFolder:reesult:" << entry;
    return entry;
}
QVariantMap WriterUI :: renameFolder ( QString relativeFolderPath , QString newName ) { QString destPath = documentsFolderPath ( ) + relativeFolderPath ; qDebug ( ) << " " << destPath << " " << newName ; QFileInfo folderInfo ( destPath ) ; QDir folder ( destPath ) ; if ( ! folder . exists ( ) ) return QVariantMap ( ) ; QDir parentFolder ( destPath ) ; parentFolder . cdUp ( ) ; qDebug ( ) << " " << parentFolder . path ( ) ; int counter = 0 ; while ( true ) { QString folderName = genFolderPath ( parentFolder . path ( ) , counter , newName ) ; QDir newFolder ( folderName ) ; if ( ! newFolder . exists ( ) ) break ; counter ++ ; } QString newFolderName = genFolderPath ( parentFolder . path ( ) , counter , newName ) ; if ( ! folder . rename ( destPath , newFolderName ) ) return QVariantMap ( ) ; QFileInfo info ( newFolderName ) ; if ( ! info . exists ( ) ) return QVariantMap ( ) ; QVariantMap entry ; entry [ " " ] = " " ; entry [ " " ] = relativePath ( info . filePath ( ) ) ; loadFileInfo ( entry , info ) ; qDebug ( ) << " " << entry ; return entry ; }
Rename an folder and return the folder info.
Rename an folder and return the folder info .