summaryrefslogtreecommitdiff
path: root/ui/grid_view.h
blob: 87d5c38da8f2b63fde9342c0930b0b11a7299c20 (plain)
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html       *
// * Copyright (C) 2008-2011 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************

#ifndef GRIDVIEW_H_INCLUDED
#define GRIDVIEW_H_INCLUDED

#include "../file_hierarchy.h"


namespace zen
{
//gui view of FolderComparison
class GridView
{
public:
    //direct data access via row number
    const FileSystemObject* getObject(size_t row) const;  //returns NULL if object is not found; logarithmic complexity
    FileSystemObject* getObject(size_t row);              //
    size_t rowsOnView() const; //only the currently visible elements
    size_t rowsTotal() const;  //total number of rows available

    //get references to FileSystemObject: no NULL-check needed! Everything's bound.
    void getAllFileRef(const std::set<size_t>& guiRows, std::vector<FileSystemObject*>& output);

    struct StatusCmpResult
    {
        StatusCmpResult();

        bool existsLeftOnly;
        bool existsRightOnly;
        bool existsLeftNewer;
        bool existsRightNewer;
        bool existsDifferent;
        bool existsEqual;
        bool existsConflict;

        unsigned int filesOnLeftView;
        unsigned int foldersOnLeftView;
        unsigned int filesOnRightView;
        unsigned int foldersOnRightView;

        zen::UInt64 filesizeLeftView;
        zen::UInt64 filesizeRightView;
    };

    //comparison results view
    StatusCmpResult updateCmpResult(bool hideFiltered,
                                    bool leftOnlyFilesActive,
                                    bool rightOnlyFilesActive,
                                    bool leftNewerFilesActive,
                                    bool rightNewerFilesActive,
                                    bool differentFilesActive,
                                    bool equalFilesActive,
                                    bool conflictFilesActive);

    struct StatusSyncPreview
    {
        StatusSyncPreview();

        bool existsSyncCreateLeft;
        bool existsSyncCreateRight;
        bool existsSyncDeleteLeft;
        bool existsSyncDeleteRight;
        bool existsSyncDirLeft;
        bool existsSyncDirRight;
        bool existsSyncDirNone;
        bool existsSyncEqual;
        bool existsConflict;

        unsigned int filesOnLeftView;
        unsigned int foldersOnLeftView;
        unsigned int filesOnRightView;
        unsigned int foldersOnRightView;

        zen::UInt64 filesizeLeftView;
        zen::UInt64 filesizeRightView;
    };

    //synchronization preview
    StatusSyncPreview updateSyncPreview(bool hideFiltered,
                                        bool syncCreateLeftActive,
                                        bool syncCreateRightActive,
                                        bool syncDeleteLeftActive,
                                        bool syncDeleteRightActive,
                                        bool syncDirOverwLeftActive,
                                        bool syncDirOverwRightActive,
                                        bool syncDirNoneActive,
                                        bool syncEqualActive,
                                        bool conflictFilesActive);



    FolderComparison& getDataTentative();    //get data for operation that does NOT add or reorder rows! (deletion is okay)
    void setData(FolderComparison& newData); //set data, taking ownership: warning std::swap() is used!!!
    void removeInvalidRows();                 //remove rows that have been deleted meanwhile: call after manual deletion and synchronization!
    void clearAllRows();                      //clears everything

    //sorting...
    enum SortType
    {
        SORT_BY_REL_NAME,
        SORT_BY_FILENAME,
        SORT_BY_FILESIZE,
        SORT_BY_DATE,
        SORT_BY_EXTENSION,
        SORT_BY_CMP_RESULT,
        SORT_BY_DIRECTORY,
        SORT_BY_SYNC_DIRECTION
    };

    bool static getDefaultDirection(SortType type); //true: ascending; false: descending

    void sortView(SortType type, bool onLeft, bool ascending); //always call this method for sorting, never sort externally!

private:
    class SerializeHierarchy;

    struct RefIndex
    {
        RefIndex(size_t folderInd, HierarchyObject::ObjectID id) :
            folderIndex(folderInd),
            objId(id) {}
        size_t folderIndex;
        HierarchyObject::ObjectID objId;
    };

    FileSystemObject* getReferencedRow(const RefIndex ref); //returns NULL if not found
    const FileSystemObject* getReferencedRow(const RefIndex ref) const; //returns NULL if not found
    bool isInvalidRow(const RefIndex& ref) const;


    std::vector<RefIndex> viewRef;  //partial view on sortedRef
    //              |
    //              | (update...)
    //             \|/
    std::vector<RefIndex> sortedRef; //equivalent to folderCmp, but may be sorted
    //              |
    //              | (setData)
    //             \|/
    FolderComparison folderCmp; //actual comparison data: owned by GridView!


    //sorting classes
    template <bool ascending>
    class LessDirectoryPair;

    template <bool ascending, SelectedSide side>
    class LessRelativeName;

    template <bool ascending, SelectedSide side>
    class LessShortFileName;

    template <bool ascending, SelectedSide side>
    class LessFilesize;

    template <bool ascending, SelectedSide side>
    class LessFiletime;

    template <bool ascending, SelectedSide side>
    class LessExtension;

    template <bool ascending>
    class LessCmpResult;

    template <bool ascending>
    class LessSyncDirection;
};










//############################################################################
//inline implementation

inline
const FileSystemObject* GridView::getObject(size_t row) const
{
    if (row < rowsOnView())
        return getReferencedRow(viewRef[row]);
    else
        return NULL;
}

inline
FileSystemObject* GridView::getObject(size_t row)
{
    //code re-use of const method: see Meyers Effective C++
    return const_cast<FileSystemObject*>(static_cast<const GridView&>(*this).getObject(row));
}


inline
size_t GridView::rowsOnView() const
{
    return viewRef.size();
}


inline
FolderComparison& GridView::getDataTentative()
{
    return folderCmp;
}

inline
size_t GridView::rowsTotal() const //total number of rows available
{
    return sortedRef.size();
}


inline
const zen::FileSystemObject* GridView::getReferencedRow(const RefIndex ref) const
{
    return folderCmp[ref.folderIndex].retrieveById(ref.objId);
}


inline
zen::FileSystemObject* GridView::getReferencedRow(const RefIndex ref)
{
    //code re-use of const method: see Meyers Effective C++
    return const_cast<FileSystemObject*>(static_cast<const GridView&>(*this).getReferencedRow(ref));
}
}


#endif // GRIDVIEW_H_INCLUDED
bgstack15