summaryrefslogtreecommitdiff
path: root/ui/SmallDialogs.cpp
blob: 044560243c965bddafe6f912d1aa7f1dae364bf6 (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
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
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
// **************************************************************************
// * 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-2010 ZenJu (zhnmju123 AT gmx.de)                    *
// **************************************************************************
//
#include "guiGenerated.h"
#include "smallDialogs.h"
#include "messagePopup.h"
#include "../library/resources.h"
#include "../algorithm.h"
#include "../shared/stringConv.h"
#include "../shared/util.h"
#include "../synchronization.h"
#include "../library/customGrid.h"
#include "../shared/customButton.h"
#include "../shared/localization.h"
#include "../shared/globalFunctions.h"
#include "../shared/buildInfo.h"
#include <wx/wupdlock.h>
#include <wx/msgdlg.h>

using namespace FreeFileSync;


class AboutDlg : public AboutDlgGenerated
{
public:
    AboutDlg(wxWindow* window);

private:
    void OnClose(wxCloseEvent& event);
    void OnOK(wxCommandEvent& event);
};


AboutDlg::AboutDlg(wxWindow* window) : AboutDlgGenerated(window)
{
    m_bitmap9->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("website")));
    m_bitmap10->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("email")));
    m_bitmap11->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("logo")));
    m_bitmap13->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("gpl")));

    //create language credits
    for (std::vector<LocInfoLine>::const_iterator i = LocalizationInfo::getMapping().begin(); i != LocalizationInfo::getMapping().end(); ++i)
    {
        //flag
        wxStaticBitmap* staticBitmapFlag = new wxStaticBitmap(m_scrolledWindowTranslators, wxID_ANY, GlobalResources::getInstance().getImageByName(i->languageFlag), wxDefaultPosition, wxSize(-1,11), 0 );
        fgSizerTranslators->Add(staticBitmapFlag, 0, wxALIGN_CENTER_VERTICAL|wxALIGN_CENTER_HORIZONTAL, 5 );

        //language name
        wxStaticText* staticTextLanguage = new wxStaticText(m_scrolledWindowTranslators, wxID_ANY, i->languageName, wxDefaultPosition, wxDefaultSize, 0 );
        staticTextLanguage->Wrap( -1 );
        fgSizerTranslators->Add(staticTextLanguage, 0, wxALIGN_CENTER_VERTICAL, 5);

        //translator name
        wxStaticText* staticTextTranslator = new wxStaticText(m_scrolledWindowTranslators, wxID_ANY, i->translatorName, wxDefaultPosition, wxDefaultSize, 0 );
        staticTextTranslator->Wrap( -1 );
        fgSizerTranslators->Add(staticTextTranslator, 0, wxALIGN_CENTER_VERTICAL, 5);
    }

    bSizerTranslators->Fit(m_scrolledWindowTranslators);


    //build information
    wxString build = wxString(wxT("(")) + _("Build:") + wxT(" ") + __TDATE__;
#if wxUSE_UNICODE
    build += wxT(" - Unicode");
#else
    build += wxT(" - ANSI");
#endif //wxUSE_UNICODE

    //compile time info about 32/64-bit build
    if (Utility::is64BitBuild)
        build += wxT(" x64)");
    else
        build += wxT(" x86)");
    assert_static(Utility::is32BitBuild || Utility::is64BitBuild);


    m_build->SetLabel(build);

    m_animationControl1->SetAnimation(*GlobalResources::getInstance().animationMoney);
    m_animationControl1->Play();

    m_buttonOkay->SetFocus();
    Fit();
}


void AboutDlg::OnClose(wxCloseEvent& event)
{
    EndModal(0);
}


void AboutDlg::OnOK(wxCommandEvent& event)
{
    EndModal(0);
}


void FreeFileSync::showAboutDialog()
{
    AboutDlg* aboutDlg = new AboutDlg(NULL);
    aboutDlg->ShowModal();
    aboutDlg->Destroy();
}
//########################################################################################


class HelpDlg : public HelpDlgGenerated
{
public:
    HelpDlg(wxWindow* window);

private:
    void OnClose(wxCloseEvent& event);
    void OnOK(wxCommandEvent& event);
};


