Ticket #2412: time_pref_net2.patch
File time_pref_net2.patch, 89.0 KB (added by , 13 years ago) |
---|
-
src/preferences/time/ntp.cpp
1 /* 2 * Copyright 2004-2009, pinc Software. All Rights Reserved. 3 * Distributed under the terms of the MIT license. 4 */ 5 6 #include "ntp.h" 7 8 #include <errno.h> 9 #include <netdb.h> 10 #include <string.h> 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <sys/select.h> 14 #include <sys/socket.h> 15 #include <unistd.h> 16 17 #include <OS.h> 18 19 20 /* This structure and its data fields are described in RFC 1305 21 * "Network Time Protocol (Version 3)" in appendix A. 22 */ 23 24 struct fixed32 { 25 int16 integer; 26 uint16 fraction; 27 28 void 29 SetTo(int16 integer, uint16 fraction = 0) 30 { 31 this->integer = htons(integer); 32 this->fraction = htons(fraction); 33 } 34 35 int16 Integer() { return htons(integer); } 36 uint16 Fraction() { return htons(fraction); } 37 }; 38 39 struct ufixed64 { 40 uint32 integer; 41 uint32 fraction; 42 43 void 44 SetTo(uint32 integer, uint32 fraction = 0) 45 { 46 this->integer = htonl(integer); 47 this->fraction = htonl(fraction); 48 } 49 50 uint32 Integer() { return htonl(integer); } 51 uint32 Fraction() { return htonl(fraction); } 52 }; 53 54 struct ntp_data { 55 uint8 mode : 3; 56 uint8 version : 3; 57 uint8 leap_indicator : 2; 58 59 uint8 stratum; 60 int8 poll; 61 int8 precision; /* in seconds of the nearest power of two */ 62 63 fixed32 root_delay; 64 fixed32 root_dispersion; 65 uint32 root_identifier; 66 67 ufixed64 reference_timestamp; 68 ufixed64 originate_timestamp; 69 ufixed64 receive_timestamp; 70 ufixed64 transmit_timestamp; 71 72 /* optional authenticator follows (96 bits) */ 73 }; 74 75 #define NTP_PORT 123 76 #define NTP_VERSION_3 3 77 78 enum ntp_leap_warnings { 79 LEAP_NO_WARNING = 0, 80 LEAP_LAST_MINUTE_61_SECONDS, 81 LEAP_LAST_MINUTE_59_SECONDS, 82 LEAP_CLOCK_NOT_IN_SYNC, 83 }; 84 85 enum ntp_modes { 86 MODE_RESERVED = 0, 87 MODE_SYMMETRIC_ACTIVE, 88 MODE_SYMMETRIC_PASSIVE, 89 MODE_CLIENT, 90 MODE_SERVER, 91 MODE_BROADCAST, 92 MODE_NTP_CONTROL_MESSAGE, 93 }; 94 95 96 const uint32 kUTCtoGMT = 12 * 60 * 60; 97 98 99 uint32 100 seconds_system_difference(void) 101 { 102 const uint32 kYear2000 = 3155713200UL; 103 // that many seconds from year 1900 to 2000. 104 105 struct tm tm; 106 memset(&tm, 0, sizeof(struct tm)); 107 tm.tm_mday = 1; 108 tm.tm_year = 100; 109 110 return kYear2000 - mktime(&tm); 111 } 112 113 114 uint32 115 seconds_since_1900() 116 { 117 return seconds_system_difference() + real_time_clock(); 118 } 119 120 121 status_t 122 ntp_update_time(const char* hostname, const char** errorString, 123 int32* errorCode) 124 { 125 hostent *server = gethostbyname(hostname); 126 127 if (server == NULL) { 128 129 *errorString = "Could not contact server"; 130 return B_ENTRY_NOT_FOUND; 131 } 132 133 ntp_data message; 134 memset(&message, 0, sizeof(ntp_data)); 135 136 message.leap_indicator = LEAP_CLOCK_NOT_IN_SYNC; 137 message.version = NTP_VERSION_3; 138 message.mode = MODE_CLIENT; 139 140 message.stratum = 1; // primary reference 141 message.precision = -5; // 2^-5 ~ 32-64 Hz precision 142 143 message.root_delay.SetTo(1); // 1 sec 144 message.root_dispersion.SetTo(1); 145 146 message.transmit_timestamp.SetTo(seconds_since_1900()); 147 148 int connection = socket(AF_INET, SOCK_DGRAM, 0); 149 if (connection < 0) { 150 *errorString = "Could not create socket"; 151 *errorCode = errno; 152 return B_ERROR; 153 } 154 155 struct sockaddr_in address; 156 address.sin_family = AF_INET; 157 address.sin_port = htons(NTP_PORT); 158 address.sin_addr.s_addr = *(uint32 *)server->h_addr_list[0]; 159 160 if (sendto(connection, (char *)&message, sizeof(ntp_data), 161 0, (struct sockaddr *)&address, sizeof(address)) < 0) { 162 *errorString = "Sending request failed"; 163 *errorCode = errno; 164 return B_ERROR; 165 } 166 167 fd_set waitForReceived; 168 FD_ZERO(&waitForReceived); 169 FD_SET(connection, &waitForReceived); 170 171 struct timeval timeout; 172 timeout.tv_sec = 3; 173 timeout.tv_usec = 0; 174 // we'll wait 3 seconds for the answer 175 176 if (select(connection + 1, &waitForReceived, NULL, NULL, &timeout) <= 0) { 177 *errorString = "Waiting for answer failed"; 178 *errorCode = errno; 179 return B_ERROR; 180 } 181 182 message.transmit_timestamp.SetTo(0); 183 184 socklen_t addressSize = sizeof(address); 185 if (recvfrom(connection, (char *)&message, sizeof(ntp_data), 0, 186 (sockaddr *)&address, &addressSize) < (ssize_t)sizeof(ntp_data)) { 187 *errorString = "Message receiving failed"; 188 *errorCode = errno; 189 close(connection); 190 return B_ERROR; 191 } 192 193 close(connection); 194 195 if (message.transmit_timestamp.Integer() == 0) { 196 *errorString = "Received invalid time"; 197 return B_BAD_VALUE; 198 } 199 200 time_t now = message.transmit_timestamp.Integer() - 201 seconds_system_difference() + kUTCtoGMT; 202 set_real_time_clock(now); 203 return B_OK; 204 } -
src/preferences/time/Time.h
31 31 32 32 33 33 #endif // _TIME_H 34 -
src/preferences/time/NetworkTimeView.cpp
1 /* 2 * Copyright 2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hamish Morrison <hamish@lavabit.com> 7 * Axel Dörfler <axeld@pinc-software.de> 8 */ 9 10 #include "NetworkTimeView.h" 11 12 #include <stdio.h> 13 #include <string.h> 14 15 #include <Alert.h> 16 #include <Button.h> 17 #include <CheckBox.h> 18 #include <File.h> 19 #include <FindDirectory.h> 20 #include <ListView.h> 21 #include <Path.h> 22 #include <ScrollView.h> 23 #include <TextControl.h> 24 25 #include "ntp.h" 26 #include "TimeMessages.h" 27 28 29 Settings::Settings() 30 : 31 fMessage(kMsgNetworkTimeSettings) 32 { 33 ResetToDefaults(); 34 Load(); 35 } 36 37 38 Settings::~Settings() 39 { 40 Save(); 41 } 42 43 44 void 45 Settings::AddServer(const char* server) 46 { 47 if (_GetStringByValue("server", server) == B_ERROR) 48 fMessage.AddString("server", server); 49 } 50 51 52 const char* 53 Settings::GetServer(int32 index) const 54 { 55 const char* server; 56 fMessage.FindString("server", index, &server); 57 return server; 58 } 59 60 61 void 62 Settings::RemoveServer(const char* server) 63 { 64 int32 index = _GetStringByValue("server", server); 65 if (index != B_ERROR) { 66 fMessage.RemoveData("server", index); 67 68 int32 count; 69 fMessage.GetInfo("server", NULL, &count); 70 if (GetDefaultServer() >= count) 71 SetDefaultServer(count - 1); 72 } 73 } 74 75 76 void 77 Settings::SetDefaultServer(int32 index) 78 { 79 if (fMessage.ReplaceInt32("default server", index) != B_OK) 80 fMessage.AddInt32("default server", index); 81 } 82 83 84 int32 85 Settings::GetDefaultServer() const 86 { 87 int32 index; 88 fMessage.FindInt32("default server", &index); 89 return index; 90 } 91 92 93 void 94 Settings::SetTryAllServers(bool boolean) 95 { 96 fMessage.ReplaceBool("try all servers", boolean); 97 } 98 99 100 bool 101 Settings::GetTryAllServers() const 102 { 103 bool boolean; 104 fMessage.FindBool("try all servers", &boolean); 105 return boolean; 106 } 107 108 109 void 110 Settings::SetSynchronizeAtBoot(bool boolean) 111 { 112 fMessage.ReplaceBool("synchronize at boot", boolean); 113 } 114 115 116 bool 117 Settings::GetSynchronizeAtBoot() const 118 { 119 bool boolean; 120 fMessage.FindBool("synchronize at boot", &boolean); 121 return boolean; 122 } 123 124 125 void 126 Settings::ResetServersToDefaults() 127 { 128 fMessage.RemoveName("server"); 129 130 fMessage.AddString("server", "pool.ntp.org"); 131 fMessage.AddString("server", "de.pool.ntp.org"); 132 fMessage.AddString("server", "time.nist.gov"); 133 134 if (fMessage.ReplaceInt32("default server", 0) != B_OK) 135 fMessage.AddInt32("default server", 0); 136 } 137 138 139 void 140 Settings::ResetToDefaults() 141 { 142 fMessage.MakeEmpty(); 143 ResetServersToDefaults(); 144 145 fMessage.AddBool("synchronize at boot", true); 146 fMessage.AddBool("try all servers", true); 147 } 148 149 150 void 151 Settings::Revert() 152 { 153 fMessage = fOldMessage; 154 } 155 156 157 bool 158 Settings::SettingsChanged() 159 { 160 ssize_t oldSize = fOldMessage.FlattenedSize(); 161 ssize_t newSize = fMessage.FlattenedSize(); 162 163 if (oldSize != newSize) 164 return true; 165 166 char* oldBytes = new char[oldSize]; 167 fOldMessage.Flatten(oldBytes, oldSize); 168 char* newBytes = new char[newSize]; 169 fMessage.Flatten(newBytes, newSize); 170 171 int result = memcmp(oldBytes, newBytes, oldSize); 172 delete[] oldBytes, newBytes; 173 if (result != 0) 174 return true; 175 else 176 return false; 177 } 178 179 180 status_t 181 Settings::Load() 182 { 183 status_t status; 184 185 BPath path; 186 if ((status = _GetPath(path)) != B_OK) 187 return status; 188 189 BFile file(path.Path(), B_READ_ONLY); 190 if ((status = file.InitCheck()) != B_OK) 191 return status; 192 193 BMessage load; 194 if ((status = load.Unflatten(&file)) != B_OK) 195 return status; 196 197 if (load.what != kMsgNetworkTimeSettings) 198 return B_BAD_TYPE; 199 200 fMessage = load; 201 fOldMessage = fMessage; 202 return B_OK; 203 } 204 205 206 status_t 207 Settings::Save() 208 { 209 status_t status; 210 211 BPath path; 212 if ((status = _GetPath(path)) != B_OK) 213 return status; 214 215 BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); 216 if ((status = file.InitCheck()) != B_OK) 217 return status; 218 219 file.SetSize(0); 220 221 return fMessage.Flatten(&file); 222 } 223 224 225 int32 226 Settings::_GetStringByValue(const char* name, const char* value) 227 { 228 const char* string; 229 for (int32 index = 0; fMessage.FindString( 230 name, index, &string) == B_OK; index++) 231 if (strcmp(string, value) == 0) 232 return index; 233 return B_ERROR; 234 } 235 236 237 status_t 238 Settings::_GetPath(BPath& path) 239 { 240 status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); 241 if (status != B_OK) 242 return status; 243 path.Append("pinc.networktime settings"); 244 return B_OK; 245 } 246 247 248 NetworkTimeView::NetworkTimeView(const char* name) 249 : 250 BGroupView(name, B_VERTICAL, B_USE_DEFAULT_SPACING), 251 fSettings(), 252 fUpdateThread(-1) 253 { 254 fSettings.Load(); 255 _InitView(); 256 } 257 258 259 void 260 NetworkTimeView::MessageReceived(BMessage* message) 261 { 262 switch (message->what) { 263 case kMsgSetDefaultServer: 264 { 265 int32 sel = fServerListView->CurrentSelection(); 266 if (sel < 0) 267 fServerListView->Select(fSettings.GetDefaultServer()); 268 else { 269 fSettings.SetDefaultServer(sel); 270 Looper()->PostMessage(new BMessage(kMsgChange)); 271 } 272 break; 273 } 274 case kMsgAddServer: 275 fSettings.AddServer(fServerTextControl->Text()); 276 _UpdateServerList(); 277 Looper()->PostMessage(new BMessage(kMsgChange)); 278 break; 279 280 case kMsgRemoveServer: 281 fSettings.RemoveServer(((BStringItem*) 282 fServerListView->ItemAt( 283 fServerListView-> 284 CurrentSelection()))->Text()); 285 _UpdateServerList(); 286 Looper()->PostMessage(new BMessage(kMsgChange)); 287 break; 288 289 case kMsgResetServerList: 290 fSettings.ResetServersToDefaults(); 291 _UpdateServerList(); 292 Looper()->PostMessage(new BMessage(kMsgChange)); 293 break; 294 295 case kMsgTryAllServers: 296 fSettings.SetTryAllServers( 297 fTryAllServersCheckBox->Value()); 298 Looper()->PostMessage(new BMessage(kMsgChange)); 299 break; 300 301 case kMsgSynchronizeAtBoot: 302 fSettings.SetSynchronizeAtBoot( 303 fSynchronizeAtBootCheckBox->Value()); 304 Looper()->PostMessage(new BMessage(kMsgChange)); 305 break; 306 307 case kMsgStopSynchronization: 308 if (fUpdateThread >= B_OK) 309 kill_thread(fUpdateThread); 310 _DoneSynchronizing(); 311 break; 312 313 case kMsgSynchronize: 314 { 315 if (fUpdateThread >= B_OK) 316 break; 317 318 BMessenger* messenger = new BMessenger(this); 319 update_time(fSettings, messenger, &fUpdateThread); 320 fSynchronizeButton->SetLabel("Stop"); 321 fSynchronizeButton->Message()->what = kMsgStopSynchronization; 322 break; 323 } 324 325 case kMsgSynchronizationResult: 326 { 327 _DoneSynchronizing(); 328 329 status_t status; 330 if (message->FindInt32("status", (int32 *)&status) == B_OK) { 331 if (status == B_OK) return; 332 333 const char* errorString; 334 message->FindString("error string", &errorString); 335 char buffer[256]; 336 337 int32 errorCode; 338 if (message->FindInt32("error code", &errorCode) 339 == B_OK) 340 snprintf(buffer, sizeof(buffer), 341 "The following error occured " 342 "while synchronizing:\r\n%s: %s", 343 errorString, strerror(errorCode)); 344 else 345 snprintf(buffer, sizeof(buffer), 346 "The following error occured " 347 "while synchronizing:\r\n%s", 348 errorString); 349 350 (new BAlert("Time", buffer, "OK"))->Go(); 351 } 352 break; 353 } 354 355 case kMsgRevert: 356 fSettings.Revert(); 357 fTryAllServersCheckBox->SetValue( 358 fSettings.GetTryAllServers()); 359 fSynchronizeAtBootCheckBox->SetValue( 360 fSettings.GetSynchronizeAtBoot()); 361 _UpdateServerList(); 362 break; 363 } 364 } 365 366 367 void 368 NetworkTimeView::AttachedToWindow() 369 { 370 fServerListView->SetTarget(this); 371 fAddButton->SetTarget(this); 372 fRemoveButton->SetTarget(this); 373 fResetButton->SetTarget(this); 374 fTryAllServersCheckBox->SetTarget(this); 375 fSynchronizeAtBootCheckBox->SetTarget(this); 376 fSynchronizeButton->SetTarget(this); 377 } 378 379 380 bool 381 NetworkTimeView::CheckCanRevert() 382 { 383 return fSettings.SettingsChanged(); 384 } 385 386 void 387 NetworkTimeView::_InitView() 388 { 389 fServerTextControl = new BTextControl(NULL, NULL, NULL); 390 391 fAddButton = new BButton("add", "Add", new BMessage(kMsgAddServer)); 392 fRemoveButton = new BButton("remove", "Remove", 393 new BMessage(kMsgRemoveServer)); 394 fResetButton = new BButton("reset", "Reset", 395 new BMessage(kMsgResetServerList)); 396 397 fServerListView = new BListView("serverList"); 398 fServerListView->SetSelectionMessage(new 399 BMessage(kMsgSetDefaultServer)); 400 BScrollView* scrollView = new BScrollView("serverScrollView", 401 fServerListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); 402 _UpdateServerList(); 403 404 fTryAllServersCheckBox = new BCheckBox("tryAllServers", 405 "Try all servers", new BMessage(kMsgTryAllServers)); 406 fTryAllServersCheckBox->SetValue(fSettings.GetTryAllServers()); 407 408 fSynchronizeAtBootCheckBox = new BCheckBox("autoUpdate", 409 "Synchronize at boot", new BMessage(kMsgSynchronizeAtBoot)); 410 fSynchronizeAtBootCheckBox->SetValue(fSettings.GetSynchronizeAtBoot()); 411 fSynchronizeButton = new BButton("update", "Synchronize now", 412 new BMessage(kMsgSynchronize)); 413 fSynchronizeButton->SetExplicitAlignment( 414 BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM)); 415 416 BLayoutBuilder::Group<>(this) 417 .AddGroup(B_HORIZONTAL) 418 .AddGroup(B_VERTICAL, 0) 419 .Add(fServerTextControl) 420 .Add(scrollView) 421 .End() 422 .AddGroup(B_VERTICAL) 423 .Add(fAddButton) 424 .Add(fRemoveButton) 425 .Add(fResetButton) 426 .AddGlue() 427 .End() 428 .End() 429 .AddGroup(B_HORIZONTAL) 430 .AddGroup(B_VERTICAL) 431 .Add(fTryAllServersCheckBox) 432 .Add(fSynchronizeAtBootCheckBox) 433 .End() 434 .Add(fSynchronizeButton) 435 .End() 436 .SetInsets(5, 5, 5, 5); 437 } 438 439 440 void 441 NetworkTimeView::_UpdateServerList() 442 { 443 while (fServerListView->RemoveItem(0L) != NULL); 444 445 const char* server; 446 int32 index = 0; 447 448 while ((server = fSettings.GetServer(index++)) != NULL) 449 fServerListView->AddItem(new BStringItem(server)); 450 451 fServerListView->Select(fSettings.GetDefaultServer()); 452 fServerListView->ScrollToSelection(); 453 } 454 455 456 void 457 NetworkTimeView::_DoneSynchronizing() 458 { 459 fUpdateThread = -1; 460 fSynchronizeButton->SetLabel("Synchronize"); 461 fSynchronizeButton->Message()->what = kMsgSynchronize; 462 } 463 464 465 status_t 466 update_time(const Settings& settings, const char** errorString, 467 int32* errorCode) 468 { 469 int32 defaultServer = settings.GetDefaultServer(); 470 471 status_t status = B_ENTRY_NOT_FOUND; 472 const char* server = settings.GetServer(defaultServer); 473 474 if (server != NULL) 475 status = ntp_update_time(server, errorString, errorCode); 476 477 if (status != B_OK && settings.GetTryAllServers()) { 478 for (int32 index = 0; ; index++) { 479 if (index == defaultServer) 480 index++; 481 server = settings.GetServer(index); 482 if (server == NULL) 483 break; 484 485 status = ntp_update_time(server, errorString, errorCode); 486 if (status == B_OK) 487 break; 488 } 489 } 490 491 return status; 492 } 493 494 495 int32 496 update_thread(void* params) 497 { 498 BList* list = (BList*)params; 499 BMessenger* messenger = (BMessenger*)list->ItemAt(1); 500 501 const char* errorString = NULL; 502 int32 errorCode = 0; 503 status_t status = update_time(*(Settings*)list->ItemAt(0), 504 &errorString, &errorCode); 505 506 BMessage result(kMsgSynchronizationResult); 507 result.AddInt32("status", status); 508 result.AddString("error string", errorString); 509 if (errorCode != 0) 510 result.AddInt32("error code", errorCode); 511 messenger->SendMessage(&result); 512 513 delete messenger; 514 return B_OK; 515 } 516 517 518 status_t 519 update_time(const Settings& settings, BMessenger* messenger, 520 thread_id* thread) 521 { 522 BList* params = new BList(2); 523 params->AddItem((void*)&settings); 524 params->AddItem((void*)messenger); 525 *thread = spawn_thread(update_thread, "ntpUpdate", 64, params); 526 return resume_thread(*thread); 527 } -
src/preferences/time/TimeZoneListItem.cpp
1 1 /* 2 * Copyright 201 0, Haiku Inc. All rights reserved.2 * Copyright 2011, Haiku Inc. All rights reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 9 9 * Oliver Tappe <zooey@hirschkaefer.de> 10 10 */ 11 11 12 13 12 #include "TimeZoneListItem.h" 14 13 15 14 #include <new> -
src/preferences/time/BaseView.cpp
8 8 */ 9 9 10 10 #include "BaseView.h" 11 #include "TimeMessages.h"12 11 13 14 12 #include <DateTime.h> 15 13 #include <OS.h> 16 14 15 #include "TimeMessages.h" 17 16 18 TTimeBaseView::TTimeBaseView(BRect frame, const char* name) 19 : BView(frame, name, B_FOLLOW_NONE, B_PULSE_NEEDED), 20 fMessage(H_TIME_UPDATE) 17 18 TTimeBaseView::TTimeBaseView(const char* name) 19 : 20 BGroupView(name, B_VERTICAL, 0), 21 fMessage(H_TIME_UPDATE) 21 22 { 23 SetFlags(Flags() | B_PULSE_NEEDED); 22 24 } 23 25 24 26 … … 108 110 109 111 SendNotices(H_TM_CHANGED, &fMessage); 110 112 } 111 -
src/preferences/time/ZoneView.cpp
8 8 * Philippe Saint-Pierre <stpere@gmail.com> 9 9 * Adrien Destugues <pulkomandy@pulkomandy.ath.cx> 10 10 * Oliver Tappe <zooey@hirschkaefer.de> 11 * Hamish Morrison <hamish@lavabit.com> 11 12 */ 12 13 13 14 14 #include "ZoneView.h" 15 15 16 16 #include <stdlib.h> 17 #include <syscalls.h> 17 18 18 19 #include <map> 19 20 #include <new> … … 36 37 #include <StorageDefs.h> 37 38 #include <String.h> 38 39 #include <TimeZone.h> 40 #include <ToolTip.h> 39 41 #include <View.h> 40 42 #include <Window.h> 41 43 42 #include <syscalls.h>43 #include <ToolTip.h>44 45 44 #include <unicode/datefmt.h> 46 45 #include <unicode/utmscale.h> 47 46 #include <ICUWrapper.h> … … 49 48 #include "TimeMessages.h" 50 49 #include "TimeZoneListItem.h" 51 50 #include "TZDisplay.h" 52 #include "TimeWindow.h"53 51 54 52 55 53 #undef B_TRANSLATE_CONTEXT … … 77 75 78 76 79 77 80 TimeZoneView::TimeZoneView( BRect frame)78 TimeZoneView::TimeZoneView(const char* name) 81 79 : 82 B View(frame, "timeZoneView", B_FOLLOW_NONE, B_WILL_DRAW | B_NAVIGABLE_JUMP),80 BGroupView(name, B_HORIZONTAL, B_USE_DEFAULT_SPACING), 83 81 fToolTip(NULL), 84 82 fCurrentZoneItem(NULL), 85 83 fOldZoneItem(NULL), … … 159 157 case H_SET_TIME_ZONE: 160 158 { 161 159 _SetSystemTimeZone(); 162 ((TTimeWindow*)Window())->SetRevertStatus();160 Looper()->PostMessage(new BMessage(kMsgChange)); 163 161 break; 164 162 } 165 163 … … 173 171 break; 174 172 175 173 default: 176 B View::MessageReceived(message);174 BGroupView::MessageReceived(message); 177 175 break; 178 176 } 179 177 } … … 233 231 void 234 232 TimeZoneView::_InitView() 235 233 { 236 // left side 237 BRect frameLeft(Bounds()); 238 frameLeft.right = frameLeft.Width() / 2.0; 239 frameLeft.InsetBy(10.0f, 10.0f); 240 241 // City Listing 242 fZoneList = new BOutlineListView(frameLeft, "cityList", 243 B_SINGLE_SELECTION_LIST); 234 fZoneList = new BOutlineListView("cityList", B_SINGLE_SELECTION_LIST); 244 235 fZoneList->SetSelectionMessage(new BMessage(H_CITY_CHANGED)); 245 236 fZoneList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE)); 246 247 237 _BuildZoneMenu(); 248 249 238 BScrollView* scrollList = new BScrollView("scrollList", fZoneList, 250 B_FOLLOW_ALL, 0, false, true); 251 AddChild(scrollList); 239 B_FRAME_EVENTS | B_WILL_DRAW, false, true); 252 240 253 // right side 254 BRect frameRight(Bounds()); 255 frameRight.left = frameRight.Width() / 2.0; 256 frameRight.InsetBy(10.0f, 10.0f); 257 frameRight.top = frameLeft.top; 241 fCurrent = new TTZDisplay("currentTime", B_TRANSLATE("Current time:")); 242 fPreview = new TTZDisplay("previewTime", B_TRANSLATE("Preview time:")); 258 243 259 // Time Displays 260 fCurrent = new TTZDisplay(frameRight, "currentTime", 261 B_TRANSLATE("Current time:")); 262 AddChild(fCurrent); 263 fCurrent->ResizeToPreferred(); 264 265 frameRight.top = fCurrent->Frame().bottom + 10.0; 266 fPreview = new TTZDisplay(frameRight, "previewTime", 267 B_TRANSLATE("Preview time:")); 268 AddChild(fPreview); 269 fPreview->ResizeToPreferred(); 270 271 // set button 272 fSetZone = new BButton(frameRight, "setTimeZone", 273 B_TRANSLATE("Set time zone"), 244 fSetZone = new BButton("setTimeZone", B_TRANSLATE("Set time zone"), 274 245 new BMessage(H_SET_TIME_ZONE)); 275 AddChild(fSetZone);276 246 fSetZone->SetEnabled(false); 277 fSetZone->ResizeToPreferred(); 278 279 fSetZone->MoveTo(frameRight.right - fSetZone->Bounds().Width(), 280 scrollList->Frame().bottom - fSetZone->Bounds().Height()); 247 fSetZone->SetExplicitAlignment( 248 BAlignment(B_ALIGN_RIGHT, B_ALIGN_BOTTOM)); 249 250 BLayoutBuilder::Group<>(this) 251 .Add(scrollList) 252 .AddGroup(B_VERTICAL, 5) 253 .Add(fCurrent) 254 .Add(fPreview) 255 .AddGlue() 256 .Add(fSetZone) 257 .End() 258 .SetInsets(5, 5, 5, 5); 281 259 } 282 260 283 261 … … 336 314 337 315 BString region(zoneID, slashPos); 338 316 339 if (region == "Etc")317 if (region == B_TRANSLATE("Etc")) 340 318 region = kOtherRegion; 341 319 else if (countryName.Length() == 0) { 342 320 // skip global timezones from other regions, we are just -
src/preferences/time/DateTimeEdit.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * McCall <mccall@@digitalparadise.co.uk> 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 * 9 * Hamish Morrison <hamish@lavabit.com> 10 10 */ 11 11 #ifndef _DATE_TIME_EDIT_H 12 12 #define _DATE_TIME_EDIT_H 13 13 14 14 15 #include "SectionEdit.h"16 17 15 #include <DateTime.h> 18 16 #include <Locale.h> 19 17 #include <String.h> 20 18 19 #include "SectionEdit.h" 21 20 21 22 22 class TTimeEdit : public TSectionEdit { 23 23 public: 24 TTimeEdit(BRect frame, const char* name, 25 uint32 sections); 24 TTimeEdit(const char* name, uint32 sections); 26 25 virtual ~TTimeEdit(); 27 26 28 27 virtual void KeyDown(const char* bytes, int32 numBytes); 29 28 30 29 virtual void InitView(); 31 virtual void DrawSection(uint32 index, bool isfocus); 32 virtual void DrawSeparator(uint32 index); 30 virtual void DrawSection(uint32 index, BRect bounds, 31 bool isfocus); 32 virtual void DrawSeparator(uint32 index, BRect bounds); 33 33 34 virtual void SetSections(BRect area);35 34 virtual void SectionFocus(uint32 index); 36 virtual float SeparatorWidth() const; 35 virtual float MinSectionWidth(); 36 virtual float SeparatorWidth(); 37 37 38 virtual float PreferredHeight(); 38 39 virtual void DoUpPress(); 39 40 virtual void DoDownPress(); 40 41 … … 48 49 bool _IsValidDoubleDigit(int32 value); 49 50 int32 _SectionValue(int32 index) const; 50 51 51 private:52 52 BDateTime fTime; 53 53 bigtime_t fLastKeyDownTime; 54 54 int32 fLastKeyDownInt; … … 65 65 66 66 class TDateEdit : public TSectionEdit { 67 67 public: 68 TDateEdit(BRect frame, const char* name, 69 uint32 sections); 68 TDateEdit(const char* name, uint32 sections); 70 69 virtual ~TDateEdit(); 71 70 virtual void KeyDown(const char* bytes, int32 numBytes); 72 71 73 72 virtual void InitView(); 74 virtual void DrawSection(uint32 index, bool isfocus); 75 virtual void DrawSeparator(uint32 index); 73 virtual void DrawSection(uint32 index, BRect bounds, 74 bool isfocus); 75 virtual void DrawSeparator(uint32 index, BRect bounds); 76 76 77 virtual void SetSections(BRect area);78 77 virtual void SectionFocus(uint32 index); 79 virtual float SeparatorWidth() const; 78 virtual float MinSectionWidth(); 79 virtual float SeparatorWidth(); 80 80 81 virtual float PreferredHeight(); 81 82 virtual void DoUpPress(); 82 83 virtual void DoDownPress(); 83 84 84 85 virtual void BuildDispatch(BMessage* message); 86 85 87 86 88 void SetDate(int32 year, int32 month, int32 day); 87 89 … … 90 92 void _CheckRange(); 91 93 bool _IsValidDoubleDigit(int32 value); 92 94 int32 _SectionValue(int32 index) const; 93 94 private: 95 95 96 BDate fDate; 96 97 bigtime_t fLastKeyDownTime; 97 98 int32 fLastKeyDownInt; … … 107 108 108 109 109 110 #endif // _DATE_TIME_EDIT_H 110 -
src/preferences/time/SectionEdit.cpp
1 1 /* 2 * Copyright 2004-20 07, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Mike Berg <mike@berg-net.us> 7 7 * Julun <host.haiku@gmx.de> 8 * 8 * Hamish Morrison <hamish@lavabit.com> 9 9 */ 10 10 11 12 11 #include "SectionEdit.h" 13 12 14 13 #include <Bitmap.h> 15 14 #include <ControlLook.h> 15 #include <LayoutUtils.h> 16 16 #include <List.h> 17 17 #include <Window.h> 18 18 19 19 #include "TimeMessages.h" 20 20 21 21 22 TSection::TSection(BRect frame)23 :24 fFrame(frame)25 {26 }27 28 29 BRect30 TSection::Bounds() const31 {32 BRect frame(fFrame);33 return frame.OffsetByCopy(B_ORIGIN);34 }35 36 37 void38 TSection::SetFrame(BRect frame)39 {40 fFrame = frame;41 }42 43 44 BRect45 TSection::Frame() const46 {47 return fFrame;48 }49 50 51 22 const uint32 kArrowAreaWidth = 16; 52 23 53 24 54 TSectionEdit::TSectionEdit( BRect frame,const char* name, uint32 sections)25 TSectionEdit::TSectionEdit(const char* name, uint32 sections) 55 26 : 56 BControl(frame, name, NULL, NULL, B_FOLLOW_NONE, B_NAVIGABLE | B_WILL_DRAW), 57 fSectionList(NULL), 27 BControl(name, NULL, NULL, B_WILL_DRAW | B_NAVIGABLE), 58 28 fFocus(-1), 59 29 fSectionCount(sections), 60 30 fHoldValue(0) 61 31 { 62 InitView();63 32 } 64 33 65 34 66 35 TSectionEdit::~TSectionEdit() 67 36 { 68 int32 count = fSectionList->CountItems();69 if (count > 0) {70 for (int32 index = 0; index < count; index++)71 delete (TSection*)fSectionList->ItemAt(index);72 }73 delete fSectionList;74 37 } 75 38 76 39 … … 88 51 DrawBorder(updateRect); 89 52 90 53 for (uint32 idx = 0; idx < fSectionCount; idx++) { 91 DrawSection(idx, ((uint32)fFocus == idx) && IsFocus()); 54 DrawSection(idx, FrameForSection(idx), 55 ((uint32)fFocus == idx) && IsFocus()); 92 56 if (idx < fSectionCount - 1) 93 DrawSeparator(idx );57 DrawSeparator(idx, FrameForSeparator(idx)); 94 58 } 95 59 } 96 60 … … 104 68 DoUpPress(); 105 69 else if (fDownRect.Contains(where)) 106 70 DoDownPress(); 107 else if (fSectionList->CountItems() > 0) { 108 TSection* section; 71 else if (fSectionCount > 0) { 109 72 for (uint32 idx = 0; idx < fSectionCount; idx++) { 110 section = (TSection*)fSectionList->ItemAt(idx); 111 if (section->Frame().Contains(where)) { 73 if (FrameForSection(idx).Contains(where)) { 112 74 SectionFocus(idx); 113 75 return; 114 76 } … … 117 79 } 118 80 119 81 82 BSize 83 TSectionEdit::MaxSize() 84 { 85 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 86 BSize(B_SIZE_UNLIMITED, PreferredHeight())); 87 } 88 89 90 BSize 91 TSectionEdit::MinSize() 92 { 93 BSize minSize; 94 minSize.height = PreferredHeight(); 95 minSize.width = (SeparatorWidth() + MinSectionWidth()) 96 * fSectionCount; 97 return BLayoutUtils::ComposeSize(ExplicitMinSize(), 98 minSize); 99 } 100 101 102 BSize 103 TSectionEdit::PreferredSize() 104 { 105 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), 106 MinSize()); 107 } 108 109 110 BRect 111 TSectionEdit::FrameForSection(uint32 index) 112 { 113 BRect area = SectionArea(); 114 float sepWidth = SeparatorWidth(); 115 116 float width = (area.Width() - 117 sepWidth * (fSectionCount - 1)) 118 / fSectionCount; 119 area.left += index * (width + sepWidth); 120 area.right = area.left + width; 121 122 return area; 123 } 124 125 126 BRect 127 TSectionEdit::FrameForSeparator(uint32 index) 128 { 129 BRect area = SectionArea(); 130 float sepWidth = SeparatorWidth(); 131 132 float width = (area.Width() - 133 sepWidth * (fSectionCount - 1)) 134 / fSectionCount; 135 area.left += (index + 1) * width + index * sepWidth; 136 area.right = area.left + sepWidth; 137 138 return area; 139 } 140 141 120 142 void 121 143 TSectionEdit::MakeFocus(bool focused) 122 144 { … … 181 203 uint32 182 204 TSectionEdit::CountSections() const 183 205 { 184 return fSection List->CountItems();206 return fSectionCount; 185 207 } 186 208 187 209 … … 192 214 } 193 215 194 216 195 void 196 TSectionEdit:: InitView()217 BRect 218 TSectionEdit::SectionArea() const 197 219 { 198 // setup sections 199 fSectionList = new BList(fSectionCount); 200 fSectionArea = Bounds().InsetByCopy(2, 2); 201 fSectionArea.right -= kArrowAreaWidth; 220 BRect sectionArea = Bounds().InsetByCopy(2, 2); 221 sectionArea.right -= kArrowAreaWidth; 222 return sectionArea; 202 223 } 203 224 204 225 … … 219 240 bounds.bottom / 2.0); 220 241 fDownRect = fUpRect.OffsetByCopy(0, fUpRect.Height() + 2); 221 242 222 BPoint middle(floorf(fUpRect.left + fUpRect.Width() / 2), fUpRect.top + 1); 243 BPoint middle(floorf(fUpRect.left + fUpRect.Width() / 2), 244 fUpRect.top + 1); 223 245 BPoint left(fUpRect.left + 3, fUpRect.bottom - 1); 224 246 BPoint right(left.x + 2 * (middle.x - left.x), fUpRect.bottom - 1); 225 247 226 248 SetPenSize(2); 249 SetLowColor(ViewColor()); 227 250 228 251 if (updateRect.Intersects(fUpRect)) { 229 252 FillRect(fUpRect, B_SOLID_LOW); … … 245 268 246 269 SetPenSize(1); 247 270 } 248 249 250 float251 TSectionEdit::SeparatorWidth() const252 {253 return 0.0f;254 } -
src/preferences/time/TimeSettings.cpp
19 19 20 20 21 21 TimeSettings::TimeSettings() 22 : fSettingsFile("Time_preflet_window") 22 : 23 fSettingsFile("Time_preflet_window") 23 24 { 24 25 } 25 26 … … 63 64 if (file.InitCheck() == B_OK) 64 65 file.Write(&leftTop, sizeof(BPoint)); 65 66 } 66 -
src/preferences/time/AnalogClock.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Mike Berg <mike@berg-net.us> 7 7 * Julun <host.haiku@gmx.de> 8 * Hamish Morrison <hamish@lavabit.com> 8 9 */ 9 10 #ifndef _ANALOG_CLOCK_H 10 11 #define _ANALOG_CLOCK_H … … 13 14 #include <View.h> 14 15 15 16 16 class BBitmap;17 class OffscreenClock;18 19 20 17 class TAnalogClock : public BView { 21 18 public: 22 TAnalogClock(BRect frame, const char* name, 23 bool drawSecondHand = true, bool interactive = true); 24 virtual ~TAnalogClock(); 19 TAnalogClock(const char* name, 20 bool drawSecondHand = true, 21 bool interactive = true); 22 virtual ~TAnalogClock(); 25 23 26 virtual void AttachedToWindow(); 27 virtual void Draw(BRect updateRect); 28 virtual void MessageReceived(BMessage* message); 29 virtual void MouseDown(BPoint point); 30 virtual void MouseUp(BPoint point); 31 virtual void MouseMoved(BPoint point, uint32 transit, 32 const BMessage* message); 24 virtual void Draw(BRect updateRect); 25 virtual void MessageReceived(BMessage* message); 26 virtual void MouseDown(BPoint point); 27 virtual void MouseUp(BPoint point); 28 virtual void MouseMoved(BPoint point, uint32 transit, 29 const BMessage* message); 30 virtual void FrameResized(float, float); 31 32 virtual BSize MaxSize(); 33 virtual BSize MinSize(); 34 virtual BSize PreferredSize(); 33 35 34 void SetTime(int32 hour, int32 minute, int32 second); 36 void SetTime(int32 hour, int32 minute, int32 second); 37 bool IsChangingTime(); 38 void ChangeTimeFinished(); 35 39 36 bool IsChangingTime() 37 { return fTimeChangeIsOngoing; } 38 void ChangeTimeFinished(); 40 void GetTime(int32* hour, int32* minute, int32* second); 41 void DrawClock(); 42 43 bool InHourHand(BPoint point); 44 bool InMinuteHand(BPoint point); 45 46 void SetHourHand(BPoint point); 47 void SetMinuteHand(BPoint point); 48 49 void SetHourDragging(bool dragging); 50 void SetMinuteDragging(bool dragging); 39 51 private: 40 void _InitView(BRect frame); 52 float _GetPhi(BPoint point); 53 bool _InHand(BPoint point, int32 ticks, float radius); 54 void _DrawHands(float x, float y, float radius, 55 rgb_color hourHourColor, 56 rgb_color hourMinuteColor, 57 rgb_color secondsColor, rgb_color knobColor); 41 58 42 BBitmap* fBitmap; 43 OffscreenClock* fClock; 59 int32 fHours; 60 int32 fMinutes; 61 int32 fSeconds; 62 bool fDirty; 63 64 float fCenterX; 65 float fCenterY; 66 float fRadius; 44 67 45 bool fDrawSecondHand;46 bool fInteractive;47 bool fDraggingHourHand;48 bool fDraggingMinuteHand;68 bool fHourDragging; 69 bool fMinuteDragging; 70 bool fDrawSecondHand; 71 bool fInteractive; 49 72 50 bool fTimeChangeIsOngoing;73 bool fTimeChangeIsOngoing; 51 74 }; 52 75 53 76 -
src/preferences/time/TimeWindow.cpp
1 1 /* 2 * Copyright 2004-20 07, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 7 * Julun <host.haiku@gmx.de> 8 * 8 * Hamish Morrison <hamish@lavabit.com> 9 9 */ 10 10 11 11 #include "TimeWindow.h" 12 #include "BaseView.h"13 #include "DateTimeView.h"14 #include "TimeMessages.h"15 #include "TimeSettings.h"16 #include "ZoneView.h"17 12 18 19 13 #include <Application.h> 14 #include <Button.h> 20 15 #include <Catalog.h> 16 #include <LayoutBuilder.h> 21 17 #include <Message.h> 22 18 #include <Screen.h> 23 19 #include <TabView.h> 24 #include <Button.h>25 20 21 #include "BaseView.h" 22 #include "DateTimeView.h" 23 #include "NetworkTimeView.h" 24 #include "TimeMessages.h" 25 #include "TimeSettings.h" 26 #include "ZoneView.h" 27 28 26 29 #undef B_TRANSLATE_CONTEXT 27 30 #define B_TRANSLATE_CONTEXT "Time" 28 31 29 TTimeWindow::TTimeWindow(BRect rect) 30 : BWindow(rect, B_TRANSLATE("Time"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE) 32 33 TTimeWindow::TTimeWindow() 34 : 35 BWindow(BRect(0, 0, 0, 0), B_TRANSLATE("Time"), B_TITLED_WINDOW, 36 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) 31 37 { 32 38 _InitWindow(); 33 39 _AlignWindow(); … … 41 47 } 42 48 43 49 44 void 45 TTimeWindow:: SetRevertStatus()50 bool 51 TTimeWindow::QuitRequested() 46 52 { 47 fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert() 48 || fTimeZoneView->CheckCanRevert()); 53 TimeSettings().SetLeftTop(Frame().LeftTop()); 54 55 fBaseView->StopWatchingAll(fTimeZoneView); 56 fBaseView->StopWatchingAll(fDateTimeView); 57 58 be_app->PostMessage(B_QUIT_REQUESTED); 59 60 return BWindow::QuitRequested(); 49 61 } 50 62 51 63 … … 57 69 fBaseView->ChangeTime(message); 58 70 // To make sure no old time message is in the queue 59 71 _SendTimeChangeFinished(); 60 SetRevertStatus();72 _SetRevertStatus(); 61 73 break; 62 74 63 75 case B_ABOUT_REQUESTED: … … 67 79 case kMsgRevert: 68 80 fDateTimeView->MessageReceived(message); 69 81 fTimeZoneView->MessageReceived(message); 82 fNetworkTimeView->MessageReceived(message); 70 83 fRevertButton->SetEnabled(false); 71 84 break; 72 85 73 86 case kRTCUpdate: 74 87 fDateTimeView->MessageReceived(message); 75 88 fTimeZoneView->MessageReceived(message); 76 SetRevertStatus();89 _SetRevertStatus(); 77 90 break; 78 91 92 case kMsgChange: 93 _SetRevertStatus(); 94 break; 95 79 96 default: 80 97 BWindow::MessageReceived(message); 81 98 break; … … 83 100 } 84 101 85 102 86 bool87 TTimeWindow::QuitRequested()88 {89 TimeSettings().SetLeftTop(Frame().LeftTop());90 91 fBaseView->StopWatchingAll(fTimeZoneView);92 fBaseView->StopWatchingAll(fDateTimeView);93 94 be_app->PostMessage(B_QUIT_REQUESTED);95 96 return BWindow::QuitRequested();97 }98 99 100 103 void 101 104 TTimeWindow::_InitWindow() 102 105 { 103 106 SetPulseRate(500000); 104 107 105 fDateTimeView = new DateTimeView(Bounds()); 108 fDateTimeView = new DateTimeView(B_TRANSLATE("Date and time")); 109 fTimeZoneView = new TimeZoneView(B_TRANSLATE("Time zone")); 110 fNetworkTimeView = new NetworkTimeView(B_TRANSLATE("Network time")); 106 111 107 BRect bounds = fDateTimeView->Bounds(); 108 fTimeZoneView = new TimeZoneView(bounds); 109 110 fBaseView = new TTimeBaseView(bounds, "baseView"); 111 AddChild(fBaseView); 112 112 fBaseView = new TTimeBaseView("baseView"); 113 113 fBaseView->StartWatchingAll(fDateTimeView); 114 114 fBaseView->StartWatchingAll(fTimeZoneView); 115 115 116 bounds.OffsetBy(10.0, 10.0); 117 BTabView* tabView = new BTabView(bounds.InsetByCopy(-5.0, -5.0), 118 "tabView" , B_WIDTH_AS_USUAL, B_FOLLOW_NONE); 119 120 BTab* tab = new BTab(); 121 tabView->AddTab(fDateTimeView, tab); 122 tab->SetLabel(B_TRANSLATE("Date & Time")); 123 124 tab = new BTab(); 125 tabView->AddTab(fTimeZoneView, tab); 126 tab->SetLabel(B_TRANSLATE("Time zone")); 127 116 BTabView* tabView = new BTabView("tabView"); 117 tabView->AddTab(fDateTimeView); 118 tabView->AddTab(fTimeZoneView); 119 tabView->AddTab(fNetworkTimeView); 120 128 121 fBaseView->AddChild(tabView); 129 tabView->ResizeBy(0.0, tabView->TabHeight());130 122 131 BRect rect = Bounds(); 132 133 rect.left = 10; 134 rect.top = rect.bottom - 10; 135 136 fRevertButton = new BButton(rect, "revert", B_TRANSLATE("Revert"), 137 new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); 138 139 fRevertButton->ResizeToPreferred(); 123 fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), 124 new BMessage(kMsgRevert)); 140 125 fRevertButton->SetEnabled(false); 141 float buttonHeight = fRevertButton->Bounds().Height();142 fRevertButton->MoveBy(0, -buttonHeight);143 fBaseView->AddChild(fRevertButton);144 126 fRevertButton->SetTarget(this); 145 146 fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0, 147 tabView->Bounds().Height() + buttonHeight + 30.0); 148 149 ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height()); 127 fRevertButton->SetExplicitAlignment( 128 BAlignment(B_ALIGN_LEFT, B_ALIGN_MIDDLE)); 129 130 BLayoutBuilder::Group<>(this, B_VERTICAL, 5) 131 .Add(fBaseView) 132 .Add(fRevertButton) 133 .SetInsets(5, 5, 5, 5); 150 134 } 151 135 152 136 … … 175 159 BMessage msg(kChangeTimeFinished); 176 160 messenger.SendMessage(&msg); 177 161 } 162 163 164 void 165 TTimeWindow::_SetRevertStatus() 166 { 167 fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert() 168 || fTimeZoneView->CheckCanRevert() 169 || fNetworkTimeView->CheckCanRevert()); 170 } -
src/preferences/time/Jamfile
12 12 DateTimeEdit.cpp 13 13 SectionEdit.cpp 14 14 DateTimeView.cpp 15 NetworkTimeView.cpp 16 ntp.cpp 15 17 Time.cpp 16 18 TimeSettings.cpp 17 19 TimeWindow.cpp … … 28 30 29 31 Preference Time 30 32 : $(sources) 31 : be libshared.a $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS) 33 : be libshared.a $(TARGET_LIBSTDC++) $(HAIKU_LOCALE_LIBS) $(HAIKU_NETWORK_LIBS) 32 34 : Time.rdef 33 35 ; 34 36 -
src/preferences/time/DateTimeView.cpp
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 9 * Philippe Saint-Pierre <stpere@gmail.com> 10 * Hamish Morrison <hamish@lavabit.com> 10 11 */ 11 12 12 13 #include "DateTimeView.h" 13 #include "AnalogClock.h"14 #include "DateTimeEdit.h"15 #include "TimeMessages.h"16 #include "TimeWindow.h"17 14 15 #include <time.h> 16 #include <syscalls.h> 17 18 #include <Box.h> 18 19 #include <CalendarView.h> 19 20 #include <Catalog.h> 20 21 #include <CheckBox.h> … … 25 26 #include <Message.h> 26 27 #include <Path.h> 27 28 #include <RadioButton.h> 28 #include <String.h>29 29 #include <StringView.h> 30 30 #include <Window.h> 31 31 32 #include <time.h> 32 #include "AnalogClock.h" 33 #include "DateTimeEdit.h" 34 #include "TimeMessages.h" 35 #include "TimeWindow.h" 33 36 34 #include <syscalls.h>35 37 36 38 #undef B_TRANSLATE_CONTEXT 37 39 #define B_TRANSLATE_CONTEXT "Time" … … 42 44 using BPrivate::B_LOCAL_TIME; 43 45 44 46 45 DateTimeView::DateTimeView( BRect frame)46 : BView(frame, "dateTimeView", B_FOLLOW_NONE, B_WILL_DRAW47 | B_NAVIGABLE_JUMP),47 DateTimeView::DateTimeView(const char* name) 48 : 49 BGroupView(name, B_HORIZONTAL, 5), 48 50 fGmtTime(NULL), 49 51 fUseGmtTime(false), 50 52 fInitialized(false), … … 208 210 void 209 211 DateTimeView::_InitView() 210 212 { 211 font_height fontHeight; 212 be_plain_font->GetHeight(&fontHeight); 213 float textHeight = fontHeight.descent + fontHeight.ascent 214 + fontHeight.leading + 6.0; // 6px border 215 216 // left side 217 BRect bounds = Bounds(); 218 bounds.InsetBy(10.0, 10.0); 219 bounds.top += textHeight + 10.0; 220 221 fCalendarView = new BCalendarView(bounds, "calendar"); 213 fCalendarView = new BCalendarView("calendar"); 222 214 fCalendarView->SetWeekNumberHeaderVisible(false); 223 fCalendarView->ResizeToPreferred();224 215 fCalendarView->SetSelectionMessage(new BMessage(kDayChanged)); 225 216 fCalendarView->SetInvocationMessage(new BMessage(kDayChanged)); 226 217 227 bounds.top -= textHeight + 10.0; 228 bounds.bottom = bounds.top + textHeight; 229 bounds.right = fCalendarView->Frame().right; 230 231 fDateEdit = new TDateEdit(bounds, "dateEdit", 3); 232 AddChild(fDateEdit); 233 AddChild(fCalendarView); 234 235 // right side, 2px extra for separator 236 bounds.OffsetBy(bounds.Width() + 22.0, 0.0); 237 fTimeEdit = new TTimeEdit(bounds, "timeEdit", 4); 238 AddChild(fTimeEdit); 239 240 bounds = fCalendarView->Frame(); 241 bounds.OffsetBy(bounds.Width() + 22.0, 0.0); 242 243 fClock = new TAnalogClock(bounds, "analogClock"); 244 AddChild(fClock); 218 fDateEdit = new TDateEdit("dateEdit", 3); 219 fTimeEdit = new TTimeEdit("timeEdit", 4); 220 fClock = new TAnalogClock("analogClock"); 221 245 222 BTime time(BTime::CurrentTime(B_LOCAL_TIME)); 246 223 fClock->SetTime(time.Hour(), time.Minute(), time.Second()); 247 224 248 // clock radio buttons 249 bounds.top = fClock->Frame().bottom + 10.0; 250 BStringView* text = new BStringView(bounds, "clockSetTo", 225 BStringView* text = new BStringView("clockSetTo", 251 226 B_TRANSLATE("Clock set to:")); 252 AddChild(text); 253 text->ResizeToPreferred(); 254 255 bounds.left += 10.0f; 256 bounds.top = text->Frame().bottom; 257 fLocalTime = new BRadioButton(bounds, "localTime", 227 fLocalTime = new BRadioButton("localTime", 258 228 B_TRANSLATE("Local time"), new BMessage(kRTCUpdate)); 259 AddChild(fLocalTime);260 fLocalTime->ResizeToPreferred();229 fGmtTime = new BRadioButton("greenwichMeanTime", 230 B_TRANSLATE("GMT"), new BMessage(kRTCUpdate)); 261 231 262 bounds.left = fLocalTime->Frame().right + 10.0;263 fGmtTime = new BRadioButton(bounds, "greenwichMeanTime",264 B_TRANSLATE("GMT"), new BMessage(kRTCUpdate));265 AddChild(fGmtTime);266 fGmtTime->ResizeToPreferred();267 268 232 if (fUseGmtTime) 269 233 fGmtTime->SetValue(B_CONTROL_ON); 270 234 else 271 235 fLocalTime->SetValue(B_CONTROL_ON); 272 273 236 fOldUseGmtTime = fUseGmtTime; 274 237 275 ResizeTo(fClock->Frame().right + 10.0, fGmtTime->Frame().bottom + 10.0); 238 BBox* divider = new BBox(BRect(0, 0, 1, 1), 239 B_EMPTY_STRING, B_FOLLOW_ALL_SIDES, 240 B_WILL_DRAW | B_FRAME_EVENTS, B_FANCY_BORDER); 241 divider->SetExplicitMaxSize(BSize(1, B_SIZE_UNLIMITED)); 242 243 BLayoutBuilder::Group<>(this) 244 .AddGroup(B_VERTICAL, 5) 245 .Add(fDateEdit) 246 .Add(fCalendarView) 247 .End() 248 .Add(divider) 249 .AddGroup(B_VERTICAL, 5) 250 .Add(fTimeEdit) 251 .Add(fClock) 252 .Add(text) 253 .AddGroup(B_HORIZONTAL, 5) 254 .Add(fLocalTime) 255 .Add(fGmtTime) 256 .End() 257 .End() 258 .SetInsets(5, 5, 5, 5); 276 259 } 277 260 278 261 -
src/preferences/time/TZDisplay.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 * 9 * Hamish Morrison <hamish@lavabit.com> 10 10 */ 11 11 #ifndef _TZ_DISPLAY_H 12 12 #define _TZ_DISPLAY_H 13 13 14 14 15 #include <String.h> 15 16 #include <View.h> 16 #include <String.h>17 17 18 18 19 19 class TTZDisplay : public BView { 20 20 public: 21 TTZDisplay( BRect frame,const char* name,21 TTZDisplay(const char* name, 22 22 const char* label); 23 23 virtual ~TTZDisplay(); 24 24 25 25 virtual void AttachedToWindow(); 26 26 virtual void ResizeToPreferred(); 27 27 virtual void Draw(BRect updateRect); 28 29 virtual BSize MaxSize(); 30 virtual BSize MinSize(); 31 virtual BSize PreferredSize(); 28 32 29 33 const char* Label() const; 30 34 void SetLabel(const char* label); … … 36 40 void SetTime(const char* time); 37 41 38 42 private: 43 BSize _CalcPrefSize(); 44 39 45 BString fLabel; 40 46 BString fText; 41 47 BString fTime; … … 43 49 44 50 45 51 #endif // _TZ_DISPLAY_H 46 -
src/preferences/time/Time.cpp
1 1 /* 2 * Copyright 2002-20 07, Haiku. All rights reserved.2 * Copyright 2002-2011, Haiku. All rights reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Andrew McCall <mccall@digitalparadise.co.uk> 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 * Hamish Morrison <hamish@lavabit.com> 9 10 */ 10 11 11 12 #include "Time.h" 12 #include "TimeWindow.h"13 13 14 #include <stdio.h> 15 #include <unistd.h> 14 16 15 17 #include <Alert.h> 16 18 #include <Catalog.h> 17 19 18 #include <unistd.h> 20 #include "NetworkTimeView.h" 21 #include "TimeWindow.h" 19 22 23 20 24 #undef B_TRANSLATE_CONTEXT 21 25 #define B_TRANSLATE_CONTEXT "Time" 22 26 27 23 28 const char* kAppSignature = "application/x-vnd.Haiku-Time"; 24 29 25 30 26 31 TimeApplication::TimeApplication() 27 : BApplication(kAppSignature), 28 fWindow(NULL) 32 : 33 BApplication(kAppSignature), 34 fWindow(NULL) 29 35 { 30 fWindow = new TTimeWindow( BRect(100, 100, 570, 327));36 fWindow = new TTimeWindow(); 31 37 } 32 38 33 39 … … 47 53 TimeApplication::AboutRequested() 48 54 { 49 55 BAlert* alert = new BAlert(B_TRANSLATE("about"), 50 B_TRANSLATE("Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" 51 "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku."), 56 B_TRANSLATE( 57 "Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" 58 "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku."), 52 59 B_TRANSLATE("OK")); 53 60 alert->Go(); 54 61 } 55 62 56 63 57 // #pragma mark -58 59 60 64 int 61 65 main(int argc, char** argv) 62 66 { 63 TimeApplication app; 64 setuid(0); 65 app.Run(); 67 if (argc > 1) { 68 if (strcmp(argv[1], "--update") != 0) 69 return 0; 70 71 Settings settings; 72 if (!settings.GetSynchronizeAtBoot()) 73 return 0; 66 74 75 const char* errorString = NULL; 76 int32 errorCode = 0; 77 if (update_time(settings, &errorString, &errorCode) == B_OK) 78 printf("Synchronization successful\r\n"); 79 else if (errorCode != 0) 80 printf("The following error occured " 81 "while synchronizing:\r\n%s: %s\r\n", 82 errorString, strerror(errorCode)); 83 else 84 printf("The following error occured " 85 "while synchronizing:\r\n%s\r\n", 86 errorString); 87 } 88 else { 89 TimeApplication app; 90 setuid(0); 91 app.Run(); 92 } 93 67 94 return 0; 68 95 } 69 -
src/preferences/time/DateTimeEdit.cpp
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 8 8 * Julun <host.haiku@gmx.de> 9 9 * Clemens <mail@Clemens-Zeidler.de> 10 10 * Adrien Destugues <pulkomandy@pulkomandy.cx> 11 * Hamish Morrison <hamish@lavabit.com> 11 12 */ 12 13 13 14 14 #include "DateTimeEdit.h" 15 15 16 16 #include <stdlib.h> … … 24 24 using BPrivate::B_LOCAL_TIME; 25 25 26 26 27 TTimeEdit::TTimeEdit( BRect frame,const char* name, uint32 sections)27 TTimeEdit::TTimeEdit(const char* name, uint32 sections) 28 28 : 29 TSectionEdit( frame,name, sections),29 TSectionEdit(name, sections), 30 30 fLastKeyDownTime(0), 31 31 fFields(NULL), 32 32 fFieldCount(0), … … 57 57 int32 section = FocusIndex(); 58 58 if (section < 0 || section > 2) 59 59 return; 60 61 60 bigtime_t currentTime = system_time(); 62 61 if (currentTime - fLastKeyDownTime < 1000000) { 63 62 int32 doubleDigit = number + fLastKeyDownInt * 10; … … 84 83 { 85 84 // make sure we call the base class method, as it 86 85 // will create the arrow bitmaps and the section list 87 TSectionEdit::InitView();88 89 86 fTime = BDateTime::CurrentDateTime(B_LOCAL_TIME); 90 87 _UpdateFields(); 91 92 SetSections(fSectionArea);93 88 } 94 89 95 90 96 91 void 97 TTimeEdit::DrawSection(uint32 index, bool hasFocus)92 TTimeEdit::DrawSection(uint32 index, BRect bounds, bool hasFocus) 98 93 { 99 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index));100 if (!section)101 return;102 103 94 if (fFieldPositions == NULL || index * 2 + 1 >= (uint32)fFieldPosCount) 104 95 return; 105 106 BRect bounds = section->Frame();107 108 96 SetLowColor(ViewColor()); 109 97 if (hasFocus) 110 98 SetLowColor(tint_color(ViewColor(), B_DARKEN_1_TINT)); … … 113 101 fText.CopyCharsInto(field, fFieldPositions[index * 2], 114 102 fFieldPositions[index * 2 + 1] - fFieldPositions[index * 2]); 115 103 116 // calc and center text in section rect 117 float width = be_plain_font->StringWidth(field); 118 119 BPoint offset(-((bounds.Width()- width) / 2.0) - 1.0, 120 bounds.Height() / 2.0 - 6.0); 121 104 BPoint point(bounds.LeftBottom()); 105 point.y -= bounds.Height() / 2.0 - 6.0; 106 point.x += (bounds.Width() - StringWidth(field)) / 2; 122 107 SetHighColor(0, 0, 0, 255); 123 108 FillRect(bounds, B_SOLID_LOW); 124 DrawString(field, bounds.LeftBottom() - offset);109 DrawString(field, point); 125 110 } 126 111 127 112 128 113 void 129 TTimeEdit::DrawSeparator(uint32 index )114 TTimeEdit::DrawSeparator(uint32 index, BRect bounds) 130 115 { 131 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index));132 if (!section)133 return;134 135 116 if (fFieldPositions == NULL || index * 2 + 2 >= (uint32)fFieldPosCount) 136 117 return; 137 118 … … 139 120 fText.CopyCharsInto(field, fFieldPositions[index * 2 + 1], 140 121 fFieldPositions[index * 2 + 2] - fFieldPositions[index * 2 + 1]); 141 122 142 float sepWidth = SeparatorWidth(); 143 BRect bounds = section->Frame(); 144 float width = be_plain_font->StringWidth(field); 145 BPoint offset(-((sepWidth - width) / 2.0) - 1.0, 146 bounds.Height() / 2.0 - 6.0); 147 DrawString(field, bounds.RightBottom() - offset); 123 BPoint point(bounds.LeftBottom()); 124 point.y -= bounds.Height() / 2.0 - 6.0; 125 point.x += (bounds.Width() - StringWidth(field)) / 2; 126 SetHighColor(0, 0, 0, 255); 127 DrawString(field, point); 148 128 } 149 129 150 130 151 void 152 TTimeEdit::Se tSections(BRect area)131 float 132 TTimeEdit::SeparatorWidth() 153 133 { 154 // by default divide up the sections evenly 155 BRect bounds(area); 156 157 float sepWidth = SeparatorWidth(); 158 159 float sep_2 = ceil(sepWidth / fSectionCount + 1); 160 float width = bounds.Width() / fSectionCount - sep_2; 161 bounds.right = bounds.left + (width - sepWidth / fSectionCount); 162 163 for (uint32 idx = 0; idx < fSectionCount; idx++) { 164 fSectionList->AddItem(new TSection(bounds)); 165 166 bounds.left = bounds.right + sepWidth; 167 if (idx == fSectionCount - 2) 168 bounds.right = area.right - 1; 169 else 170 bounds.right = bounds.left + (width - sep_2); 171 } 134 return 10.0f; 172 135 } 173 136 174 137 175 138 float 176 TTimeEdit:: SeparatorWidth() const139 TTimeEdit::MinSectionWidth() 177 140 { 178 return 10.0f;141 return be_plain_font->StringWidth("00"); 179 142 } 180 143 181 144 … … 236 199 237 200 // send message to change time 238 201 DispatchMessage(); 202 239 203 } 240 204 241 205 … … 247 211 248 212 message->AddBool("time", true); 249 213 250 for (int32 index = 0; index < fSectionList->CountItems() - 1; ++index) {214 for (int32 index = 0; index < (int)fSectionCount; ++index) { 251 215 uint32 data = _SectionValue(index); 252 216 253 217 if (fFocus == index) … … 277 241 TTimeEdit::_UpdateFields() 278 242 { 279 243 time_t time = fTime.Time_t(); 280 244 281 245 if (fFieldPositions != NULL) { 282 246 free(fFieldPositions); 283 247 fFieldPositions = NULL; 284 248 } 285 BLocale::Default()->FormatTime(&fText, fFieldPositions, fFieldPosCount,286 time, B_MEDIUM_TIME_FORMAT);249 BLocale::Default()->FormatTime(&fText, fFieldPositions, 250 fFieldPosCount, time, B_MEDIUM_TIME_FORMAT); 287 251 288 252 if (fFields != NULL) { 289 253 free(fFields); … … 415 379 } 416 380 417 381 382 float 383 TTimeEdit::PreferredHeight() 384 { 385 font_height fontHeight; 386 GetFontHeight(&fontHeight); 387 return ceilf((fontHeight.ascent + fontHeight.descent) * 1.4); 388 } 389 390 418 391 // #pragma mark - 419 392 420 393 421 TDateEdit::TDateEdit( BRect frame,const char* name, uint32 sections)394 TDateEdit::TDateEdit(const char* name, uint32 sections) 422 395 : 423 TSectionEdit( frame,name, sections),396 TSectionEdit(name, sections), 424 397 fFields(NULL), 425 398 fFieldCount(0), 426 399 fFieldPositions(NULL), … … 486 459 { 487 460 // make sure we call the base class method, as it 488 461 // will create the arrow bitmaps and the section list 489 TSectionEdit::InitView();490 491 462 fDate = BDate::CurrentDate(B_LOCAL_TIME); 492 463 _UpdateFields(); 493 494 SetSections(fSectionArea);495 464 } 496 465 497 466 498 467 void 499 TDateEdit::DrawSection(uint32 index, bool hasFocus)468 TDateEdit::DrawSection(uint32 index, BRect bounds, bool hasFocus) 500 469 { 501 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index));502 if (!section)503 return;504 505 470 if (fFieldPositions == NULL || index * 2 + 1 >= (uint32)fFieldPosCount) 506 471 return; 507 472 … … 513 478 fText.CopyCharsInto(field, fFieldPositions[index * 2], 514 479 fFieldPositions[index * 2 + 1] - fFieldPositions[index * 2]); 515 480 516 // calc and center text in section rect 517 BRect bounds = section->Frame(); 518 float width = StringWidth(field); 519 BPoint offset(-(bounds.Width() - width) / 2.0 - 1.0, 520 (bounds.Height() / 2.0 - 6.0)); 521 481 BPoint point(bounds.LeftBottom()); 482 point.y -= bounds.Height() / 2.0 - 6.0; 483 point.x += (bounds.Width() - StringWidth(field)) / 2; 522 484 SetHighColor(0, 0, 0, 255); 523 485 FillRect(bounds, B_SOLID_LOW); 524 DrawString(field, bounds.LeftBottom() - offset);486 DrawString(field, point); 525 487 } 526 488 527 489 528 490 void 529 TDateEdit::DrawSeparator(uint32 index )491 TDateEdit::DrawSeparator(uint32 index, BRect bounds) 530 492 { 531 493 if (index >= 2) 532 494 return; 533 495 534 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(index));535 if (!section)536 return;537 538 496 if (fFieldPositions == NULL || index * 2 + 2 >= (uint32)fFieldPosCount) 539 497 return; 540 498 … … 542 500 fText.CopyCharsInto(field, fFieldPositions[index * 2 + 1], 543 501 fFieldPositions[index * 2 + 2] - fFieldPositions[index * 2 + 1]); 544 502 545 BRect bounds = section->Frame(); 546 float width = be_plain_font->StringWidth(field); 547 float sepWidth = SeparatorWidth(); 548 BPoint offset(-((sepWidth - width) / 2.0) - 1.0, 549 bounds.Height() / 2.0 - 6.0); 550 503 BPoint point(bounds.LeftBottom()); 504 point.y -= bounds.Height() / 2.0 - 6.0; 505 point.x += (bounds.Width() - StringWidth(field)) / 2; 551 506 SetHighColor(0, 0, 0, 255); 552 DrawString(field, bounds.RightBottom() - offset);507 DrawString(field, point); 553 508 } 554 509 555 510 556 511 void 557 TDateEdit::Se tSections(BRect area)512 TDateEdit::SectionFocus(uint32 index) 558 513 { 559 // TODO : we have to be more clever here, as the fields can move and have 560 // different sizes depending on the locale 561 562 // create sections 563 for (uint32 idx = 0; idx < fSectionCount; idx++) 564 fSectionList->AddItem(new TSection(area)); 565 566 BRect bounds(area); 567 float sepWidth = SeparatorWidth(); 568 569 TSection* section = static_cast<TSection*>(fSectionList->ItemAt(0)); 570 float width = be_plain_font->StringWidth("0000") + 10; 571 bounds.left = area.left; 572 bounds.right = bounds.left + width; 573 section->SetFrame(bounds); 574 575 section = static_cast<TSection*>(fSectionList->ItemAt(1)); 576 width = be_plain_font->StringWidth("0000") + 10; 577 bounds.left = bounds.right + sepWidth; 578 bounds.right = bounds.left + width; 579 section->SetFrame(bounds); 580 581 section = static_cast<TSection*>(fSectionList->ItemAt(2)); 582 width = be_plain_font->StringWidth("0000") + 10; 583 bounds.left = bounds.right + sepWidth; 584 bounds.right = bounds.left + width; 585 section->SetFrame(bounds); 514 fLastKeyDownTime = 0; 515 fFocus = index; 516 fHoldValue = _SectionValue(index); 517 Draw(Bounds()); 586 518 } 587 519 588 520 589 521 float 590 TDateEdit:: SeparatorWidth() const522 TDateEdit::MinSectionWidth() 591 523 { 592 return 10.0f;524 return be_plain_font->StringWidth("00"); 593 525 } 594 526 595 527 596 void 597 TDateEdit::Se ctionFocus(uint32 index)528 float 529 TDateEdit::SeparatorWidth() 598 530 { 599 fLastKeyDownTime = 0; 600 fFocus = index; 601 fHoldValue = _SectionValue(index); 602 Draw(Bounds()); 531 return 10.0f; 603 532 } 604 533 605 534 … … 657 586 658 587 message->AddBool("time", false); 659 588 660 for (int32 index = 0; index < fSectionList->CountItems(); ++index) {589 for (int32 index = 0; index < (int)fSectionCount; ++index) { 661 590 uint32 data = _SectionValue(index); 662 591 663 592 if (fFocus == index) … … 687 616 TDateEdit::_UpdateFields() 688 617 { 689 618 time_t time = BDateTime(fDate, BTime()).Time_t(); 690 619 691 620 if (fFieldPositions != NULL) { 692 621 free(fFieldPositions); 693 622 fFieldPositions = NULL; 694 623 } 695 624 BLocale::Default()->FormatDate(&fText, fFieldPositions, fFieldPosCount, 696 625 time, B_SHORT_DATE_FORMAT); 697 626 698 627 if (fFields != NULL) { 699 628 free(fFields); 700 629 fFields = NULL; 701 } 630 } 702 631 BLocale::Default()->GetDateFields(fFields, fFieldCount, 703 632 B_SHORT_DATE_FORMAT); 704 633 } … … 817 746 818 747 return value; 819 748 } 749 750 751 float 752 TDateEdit::PreferredHeight() 753 { 754 font_height fontHeight; 755 GetFontHeight(&fontHeight); 756 return ceilf((fontHeight.ascent + fontHeight.descent) * 1.4); 757 } -
src/preferences/time/ntp.h
1 /* 2 * Copyright 2004, pinc Software. All Rights Reserved. 3 * Distributed under the terms of the MIT license. 4 */ 5 #ifndef NTP_H 6 #define NTP_H 7 8 9 #include <SupportDefs.h> 10 11 12 extern status_t ntp_update_time(const char *host, 13 const char** errorString, int32* errorCode); 14 15 16 #endif /* NTP_H */ -
src/preferences/time/NetworkTimeView.h
1 /* 2 * Copyright 2011, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Hamish Morrison <hamish@lavabit.com> 7 * Axel Dörfler <axeld@pinc-software.de> 8 */ 9 #ifndef NETWORK_TIME_VIEW_H 10 #define NETWORK_TIME_VIEW_H 11 12 13 #include <LayoutBuilder.h> 14 15 16 class BButton; 17 class BCheckBox; 18 class BListView; 19 class BTextControl; 20 class BMessage; 21 class BMessenger; 22 class BPath; 23 class Settings; 24 25 26 static const uint32 kMsgNetworkTimeSettings = 'ntst'; 27 static const uint32 kMsgSetDefaultServer = 'setd'; 28 static const uint32 kMsgAddServer = 'asrv'; 29 static const uint32 kMsgRemoveServer = 'rsrv'; 30 static const uint32 kMsgResetServerList = 'rstl'; 31 static const uint32 kMsgTryAllServers = 'tras'; 32 static const uint32 kMsgSynchronizeAtBoot = 'synb'; 33 static const uint32 kMsgSynchronize = 'sync'; 34 static const uint32 kMsgStopSynchronization = 'stps'; 35 static const uint32 kMsgSynchronizationResult = 'syrs'; 36 static const uint32 kMsgNetworkTimeChange = 'ntch'; 37 38 39 status_t 40 update_time(const Settings& settings, BMessenger* messenger, 41 thread_id* thread); 42 43 44 status_t 45 update_time(const Settings& settings, const char** errorString, 46 int32* errorCode); 47 48 49 class Settings { 50 public: 51 Settings(); 52 ~Settings(); 53 54 void AddServer(const char* server); 55 const char* GetServer(int32 index) const; 56 void RemoveServer(const char* server); 57 void SetDefaultServer(int32 index); 58 int32 GetDefaultServer() const; 59 void SetTryAllServers(bool boolean); 60 bool GetTryAllServers() const; 61 void SetSynchronizeAtBoot(bool boolean); 62 bool GetSynchronizeAtBoot() const; 63 64 void ResetServersToDefaults(); 65 void ResetToDefaults(); 66 void Revert(); 67 bool SettingsChanged(); 68 69 status_t Load(); 70 status_t Save(); 71 72 private: 73 int32 _GetStringByValue(const char* name, 74 const char* value); 75 status_t _GetPath(BPath& path); 76 77 BMessage fMessage; 78 BMessage fOldMessage; 79 bool fWasUpdated; 80 }; 81 82 83 class NetworkTimeView : public BGroupView { 84 public: 85 NetworkTimeView(const char* name); 86 87 virtual void MessageReceived(BMessage* message); 88 virtual void AttachedToWindow(); 89 90 bool CheckCanRevert(); 91 private: 92 void _InitView(); 93 void _UpdateServerList(); 94 void _DoneSynchronizing(); 95 96 Settings fSettings; 97 98 BTextControl* fServerTextControl; 99 BButton* fAddButton; 100 BButton* fRemoveButton; 101 BButton* fResetButton; 102 103 BListView* fServerListView; 104 BCheckBox* fTryAllServersCheckBox; 105 BCheckBox* fSynchronizeAtBootCheckBox; 106 BButton* fSynchronizeButton; 107 108 thread_id fUpdateThread; 109 }; 110 111 #endif -
src/preferences/time/TimeZoneListItem.h
5 5 * Authors: 6 6 * Adrien Destugues <pulkomandy@pulkomandy.ath.cx> 7 7 */ 8 9 8 #ifndef _TIME_ZONE_LIST_ITEM_H 10 9 #define _TIME_ZONE_LIST_ITEM_H 11 10 -
src/preferences/time/BaseView.h
10 10 #define _BASE_VIEW_H 11 11 12 12 13 #include <LayoutBuilder.h> 13 14 #include <Message.h> 14 #include <View.h>15 15 16 16 17 class TTimeBaseView : public BView {17 class TTimeBaseView : public BGroupView { 18 18 public: 19 TTimeBaseView( BRect frame,const char* name);19 TTimeBaseView(const char* name); 20 20 virtual ~TTimeBaseView(); 21 21 22 22 virtual void Pulse(); … … 26 26 27 27 private: 28 28 void _SendNotices(); 29 30 private: 29 31 30 BMessage fMessage; 32 31 }; 33 32 -
src/preferences/time/ZoneView.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Mike Berg <mike@berg-net.us> 7 7 * Julun <host.haiku@gmx.de> 8 * Hamish Morrison <hamish@lavabit.com> 8 9 */ 9 10 #ifndef ZONE_VIEW_H 10 11 #define ZONE_VIEW_H 11 12 12 13 14 #include <LayoutBuilder.h> 13 15 #include <TimeZone.h> 14 #include <View.h>15 16 16 17 17 18 class BButton; … … 24 25 class TTZDisplay; 25 26 26 27 27 class TimeZoneView : public B View {28 class TimeZoneView : public BGroupView { 28 29 public: 29 TimeZoneView( BRect frame);30 TimeZoneView(const char* name); 30 31 virtual ~TimeZoneView(); 31 32 32 33 virtual void AttachedToWindow(); … … 51 52 52 53 void _Revert(); 53 54 54 private:55 55 BOutlineListView* fZoneList; 56 56 BButton* fSetZone; 57 57 TTZDisplay* fCurrent; -
src/preferences/time/AnalogClock.cpp
1 1 /* 2 * Copyright 2004-20 09, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 7 7 * Julun <host.haiku@gmx.de> 8 8 * Stephan Aßmus <superstippi@gmx.de> 9 9 * Clemens <mail@Clemens-Zeidler.de> 10 * Hamish Morrison <hamish@lavabit.com> 10 11 */ 11 12 12 13 #include "AnalogClock.h" … … 14 15 #include <math.h> 15 16 #include <stdio.h> 16 17 17 #include < Bitmap.h>18 #include <LayoutUtils.h> 18 19 #include <Message.h> 19 20 #include <Window.h> 20 21 … … 24 25 #define DRAG_DELTA_PHI 0.2 25 26 26 27 27 class OffscreenClock : public BView { 28 public: 29 OffscreenClock(BRect frame, const char* name, 30 bool drawSecondHand = true); 31 virtual ~OffscreenClock(); 28 TAnalogClock::TAnalogClock(const char* name, 29 bool drawSecondHand, bool interactive) 30 : 31 BView(name, B_WILL_DRAW | B_DRAW_ON_CHILDREN | B_FRAME_EVENTS), 32 fHours(0), 33 fMinutes(0), 34 fSeconds(0), 35 fDirty(true), 36 fHourDragging(false), 37 fMinuteDragging(false), 38 fDrawSecondHand(drawSecondHand), 39 fInteractive(interactive), 40 fTimeChangeIsOngoing(false) 41 { 42 SetFlags(Flags() | B_SUBPIXEL_PRECISE); 43 } 32 44 33 void SetTime(int32 hour, int32 minute, int32 second);34 void GetTime(int32* hour, int32* minute, int32* second);35 bool IsDirty() const { return fDirty; }36 void DrawClock();37 45 38 bool InHourHand(BPoint point); 39 bool InMinuteHand(BPoint point); 46 TAnalogClock::~TAnalogClock() 47 { 48 } 40 49 41 void SetHourHand(BPoint point);42 void SetMinuteHand(BPoint point);43 50 44 void SetHourDragging(bool dragging); 45 void SetMinuteDragging(bool dragging); 51 void 52 TAnalogClock::MessageReceived(BMessage* message) 53 { 54 int32 change; 55 switch (message->what) { 56 case B_OBSERVER_NOTICE_CHANGE: 57 message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change); 58 switch (change) { 59 case H_TM_CHANGED: 60 { 61 int32 hour = 0; 62 int32 minute = 0; 63 int32 second = 0; 64 if (message->FindInt32("hour", &hour) == B_OK 65 && message->FindInt32("minute", &minute) == B_OK 66 && message->FindInt32("second", &second) == B_OK) 67 SetTime(hour, minute, second); 68 break; 69 } 70 default: 71 BView::MessageReceived(message); 72 break; 73 } 74 break; 75 default: 76 BView::MessageReceived(message); 77 break; 78 } 79 } 46 80 47 private:48 float _GetPhi(BPoint point);49 bool _InHand(BPoint point, int32 ticks, float radius);50 void _DrawHands(float x, float y, float radius,51 rgb_color hourHourColor,52 rgb_color hourMinuteColor,53 rgb_color secondsColor, rgb_color knobColor);54 81 55 int32 fHours; 56 int32 fMinutes; 57 int32 fSeconds; 58 bool fDirty; 82 void 83 TAnalogClock::MouseDown(BPoint point) 84 { 85 if(!fInteractive) { 86 BView::MouseDown(point); 87 return; 88 } 89 90 if (InMinuteHand(point)) { 91 fMinuteDragging = true; 92 fDirty = true; 93 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); 94 Invalidate(); 95 return; 96 } 97 if (InHourHand(point)) { 98 fHourDragging = true; 99 fDirty = true; 100 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS); 101 Invalidate(); 102 return; 103 } 104 } 59 105 60 float fCenterX;61 float fCenterY;62 float fRadius;63 106 64 bool fHourDragging; 65 bool fMinuteDragging; 66 67 bool fDrawSecondHand; 68 }; 107 void 108 TAnalogClock::MouseUp(BPoint point) 109 { 110 if(!fInteractive) { 111 BView::MouseUp(point); 112 return; 113 } 114 115 if (fHourDragging || fMinuteDragging) { 116 int32 hour, minute, second; 117 GetTime(&hour, &minute, &second); 118 BMessage message(H_USER_CHANGE); 119 message.AddBool("time", true); 120 message.AddInt32("hour", hour); 121 message.AddInt32("minute", minute); 122 Window()->PostMessage(&message); 123 fTimeChangeIsOngoing = true; 124 } 125 fHourDragging = false; 126 fDirty = true; 127 fMinuteDragging = false; 128 fDirty = true; 129 } 69 130 70 131 71 OffscreenClock::OffscreenClock(BRect frame, const char* name, 72 bool drawSecondHand) 73 : 74 BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW), 75 fHours(0), 76 fMinutes(0), 77 fSeconds(0), 78 fDirty(true), 79 fHourDragging(false), 80 fMinuteDragging(false), 81 fDrawSecondHand(drawSecondHand) 132 void 133 TAnalogClock::MouseMoved(BPoint point, uint32 transit, const BMessage* message) 82 134 { 83 SetFlags(Flags() | B_SUBPIXEL_PRECISE); 135 if(!fInteractive) { 136 BView::MouseMoved(point, transit, message); 137 return; 138 } 84 139 85 BRect bounds = Bounds(); 86 fCenterX = floorf((bounds.left + bounds.right) / 2 + 0.5) + 0.5; 87 fCenterY = floorf((bounds.top + bounds.bottom) / 2 + 0.5) + 0.5; 88 // + 0.5 is for the offset to pixel centers 89 // (important when drawing with B_SUBPIXEL_PRECISE) 140 if (fMinuteDragging) 141 SetMinuteHand(point); 142 if (fHourDragging) 143 SetHourHand(point); 90 144 91 fRadius = floorf((MIN(bounds.Width(), bounds.Height()) / 2.0)) - 2.5; 92 fRadius -= 3; 145 Invalidate(); 93 146 } 94 147 95 148 96 OffscreenClock::~OffscreenClock() 149 void 150 TAnalogClock::Draw(BRect /*updateRect*/) 97 151 { 152 if (fDirty) 153 DrawClock(); 98 154 } 99 155 100 156 101 157 void 102 OffscreenClock::SetTime(int32 hour, int32 minute, int32 second)158 TAnalogClock::SetTime(int32 hour, int32 minute, int32 second) 103 159 { 160 // don't set the time if the hands are in a drag action 161 if (fHourDragging || fMinuteDragging || fTimeChangeIsOngoing) 162 return; 163 104 164 if (fHours == hour && fMinutes == minute && fSeconds == second) 105 165 return; 106 166 … … 109 169 fSeconds = second; 110 170 111 171 fDirty = true; 172 173 BWindow* window = Window(); 174 if (window && window->Lock()) { 175 Invalidate(); 176 Window()->Unlock(); 177 } 112 178 } 113 179 114 180 181 bool 182 TAnalogClock::IsChangingTime() 183 { 184 return fTimeChangeIsOngoing; 185 } 186 187 115 188 void 116 OffscreenClock::GetTime(int32* hour, int32* minute, int32* second)189 TAnalogClock::ChangeTimeFinished() 117 190 { 191 fTimeChangeIsOngoing = false; 192 } 193 194 195 void 196 TAnalogClock::GetTime(int32* hour, int32* minute, int32* second) 197 { 118 198 *hour = fHours; 119 199 *minute = fMinutes; 120 200 *second = fSeconds; … … 122 202 123 203 124 204 void 125 OffscreenClock::DrawClock()205 TAnalogClock::DrawClock() 126 206 { 127 207 if (!LockLooper()) 128 208 return; … … 132 212 rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR); 133 213 SetHighColor(background); 134 214 FillRect(bounds); 135 136 215 137 216 bounds.Set(fCenterX - fRadius, fCenterY - fRadius, 138 217 fCenterX + fRadius, fCenterY + fRadius); 139 218 … … 207 286 } 208 287 209 288 289 void 290 TAnalogClock::FrameResized(float, float) 291 { 292 BRect bounds = Bounds(); 293 294 // + 0.5 is for the offset to pixel centers 295 // (important when drawing with B_SUBPIXEL_PRECISE) 296 fCenterX = floorf((bounds.left + bounds.right) / 2 + 0.5) + 0.5; 297 fCenterY = floorf((bounds.top + bounds.bottom) / 2 + 0.5) + 0.5; 298 fRadius = floorf((MIN(bounds.Width(), bounds.Height()) / 2.0)) - 2.5; 299 fRadius -= 3; 300 } 301 302 303 BSize 304 TAnalogClock::MaxSize() 305 { 306 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 307 BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); 308 } 309 310 311 BSize 312 TAnalogClock::MinSize() 313 { 314 return BSize(0, 0); 315 } 316 317 318 BSize 319 TAnalogClock::PreferredSize() 320 { 321 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), 322 BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); 323 } 324 325 210 326 bool 211 OffscreenClock::InHourHand(BPoint point)327 TAnalogClock::InHourHand(BPoint point) 212 328 { 213 329 int32 ticks = fHours; 214 330 if (ticks > 12) … … 222 338 223 339 224 340 bool 225 OffscreenClock::InMinuteHand(BPoint point)341 TAnalogClock::InMinuteHand(BPoint point) 226 342 { 227 343 return _InHand(point, fMinutes, fRadius * 0.9); 228 344 } 229 345 230 346 231 347 void 232 OffscreenClock::SetHourHand(BPoint point)348 TAnalogClock::SetHourHand(BPoint point) 233 349 { 234 350 point.x -= fCenterX; 235 351 point.y -= fCenterY; … … 247 363 248 364 249 365 void 250 OffscreenClock::SetMinuteHand(BPoint point)366 TAnalogClock::SetMinuteHand(BPoint point) 251 367 { 252 368 point.x -= fCenterX; 253 369 point.y -= fCenterY; … … 260 376 } 261 377 262 378 263 void264 OffscreenClock::SetHourDragging(bool dragging)265 {266 fHourDragging = dragging;267 fDirty = true;268 }269 270 271 void272 OffscreenClock::SetMinuteDragging(bool dragging)273 {274 fMinuteDragging = dragging;275 fDirty = true;276 }277 278 279 379 float 280 OffscreenClock::_GetPhi(BPoint point)380 TAnalogClock::_GetPhi(BPoint point) 281 381 { 282 382 if (point.x == 0 && point.y < 0) 283 383 return 2 * M_PI; … … 302 402 303 403 304 404 bool 305 OffscreenClock::_InHand(BPoint point, int32 ticks, float radius)405 TAnalogClock::_InHand(BPoint point, int32 ticks, float radius) 306 406 { 307 407 point.x -= fCenterX; 308 408 point.y -= fCenterY; … … 323 423 324 424 325 425 void 326 OffscreenClock::_DrawHands(float x, float y, float radius, 327 rgb_color hourColor, 328 rgb_color minuteColor, 329 rgb_color secondsColor, 330 rgb_color knobColor) 426 TAnalogClock::_DrawHands(float x, float y, float radius, 427 rgb_color hourColor, rgb_color minuteColor, 428 rgb_color secondsColor, rgb_color knobColor) 331 429 { 332 430 float offsetX; 333 431 float offsetY; … … 361 459 SetHighColor(knobColor); 362 460 FillEllipse(BPoint(x, y), radius * 0.06, radius * 0.06); 363 461 } 364 365 366 // #pragma mark -367 368 369 TAnalogClock::TAnalogClock(BRect frame, const char* name,370 bool drawSecondHand, bool interactive)371 :372 BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN),373 fBitmap(NULL),374 fClock(NULL),375 fDrawSecondHand(drawSecondHand),376 fInteractive(interactive),377 fDraggingHourHand(false),378 fDraggingMinuteHand(false),379 fTimeChangeIsOngoing(false)380 {381 _InitView(frame);382 }383 384 385 TAnalogClock::~TAnalogClock()386 {387 delete fBitmap;388 }389 390 391 void392 TAnalogClock::_InitView(BRect rect)393 {394 fClock = new OffscreenClock(Bounds(), "offscreen", fDrawSecondHand);395 fBitmap = new BBitmap(Bounds(), B_RGB32, true);396 fBitmap->Lock();397 fBitmap->AddChild(fClock);398 fBitmap->Unlock();399 }400 401 402 void403 TAnalogClock::AttachedToWindow()404 {405 SetViewColor(B_TRANSPARENT_COLOR);406 }407 408 409 void410 TAnalogClock::MessageReceived(BMessage* message)411 {412 int32 change;413 switch (message->what) {414 case B_OBSERVER_NOTICE_CHANGE:415 message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);416 switch (change) {417 case H_TM_CHANGED:418 {419 int32 hour = 0;420 int32 minute = 0;421 int32 second = 0;422 if (message->FindInt32("hour", &hour) == B_OK423 && message->FindInt32("minute", &minute) == B_OK424 && message->FindInt32("second", &second) == B_OK)425 SetTime(hour, minute, second);426 break;427 }428 default:429 BView::MessageReceived(message);430 break;431 }432 break;433 default:434 BView::MessageReceived(message);435 break;436 }437 }438 439 440 void441 TAnalogClock::MouseDown(BPoint point)442 {443 if(!fInteractive) {444 BView::MouseDown(point);445 return;446 }447 448 fDraggingMinuteHand = fClock->InMinuteHand(point);449 if (fDraggingMinuteHand) {450 fClock->SetMinuteDragging(true);451 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);452 Invalidate();453 return;454 }455 fDraggingHourHand = fClock->InHourHand(point);456 if (fDraggingHourHand) {457 fClock->SetHourDragging(true);458 SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);459 Invalidate();460 return;461 }462 }463 464 465 void466 TAnalogClock::MouseUp(BPoint point)467 {468 if(!fInteractive) {469 BView::MouseUp(point);470 return;471 }472 473 if (fDraggingHourHand || fDraggingMinuteHand) {474 int32 hour, minute, second;475 fClock->GetTime(&hour, &minute, &second);476 BMessage message(H_USER_CHANGE);477 message.AddBool("time", true);478 message.AddInt32("hour", hour);479 message.AddInt32("minute", minute);480 Window()->PostMessage(&message);481 fTimeChangeIsOngoing = true;482 }483 fDraggingHourHand = false;484 fDraggingMinuteHand = false;485 fClock->SetMinuteDragging(false);486 fClock->SetHourDragging(false);487 }488 489 490 void491 TAnalogClock::MouseMoved(BPoint point, uint32 transit, const BMessage* message)492 {493 if(!fInteractive) {494 BView::MouseMoved(point, transit, message);495 return;496 }497 498 if (fDraggingMinuteHand)499 fClock->SetMinuteHand(point);500 if (fDraggingHourHand)501 fClock->SetHourHand(point);502 503 Invalidate();504 }505 506 507 void508 TAnalogClock::Draw(BRect /*updateRect*/)509 {510 if (fBitmap) {511 if (fClock->IsDirty())512 fClock->DrawClock();513 DrawBitmap(fBitmap, BPoint(0, 0));514 }515 }516 517 518 void519 TAnalogClock::SetTime(int32 hour, int32 minute, int32 second)520 {521 // don't set the time if the hands are in a drag action522 if (fDraggingHourHand || fDraggingMinuteHand || fTimeChangeIsOngoing)523 return;524 525 if (fClock)526 fClock->SetTime(hour, minute, second);527 528 BWindow* window = Window();529 if (window && window->Lock()) {530 Invalidate();531 Window()->Unlock();532 }533 }534 535 536 void537 TAnalogClock::ChangeTimeFinished()538 {539 fTimeChangeIsOngoing = false;540 } -
src/preferences/time/SectionEdit.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Mike Berg <mike@berg-net.us> 7 7 * Julun <host.haiku@gmx.de> 8 * 8 * Hamish Morrison <hamish@lavabit.com> 9 9 */ 10 10 #ifndef _SECTION_EDIT_H 11 11 #define _SECTION_EDIT_H … … 18 18 class BList; 19 19 20 20 21 class TSection {21 class TSectionEdit : public BControl { 22 22 public: 23 TSection(BRect frame); 24 25 BRect Bounds() const; 26 void SetFrame(BRect frame); 27 BRect Frame() const; 28 29 private: 30 BRect fFrame; 31 }; 32 33 34 class TSectionEdit: public BControl { 35 public: 36 TSectionEdit(BRect frame, const char* name, 23 TSectionEdit(const char* name, 37 24 uint32 sections); 38 25 virtual ~TSectionEdit(); 39 26 … … 43 30 virtual void MakeFocus(bool focused = true); 44 31 virtual void KeyDown(const char* bytes, int32 numBytes); 45 32 33 BSize MaxSize(); 34 BSize MinSize(); 35 BSize PreferredSize(); 36 46 37 uint32 CountSections() const; 47 38 int32 FocusIndex() const; 48 39 BRect SectionArea() const; 49 40 50 41 protected: 51 virtual void InitView();52 53 // hooks54 42 virtual void DrawBorder(const BRect& updateRect); 55 virtual void DrawSection(uint32 index, bool isFocus) {} 56 virtual void DrawSeparator(uint32 index) {} 43 virtual void DrawSection(uint32 index, BRect bounds, 44 bool isFocus) {} 45 virtual void DrawSeparator(uint32 index, BRect bounds) {} 57 46 47 BRect FrameForSection(uint32 index); 48 BRect FrameForSeparator(uint32 index); 49 58 50 virtual void SectionFocus(uint32 index) {} 59 51 virtual void SectionChange(uint32 index, uint32 value) {} 60 52 virtual void SetSections(BRect area) {} 61 virtual float SeparatorWidth() const; 62 53 54 virtual float SeparatorWidth() = 0; 55 virtual float MinSectionWidth() = 0; 56 virtual float PreferredHeight() = 0; 57 63 58 virtual void DoUpPress() {} 64 59 virtual void DoDownPress() {} 65 60 66 61 virtual void DispatchMessage(); 67 62 virtual void BuildDispatch(BMessage* message) = 0; 68 69 protected: 70 BList* fSectionList; 71 63 72 64 BRect fUpRect; 73 65 BRect fDownRect; 74 BRect fSectionArea;75 66 76 67 int32 fFocus; 77 68 uint32 fSectionCount; -
src/preferences/time/TZDisplay.cpp
1 1 /* 2 * Copyright 2004-20 07, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: 6 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 * 9 * Hamish Morrison <hamish@lavabit.com> 10 10 */ 11 11 12 #include "TZDisplay.h" 13 12 14 #include <stdio.h> 13 15 14 #include "TZDisplay.h"16 #include <LayoutUtils.h> 15 17 16 18 17 namespace {18 float _FontHeight()19 {20 font_height fontHeight;21 be_plain_font->GetHeight(&fontHeight);22 float height = ceil(fontHeight.descent + fontHeight.ascent23 + fontHeight.leading);24 return height;25 }26 }27 19 28 29 TTZDisplay::TTZDisplay(BRect frame, const char* name, const char* label) 30 : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW),31 32 33 20 TTZDisplay::TTZDisplay(const char* name, const char* label) 21 : 22 BView(name, B_WILL_DRAW), 23 fLabel(label), 24 fText(""), 25 fTime("") 34 26 { 35 27 } 36 28 … … 51 43 void 52 44 TTZDisplay::ResizeToPreferred() 53 45 { 54 ResizeTo(Bounds().Width(), _FontHeight() * 2.0 + 4.0); 46 BSize size = _CalcPrefSize(); 47 ResizeTo(size.width, size.height); 55 48 } 56 49 57 50 58 51 void 59 TTZDisplay::Draw(BRect /* updateRect */)52 TTZDisplay::Draw(BRect) 60 53 { 61 54 SetLowColor(ViewColor()); 62 55 63 56 BRect bounds = Bounds(); 64 57 FillRect(Bounds(), B_SOLID_LOW); 58 59 font_height height; 60 GetFontHeight(&height); 61 float fontHeight = ceilf(height.descent + height.ascent + 62 height.leading); 65 63 66 float fontHeight = _FontHeight(); 67 68 BPoint pt(bounds.left + 2.0, fontHeight / 2.0 + 2.0); 64 BPoint pt(bounds.left, ceilf(bounds.top + height.ascent)); 69 65 DrawString(fLabel.String(), pt); 70 66 71 67 pt.y += fontHeight; 72 68 DrawString(fText.String(), pt); 73 69 74 70 pt.y -= fontHeight; 75 pt.x = bounds.right - StringWidth(fTime.String()) - 2.0;71 pt.x = bounds.right - StringWidth(fTime.String()); 76 72 DrawString(fTime.String(), pt); 77 73 } 78 74 … … 89 85 { 90 86 fLabel.SetTo(label); 91 87 Invalidate(); 88 InvalidateLayout(); 92 89 } 93 90 94 91 … … 104 101 { 105 102 fText.SetTo(text); 106 103 Invalidate(); 104 InvalidateLayout(); 107 105 } 108 106 109 107 … … 119 117 { 120 118 fTime.SetTo(time); 121 119 Invalidate(); 120 InvalidateLayout(); 122 121 } 123 122 123 124 BSize 125 TTZDisplay::MaxSize() 126 { 127 BSize size = _CalcPrefSize(); 128 size.width = B_SIZE_UNLIMITED; 129 130 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 131 size); 132 } 133 134 135 BSize 136 TTZDisplay::MinSize() 137 { 138 return BLayoutUtils::ComposeSize(ExplicitMinSize(), 139 _CalcPrefSize()); 140 } 141 142 143 BSize 144 TTZDisplay::PreferredSize() 145 { 146 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), 147 _CalcPrefSize()); 148 } 149 150 151 BSize 152 TTZDisplay::_CalcPrefSize() 153 { 154 font_height fontHeight; 155 GetFontHeight(&fontHeight); 156 157 BSize size; 158 size.height = 2 * ceilf(fontHeight.ascent + fontHeight.descent + 159 fontHeight.leading); 160 161 float firstLine = ceilf(StringWidth(fLabel.String()) + 162 StringWidth(" ") + StringWidth(fTime.String())); 163 float secondLine = ceilf(StringWidth(fText.String())); 164 size.width = firstLine > secondLine ? firstLine : secondLine; 165 return size; 166 } -
src/preferences/time/TimeSettings.h
29 29 30 30 31 31 #endif // _TIME_SETTINGS_H 32 -
src/preferences/time/TimeWindow.h
5 5 * Authors: 6 6 * Andrew McCall <mccall@@digitalparadise.co.uk> 7 7 * Julun <host.haiku@gmx.de> 8 *9 8 */ 10 9 #ifndef _TIME_WINDOW_H 11 10 #define _TIME_WINDOW_H … … 18 17 class DateTimeView; 19 18 class TTimeBaseView; 20 19 class TimeZoneView; 20 class NetworkTimeView; 21 21 22 22 23 23 class TTimeWindow : public BWindow { 24 24 public: 25 TTimeWindow( BRect rect);25 TTimeWindow(); 26 26 virtual ~TTimeWindow(); 27 27 28 28 virtual bool QuitRequested(); 29 29 virtual void MessageReceived(BMessage* message); 30 void SetRevertStatus();31 30 32 31 private: 33 32 void _InitWindow(); 34 33 void _AlignWindow(); 35 36 34 void _SendTimeChangeFinished(); 35 void _SetRevertStatus(); 37 36 38 private:39 37 TTimeBaseView* fBaseView; 40 38 DateTimeView* fDateTimeView; 41 39 TimeZoneView* fTimeZoneView; 40 NetworkTimeView* fNetworkTimeView; 42 41 BButton* fRevertButton; 43 42 }; 44 43 45 44 46 45 #endif // _TIME_WINDOW_H 47 -
src/preferences/time/TimeMessages.h
43 43 // clicked on revert button 44 44 const uint32 kMsgRevert = 'rvrt'; 45 45 46 // something was changed 47 const uint32 kMsgChange = 'chng'; 48 46 49 // change time finished 47 50 const uint32 kChangeTimeFinished = 'tcfi'; 48 51 49 52 50 53 #endif // _TIME_MESSAGES_H 51 -
src/preferences/time/DateTimeView.h
1 1 /* 2 * Copyright 2004-201 0, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved. 3 3 * Distributed under the terms of the MIT License. 4 4 * 5 5 * Authors: … … 7 7 * Mike Berg <mike@berg-net.us> 8 8 * Julun <host.haiku@gmx.de> 9 9 * Philippe Saint-Pierre <stpere@gmail.com> 10 * Hamish Morrison <hamish@lavabit.com> 10 11 */ 11 12 #ifndef _DATE_TIME_VIEW_H 12 13 #define _DATE_TIME_VIEW_H 13 14 14 15 15 #include < View.h>16 #include <LayoutBuilder.h> 16 17 17 18 18 19 class TDateEdit; … … 27 28 using BPrivate::BCalendarView; 28 29 29 30 30 class DateTimeView : public B View {31 class DateTimeView : public BGroupView { 31 32 public: 32 DateTimeView( BRect frame);33 DateTimeView(const char* name); 33 34 virtual ~DateTimeView(); 34 35 35 36 virtual void AttachedToWindow(); … … 48 49 void _Revert(); 49 50 time_t _PrefletUptime() const; 50 51 51 private:52 52 BRadioButton* fLocalTime; 53 53 BRadioButton* fGmtTime; 54 54 TDateEdit* fDateEdit; -
src/kits/shared/CalendarView.cpp
11 11 12 12 #include <stdlib.h> 13 13 14 #include <LayoutUtils.h> 14 15 #include <Window.h> 15 16 16 17 … … 72 73 } 73 74 74 75 76 BCalendarView::BCalendarView(const char* name, uint32 flags) 77 : 78 BView(name, flags), 79 BInvoker(), 80 fSelectionMessage(NULL), 81 fDay(0), 82 fYear(0), 83 fMonth(0), 84 fFocusChanged(false), 85 fSelectionChanged(false), 86 fWeekStart(B_WEEK_START_SUNDAY), 87 fDayNameHeaderVisible(true), 88 fWeekNumberHeaderVisible(true) 89 { 90 _InitObject(); 91 } 92 93 75 94 BCalendarView::~BCalendarView() 76 95 { 77 96 SetSelectionMessage(NULL); … … 559 578 } 560 579 561 580 581 BSize 582 BCalendarView::MaxSize() 583 { 584 return BLayoutUtils::ComposeSize(ExplicitMaxSize(), 585 BSize(B_SIZE_UNLIMITED, B_SIZE_UNLIMITED)); 586 } 587 588 589 BSize 590 BCalendarView::MinSize() 591 { 592 float width, height; 593 _GetPreferredSize(&width, &height); 594 return BLayoutUtils::ComposeSize(ExplicitMinSize(), 595 BSize(width, height)); 596 } 597 598 599 BSize 600 BCalendarView::PreferredSize() 601 { 602 return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), 603 MinSize()); 604 } 605 606 562 607 int32 563 608 BCalendarView::Day() const 564 609 { -
headers/private/shared/CalendarView.h
36 36 BCalendarView(BRect frame, const char *name, week_start start, 37 37 uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, 38 38 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 39 40 BCalendarView(const char* name, 41 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); 39 42 40 43 virtual ~BCalendarView(); 41 44 … … 88 91 89 92 virtual void ResizeToPreferred(); 90 93 virtual void GetPreferredSize(float *width, float *height); 94 95 virtual BSize MaxSize(); 96 virtual BSize MinSize(); 97 virtual BSize PreferredSize(); 91 98 92 99 int32 Day() const; 93 100 int32 Year() const;