Qt 4.8
Public Slots | Signals | Public Functions | Protected Functions | Private Functions | Properties | List of all members
QFileInfoGatherer Class Reference

#include <qfileinfogatherer_p.h>

Inheritance diagram for QFileInfoGatherer:
QThread QObject

Public Slots

void fetchExtendedInformation (const QString &path, const QStringList &files)
 Fetch extended information for all files in path. More...
 
QFileIconProvidericonProvider () const
 
void list (const QString &directoryPath)
 
bool resolveSymlinks () const
 
void setIconProvider (QFileIconProvider *provider)
 
void setResolveSymlinks (bool enable)
 
void updateFile (const QString &path)
 Fetch extended information for all filePath. More...
 
- Public Slots inherited from QThread
void quit ()
 Tells the thread's event loop to exit with return code 0 (success). More...
 
void start (Priority=InheritPriority)
 Begins execution of the thread by calling run(). More...
 
void terminate ()
 Terminates the execution of the thread. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 

Signals

void directoryLoaded (const QString &path)
 
void nameResolved (const QString &fileName, const QString &resolvedName) const
 
void newListOfFiles (const QString &directory, const QStringList &listOfFiles) const
 
void updates (const QString &directory, const QList< QPair< QString, QFileInfo > > &updates)
 
- Signals inherited from QThread
void finished ()
 This signal is emitted when the thread has finished executing. More...
 
void started ()
 This signal is emitted when the thread starts executing. More...
 
void terminated ()
 This signal is emitted when the thread is terminated. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 

Public Functions

void clear ()
 
QExtendedInformation getInfo (const QFileInfo &info) const
 
 QFileInfoGatherer (QObject *parent=0)
 Creates thread. More...
 
void removePath (const QString &path)
 
 ~QFileInfoGatherer ()
 Destroys thread. More...
 
- Public Functions inherited from QThread
void exit (int retcode=0)
 Tells the thread's event loop to exit with a return code. More...
 
bool isFinished () const
 Returns true if the thread is finished; otherwise returns false. More...
 
bool isRunning () const
 Returns true if the thread is running; otherwise returns false. More...
 
Priority priority () const
 Returns the priority for a running thread. More...
 
 QThread (QObject *parent=0)
 Constructs a new QThread to manage a new thread. More...
 
void setPriority (Priority priority)
 This function sets the priority for a running thread. More...
 
void setStackSize (uint stackSize)
 Sets the maximum stack size for the thread to stackSize. More...
 
uint stackSize () const
 Returns the maximum stack size for the thread (if set with setStackSize()); otherwise returns zero. More...
 
bool wait (unsigned long time=ULONG_MAX)
 Blocks the thread until either of these conditions is met: More...
 
 ~QThread ()
 Destroys the QThread. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

void getFileInfos (const QString &path, const QStringList &files)
 
void run ()
 The starting point for the thread. More...
 
- Protected Functions inherited from QThread
int exec ()
 Enters the event loop and waits until exit() is called, returning the value that was passed to exit(). More...
 
 QThread (QThreadPrivate &dd, QObject *parent=0)
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Functions

void fetch (const QFileInfo &info, QElapsedTimer &base, bool &firstTime, QList< QPair< QString, QFileInfo > > &updatedFiles, const QString &path)
 
QString translateDriveName (const QFileInfo &drive) const
 

Properties

volatile bool abort
 
QWaitCondition condition
 
QFileIconProvider defaultProvider
 
QStack< QStringListfiles
 
QFileIconProviderm_iconProvider
 
bool m_resolveSymlinks
 
QMutex mutex
 
QStack< QStringpath
 
QFileSystemWatcherwatcher
 

Additional Inherited Members

- Public Types inherited from QThread
enum  Priority {
  IdlePriority, LowestPriority, LowPriority, NormalPriority,
  HighPriority, HighestPriority, TimeCriticalPriority, InheritPriority
}
 This enum type indicates how the operating system should schedule newly created threads. More...
 