HelpDlg::HelpDlg(wxWindow* window) : HelpDlgGenerated(window)
{
    m_notebook1->SetFocus();

    m_bitmap25->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("help")));

    //populate decision trees: "compare by date"
    wxTreeItemId treeRoot      = m_treeCtrl1->AddRoot(_("DECISION TREE"));
    wxTreeItemId treeBothSides = m_treeCtrl1->AppendItem(treeRoot, _("file exists on both sides"));
    wxTreeItemId treeOneSide   = m_treeCtrl1->AppendItem(treeRoot, _("on one side only"));

    m_treeCtrl1->AppendItem(treeOneSide, _("- left"));
    m_treeCtrl1->AppendItem(treeOneSide, _("- right"));

    m_treeCtrl1->AppendItem(treeBothSides, _("- equal"));
    wxTreeItemId treeDifferent = m_treeCtrl1->AppendItem(treeBothSides, _("different"));

    m_treeCtrl1->AppendItem(treeDifferent, _("- left newer"));
    m_treeCtrl1->AppendItem(treeDifferent, _("- right newer"));
    m_treeCtrl1->AppendItem(treeDifferent, _("- conflict (same date, different size)"));

    m_treeCtrl1->ExpandAll();

    //populate decision trees: "compare by content"
    wxTreeItemId tree2Root      = m_treeCtrl2->AddRoot(_("DECISION TREE"));
    wxTreeItemId tree2BothSides = m_treeCtrl2->AppendItem(tree2Root, _("file exists on both sides"));
    wxTreeItemId tree2OneSide   = m_treeCtrl2->AppendItem(tree2Root, _("on one side only"));

    m_treeCtrl2->AppendItem(tree2OneSide, _("- left"));
    m_treeCtrl2->AppendItem(tree2OneSide, _("- right"));

    m_treeCtrl2->AppendItem(tree2BothSides, _("- equal"));
    m_treeCtrl2->AppendItem(tree2BothSides, _("- different"));

    m_treeCtrl2->ExpandAll();
}


void HelpDlg::OnClose(wxCloseEvent& event)
{
    Destroy();
}


void HelpDlg::OnOK(wxCommandEvent& event)
{
    Destroy();
}


void FreeFileSync::showHelpDialog()
{
    HelpDlg* helpDlg = new HelpDlg(NULL);
    helpDlg->ShowModal();
    helpDlg->Destroy();
}
//########################################################################################


class FilterDlg : public FilterDlgGenerated
{
public:
    FilterDlg(wxWindow* window,
              bool isGlobalFilter,
              Zstring& filterIncl,
              Zstring& filterExcl);
    ~FilterDlg() {}

    enum
    {
        BUTTON_APPLY = 1
    };

private:
    void OnHelp(wxCommandEvent& event);
    void OnDefault(wxCommandEvent& event);
    void OnApply(wxCommandEvent& event);
    void OnCancel(wxCommandEvent& event);
    void OnClose(wxCloseEvent& event);

    const bool isGlobalFilter_;
    Zstring& includeFilter;
    Zstring& excludeFilter;
};


FilterDlg::FilterDlg(wxWindow* window,
                     bool isGlobalFilter, //global or local filter dialog?
                     Zstring& filterIncl,
                     Zstring& filterExcl) :
    FilterDlgGenerated(window),
    isGlobalFilter_(isGlobalFilter),
    includeFilter(filterIncl),
    excludeFilter(filterExcl)
{
    m_bitmap8->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("include")));
    m_bitmap9->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("exclude")));
    m_bitmap26->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("filterOn")));
    m_bpButtonHelp->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("help")));

    m_textCtrlInclude->SetValue(zToWx(includeFilter));
    m_textCtrlExclude->SetValue(zToWx(excludeFilter));

    m_panel13->Hide();
    m_button10->SetFocus();

    //adapt header for global/local dialog
    if (isGlobalFilter_)
        m_staticTexHeader->SetLabel(_("Filter: All pairs"));
    else
        m_staticTexHeader->SetLabel(_("Filter: Single pair"));

    Fit();
}


void FilterDlg::OnHelp(wxCommandEvent& event)
{
    m_bpButtonHelp->Hide();
    m_panel13->Show();
    Fit();
    Refresh();

    event.Skip();
}


void FilterDlg::OnDefault(wxCommandEvent& event)
{
    const FilterConfig nullFilter;

    if (isGlobalFilter_)
    {
        m_textCtrlInclude->SetValue(zToWx(nullFilter.includeFilter));
        //exclude various recycle bin directories with global filter
        m_textCtrlExclude->SetValue(zToWx(standardExcludeFilter()));
    }
    else
    {
        m_textCtrlInclude->SetValue(zToWx(nullFilter.includeFilter));
        m_textCtrlExclude->SetValue(zToWx(nullFilter.excludeFilter));
    }

    //changes to mainDialog are only committed when the OK button is pressed
    Fit();
}


