summaryrefslogtreecommitdiff
path: root/ui/gridView.h
blob: eaa8ad8ce23239f7418d5620429f24075ca1cc2b (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
#ifndef GRIDVIEW_H_INCLUDED
#define GRIDVIEW_H_INCLUDED

#include "../fileHierarchy.h"


namespace FreeFileSync
{
//gui view of FolderComparison
class GridView
{
public:
    //direct data access via row number
    const FileSystemObject* getObject(unsigned int row) const;  //returns NULL if object is not found; logarithmic complexity
    FileSystemObject* getObject(unsigned int 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<unsigned int>& 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;

        wxULongLong filesizeLeftView;
        wxULongLong 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;

        wxULongLong filesizeLeftView;
        wxULongLong 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_CMP_RESULT,
        SORT_BY_DIRECTORY,
        SORT_BY_SYNC_DIRECTION
    };

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

private:
    class SerializeHierarchy;

    struct RefIndex
    {
        RefIndex(unsigned int folderInd, HierarchyObject::ObjectID id) :
            folderIndex(folderInd),
            objId(id) {}
        unsigned int 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 SortByDirectory;

    template <bool ascending, SelectedSide side>
    class SortByRelName;

    template <bool ascending, SelectedSide side>
    class SortByFileName;

    template <bool ascending, SelectedSide side>
    class SortByFileSize;

    template <bool ascending, SelectedSide side>
    class SortByDate;

    template <bool ascending>
    class SortByCmpResult;

    template <bool ascending>
    class SortBySyncDirection;
};










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

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

inline
FileSystemObject* GridView::getObject(unsigned int 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 FreeFileSync::FileSystemObject* GridView::getReferencedRow(const RefIndex ref) const
{
    return folderCmp[ref.folderIndex].retrieveById(ref.objId);
}


inline
FreeFileSync::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