- Static Public Functions inherited from QThread
static QThreadcurrentThread ()
 Returns a pointer to a QThread which manages the currently executing thread. More...
 
static Qt::HANDLE currentThreadId ()
 Returns the thread handle of the currently executing thread. More...
 
static int idealThreadCount ()
 Returns the ideal number of threads that can be run on the system. More...
 
static void yieldCurrentThread ()
 Yields execution of the current thread to another runnable thread, if any. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Static Protected Functions inherited from QThread
static void msleep (unsigned long)
 Forces the current thread to sleep for msecs milliseconds. More...
 
static void setTerminationEnabled (bool enabled=true)
 Enables or disables termination of the current thread based on the enabled parameter. More...
 
static void sleep (unsigned long)
 Forces the current thread to sleep for secs seconds. More...
 
static void usleep (unsigned long)
 Forces the current thread to sleep for usecs microseconds. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 155 of file qfileinfogatherer_p.h.

Constructors and Destructors

◆ QFileInfoGatherer()

QFileInfoGatherer::QFileInfoGatherer ( QObject parent = 0)

Creates thread.

Definition at line 74 of file qfileinfogatherer.cpp.

75  : QThread(parent), abort(false),
76 #ifndef QT_NO_FILESYSTEMWATCHER
77  watcher(0),
78 #endif
80 {
81 #ifdef Q_OS_WIN
82  m_resolveSymlinks = true;
83 #elif !defined(Q_OS_INTEGRITY) && !defined(Q_OS_VXWORKS)
84  userId = getuid();
85  groupId = getgid();
86 #endif
87 #ifndef QT_NO_FILESYSTEMWATCHER
88  watcher = new QFileSystemWatcher(this);
89  connect(watcher, SIGNAL(directoryChanged(QString)), this, SLOT(list(QString)));
90  connect(watcher, SIGNAL(fileChanged(QString)), this, SLOT(updateFile(QString)));
91 #endif
93 }
void updateFile(const QString &path)
Fetch extended information for all filePath.
The QFileSystemWatcher class provides an interface for monitoring files and directories for modificat...
QThread(QObject *parent=0)
Constructs a new QThread to manage a new thread.
Definition: qthread.cpp:433
#define SLOT(a)
Definition: qobjectdefs.h:226
QFileIconProvider defaultProvider
QFileSystemWatcher * watcher
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define SIGNAL(a)
Definition: qobjectdefs.h:227
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QFileIconProvider * m_iconProvider
void list(const QString &directoryPath)
void start(Priority=InheritPriority)
Begins execution of the thread by calling run().

◆ ~QFileInfoGatherer()

QFileInfoGatherer::~QFileInfoGatherer ( )

Destroys thread.

Definition at line 98 of file qfileinfogatherer.cpp.

99 {
100  QMutexLocker locker(&mutex);
101  abort = true;
102  condition.wakeOne();
103  locker.unlock();
104  wait();
105 }
QWaitCondition condition
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
bool wait(unsigned long time=ULONG_MAX)
Blocks the thread until either of these conditions is met:

Functions

◆ clear()

void QFileInfoGatherer::clear ( )

Definition at line 170 of file qfileinfogatherer.cpp.

171 {
172 #ifndef QT_NO_FILESYSTEMWATCHER
173  QMutexLocker locker(&mutex);
176 #endif
177 }
void removePaths(const QStringList &files)
Removes the specified paths from the file system watcher.
QFileSystemWatcher * watcher
QStringList files() const
Returns a list of paths to files that are being watched.
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
QStringList directories() const
Returns a list of paths to directories that are being watched.

◆ directoryLoaded

void QFileInfoGatherer::directoryLoaded ( const QString path)
signal

Referenced by getFileInfos().

◆ fetch()

void QFileInfoGatherer::fetch ( const QFileInfo info,
QElapsedTimer base,
bool &  firstTime,
QList< QPair< QString, QFileInfo > > &  updatedFiles,
const QString path 
)
private

