249 if dirName != "" and \ |
249 if dirName != "" and \ |
250 not dirName.startswith("//") and \ |
250 not dirName.startswith("//") and \ |
251 not dirName.startswith("\\\\"): |
251 not dirName.startswith("\\\\"): |
252 if dirName not in self.watcher.directories(): |
252 if dirName not in self.watcher.directories(): |
253 self.watcher.addPath(dirName) |
253 self.watcher.addPath(dirName) |
254 if dirName in self.watchedItems and \ |
254 if dirName in self.watchedItems: |
255 itm not in self.watchedItems[dirName]: |
255 if itm not in self.watchedItems[dirName]: |
256 self.watchedItems[dirName].append(itm) |
256 self.watchedItems[dirName].append(itm) |
257 else: |
257 else: |
258 self.watchedItems[dirName] = [itm] |
258 self.watchedItems[dirName] = [itm] |
259 |
259 |
260 def _removeWatchedItem(self, itm): |
260 def _removeWatchedItem(self, itm): |
261 """ |
261 """ |
263 |
263 |
264 @param itm item to be removed (BrowserDirectoryItem) |
264 @param itm item to be removed (BrowserDirectoryItem) |
265 """ |
265 """ |
266 if isinstance(itm, BrowserDirectoryItem): |
266 if isinstance(itm, BrowserDirectoryItem): |
267 dirName = itm.dirName() |
267 dirName = itm.dirName() |
268 if dirName in self.watchedItems and \ |
268 if dirName in self.watchedItems: |
269 itm in self.watchedItems[dirName]: |
269 if itm in self.watchedItems[dirName]: |
270 self.watchedItems[dirName].remove(itm) |
270 self.watchedItems[dirName].remove(itm) |
271 if len(self.watchedItems[dirName]) == 0: |
271 if len(self.watchedItems[dirName]) == 0: |
272 del self.watchedItems[dirName] |
272 del self.watchedItems[dirName] |
273 self.watcher.removePath(dirName) |
273 self.watcher.removePath(dirName) |
274 |
274 |
275 def __directoryChanged(self, path): |
275 def directoryChanged(self, path): |
276 """ |
276 """ |
277 Private slot to handle the directoryChanged signal of the watcher. |
277 Public slot to handle the directoryChanged signal of the watcher. |
278 |
278 |
279 @param path path of the directory (string) |
279 @param path path of the directory (string) |
280 """ |
280 """ |
281 if path not in self.watchedItems: |
281 if path not in self.watchedItems: |
282 # just ignore the situation we don't have a reference to the item |
282 # just ignore the situation we don't have a reference to the item |
283 return |
283 return |
284 |
284 |
285 for itm in self.watchedItems[path]: |
285 for itm in self.watchedItems[path]: |
286 if itm.isPopulated(): |
286 oldCnt = itm.childCount() |
287 oldCnt = itm.childCount() |
287 |
|
288 qdir = QDir(itm.dirName()) |
|
289 |
|
290 entryInfoList = qdir.entryInfoList( |
|
291 QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot)) |
|
292 |
|
293 # step 1: check for new entries |
|
294 children = itm.children() |
|
295 for f in entryInfoList: |
|
296 fpath = f.absoluteFilePath() |
|
297 childFound = False |
|
298 for child in children: |
|
299 if child.name() == fpath: |
|
300 childFound = True |
|
301 children.remove(child) |
|
302 break |
|
303 if childFound: |
|
304 continue |
288 |
305 |
289 qdir = QDir(itm.dirName()) |
306 cnt = itm.childCount() |
290 |
307 self.beginInsertRows(self.createIndex(itm.row(), 0, itm), |
291 entryInfoList = qdir.entryInfoList( |
308 cnt, cnt) |
292 QDir.Filters(QDir.AllEntries | QDir.NoDotAndDotDot)) |
309 if f.isDir(): |
293 |
310 node = BrowserDirectoryItem(itm, |
294 # step 1: check for new entries |
311 Utilities.toNativeSeparators(f.absoluteFilePath()), |
295 for f in entryInfoList: |
312 False) |
296 fpath = f.absoluteFilePath() |
313 else: |
297 childFound = False |
314 node = BrowserFileItem(itm, |
298 for child in itm.children(): |
315 Utilities.toNativeSeparators(f.absoluteFilePath())) |
299 if child.name() == fpath: |
316 self._addItem(node, itm) |
300 childFound = True |
317 self.endInsertRows() |
|
318 |
|
319 # step 2: check for removed entries |
|
320 if len(entryInfoList) != itm.childCount(): |
|
321 for row in range(oldCnt - 1, -1, -1): |
|
322 child = itm.child(row) |
|
323 entryFound = False |
|
324 for f in entryInfoList: |
|
325 if f.absoluteFilePath() == child.name(): |
|
326 entryFound = True |
|
327 entryInfoList.remove(f) |
301 break |
328 break |
302 if childFound: |
329 if entryFound: |
303 continue |
330 continue |
304 |
331 |
305 cnt = itm.childCount() |
332 self._removeWatchedItem(child) |
306 self.beginInsertRows(self.createIndex(itm.row(), 0, itm), |
333 self.beginRemoveRows(self.createIndex(itm.row(), 0, itm), |
307 cnt, cnt) |
334 row, row) |
308 if f.isDir(): |
335 itm.removeChild(child) |
309 node = BrowserDirectoryItem(itm, |
336 self.endRemoveRows() |
310 Utilities.toNativeSeparators(f.absoluteFilePath()), |
|
311 False) |
|
312 self._addWatchedItem(node) |
|
313 else: |
|
314 node = BrowserFileItem(itm, |
|
315 Utilities.toNativeSeparators(f.absoluteFilePath())) |
|
316 self._addItem(node, itm) |
|
317 self.endInsertRows() |
|
318 |
|
319 # step 2: check for removed entries |
|
320 if len(entryInfoList) != itm.childCount(): |
|
321 for row in range(oldCnt - 1, -1, -1): |
|
322 child = itm.child(row) |
|
323 entryFound = False |
|
324 for f in entryInfoList: |
|
325 if f.absoluteFilePath() == child.name(): |
|
326 entryFound = True |
|
327 break |
|
328 if entryFound: |
|
329 continue |
|
330 |
|
331 self.beginRemoveRows(self.createIndex(itm.row(), 0, itm), |
|
332 row, row) |
|
333 itm.removeChild(child) |
|
334 self.endRemoveRows() |
|
335 |
337 |
336 def __populateModel(self): |
338 def __populateModel(self): |
337 """ |
339 """ |
338 Private method to populate the browser model. |
340 Private method to populate the browser model. |
339 """ |
341 """ |