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
|
// *****************************************************************************
// * 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 CONFIG_HISTORY_3248789479826359832
#define CONFIG_HISTORY_3248789479826359832
#include <wx+/grid.h>
#include <zen/zstring.h>
namespace zen
{
enum class ColumnTypeCfg
{
NAME,
LAST_SYNC,
};
struct ColAttributesCfg
{
ColumnTypeCfg type = ColumnTypeCfg::NAME;
int offset = 0;
int stretch = 0;
bool visible = false;
};
inline
std::vector<ColAttributesCfg> getCfgGridDefaultColAttribs()
{
return
{
{ ColumnTypeCfg::NAME, -75, 1, true },
{ ColumnTypeCfg::LAST_SYNC, 75, 0, true },
};
}
const ColumnTypeCfg cfgGridLastSortColumnDefault = ColumnTypeCfg::NAME;
inline
bool getDefaultSortDirection(ColumnTypeCfg colType)
{
switch (colType)
{
case ColumnTypeCfg::NAME:
return true;
case ColumnTypeCfg::LAST_SYNC: //actual sort order is "time since last sync"
return false;
}
assert(false);
return true;
}
//---------------------------------------------------------------------------------------------------------------------
Zstring getLastRunConfigPath();
class ConfigView
{
public:
ConfigView() {}
void addCfgFiles(const std::vector<Zstring>& filePaths);
void removeItems(const std::vector<Zstring>& filePaths);
void setLastSyncTime(const std::vector<std::pair<Zstring /*filePath*/, time_t /*lastSyncTime*/>>& syncTimes);
struct Details
{
Zstring filePath;
Zstring name;
time_t lastSyncTime = 0;
int lastUseIndex = 0; //support truncating the config list size via last usage, the higher the index the more recent the usage
bool isLastRunCfg = false; //LastRun.ffs_gui
enum ConfigType
{
CFG_TYPE_NONE,
CFG_TYPE_GUI,
CFG_TYPE_BATCH,
} cfgType = CFG_TYPE_NONE;
};
const Details* getItem(size_t row) const;
size_t getRowCount() const { assert(cfgList_.size() == cfgListView_.size()); return cfgListView_.size(); }
void setSortDirection(ColumnTypeCfg colType, bool ascending);
std::pair<ColumnTypeCfg, bool> getSortDirection() { return std::make_pair(sortColumn_, sortAscending_); }
private:
ConfigView (const ConfigView&) = delete;
ConfigView& operator=(const ConfigView&) = delete;
void sortListView();
template <bool ascending> void sortListViewImpl();
const Zstring lastRunConfigPath_ = getLastRunConfigPath(); //let's not use another static...
using CfgFileList = std::map<Zstring /*file path*/, Details, LessFilePath>;
CfgFileList cfgList_;
std::vector<CfgFileList::iterator> cfgListView_; //sorted view on cfgList_
ColumnTypeCfg sortColumn_ = cfgGridLastSortColumnDefault;
bool sortAscending_ = getDefaultSortDirection(cfgGridLastSortColumnDefault);
};
namespace cfggrid
{
void init(Grid& grid);
ConfigView& getDataView(Grid& grid); //grid.Refresh() after making changes!
void addAndSelect(Grid& grid, const std::vector<Zstring>& filePaths, bool scrollToSelection);
int getSyncOverdueDays(Grid& grid);
void setSyncOverdueDays(Grid& grid, int syncOverdueDays);
}
}
#endif //CONFIG_HISTORY_3248789479826359832
|