Definition at line 341 of file qfileinfogatherer.cpp.

Referenced by getFileInfos().

341  {
342  updatedFiles.append(QPair<QString, QFileInfo>(fileInfo.fileName(), fileInfo));
343  QElapsedTimer current;
344  current.start();
345  if ((firstTime && updatedFiles.count() > 100) || base.msecsTo(current) > 1000) {
346  emit updates(path, updatedFiles);
347  updatedFiles.clear();
348  base = current;
349  firstTime = false;
350  }
351 }
qint64 msecsTo(const QElapsedTimer &other) const
Returns the number of milliseconds between this QElapsedTimer and other.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
#define emit
Definition: qobjectdefs.h:76
void updates(const QString &directory, const QList< QPair< QString, QFileInfo > > &updates)
void clear()
Removes all items from the list.
Definition: qlist.h:764
void start()
Starts this timer.

◆ fetchExtendedInformation

void QFileInfoGatherer::fetchExtendedInformation ( const QString path,
const QStringList files 
)
slot

Fetch extended information for all files in path.

See also
updateFile(), update(), resolvedName()

Definition at line 137 of file qfileinfogatherer.cpp.

Referenced by list(), and updateFile().

138 {
139  QMutexLocker locker(&mutex);
140  // See if we already have this dir/file in our que
141  int loc = this->path.lastIndexOf(path);
142  while (loc > 0) {
143  if (this->files.at(loc) == files) {
144  return;
145  }
146  loc = this->path.lastIndexOf(path, loc - 1);
147  }
148  this->path.push(path);
149  this->files.push(files);
150  condition.wakeAll();
151 }
QStack< QStringList > files
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
QWaitCondition condition
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000

◆ getFileInfos()

void QFileInfoGatherer::getFileInfos ( const QString path,
const QStringList files 
)
protected

Definition at line 279 of file qfileinfogatherer.cpp.

Referenced by run().

