[Pkg-owncloud-commits] [owncloud-client] 221/470: Don's use SyncFileStatus for Folder::createGuiLog

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu May 12 16:25:06 UTC 2016


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 69aa39f1f645f262106ef103e7c373cda2f57654
Author: Jocelyn Turcotte <jturcotte at woboq.com>
Date:   Thu Mar 24 18:20:49 2016 +0100

    Don's use SyncFileStatus for Folder::createGuiLog
    
    SyncFileStatus' purpose is to track overlay icon status.
    Instead of putting comments and default: clauses in switch
    on both sides about unused enums, use different enums.
    
    This also remove STATUS_NEW which is the equivalent of
    STATUS_SYNC in all shell extension implementations, and
    remove STATUS_UPDATED and STATUS_STAT_ERROR which have
    the same semantic as STATUS_UPTODATE and STATUS__ERROR.
---
 src/gui/folder.cpp                    | 32 +++++++++++++---------------
 src/gui/folder.h                      | 12 +++++++++--
 src/gui/socketapi.cpp                 |  6 ++----
 src/gui/socketapi.h                   |  1 +
 src/libsync/syncengine.cpp            |  8 +++----
 src/libsync/syncfilestatus.cpp        | 21 ++++++-------------
 src/libsync/syncfilestatus.h          | 17 +++++----------
 src/libsync/syncfilestatustracker.cpp | 39 ++++++++++++++++++-----------------
 8 files changed, 62 insertions(+), 74 deletions(-)

diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index bfa857f..c00b95d 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -441,32 +441,32 @@ void Folder::bubbleUpSyncResult()
     _syncResult.setWarnCount(ignoredItems);
 
     if( firstItemNew ) {
-        createGuiLog( firstItemNew->_file,     SyncFileStatus::STATUS_NEW, newItems );
+        createGuiLog( firstItemNew->_file, LogStatusNew, newItems );
     }
     if( firstItemDeleted ) {
-        createGuiLog( firstItemDeleted->_file, SyncFileStatus::STATUS_REMOVE, removedItems );
+        createGuiLog( firstItemDeleted->_file, LogStatusRemove, removedItems );
     }
     if( firstItemUpdated ) {
-        createGuiLog( firstItemUpdated->_file, SyncFileStatus::STATUS_UPDATED, updatedItems );
+        createGuiLog( firstItemUpdated->_file, LogStatusUpdated, updatedItems );
     }
 
     if( firstItemRenamed ) {
-        SyncFileStatus status(SyncFileStatus::STATUS_RENAME);
+        LogStatus status(LogStatusRename);
         // if the path changes it's rather a move
         QDir renTarget = QFileInfo(firstItemRenamed->_renameTarget).dir();
         QDir renSource = QFileInfo(firstItemRenamed->_file).dir();
         if(renTarget != renSource) {
-            status.set(SyncFileStatus::STATUS_MOVE);
+            status = LogStatusMove;
         }
         createGuiLog( firstItemRenamed->_originalFile, status, renamedItems, firstItemRenamed->_renameTarget );
     }
 
-    createGuiLog( firstItemError->_file,   SyncFileStatus::STATUS_ERROR, errorItems );
+    createGuiLog( firstItemError->_file, LogStatusError, errorItems );
 
     qDebug() << "OO folder slotSyncFinished: result: " << int(_syncResult.status());
 }
 
