Merge lp:~carlos-mazieri/ubuntu-filemanager-app/extfswatcher-improvement into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 185
Merged at revision: 185
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/extfswatcher-improvement
Merge into: lp:ubuntu-filemanager-app
Diff against target: 86 lines (+31/-20)
1 file modified
src/plugin/folderlistmodel/externalfswatcher.cpp (+31/-20)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/extfswatcher-improvement
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+219937@code.launchpad.net

Commit message

ExternalFSWatcher class improvement

Description of the change

ExternalFSWatcher class improvements:
   * setCurrentPath() calls setCurrentPaths() as they used to have similar code
   * setCurrentPaths() clears m_changedPath avoids unnecessary notifications
   * slotFireChanges() improved documentation

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugin/folderlistmodel/externalfswatcher.cpp'
2--- src/plugin/folderlistmodel/externalfswatcher.cpp 2014-05-13 23:28:43 +0000
3+++ src/plugin/folderlistmodel/externalfswatcher.cpp 2014-05-17 14:47:33 +0000
4@@ -31,8 +31,10 @@
5 << Q_FUNC_INFO << "m_setPath:" << m_setPaths \
6 << "m_changedPath:" << m_changedPath \
7 << "m_waitingEmit:" << m_waitingEmitCounter
8+# define DEBUG_FSWATCHER_MSG(msg) DEBUG_FSWATCHER() << msg
9 #else
10 # define DEBUG_FSWATCHER() /**/
11+# define DEBUG_FSWATCHER_MSG(msg) /* msg */
12 #endif //
13
14
15@@ -51,22 +53,29 @@
16 {
17 if (!curPath.isEmpty() && (m_setPaths.count() != 1 || m_setPaths.at(0) != curPath))
18 {
19- clearPaths();
20- m_setPaths.clear();
21- m_setPaths.append(curPath);
22- QFileSystemWatcher::addPath(curPath);
23+ setCurrentPaths(QStringList(curPath));
24 }
25- DEBUG_FSWATCHER();
26 }
27
28
29 void ExternalFSWatcher::setCurrentPaths(const QStringList &paths)
30-{
31- QStringList myPaths(paths);
32- ::qSort(myPaths);
33+{
34+ if (paths.count() > 0)
35+ {
36+ QStringList myPaths(paths);
37+ ::qSort(myPaths);
38+ m_setPaths = myPaths;
39+ }
40+ else
41+ {
42+ m_setPaths = paths;
43+ }
44 clearPaths();
45- m_setPaths = myPaths;
46- QFileSystemWatcher::addPaths(paths);
47+ //cleaning m_changedPath avoids any notification for a change
48+ // already scheduled to happen in slotFireChanges()
49+ m_changedPath.clear();
50+ QFileSystemWatcher::addPaths(m_setPaths);
51+ DEBUG_FSWATCHER();
52 }
53
54
55@@ -117,21 +126,23 @@
56 */
57 void ExternalFSWatcher::slotFireChanges()
58 {
59- if ( --m_waitingEmitCounter == 0
60- && m_lastChangedIndex != -1
61- && m_lastChangedIndex < m_setPaths.count() )
62- {
63- if (m_setPaths.at(m_lastChangedIndex) == m_changedPath)
64+ DEBUG_FSWATCHER();
65+ if ( --m_waitingEmitCounter == 0 ) //no more changes queued (it is the LAST), time to notify
66+ {
67+ //the notification will not fired if either setCurrentPath() or setCurrentPaths()
68+ //was called after the change in the disk be noticed
69+ if (m_lastChangedIndex != -1 &&
70+ m_lastChangedIndex < m_setPaths.count() &&
71+ m_setPaths.at(m_lastChangedIndex) == m_changedPath)
72 {
73 emit pathModified(m_changedPath);
74-#if DEBUG_EXT_FS_WATCHER
75- DEBUG_FSWATCHER() << "emit pathModified()";
76-#endif
77+ DEBUG_FSWATCHER_MSG("emit pathModified()");
78 }
79- //restore the original list in QFileSystemWatcher
80+ //restore the original m_setPaths list in QFileSystemWatcher anyway
81+ //it does not matter if the notification was fired or not.
82 clearPaths();
83 QFileSystemWatcher::addPaths(m_setPaths);
84- }
85+ }
86 }
87
88

Subscribers

People subscribed via source and target branches