280 {
281 #ifndef QT_NO_FILESYSTEMWATCHER
282  if (files.isEmpty()
283  && !watcher->directories().contains(path)
284  && !path.isEmpty()
285  && !path.startsWith(QLatin1String("//")) /*don't watch UNC path*/) {
286  watcher->addPath(path);
287  }
288 #endif
289 
290  // List drives
291  if (path.isEmpty()) {
292 #ifdef QT_BUILD_INTERNAL
293  fetchedRoot = true;
294 #endif
295  QFileInfoList infoList;
296  if (files.isEmpty()) {
297  infoList = QDir::drives();
298  } else {
299  for (int i = 0; i < files.count(); ++i)
300  infoList << QFileInfo(files.at(i));
301  }
302  for (int i = infoList.count() - 1; i >= 0; --i) {
303  QString driveName = translateDriveName(infoList.at(i));
304  QList<QPair<QString,QFileInfo> > updatedFiles;
305  updatedFiles.append(QPair<QString,QFileInfo>(driveName, infoList.at(i)));
306  emit updates(path, updatedFiles);
307  }
308  return;
309  }
310 
312  base.start();
313  QFileInfo fileInfo;
314  bool firstTime = true;
315  QList<QPair<QString, QFileInfo> > updatedFiles;
316  QStringList filesToCheck = files;
317 
318  QString itPath = QDir::fromNativeSeparators(files.isEmpty() ? path : QLatin1String(""));
320  QStringList allFiles;
321  while(!abort && dirIt.hasNext()) {
322  dirIt.next();
323  fileInfo = dirIt.fileInfo();
324  allFiles.append(fileInfo.fileName());
325  fetch(fileInfo, base, firstTime, updatedFiles, path);
326  }
327  if (!allFiles.isEmpty())
328  emit newListOfFiles(path, allFiles);
329 
330  QStringList::const_iterator filesIt = filesToCheck.constBegin();
331  while(!abort && filesIt != filesToCheck.constEnd()) {
332  fileInfo.setFile(path + QDir::separator() + *filesIt);
333  ++filesIt;
334  fetch(fileInfo, base, firstTime, updatedFiles, path);
335  }
336  if (!updatedFiles.isEmpty())
337  emit updates(path, updatedFiles);
338  emit directoryLoaded(path);
339 }
QStack< QStringList > files
void newListOfFiles(const QString &directory, const QStringList &listOfFiles) const
void fetch(const QFileInfo &info, QElapsedTimer &base, bool &firstTime, QList< QPair< QString, QFileInfo > > &updatedFiles, const QString &path)
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
const_iterator constBegin() const
Returns a const STL-style iterator pointing to the first item in the list.
Definition: qlist.h:269
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QFileSystemWatcher * watcher
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QDirIterator class provides an iterator for directory entrylists.
Definition: qdiriterator.h:54
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString translateDriveName(const QFileInfo &drive) const
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
The QElapsedTimer class provides a fast way to calculate elapsed times.
Definition: qelapsedtimer.h:53
static const uint base
Definition: qurl.cpp:268
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
friend class const_iterator
Definition: qlist.h:264
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
#define emit
Definition: qobjectdefs.h:76
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QStack< QString > path
void setFile(const QString &file)
Sets the file that the QFileInfo provides information about to file.
Definition: qfileinfo.cpp:468
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
void updates(const QString &directory, const QList< QPair< QString, QFileInfo > > &updates)
static QFileInfoList drives()
Returns a list of the root directories on this system.
Definition: qdir.cpp:1812
QStringList directories() const
Returns a list of paths to directories that are being watched.
void directoryLoaded(const QString &path)
void addPath(const QString &file)
Adds path to the file system watcher if path exists.
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using &#39;/&#39; as file separator.
Definition: qdir.cpp:848
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
void start()
Starts this timer.
const_iterator constEnd() const
Returns a const STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:272

◆ getInfo()

QExtendedInformation QFileInfoGatherer::getInfo ( const QFileInfo info) const

Definition at line 230 of file qfileinfogatherer.cpp.

231 {
232  QExtendedInformation info(fileInfo);
233  info.icon = m_iconProvider->icon(fileInfo);
234  info.displayType = m_iconProvider->type(fileInfo);
235 #ifndef QT_NO_FILESYSTEMWATCHER
236  // ### Not ready to listen all modifications
237  #if 0
238  // Enable the next two commented out lines to get updates when the file sizes change...
239  if (!fileInfo.exists() && !fileInfo.isSymLink()) {
240  info.size = -1;
241  //watcher->removePath(fileInfo.absoluteFilePath());
242  } else {
243  if (!fileInfo.absoluteFilePath().isEmpty() && fileInfo.exists() && fileInfo.isReadable()
244  && !watcher->files().contains(fileInfo.absoluteFilePath())) {
245  //watcher->addPath(fileInfo.absoluteFilePath());
246  }
247  }
248  #endif
249 #endif
250 
251  if (m_resolveSymlinks && info.isSymLink(/* ignoreNtfsSymLinks = */ true)) {
252  QFileInfo resolvedInfo(fileInfo.symLinkTarget());
253  resolvedInfo = resolvedInfo.canonicalFilePath();
254  if (resolvedInfo.exists()) {
255  emit nameResolved(fileInfo.filePath(), resolvedInfo.fileName());
256  }
257  }
258  return info;
259 }
static mach_timebase_info_data_t info
virtual QIcon icon(IconType type) const
Returns an icon set for the given type.
QFileSystemWatcher * watcher
virtual QString type(const QFileInfo &info) const
Returns the type of the file described by info.
QStringList files() const
Returns a list of paths to files that are being watched.
#define emit
Definition: qobjectdefs.h:76
QString canonicalFilePath() const
Returns the canonical path including the file name, i.e.
Definition: qfileinfo.cpp:551
QFileIconProvider * m_iconProvider
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
qint64 size() const
Returns the file size in bytes.
Definition: qfileinfo.cpp:1248
void nameResolved(const QString &fileName, const QString &resolvedName) const
bool isSymLink() const
Returns true if this object points to a symbolic link (or to a shortcut on Windows); otherwise return...
Definition: qfileinfo.cpp:1044
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60