void FilterDlg::OnApply(wxCommandEvent& event)
{
    //only if user presses ApplyFilter, he wants the changes to be committed
    includeFilter = wxToZ(m_textCtrlInclude->GetValue());
    excludeFilter = wxToZ(m_textCtrlExclude->GetValue());

    //when leaving dialog: filter and redraw grid, if filter is active
    EndModal(BUTTON_APPLY);
}


void FilterDlg::OnCancel(wxCommandEvent& event)
{
    EndModal(0);
}


void FilterDlg::OnClose(wxCloseEvent& event)
{
    EndModal(0);
}



DefaultReturnCode::Response FreeFileSync::showFilterDialog(bool isGlobalFilter,
        Zstring& filterIncl,
        Zstring& filterExcl)
{
    DefaultReturnCode::Response rv = DefaultReturnCode::BUTTON_CANCEL;
    FilterDlg* filterDlg = new FilterDlg(NULL,
                                         isGlobalFilter, //is main filter dialog
                                         filterIncl,
                                         filterExcl);
    if (filterDlg->ShowModal() == FilterDlg::BUTTON_APPLY)
        rv = DefaultReturnCode::BUTTON_OKAY;

    filterDlg->Destroy();
    return rv;
}
//########################################################################################


class DeleteDialog : public DeleteDlgGenerated
{
public:
    DeleteDialog(wxWindow* main,
                 const std::vector<FreeFileSync::FileSystemObject*>& rowsOnLeft,
                 const std::vector<FreeFileSync::FileSystemObject*>& rowsOnRight,
                 bool& deleteOnBothSides,
                 bool& useRecycleBin,
                 int& totalDeleteCount);

    enum
    {
        BUTTON_OKAY = 1,
        BUTTON_CANCEL
    };

private:
    void OnOK(wxCommandEvent& event);
    void OnCancel(wxCommandEvent& event);
    void OnClose(wxCloseEvent& event);
    void OnDelOnBothSides(wxCommandEvent& event);
    void OnUseRecycler(wxCommandEvent& event);

    void updateTexts();

    const std::vector<FreeFileSync::FileSystemObject*>& rowsToDeleteOnLeft;
    const std::vector<FreeFileSync::FileSystemObject*>& rowsToDeleteOnRight;
    bool& m_deleteOnBothSides;
    bool& m_useRecycleBin;
    int&  totalDelCount;
};


DeleteDialog::DeleteDialog(wxWindow* main,
                           const std::vector<FileSystemObject*>& rowsOnLeft,
                           const std::vector<FileSystemObject*>& rowsOnRight,
                           bool& deleteOnBothSides,
                           bool& useRecycleBin,
                           int& totalDeleteCount) :
    DeleteDlgGenerated(main),
    rowsToDeleteOnLeft(rowsOnLeft),
    rowsToDeleteOnRight(rowsOnRight),
    m_deleteOnBothSides(deleteOnBothSides),
    m_useRecycleBin(useRecycleBin),
    totalDelCount(totalDeleteCount)
{
    m_checkBoxDeleteBothSides->SetValue(deleteOnBothSides);
    m_checkBoxUseRecycler->SetValue(useRecycleBin);
    updateTexts();

    m_buttonOK->SetFocus();
}


void DeleteDialog::updateTexts()
{
    if (m_checkBoxUseRecycler->GetValue())
    {
        m_staticTextHeader->SetLabel(_("Do you really want to move the following objects(s) to the Recycle Bin?"));
        m_bitmap12->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("recycler")));
    }
    else
    {
        m_staticTextHeader->SetLabel(_("Do you really want to delete the following objects(s)?"));
        m_bitmap12->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("deleteFile")));
    }

    const std::pair<wxString, int> delInfo = FreeFileSync::deleteFromGridAndHDPreview(
                rowsToDeleteOnLeft,
                rowsToDeleteOnRight,
                m_checkBoxDeleteBothSides->GetValue());

    const wxString filesToDelete = delInfo.first;
    totalDelCount = delInfo.second;

    m_textCtrlMessage->SetValue(filesToDelete);

    Layout();
}


