QFileInfoGatherer: general cleanups
authorMarc Mutz <marc.mutz@kdab.com>
Tue, 7 Aug 2012 17:45:16 +0000 (19:45 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Mon, 24 Sep 2012 22:08:16 +0000 (00:08 +0200)
- fix typo in comment
- make translateDriveName file-static
- use QList::reserve()
- explicit ctor
- annotate functions called by owning thread/run()
- iconProvider() and resolveSymlinks() shouldn't be slots
- private instead of protected
- run() marked Q_DECL_OVERRIDE
- annotate which members are protected by 'mutex'

Change-Id: Ic176a030b0597c98f48185efd17260fd62532460
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
src/widgets/dialogs/qfileinfogatherer.cpp
src/widgets/dialogs/qfileinfogatherer_p.h

index d1718bb..22a7d50 100644 (file)
@@ -129,7 +129,7 @@ QFileIconProvider *QFileInfoGatherer::iconProvider() const
 void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStringList &files)
 {
     QMutexLocker locker(&mutex);
-    // See if we already have this dir/file in our que
+    // See if we already have this dir/file in our queue
     int loc = this->path.lastIndexOf(path);
     while (loc > 0)  {
         if (this->files.at(loc) == files) {
@@ -243,7 +243,7 @@ QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const
     return info;
 }
 
-QString QFileInfoGatherer::translateDriveName(const QFileInfo &drive) const
+static QString translateDriveName(const QFileInfo &drive)
 {
     QString driveName = drive.absoluteFilePath();
 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
@@ -280,6 +280,7 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil
         if (files.isEmpty()) {
             infoList = QDir::drives();
         } else {
+            infoList.reserve(files.count());
             for (int i = 0; i < files.count(); ++i)
                 infoList << QFileInfo(files.at(i));
         }
index e3bfb06..9837b1a 100644 (file)
@@ -157,36 +157,37 @@ Q_SIGNALS:
     void directoryLoaded(const QString &path);
 
 public:
-    QFileInfoGatherer(QObject *parent = 0);
+    explicit QFileInfoGatherer(QObject *parent = 0);
     ~QFileInfoGatherer();
 
+    // only callable from this->thread():
     void clear();
     void removePath(const QString &path);
     QExtendedInformation getInfo(const QFileInfo &info) const;
+    QFileIconProvider *iconProvider() const;
+    bool resolveSymlinks() const;
 
 public Q_SLOTS:
     void list(const QString &directoryPath);
     void fetchExtendedInformation(const QString &path, const QStringList &files);
     void updateFile(const QString &path);
     void setResolveSymlinks(bool enable);
-    bool resolveSymlinks() const;
     void setIconProvider(QFileIconProvider *provider);
-    QFileIconProvider *iconProvider() const;
-
-protected:
-    void run();
-    void getFileInfos(const QString &path, const QStringList &files);
 
 private:
+    void run() Q_DECL_OVERRIDE;
+    // called by run():
+    void getFileInfos(const QString &path, const QStringList &files);
     void fetch(const QFileInfo &info, QElapsedTimer &base, bool &firstTime, QList<QPair<QString, QFileInfo> > &updatedFiles, const QString &path);
-    QString translateDriveName(const QFileInfo &drive) const;
 
+private:
     mutable QMutex mutex;
+    // begin protected by mutex
     QWaitCondition condition;
-    QAtomicInt abort;
-
     QStack<QString> path;
     QStack<QStringList> files;
+    // end protected by mutex
+    QAtomicInt abort;
 
 #ifndef QT_NO_FILESYSTEMWATCHER
     QFileSystemWatcher *watcher;