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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
#include "smallDialogs.h"
#include "../library/globalFunctions.h"
//#include <fstream>
#include "../library/resources.h"
using namespace globalFunctions;
AboutDlg::AboutDlg(wxWindow* window) : AboutDlgGenerated(window)
{
m_bitmap9->SetBitmap(*GlobalResources::bitmapWebsite);
m_bitmap10->SetBitmap(*GlobalResources::bitmapEmail);
m_bitmap11->SetBitmap(*GlobalResources::bitmapLogo);
m_bitmap13->SetBitmap(*GlobalResources::bitmapGPL);
//build information
wxString build = wxString(_("(Build: ")) + __TDATE__;
#if wxUSE_UNICODE
build+= wxT(" - Unicode");
#else
build+= wxT(" - ANSI");
#endif //wxUSE_UNICODE
build+= + wxT(")");
m_build->SetLabel(build);
m_animationControl1->SetAnimation(*GlobalResources::animationMoney);
m_animationControl1->Play(); //Note: The animation is created hidden(!) to not disturb constraint based window creation;
m_animationControl1->Show(); //an empty animation consumes a lot of space that later is NOT removed anymore.
m_button8->SetFocus();
}
AboutDlg::~AboutDlg() {}
void AboutDlg::OnClose(wxCloseEvent& event)
{
Destroy();
}
void AboutDlg::OnOK(wxCommandEvent& event)
{
Destroy();
}
//########################################################################################
HelpDlg::HelpDlg(wxWindow* window) : HelpDlgGenerated(window)
{
m_button8->SetFocus();
}
HelpDlg::~HelpDlg() {}
void HelpDlg::OnClose(wxCloseEvent& event)
{
Destroy();
}
void HelpDlg::OnOK(wxCommandEvent& event)
{
Destroy();
}
//########################################################################################
FilterDlg::FilterDlg(wxWindow* window, wxString& filterIncl, wxString& filterExcl) :
FilterDlgGenerated(window),
includeFilter(filterIncl),
excludeFilter(filterExcl)
{
m_bitmap8->SetBitmap(*GlobalResources::bitmapInclude);
m_bitmap9->SetBitmap(*GlobalResources::bitmapExclude);
m_textCtrlInclude->SetValue(includeFilter);
m_textCtrlExclude->SetValue(excludeFilter);
}
FilterDlg::~FilterDlg() {}
void FilterDlg::OnClose(wxCloseEvent& event)
{
EndModal(0);
}
void FilterDlg::OnOK(wxCommandEvent& event)
{
//only if user presses ApplyFilter, he wants the changes to be committed
includeFilter = m_textCtrlInclude->GetValue();
excludeFilter = m_textCtrlExclude->GetValue();
//when leaving dialog: filter and redraw grid, if filter is active
EndModal(okayButtonPressed);
}
void FilterDlg::OnCancel(wxCommandEvent& event)
{
EndModal(0);
}
void FilterDlg::OnDefault(wxCommandEvent& event)
{
m_textCtrlInclude->SetValue("*");
m_textCtrlExclude->SetValue("");
//changes to mainDialog are only committed when the OK button is pressed
event.Skip();
}
//########################################################################################
DeleteDialog::DeleteDialog(const wxString& headerText, const wxString& messageText, wxWindow* main) :
DeleteDlgGenerated(main)
{
m_staticTextHeader->SetLabel(headerText);
m_textCtrlMessage->SetValue(messageText);
m_bitmap12->SetBitmap(*GlobalResources::bitmapDeleteFile);
m_buttonOK->SetFocus();
}
DeleteDialog::~DeleteDialog() {}
void DeleteDialog::OnOK(wxCommandEvent& event)
{
EndModal(okayButtonPressed);
}
void DeleteDialog::OnCancel(wxCommandEvent& event)
{
EndModal(cancelButtonPressed);
}
void DeleteDialog::OnClose(wxCloseEvent& event)
{
EndModal(cancelButtonPressed);
}
//########################################################################################
ErrorDlg::ErrorDlg(const wxString messageText, bool& continueError) :
ErrorDlgGenerated(0),
continueOnError(continueError)
{
m_bitmap10->SetBitmap(*GlobalResources::bitmapWarning);
m_textCtrl8->SetValue(messageText);
m_buttonContinue->SetFocus();
}
ErrorDlg::~ErrorDlg() {}
void ErrorDlg::OnClose(wxCloseEvent& event)
{
//continueOnError = m_checkBoxContinueError->GetValue(); -> not needed here
EndModal(abortButtonPressed);
}
void ErrorDlg::OnContinue(wxCommandEvent& event)
{
continueOnError = m_checkBoxContinueError->GetValue();
EndModal(continueButtonPressed);
}
void ErrorDlg::OnRetry(wxCommandEvent& event)
{
//continueOnError = m_checkBoxContinueError->GetValue(); -> not needed here
EndModal(retryButtonPressed);
}
void ErrorDlg::OnAbort(wxCommandEvent& event)
{
//continueOnError = m_checkBoxContinueError->GetValue(); -> not needed here
EndModal(abortButtonPressed);
}
//########################################################################################
/*
class for calculation of remaining time:
----------------------------------------
"filesize |-> time" is an affine linear function f(x) = z_1 + z_2 x
For given n measurements, sizes x_0, ..., x_n and times f_0, ..., f_n, the function f (as a polynom of degree 1) can be lineary approximated by
z_1 = (r - s * q / p) / ((n + 1) - s * s / p)
z_2 = (q - s * z_1) / p = (r - (n + 1) z_1) / s
with
p := x_0^2 + ... + x_n^2
q := f_0 x_0 + ... + f_n x_n
r := f_0 + ... + f_n
s := x_0 + ... + x_n
=> the time to process N files with amount of data D is: N * z_1 + D * z_2
Problem:
--------
Times f_0, ..., f_n can be very small so that precision of the PC clock is poor.
=> Times have to be accumulated to enhance precision:
Copying of m files with sizes x_i and times f_i (i = 1, ..., m) takes sum_i f(x_i) := m * z_1 + z_2 * sum x_i = sum f_i
With X defined as the accumulated sizes and F the accumulated times this gives: (in theory...)
m * z_1 + z_2 * X = F <=>
z_1 + z_2 * X / m = F / m
=> we optain a new (artificial) measurement with size X / m and time F / m to be used in the linear approximation above
RemainingTime::RemainingTime() : n(0), m(0), X(0), F(0), p(0), q(0), r(0), s(0), z_1(0), z_2(0), lastExec(0) {}
RemainingTime::~RemainingTime()
{
ofstream output("test.txt");
for (unsigned i = 0; i < x.size(); ++i)
{
output<<x[i]<<" "<<f[i]<<'\n';
}
output<<'\n'<<z_1<<" "<<z_2<<'\n';
output.close();
}
wxLongLong RemainingTime::getRemainingTime(double processedDataSinceLastCall, int remainingFiles, double remainingData) //returns the remaining time in seconds
{
wxLongLong newExec = wxGetLocalTimeMillis();
if (lastExec != 0)
{
X+= processedDataSinceLastCall;
F = (newExec - lastExec).ToDouble();
++m;
if (F > 1000) //add new measurement only if F is accumulated to a certain degree
{
lastExec = newExec;
++n;
double x_i = X / m;
double f_i = F / m;
X = 0;
F = 0;
m = 0;
x.push_back(x_i);
f.push_back(f_i);
p+= x_i * x_i;
q+= f_i * x_i;
r+= f_i;
s+= x_i;
if (p != 0)
{
double tmp = (n - s * s / p);
if (tmp != 0 && s != 0)
{ //recalculate coefficients for affine-linear function
z_1 = (r - s * q / p) / tmp;
z_2 = (r - n * z_1) / s; //not (n + 1) here, since n already is the number of measurements
}
}
}
return int(remainingFiles * z_1 + remainingData * z_2);
}
//else
lastExec = newExec;
return 0;
}*/
//########################################################################################
SyncStatus::SyncStatus(StatusUpdater* updater, wxWindow* parentWindow) :
SyncStatusDlgGenerated(parentWindow),
currentStatusUpdater(updater),
windowToDis(parentWindow),
currentProcessIsRunning(true),
totalData(0),
currentData(0),
scalingFactor(0),
currentObjects(0),
totalObjects(0),
processPaused(false)
{
m_animationControl1->SetAnimation(*GlobalResources::animationSync);
m_animationControl1->Play();
//initialize gauge
m_gauge1->SetRange(50000);
m_gauge1->SetValue(0);
m_buttonAbort->SetFocus();
if (windowToDis) //disable (main) window while this status dialog is shown
windowToDis->Disable();
}
SyncStatus::~SyncStatus()
{
if (windowToDis)
{
windowToDis->Enable();
windowToDis->Raise();
windowToDis->SetFocus();
}
}
void SyncStatus::resetGauge(int totalObjectsToProcess, double totalDataToProcess)
{
currentData = 0;
totalData = totalDataToProcess;
currentObjects = 0;
totalObjects = totalObjectsToProcess;
if (totalData != 0)
scalingFactor = 50000 / totalData; //let's normalize to 50000
else
scalingFactor = 0;
}
void SyncStatus::incProgressIndicator_NoUpdate(int objectsProcessed, double dataProcessed)
{
currentData+= dataProcessed;
currentObjects+= objectsProcessed;
}
void SyncStatus::setStatusText_NoUpdate(const wxString& text)
{
currentStatusText = text;
}
void SyncStatus::updateStatusDialogNow()
{
//progress indicator
m_gauge1->SetValue(int(currentData * scalingFactor));
//status text
m_textCtrlInfo->SetValue(currentStatusText);
//remaining objects
m_staticTextRemainingObj->SetLabel(numberToWxString(totalObjects - currentObjects));
//remaining bytes left for copy
const wxString remainingBytes = FreeFileSync::formatFilesizeToShortString(totalData - currentData);
m_staticTextDataRemaining->SetLabel(remainingBytes);
//do the ui update
bSizer28->Layout();
updateUI_Now();
//support for pause button
while (processPaused && currentProcessIsRunning)
{
wxMilliSleep(UI_UPDATE_INTERVAL);
updateUI_Now();
}
}
void SyncStatus::setCurrentStatus(SyncStatusID id)
{
switch (id)
{
case ABORTED:
m_bitmapStatus->SetBitmap(*GlobalResources::bitmapStatusError);
m_staticTextStatus->SetLabel(_("Aborted"));
break;
case FINISHED_WITH_SUCCESS:
m_bitmapStatus->SetBitmap(*GlobalResources::bitmapStatusSuccess);
m_staticTextStatus->SetLabel(_("Completed"));
break;
case FINISHED_WITH_ERROR:
m_bitmapStatus->SetBitmap(*GlobalResources::bitmapStatusWarning);
m_staticTextStatus->SetLabel(_("Completed"));
break;
case PAUSE:
m_bitmapStatus->SetBitmap(*GlobalResources::bitmapStatusPause);
m_staticTextStatus->SetLabel(_("Pause"));
break;
case SCANNING:
m_bitmapStatus->SetBitmap(*GlobalResources::bitmapStatusComparing);
m_staticTextStatus->SetLabel(_("Scanning..."));
break;
case COMPARING:
m_bitmapStatus->SetBitmap(*GlobalResources::bitmapStatusComparing);
m_staticTextStatus->SetLabel(_("Comparing..."));
break;
case SYNCHRONIZING:
m_bitmapStatus->SetBitmap(*GlobalResources::bitmapStatusSyncing);
m_staticTextStatus->SetLabel(_("Synchronizing..."));
break;
}
}
void SyncStatus::processHasFinished(SyncStatusID id) //essential to call this in StatusUpdater derived class destructor
{ //at the LATEST(!) to prevent access to currentStatusUpdater
currentProcessIsRunning = false; //enable okay and close events; may be set ONLY in this method
setCurrentStatus(id);
m_buttonAbort->Disable();
m_buttonAbort->Hide();
m_buttonPause->Disable();
m_buttonPause->Hide();
m_buttonOK->Show();
m_buttonOK->SetFocus();
m_animationControl1->Stop();
//m_animationControl1->SetInactiveBitmap(*GlobalResources::bitmapFinished);
m_animationControl1->Hide();
updateStatusDialogNow(); //keep this sequence to avoid display distortion, if e.g. only 1 item is sync'ed
Layout(); //
}
void SyncStatus::OnOkay(wxCommandEvent& event)
{
if (!currentProcessIsRunning) Destroy();
}
void SyncStatus::OnPause(wxCommandEvent& event)
{
if (processPaused)
{
processPaused = false;
m_buttonPause->SetLabel(_("Pause"));
m_animationControl1->Play();
}
else
{
processPaused = true;
m_buttonPause->SetLabel(_("Continue"));
m_animationControl1->Stop();
}
}
void SyncStatus::OnAbort(wxCommandEvent& event)
{
processPaused = false;
if (currentProcessIsRunning) currentStatusUpdater->requestAbortion();
}
void SyncStatus::OnClose(wxCloseEvent& event)
{
processPaused = false;
if (currentProcessIsRunning) currentStatusUpdater->requestAbortion();
else
Destroy();
}
//########################################################################################
CompareStatus::CompareStatus(wxWindow* parentWindow) :
CompareStatusGenerated(parentWindow),
scannedFiles(0),
totalCmpData(0),
processedCmpData(0),
scalingFactorCmp(0),
processedCmpObjects(0),
totalCmpObjects(0)
/*timeRemaining(0),
timeRemainingTimeStamp(0)*/
{ //initialize gauge
m_gauge2->SetRange(50000);
m_gauge2->SetValue(0);
//initially hide status that's relevant for comparing bytewise only
bSizer42->Hide(sbSizer13);
bSizer42->Hide(sbSizer11);
bSizer42->Layout();
}
CompareStatus::~CompareStatus() {}
void CompareStatus::resetCmpGauge(int totalCmpObjectsToProcess, double totalCmpDataToProcess)
{
processedCmpData = 0;
totalCmpData = totalCmpDataToProcess;
processedCmpObjects = 0;
totalCmpObjects = totalCmpObjectsToProcess;
if (totalCmpData != 0)
scalingFactorCmp = 50000 / totalCmpData; //let's normalize to 50000
else
scalingFactorCmp = 0;
//show status for comparing bytewise
bSizer42->Show(sbSizer13);
bSizer42->Show(sbSizer11);
bSizer42->Layout();
}
void CompareStatus::incScannedFiles_NoUpdate(int number)
{
scannedFiles+= number;
}
void CompareStatus::incProcessedCmpData_NoUpdate(int objectsProcessed, double dataProcessed)
{
processedCmpData+= dataProcessed;
processedCmpObjects+= objectsProcessed;
/* timeRemaining = calcTimeLeft.getRemainingTime(dataProcessed, totalCmpObjects - processedCmpObjects, totalCmpData - processedCmpData);
timeRemainingTimeStamp = wxGetLocalTimeMillis();*/
}
void CompareStatus::setStatusText_NoUpdate(const wxString& text)
{
currentStatusText = text;
}
void CompareStatus::updateStatusPanelNow()
{
//status texts
m_textCtrlFilename->SetValue(currentStatusText);
m_staticTextScanned->SetLabel(numberToWxString(scannedFiles));
//progress indicator for "compare file content"
m_gauge2->SetValue(int(processedCmpData * scalingFactorCmp));
//remaining file to compare
m_staticTextFilesToCompare->SetLabel(numberToWxString(totalCmpObjects - processedCmpObjects));
//remaining bytes left for file comparison
const wxString remainingBytes = FreeFileSync::formatFilesizeToShortString(totalCmpData - processedCmpData);
m_staticTextDataToCompare->SetLabel(remainingBytes);
/*
//remaining time in seconds
if (timeRemaining != 0)
{
int time = ((timeRemaining - (wxGetLocalTimeMillis() - timeRemainingTimeStamp)) / 1000).GetLo();
m_staticTextRemainingTime->SetLabel(numberToWxString(time) + " s");
}
*/
//do the ui update
bSizer42->Layout();
updateUI_Now();
}
|