void DeleteDialog::OnOK(wxCommandEvent& event)
{
    EndModal(BUTTON_OKAY);
}

void DeleteDialog::OnCancel(wxCommandEvent& event)
{
    EndModal(BUTTON_CANCEL);
}

void DeleteDialog::OnClose(wxCloseEvent& event)
{
    EndModal(BUTTON_CANCEL);
}

void DeleteDialog::OnDelOnBothSides(wxCommandEvent& event)
{
    m_deleteOnBothSides = m_checkBoxDeleteBothSides->GetValue();
    updateTexts();
}

void DeleteDialog::OnUseRecycler(wxCommandEvent& event)
{
    m_useRecycleBin = m_checkBoxUseRecycler->GetValue();
    updateTexts();
}


DefaultReturnCode::Response FreeFileSync::showDeleteDialog(const std::vector<FreeFileSync::FileSystemObject*>& rowsOnLeft,
        const std::vector<FreeFileSync::FileSystemObject*>& rowsOnRight,
        bool& deleteOnBothSides,
        bool& useRecycleBin,
        int& totalDeleteCount)
{
    DefaultReturnCode::Response rv = DefaultReturnCode::BUTTON_CANCEL;

    DeleteDialog* confirmDeletion = new DeleteDialog(NULL,
            rowsOnLeft,
            rowsOnRight,
            deleteOnBothSides,
            useRecycleBin,
            totalDeleteCount);
    if (confirmDeletion->ShowModal() == DeleteDialog::BUTTON_OKAY)
        rv = DefaultReturnCode::BUTTON_OKAY;

    confirmDeletion->Destroy();
    return rv;
}
//########################################################################################


class CustomizeColsDlg : public CustomizeColsDlgGenerated
{
public:
    CustomizeColsDlg(wxWindow* window, xmlAccess::ColumnAttributes& attr);

    enum
    {
        BUTTON_OKAY = 10
    };

private:
    void OnOkay(wxCommandEvent& event);
    void OnDefault(wxCommandEvent& event);
    void OnCancel(wxCommandEvent& event);
    void OnClose(wxCloseEvent& event);

    void OnMoveUp(wxCommandEvent& event);
    void OnMoveDown(wxCommandEvent& event);

    xmlAccess::ColumnAttributes& output;
};


CustomizeColsDlg::CustomizeColsDlg(wxWindow* window, xmlAccess::ColumnAttributes& attr) :
    CustomizeColsDlgGenerated(window),
    output(attr)
{
    m_bpButton29->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("moveUp")));
    m_bpButton30->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("moveDown")));

    xmlAccess::ColumnAttributes columnSettings = attr;

    sort(columnSettings.begin(), columnSettings.end(), xmlAccess::sortByPositionOnly);

    for (xmlAccess::ColumnAttributes::const_iterator i = columnSettings.begin(); i != columnSettings.end(); ++i) //love these iterators!
    {
        m_checkListColumns->Append(CustomGridRim::getTypeName(i->type));
        m_checkListColumns->Check(i - columnSettings.begin(), i->visible);
    }

    m_checkListColumns->SetSelection(0);
    Fit();
}


void CustomizeColsDlg::OnOkay(wxCommandEvent& event)
{
    for (int i = 0; i < int(m_checkListColumns->GetCount()); ++i)
    {
        const wxString label = m_checkListColumns->GetString(i);
        for (xmlAccess::ColumnAttributes::iterator j = output.begin(); j != output.end(); ++j)
        {
            if (CustomGridRim::getTypeName(j->type) == label) //not nice but short and no performance issue
            {
                j->position = i;
                j->visible  = m_checkListColumns->IsChecked(i);;
                break;
            }
        }
    }

    EndModal(BUTTON_OKAY);
}


void CustomizeColsDlg::OnDefault(wxCommandEvent& event)
{
    xmlAccess::ColumnAttributes defaultColumnAttr = CustomGridRim::getDefaultColumnAttributes();

    m_checkListColumns->Clear();
    for (xmlAccess::ColumnAttributes::const_iterator i = defaultColumnAttr.begin(); i != defaultColumnAttr.end(); ++i)
    {
        m_checkListColumns->Append(CustomGridRim::getTypeName(i->type));
        m_checkListColumns->Check(i - defaultColumnAttr.begin(), i->visible);
    }
}


