src/writely/WriterUI.cpp
/**
 * List file in given directory and return a list of QVariantMap for QML controls
 */
List file in given directory and return a list of QVariantMap for QML controls
List file in given directory and return a list of QVariantMap for QML controls
QVariantList WriterUI::listDirectory(QString path) {
    qDebug() << "WriterUI::listDirectory:path:" << path;
    QVariantList docList;
    QString destPath = QDir::homePath() + "/documents";
    if (path.length() > 0)
        destPath += path;
    QDir dir(destPath);
    if (!dir.exists())
        return docList;
    QDir::SortFlags flag = ( browserSortType() == "name") ? QDir::Name : QDir::Time;
    QFileInfoList infoList = dir.entryInfoList( QDir::NoFilter, QDir::DirsFirst | flag  | QDir::IgnoreCase );
    foreach (QFileInfo fileInfo, infoList) {
        if ( fileInfo.fileName() == "." || fileInfo.fileName() == ".." ) continue;
        if ( fileInfo.isDir() ) {
            QVariantMap entry;
            entry["type"] = "folder";
            loadFileInfo(entry, fileInfo);
            docList << entry;
            continue;
        }
        if (fileInfo.isFile() && fileInfo.suffix().toLower() == "txt") {
            QVariantMap entry;
            entry["type"] = "file";
            loadFileInfo(entry, fileInfo);
            docList << entry;
            continue;
        }
    }
    return docList;
}
QVariantList WriterUI :: listDirectory ( QString path ) { qDebug ( ) << " " << path ; QVariantList docList ; QString destPath = QDir :: homePath ( ) + " " ; if ( path . length ( ) > 0 ) destPath += path ; QDir dir ( destPath ) ; if ( ! dir . exists ( ) ) return docList ; QDir :: SortFlags flag = ( browserSortType ( ) == " " ) ? QDir :: Name : QDir :: Time ; QFileInfoList infoList = dir . entryInfoList ( QDir :: NoFilter , QDir :: DirsFirst | flag | QDir :: IgnoreCase ) ; foreach ( QFileInfo fileInfo , infoList ) { if ( fileInfo . fileName ( ) == " " || fileInfo . fileName ( ) == " " ) continue ; if ( fileInfo . isDir ( ) ) { QVariantMap entry ; entry [ " " ] = " " ; loadFileInfo ( entry , fileInfo ) ; docList << entry ; continue ; } if ( fileInfo . isFile ( ) && fileInfo . suffix ( ) . toLower ( ) == " " ) { QVariantMap entry ; entry [ " " ] = " " ; loadFileInfo ( entry , fileInfo ) ; docList << entry ; continue ; } } return docList ; }
List file in given directory and return a list of QVariantMap for QML controls
List file in given directory and return a list of QVariantMap for QML controls
//        qDebug() << "entry:name" << fileInfo.fileName() << "path:" << fileInfo.filePath() << "isDir:" << fileInfo.isDir() << "isFile:" << fileInfo.isFile();