summaryrefslogtreecommitdiff
path: root/ui/MainDialog.h
blob: 46151521ad1c17f0730e77c8aed14d71227573b7 (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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/***************************************************************
 * Name:      FreeFileSyncMain.h
 * Purpose:   Defines Application Frame
 * Author:    ZenJu (zhnmju123@gmx.de)
 * Created:   2008-07-16
 * Copyright: ZenJu ()
 * License:
 **************************************************************/

#ifndef MAINDIALOG_H
#define MAINDIALOG_H

#include "guiGenerated.h"
#include "syncDialog.h"
#include "smallDialogs.h"
#include "../library/resources.h"
#include "../library/misc.h"
#include <wx/dnd.h>
#include <wx/config.h>
#include <stack>
#include "../library/processXml.h"

using namespace std;

//IDs for context menu items
enum ContextItem
{
    CONTEXT_FILTER_TEMP = 10,
    CONTEXT_EXCLUDE_EXT,
    CONTEXT_EXCLUDE_OBJ,
    CONTEXT_CLIPBOARD,
    CONTEXT_EXPLORER,
    CONTEXT_DELETE_FILES
};

extern int leadingPanel; //better keep this an int! event.GetEventObject() does NOT always return m_grid1, m_grid2, m_grid3!

class CompareStatusHandler;
class FileDropEvent;
class TiXmlElement;

class MainDialog : public GuiGenerated
{
    friend class CompareStatusHandler;
    friend class FileDropEvent;

public:
    MainDialog(wxFrame* frame, const wxString& cfgFileName, CustomLocale* language, xmlAccess::XmlGlobalSettings& settings);
    ~MainDialog();

private:
    //configuration load/save
    bool readConfigurationFromXml(const wxString& filename, bool programStartup = false);
    bool writeConfigurationToXml(const wxString& filename);

    void readGlobalSettings();
    void writeGlobalSettings();

    void updateViewFilterButtons();
    void updateFilterButton(wxBitmapButton* filterButton, bool isActive);
    void updateCompareButtons();

    void addCfgFileToHistory(const wxString& filename);

    void addFolderPair(const wxString& leftDir, const wxString& rightDir);
    void removeFolderPair(bool removeAll = false);

    //main method for putting gridData on UI: maps data respecting current view settings
    void writeGrid(const FileCompareResult& gridData);
    void mapGridDataToUI(GridView& output, const FileCompareResult& fileCmpResult);
    void updateStatusInformation(const GridView& output);

    //context menu functions
    set<int> getSelectedRows();
    void filterRangeTemp(const set<int>& rowsToFilterOnUI_View);
    void copySelectionToClipboard(const set<int>& selectedRows, int selectedGrid);
    void openWithFileBrowser(int rowNumber, int gridNr);
    void deleteFilesOnGrid(const set<int>& rowsToDeleteOnUI);

    //work to be done in idle time
    void OnIdleEvent(wxEvent& event);

    //delayed status information restore
    void pushStatusInformation(const wxString& text);
    void clearStatusBar();

    //events
    void onGrid1access(wxEvent& event);
    void onGrid2access(wxEvent& event);
    void onGrid3access(wxEvent& event);

    void onGrid1ButtonEvent(wxKeyEvent& event);
    void onGrid2ButtonEvent(wxKeyEvent& event);
    void onGrid3ButtonEvent(wxKeyEvent& event);
    void OnOpenContextMenu(wxGridEvent& event);

    void OnWriteDirManually(wxCommandEvent& event);
    void OnDirSelected(wxFileDirPickerEvent& event);

    //manual filtering of rows:
    void OnGridSelectCell(wxGridEvent& event);
    void OnGrid3LeftMouseUp(wxEvent& event);
    void OnGrid3LeftMouseDown(wxEvent& event);

    void onContextMenuSelection(wxCommandEvent& event);

    void OnLeftGridDoubleClick( wxGridEvent& event);
    void OnRightGridDoubleClick(wxGridEvent& event);
    void OnSortLeftGrid(        wxGridEvent& event);
    void OnSortRightGrid(       wxGridEvent& event);

    void OnLeftOnlyFiles(       wxCommandEvent& event);
    void OnLeftNewerFiles(      wxCommandEvent& event);
    void OnDifferentFiles(      wxCommandEvent& event);
    void OnRightNewerFiles(     wxCommandEvent& event);
    void OnRightOnlyFiles(      wxCommandEvent& event);
    void OnEqualFiles(          wxCommandEvent& event);

    void OnSaveConfig(          wxCommandEvent& event);
    void OnLoadConfig(          wxCommandEvent& event);
    void loadConfiguration(const wxString& filename);
    void OnChoiceKeyEvent(      wxKeyEvent& event );

    void onResizeMainWindow(    wxEvent& event);
    void OnAbortCompare(        wxCommandEvent& event);
    void OnFilterButton(        wxCommandEvent& event);
    void OnHideFilteredButton(  wxCommandEvent& event);
    void OnConfigureFilter(     wxHyperlinkEvent& event);
    void OnShowHelpDialog(      wxCommandEvent& event);
    void OnSwapDirs(            wxCommandEvent& event);
    void OnCompareByTimeSize(   wxCommandEvent& event);
    void OnCompareByContent(    wxCommandEvent& event);
    void OnCompare(             wxCommandEvent& event);
    void OnSync(                wxCommandEvent& event);
    void OnClose(               wxCloseEvent&   event);
    void OnQuit(                wxCommandEvent& event);

    void OnAddFolderPair(       wxCommandEvent& event);
    void OnRemoveFolderPair(    wxCommandEvent& event);

    //menu events
    void OnMenuSaveConfig(      wxCommandEvent& event);
    void OnMenuLoadConfig(      wxCommandEvent& event);
    void OnMenuExportFileList(  wxCommandEvent& event);
    void OnMenuAdjustFileTimes( wxCommandEvent& event);
    void OnMenuBatchJob(        wxCommandEvent& event);
    void OnMenuAbout(           wxCommandEvent& event);
    void OnMenuQuit(            wxCommandEvent& event);
    void OnMenuLangEnglish(     wxCommandEvent& event);
    void OnMenuLangGerman(      wxCommandEvent& event);
    void OnMenuLangFrench(      wxCommandEvent& event);
    void OnMenuLangJapanese(    wxCommandEvent& event);
    void OnMenuLangDutch(       wxCommandEvent& event);

    void enableSynchronization(bool value);

//***********************************************
    //application variables are stored here:

    //global settings used by GUI and batch mode
    xmlAccess::XmlGlobalSettings& globalSettings;

    //technical representation of grid-data
    FileCompareResult currentGridData;

    //UI view of currentGridData
    GridView gridRefUI;

//-------------------------------------
    //functional configuration
    MainConfiguration cfg;

    //folder pairs:
    //m_directoryLeft, m_directoryRight
    vector<FolderPairGenerated*> additionalFolderPairs; //additional pairs to the standard pair

    //gui settings
    int widthNotMaximized;
    int heightNotMaximized;
    int posXNotMaximized;
    int posYNotMaximized;
    bool hideFilteredElements;
//-------------------------------------

    //convenience method to get all folder pairs (unformatted)
    void getFolderPairs(vector<FolderPair>& output,  bool formatted = false);

    //UI View Filter settings
    bool leftOnlyFilesActive;
    bool leftNewerFilesActive;
    bool differentFilesActive;
    bool equalFilesActive;
    bool rightNewerFilesActive;
    bool rightOnlyFilesActive;

//***********************************************
    wxMenu* contextMenu;

    CustomLocale* programLanguage;

    //status information
    wxLongLong lastStatusChange;
    stack<wxString> stackObjects;

    //compare status panel (hidden on start, shown when comparing)
    CompareStatus* compareStatus;

    //save the last used config filenames
    wxConfig* cfgFileHistory;
    vector<wxString> cfgFileNames;
    static const int CfgHistroyLength = 10;

    //variables for filtering of m_grid3
    bool filteringInitialized;
    bool filteringPending;

    //temporal variables used by exclude via context menu
    wxString exFilterCandidateExtension;
    struct FilterObject
    {
        wxString relativeName;
        FileDescrLine::ObjectType type;
    };
    vector<FilterObject> exFilterCandidateObj;

    bool synchronizationEnabled; //determines whether synchronization should be allowed

    bool restartOnExit; //restart dialog on exit (currently used, when language is changed)

    CompareStatusHandler* cmpStatusHandlerTmp;  //used only by the abort button when comparing
};

//######################################################################################


class FileDropEvent : public wxFileDropTarget
{
public:
    FileDropEvent(MainDialog* dlg, const wxPanel* obj) :
            mainDlg(dlg),
            dropTarget(obj)
    {}

    ~FileDropEvent() {}

    //overwritten virtual method
    bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames);

private:
    MainDialog* mainDlg;
    const wxPanel* dropTarget;
};