void CustomizeColsDlg::OnCancel(wxCommandEvent& event)
{
    EndModal(0);
}


void CustomizeColsDlg::OnClose(wxCloseEvent& event)
{
    EndModal(0);
}


void CustomizeColsDlg::OnMoveUp(wxCommandEvent& event)
{
    const int pos = m_checkListColumns->GetSelection();
    if (1 <= pos && pos < int(m_checkListColumns->GetCount()))
    {
        const bool checked    = m_checkListColumns->IsChecked(pos);
        const wxString label  = m_checkListColumns->GetString(pos);

        m_checkListColumns->SetString(pos, m_checkListColumns->GetString(pos - 1));
        m_checkListColumns->Check(pos, m_checkListColumns->IsChecked(pos - 1));
        m_checkListColumns->SetString(pos - 1, label);
        m_checkListColumns->Check(pos - 1, checked);
        m_checkListColumns->Select(pos - 1);
    }
}


void CustomizeColsDlg::OnMoveDown(wxCommandEvent& event)
{
    const int pos = m_checkListColumns->GetSelection();
    if (0 <= pos && pos < int(m_checkListColumns->GetCount()) - 1)
    {
        const bool checked    = m_checkListColumns->IsChecked(pos);
        const wxString label  = m_checkListColumns->GetString(pos);

        m_checkListColumns->SetString(pos, m_checkListColumns->GetString(pos + 1));
        m_checkListColumns->Check(pos, m_checkListColumns->IsChecked(pos + 1));
        m_checkListColumns->SetString(pos + 1, label);
        m_checkListColumns->Check(pos + 1, checked);
        m_checkListColumns->Select(pos + 1);
    }
}


DefaultReturnCode::Response FreeFileSync::showCustomizeColsDlg(xmlAccess::ColumnAttributes& attr)
{
    DefaultReturnCode::Response rv = DefaultReturnCode::BUTTON_CANCEL;

    CustomizeColsDlg* customizeDlg = new CustomizeColsDlg(NULL, attr);
    if (customizeDlg->ShowModal() == CustomizeColsDlg::BUTTON_OKAY)
        rv = DefaultReturnCode::BUTTON_OKAY;
    customizeDlg->Destroy();

    return rv;
}
//########################################################################################


class SyncPreviewDlg : public SyncPreviewDlgGenerated
{
public:
    SyncPreviewDlg(wxWindow* parentWindow,
                   const wxString& variantName,
                   const FreeFileSync::SyncStatistics& statistics,
                   bool& dontShowAgain);
    enum
    {
        BUTTON_START  = 1,
        BUTTON_CANCEL = 2
    };

private:
    void OnClose(wxCloseEvent& event);
    void OnCancel(wxCommandEvent& event);
    void OnStartSync(wxCommandEvent& event);

    bool& m_dontShowAgain;
};



SyncPreviewDlg::SyncPreviewDlg(wxWindow* parentWindow,
                               const wxString& variantName,
                               const FreeFileSync::SyncStatistics& statistics,
                               bool& dontShowAgain) :
    SyncPreviewDlgGenerated(parentWindow),
    m_dontShowAgain(dontShowAgain)
{
    using FreeFileSync::numberToWxString;

    m_buttonStartSync->setBitmapFront(GlobalResources::getInstance().getImageByName(wxT("startSync")));
    m_bitmapCreate->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("create")));
    m_bitmapUpdate->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("update")));
    m_bitmapDelete->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("delete")));
    m_bitmapData->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("data")));

    m_staticTextVariant->SetLabel(variantName);
    m_textCtrlData->SetValue(FreeFileSync::formatFilesizeToShortString(statistics.getDataToProcess()));

    m_textCtrlCreateL->SetValue(numberToWxString(statistics.getCreate(   true, false), true));
    m_textCtrlUpdateL->SetValue(numberToWxString(statistics.getOverwrite(true, false), true));
    m_textCtrlDeleteL->SetValue(numberToWxString(statistics.getDelete(   true, false), true));

    m_textCtrlCreateR->SetValue(numberToWxString(statistics.getCreate(   false, true), true));
    m_textCtrlUpdateR->SetValue(numberToWxString(statistics.getOverwrite(false, true), true));
    m_textCtrlDeleteR->SetValue(numberToWxString(statistics.getDelete(   false, true), true));

    m_checkBoxDontShowAgain->SetValue(dontShowAgain);

    m_buttonStartSync->SetFocus();
    Fit();
}