-void Folder::createGuiLog( const QString& filename, SyncFileStatus status, int count,
+void Folder::createGuiLog( const QString& filename, LogStatus status, int count,
                            const QString& renameTarget )
 {
     if(count > 0) {
@@ -475,53 +475,49 @@ void Folder::createGuiLog( const QString& filename, SyncFileStatus status, int c
         QString file = QDir::toNativeSeparators(filename);
         QString text;
 
-        // not all possible values of status are evaluated here because the others
-        // are not used in the calling function. Please check there.
-        switch (status.tag()) {
-        case SyncFileStatus::STATUS_REMOVE:
+        switch (status) {
+        case LogStatusRemove:
             if( count > 1 ) {
                 text = tr("%1 and %2 other files have been removed.", "%1 names a file.").arg(file).arg(count-1);
             } else {
                 text = tr("%1 has been removed.", "%1 names a file.").arg(file);
             }
             break;
-        case SyncFileStatus::STATUS_NEW:
+        case LogStatusNew:
             if( count > 1 ) {
                 text = tr("%1 and %2 other files have been downloaded.", "%1 names a file.").arg(file).arg(count-1);
             } else {
                 text = tr("%1 has been downloaded.", "%1 names a file.").arg(file);
             }
             break;
-        case SyncFileStatus::STATUS_UPDATED:
+        case LogStatusUpdated:
             if( count > 1 ) {
                 text = tr("%1 and %2 other files have been updated.").arg(file).arg(count-1);
             } else {
                 text = tr("%1 has been updated.", "%1 names a file.").arg(file);
             }
             break;
-        case SyncFileStatus::STATUS_RENAME:
+        case LogStatusRename:
             if( count > 1 ) {
                 text = tr("%1 has been renamed to %2 and %3 other files have been renamed.").arg(file).arg(renameTarget).arg(count-1);
             } else {
                 text = tr("%1 has been renamed to %2.", "%1 and %2 name files.").arg(file).arg(renameTarget);
             }
             break;
-        case SyncFileStatus::STATUS_MOVE:
+        case LogStatusMove:
             if( count > 1 ) {
                 text = tr("%1 has been moved to %2 and %3 other files have been moved.").arg(file).arg(renameTarget).arg(count-1);
             } else {
                 text = tr("%1 has been moved to %2.").arg(file).arg(renameTarget);
             }
             break;
-        case SyncFileStatus::STATUS_ERROR:
+        case LogStatusError:
             if( count > 1 ) {
                 text = tr("%1 and %2 other files could not be synced due to errors. See the log for details.", "%1 names a file.").arg(file).arg(count-1);
             } else {
                 text = tr("%1 could not be synced due to an error. See the log for details.").arg(file);
             }
             break;
-        default:
-            break;
         }
 
         if( !text.isEmpty() ) {
diff --git a/src/gui/folder.h b/src/gui/folder.h
index 0603e7a..55035c4 100644
--- a/src/gui/folder.h
+++ b/src/gui/folder.h
@@ -21,7 +21,6 @@
 #include "progressdispatcher.h"
 #include "syncjournaldb.h"
 #include "clientproxy.h"
-#include "syncfilestatus.h"
 #include "networkjobs.h"
 
 #include <csync.h>
@@ -266,7 +265,16 @@ private:
 
     void checkLocalPath();
 
-    void createGuiLog(const QString& filename, SyncFileStatus status, int count,
+    enum LogStatus {
+        LogStatusRemove,
+        LogStatusRename,
+        LogStatusMove,
+        LogStatusNew,
+        LogStatusError,
+        LogStatusUpdated
+    };
+
+    void createGuiLog(const QString& filename, LogStatus status, int count,
                        const QString& renameTarget = QString::null );
 
     AccountStatePtr _accountState;
diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp
index 338fdfb..754291e 100644
--- a/src/gui/socketapi.cpp
+++ b/src/gui/socketapi.cpp
@@ -330,8 +330,7 @@ void SocketApi::command_SHARE(const QString& localFile, QIODevice* socket)
         SyncFileStatus fileStatus = shareFolder->syncEngine().syncFileStatusTracker().fileStatus(file);
 
         // Verify the file is on the server (to our knowledge of course)
-        if (fileStatus.tag() != SyncFileStatus::STATUS_UPTODATE &&
-            fileStatus.tag() != SyncFileStatus::STATUS_UPDATED) {
+        if (fileStatus.tag() != SyncFileStatus::StatusUpToDate) {
             const QString message = QLatin1String("SHARE:NOTSYNCED:")+QDir::toNativeSeparators(localFile);
             sendMessage(socket, message);
             return;
@@ -386,8 +385,7 @@ void SocketApi::command_SHARE_STATUS(const QString &localFile, QIODevice *socket
         SyncFileStatus fileStatus = shareFolder->syncEngine().syncFileStatusTracker().fileStatus(file);
 
         // Verify the file is on the server (to our knowledge of course)
-        if (fileStatus.tag() != SyncFileStatus::STATUS_UPTODATE &&
-            fileStatus.tag() != SyncFileStatus::STATUS_UPDATED) {
+        if (fileStatus.tag() != SyncFileStatus::StatusUpToDate) {
             const QString message = QLatin1String("SHARE_STATUS:NOTSYNCED:")+QDir::toNativeSeparators(localFile);
             sendMessage(socket, message);
             return;
diff --git a/src/gui/socketapi.h b/src/gui/socketapi.h
index f010142..e3f1e48 100644
--- a/src/gui/socketapi.h
+++ b/src/gui/socketapi.h
@@ -17,6 +17,7 @@
 #define SOCKETAPI_H
 
 #include "syncfileitem.h"
+#include "syncfilestatus.h"
 #include "ownsql.h"
 
 #if defined(Q_OS_MAC)
diff --git a/src/libsync/syncengine.cpp b/src/libsync/syncengine.cpp
index 44864d9..3e119fa 100644
--- a/src/libsync/syncengine.cpp
+++ b/src/libsync/syncengine.cpp
@@ -1321,13 +1321,13 @@ bool SyncEngine::estimateState(QString fn, csync_ftw_type_e t, SyncFileStatus* s
                 item->_file == fn || item->_renameTarget == fn /* the same directory or file */) {
             if (item->_status == SyncFileItem::NormalError
                 || item->_status == SyncFileItem::FatalError)
-                s->set(SyncFileStatus::STATUS_ERROR);
+                s->set(SyncFileStatus::StatusError);
             else if (item->_status == SyncFileItem::FileIgnored)
-                s->set(SyncFileStatus::STATUS_IGNORE);
+                s->set(SyncFileStatus::StatusIgnore);
             else if (item->_status == SyncFileItem::Success)
-                s->set(SyncFileStatus::STATUS_UPDATED);
+                s->set(SyncFileStatus::StatusUpToDate);
             else
-                s->set(SyncFileStatus::STATUS_EVAL);
+                s->set(SyncFileStatus::StatusSync);
             qDebug() << Q_FUNC_INFO << "Setting" << fn << "to" << s->toSocketAPIString();
             return true;
         }
diff --git a/src/libsync/syncfilestatus.cpp b/src/libsync/syncfilestatus.cpp
index 313be6d..6d234a3 100644
--- a/src/libsync/syncfilestatus.cpp
+++ b/src/libsync/syncfilestatus.cpp
@@ -17,7 +17,7 @@
 
 namespace OCC {
 SyncFileStatus::SyncFileStatus()
-    :_tag(STATUS_NONE), _sharedWithMe(false)
+    :_tag(StatusNone), _sharedWithMe(false)
 {
 }
 
@@ -53,30 +53,21 @@ QString SyncFileStatus::toSocketAPIString() const
 
     switch(_tag)
     {
-    case STATUS_NONE:
+    case StatusNone:
         statusString = QLatin1String("NONE");
         break;
-    case STATUS_EVAL:
+    case StatusSync:
         statusString = QLatin1String("SYNC");
         break;
-    case STATUS_NEW:
-        statusString = QLatin1String("NEW");
-        break;
-    case STATUS_IGNORE:
+    case StatusIgnore:
         statusString = QLatin1String("IGNORE");
         break;
-    case STATUS_UPTODATE:
-    case STATUS_UPDATED:
+    case StatusUpToDate:
         statusString = QLatin1String("OK");
         break;
-    case STATUS_STAT_ERROR:
-    case STATUS_ERROR:
+    case StatusError:
         statusString = QLatin1String("ERROR");
         break;
-    default:
-        qWarning() << "This status should not be here:" << _tag;
-        Q_ASSERT(false);
-        statusString = QLatin1String("NONE");
     }
     if(_sharedWithMe) {
         statusString += QLatin1String("+SWM");
diff --git a/src/libsync/syncfilestatus.h b/src/libsync/syncfilestatus.h
index 28cb67f..1af254f 100644
--- a/src/libsync/syncfilestatus.h
+++ b/src/libsync/syncfilestatus.h
@@ -28,18 +28,11 @@ class OWNCLOUDSYNC_EXPORT SyncFileStatus
 {
 public:
     enum SyncFileStatusTag {
-        STATUS_NONE,
-        STATUS_EVAL,
-        STATUS_REMOVE,
-        STATUS_RENAME,
-        STATUS_MOVE,
-        STATUS_NEW,
-        STATUS_CONFLICT,
-        STATUS_IGNORE,
-        STATUS_UPTODATE,
-        STATUS_STAT_ERROR,
-        STATUS_ERROR,
-        STATUS_UPDATED
+        StatusNone,
+        StatusSync,
+        StatusIgnore,
+        StatusUpToDate,
+        StatusError,
     };
 
     SyncFileStatus();
diff --git a/src/libsync/syncfilestatustracker.cpp b/src/libsync/syncfilestatustracker.cpp
index 674c608..86da7b3 100644
--- a/src/libsync/syncfilestatustracker.cpp
+++ b/src/libsync/syncfilestatustracker.cpp
@@ -65,10 +65,10 @@ bool SyncFileStatusTracker::estimateState(QString fn, csync_ftw_type_e t, SyncFi
     if (t == CSYNC_FTW_TYPE_DIR) {
         if (Utility::doesSetContainPrefix(_stateLastSyncItemsWithError, fn)) {
             qDebug() << Q_FUNC_INFO << "Folder has error" << fn;
-            s->set(SyncFileStatus::STATUS_ERROR);
+            s->set(SyncFileStatus::StatusError);
             return true;
         }
-        // If sync is running, check _syncedItems, possibly give it STATUS_EVAL (=syncing down)
+        // If sync is running, check _syncedItems, possibly give it StatusSync
         if (_syncEngine->isSyncRunning()) {
             if (_syncEngine->estimateState(fn, t, s)) {
                 return true;
@@ -78,7 +78,7 @@ bool SyncFileStatusTracker::estimateState(QString fn, csync_ftw_type_e t, SyncFi
     } else if ( t== CSYNC_FTW_TYPE_FILE) {
         // check if errorList has the directory/file
         if (Utility::doesSetContainPrefix(_stateLastSyncItemsWithError, fn)) {
-            s->set(SyncFileStatus::STATUS_ERROR);
+            s->set(SyncFileStatus::StatusError);
             return true;
         }
         // If sync running: _syncedItems -> SyncingState
@@ -115,7 +115,7 @@ SyncFileStatus SyncFileStatusTracker::fileStatus(const QString& systemFileName)
     const QFileInfo fi(file);
     if( !FileSystem::fileExists(file, fi) ) {
         qDebug() << "OO File " << file << " is not existing";
-        return SyncFileStatus(SyncFileStatus::STATUS_STAT_ERROR);
+        return SyncFileStatus(SyncFileStatus::StatusError);
     }
 
     // file is ignored?
@@ -126,7 +126,7 @@ SyncFileStatus SyncFileStatusTracker::fileStatus(const QString& systemFileName)
             && fi.suffix() != "lnk"
 #endif
             ) {
-        return SyncFileStatus(SyncFileStatus::STATUS_IGNORE);
+        return SyncFileStatus(SyncFileStatus::StatusIgnore);
     }
 
     csync_ftw_type_e type = CSYNC_FTW_TYPE_FILE;
@@ -136,17 +136,17 @@ SyncFileStatus SyncFileStatusTracker::fileStatus(const QString& systemFileName)
 
     // Is it excluded?
     if( _syncEngine->excludedFiles().isExcluded(file, _syncEngine->localPath(), _syncEngine->ignoreHiddenFiles()) ) {
-        return SyncFileStatus(SyncFileStatus::STATUS_IGNORE);
+        return SyncFileStatus(SyncFileStatus::StatusIgnore);
     }
 
     // Error if it is in the selective sync blacklist
     foreach(const auto &s, _syncEngine->journal()->getSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList)) {
         if (fileNameSlash.startsWith(s)) {
-            return SyncFileStatus(SyncFileStatus::STATUS_ERROR);
+            return SyncFileStatus(SyncFileStatus::StatusError);
         }
     }
 
-    SyncFileStatus status(SyncFileStatus::STATUS_NONE);
+    SyncFileStatus status(SyncFileStatus::StatusNone);
     SyncJournalFileRecord rec = _syncEngine->journal()->getFileRecord(fileName );
 
     if (estimateState(fileName, type, &status)) {
@@ -156,32 +156,33 @@ SyncFileStatus SyncFileStatusTracker::fileStatus(const QString& systemFileName)
         // FIXME: The new parent folder logic should take over this, treating the root the same as any folder.
     } else if (type == CSYNC_FTW_TYPE_DIR) {
         if (rec.isValid()) {
-            status.set(SyncFileStatus::STATUS_UPTODATE);
+            status.set(SyncFileStatus::StatusUpToDate);
         } else {
-            qDebug() << "Could not determine state for folder" << fileName << "will set STATUS_NEW";
-            status.set(SyncFileStatus::STATUS_NEW);
+            qDebug() << "Could not determine state for folder" << fileName << "will set StatusSync";
+            status.set(SyncFileStatus::StatusSync);
         }
     } else if (type == CSYNC_FTW_TYPE_FILE) {
         if (rec.isValid()) {
             if( FileSystem::getModTime(fi.absoluteFilePath()) == Utility::qDateTimeToTime_t(rec._modtime) ) {
-                status.set(SyncFileStatus::STATUS_UPTODATE);
+                status.set(SyncFileStatus::StatusUpToDate);
             } else {
                 if (rec._remotePerm.isNull() || rec._remotePerm.contains("W") ) {
-                    status.set(SyncFileStatus::STATUS_EVAL);
+                    status.set(SyncFileStatus::StatusSync);
                 } else {
-                    status.set(SyncFileStatus::STATUS_ERROR);
+                    status.set(SyncFileStatus::StatusError);
                 }
             }
         } else {
-            qDebug() << "Could not determine state for file" << fileName << "will set STATUS_NEW";
-            status.set(SyncFileStatus::STATUS_NEW);
+            qDebug() << "Could not determine state for file" << fileName << "will set StatusSync";
+            status.set(SyncFileStatus::StatusSync);
         }
     }
 
     if (rec.isValid() && rec._remotePerm.contains("S"))
         status.setSharedWithMe(true);
 
-    if (status.tag() == SyncFileStatus::STATUS_NEW) {
+    // FIXME: Wrong, but will go away
+    if (status.tag() == SyncFileStatus::StatusSync) {
         // check the parent folder if it is shared and if it is allowed to create a file/dir within
         QDir d( fi.path() );
         auto parentPath = d.path();
@@ -199,7 +200,7 @@ SyncFileStatus SyncFileStatusTracker::fileStatus(const QString& systemFileName)
         if( dirRec.isValid() && !dirRec._remotePerm.isNull()) {
             if( (isDir && !dirRec._remotePerm.contains("K"))
                     || (!isDir && !dirRec._remotePerm.contains("C")) ) {
-                status.set(SyncFileStatus::STATUS_ERROR);
+                status.set(SyncFileStatus::StatusError);
             }
         }
     }
@@ -252,7 +253,7 @@ void SyncFileStatusTracker::slotItemDiscovered(const SyncFileItem &item)
         systemFileName += QLatin1Char('/');
     }
 
-    emit fileStatusChanged(systemFileName, SyncFileStatus(SyncFileStatus::STATUS_EVAL));
+    emit fileStatusChanged(systemFileName, SyncFileStatus(SyncFileStatus::StatusSync));
 }
 
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list