Ticket #2210: RevertTimezone.diff
File RevertTimezone.diff, 12.8 KB (added by , 16 years ago) |
---|
-
src/preferences/time/Time.cpp
46 46 { 47 47 BAlert *alert = new BAlert("about", 48 48 "Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t" 49 "Julun\n\ nCopyright 2004-2007, Haiku.", "OK");49 "Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku.", "OK"); 50 50 alert->Go(); 51 51 } 52 52 -
src/preferences/time/ZoneView.cpp
1 1 /* 2 * Copyright 2004-200 7, Haiku, Inc. All Rights Reserved.2 * Copyright 2004-2008, 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 * Philippe Saint-Pierre <stpere@gmail.com> 8 9 */ 9 10 10 11 /* … … 21 22 #include "ZoneView.h" 22 23 #include "TimeMessages.h" 23 24 #include "TZDisplay.h" 25 #include "TimeWindow.h" 24 26 25 27 26 28 #include <Button.h> … … 37 39 #include <StorageDefs.h> 38 40 #include <String.h> 39 41 #include <View.h> 42 #include <Window.h> 40 43 41 44 42 45 #include <stdio.h> … … 67 70 } 68 71 69 72 73 bool 74 TimeZoneView::CheckCanRevert() 75 { 76 return fCurrentZone != fOldZone; 77 } 78 79 80 void 81 TimeZoneView::_Revert() 82 { 83 BPath parent; 84 85 fCurrentZone = fOldZone; 86 int32 czone; 87 88 if (strcmp(fCurrentZone.Leaf(), "Greenwich") == 0) { 89 fRegionPopUp->FindItem("Others")->SetMarked(true); 90 czone = FillCityList("Others"); 91 } else { 92 fCurrentZone.GetParent(&parent); 93 fRegionPopUp->FindItem(parent.Leaf())->SetMarked(true); 94 czone = FillCityList(parent.Path()); 95 } 96 97 if (czone > -1) { 98 fCityList->Select(czone); 99 fCityList->ScrollToSelection(); 100 fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); 101 SetPreview(); 102 } 103 SetTimeZone(); 104 } 105 106 70 107 TimeZoneView::~TimeZoneView() 71 108 { 72 109 } … … 87 124 88 125 // update displays 89 126 BPath parent; 90 fCurrentZone.GetParent(&parent); 91 int32 czone = FillCityList(parent.Path()); 92 if (czone > -1) { 93 fCityList->Select(czone); 94 fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); 127 if (strcmp(fCurrentZone.Leaf(), "Greenwich") != 0) { 128 fCurrentZone.GetParent(&parent); 129 int32 czone = FillCityList(parent.Path()); 130 if (czone > -1) { 131 fCityList->Select(czone); 132 fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); 133 } 134 } else { 135 int32 czone = FillCityList("Others"); 136 if (czone > -1) { 137 fCityList->Select(czone); 138 fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); 139 } 95 140 } 96 141 } 97 142 fCityList->ScrollToSelection(); … … 120 165 break; 121 166 122 167 case H_SET_TIME_ZONE: 168 { 123 169 SetTimeZone(); 170 BMessage msg(*message); 171 msg.what = kRTCUpdate; 172 Window()->PostMessage(&msg); 173 ((TTimeWindow*)Window())->SetRevertStatus(); 124 174 break; 125 175 } 176 177 case kMsgRevert: 178 _Revert(); 179 break; 180 126 181 case H_CITY_CHANGED: 127 182 SetPreview(); 128 183 break; … … 242 297 243 298 // skip Etc directory 244 299 if (itemtext.Compare("Etc", 3) == 0) 245 300 continue; 246 301 247 302 markit = itemtext.Compare(region.Leaf()) == 0; 248 303 … … 263 318 fRegionPopUp->AddItem(item); 264 319 } 265 320 } 321 BMessage *msg = new BMessage(H_REGION_CHANGED); 322 msg->AddString("region", "Others"); 323 324 item = new BMenuItem("Others", msg); 325 item->SetMarked(strcmp(fCurrentZone.Leaf(), "Greenwich") == 0); 326 fRegionPopUp->AddItem(item); 266 327 } 267 328 268 329 … … 277 338 fCityList->MakeEmpty(); 278 339 } 279 340 280 // Enter time zones directory. Find subdir with name that matches string 281 // stored in area. Enter subdirectory and count the items. For each item,282 // add a StringItem to fCityList Time zones directory341 BStringItem *city; 342 int32 index = -1; 343 if (strcmp(area, "Others") != 0) { 283 344 284 BPath path;285 if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK)286 return 0;345 // Enter time zones directory. Find subdir with name that matches string 346 // stored in area. Enter subdirectory and count the items. For each item, 347 // add a StringItem to fCityList Time zones directory 287 348 288 path.Append("timezones"); 349 BPath path; 350 if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK) 351 return 0; 289 352 290 BPath Area(area); 291 BDirectory zoneDir(path.Path()); 292 BDirectory cityDir; 293 BStringItem *city; 294 BString city_name; 295 BEntry entry; 296 int32 index = -1; 353 path.Append("timezones"); 354 355 BPath Area(area); 356 BDirectory zoneDir(path.Path()); 357 BDirectory cityDir; 358 BString city_name; 359 BEntry entry; 360 297 361 298 //locate subdirectory:299 if (zoneDir.Contains(Area.Leaf(), B_DIRECTORY_NODE)) {300 cityDir.SetTo(&zoneDir, Area.Leaf());362 //locate subdirectory: 363 if (zoneDir.Contains(Area.Leaf(), B_DIRECTORY_NODE)) { 364 cityDir.SetTo(&zoneDir, Area.Leaf()); 301 365 302 // There is a subdir with a name that matches 'area'. That's the one!! 303 // Iterate over the items in the subdir, fill listview with TZoneItems 304 while(cityDir.GetNextEntry(&entry) == B_NO_ERROR) { 305 if (!entry.IsDirectory()) { 306 BPath zone(&entry); 307 city_name = zone.Leaf(); 308 city_name.ReplaceAll("_IN", ", Indiana"); 309 city_name.ReplaceAll("__Calif", ", Calif"); 310 city_name.ReplaceAll("__", ", "); 311 city_name.ReplaceAll("_", " "); 312 city = new TZoneItem(city_name.String(), zone.Path()); 313 fCityList->AddItem(city); 314 if (strcmp(fCurrentZone.Leaf(), zone.Leaf()) == 0) 315 index = fCityList->IndexOf(city); 366 // There is a subdir with a name that matches 'area'. That's the one!! 367 // Iterate over the items in the subdir, fill listview with TZoneItems 368 while(cityDir.GetNextEntry(&entry) == B_NO_ERROR) { 369 if (!entry.IsDirectory()) { 370 BPath zone(&entry); 371 city_name = zone.Leaf(); 372 city_name.ReplaceAll("_IN", ", Indiana"); 373 city_name.ReplaceAll("__Calif", ", Calif"); 374 city_name.ReplaceAll("__", ", "); 375 city_name.ReplaceAll("_", " "); 376 city = new TZoneItem(city_name.String(), zone.Path()); 377 fCityList->AddItem(city); 378 if (strcmp(fCurrentZone.Leaf(), zone.Leaf()) == 0) 379 index = fCityList->IndexOf(city); 380 } 316 381 } 317 382 } 383 } else { 384 city = new TZoneItem("Greenwich", "/boot/beos/etc/timezones/Greenwich"); 385 fCityList->AddItem(city); 386 if (strcmp(fCurrentZone.Leaf(), "Greenwich") == 0) { 387 index = fCityList->IndexOf(city); 388 } 318 389 } 319 390 return index; 320 391 } … … 363 434 tzLink.SetTo("/boot/beos/etc/timezones/Pacific/fiji"); 364 435 // do something like set to a default GMT??? 365 436 } 437 else if (!tzLink.Exists()) { // link doesn't exists 438 tzLink.SetTo("/boot/beos/etc/timezones/Greenwich"); 439 } 366 440 } else { 367 // set tzlink to a default441 // directory doesn't exist 368 442 tzLink.SetTo("/boot/beos/etc/timezones/EST"); 369 443 } 370 444 #endif 371 445 // we need something in the current zone 372 446 fCurrentZone.SetTo(&tzLink); 447 fOldZone.SetTo(&tzLink); 373 448 } 374 449 375 450 … … 449 524 450 525 // update environment 451 526 SetTimeZone(target.Path()); 452 527 453 528 // update display 454 529 time_t current = time(0); 455 530 struct tm *ltime = localtime(¤t); -
src/preferences/time/ZoneView.h
28 28 29 29 virtual void AttachedToWindow(); 30 30 virtual void MessageReceived(BMessage *message); 31 bool CheckCanRevert(); 31 32 32 33 private: 33 34 void UpdateDateTime(BMessage *message); … … 39 40 void InitView(); 40 41 void ReadTimeZoneLink(); 41 42 void BuildRegionMenu(); 43 void _Revert(); 42 44 43 45 // returns index of current zone 44 46 int32 FillCityList(const char *area); … … 53 55 int32 fHour; 54 56 int32 fMinute; 55 57 BPath fCurrentZone; 58 BPath fOldZone; 56 59 bool fInitialized; 57 60 }; 58 61 -
src/preferences/time/TimeWindow.cpp
20 20 #include <Message.h> 21 21 #include <Screen.h> 22 22 #include <TabView.h> 23 #include <Button.h> 23 24 24 25 25 26 TTimeWindow::TTimeWindow(BRect rect) … … 37 38 } 38 39 39 40 41 void 42 TTimeWindow::SetRevertStatus() 43 { 44 fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert() 45 || fTimeZoneView->CheckCanRevert()); 46 } 47 48 40 49 void 41 50 TTimeWindow::MessageReceived(BMessage *message) 42 51 { 43 52 switch(message->what) { 44 53 case H_USER_CHANGE: 45 54 fBaseView->ChangeTime(message); 46 fDateTimeView->CheckCanRevert();55 SetRevertStatus(); 47 56 break; 48 57 49 58 case B_ABOUT_REQUESTED: 50 59 be_app->PostMessage(B_ABOUT_REQUESTED); 51 60 break; 52 61 62 case kMsgRevert: 63 fDateTimeView->MessageReceived(message); 64 fTimeZoneView->MessageReceived(message); 65 fRevertButton->SetEnabled(false); 66 break; 67 68 case kRTCUpdate: 69 fDateTimeView->MessageReceived(message); 70 SetRevertStatus(); 71 break; 72 53 73 default: 54 74 BWindow::MessageReceived(message); 55 75 break; … … 101 121 102 122 fBaseView->AddChild(tabView); 103 123 tabView->ResizeBy(0.0, tabView->TabHeight()); 124 125 BRect rect = Bounds(); 126 127 rect.left = 10; 128 rect.top = rect.bottom - 10; 129 130 fRevertButton = new BButton(rect, "revert", "Revert", 131 new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW); 132 133 fRevertButton->ResizeToPreferred(); 134 fRevertButton->SetEnabled(false); 135 float buttonHeight = fRevertButton->Bounds().Height(); 136 fRevertButton->MoveBy(0, -buttonHeight); 137 fBaseView->AddChild(fRevertButton); 138 fRevertButton->SetTarget(this); 139 104 140 fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0, 105 tabView->Bounds().Height() + 10.0);141 tabView->Bounds().Height() + buttonHeight + 30.0); 106 142 107 143 ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height()); 108 144 } -
src/preferences/time/DateTimeView.cpp
15 15 #include "DateTimeEdit.h" 16 16 #include "TimeMessages.h" 17 17 #include "DateTime.h" 18 #include "TimeWindow.h" 18 19 19 20 20 #include <Button.h>21 21 #include <CheckBox.h> 22 22 #include <Entry.h> 23 23 #include <File.h> … … 69 69 if (!fInitialized) { 70 70 fInitialized = true; 71 71 72 fGmtTime->SetTarget(this);73 fLocalTime->SetTarget(this);74 72 fCalendarView->SetTarget(this); 75 fRevertButton->SetTarget(this);76 73 } 77 74 } 78 75 … … 131 128 case kRTCUpdate: 132 129 fUseGmtTime = fGmtTime->Value() == B_CONTROL_ON; 133 130 _UpdateGmtSettings(); 134 CheckCanRevert();135 131 break; 136 132 137 133 case kMsgRevert: 138 134 _Revert(); 139 fRevertButton->SetEnabled(false);140 135 break; 141 136 142 137 default: … … 146 141 } 147 142 148 143 149 void 144 bool 150 145 DateTimeView::CheckCanRevert() 151 146 { 152 147 // check GMT vs Local setting … … 157 152 time_t changedNow; 158 153 time(&changedNow); 159 154 160 enable = enable || (changedNow != unchangedNow); 161 162 fRevertButton->SetEnabled(enable); 155 return enable || (changedNow != unchangedNow); 163 156 } 164 157 165 158 … … 266 259 267 260 fOldUseGmtTime = fUseGmtTime; 268 261 269 BRect rect = Bounds();270 271 rect.left = 10;272 rect.top = rect.bottom - 10;273 274 fRevertButton = new BButton(rect, "revert", "Revert",275 new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW);276 277 fRevertButton->ResizeToPreferred();278 fRevertButton->SetEnabled(false);279 float buttonHeight = fRevertButton->Bounds().Height();280 fRevertButton->MoveBy(0, -buttonHeight);281 AddChild(fRevertButton);282 283 262 ResizeTo(fClock->Frame().right + 10.0, fGmtTime->Frame().bottom + 10.0); 284 263 } 285 264 -
src/preferences/time/TimeWindow.h
27 27 28 28 virtual bool QuitRequested(); 29 29 virtual void MessageReceived(BMessage *message); 30 void SetRevertStatus(); 30 31 31 32 private: 32 33 void _InitWindow(); … … 36 37 TTimeBaseView *fBaseView; 37 38 DateTimeView *fDateTimeView; 38 39 TimeZoneView *fTimeZoneView; 40 BButton *fRevertButton; 39 41 }; 40 42 41 43 #endif // TIME_WINDOW_H -
src/preferences/time/DateTimeView.h
20 20 class BCalendarView; 21 21 class BRadioButton; 22 22 class TAnalogClock; 23 class BButton;24 23 25 24 26 25 class DateTimeView : public BView { … … 32 31 virtual void Draw(BRect updaterect); 33 32 virtual void MessageReceived(BMessage *message); 34 33 35 void CheckCanRevert(); 34 bool CheckCanRevert(); 35 bool GetUseGmtTime(); 36 36 37 37 private: 38 38 void _InitView(); … … 51 51 BCalendarView *fCalendarView; 52 52 TAnalogClock *fClock; 53 53 54 BButton *fRevertButton; 55 56 bool fUseGmtTime; 54 bool fUseGmtTime; 57 55 bool fOldUseGmtTime; 58 56 bool fInitialized; 59 57