1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
// *****************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: https://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
#ifndef GRID_VIEW_H_9285028345703475842569
#define GRID_VIEW_H_9285028345703475842569
#include <vector>
#include <variant>
#include <unordered_map>
#include <zen/stl_tools.h>
#include "file_grid_attr.h"
#include "../base/file_hierarchy.h"
namespace fff
{
class FileView //grid view of FolderComparison
{
public:
FileView() {}
explicit FileView(FolderComparison& folderCmp); //takes weak (non-owning) references
size_t rowsOnView() const { return viewRef_ .size(); } //only visible elements
size_t rowsTotal () const { return sortedRef_.size(); } //total rows available
//returns nullptr if object is not found; complexity: constant!
const FileSystemObject* getFsObject(size_t row) const { return row < viewRef_.size() ? FileSystemObject::retrieve(viewRef_[row].objId) : nullptr; }
/**/ FileSystemObject* getFsObject(size_t row) { return const_cast<FileSystemObject*>(static_cast<const FileView&>(*this).getFsObject(row)); } //see Meyers Effective C++
//references to FileSystemObject: no nullptr-check needed! everything is bound
std::vector<FileSystemObject*> getAllFileRef(const std::vector<size_t>& rows);
struct PathDrawInfo
{
size_t groupFirstRow = 0; //half-open range
size_t groupLastRow = 0; //
const size_t groupIdx = 0;
uint64_t viewUpdateId = 0; //help detect invalid buffers after updateView()
FolderPair* folderGroupObj = nullptr; //nullptr if group is BaseFolderPair (or fsObj not found)
FileSystemObject* fsObj = nullptr; //nullptr if object is not found
};
PathDrawInfo getDrawInfo(size_t row); //complexity: constant!
struct FileStats
{
int fileCount = 0;
int folderCount = 0;
uint64_t bytes = 0;
};
struct DifferenceViewStats
{
int excluded = 0;
int equal = 0;
int conflict = 0;
int leftOnly = 0;
int rightOnly = 0;
int leftNewer = 0;
int rightNewer = 0;
int different = 0;
FileStats fileStatsLeft;
FileStats fileStatsRight;
};
DifferenceViewStats applyDifferenceFilter(bool showExcluded,
bool showLeftOnly,
bool showRightOnly,
bool showLeftNewer,
bool showRightNewer,
bool showDifferent,
bool showEqual,
bool showConflict);
struct ActionViewStats
{
int excluded = 0;
int equal = 0;
int conflict = 0;
int createLeft = 0;
int createRight = 0;
int deleteLeft = 0;
int deleteRight = 0;
int updateLeft = 0;
int updateRight = 0;
int updateNone = 0;
FileStats fileStatsLeft;
FileStats fileStatsRight;
};
ActionViewStats applyActionFilter(bool showExcluded,
bool showCreateLeft,
bool showCreateRight,
bool showDeleteLeft,
bool showDeleteRight,
bool showUpdateLeft,
bool showUpdateRight,
bool showDoNothing,
bool showEqual,
bool showConflict);
void removeInvalidRows(); //remove references to rows that have been deleted meanwhile: call after manual deletion and synchronization!
//sorting...
void sortView(ColumnTypeRim type, ItemPathFormat pathFmt, bool onLeft, bool ascending); //always call these; never sort externally!
void sortView(ColumnTypeCenter type, bool ascending); //
struct SortInfo
{
std::variant<ColumnTypeRim, ColumnTypeCenter> sortCol;
bool onLeft = false; //only use if sortCol is ColumnTypeRim
bool ascending = false;
};
const SortInfo* getSortConfig() const { return zen::get(currentSort_); } //return nullptr if currently not sorted
ptrdiff_t findRowDirect(FileSystemObject::ObjectIdConst objId) const; //find an object's row position on view list directly, return < 0 if not found
ptrdiff_t findRowFirstChild(const ContainerObject* conObj) const; //find first child of FolderPair or BaseFolderPair *on sorted sub view*
//"conObj" may be invalid, it is NOT dereferenced, return < 0 if not found
//count non-empty pairs to distinguish single/multiple folder pair cases
size_t getEffectiveFolderPairCount() const;
private:
FileView (const FileView&) = delete;
FileView& operator=(const FileView&) = delete;
template <class Predicate> void updateView(Predicate pred);
std::unordered_map<FileSystemObject::ObjectIdConst, size_t> rowPositions_; //find row positions on viewRef_ directly
std::unordered_map<const void* /*ContainerObject*/, size_t> rowPositionsFirstChild_; //find first child on sortedRef of a hierarchy object
//void* instead of ContainerObject*: these are weak pointers and should *never be dereferenced*!
struct GroupDetail
{
size_t groupFirstRow = 0;
};
std::vector<GroupDetail> groupDetails_;
uint64_t viewUpdateId_ = 0; //help clients detect invalid buffers after updateView()
struct ViewRow
{
FileSystemObject::ObjectId objId = nullptr;
size_t groupIdx = 0; //...into groupDetails_
};
std::vector<ViewRow> viewRef_; //partial view on sortedRef_
/* /|\
| (applyFilterBy...) */
std::vector<FileSystemObject::ObjectId> sortedRef_; //flat view of weak pointers on folderCmp; may be sorted
/* /|\
| (constructor)
FolderComparison folderCmp */
std::vector<std::tuple<const void* /*BaseFolderPair*/, AbstractPath, AbstractPath>> folderPairs_;
std::optional<SortInfo> currentSort_;
};
}
#endif //GRID_VIEW_H_9285028345703475842569
|