From 4226e548662339ea1ca37b45385a7cf9b237ff1e Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Fri, 18 Apr 2014 17:07:43 +0200 Subject: 3.8 --- ui/gridView.cpp | 121 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 76 insertions(+), 45 deletions(-) (limited to 'ui/gridView.cpp') diff --git a/ui/gridView.cpp b/ui/gridView.cpp index b1ecb9eb..b3b1f2ae 100644 --- a/ui/gridView.cpp +++ b/ui/gridView.cpp @@ -27,6 +27,50 @@ GridView::StatusCmpResult::StatusCmpResult() : foldersOnRightView(0) {} +template +void getNumbers(const FileSystemObject& fsObj, StatusResult& result) +{ + struct GetValues : public FSObjectVisitor + { + GetValues(StatusResult& res) : result_(res) {} + + virtual void visit(const FileMapping& fileObj) + { + if (!fileObj.isEmpty()) + { + result_.filesizeLeftView += fileObj.getFileSize(); + ++result_.filesOnLeftView; + } + if (!fileObj.isEmpty()) + { + result_.filesizeRightView += fileObj.getFileSize(); + ++result_.filesOnRightView; + } + } + + virtual void visit(const SymLinkMapping& linkObj) + { + if (!linkObj.isEmpty()) + ++result_.filesOnLeftView; + + if (!linkObj.isEmpty()) + ++result_.filesOnRightView; + } + + virtual void visit(const DirMapping& dirObj) + { + if (!dirObj.isEmpty()) + ++result_.foldersOnLeftView; + + if (!dirObj.isEmpty()) + ++result_.foldersOnRightView; + } + StatusResult& result_; + } getVal(result); + fsObj.accept(getVal); +} + + GridView::StatusCmpResult GridView::updateCmpResult(bool hideFiltered, //maps sortedRef to viewRef bool leftOnlyFilesActive, bool rightOnlyFilesActive, @@ -82,28 +126,7 @@ GridView::StatusCmpResult GridView::updateCmpResult(bool hideFiltered, //maps so } //calculate total number of bytes for each side - const FileMapping* fileObj = dynamic_cast(fsObj); - if (fileObj) - { - if (!fileObj->isEmpty()) - { - output.filesizeLeftView += fileObj->getFileSize(); - ++output.filesOnLeftView; - } - if (!fileObj->isEmpty()) - { - output.filesizeRightView += fileObj->getFileSize(); - ++output.filesOnRightView; - } - } - else - { - if (!fsObj->isEmpty()) - ++output.foldersOnLeftView; - - if (!fsObj->isEmpty()) - ++output.foldersOnRightView; - } + getNumbers(*fsObj, output); viewRef.push_back(*j); } @@ -196,28 +219,7 @@ GridView::StatusSyncPreview GridView::updateSyncPreview(bool hideFiltered, //map } //calculate total number of bytes for each side - const FileMapping* fileObj = dynamic_cast(fsObj); - if (fileObj) - { - if (!fileObj->isEmpty()) - { - output.filesizeLeftView += fileObj->getFileSize(); - ++output.filesOnLeftView; - } - if (!fileObj->isEmpty()) - { - output.filesizeRightView += fileObj->getFileSize(); - ++output.filesOnRightView; - } - } - else - { - if (!fsObj->isEmpty()) - ++output.foldersOnLeftView; - - if (!fsObj->isEmpty()) - ++output.foldersOnRightView; - } + getNumbers(*fsObj, output); viewRef.push_back(*j); } @@ -279,6 +281,9 @@ public: //add file references std::for_each(hierObj.useSubFiles().begin(), hierObj.useSubFiles().end(), *this); + //add symlink references + std::for_each(hierObj.useSubLinks().begin(), hierObj.useSubLinks().end(), *this); + //add dir references std::for_each(hierObj.useSubDirs().begin(), hierObj.useSubDirs().end(), *this); } @@ -288,6 +293,11 @@ public: sortedRef_.push_back(RefIndex(index_, fileObj.getId())); } + void operator()(const SymLinkMapping& linkObj) + { + sortedRef_.push_back(RefIndex(index_, linkObj.getId())); + } + void operator()(const DirMapping& dirObj) { sortedRef_.push_back(RefIndex(index_, dirObj.getId())); @@ -486,7 +496,28 @@ private: }; //------------------------------------------------------------------------------------------------------- -void GridView::sortView(const SortType type, const bool onLeft, const bool ascending) +bool GridView::getDefaultDirection(SortType type) //true: ascending; false: descending +{ + switch (type) + { + case SORT_BY_FILESIZE: + case SORT_BY_DATE: + return false; + + case SORT_BY_REL_NAME: + case SORT_BY_FILENAME: + case SORT_BY_EXTENSION: + case SORT_BY_CMP_RESULT: + case SORT_BY_DIRECTORY: + case SORT_BY_SYNC_DIRECTION: + return true; + } + assert(false); + return true; +} + + +void GridView::sortView(SortType type, bool onLeft, bool ascending) { viewRef.clear(); -- cgit