| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/widgets/dialogs/qfileinfogatherer.cpp | 
| Switch to Source code | Preprocessed file | 
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | static QBasicAtomicInt fetchedRoot = { false }; | - | ||||||||||||||||||
| 7 | __attribute__((visibility("default"))) void qt_test_resetFetchedRoot() | - | ||||||||||||||||||
| 8 | { | - | ||||||||||||||||||
| 9 | fetchedRoot.store(false); | - | ||||||||||||||||||
| 10 | } never executed:  end of block | 0 | ||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | __attribute__((visibility("default"))) bool qt_test_isFetchedRoot() | - | ||||||||||||||||||
| 13 | { | - | ||||||||||||||||||
| 14 |     return never executed:   fetchedRoot.load();return fetchedRoot.load();never executed:  return fetchedRoot.load(); | 0 | ||||||||||||||||||
| 15 | } | - | ||||||||||||||||||
| 16 | - | |||||||||||||||||||
| 17 | - | |||||||||||||||||||
| 18 | - | |||||||||||||||||||
| 19 | - | |||||||||||||||||||
| 20 | - | |||||||||||||||||||
| 21 | QFileInfoGatherer::QFileInfoGatherer(QObject *parent) | - | ||||||||||||||||||
| 22 | : QThread(parent), abort(false), | - | ||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | watcher(0), | - | ||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | - | |||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | - | |||||||||||||||||||
| 29 | m_iconProvider(&defaultProvider) | - | ||||||||||||||||||
| 30 | { | - | ||||||||||||||||||
| 31 | - | |||||||||||||||||||
| 32 | watcher = new QFileSystemWatcher(this); | - | ||||||||||||||||||
| 33 | connect(watcher, qFlagLocation("2""directoryChanged(QString)" "\0" __FILE__ ":" "77"), this, qFlagLocation("1""list(QString)" "\0" __FILE__ ":" "77")); | - | ||||||||||||||||||
| 34 | connect(watcher, qFlagLocation("2""fileChanged(QString)" "\0" __FILE__ ":" "78"), this, qFlagLocation("1""updateFile(QString)" "\0" __FILE__ ":" "78")); | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | start(LowPriority); | - | ||||||||||||||||||
| 37 | } never executed:  end of block | 0 | ||||||||||||||||||
| 38 | - | |||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | - | |||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | QFileInfoGatherer::~QFileInfoGatherer() | - | ||||||||||||||||||
| 43 | { | - | ||||||||||||||||||
| 44 | abort.store(true); | - | ||||||||||||||||||
| 45 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
| 46 | condition.wakeAll(); | - | ||||||||||||||||||
| 47 | locker.unlock(); | - | ||||||||||||||||||
| 48 | wait(); | - | ||||||||||||||||||
| 49 | } never executed:  end of block | 0 | ||||||||||||||||||
| 50 | - | |||||||||||||||||||
| 51 | void QFileInfoGatherer::setResolveSymlinks(bool enable) | - | ||||||||||||||||||
| 52 | { | - | ||||||||||||||||||
| 53 | (void)enable;; | - | ||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | - | |||||||||||||||||||
| 57 | } never executed:  end of block | 0 | ||||||||||||||||||
| 58 | - | |||||||||||||||||||
| 59 | bool QFileInfoGatherer::resolveSymlinks() const | - | ||||||||||||||||||
| 60 | { | - | ||||||||||||||||||
| 61 | - | |||||||||||||||||||
| 62 | - | |||||||||||||||||||
| 63 | - | |||||||||||||||||||
| 64 |     return never executed:   false;return false;never executed:  return false; | 0 | ||||||||||||||||||
| 65 | - | |||||||||||||||||||
| 66 | } | - | ||||||||||||||||||
| 67 | - | |||||||||||||||||||
| 68 | void QFileInfoGatherer::setIconProvider(QFileIconProvider *provider) | - | ||||||||||||||||||
| 69 | { | - | ||||||||||||||||||
| 70 | m_iconProvider = provider; | - | ||||||||||||||||||
| 71 | } never executed:  end of block | 0 | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | QFileIconProvider *QFileInfoGatherer::iconProvider() const | - | ||||||||||||||||||
| 74 | { | - | ||||||||||||||||||
| 75 |     return never executed:   m_iconProvider;return m_iconProvider;never executed:  return m_iconProvider; | 0 | ||||||||||||||||||
| 76 | } | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | - | |||||||||||||||||||
| 79 | - | |||||||||||||||||||
| 80 | - | |||||||||||||||||||
| 81 | - | |||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStringList &files) | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
| 86 | - | |||||||||||||||||||
| 87 | int loc = this->path.lastIndexOf(path); | - | ||||||||||||||||||
| 88 |     while (loc > 0
  | 0 | ||||||||||||||||||
| 89 |         if (this->files.at(loc) == files
  | 0 | ||||||||||||||||||
| 90 |             return; never executed:  return; | 0 | ||||||||||||||||||
| 91 | } | - | ||||||||||||||||||
| 92 | loc = this->path.lastIndexOf(path, loc - 1); | - | ||||||||||||||||||
| 93 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 94 | this->path.push(path); | - | ||||||||||||||||||
| 95 | this->files.push(files); | - | ||||||||||||||||||
| 96 | condition.wakeAll(); | - | ||||||||||||||||||
| 97 | - | |||||||||||||||||||
| 98 | - | |||||||||||||||||||
| 99 |     if (files.isEmpty()
  | 0 | ||||||||||||||||||
| 100 |         && !path.isEmpty()
  | 0 | ||||||||||||||||||
| 101 |         && !path.startsWith(QLatin1String("//"))
  | 0 | ||||||||||||||||||
| 102 |         if (!watcher->directories().contains(path)
  | 0 | ||||||||||||||||||
| 103 |             watcher->addPath(path); never executed:  watcher->addPath(path); | 0 | ||||||||||||||||||
| 104 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 105 | - | |||||||||||||||||||
| 106 | } never executed:  end of block | 0 | ||||||||||||||||||
| 107 | - | |||||||||||||||||||
| 108 | - | |||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | - | |||||||||||||||||||
| 111 | - | |||||||||||||||||||
| 112 | - | |||||||||||||||||||
| 113 | void QFileInfoGatherer::updateFile(const QString &filePath) | - | ||||||||||||||||||
| 114 | { | - | ||||||||||||||||||
| 115 | QString dir = filePath.mid(0, filePath.lastIndexOf(QDir::separator())); | - | ||||||||||||||||||
| 116 | QString fileName = filePath.mid(dir.length() + 1); | - | ||||||||||||||||||
| 117 | fetchExtendedInformation(dir, QStringList(fileName)); | - | ||||||||||||||||||
| 118 | } never executed:  end of block | 0 | ||||||||||||||||||
| 119 | - | |||||||||||||||||||
| 120 | - | |||||||||||||||||||
| 121 | - | |||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | - | |||||||||||||||||||
| 124 | - | |||||||||||||||||||
| 125 | void QFileInfoGatherer::clear() | - | ||||||||||||||||||
| 126 | { | - | ||||||||||||||||||
| 127 | - | |||||||||||||||||||
| 128 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
| 129 | watcher->removePaths(watcher->files()); | - | ||||||||||||||||||
| 130 | watcher->removePaths(watcher->directories()); | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | } never executed:  end of block | 0 | ||||||||||||||||||
| 133 | - | |||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | - | |||||||||||||||||||
| 136 | - | |||||||||||||||||||
| 137 | - | |||||||||||||||||||
| 138 | - | |||||||||||||||||||
| 139 | void QFileInfoGatherer::removePath(const QString &path) | - | ||||||||||||||||||
| 140 | { | - | ||||||||||||||||||
| 141 | - | |||||||||||||||||||
| 142 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
| 143 | watcher->removePath(path); | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | - | |||||||||||||||||||
| 146 | - | |||||||||||||||||||
| 147 | } never executed:  end of block | 0 | ||||||||||||||||||
| 148 | - | |||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | - | |||||||||||||||||||
| 152 | - | |||||||||||||||||||
| 153 | - | |||||||||||||||||||
| 154 | void QFileInfoGatherer::list(const QString &directoryPath) | - | ||||||||||||||||||
| 155 | { | - | ||||||||||||||||||
| 156 | fetchExtendedInformation(directoryPath, QStringList()); | - | ||||||||||||||||||
| 157 | } never executed:  end of block | 0 | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | - | |||||||||||||||||||
| 160 | - | |||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | void QFileInfoGatherer::run() | - | ||||||||||||||||||
| 163 | { | - | ||||||||||||||||||
| 164 | for(;;) { | - | ||||||||||||||||||
| 165 | QMutexLocker locker(&mutex); | - | ||||||||||||||||||
| 166 |         while (!abort.load()
 
  | 0 | ||||||||||||||||||
| 167 |             condition.wait(&mutex); never executed:  condition.wait(&mutex); | 0 | ||||||||||||||||||
| 168 |         if (abort.load()
  | 0 | ||||||||||||||||||
| 169 |             return; never executed:  return; | 0 | ||||||||||||||||||
| 170 | const QString thisPath = path.front(); | - | ||||||||||||||||||
| 171 | path.pop_front(); | - | ||||||||||||||||||
| 172 | const QStringList thisList = files.front(); | - | ||||||||||||||||||
| 173 | files.pop_front(); | - | ||||||||||||||||||
| 174 | locker.unlock(); | - | ||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | getFileInfos(thisPath, thisList); | - | ||||||||||||||||||
| 177 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 178 | } never executed:  end of block | 0 | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | QExtendedInformation QFileInfoGatherer::getInfo(const QFileInfo &fileInfo) const | - | ||||||||||||||||||
| 181 | { | - | ||||||||||||||||||
| 182 | QExtendedInformation info(fileInfo); | - | ||||||||||||||||||
| 183 | info.icon = m_iconProvider->icon(fileInfo); | - | ||||||||||||||||||
| 184 | info.displayType = m_iconProvider->type(fileInfo); | - | ||||||||||||||||||
| 185 |     return never executed:   info;return info;never executed:  return info; | 0 | ||||||||||||||||||
| 186 | } | - | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | static QString translateDriveName(const QFileInfo &drive) | - | ||||||||||||||||||
| 189 | { | - | ||||||||||||||||||
| 190 | QString driveName = drive.absoluteFilePath(); | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | - | |||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | - | |||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | - | |||||||||||||||||||
| 197 |     return never executed:   driveName;return driveName;never executed:  return driveName; | 0 | ||||||||||||||||||
| 198 | } | - | ||||||||||||||||||
| 199 | - | |||||||||||||||||||
| 200 | - | |||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &files) | - | ||||||||||||||||||
| 205 | { | - | ||||||||||||||||||
| 206 | - | |||||||||||||||||||
| 207 |     if (path.isEmpty()
  | 0 | ||||||||||||||||||
| 208 | - | |||||||||||||||||||
| 209 | fetchedRoot.store(true); | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | QFileInfoList infoList; | - | ||||||||||||||||||
| 212 |         if (files.isEmpty()
  | 0 | ||||||||||||||||||
| 213 | infoList = QDir::drives(); | - | ||||||||||||||||||
| 214 |         } never executed:   else {end of block | 0 | ||||||||||||||||||
| 215 | infoList.reserve(files.count()); | - | ||||||||||||||||||
| 216 |             for (int i = 0; i < files.count()
  | 0 | ||||||||||||||||||
| 217 |                 infoList << QFileInfo(files.at(i)); never executed:  infoList << QFileInfo(files.at(i)); | 0 | ||||||||||||||||||
| 218 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 219 |         for (int i = infoList.count() - 1; i >= 0
  | 0 | ||||||||||||||||||
| 220 | QString driveName = translateDriveName(infoList.at(i)); | - | ||||||||||||||||||
| 221 | QVector<QPair<QString,QFileInfo> > updatedFiles; | - | ||||||||||||||||||
| 222 | updatedFiles.append(QPair<QString,QFileInfo>(driveName, infoList.at(i))); | - | ||||||||||||||||||
| 223 | updates(path, updatedFiles); | - | ||||||||||||||||||
| 224 |         } never executed:  end of block | 0 | ||||||||||||||||||
| 225 |         return; never executed:  return; | 0 | ||||||||||||||||||
| 226 | } | - | ||||||||||||||||||
| 227 | - | |||||||||||||||||||
| 228 | QElapsedTimer base; | - | ||||||||||||||||||
| 229 | base.start(); | - | ||||||||||||||||||
| 230 | QFileInfo fileInfo; | - | ||||||||||||||||||
| 231 | bool firstTime = true; | - | ||||||||||||||||||
| 232 | QVector<QPair<QString, QFileInfo> > updatedFiles; | - | ||||||||||||||||||
| 233 | QStringList filesToCheck = files; | - | ||||||||||||||||||
| 234 | - | |||||||||||||||||||
| 235 | QString itPath = QDir::fromNativeSeparators(files.isEmpty() ? path : QLatin1String("")); | - | ||||||||||||||||||
| 236 | QDirIterator dirIt(itPath, QDir::AllEntries | QDir::System | QDir::Hidden); | - | ||||||||||||||||||
| 237 | QStringList allFiles; | - | ||||||||||||||||||
| 238 |     while (!abort.load()
 
  | 0 | ||||||||||||||||||
| 239 | dirIt.next(); | - | ||||||||||||||||||
| 240 | fileInfo = dirIt.fileInfo(); | - | ||||||||||||||||||
| 241 | allFiles.append(fileInfo.fileName()); | - | ||||||||||||||||||
| 242 | fetch(fileInfo, base, firstTime, updatedFiles, path); | - | ||||||||||||||||||
| 243 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 244 |     if (!allFiles.isEmpty()
  | 0 | ||||||||||||||||||
| 245 |         newListOfFiles(path, allFiles); never executed:  newListOfFiles(path, allFiles); | 0 | ||||||||||||||||||
| 246 | - | |||||||||||||||||||
| 247 | QStringList::const_iterator filesIt = filesToCheck.constBegin(); | - | ||||||||||||||||||
| 248 |     while (!abort.load()
 
  | 0 | ||||||||||||||||||
| 249 | fileInfo.setFile(path + QDir::separator() + *filesIt); | - | ||||||||||||||||||
| 250 | ++filesIt; | - | ||||||||||||||||||
| 251 | fetch(fileInfo, base, firstTime, updatedFiles, path); | - | ||||||||||||||||||
| 252 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 253 |     if (!updatedFiles.isEmpty()
  | 0 | ||||||||||||||||||
| 254 |         updates(path, updatedFiles); never executed:  updates(path, updatedFiles); | 0 | ||||||||||||||||||
| 255 | directoryLoaded(path); | - | ||||||||||||||||||
| 256 | } never executed:  end of block | 0 | ||||||||||||||||||
| 257 | - | |||||||||||||||||||
| 258 | void QFileInfoGatherer::fetch(const QFileInfo &fileInfo, QElapsedTimer &base, bool &firstTime, QVector<QPair<QString, QFileInfo> > &updatedFiles, const QString &path) { | - | ||||||||||||||||||
| 259 | updatedFiles.append(QPair<QString, QFileInfo>(fileInfo.fileName(), fileInfo)); | - | ||||||||||||||||||
| 260 | QElapsedTimer current; | - | ||||||||||||||||||
| 261 | current.start(); | - | ||||||||||||||||||
| 262 |     if ((firstTime
 
 
  | 0 | ||||||||||||||||||
| 263 | updates(path, updatedFiles); | - | ||||||||||||||||||
| 264 | updatedFiles.clear(); | - | ||||||||||||||||||
| 265 | base = current; | - | ||||||||||||||||||
| 266 | firstTime = false; | - | ||||||||||||||||||
| 267 |     } never executed:  end of block | 0 | ||||||||||||||||||
| 268 | } never executed:  end of block | 0 | ||||||||||||||||||
| 269 | - | |||||||||||||||||||
| 270 | - | |||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | - | |||||||||||||||||||
| 273 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |