diff --git a/src/preferences/time/NetworkTimeView.cpp b/src/preferences/time/NetworkTimeView.cpp index 737642d63b..4c4c5adb0d 100644 --- a/src/preferences/time/NetworkTimeView.cpp +++ b/src/preferences/time/NetworkTimeView.cpp @@ -295,21 +295,18 @@ NetworkTimeView::MessageReceived(BMessage* message) case kMsgServerEdited: { rgb_color defaultColor = ui_color(B_CONTROL_TEXT_COLOR); - rgb_color red = {255, 0, 0}; - int32 length = fServerTextControl->TextView()->TextLength(); - - if (_IsValidServerName(fServerTextControl->TextView()->Text())) { - fServerTextControl->TextView()->SetFontAndColor(0, length, NULL, - 0, &defaultColor); - } else { - fServerTextControl->TextView()->SetFontAndColor(0, length, NULL, - 0, &red); - } + rgb_color invalid = ui_color(B_FAILURE_COLOR); + bool isValidServerName + = _IsValidServerName(fServerTextControl->Text()); + fServerTextControl->TextView()->SetFontAndColor(0, + fServerTextControl->TextView()->TextLength(), NULL, 0, + isValidServerName ? &defaultColor : &invalid); + fAddButton->SetEnabled(isValidServerName); break; } case kMsgAddServer: - if (!_IsValidServerName(fServerTextControl->TextView()->Text())) + if (!_IsValidServerName(fServerTextControl->Text())) break; fSettings.AddServer(fServerTextControl->Text()); @@ -418,6 +415,7 @@ NetworkTimeView::AttachedToWindow() fServerTextControl->SetTarget(this); fServerListView->SetTarget(this); fAddButton->SetTarget(this); + fAddButton->SetEnabled(false); fRemoveButton->SetTarget(this); fResetButton->SetTarget(this); fTryAllServersCheckBox->SetTarget(this); @@ -521,9 +519,9 @@ NetworkTimeView::_DoneSynchronizing() bool -NetworkTimeView::_IsValidServerName(const char * serverName) +NetworkTimeView::_IsValidServerName(const char* serverName) { - if (serverName[0] == '\0') + if (serverName == NULL || *serverName == '\0') return false; for (int32 i = 0; serverName[i] != '\0'; i++) { diff --git a/src/preferences/time/NetworkTimeView.h b/src/preferences/time/NetworkTimeView.h index 8822c489a1..3a56826c96 100644 --- a/src/preferences/time/NetworkTimeView.h +++ b/src/preferences/time/NetworkTimeView.h @@ -93,7 +93,7 @@ private: void _InitView(); void _UpdateServerList(); void _DoneSynchronizing(); - bool _IsValidServerName(const char * serverName); + bool _IsValidServerName(const char* serverName); Settings fSettings;