Changeset 173


Ignore:
Timestamp:
Sep 9, 2009, 2:38:34 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

gui/dialogs: Fixed: Duplicate file names were added to the file list in QFileDialog when an existing directory was typed directly in the filename entry field with a different case of letters than in the original (on platforms with case insensitive file systems), #65.

Location:
trunk/src/gui/dialogs
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/dialogs/qfilesystemmodel.cpp

    r172 r173  
    353353        absolutePath = QDir(longPath).absolutePath();
    354354
    355     // ### TODO can we use bool QAbstractFileEngine::caseSensitive() const?
    356355    QStringList pathElements = absolutePath.split(QLatin1Char('/'), QString::SkipEmptyParts);
    357356    if ((pathElements.isEmpty())
     
    10891088
    10901089    QList<QPair<QFileSystemModelPrivate::QFileSystemNode*, int> > values;
    1091     QHash<QString, QFileSystemNode *>::const_iterator iterator;
     1090    QHash<FileNameKey, QFileSystemNode *>::const_iterator iterator;
    10921091    int i = 0;
    10931092    for(iterator = indexNode->children.begin() ; iterator != indexNode->children.end() ; ++iterator) {
     
    15881587    QStringList newFiles = files;
    15891588    qSort(newFiles.begin(), newFiles.end());
    1590     QHash<QString, QFileSystemNode*>::const_iterator i = parentNode->children.constBegin();
     1589    QHash<FileNameKey, QFileSystemNode*>::const_iterator i = parentNode->children.constBegin();
    15911590    while (i != parentNode->children.constEnd()) {
    15921591        QStringList::iterator iterator;
  • trunk/src/gui/dialogs/qfilesystemmodel_p.h

    r2 r173  
    8181
    8282public:
     83
     84#if defined(Q_OS_WIN) || defined(Q_OS_OS2)
     85    // On Windows and OS/2, file names are case insensitive so use a lowercased
     86    // string as a key in the hash map of name->node pairs. Note that strictly
     87    // speaking we should use QAbstractFileEngine::caseSensitive() to check if
     88    // the case should matter but on these platforms this method in QFSFileEngine
     89    // always returns false while doing this check would require to add a
     90    // QFileSystemNode* argument to the constructor and hence change almost every
     91    // line that uses the hash because the automatic QString->FileNameKey would
     92    // not work in this case. Note2: on Windows, evreything actually works without
     93    // this class but that's just because we use qt_GetLongPathName() which
     94    // always returns a real filename case and any changes in the case are
     95    // instantly picked up by QFileSystemWatcher anyway (otherwise we'd get dups
     96    // in the file ilst there too).
     97    class FileNameKey : public QString
     98    {
     99    public:
     100        FileNameKey(const QString &copy) : QString(copy.toLower()) {}
     101    };
     102#else
     103    typedef QString FileNameKey;
     104#endif
     105
    83106    class QFileSystemNode
    84107    {
     
    87110            : fileName(filename), populatedChildren(false), isVisible(false), parent(p), info(0) {}
    88111        ~QFileSystemNode() {
    89             QHash<QString, QFileSystemNode*>::const_iterator i = children.constBegin();
     112            QHash<FileNameKey, QFileSystemNode*>::const_iterator i = children.constBegin();
    90113            while (i != children.constEnd()) {
    91114                    delete i.value();
     
    162185            if (info)
    163186                info->icon = iconProvider->icon(QFileInfo(path));
    164             QHash<QString, QFileSystemNode *>::const_iterator iterator;
     187            QHash<FileNameKey, QFileSystemNode *>::const_iterator iterator;
    165188            for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) {
    166189                iterator.value()->updateIcon(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName);
     
    171194            if (info)
    172195                info->displayType = iconProvider->type(QFileInfo(path));
    173             QHash<QString, QFileSystemNode *>::const_iterator iterator;
     196            QHash<FileNameKey, QFileSystemNode *>::const_iterator iterator;
    174197            for(iterator = children.constBegin() ; iterator != children.constEnd() ; ++iterator) {
    175198                 iterator.value()->retranslateStrings(iconProvider, path + QLatin1Char('/') + iterator.value()->fileName);
     
    179202        bool populatedChildren;
    180203        bool isVisible;
    181         QHash<QString,QFileSystemNode *> children;
     204        QHash<FileNameKey, QFileSystemNode *> children;
    182205        QList<QString> visibleChildren;
    183206        QFileSystemNode *parent;
Note: See TracChangeset for help on using the changeset viewer.