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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
// **************************************************************************
// * 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) *
// **************************************************************************
//
#include "sync_cfg.h"
#include "../library/resources.h"
#include "../shared/dir_name.h"
#include <wx/wupdlock.h>
#include "../shared/mouse_move_dlg.h"
#include "../shared/string_conv.h"
#include "../shared/dir_picker_i18n.h"
#include "gui_generated.h"
#include <memory>
#include "../shared/wx_choice_enum.h"
#include "../shared/dir_name.h"
using namespace zen;
using namespace xmlAccess;
class SyncCfgDialog : public SyncCfgDlgGenerated
{
public:
SyncCfgDialog(wxWindow* window,
zen::CompareVariant compareVar,
zen::SyncConfig& syncConfiguration,
zen::DeletionPolicy& handleDeletion,
wxString& customDeletionDirectory,
xmlAccess::OnGuiError* handleError); //optional input parameter
~SyncCfgDialog();
private:
virtual void OnSyncAutomatic( wxCommandEvent& event);
virtual void OnSyncMirror( wxCommandEvent& event);
virtual void OnSyncUpdate( wxCommandEvent& event);
virtual void OnSyncCustom( wxCommandEvent& event);
virtual void OnExLeftSideOnly( wxCommandEvent& event);
virtual void OnExRightSideOnly( wxCommandEvent& event);
virtual void OnLeftNewer( wxCommandEvent& event);
virtual void OnRightNewer( wxCommandEvent& event);
virtual void OnDifferent( wxCommandEvent& event);
virtual void OnConflict( wxCommandEvent& event);
virtual void OnClose( wxCloseEvent& event);
virtual void OnCancel( wxCommandEvent& event);
virtual void OnApply( wxCommandEvent& event);
void updateGui();
void OnChangeErrorHandling(wxCommandEvent& event);
void OnChangeDeletionHandling(wxCommandEvent& event);
const zen::CompareVariant cmpVariant;
//temporal copy of maindialog.cfg.syncConfiguration -> ownership NOT within GUI controls!
zen::SyncConfig currentSyncConfig;
//changing data
zen::SyncConfig& refSyncConfiguration;
zen::DeletionPolicy& refHandleDeletion;
wxString& refCustomDeletionDirectory;
xmlAccess::OnGuiError* refHandleError;
zen::DirectoryName customDelFolder;
zen::EnumDescrList<zen::DeletionPolicy> enumDelhandDescr;
zen::EnumDescrList<xmlAccess::OnGuiError> enumErrhandDescr;
};
void updateConfigIcons(const SyncConfig& syncConfig,
wxBitmapButton* buttonLeftOnly,
wxBitmapButton* buttonRightOnly,
wxBitmapButton* buttonLeftNewer,
wxBitmapButton* buttonRightNewer,
wxBitmapButton* buttonDifferent,
wxBitmapButton* buttonConflict,
wxStaticBitmap* bitmapLeftOnly,
wxStaticBitmap* bitmapRightOnly,
wxStaticBitmap* bitmapLeftNewer,
wxStaticBitmap* bitmapRightNewer,
wxStaticBitmap* bitmapDifferent,
wxStaticBitmap* bitmapConflict) //sizer containing all sync-directions
{
if (syncConfig.var != SyncConfig::AUTOMATIC) //automatic mode needs no sync-directions
{
const DirectionSet dirCfg = extractDirections(syncConfig);
switch (dirCfg.exLeftSideOnly)
{
case SYNC_DIR_RIGHT:
buttonLeftOnly->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowRightCr")));
buttonLeftOnly->SetToolTip(getDescription(SO_CREATE_NEW_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonLeftOnly->SetBitmapLabel(GlobalResources::instance().getImage(wxT("deleteLeft")));
buttonLeftOnly->SetToolTip(getDescription(SO_DELETE_LEFT));
break;
case SYNC_DIR_NONE:
buttonLeftOnly->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowNone")));
buttonLeftOnly->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (dirCfg.exRightSideOnly)
{
case SYNC_DIR_RIGHT:
buttonRightOnly->SetBitmapLabel(GlobalResources::instance().getImage(wxT("deleteRight")));
buttonRightOnly->SetToolTip(getDescription(SO_DELETE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonRightOnly->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowLeftCr")));
buttonRightOnly->SetToolTip(getDescription(SO_CREATE_NEW_LEFT));
break;
case SYNC_DIR_NONE:
buttonRightOnly->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowNone")));
buttonRightOnly->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (dirCfg.leftNewer)
{
case SYNC_DIR_RIGHT:
buttonLeftNewer->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowRight")));
buttonLeftNewer->SetToolTip(getDescription(SO_OVERWRITE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonLeftNewer->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowLeft")));
buttonLeftNewer->SetToolTip(getDescription(SO_OVERWRITE_LEFT));
break;
case SYNC_DIR_NONE:
buttonLeftNewer->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowNone")));
buttonLeftNewer->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (dirCfg.rightNewer)
{
case SYNC_DIR_RIGHT:
buttonRightNewer->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowRight")));
buttonRightNewer->SetToolTip(getDescription(SO_OVERWRITE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonRightNewer->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowLeft")));
buttonRightNewer->SetToolTip(getDescription(SO_OVERWRITE_LEFT));
break;
case SYNC_DIR_NONE:
buttonRightNewer->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowNone")));
buttonRightNewer->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (dirCfg.different)
{
case SYNC_DIR_RIGHT:
buttonDifferent->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowRight")));
buttonDifferent->SetToolTip(getDescription(SO_OVERWRITE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonDifferent->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowLeft")));
buttonDifferent->SetToolTip(getDescription(SO_OVERWRITE_LEFT));
break;
case SYNC_DIR_NONE:
buttonDifferent->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowNone")));
buttonDifferent->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (dirCfg.conflict)
{
case SYNC_DIR_RIGHT:
buttonConflict->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowRight")));
buttonConflict->SetToolTip(getDescription(SO_OVERWRITE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonConflict->SetBitmapLabel(GlobalResources::instance().getImage(wxT("arrowLeft")));
buttonConflict->SetToolTip(getDescription(SO_OVERWRITE_LEFT));
break;
case SYNC_DIR_NONE:
buttonConflict->SetBitmapLabel(GlobalResources::instance().getImage(wxT("conflict")));
buttonConflict->SetToolTip(_("Leave as unresolved conflict"));
break;
}
}
}
SyncCfgDialog::SyncCfgDialog(wxWindow* window,
CompareVariant compareVar,
SyncConfig& syncConfiguration,
DeletionPolicy& handleDeletion,
wxString& customDeletionDirectory,
OnGuiError* handleError) :
SyncCfgDlgGenerated(window),
cmpVariant(compareVar),
currentSyncConfig(syncConfiguration), //make working copy of syncConfiguration
refSyncConfiguration(syncConfiguration),
refHandleDeletion(handleDeletion),
refCustomDeletionDirectory(customDeletionDirectory),
refHandleError(handleError),
customDelFolder(*m_panelCustomDeletionDir, *m_dirPickerCustomDelFolder, *m_textCtrlCustomDelFolder)
{
#ifdef FFS_WIN
new zen::MouseMoveWindow(*this); //allow moving main dialog by clicking (nearly) anywhere...; ownership passed to "this"
#endif
enumDelhandDescr.
add(DELETE_PERMANENTLY, _("Delete permanently"), _("Delete or overwrite files permanently")).
add(MOVE_TO_RECYCLE_BIN, _("Use Recycle Bin"), _("Use Recycle Bin when deleting or overwriting files")).
add(MOVE_TO_CUSTOM_DIRECTORY, _("Versioning"), _("Move files into a time-stamped subdirectory"));
enumErrhandDescr.
add(ON_GUIERROR_POPUP, _("Show popup"), _("Show popup on errors or warnings")).
add(ON_GUIERROR_IGNORE, _("Ignore errors"), _("Hide all error and warning messages"));
//a proper set-method may be in order some time...
setEnumVal(enumDelhandDescr, *m_choiceHandleDeletion, handleDeletion);
customDelFolder.setName(customDeletionDirectory);
updateGui();
//error handling
if (handleError)
setEnumVal(enumErrhandDescr, *m_choiceHandleError, *handleError);
else
{
sbSizerErrorHandling->Show(false);
Layout();
}
//set sync config icons
updateGui();
//set icons for this dialog
m_bitmapLeftOnly ->SetBitmap(GlobalResources::instance().getImage(wxT("leftOnly")));
m_bitmapRightOnly ->SetBitmap(GlobalResources::instance().getImage(wxT("rightOnly")));
m_bitmapLeftNewer ->SetBitmap(GlobalResources::instance().getImage(wxT("leftNewer")));
m_bitmapRightNewer->SetBitmap(GlobalResources::instance().getImage(wxT("rightNewer")));
m_bitmapDifferent ->SetBitmap(GlobalResources::instance().getImage(wxT("different")));
m_bitmapConflict ->SetBitmap(GlobalResources::instance().getImage(wxT("conflictGrey")));
m_bitmapDatabase ->SetBitmap(GlobalResources::instance().getImage(wxT("database")));
bSizer201->Layout(); //wxButtonWithImage size might have changed
m_buttonOK->SetFocus();
Fit();
}
//#################################################################################################################
SyncCfgDialog::~SyncCfgDialog() {} //non-inline destructor for std::auto_ptr to work with forward declaration
void SyncCfgDialog::updateGui()
{
//wxWindowUpdateLocker dummy(this); //avoid display distortion
wxWindowUpdateLocker dummy2(m_panelCustomDeletionDir); //avoid display distortion
wxWindowUpdateLocker dummy3(m_bpButtonLeftOnly);
wxWindowUpdateLocker dummy4(m_bpButtonRightOnly);
wxWindowUpdateLocker dummy5(m_bpButtonLeftNewer);
wxWindowUpdateLocker dummy6(m_bpButtonRightNewer);
wxWindowUpdateLocker dummy7(m_bpButtonDifferent);
wxWindowUpdateLocker dummy8(m_bpButtonConflict);
updateConfigIcons(currentSyncConfig,
m_bpButtonLeftOnly,
m_bpButtonRightOnly,
m_bpButtonLeftNewer,
m_bpButtonRightNewer,
m_bpButtonDifferent,
m_bpButtonConflict,
m_bitmapLeftOnly,
m_bitmapRightOnly,
m_bitmapLeftNewer,
m_bitmapRightNewer,
m_bitmapDifferent,
m_bitmapConflict);
//display only relevant sync options
m_bitmapDatabase->Show(true);
sbSizerSyncDirections->Show(true);
if (currentSyncConfig.var == SyncConfig::AUTOMATIC)
{
sbSizerSyncDirections->Show(false);
}
else
{
m_bitmapDatabase->Show(false);
switch (cmpVariant)
{
case CMP_BY_TIME_SIZE:
bSizerDifferent ->Show(false);
break;
case CMP_BY_CONTENT:
bSizerLeftNewer ->Show(false);
bSizerRightNewer->Show(false);
break;
}
}
//set radiobuttons -> have no parameter-ownership at all!
switch (currentSyncConfig.var)
{
case SyncConfig::AUTOMATIC:
m_radioBtnAutomatic->SetValue(true); //automatic mode
break;
case SyncConfig::MIRROR:
m_radioBtnMirror->SetValue(true); //one way ->
break;
case SyncConfig::UPDATE:
m_radioBtnUpdate->SetValue(true); //Update ->
break;
case SyncConfig::CUSTOM:
m_radioBtnCustom->SetValue(true); //custom
break;
}
Layout();
GetSizer()->SetSizeHints(this); //this works like a charm for GTK2 with window resizing problems!!! (includes call to Fit())
m_panelCustomDeletionDir->Enable(getEnumVal(enumDelhandDescr, *m_choiceHandleDeletion) == zen::MOVE_TO_CUSTOM_DIRECTORY);
}
void SyncCfgDialog::OnClose(wxCloseEvent& event)
{
EndModal(0);
}
void SyncCfgDialog::OnCancel(wxCommandEvent& event)
{
EndModal(0);
}
void SyncCfgDialog::OnApply(wxCommandEvent& event)
{
//write configuration to main dialog
refSyncConfiguration = currentSyncConfig;
refHandleDeletion = getEnumVal(enumDelhandDescr, *m_choiceHandleDeletion);
refCustomDeletionDirectory = customDelFolder.getName();
if (refHandleError)
*refHandleError = getEnumVal(enumErrhandDescr, *m_choiceHandleError);
EndModal(ReturnSyncConfig::BUTTON_OKAY);
}
void SyncCfgDialog::OnChangeErrorHandling(wxCommandEvent& event)
{
updateTooltipEnumVal(enumErrhandDescr, *m_choiceHandleError);
}
void SyncCfgDialog::OnChangeDeletionHandling(wxCommandEvent& event)
{
updateTooltipEnumVal(enumDelhandDescr, *m_choiceHandleDeletion);
updateGui();
}
void SyncCfgDialog::OnSyncAutomatic(wxCommandEvent& event)
{
currentSyncConfig.var = SyncConfig::AUTOMATIC;
updateGui();
}
void SyncCfgDialog::OnSyncMirror(wxCommandEvent& event)
{
currentSyncConfig.var = SyncConfig::MIRROR;
updateGui();
}
void SyncCfgDialog::OnSyncUpdate(wxCommandEvent& event)
{
currentSyncConfig.var = SyncConfig::UPDATE;
updateGui();
}
void SyncCfgDialog::OnSyncCustom(wxCommandEvent& event)
{
currentSyncConfig.var = SyncConfig::CUSTOM;
updateGui();
}
void toggleSyncDirection(SyncDirection& current)
{
switch (current)
{
case SYNC_DIR_RIGHT:
current = SYNC_DIR_LEFT;
break;
case SYNC_DIR_LEFT:
current = SYNC_DIR_NONE;
break;
case SYNC_DIR_NONE:
current = SYNC_DIR_RIGHT;
break;
}
}
void pressCustomDir(SyncConfig& syncCfg, SyncDirection& syncdir)
{
switch (syncCfg.var)
{
case SyncConfig::AUTOMATIC:
assert(false);
break;
case SyncConfig::MIRROR:
case SyncConfig::UPDATE:
syncCfg.custom = extractDirections(syncCfg);
syncCfg.var = SyncConfig::CUSTOM;
toggleSyncDirection(syncdir);
break;
case SyncConfig::CUSTOM:
toggleSyncDirection(syncdir);
//some config optimization: if custom settings happen to match "mirror" or "update", just switch variant
DirectionSet currentSet = extractDirections(syncCfg);
DirectionSet setMirror;
DirectionSet setUpdate;
{
SyncConfig mirrorCfg;
mirrorCfg.var = SyncConfig::MIRROR;
setMirror = extractDirections(mirrorCfg);
}
{
SyncConfig updateCfg;
updateCfg.var = SyncConfig::UPDATE;
setUpdate = extractDirections(updateCfg);
}
if (currentSet == setMirror)
syncCfg.var = SyncConfig::MIRROR;
else if (currentSet == setUpdate)
syncCfg.var = SyncConfig::UPDATE;
break;
}
}
void SyncCfgDialog::OnExLeftSideOnly(wxCommandEvent& event )
{
pressCustomDir(currentSyncConfig, currentSyncConfig.custom.exLeftSideOnly);
updateGui();
}
void SyncCfgDialog::OnExRightSideOnly(wxCommandEvent& event )
{
pressCustomDir(currentSyncConfig, currentSyncConfig.custom.exRightSideOnly);
updateGui();
}
void SyncCfgDialog::OnLeftNewer(wxCommandEvent& event )
{
pressCustomDir(currentSyncConfig, currentSyncConfig.custom.leftNewer);
updateGui();
}
void SyncCfgDialog::OnRightNewer(wxCommandEvent& event )
{
pressCustomDir(currentSyncConfig, currentSyncConfig.custom.rightNewer);
updateGui();
}
void SyncCfgDialog::OnDifferent(wxCommandEvent& event )
{
pressCustomDir(currentSyncConfig, currentSyncConfig.custom.different);
updateGui();
}
void SyncCfgDialog::OnConflict(wxCommandEvent& event)
{
pressCustomDir(currentSyncConfig, currentSyncConfig.custom.conflict);
updateGui();
}
ReturnSyncConfig::ButtonPressed zen::showSyncConfigDlg(zen::CompareVariant compareVar,
zen::SyncConfig& syncConfiguration,
zen::DeletionPolicy& handleDeletion,
wxString& customDeletionDirectory,
xmlAccess::OnGuiError* handleError) //optional input parameter
{
SyncCfgDialog syncDlg(NULL,
compareVar,
syncConfiguration,
handleDeletion,
customDeletionDirectory,
handleError);
return static_cast<ReturnSyncConfig::ButtonPressed>(syncDlg.ShowModal());
}
|