void SyncPreviewDlg::OnClose(wxCloseEvent& event)
{
    EndModal(BUTTON_CANCEL);
}


void SyncPreviewDlg::OnCancel(wxCommandEvent& event)
{
    EndModal(BUTTON_CANCEL);
}


void SyncPreviewDlg::OnStartSync(wxCommandEvent& event)
{
    m_dontShowAgain = m_checkBoxDontShowAgain->GetValue();
    EndModal(BUTTON_START);
}


DefaultReturnCode::Response FreeFileSync::showSyncPreviewDlg(
    const wxString& variantName,
    const FreeFileSync::SyncStatistics& statistics,
    bool& dontShowAgain)
{
    DefaultReturnCode::Response rv = DefaultReturnCode::BUTTON_CANCEL;

    SyncPreviewDlg* preview = new SyncPreviewDlg(NULL,
            variantName,
            statistics,
            dontShowAgain);

    if (preview->ShowModal() == SyncPreviewDlg::BUTTON_START)
        rv = DefaultReturnCode::BUTTON_OKAY;

    preview->Destroy();

    return rv;
}
//########################################################################################


class CompareCfgDialog : public CmpCfgDlgGenerated
{
public:
    CompareCfgDialog(wxWindow* parentWindow,
                     const wxPoint& position,
                     FreeFileSync::CompareVariant& cmpVar,
                     bool& processSymlinks,
                     bool& traverseDirectorySymlinks,
                     bool& copyFileSymlinks);

    enum
    {
        BUTTON_OKAY = 10
    };

private:
    void OnOkay(wxCommandEvent& event);
    void OnClose(wxCloseEvent& event);
    void OnCancel(wxCommandEvent& event);
    void OnTimeSize(wxCommandEvent& event);
    void OnContent(wxCommandEvent& event);
    void OnIncludeSymlinks(wxCommandEvent& event);
    void OnTraverseDirSymlink(wxCommandEvent& event);
    void OnShowHelp(wxCommandEvent& event);

    void updateView();

    FreeFileSync::CompareVariant& cmpVarOut;
    bool& processSymlinksOut;
    bool& traverseDirectorySymlinksOut;
    bool& copyFileSymlinksOut;
};


CompareCfgDialog::CompareCfgDialog(wxWindow* parentWindow,
                                   const wxPoint& position,
                                   CompareVariant& cmpVar,
                                   bool& processSymlinks,
                                   bool& traverseDirectorySymlinks,
                                   bool& copyFileSymlinks) :
    CmpCfgDlgGenerated(parentWindow),
    cmpVarOut(cmpVar),
    processSymlinksOut(processSymlinks),
    traverseDirectorySymlinksOut(traverseDirectorySymlinks),
    copyFileSymlinksOut(copyFileSymlinks)
{
    //move dialog up so that compare-config button and first config-variant are on same level
    Move(wxPoint(position.x, std::max(0, position.y - (m_buttonTimeSize->GetScreenPosition() - GetScreenPosition()).y)));

    m_bpButtonHelp->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("help")));
    m_bitmapByTime->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("cmpByTime")));
    m_bitmapByContent->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("cmpByContent")));

    switch (cmpVar)
    {
    case CMP_BY_TIME_SIZE:
        m_radioBtnSizeDate->SetValue(true);
        m_buttonContent->SetFocus(); //set focus on the other button
        break;
    case CMP_BY_CONTENT:
        m_radioBtnContent->SetValue(true);
        m_buttonTimeSize->SetFocus(); //set focus on the other button
        break;
    }

    m_checkBoxIncludeSymlinks->SetValue(processSymlinksOut);
//    m_checkBoxTraverseDirSymlink->SetValue(traverseDirectorySymlinksOut);
//    m_checkBoxCopyFileSymlink->SetValue(copyFileSymlinksOut);

    updateView();
}

void CompareCfgDialog::updateView()
{
    Fit();
}

void CompareCfgDialog::OnOkay(wxCommandEvent& event)
{
    if (m_radioBtnContent->GetValue())
        cmpVarOut = CMP_BY_CONTENT;
    else
        cmpVarOut = CMP_BY_TIME_SIZE;

    processSymlinksOut           = m_checkBoxIncludeSymlinks->GetValue();
//    traverseDirectorySymlinksOut = m_checkBoxTraverseDirSymlink->GetValue();
//    copyFileSymlinksOut          = m_checkBoxCopyFileSymlink->GetValue();

    //simplify GUI: set reasonable default values for "traverseDirectorySymlinks" and "copyFileSymlinks"
    traverseDirectorySymlinksOut = true;
    copyFileSymlinksOut          = false;

    EndModal(BUTTON_OKAY);
}

void CompareCfgDialog::OnIncludeSymlinks(wxCommandEvent& event)
{
    updateView();
    event.Skip();
}

void CompareCfgDialog::OnTraverseDirSymlink(wxCommandEvent& event)
{
    updateView();
    event.Skip();
}


void CompareCfgDialog::OnClose(wxCloseEvent& event)
{
    EndModal(0);
}


void CompareCfgDialog::OnCancel(wxCommandEvent& event)
{
    EndModal(0);
}


void CompareCfgDialog::OnTimeSize(wxCommandEvent& event)
{
    m_radioBtnSizeDate->SetValue(true);
    OnOkay(event);
}


void CompareCfgDialog::OnContent(wxCommandEvent& event)
{
    m_radioBtnContent->SetValue(true);
    OnOkay(event);
}


void CompareCfgDialog::OnShowHelp(wxCommandEvent& event)
{
    HelpDlg* helpDlg = new HelpDlg(this);
    helpDlg->ShowModal();
}


DefaultReturnCode::Response FreeFileSync::showCompareCfgDialog(
    const wxPoint& position,
    CompareVariant& cmpVar,
    bool& processSymlinks,
    bool& traverseDirectorySymlinks,
    bool& copyFileSymlinks)
{
    CompareCfgDialog syncDlg(NULL, position, cmpVar, processSymlinks, traverseDirectorySymlinks, copyFileSymlinks);

    return syncDlg.ShowModal() == CompareCfgDialog::BUTTON_OKAY ?
           DefaultReturnCode::BUTTON_OKAY :
           DefaultReturnCode::BUTTON_CANCEL;
}
//########################################################################################


class GlobalSettingsDlg : public GlobalSettingsDlgGenerated
{
public:
    GlobalSettingsDlg(wxWindow* window, xmlAccess::XmlGlobalSettings& globalSettings);

    enum
    {
        BUTTON_OKAY = 10
    };

private:
    void OnOkay(wxCommandEvent& event);
    void OnResetDialogs(wxCommandEvent& event);
    void OnDefault(wxCommandEvent& event);
    void OnCancel(wxCommandEvent& event);
    void OnClose(wxCloseEvent& event);
    void OnAddRow(wxCommandEvent& event);
    void OnRemoveRow(wxCommandEvent& event);

    void set(const xmlAccess::ExternalApps& extApp);
    xmlAccess::ExternalApps getExtApp();

    xmlAccess::XmlGlobalSettings& settings;
};


GlobalSettingsDlg::GlobalSettingsDlg(wxWindow* window, xmlAccess::XmlGlobalSettings& globalSettings) :
    GlobalSettingsDlgGenerated(window),
    settings(globalSettings)
{
    m_bitmapSettings->SetBitmap(GlobalResources::getInstance().getImageByName(wxT("settings")));
    m_buttonResetDialogs->setBitmapFront(GlobalResources::getInstance().getImageByName(wxT("warningSmall")), 5);
    m_bpButtonAddRow->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("addFolderPair")));
    m_bpButtonRemoveRow->SetBitmapLabel(GlobalResources::getInstance().getImageByName(wxT("removeFolderPair")));

    m_checkBoxIgnoreOneHour->SetValue(globalSettings.ignoreOneHourDiff);
    m_checkBoxCopyLocked->SetValue(globalSettings.copyLockedFiles);

#ifndef FFS_WIN
    m_checkBoxCopyLocked->Hide();
#endif

    set(globalSettings.gui.externelApplications);

    const wxString toolTip = wxString(_("Integrate external applications into context menu. The following macros are available:")) + wxT("\n\n") +
                             wxT("%name   \t") + _("- full file or directory name") + wxT("\n") +
                             wxT("%dir        \t") + _("- directory part only") + wxT("\n") +
                             wxT("%nameCo \t") + _("- Other side's counterpart to %name") + wxT("\n") +
                             wxT("%dirCo   \t") + _("- Other side's counterpart to %dir");

    m_gridCustomCommand->GetGridWindow()->SetToolTip(toolTip);
    m_gridCustomCommand->GetGridColLabelWindow()->SetToolTip(toolTip);

    m_buttonOkay->SetFocus();

    Fit();
}


