diff options
Diffstat (limited to 'ui/sync_cfg.cpp')
-rw-r--r-- | ui/sync_cfg.cpp | 269 |
1 files changed, 122 insertions, 147 deletions
diff --git a/ui/sync_cfg.cpp b/ui/sync_cfg.cpp index 794569cc..d8d238b3 100644 --- a/ui/sync_cfg.cpp +++ b/ui/sync_cfg.cpp @@ -1,22 +1,21 @@ // ************************************************************************** // * 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) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved * +// * Copyright (C) ZenJu (zenju AT gmx DOT de) - All Rights Reserved * // ************************************************************************** #include "sync_cfg.h" #include <memory> -#include "../lib/resources.h" -#include "dir_name.h" #include <wx/wupdlock.h> #include <wx+/mouse_move_dlg.h> -#include <wx+/dir_picker.h> #include <wx+/rtl.h> -#include "gui_generated.h" #include <wx+/choice_enum.h> #include <wx+/image_tools.h> -#include "../file_hierarchy.h" +#include "gui_generated.h" #include "exec_finished_box.h" +#include "dir_name.h" +#include "../file_hierarchy.h" +#include "../lib/resources.h" using namespace zen; using namespace xmlAccess; @@ -32,22 +31,22 @@ public: ExecWhenFinishedCfg* execWhenFinished); //optional input parameter private: - virtual void OnSyncAutomatic( wxCommandEvent& event); - virtual void OnSyncMirror( wxCommandEvent& event); - virtual void OnSyncUpdate( wxCommandEvent& event); - virtual void OnSyncCustom( wxCommandEvent& event); - - virtual void OnSyncAutomaticDouble( wxMouseEvent& event); - virtual void OnSyncMirrorDouble( wxMouseEvent& event); - virtual void OnSyncUpdateDouble( wxMouseEvent& event); - virtual void OnSyncCustomDouble( wxMouseEvent& 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 OnSyncAutomatic(wxCommandEvent& event) { directionCfg.var = DirectionConfig::AUTOMATIC; updateGui(); } + virtual void OnSyncMirror (wxCommandEvent& event) { directionCfg.var = DirectionConfig::MIRROR; updateGui(); } + virtual void OnSyncUpdate (wxCommandEvent& event) { directionCfg.var = DirectionConfig::UPDATE; updateGui(); } + virtual void OnSyncCustom (wxCommandEvent& event) { directionCfg.var = DirectionConfig::CUSTOM; updateGui(); } + + virtual void OnSyncAutomaticDouble(wxMouseEvent& event); + virtual void OnSyncMirrorDouble (wxMouseEvent& event); + virtual void OnSyncUpdateDouble (wxMouseEvent& event); + virtual void OnSyncCustomDouble (wxMouseEvent& 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) { EndModal(ReturnSyncConfig::BUTTON_CANCEL); } virtual void OnCancel(wxCommandEvent& event) { EndModal(ReturnSyncConfig::BUTTON_CANCEL); } @@ -55,40 +54,37 @@ private: void updateGui(); - void OnChangeErrorHandling(wxCommandEvent& event); - void OnChangeDeletionHandling(wxCommandEvent& event); + virtual void OnDeletionPermanent (wxCommandEvent& event) { handleDeletion = DELETE_PERMANENTLY; updateGui(); } + virtual void OnDeletionRecycler (wxCommandEvent& event) { handleDeletion = DELETE_TO_RECYCLER; updateGui(); } + virtual void OnDeletionVersioning (wxCommandEvent& event) { handleDeletion = DELETE_TO_VERSIONING; updateGui(); } - const zen::CompareVariant cmpVariant; + virtual void OnErrorPopup (wxCommandEvent& event) { handleGuiError = ON_GUIERROR_POPUP; updateGui(); } + virtual void OnErrorIgnore(wxCommandEvent& event) { handleGuiError = ON_GUIERROR_IGNORE; updateGui(); } - //temporal copy of maindialog.cfg.directionCfg -> ownership NOT within GUI controls! - DirectionConfig currentDirectionCfg; + virtual void OnToggleVersionsLimit(wxCommandEvent& event) { updateGui(); } + + //parameters with ownership NOT within GUI controls! + DirectionConfig directionCfg; + const CompareVariant cmpVariant; + DeletionPolicy handleDeletion; //use Recycler, delete permanently or move to user-defined location + OnGuiError handleGuiError; //changing data SyncConfig& syncCfgOut; xmlAccess::OnGuiError* refHandleError; ExecWhenFinishedCfg* refExecWhenFinished; - DirectoryName<FolderHistoryBox> customDelFolder; - - EnumDescrList<zen::DeletionPolicy> enumDelhandDescr; - EnumDescrList<xmlAccess::OnGuiError> enumErrhandDescr; + DirectoryName<FolderHistoryBox> versioningFolder; }; - void updateConfigIcons(const DirectionConfig& directionCfg, 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 + wxBitmapButton* buttonConflict) { if (directionCfg.var != DirectionConfig::AUTOMATIC) //automatic mode needs no sync-directions { @@ -199,35 +195,28 @@ SyncCfgDialog::SyncCfgDialog(wxWindow* parent, xmlAccess::OnGuiError* handleError, ExecWhenFinishedCfg* execWhenFinished) : SyncCfgDlgGenerated(parent), + directionCfg(syncCfg.directionCfg), //make working copy cmpVariant(compareVar), - currentDirectionCfg(syncCfg.directionCfg), //make working copy + handleDeletion(syncCfg.handleDeletion), + handleGuiError(ON_GUIERROR_POPUP), //dummy init syncCfgOut(syncCfg), refHandleError(handleError), refExecWhenFinished(execWhenFinished), - customDelFolder(*m_panelCustomDeletionDir, *m_dirPickerCustomDelFolder, *m_customDelFolder) + versioningFolder(*m_panelVersioning, *m_buttonSelectDirVersioning, *m_versioningFolder) { #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 subfolder")); - - enumErrhandDescr. - add(ON_GUIERROR_POPUP, _("Show pop-up"), _("Show pop-up 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, syncCfg.handleDeletion); - customDelFolder.setName(utfCvrtTo<wxString>(syncCfg.customDeletionDirectory)); + versioningFolder.setName(utfCvrtTo<wxString>(syncCfg.versioningDirectory)); + //map single parameter "version limit" to both checkbox and spin ctrl: + m_checkBoxVersionsLimit->SetValue(syncCfg.versionCountLimit >= 0); + m_spinCtrlVersionsLimit->SetValue(syncCfg.versionCountLimit >= 0 ? syncCfg.versionCountLimit : 10 /*SyncConfig().versionCountLimit*/); updateGui(); //error handling if (handleError) - setEnumVal(enumErrhandDescr, *m_choiceHandleError, *handleError); + handleGuiError = *handleError; else { sbSizerErrorHandling->Show(false); @@ -236,7 +225,7 @@ SyncCfgDialog::SyncCfgDialog(wxWindow* parent, if (execWhenFinished) { - m_comboBoxExecFinished->setHistoryRef(*execWhenFinished->history); + m_comboBoxExecFinished->initHistory(*execWhenFinished->history, execWhenFinished->historyMax); m_comboBoxExecFinished->setValue(*execWhenFinished->command); } else @@ -263,13 +252,13 @@ SyncCfgDialog::SyncCfgDialog(wxWindow* parent, Fit(); } -//################################################################################################################# +//################################################################################################################# void SyncCfgDialog::updateGui() { //wxWindowUpdateLocker dummy(this); //avoid display distortion - wxWindowUpdateLocker dummy2(m_panelCustomDeletionDir); //avoid display distortion + wxWindowUpdateLocker dummy2(m_panelVersioning); //avoid display distortion wxWindowUpdateLocker dummy3(m_bpButtonLeftOnly); wxWindowUpdateLocker dummy4(m_bpButtonRightOnly); wxWindowUpdateLocker dummy5(m_bpButtonLeftNewer); @@ -277,137 +266,123 @@ void SyncCfgDialog::updateGui() wxWindowUpdateLocker dummy7(m_bpButtonDifferent); wxWindowUpdateLocker dummy8(m_bpButtonConflict); - updateConfigIcons(currentDirectionCfg, + updateConfigIcons(directionCfg, m_bpButtonLeftOnly, m_bpButtonRightOnly, m_bpButtonLeftNewer, m_bpButtonRightNewer, m_bpButtonDifferent, - m_bpButtonConflict, - m_bitmapLeftOnly, - m_bitmapRightOnly, - m_bitmapLeftNewer, - m_bitmapRightNewer, - m_bitmapDifferent, - m_bitmapConflict); + m_bpButtonConflict); //display only relevant sync options - m_bitmapDatabase->Show(true); - sbSizerSyncDirections->Show(true); + m_bitmapDatabase ->Show(directionCfg.var == DirectionConfig::AUTOMATIC); + sbSizerSyncDirections->Show(directionCfg.var != DirectionConfig::AUTOMATIC); - if (currentDirectionCfg.var == DirectionConfig::AUTOMATIC) - { - sbSizerSyncDirections->Show(false); - } - else + switch (cmpVariant) { - m_bitmapDatabase->Show(false); - switch (cmpVariant) - { - case CMP_BY_TIME_SIZE: - bSizerDifferent ->Show(false); - break; + case CMP_BY_TIME_SIZE: + bSizerDifferent ->Show(false); + break; - case CMP_BY_CONTENT: - bSizerLeftNewer ->Show(false); - bSizerRightNewer->Show(false); - break; - } + case CMP_BY_CONTENT: + bSizerLeftNewer ->Show(false); + bSizerRightNewer->Show(false); + break; } - //set radiobuttons -> have no parameter-ownership at all! + //update toggle buttons -> they have no parameter-ownership at all! m_staticTextAutomatic->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); m_staticTextMirror ->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); m_staticTextUpdate ->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); m_staticTextCustom ->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT)); - switch (currentDirectionCfg.var) + + m_toggleBtnAutomatic->SetValue(false); + m_toggleBtnMirror ->SetValue(false); + m_toggleBtnUpdate ->SetValue(false); + m_toggleBtnCustom ->SetValue(false); + + switch (directionCfg.var) { case DirectionConfig::AUTOMATIC: - m_radioBtnAutomatic->SetValue(true); //automatic mode + m_toggleBtnAutomatic->SetValue(true); m_staticTextAutomatic->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); break; case DirectionConfig::MIRROR: - m_radioBtnMirror->SetValue(true); //one way -> + m_toggleBtnMirror->SetValue(true); m_staticTextMirror->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); break; case DirectionConfig::UPDATE: - m_radioBtnUpdate->SetValue(true); //Update -> + m_toggleBtnUpdate->SetValue(true); m_staticTextUpdate->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); break; case DirectionConfig::CUSTOM: - m_radioBtnCustom->SetValue(true); //custom + m_toggleBtnCustom->SetValue(true); m_staticTextCustom->SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); break; } + m_toggleBtnPermanent ->SetValue(false); + m_toggleBtnRecycler ->SetValue(false); + m_toggleBtnVersioning->SetValue(false); + switch (handleDeletion) + { + case DELETE_PERMANENTLY: + m_toggleBtnPermanent->SetValue(true); + break; + case DELETE_TO_RECYCLER: + m_toggleBtnRecycler->SetValue(true); + break; + case DELETE_TO_VERSIONING: + m_toggleBtnVersioning->SetValue(true); + break; + } + + m_panelVersioning ->Show(handleDeletion == DELETE_TO_VERSIONING); + m_checkBoxVersionsLimit->Show(handleDeletion == DELETE_TO_VERSIONING); + m_spinCtrlVersionsLimit->Show(handleDeletion == DELETE_TO_VERSIONING); + m_spinCtrlVersionsLimit->Enable(m_checkBoxVersionsLimit->GetValue()); + + m_toggleBtnErrorIgnore->SetValue(false); + m_toggleBtnErrorPopup ->SetValue(false); + switch (handleGuiError) + { + case ON_GUIERROR_IGNORE: + m_toggleBtnErrorIgnore->SetValue(true); + break; + case ON_GUIERROR_POPUP: + m_toggleBtnErrorPopup->SetValue(true); + break; + } + Layout(); + Refresh(); //removes a few artifacts when toggling display of versioning folder 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::OnApply(wxCommandEvent& event) { //write configuration to main dialog - syncCfgOut.directionCfg = currentDirectionCfg; - syncCfgOut.handleDeletion = getEnumVal(enumDelhandDescr, *m_choiceHandleDeletion); - syncCfgOut.customDeletionDirectory = utfCvrtTo<Zstring>(customDelFolder.getName()); + syncCfgOut.directionCfg = directionCfg; + syncCfgOut.handleDeletion = handleDeletion; + syncCfgOut.versioningDirectory = utfCvrtTo<Zstring>(versioningFolder.getName()); + //get single parameter "version limit" from both checkbox and spin ctrl: + syncCfgOut.versionCountLimit = m_checkBoxVersionsLimit->GetValue() ? m_spinCtrlVersionsLimit->GetValue() : -1; if (refHandleError) - *refHandleError = getEnumVal(enumErrhandDescr, *m_choiceHandleError); + *refHandleError = handleGuiError; if (refExecWhenFinished) { *refExecWhenFinished->command = m_comboBoxExecFinished->getValue(); - addValueToHistory(*refExecWhenFinished->command, *refExecWhenFinished->history, refExecWhenFinished->historyMax); + //a good place to commit current "on completion" history item + m_comboBoxExecFinished->addItemHistory(); } 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) -{ - currentDirectionCfg.var = DirectionConfig::AUTOMATIC; - updateGui(); -} - - -void SyncCfgDialog::OnSyncMirror(wxCommandEvent& event) -{ - currentDirectionCfg.var = DirectionConfig::MIRROR; - updateGui(); -} - - -void SyncCfgDialog::OnSyncUpdate(wxCommandEvent& event) -{ - currentDirectionCfg.var = DirectionConfig::UPDATE; - updateGui(); -} - - -void SyncCfgDialog::OnSyncCustom(wxCommandEvent& event) -{ - currentDirectionCfg.var = DirectionConfig::CUSTOM; - updateGui(); -} - - void SyncCfgDialog::OnSyncAutomaticDouble(wxMouseEvent& event) { wxCommandEvent dummy; @@ -436,7 +411,8 @@ void SyncCfgDialog::OnSyncCustomDouble(wxMouseEvent& event) OnApply(dummy); } - +namespace +{ void toggleSyncDirection(SyncDirection& current) { switch (current) @@ -492,46 +468,46 @@ void pressCustomDir(DirectionConfig& directionCfg, SyncDirection& syncdir) break; } } - +} void SyncCfgDialog::OnExLeftSideOnly(wxCommandEvent& event ) { - pressCustomDir(currentDirectionCfg, currentDirectionCfg.custom.exLeftSideOnly); + pressCustomDir(directionCfg, directionCfg.custom.exLeftSideOnly); updateGui(); } void SyncCfgDialog::OnExRightSideOnly(wxCommandEvent& event ) { - pressCustomDir(currentDirectionCfg, currentDirectionCfg.custom.exRightSideOnly); + pressCustomDir(directionCfg, directionCfg.custom.exRightSideOnly); updateGui(); } void SyncCfgDialog::OnLeftNewer(wxCommandEvent& event ) { - pressCustomDir(currentDirectionCfg, currentDirectionCfg.custom.leftNewer); + pressCustomDir(directionCfg, directionCfg.custom.leftNewer); updateGui(); } void SyncCfgDialog::OnRightNewer(wxCommandEvent& event ) { - pressCustomDir(currentDirectionCfg, currentDirectionCfg.custom.rightNewer); + pressCustomDir(directionCfg, directionCfg.custom.rightNewer); updateGui(); } void SyncCfgDialog::OnDifferent(wxCommandEvent& event ) { - pressCustomDir(currentDirectionCfg, currentDirectionCfg.custom.different); + pressCustomDir(directionCfg, directionCfg.custom.different); updateGui(); } void SyncCfgDialog::OnConflict(wxCommandEvent& event) { - pressCustomDir(currentDirectionCfg, currentDirectionCfg.custom.conflict); + pressCustomDir(directionCfg, directionCfg.custom.conflict); updateGui(); } @@ -550,4 +526,3 @@ ReturnSyncConfig::ButtonPressed zen::showSyncConfigDlg(wxWindow* parent, return static_cast<ReturnSyncConfig::ButtonPressed>(syncDlg.ShowModal()); } - |