MGR: Continue fixing deficiencies in Computing Preferences dialog reported by Juha.

This commit is contained in:
Charlie Fenton 2014-06-20 04:48:05 -07:00
parent 3557365a91
commit 77dbcfd963
3 changed files with 53 additions and 48 deletions

View File

@ -375,11 +375,6 @@ void CDlgAdvPreferences::ReadPreferenceSettings() {
this->UpdateControlStates();
}
void clamp_pct(double& x) {
if (x < 0) x = 0;
if (x > 100) x = 100;
}
/* write overridden preferences to disk (global_prefs_override.xml) */
/* IMPORTANT: Any items added here must be checked in ValidateInput()! */
bool CDlgAdvPreferences::SavePreferencesSettings() {
@ -436,7 +431,6 @@ bool CDlgAdvPreferences::SavePreferencesSettings() {
m_txtProcUseProcessors->GetValue().ToDouble(&td);
td = RoundToHundredths(td);
clamp_pct(td);
prefs.max_ncpus_pct=td;
mask.max_ncpus_pct=true;
@ -512,7 +506,6 @@ bool CDlgAdvPreferences::SavePreferencesSettings() {
//
m_txtDiskMaxOfTotal->GetValue().ToDouble(&td);
td = RoundToHundredths(td);
clamp_pct(td);
prefs.disk_max_used_pct=td;
mask.disk_max_used_pct=true;
//
@ -522,21 +515,18 @@ bool CDlgAdvPreferences::SavePreferencesSettings() {
//
m_txtDiskMaxSwap->GetValue().ToDouble(&td);
td = RoundToHundredths(td);
clamp_pct(td);
td = td / 100.0 ;
prefs.vm_max_used_frac=td;
mask.vm_max_used_frac=true;
//Memory
m_txtMemoryMaxInUse->GetValue().ToDouble(&td);
td = RoundToHundredths(td);
clamp_pct(td);
td = td / 100.0;
prefs.ram_max_used_busy_frac=td;
mask.ram_max_used_busy_frac=true;
//
m_txtMemoryMaxOnIdle->GetValue().ToDouble(&td);
td = RoundToHundredths(td);
clamp_pct(td);
td = td / 100.0;
prefs.ram_max_used_idle_frac=td;
mask.ram_max_used_idle_frac=true;
@ -594,7 +584,7 @@ bool CDlgAdvPreferences::ValidateInput() {
}
}
buffer = m_txtMaxLoad->GetValue();
if(!IsValidFloatValue(buffer)) {
if(!IsValidFloatValueBetween(buffer, 0.0, 100.0)) {
ShowErrorMessage(invMsgFloat, m_txtMaxLoad);
return false;
}
@ -635,13 +625,13 @@ bool CDlgAdvPreferences::ValidateInput() {
}
buffer = m_txtProcUseProcessors->GetValue();
if(!IsValidFloatValue(buffer)) {
if(!IsValidFloatValueBetween(buffer, 0.0, 100.0)) {
ShowErrorMessage(invMsgFloat, m_txtProcUseProcessors);
return false;
}
buffer = m_txtProcUseCPUTime->GetValue();
if(!IsValidFloatValue(buffer)) {
if(!IsValidFloatValueBetween(buffer, 0.0, 100.0)) {
ShowErrorMessage(invMsgFloat, m_txtProcUseCPUTime);
return false;
}
@ -672,14 +662,14 @@ bool CDlgAdvPreferences::ValidateInput() {
}
//limit additional days from 0 to 10
double td;
if (!m_txtNetConnectInterval->GetValue().ToDouble(&td)) td = -1.;
if(td>10.0 || td < 0.0) {
buffer = m_txtNetConnectInterval->GetValue();
if(!IsValidFloatValueBetween(buffer, 0.0, 10.0)) {
ShowErrorMessage(invMsgFloat,m_txtNetConnectInterval);
return false;
}
if (!m_txtNetAdditionalDays->GetValue().ToDouble(&td)) td = -1.;
if(td>10.0 || td < 0.0) {
buffer = m_txtNetAdditionalDays->GetValue();
if(!IsValidFloatValueBetween(buffer, 0.0, 10.0)) {
ShowErrorMessage(invMsgFloat,m_txtNetAdditionalDays);
return false;
}
@ -730,7 +720,7 @@ bool CDlgAdvPreferences::ValidateInput() {
}
buffer = m_txtDiskMaxOfTotal->GetValue();
if(!IsValidFloatValue(buffer)) {
if(!IsValidFloatValueBetween(buffer, 0.0, 100.0)) {
ShowErrorMessage(invMsgFloat, m_txtDiskMaxOfTotal);
return false;
}
@ -742,19 +732,19 @@ bool CDlgAdvPreferences::ValidateInput() {
}
buffer = m_txtDiskMaxSwap->GetValue();
if(!IsValidFloatValue(buffer)) {
if(!IsValidFloatValueBetween(buffer, 0.0, 100.0)) {
ShowErrorMessage(invMsgFloat, m_txtDiskMaxSwap);
return false;
}
buffer = m_txtMemoryMaxInUse->GetValue();
if(!IsValidFloatValue(buffer)) {
if(!IsValidFloatValueBetween(buffer, 0.0, 100.0)) {
ShowErrorMessage(invMsgFloat, m_txtMemoryMaxInUse);
return false;
}
buffer = m_txtMemoryMaxOnIdle->GetValue();
if(!IsValidFloatValue(buffer)) {
if(!IsValidFloatValueBetween(buffer, 0.0, 100.0)) {
ShowErrorMessage(invMsgFloat, m_txtMemoryMaxOnIdle);
return false;
}
@ -789,7 +779,8 @@ bool CDlgAdvPreferences::EnsureTabPageVisible(wxTextCtrl* txtCtrl) {
/* show an error message and set the focus to the control that caused the error */
void CDlgAdvPreferences::ShowErrorMessage(wxString& message,wxTextCtrl* errorCtrl) {
wxASSERT(this->EnsureTabPageVisible(errorCtrl));
bool visibleOK = this->EnsureTabPageVisible(errorCtrl);
wxASSERT(visibleOK);
//
if(message.IsEmpty()){
message = _("invalid input value detected");
@ -831,6 +822,22 @@ bool CDlgAdvPreferences::IsValidFloatValue(const wxString& value, bool allowNega
return true;
}
bool CDlgAdvPreferences::IsValidFloatValueBetween(const wxString& value, double minVal, double maxVal){
for(unsigned int i=0; i < value.Length();i++) {
if(!IsValidFloatChar(value[i])) {
return false;
}
}
//all chars are valid, now what is with the value as a whole ?
double td;
if(!value.ToDouble(&td)) {
return false;
}
if ((td < minVal) || (td > maxVal)) return false;
return true;
}
/* checks if the value is a valid time */
bool CDlgAdvPreferences::IsValidTimeValue(const wxString& value) {
for(unsigned int i=0; i < value.Length();i++) {

View File

@ -43,6 +43,7 @@ class CDlgAdvPreferences : public CDlgAdvPreferencesBase {
void SetValidators();
bool IsValidFloatChar(const wxChar& ch);
bool IsValidFloatValue(const wxString& value, bool allowNegative=false);
bool IsValidFloatValueBetween(const wxString& value, double minVal, double maxVal);
bool IsValidTimeChar(const wxChar& ch);
bool IsValidTimeValue(const wxString& value);
bool IsValidTimeIntervalChar(const wxChar& ch);

View File

@ -105,7 +105,8 @@ CDlgAdvPreferencesBase::CDlgAdvPreferencesBase( wxWindow* parent, int id, wxStri
m_btnOK = new wxButton( m_panelButtons, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );
m_btnOK->SetToolTip( _("save all values and close the dialog") );
m_btnOK->SetDefault();
buttonSizer->Add( m_btnOK, 0, wxALL, 5 );
m_btnCancel = new wxButton( m_panelButtons, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
@ -348,7 +349,7 @@ wxPanel* CDlgAdvPreferencesBase::createProcessorTab(wxNotebook* notebook)
miscProcGridSizer->Add( m_txtProcUseProcessors, 0, wxALL, 1 );
/*xgettext:no-c-format*/
m_staticText21 = new wxStaticText( miscProcStaticBox, ID_DEFAULT, _("% of the processors (0 means ignore this setting)"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText21 = new wxStaticText( miscProcStaticBox, ID_DEFAULT, _("% of the processors (0 means no restriction)"), wxDefaultPosition, wxDefaultSize, 0 );
miscProcGridSizer->Add( m_staticText21, 0, wxALL, 5 );
m_staticText22 = new wxStaticText( miscProcStaticBox, ID_DEFAULT, _("Use at most"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );
@ -358,7 +359,7 @@ wxPanel* CDlgAdvPreferencesBase::createProcessorTab(wxNotebook* notebook)
miscProcGridSizer->Add( m_txtProcUseCPUTime, 0, wxALL, 1 );
/*xgettext:no-c-format*/
m_staticText23 = new wxStaticText( miscProcStaticBox, ID_DEFAULT, _("% CPU time"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText23 = new wxStaticText( miscProcStaticBox, ID_DEFAULT, _("% of CPU time (0 means no restriction)"), wxDefaultPosition, wxDefaultSize, 0 );
miscProcGridSizer->Add( m_staticText23, 0, wxALL, 5 );
miscProcBoxSizer->Add( miscProcGridSizer, 0, wxEXPAND, 1 );
@ -383,7 +384,7 @@ wxPanel* CDlgAdvPreferencesBase::createNetworkTab(wxNotebook* notebook)
wxStaticBox* networkGeneralStaticBox = new wxStaticBox( networkTab, -1, _("General options") );
wxStaticBoxSizer* networkGeneralBoxSizer = new wxStaticBoxSizer( networkGeneralStaticBox, wxVERTICAL );
wxFlexGridSizer* networkGeneralGridSizer = new wxFlexGridSizer(6, 0, 0 );
wxFlexGridSizer* networkGeneralGridSizer = new wxFlexGridSizer(3, 0, 0 );
networkGeneralGridSizer->SetFlexibleDirection( wxHORIZONTAL );
networkGeneralGridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
@ -395,7 +396,7 @@ wxPanel* CDlgAdvPreferencesBase::createNetworkTab(wxNotebook* notebook)
m_txtNetDownloadRate = new wxTextCtrl( networkGeneralStaticBox, ID_TXTNETDOWNLOADRATE, wxT(""), wxDefaultPosition, wxSize( 50,-1 ), wxTE_RIGHT );
networkGeneralGridSizer->Add( m_txtNetDownloadRate, 0, wxALL, 1 );
m_staticText33 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("KBytes/sec."), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText33 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("KBytes/second (0 means no restriction)"), wxDefaultPosition, wxDefaultSize, 0 );
networkGeneralGridSizer->Add( m_staticText33, 0, wxALL, 5 );
m_staticText34 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("Maximum upload rate"), wxDefaultPosition, wxDefaultSize, 0 );
@ -404,7 +405,7 @@ wxPanel* CDlgAdvPreferencesBase::createNetworkTab(wxNotebook* notebook)
m_txtNetUploadRate = new wxTextCtrl( networkGeneralStaticBox, ID_TXTNETUPLOADRATE, wxT(""), wxDefaultPosition, wxSize( 50,-1 ), wxTE_RIGHT );
networkGeneralGridSizer->Add( m_txtNetUploadRate, 0, wxALL, 1 );
m_staticText35 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("KBytes/sec."), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText35 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("KBytes/second (0 means no restriction)"), wxDefaultPosition, wxDefaultSize, 0 );
networkGeneralGridSizer->Add( m_staticText35, 0, wxALL, 5 );
// buffer sizes
@ -426,7 +427,7 @@ wxPanel* CDlgAdvPreferencesBase::createNetworkTab(wxNotebook* notebook)
networkGeneralGridSizer->Add( m_txtNetConnectInterval, 0, wxALL, 1 );
m_staticText31 = new wxStaticText(
networkGeneralStaticBox, ID_DEFAULT, _("days"), wxDefaultPosition, wxDefaultSize, 0
networkGeneralStaticBox, ID_DEFAULT, _("days (maximum value: 10)"), wxDefaultPosition, wxDefaultSize, 0
);
networkGeneralGridSizer->Add( m_staticText31, 0, wxALL, 5 );
@ -445,41 +446,37 @@ wxPanel* CDlgAdvPreferencesBase::createNetworkTab(wxNotebook* notebook)
);
networkGeneralGridSizer->Add( m_txtNetAdditionalDays, 0, wxALL, 1 );
m_staticText341 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("days"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText341 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("days (maximum value: 10)"), wxDefaultPosition, wxDefaultSize, 0 );
networkGeneralGridSizer->Add( m_staticText341, 0, wxALL, 5 );
networkGeneralBoxSizer->Add( networkGeneralGridSizer, 0, wxEXPAND, 1 );
// long-term quota
m_staticText_daily_xfer1 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("Transfer at most"), wxDefaultPosition, wxDefaultSize, 0 );
networkGeneralGridSizer->Add( m_staticText_daily_xfer1, 0, wxALL, 5 );
m_txt_daily_xfer_limit_mb = new wxTextCtrl( networkGeneralStaticBox, ID_TXTNETDOWNLOADRATE, wxT(""), wxDefaultPosition, wxSize( 50,-1 ), wxTE_RIGHT );
networkGeneralGridSizer->Add( m_txt_daily_xfer_limit_mb, 0, wxALL, 1 );
wxBoxSizer* networkTransferLimitSizer = new wxBoxSizer( wxHORIZONTAL );
// Temporarily concatenate strings in order not to break existing localization tables
m_staticText_daily_xfer2 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("Mbytes")+wxT(" ")+_("every"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText_daily_xfer1 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("Transfer at most"), wxDefaultPosition, wxDefaultSize, 0 );
networkTransferLimitSizer->Add( m_staticText_daily_xfer1, 0, wxALL, 5 );
m_txt_daily_xfer_limit_mb = new wxTextCtrl( networkGeneralStaticBox, ID_TXTNETDOWNLOADRATE, wxT(""), wxDefaultPosition, wxSize( 50,-1 ), wxTE_RIGHT );
networkTransferLimitSizer->Add( m_txt_daily_xfer_limit_mb, 0, wxALL, 1 );
m_staticText_daily_xfer2 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("MBytes every"), wxDefaultPosition, wxDefaultSize, 0 );
networkTransferLimitSizer->Add( m_staticText_daily_xfer2, 0, wxALL, 5 );
m_txt_daily_xfer_period_days = new wxTextCtrl( networkGeneralStaticBox, ID_TXTNETUPLOADRATE, wxT(""), wxDefaultPosition, wxSize( 50,-1 ), wxTE_RIGHT );
networkTransferLimitSizer->Add( m_txt_daily_xfer_period_days, 0, wxALL, 1 );
m_staticText_daily_xfer4 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("days"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText_daily_xfer4 = new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, _("days (0 means no restriction)"), wxDefaultPosition, wxDefaultSize, 0 );
networkTransferLimitSizer->Add( m_staticText_daily_xfer4, 0, wxALL, 5 );
networkGeneralGridSizer->Add( networkTransferLimitSizer, 0, wxALL, 0 );
networkGeneralGridSizer->Add( new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ));
networkGeneralGridSizer->Add( new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ));
networkGeneralGridSizer->Add( new wxStaticText( networkGeneralStaticBox, ID_DEFAULT, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ));
networkGeneralBoxSizer->Add( networkTransferLimitSizer, 0, wxALL, 0 );
m_chkNetSkipImageVerification = new wxCheckBox( networkGeneralStaticBox, ID_CHKNETSKIPIMAGEVERIFICATION, _("Skip image file verification"), wxDefaultPosition, wxDefaultSize, 0 );
m_chkNetSkipImageVerification->SetToolTip( _("check this if your Internet provider modifies image files") );
networkGeneralGridSizer->Add( m_chkNetSkipImageVerification, 0, wxALL, 5 );
networkGeneralBoxSizer->Add( networkGeneralGridSizer, 0, wxEXPAND, 1 );
networkGeneralBoxSizer->Add( m_chkNetSkipImageVerification, 0, wxALL, 5 );
networkTabSizer->Add( networkGeneralBoxSizer, 0, wxEXPAND, 1 );
@ -623,7 +620,7 @@ wxPanel* CDlgAdvPreferencesBase::createDiskAndMemoryTab(wxNotebook* notebook)
diskUsageGridSizer->Add( m_txtDiskMaxSpace, 0, wxALL, 1 );
m_staticText41 = new wxStaticText( diskUsageStaticBox, ID_DEFAULT, _("Gigabytes disk space"), wxDefaultPosition, wxDefaultSize, 0 );
m_staticText41 = new wxStaticText( diskUsageStaticBox, ID_DEFAULT, _("Gigabytes disk space (0 means no restriction)"), wxDefaultPosition, wxDefaultSize, 0 );
diskUsageGridSizer->Add( m_staticText41, 0, wxALL, 5 );
m_staticText42 = new wxStaticText( diskUsageStaticBox, ID_DEFAULT, _("Leave at least"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT );