Ticket #2412: net_time_loc.patch
File net_time_loc.patch, 5.7 KB (added by , 13 years ago) |
---|
-
src/preferences/time/ntp.cpp
17 17 18 18 #include <OS.h> 19 19 20 #include <Catalog.h> 20 21 22 23 #undef B_TRANSLATE_CONTEXT 24 #define B_TRANSLATE_CONTEXT "Time" 25 26 21 27 /* This structure and its data fields are described in RFC 1305 22 28 * "Network Time Protocol (Version 3)" in appendix A. 23 29 */ … … 112 118 113 119 if (server == NULL) { 114 120 115 *errorString = "Could not contact server";121 *errorString = B_TRANSLATE("Could not contact server"); 116 122 return B_ENTRY_NOT_FOUND; 117 123 } 118 124 … … 133 139 134 140 int connection = socket(AF_INET, SOCK_DGRAM, 0); 135 141 if (connection < 0) { 136 *errorString = "Could not create socket";142 *errorString = B_TRANSLATE("Could not create socket"); 137 143 *errorCode = errno; 138 144 return B_ERROR; 139 145 } … … 145 151 146 152 if (sendto(connection, (char *)&message, sizeof(ntp_data), 147 153 0, (struct sockaddr *)&address, sizeof(address)) < 0) { 148 *errorString = "Sending request failed";154 *errorString = B_TRANSLATE("Sending request failed"); 149 155 *errorCode = errno; 150 156 return B_ERROR; 151 157 } … … 160 166 // we'll wait 3 seconds for the answer 161 167 162 168 if (select(connection + 1, &waitForReceived, NULL, NULL, &timeout) <= 0) { 163 *errorString = "Waiting for answer failed";169 *errorString = B_TRANSLATE("Waiting for answer failed"); 164 170 *errorCode = errno; 165 171 return B_ERROR; 166 172 } … … 170 176 socklen_t addressSize = sizeof(address); 171 177 if (recvfrom(connection, (char *)&message, sizeof(ntp_data), 0, 172 178 (sockaddr *)&address, &addressSize) < (ssize_t)sizeof(ntp_data)) { 173 *errorString = "Message receiving failed";179 *errorString = B_TRANSLATE("Message receiving failed"); 174 180 *errorCode = errno; 175 181 close(connection); 176 182 return B_ERROR; … … 179 185 close(connection); 180 186 181 187 if (message.transmit_timestamp.Integer() == 0) { 182 *errorString = "Received invalid time";188 *errorString = B_TRANSLATE("Received invalid time"); 183 189 return B_BAD_VALUE; 184 190 } 185 191 -
src/preferences/time/NetworkTimeView.cpp
31 31 #undef B_TRANSLATE_CONTEXT 32 32 #define B_TRANSLATE_CONTEXT "Time" 33 33 34 34 35 Settings::Settings() 35 36 : 36 37 fMessage(kMsgNetworkTimeSettings) … … 293 294 _UpdateServerList(); 294 295 Looper()->PostMessage(new BMessage(kMsgChange)); 295 296 break; 296 297 297 298 case kMsgResetServerList: 298 299 fSettings.ResetServersToDefaults(); 299 300 _UpdateServerList(); 300 301 Looper()->PostMessage(new BMessage(kMsgChange)); 301 302 break; 302 303 303 304 case kMsgTryAllServers: 304 305 fSettings.SetTryAllServers( 305 306 fTryAllServersCheckBox->Value()); … … 325 326 326 327 BMessenger* messenger = new BMessenger(this); 327 328 update_time(fSettings, messenger, &fUpdateThread); 328 fSynchronizeButton->SetLabel( "Stop");329 fSynchronizeButton->SetLabel(B_TRANSLATE("Stop")); 329 330 fSynchronizeButton->Message()->what = kMsgStopSynchronization; 330 331 break; 331 332 } … … 341 342 const char* errorString; 342 343 message->FindString("error string", &errorString); 343 344 char buffer[256]; 344 345 345 346 int32 errorCode; 346 347 if (message->FindInt32("error code", &errorCode) 347 348 == B_OK) 348 349 snprintf(buffer, sizeof(buffer), 349 "The following error occured "350 "while synchronizing:\r\n%s: %s" ,350 B_TRANSLATE("The following error occured " 351 "while synchronizing:\r\n%s: %s"), 351 352 errorString, strerror(errorCode)); 352 353 else 353 354 snprintf(buffer, sizeof(buffer), 354 "The following error occured "355 "while synchronizing:\r\n%s" ,355 B_TRANSLATE("The following error occured " 356 "while synchronizing:\r\n%s"), 356 357 errorString); 357 358 358 (new BAlert("Time", buffer, "OK"))->Go(); 359 (new BAlert(B_TRANSLATE("Time"), buffer, 360 B_TRANSLATE("OK")))->Go(); 359 361 } 360 362 break; 361 363 } … … 409 411 BScrollView* scrollView = new BScrollView("serverScrollView", 410 412 fServerListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 411 413 _UpdateServerList(); 412 414 413 415 fTryAllServersCheckBox = new BCheckBox("tryAllServers", 414 416 B_TRANSLATE("Try all servers"), new BMessage(kMsgTryAllServers)); 415 417 fTryAllServersCheckBox->SetValue(fSettings.GetTryAllServers()); 416 417 fSynchronizeAtBootCheckBox = new BCheckBox("autoUpdate", 418 B_TRANSLATE("Synchronize at boot"), new BMessage(kMsgSynchronizeAtBoot)); 418 419 fSynchronizeAtBootCheckBox = new BCheckBox("autoUpdate", 420 B_TRANSLATE("Synchronize at boot"), 421 new BMessage(kMsgSynchronizeAtBoot)); 419 422 fSynchronizeAtBootCheckBox->SetValue(fSettings.GetSynchronizeAtBoot()); 420 fSynchronizeButton = new BButton("update", B_TRANSLATE("Synchronize now"),423 fSynchronizeButton = new BButton("update", B_TRANSLATE("Synchronize"), 421 424 new BMessage(kMsgSynchronize)); 422 425 fSynchronizeButton->SetExplicitAlignment( 423 426 BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM)); 424 427 425 428 const float kInset = be_control_look->DefaultItemSpacing(); 426 429 BLayoutBuilder::Group<>(this) 427 430 .AddGroup(B_HORIZONTAL) … … 467 470 NetworkTimeView::_DoneSynchronizing() 468 471 { 469 472 fUpdateThread = -1; 470 fSynchronizeButton->SetLabel(B_TRANSLATE("Synchronize again"));473 fSynchronizeButton->SetLabel(B_TRANSLATE("Synchronize")); 471 474 fSynchronizeButton->Message()->what = kMsgSynchronize; 472 475 } 473 476 … … 480 483 481 484 status_t status = B_ENTRY_NOT_FOUND; 482 485 const char* server = settings.GetServer(defaultServer); 483 486 484 487 if (server != NULL) 485 488 status = ntp_update_time(server, errorString, errorCode); 486 489 … … 497 500 break; 498 501 } 499 502 } 500 503 501 504 return status; 502 505 } 503 506 … … 519 522 if (errorCode != 0) 520 523 result.AddInt32("error code", errorCode); 521 524 messenger->SendMessage(&result); 522 525 523 526 delete messenger; 524 527 return B_OK; 525 528 }