◆ iconProvider

QFileIconProvider * QFileInfoGatherer::iconProvider ( ) const
slot

Definition at line 127 of file qfileinfogatherer.cpp.

128 {
129  return m_iconProvider;
130 }
QFileIconProvider * m_iconProvider

◆ list

void QFileInfoGatherer::list ( const QString directoryPath)
slot

Definition at line 197 of file qfileinfogatherer.cpp.

Referenced by QFileInfoGatherer(), and run().

198 {
199  fetchExtendedInformation(directoryPath, QStringList());
200 }
void fetchExtendedInformation(const QString &path, const QStringList &files)
Fetch extended information for all files in path.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66

◆ nameResolved

void QFileInfoGatherer::nameResolved ( const QString fileName,
const QString resolvedName 
) const
signal

Referenced by getInfo().

◆ newListOfFiles

void QFileInfoGatherer::newListOfFiles ( const QString directory,
const QStringList listOfFiles 
) const
signal

Referenced by getFileInfos().

◆ removePath()

void QFileInfoGatherer::removePath ( const QString path)

Definition at line 184 of file qfileinfogatherer.cpp.

Referenced by QFileSystemModel::remove(), and QFileSystemModel::rmdir().

185 {
186 #ifndef QT_NO_FILESYSTEMWATCHER
187  QMutexLocker locker(&mutex);
188  watcher->removePath(path);
189 #endif
190 }
void removePath(const QString &file)
Removes the specified path from the file system watcher.
QFileSystemWatcher * watcher
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ resolveSymlinks

bool QFileInfoGatherer::resolveSymlinks ( ) const
slot

Definition at line 116 of file qfileinfogatherer.cpp.

117 {
118  return m_resolveSymlinks;
119 }

◆ run()

void QFileInfoGatherer::run ( void  )
protectedvirtual

The starting point for the thread.

After calling start(), the newly created thread calls this function. The default implementation simply calls exec().

You can reimplement this function to facilitate advanced thread management. Returning from this method will end the execution of the thread.

See also
start() wait()

Reimplemented from QThread.

Definition at line 205 of file qfileinfogatherer.cpp.

206 {
207  forever {
208  bool updateFiles = false;
209  QMutexLocker locker(&mutex);
210  if (abort) {
211  return;
212  }
213  if (this->path.isEmpty())
214  condition.wait(&mutex);
215  QString path;
217  if (!this->path.isEmpty()) {
218  path = this->path.first();
219  list = this->files.first();
220  this->path.pop_front();
221  this->files.pop_front();
222  updateFiles = true;
223  }
224  locker.unlock();
225  if (updateFiles)
226  getFileInfos(path, list);
227  }
228 }
QStack< QStringList > files
void pop_front()
This function is provided for STL compatibility.
Definition: qvector.h:284
void getFileInfos(const QString &path, const QStringList &files)
T & first()
Returns a reference to the first item in the vector.
Definition: qvector.h:260
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QStack< QString > path
void list(const QString &directoryPath)
QWaitCondition condition
bool wait(QMutex *mutex, unsigned long time=ULONG_MAX)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
bool isEmpty() const
Returns true if the vector has size 0; otherwise returns false.
Definition: qvector.h:139
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ setIconProvider

void QFileInfoGatherer::setIconProvider ( QFileIconProvider provider)
slot

Definition at line 121 of file qfileinfogatherer.cpp.

122 {
123  QMutexLocker locker(&mutex);
124  m_iconProvider = provider;
125 }
QFileIconProvider * m_iconProvider
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101

