src/writely/WriterUI.cpp
/**
 * Create an empty file and return the new path.
 * @param    documentPath    The relative path from the documentRoot. Must start with "/"
 * @return   empty map if the new document couldn't be created in the specified path
 */
Create an empty file and return the new path.
@param    documentPath    The relative path from the documentRoot. Must start with "/"
@return   empty map if the new document couldn't be created in the specified path
Create an empty file and return the new path . @param documentPath The relative path from the documentRoot . Must start with " / " @return empty map if the new document couldn ' t be created in the specified path
QVariantMap WriterUI::createEmptyFile( QString documentPath ) {
    if (documentPath.size() > 0 && !documentPath.startsWith("/"))
            documentPath = "/" + documentPath;
    QString destPath = QDir::homePath() + "/documents" + documentPath;
    qDebug() << "WriterUI::createEmptyFile:path" << documentPath << "fullPath" << destPath;
    QDir dir(destPath);
    if (!dir.exists()) return QVariantMap();
    int counter = 0;
    while (true) {
        QString fileName = untitledFilePath(destPath, counter);
        QFile file(fileName);
        if (!file.exists())
            break;
        counter ++;
    }
    QString newFileName = untitledFilePath(destPath, counter);
    QFile newFile( newFileName );
    if ( !newFile.open(QIODevice::WriteOnly) )
        return QVariantMap();
    newFile.close();
    QFileInfo fileInfo( newFile );
    QVariantMap entry;
    entry["type"] = "file";
    loadFileInfo( entry, fileInfo );
    return entry;
}
QVariantMap WriterUI :: createEmptyFile ( QString documentPath ) { if ( documentPath . size ( ) > 0 && ! documentPath . startsWith ( " " ) ) documentPath = " " + documentPath ; QString destPath = QDir :: homePath ( ) + " " + documentPath ; qDebug ( ) << " " << documentPath << " " << destPath ; QDir dir ( destPath ) ; if ( ! dir . exists ( ) ) return QVariantMap ( ) ; int counter = 0 ; while ( true ) { QString fileName = untitledFilePath ( destPath , counter ) ; QFile file ( fileName ) ; if ( ! file . exists ( ) ) break ; counter ++ ; } QString newFileName = untitledFilePath ( destPath , counter ) ; QFile newFile ( newFileName ) ; if ( ! newFile . open ( QIODevice :: WriteOnly ) ) return QVariantMap ( ) ; newFile . close ( ) ; QFileInfo fileInfo ( newFile ) ; QVariantMap entry ; entry [ " " ] = " " ; loadFileInfo ( entry , fileInfo ) ; return entry ; }
Create an empty file and return the new path.
Create an empty file and return the new path .