| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qfilesystemwatcher.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||
| 2 | - | |||||||
| 3 | - | |||||||
| 4 | - | |||||||
| 5 | - | |||||||
| 6 | - | |||||||
| 7 | - | |||||||
| 8 | - | |||||||
| 9 | - | |||||||
| 10 | - | |||||||
| 11 | - | |||||||
| 12 | - | |||||||
| 13 | - | |||||||
| 14 | - | |||||||
| 15 | - | |||||||
| 16 | - | |||||||
| 17 | - | |||||||
| 18 | - | |||||||
| 19 | - | |||||||
| 20 | QFileSystemWatcherEngine *QFileSystemWatcherPrivate::createNativeEngine(QObject *parent) | - | ||||||
| 21 | { | - | ||||||
| 22 | - | |||||||
| 23 | - | |||||||
| 24 | - | |||||||
| 25 | - | |||||||
| 26 | - | |||||||
| 27 | return QInotifyFileSystemWatcherEngine::create(parent); | - | ||||||
| 28 | } | - | ||||||
| 29 | - | |||||||
| 30 | QFileSystemWatcherPrivate::QFileSystemWatcherPrivate() | - | ||||||
| 31 | : native(0), poller(0) | - | ||||||
| 32 | { | - | ||||||
| 33 | } | - | ||||||
| 34 | - | |||||||
| 35 | void QFileSystemWatcherPrivate::init() | - | ||||||
| 36 | { | - | ||||||
| 37 | QFileSystemWatcher * const q = q_func(); | - | ||||||
| 38 | native = createNativeEngine(q); | - | ||||||
| 39 | if (native) { | - | ||||||
| 40 | QObject::connect(native, | - | ||||||
| 41 | qFlagLocation("2""fileChanged(QString,bool)" "\0" __FILE__ ":" "92""98"), | - | ||||||
| 42 | q, | - | ||||||
| 43 | qFlagLocation("1""_q_fileChanged(QString,bool)" "\0" __FILE__ ":" "94""100")); | - | ||||||
| 44 | QObject::connect(native, | - | ||||||
| 45 | qFlagLocation("2""directoryChanged(QString,bool)" "\0" __FILE__ ":" "96""102"), | - | ||||||
| 46 | q, | - | ||||||
| 47 | qFlagLocation("1""_q_directoryChanged(QString,bool)" "\0" __FILE__ ":" "98""104")); | - | ||||||
| 48 | } | - | ||||||
| 49 | } | - | ||||||
| 50 | - | |||||||
| 51 | void QFileSystemWatcherPrivate::initPollerEngine() | - | ||||||
| 52 | { | - | ||||||
| 53 | if(poller) | - | ||||||
| 54 | return; | - | ||||||
| 55 | - | |||||||
| 56 | QFileSystemWatcher * const q = q_func(); | - | ||||||
| 57 | poller = new QPollingFileSystemWatcherEngine(q); | - | ||||||
| 58 | QObject::connect(poller, | - | ||||||
| 59 | qFlagLocation("2""fileChanged(QString,bool)" "\0" __FILE__ ":" "110""116"), | - | ||||||
| 60 | q, | - | ||||||
| 61 | qFlagLocation("1""_q_fileChanged(QString,bool)" "\0" __FILE__ ":" "112""118")); | - | ||||||
| 62 | QObject::connect(poller, | - | ||||||
| 63 | qFlagLocation("2""directoryChanged(QString,bool)" "\0" __FILE__ ":" "114""120"), | - | ||||||
| 64 | q, | - | ||||||
| 65 | qFlagLocation("1""_q_directoryChanged(QString,bool)" "\0" __FILE__ ":" "116""122")); | - | ||||||
| 66 | } | - | ||||||
| 67 | - | |||||||
| 68 | void QFileSystemWatcherPrivate::_q_fileChanged(const QString &path, bool removed) | - | ||||||
| 69 | { | - | ||||||
| 70 | QFileSystemWatcher * const q = q_func(); | - | ||||||
| 71 | if (!files.contains(path)) { | - | ||||||
| 72 | - | |||||||
| 73 | return; | - | ||||||
| 74 | } | - | ||||||
| 75 | if (removed) | - | ||||||
| 76 | files.removeAll(path); | - | ||||||
| 77 | q->fileChanged(path, QFileSystemWatcher::QPrivateSignal()); | - | ||||||
| 78 | } | - | ||||||
| 79 | - | |||||||
| 80 | void QFileSystemWatcherPrivate::_q_directoryChanged(const QString &path, bool removed) | - | ||||||
| 81 | { | - | ||||||
| 82 | QFileSystemWatcher * const q = q_func(); | - | ||||||
| 83 | if (!directories.contains(path)) { | - | ||||||
| 84 | - | |||||||
| 85 | return; | - | ||||||
| 86 | } | - | ||||||
| 87 | if (removed) | - | ||||||
| 88 | directories.removeAll(path); | - | ||||||
| 89 | q->directoryChanged(path, QFileSystemWatcher::QPrivateSignal()); | - | ||||||
| 90 | } | - | ||||||
| 91 | QFileSystemWatcher::QFileSystemWatcher(QObject *parent) | - | ||||||
| 92 | : QObject(*new QFileSystemWatcherPrivate, parent) | - | ||||||
| 93 | { | - | ||||||
| 94 | d_func()->init(); | - | ||||||
| 95 | } | - | ||||||
| 96 | - | |||||||
| 97 | - | |||||||
| 98 | - | |||||||
| 99 | - | |||||||
| 100 | - | |||||||
| 101 | QFileSystemWatcher::QFileSystemWatcher(const QStringList &paths, QObject *parent) | - | ||||||
| 102 | : QObject(*new QFileSystemWatcherPrivate, parent) | - | ||||||
| 103 | { | - | ||||||
| 104 | d_func()->init(); | - | ||||||
| 105 | addPaths(paths); | - | ||||||
| 106 | } | - | ||||||
| 107 | - | |||||||
| 108 | - | |||||||
| 109 | - | |||||||
| 110 | - | |||||||
| 111 | QFileSystemWatcher::~QFileSystemWatcher() | - | ||||||
| 112 | { } | - | ||||||
| 113 | bool QFileSystemWatcher::addPath(const QString &path) | - | ||||||
| 114 | { | - | ||||||
| 115 | if (path.isEmpty()) { | - | ||||||
| 116 | QMessageLogger(__FILE__, 248255, __PRETTY_FUNCTION__).warning("QFileSystemWatcher::addPath: path is empty"); | - | ||||||
| 117 | return true; | - | ||||||
| 118 | } | - | ||||||
| 119 | - | |||||||
| 120 | QStringList paths = addPaths(QStringList(path)); | - | ||||||
| 121 | return paths.isEmpty(); | - | ||||||
| 122 | } | - | ||||||
| 123 | QStringList QFileSystemWatcher::addPaths(const QStringList &paths) | - | ||||||
| 124 | { | - | ||||||
| 125 | QFileSystemWatcherPrivate * const d = d_func(); | - | ||||||
| 126 | - | |||||||
| 127 | QStringList p = paths; | - | ||||||
| 128 | QMutableListIterator<QString> it(p); | - | ||||||
| 129 | - | |||||||
| 130 | while (it.hasNext()
| 487-488 | ||||||
| 131 | const QString &path = it.next(); | - | ||||||
| 132 | if (path.isEmpty()
| 1-487 | ||||||
| 133 | it.remove(); executed 1 time by 1 test: it.remove();Executed by:
| 1 | ||||||
| 134 | } executed 488 times by 8 tests: end of blockExecuted by:
| 488 | ||||||
| 135 | - | |||||||
| 136 | if (p.isEmpty()
| 2-485 | ||||||
| 137 | QMessageLogger(__FILE__, 293300, __PRETTY_FUNCTION__).warning("QFileSystemWatcher::addPaths: list is empty"); | - | ||||||
| 138 | return executed 2 times by 1 test: QStringList();return QStringList();Executed by:
executed 2 times by 1 test: return QStringList();Executed by:
| 2 | ||||||
| 139 | } | - | ||||||
| 140 | - | |||||||
| 141 | QFileSystemWatcherEngine *engine = 0; | - | ||||||
| 142 | - | |||||||
| 143 | const QString on = objectName(); | - | ||||||
| 144 | - | |||||||
| 145 | if (!on.startsWith(QLatin1String("_qt_autotest_force_engine_"))
| 27-458 | ||||||
| 146 | - | |||||||
| 147 | if(d->native
| 0-458 | ||||||
| 148 | engine = d->native; | - | ||||||
| 149 | } executed 458 times by 8 tests: else {end of blockExecuted by:
| 458 | ||||||
| 150 | d_func()->initPollerEngine(); | - | ||||||
| 151 | engine = d->poller; | - | ||||||
| 152 | } never executed: end of block | 0 | ||||||
| 153 | - | |||||||
| 154 | } else { | - | ||||||
| 155 | - | |||||||
| 156 | const QStringRef forceName = on.midRef(26); | - | ||||||
| 157 | if(forceName == QLatin1String("poller")
| 9-18 | ||||||
| 158 | QMessageLogger(__FILE__, 314321, __PRETTY_FUNCTION__).debug() << ("QFileSystemWatcher: skipping native engine, using only polling engine";); | - | ||||||
| 159 | d_func()->initPollerEngine(); | - | ||||||
| 160 | engine = d->poller; | - | ||||||
| 161 | } executed 9 times by 1 test: else if(forceName == QLatin1String("native")end of blockExecuted by:
| 0-18 | ||||||
| 162 | QMessageLogger(__FILE__, 318325, __PRETTY_FUNCTION__).debug() << ("QFileSystemWatcher: skipping polling engine, using only native engine";); | - | ||||||
| 163 | engine = d->native; | - | ||||||
| 164 | } executed 18 times by 1 test: end of blockExecuted by:
| 18 | ||||||
| 165 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||
| 166 | - | |||||||
| 167 | if(engine
| 0-485 | ||||||
| 168 | p = engine->addPaths(p, &d->files, &d->directories); executed 485 times by 8 tests: p = engine->addPaths(p, &d->files, &d->directories);Executed by:
| 485 | ||||||
| 169 | - | |||||||
| 170 | return executed 485 times by 8 tests: p;return p;Executed by:
executed 485 times by 8 tests: return p;Executed by:
| 485 | ||||||
| 171 | } | - | ||||||
| 172 | bool QFileSystemWatcher::removePath(const QString &path) | - | ||||||
| 173 | { | - | ||||||
| 174 | if (path.isEmpty()) { | - | ||||||
| 175 | QMessageLogger(__FILE__, 342349, __PRETTY_FUNCTION__).warning("QFileSystemWatcher::removePath: path is empty"); | - | ||||||
| 176 | return true; | - | ||||||
| 177 | } | - | ||||||
| 178 | - | |||||||
| 179 | QStringList paths = removePaths(QStringList(path)); | - | ||||||
| 180 | return paths.isEmpty(); | - | ||||||
| 181 | } | - | ||||||
| 182 | QStringList QFileSystemWatcher::removePaths(const QStringList &paths) | - | ||||||
| 183 | { | - | ||||||
| 184 | QFileSystemWatcherPrivate * const d = d_func(); | - | ||||||
| 185 | - | |||||||
| 186 | QStringList p = paths; | - | ||||||
| 187 | QMutableListIterator<QString> it(p); | - | ||||||
| 188 | - | |||||||
| 189 | while (it.hasNext()) { | - | ||||||
| 190 | const QString &path = it.next(); | - | ||||||
| 191 | if (path.isEmpty()) | - | ||||||
| 192 | it.remove(); | - | ||||||
| 193 | } | - | ||||||
| 194 | - | |||||||
| 195 | if (p.isEmpty()) { | - | ||||||
| 196 | QMessageLogger(__FILE__, 375382, __PRETTY_FUNCTION__).warning("QFileSystemWatcher::removePaths: list is empty"); | - | ||||||
| 197 | return QStringList(); | - | ||||||
| 198 | } | - | ||||||
| 199 | - | |||||||
| 200 | if (d->native) | - | ||||||
| 201 | p = d->native->removePaths(p, &d->files, &d->directories); | - | ||||||
| 202 | if (d->poller) | - | ||||||
| 203 | p = d->poller->removePaths(p, &d->files, &d->directories); | - | ||||||
| 204 | - | |||||||
| 205 | return p; | - | ||||||
| 206 | } | - | ||||||
| 207 | QStringList QFileSystemWatcher::directories() const | - | ||||||
| 208 | { | - | ||||||
| 209 | const QFileSystemWatcherPrivate * const d = d_func(); | - | ||||||
| 210 | return d->directories; | - | ||||||
| 211 | } | - | ||||||
| 212 | - | |||||||
| 213 | QStringList QFileSystemWatcher::files() const | - | ||||||
| 214 | { | - | ||||||
| 215 | const QFileSystemWatcherPrivate * const d = d_func(); | - | ||||||
| 216 | return d->files; | - | ||||||
| 217 | } | - | ||||||
| 218 | - | |||||||
| 219 | - | |||||||
| 220 | - | |||||||
| Switch to Source code | Preprocessed file |