◆ setResolveSymlinks

void QFileInfoGatherer::setResolveSymlinks ( bool  enable)
slot

Definition at line 107 of file qfileinfogatherer.cpp.

108 {
109  Q_UNUSED(enable);
110 #ifdef Q_OS_WIN
111  QMutexLocker locker(&mutex);
112  m_resolveSymlinks = enable;
113 #endif
114 }
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
Definition: qmutex.h:101
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ translateDriveName()

QString QFileInfoGatherer::translateDriveName ( const QFileInfo drive) const
private

Definition at line 261 of file qfileinfogatherer.cpp.

Referenced by getFileInfos().

262 {
263  QString driveName = drive.absoluteFilePath();
264 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
265  if (driveName.startsWith(QLatin1Char('/'))) // UNC host
266  return drive.fileName();
267 #endif
268 #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) || defined(Q_OS_SYMBIAN)
269  if (driveName.endsWith(QLatin1Char('/')))
270  driveName.chop(1);
271 #endif
272  return driveName;
273 }
void chop(int n)
Removes n characters from the end of the string.
Definition: qstring.cpp:4623
QString fileName() const
Returns the name of the file, excluding the path.
Definition: qfileinfo.cpp:726
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QString absoluteFilePath() const
Returns an absolute path including the file name.
Definition: qfileinfo.cpp:534
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ updateFile

void QFileInfoGatherer::updateFile ( const QString filePath)
slot

Fetch extended information for all filePath.

See also
fetchExtendedInformation()

Definition at line 158 of file qfileinfogatherer.cpp.

Referenced by QFileInfoGatherer().

159 {
160  QString dir = filePath.mid(0, filePath.lastIndexOf(QDir::separator()));
161  QString fileName = filePath.mid(dir.length() + 1);
162  fetchExtendedInformation(dir, QStringList(fileName));
163 }
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
void fetchExtendedInformation(const QString &path, const QStringList &files)
Fetch extended information for all files in path.
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
static QString fileName(const QString &fileUrl)

◆ updates

void QFileInfoGatherer::updates ( const QString directory,
const QList< QPair< QString, QFileInfo > > &  updates 
)
signal

Referenced by fetch(), and getFileInfos().

Properties

◆ abort

volatile bool QFileInfoGatherer::abort
private

Definition at line 192 of file qfileinfogatherer_p.h.

Referenced by getFileInfos(), run(), and ~QFileInfoGatherer().

◆ condition

QWaitCondition QFileInfoGatherer::condition
private

Definition at line 191 of file qfileinfogatherer_p.h.

Referenced by fetchExtendedInformation(), run(), and ~QFileInfoGatherer().

◆ defaultProvider

QFileIconProvider QFileInfoGatherer::defaultProvider
private

Definition at line 202 of file qfileinfogatherer_p.h.

◆ files

QStack<QStringList> QFileInfoGatherer::files
private

Definition at line 195 of file qfileinfogatherer_p.h.

Referenced by fetchExtendedInformation(), getFileInfos(), and run().

◆ m_iconProvider

QFileIconProvider* QFileInfoGatherer::m_iconProvider
private

Definition at line 201 of file qfileinfogatherer_p.h.

Referenced by getInfo(), iconProvider(), and setIconProvider().

◆ m_resolveSymlinks

bool QFileInfoGatherer::m_resolveSymlinks
private

◆ mutex

QMutex QFileInfoGatherer::mutex
private

◆ path

QStack<QString> QFileInfoGatherer::path
private

Definition at line 194 of file qfileinfogatherer_p.h.

Referenced by getFileInfos(), and run().

◆ watcher

QFileSystemWatcher* QFileInfoGatherer::watcher
private

Definition at line 198 of file qfileinfogatherer_p.h.

Referenced by clear(), getFileInfos(), getInfo(), QFileInfoGatherer(), and removePath().


The documentation for this class was generated from the following files: