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
|
// **************************************************************************
// * 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 "mouse_move_dlg.h"
#include "../shared/string_conv.h"
using namespace ffs3;
SyncCfgDialog::SyncCfgDialog(wxWindow* window,
const CompareVariant compareVar,
SyncConfiguration& syncConfiguration,
DeletionPolicy& handleDeletion,
wxString& customDeletionDirectory,
bool* ignoreErrors) :
SyncCfgDlgGenerated(window),
cmpVariant(compareVar),
currentSyncConfig(syncConfiguration), //make working copy of syncConfiguration
refSyncConfiguration(syncConfiguration),
refHandleDeletion(handleDeletion),
refCustomDeletionDirectory(customDeletionDirectory),
refIgnoreErrors(ignoreErrors),
customDelFolder(new DirectoryName(m_panelCustomDeletionDir, m_dirPickerCustomDelFolder, m_textCtrlCustomDelFolder))
{
#ifdef FFS_WIN
new MouseMoveWindow(*this, //allow moving main dialog by clicking (nearly) anywhere...
this, m_staticText81, m_staticText8, m_staticText101, m_staticText9); //ownership passed to "this"
#endif
setDeletionHandling(handleDeletion);
customDelFolder->setName(wxToZ(customDeletionDirectory));
//error handling
if (ignoreErrors)
setErrorHandling(*ignoreErrors);
else
{
sbSizerErrorHandling->Show(false);
Layout();
}
//set sync config icons
updateConfigIcons(cmpVariant, currentSyncConfig);
//set icons for this dialog
m_bitmapLeftOnly->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("leftOnly")));
m_bitmapRightOnly->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("rightOnly")));
m_bitmapLeftNewer->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("leftNewer")));
m_bitmapRightNewer->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("rightNewer")));
m_bitmapDifferent->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("different")));
m_bitmapConflict->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("conflictGrey")));
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::updateConfigIcons(const ffs3::CompareVariant cmpVar, const ffs3::SyncConfiguration& syncConfig)
{
//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(cmpVar,
syncConfig,
m_bpButtonLeftOnly,
m_bpButtonRightOnly,
m_bpButtonLeftNewer,
m_bpButtonRightNewer,
m_bpButtonDifferent,
m_bpButtonConflict,
m_bitmapLeftOnly,
m_bitmapRightOnly,
m_bitmapLeftNewer,
m_bitmapRightNewer,
m_bitmapDifferent,
m_bitmapConflict,
sbSizerSyncDirections);
//set radiobuttons -> have no parameter-ownership at all!
switch (ffs3::getVariant(currentSyncConfig))
{
case SyncConfiguration::AUTOMATIC:
m_radioBtnAutomatic->SetValue(true); //automatic mode
break;
case SyncConfiguration::MIRROR:
m_radioBtnMirror->SetValue(true); //one way ->
break;
case SyncConfiguration::UPDATE:
m_radioBtnUpdate->SetValue(true); //Update ->
break;
case SyncConfiguration::CUSTOM:
m_radioBtnCustom->SetValue(true); //custom
break;
}
GetSizer()->SetSizeHints(this); //this works like a charm for GTK2 with window resizing problems!!! (includes call to Fit())
}
void SyncCfgDialog::updateConfigIcons(const CompareVariant compareVar,
const SyncConfiguration& 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,
wxSizer* syncDirections) //sizer containing all sync-directions
{
//display only relevant sync options
syncDirections->Show(true);
buttonLeftOnly ->Show(); //
buttonRightOnly ->Show(); //
buttonLeftNewer ->Show(); //
buttonRightNewer->Show(); // enable everything by default
buttonDifferent ->Show(); //
buttonConflict ->Show(); //
bitmapLeftOnly ->Show(); //
bitmapRightOnly ->Show(); //
bitmapLeftNewer ->Show(); //
bitmapRightNewer->Show(); //
bitmapDifferent ->Show(); //
bitmapConflict ->Show(); //
switch (compareVar)
{
case CMP_BY_TIME_SIZE:
buttonDifferent ->Hide();
bitmapDifferent ->Hide();
break;
case CMP_BY_CONTENT:
buttonLeftNewer ->Hide();
buttonRightNewer->Hide();
bitmapLeftNewer ->Hide();
bitmapRightNewer->Hide();
break;
}
if (syncConfig.automatic) //automatic mode needs no sync-directions
syncDirections->Show(false);
switch (syncConfig.exLeftSideOnly)
{
case SYNC_DIR_RIGHT:
buttonLeftOnly->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowRightCr")));
buttonLeftOnly->SetToolTip(getDescription(SO_CREATE_NEW_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonLeftOnly->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("deleteLeft")));
buttonLeftOnly->SetToolTip(getDescription(SO_DELETE_LEFT));
break;
case SYNC_DIR_NONE:
buttonLeftOnly->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowNone")));
buttonLeftOnly->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (syncConfig.exRightSideOnly)
{
case SYNC_DIR_RIGHT:
buttonRightOnly->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("deleteRight")));
buttonRightOnly->SetToolTip(getDescription(SO_DELETE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonRightOnly->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowLeftCr")));
buttonRightOnly->SetToolTip(getDescription(SO_CREATE_NEW_LEFT));
break;
case SYNC_DIR_NONE:
buttonRightOnly->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowNone")));
buttonRightOnly->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (syncConfig.leftNewer)
{
case SYNC_DIR_RIGHT:
buttonLeftNewer->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowRight")));
buttonLeftNewer->SetToolTip(getDescription(SO_OVERWRITE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonLeftNewer->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowLeft")));
buttonLeftNewer->SetToolTip(getDescription(SO_OVERWRITE_LEFT));
break;
case SYNC_DIR_NONE:
buttonLeftNewer->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowNone")));
buttonLeftNewer->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (syncConfig.rightNewer)
{
case SYNC_DIR_RIGHT:
buttonRightNewer->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowRight")));
buttonRightNewer->SetToolTip(getDescription(SO_OVERWRITE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonRightNewer->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowLeft")));
buttonRightNewer->SetToolTip(getDescription(SO_OVERWRITE_LEFT));
break;
case SYNC_DIR_NONE:
buttonRightNewer->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowNone")));
buttonRightNewer->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (syncConfig.different)
{
case SYNC_DIR_RIGHT:
buttonDifferent->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowRight")));
buttonDifferent->SetToolTip(getDescription(SO_OVERWRITE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonDifferent->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowLeft")));
buttonDifferent->SetToolTip(getDescription(SO_OVERWRITE_LEFT));
break;
case SYNC_DIR_NONE:
buttonDifferent->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowNone")));
buttonDifferent->SetToolTip(getDescription(SO_DO_NOTHING));
break;
}
switch (syncConfig.conflict)
{
case SYNC_DIR_RIGHT:
buttonConflict->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowRight")));
buttonConflict->SetToolTip(getDescription(SO_OVERWRITE_RIGHT));
break;
case SYNC_DIR_LEFT:
buttonConflict->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("arrowLeft")));
buttonConflict->SetToolTip(getDescription(SO_OVERWRITE_LEFT));
break;
case SYNC_DIR_NONE:
buttonConflict->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("conflict")));
buttonConflict->SetToolTip(_("Leave as unresolved conflict"));
break;
}
}
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 = getDeletionHandling();
refCustomDeletionDirectory = zToWx(customDelFolder->getName());
if (refIgnoreErrors)
*refIgnoreErrors = getErrorHandling();
EndModal(BUTTON_APPLY);
}
void SyncCfgDialog::updateToolTipErrorHandling(bool ignoreErrors)
{
if (ignoreErrors)
m_choiceHandleError->SetToolTip(_("Hide all error and warning messages"));
else
m_choiceHandleError->SetToolTip(_("Show popup on errors or warnings"));
}
bool SyncCfgDialog::getErrorHandling()
{
if (m_choiceHandleError->GetSelection() == 1) //Ignore errors
return true;
else
return false; // Show popup
}
void SyncCfgDialog::setErrorHandling(bool ignoreErrors)
{
m_choiceHandleError->Clear();
m_choiceHandleError->Append(_("Show popup"));
m_choiceHandleError->Append(_("Ignore errors"));
if (ignoreErrors)
m_choiceHandleError->SetSelection(1);
else
m_choiceHandleError->SetSelection(0);
updateToolTipErrorHandling(ignoreErrors);
}
void SyncCfgDialog::OnChangeErrorHandling(wxCommandEvent& event)
{
updateToolTipErrorHandling(getErrorHandling());
}
//-------------------
void updateToolTipDeletionHandling(wxChoice* choiceHandleError, wxPanel* customDir, const ffs3::DeletionPolicy value)
{
customDir->Disable();
switch (value)
{
case ffs3::DELETE_PERMANENTLY:
choiceHandleError->SetToolTip(_("Delete or overwrite files permanently"));
break;
case ffs3::MOVE_TO_RECYCLE_BIN:
choiceHandleError->SetToolTip(_("Use Recycle Bin when deleting or overwriting files"));
break;
case ffs3::MOVE_TO_CUSTOM_DIRECTORY:
choiceHandleError->SetToolTip(_("Move files into a time-stamped subdirectory"));
customDir->Enable();
break;
}
}
ffs3::DeletionPolicy SyncCfgDialog::getDeletionHandling()
{
switch (m_choiceHandleDeletion->GetSelection())
{
case 0:
return ffs3::DELETE_PERMANENTLY;
case 1:
return ffs3::MOVE_TO_RECYCLE_BIN;
case 2:
return ffs3::MOVE_TO_CUSTOM_DIRECTORY;
default:
assert(false);
return ffs3::MOVE_TO_RECYCLE_BIN;
}
}
void SyncCfgDialog::setDeletionHandling(ffs3::DeletionPolicy newValue)
{
m_choiceHandleDeletion->Clear();
m_choiceHandleDeletion->Append(_("Delete permanently"));
m_choiceHandleDeletion->Append(_("Use Recycle Bin"));
m_choiceHandleDeletion->Append(_("User-defined directory"));
switch (newValue)
{
case ffs3::DELETE_PERMANENTLY:
m_choiceHandleDeletion->SetSelection(0);
break;
case ffs3::MOVE_TO_RECYCLE_BIN:
m_choiceHandleDeletion->SetSelection(1);
break;
case ffs3::MOVE_TO_CUSTOM_DIRECTORY:
m_choiceHandleDeletion->SetSelection(2);
break;
}
updateToolTipDeletionHandling(m_choiceHandleDeletion, m_panelCustomDeletionDir, newValue);
}
void SyncCfgDialog::OnChangeDeletionHandling(wxCommandEvent& event)
{
updateToolTipDeletionHandling(m_choiceHandleDeletion, m_panelCustomDeletionDir, getDeletionHandling());
}
void SyncCfgDialog::OnSyncAutomatic(wxCommandEvent& event)
{
ffs3::setVariant(currentSyncConfig, SyncConfiguration::AUTOMATIC);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
void SyncCfgDialog::OnSyncLeftToRight(wxCommandEvent& event)
{
ffs3::setVariant(currentSyncConfig, SyncConfiguration::MIRROR);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
void SyncCfgDialog::OnSyncUpdate(wxCommandEvent& event)
{
ffs3::setVariant(currentSyncConfig, SyncConfiguration::UPDATE);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
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 SyncCfgDialog::OnExLeftSideOnly(wxCommandEvent& event )
{
toggleSyncDirection(currentSyncConfig.exLeftSideOnly);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
void SyncCfgDialog::OnExRightSideOnly(wxCommandEvent& event )
{
toggleSyncDirection(currentSyncConfig.exRightSideOnly);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
void SyncCfgDialog::OnLeftNewer(wxCommandEvent& event )
{
toggleSyncDirection(currentSyncConfig.leftNewer);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
void SyncCfgDialog::OnRightNewer(wxCommandEvent& event )
{
toggleSyncDirection(currentSyncConfig.rightNewer);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
void SyncCfgDialog::OnDifferent(wxCommandEvent& event )
{
toggleSyncDirection(currentSyncConfig.different);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
void SyncCfgDialog::OnConflict(wxCommandEvent& event)
{
toggleSyncDirection(currentSyncConfig.conflict);
updateConfigIcons(cmpVariant, currentSyncConfig);
}
|