Changeset 613 for trunk/src/corelib/io


Ignore:
Timestamp:
Feb 27, 2010, 12:25:29 AM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib/gui: Add support for watching drive list changes (represented by the empty or null string) to the polling file system watcher and use this feature in QFileDialog to get instant drive change notifications in "My Computer".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/io/qfilesystemwatcher.cpp

    r602 r613  
    6969QT_BEGIN_NAMESPACE
    7070
     71
     72
     73
     74
    7175class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine
    7276{
     
    113117    mutable QMutex mutex;
    114118    QHash<QString, FileInfo> files, directories;
     119
     120
     121
    115122
    116123public:
     
    162169            QHash<QString, FileInfo>::iterator x = dit.next();
    163170            QString path = x.key();
    164             QFileInfo fi(path);
    165             if (!path.endsWith(QLatin1Char('/')))
    166                 fi = QFileInfo(path + QLatin1Char('/'));
    167             if (!fi.exists()) {
    168                 dit.remove();
    169                 emit directoryChanged(path, true);
    170             } else if (x.value() != fi) {
    171                 x.value() = fi;
    172                 emit directoryChanged(path, false);
     171#if defined(Q_OS_OS2)
     172            if (path.isEmpty()) {
     173                // check if we got new/changed drives
     174                QFileInfoList newDrives = QDir::drives();
     175                if (drives != QDir::drives()) {
     176                    drives = newDrives;
     177                    emit directoryChanged(QString::null, false);
     178                }
     179            } else
     180#endif
     181            {
     182                QFileInfo fi(path);
     183                if (!path.endsWith(QLatin1Char('/')))
     184                    fi = QFileInfo(path + QLatin1Char('/'));
     185                if (!fi.exists()) {
     186                    dit.remove();
     187                    emit directoryChanged(path, true);
     188                } else if (x.value() != fi) {
     189                    x.value() = fi;
     190                    emit directoryChanged(path, false);
     191                }
    173192            }
    174193            yieldCurrentThread();
     
    195214    while (it.hasNext()) {
    196215        QString path = it.next();
    197         QFileInfo fi(path);
    198         if (!fi.exists())
    199             continue;
    200         if (fi.isDir()) {
    201             if (!directories->contains(path))
    202                 directories->append(path);
    203             if (!path.endsWith(QLatin1Char('/')))
    204                 fi = QFileInfo(path + QLatin1Char('/'));
    205             this->directories.insert(path, fi);
     216#if defined(Q_OS_OS2)
     217        if (path.isEmpty()) {
     218            // asked to watch for drives
     219            if (!directories->contains(DRIVES_ROOT))
     220                directories->append(DRIVES_ROOT);
     221            this->directories.insert(DRIVES_ROOT, QFileInfo());
    206222            startOver = true;
    207         } else {
    208             if (!files->contains(path))
    209                 files->append(path);
    210             this->files.insert(path, fi);
    211             startOver = true;
     223        } else
     224#endif
     225        {
     226            QFileInfo fi(path);
     227            if (!fi.exists())
     228                continue;
     229            if (fi.isDir()) {
     230                if (!directories->contains(path))
     231                    directories->append(path);
     232                if (!path.endsWith(QLatin1Char('/')))
     233                    fi = QFileInfo(path + QLatin1Char('/'));
     234                this->directories.insert(path, fi);
     235                startOver = true;
     236            } else {
     237                if (!files->contains(path))
     238                    files->append(path);
     239                this->files.insert(path, fi);
     240                startOver = true;
     241            }
    212242        }
    213243        it.remove();
     
    226256    while (it.hasNext()) {
    227257        QString path = it.next();
     258
     259
     260
     261
     262
     263
     264
     265
     266
     267
    228268        if (this->directories.remove(path)) {
    229269            directories->removeAll(path);
     
    485525void QFileSystemWatcher::addPath(const QString &path)
    486526{
     527
    487528    if (path.isEmpty()) {
    488529        qWarning("QFileSystemWatcher::addPath: path is empty");
    489530        return;
    490531    }
     532
    491533    addPaths(QStringList(path));
    492534}
Note: See TracChangeset for help on using the changeset viewer.