//######################################################################################

//classes handling sync and compare error as well as status information

class CompareStatusHandler : public StatusHandler
{
public:
    CompareStatusHandler(MainDialog* dlg);
    ~CompareStatusHandler();

    void updateStatusText(const wxString& text);
    void initNewProcess(int objectsTotal, double dataTotal, Process processID);
    void updateProcessedData(int objectsProcessed, double dataProcessed);
    ErrorHandler::Response reportError(const wxString& text);

    void forceUiRefresh();

private:
    void abortThisProcess();

    MainDialog* mainDialog;
    bool ignoreErrors;
    Process currentProcess;
};


class SyncStatusHandler : public StatusHandler
{
public:
    SyncStatusHandler(wxWindow* dlg, bool ignoreAllErrors);
    ~SyncStatusHandler();

    void updateStatusText(const wxString& text);
    void initNewProcess(int objectsTotal, double dataTotal, Process processID);
    void updateProcessedData(int objectsProcessed, double dataProcessed);
    ErrorHandler::Response reportError(const wxString& text);

    void forceUiRefresh();

private:
    void abortThisProcess();

    SyncStatus* syncStatusFrame;
    bool ignoreErrors;
    wxArrayString unhandledErrors;   //list of non-resolved errors
};


#endif // MAINDIALOG_H
bgstack15