void GlobalSettingsDlg::OnOkay(wxCommandEvent& event)
{
    //write global settings only when okay-button is pressed!
    settings.ignoreOneHourDiff = m_checkBoxIgnoreOneHour->GetValue();
    settings.copyLockedFiles   = m_checkBoxCopyLocked->GetValue();

    settings.gui.externelApplications = getExtApp();

    EndModal(BUTTON_OKAY);
}


void GlobalSettingsDlg::OnResetDialogs(wxCommandEvent& event)
{
    QuestionDlg* messageDlg = new QuestionDlg(this,
            QuestionDlg::BUTTON_YES | QuestionDlg::BUTTON_CANCEL,
            _("Re-enable all hidden dialogs?"));

    if (messageDlg->ShowModal() == QuestionDlg::BUTTON_YES)
        settings.optDialogs.resetDialogs();
}


void GlobalSettingsDlg::OnDefault(wxCommandEvent& event)
{
    xmlAccess::XmlGlobalSettings defaultCfg;

    m_checkBoxIgnoreOneHour->SetValue(defaultCfg.ignoreOneHourDiff);
    m_checkBoxCopyLocked->SetValue(defaultCfg.copyLockedFiles);
    set(defaultCfg.gui.externelApplications);
}


void GlobalSettingsDlg::OnCancel(wxCommandEvent& event)
{
    EndModal(0);
}


void GlobalSettingsDlg::OnClose(wxCloseEvent& event)
{
    EndModal(0);
}


void GlobalSettingsDlg::set(const xmlAccess::ExternalApps& extApp)
{
    const int rowCount = m_gridCustomCommand->GetNumberRows();
    if (rowCount > 0)
        m_gridCustomCommand->DeleteRows(0, rowCount);

    m_gridCustomCommand->AppendRows(static_cast<int>(extApp.size()));
    for (xmlAccess::ExternalApps::const_iterator i = extApp.begin(); i != extApp.end(); ++i)
    {
        const int row = i - extApp.begin();
        m_gridCustomCommand->SetCellValue(row, 0, i->first);  //description
        m_gridCustomCommand->SetCellValue(row, 1, i->second); //commandline
    }
    Fit();
}


xmlAccess::ExternalApps GlobalSettingsDlg::getExtApp()
{
    xmlAccess::ExternalApps output;
    for (int i = 0; i < m_gridCustomCommand->GetNumberRows(); ++i)
        output.push_back(
            std::make_pair(m_gridCustomCommand->GetCellValue(i, 0),   //description
                           m_gridCustomCommand->GetCellValue(i, 1))); //commandline
    return output;
}


void GlobalSettingsDlg::OnAddRow(wxCommandEvent& event)
{
    wxWindowUpdateLocker dummy(this); //avoid display distortion

    const int selectedRow = m_gridCustomCommand->GetGridCursorRow();
    if (0 <= selectedRow && selectedRow < m_gridCustomCommand->GetNumberRows())
        m_gridCustomCommand->InsertRows(selectedRow);
    else
        m_gridCustomCommand->AppendRows();

    Fit();
}


void GlobalSettingsDlg::OnRemoveRow(wxCommandEvent& event)
{
    if (m_gridCustomCommand->GetNumberRows() > 0)
    {
        wxWindowUpdateLocker dummy(this); //avoid display distortion

        const int selectedRow = m_gridCustomCommand->GetGridCursorRow();
        if (0 <= selectedRow && selectedRow < m_gridCustomCommand->GetNumberRows())
            m_gridCustomCommand->DeleteRows(selectedRow);
        else
            m_gridCustomCommand->DeleteRows(m_gridCustomCommand->GetNumberRows() - 1);

        Fit();
    }
}


DefaultReturnCode::Response FreeFileSync::showGlobalSettingsDlg(xmlAccess::XmlGlobalSettings& globalSettings)
{
    DefaultReturnCode::Response rv = DefaultReturnCode::BUTTON_CANCEL;

    wxDialog* settingsDlg = new GlobalSettingsDlg(NULL, globalSettings);
    if (settingsDlg->ShowModal() == GlobalSettingsDlg::BUTTON_OKAY)
        rv = DefaultReturnCode::BUTTON_OKAY;

    settingsDlg->Destroy();

    return rv;
}
bgstack15