Applied patch by Philippe Saint-Pierre:

* Extended the scope of the Revert feature to include changes to the time zone.
* Moved the Revert button out of the tab view, so that it indicates the above
  visually. The window now handles the Revert feature.
* Added Others/Greenwhich time zone which is equivalent to an "unset" time zone.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25415 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus 2008-05-10 12:24:27 +00:00
parent 1da9f5cea5
commit 310930fd9e
7 changed files with 170 additions and 75 deletions

View File

@ -15,9 +15,9 @@
#include "DateTimeEdit.h"
#include "TimeMessages.h"
#include "DateTime.h"
#include "TimeWindow.h"
#include <Button.h>
#include <CheckBox.h>
#include <Entry.h>
#include <File.h>
@ -69,10 +69,7 @@ DateTimeView::AttachedToWindow()
if (!fInitialized) {
fInitialized = true;
fGmtTime->SetTarget(this);
fLocalTime->SetTarget(this);
fCalendarView->SetTarget(this);
fRevertButton->SetTarget(this);
}
}
@ -131,12 +128,10 @@ DateTimeView::MessageReceived(BMessage *message)
case kRTCUpdate:
fUseGmtTime = fGmtTime->Value() == B_CONTROL_ON;
_UpdateGmtSettings();
CheckCanRevert();
break;
case kMsgRevert:
_Revert();
fRevertButton->SetEnabled(false);
break;
default:
@ -146,7 +141,7 @@ DateTimeView::MessageReceived(BMessage *message)
}
void
bool
DateTimeView::CheckCanRevert()
{
// check GMT vs Local setting
@ -157,9 +152,7 @@ DateTimeView::CheckCanRevert()
time_t changedNow;
time(&changedNow);
enable = enable || (changedNow != unchangedNow);
fRevertButton->SetEnabled(enable);
return enable || (changedNow != unchangedNow);
}
@ -266,20 +259,6 @@ DateTimeView::_InitView()
fOldUseGmtTime = fUseGmtTime;
BRect rect = Bounds();
rect.left = 10;
rect.top = rect.bottom - 10;
fRevertButton = new BButton(rect, "revert", "Revert",
new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
fRevertButton->ResizeToPreferred();
fRevertButton->SetEnabled(false);
float buttonHeight = fRevertButton->Bounds().Height();
fRevertButton->MoveBy(0, -buttonHeight);
AddChild(fRevertButton);
ResizeTo(fClock->Frame().right + 10.0, fGmtTime->Frame().bottom + 10.0);
}

View File

@ -20,7 +20,6 @@ class TTimeEdit;
class BCalendarView;
class BRadioButton;
class TAnalogClock;
class BButton;
class DateTimeView : public BView {
@ -32,7 +31,8 @@ class DateTimeView : public BView {
virtual void Draw(BRect updaterect);
virtual void MessageReceived(BMessage *message);
void CheckCanRevert();
bool CheckCanRevert();
bool GetUseGmtTime();
private:
void _InitView();
@ -51,9 +51,7 @@ class DateTimeView : public BView {
BCalendarView *fCalendarView;
TAnalogClock *fClock;
BButton *fRevertButton;
bool fUseGmtTime;
bool fUseGmtTime;
bool fOldUseGmtTime;
bool fInitialized;

View File

@ -46,7 +46,7 @@ TimeApplication::AboutRequested()
{
BAlert *alert = new BAlert("about",
"Time & Date, writen by:\n\n\tAndrew Edward McCall\n\tMike Berg\n\t"
"Julun\n\nCopyright 2004-2007, Haiku.", "OK");
"Julun\n\tPhilippe Saint-Pierre\n\nCopyright 2004-2008, Haiku.", "OK");
alert->Go();
}

View File

@ -20,6 +20,7 @@
#include <Message.h>
#include <Screen.h>
#include <TabView.h>
#include <Button.h>
TTimeWindow::TTimeWindow(BRect rect)
@ -37,19 +38,38 @@ TTimeWindow::~TTimeWindow()
}
void
TTimeWindow::SetRevertStatus()
{
fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert()
|| fTimeZoneView->CheckCanRevert());
}
void
TTimeWindow::MessageReceived(BMessage *message)
{
switch(message->what) {
case H_USER_CHANGE:
fBaseView->ChangeTime(message);
fDateTimeView->CheckCanRevert();
SetRevertStatus();
break;
case B_ABOUT_REQUESTED:
be_app->PostMessage(B_ABOUT_REQUESTED);
break;
case kMsgRevert:
fDateTimeView->MessageReceived(message);
fTimeZoneView->MessageReceived(message);
fRevertButton->SetEnabled(false);
break;
case kRTCUpdate:
fDateTimeView->MessageReceived(message);
SetRevertStatus();
break;
default:
BWindow::MessageReceived(message);
break;
@ -101,8 +121,24 @@ TTimeWindow::_InitWindow()
fBaseView->AddChild(tabView);
tabView->ResizeBy(0.0, tabView->TabHeight());
BRect rect = Bounds();
rect.left = 10;
rect.top = rect.bottom - 10;
fRevertButton = new BButton(rect, "revert", "Revert",
new BMessage(kMsgRevert), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
fRevertButton->ResizeToPreferred();
fRevertButton->SetEnabled(false);
float buttonHeight = fRevertButton->Bounds().Height();
fRevertButton->MoveBy(0, -buttonHeight);
fBaseView->AddChild(fRevertButton);
fRevertButton->SetTarget(this);
fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0,
tabView->Bounds().Height() + 10.0);
tabView->Bounds().Height() + buttonHeight + 30.0);
ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height());
}

View File

@ -27,6 +27,7 @@ class TTimeWindow : public BWindow {
virtual bool QuitRequested();
virtual void MessageReceived(BMessage *message);
void SetRevertStatus();
private:
void _InitWindow();
@ -36,6 +37,7 @@ class TTimeWindow : public BWindow {
TTimeBaseView *fBaseView;
DateTimeView *fDateTimeView;
TimeZoneView *fTimeZoneView;
BButton *fRevertButton;
};
#endif // TIME_WINDOW_H

View File

@ -1,10 +1,11 @@
/*
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
* Copyright 2004-2008, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Mike Berg <mike@berg-net.us>
* Julun <host.haiku@gmx.de>
* Philippe Saint-Pierre <stpere@gmail.com>
*/
/*
@ -21,6 +22,7 @@
#include "ZoneView.h"
#include "TimeMessages.h"
#include "TZDisplay.h"
#include "TimeWindow.h"
#include <Button.h>
@ -37,6 +39,7 @@
#include <StorageDefs.h>
#include <String.h>
#include <View.h>
#include <Window.h>
#include <stdio.h>
@ -67,6 +70,42 @@ TimeZoneView::TimeZoneView(BRect frame)
}
bool
TimeZoneView::CheckCanRevert()
{
return fCurrentZone != fOldZone;
}
void
TimeZoneView::_Revert()
{
BPath parent;
fCurrentZone = fOldZone;
int32 czone;
if (strcmp(fCurrentZone.Leaf(), "Greenwich") == 0) {
if (BMenuItem* item = fRegionPopUp->FindItem("Others"))
item->SetMarked(true);
czone = FillCityList("Others");
} else {
fCurrentZone.GetParent(&parent);
if (BMenuItem* item = fRegionPopUp->FindItem(parent.Leaf()))
item->SetMarked(true);
czone = FillCityList(parent.Path());
}
if (czone > -1) {
fCityList->Select(czone);
fCityList->ScrollToSelection();
fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text());
SetPreview();
}
SetTimeZone();
}
TimeZoneView::~TimeZoneView()
{
}
@ -87,11 +126,19 @@ TimeZoneView::AttachedToWindow()
// update displays
BPath parent;
fCurrentZone.GetParent(&parent);
int32 czone = FillCityList(parent.Path());
if (czone > -1) {
fCityList->Select(czone);
fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text());
if (strcmp(fCurrentZone.Leaf(), "Greenwich") != 0) {
fCurrentZone.GetParent(&parent);
int32 czone = FillCityList(parent.Path());
if (czone > -1) {
fCityList->Select(czone);
fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text());
}
} else {
int32 czone = FillCityList("Others");
if (czone > -1) {
fCityList->Select(czone);
fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text());
}
}
}
fCityList->ScrollToSelection();
@ -120,9 +167,19 @@ TimeZoneView::MessageReceived(BMessage *message)
break;
case H_SET_TIME_ZONE:
{
SetTimeZone();
BMessage msg(*message);
msg.what = kRTCUpdate;
Window()->PostMessage(&msg);
((TTimeWindow*)Window())->SetRevertStatus();
break;
}
case kMsgRevert:
_Revert();
break;
case H_CITY_CHANGED:
SetPreview();
break;
@ -242,7 +299,7 @@ TimeZoneView::BuildRegionMenu()
// skip Etc directory
if (itemtext.Compare("Etc", 3) == 0)
continue;
continue;
markit = itemtext.Compare(region.Leaf()) == 0;
@ -263,6 +320,12 @@ TimeZoneView::BuildRegionMenu()
fRegionPopUp->AddItem(item);
}
}
BMessage *msg = new BMessage(H_REGION_CHANGED);
msg->AddString("region", "Others");
item = new BMenuItem("Others", msg);
item->SetMarked(strcmp(fCurrentZone.Leaf(), "Greenwich") == 0);
fRegionPopUp->AddItem(item);
}
@ -277,44 +340,54 @@ TimeZoneView::FillCityList(const char *area)
fCityList->MakeEmpty();
}
// Enter time zones directory. Find subdir with name that matches string
// stored in area. Enter subdirectory and count the items. For each item,
// add a StringItem to fCityList Time zones directory
BPath path;
if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK)
return 0;
path.Append("timezones");
BPath Area(area);
BDirectory zoneDir(path.Path());
BDirectory cityDir;
BStringItem *city;
BString city_name;
BEntry entry;
int32 index = -1;
//locate subdirectory:
if (zoneDir.Contains(Area.Leaf(), B_DIRECTORY_NODE)) {
cityDir.SetTo(&zoneDir, Area.Leaf());
if (strcmp(area, "Others") != 0) {
// There is a subdir with a name that matches 'area'. That's the one!!
// Iterate over the items in the subdir, fill listview with TZoneItems
while(cityDir.GetNextEntry(&entry) == B_NO_ERROR) {
if (!entry.IsDirectory()) {
BPath zone(&entry);
city_name = zone.Leaf();
city_name.ReplaceAll("_IN", ", Indiana");
city_name.ReplaceAll("__Calif", ", Calif");
city_name.ReplaceAll("__", ", ");
city_name.ReplaceAll("_", " ");
city = new TZoneItem(city_name.String(), zone.Path());
fCityList->AddItem(city);
if (strcmp(fCurrentZone.Leaf(), zone.Leaf()) == 0)
index = fCityList->IndexOf(city);
// Enter time zones directory. Find subdir with name that matches string
// stored in area. Enter subdirectory and count the items. For each item,
// add a StringItem to fCityList Time zones directory
BPath path;
if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK)
return 0;
path.Append("timezones");
BPath Area(area);
BDirectory zoneDir(path.Path());
BDirectory cityDir;
BString city_name;
BEntry entry;
//locate subdirectory:
if (zoneDir.Contains(Area.Leaf(), B_DIRECTORY_NODE)) {
cityDir.SetTo(&zoneDir, Area.Leaf());
// There is a subdir with a name that matches 'area'. That's the one!!
// Iterate over the items in the subdir, fill listview with TZoneItems
while(cityDir.GetNextEntry(&entry) == B_NO_ERROR) {
if (!entry.IsDirectory()) {
BPath zone(&entry);
city_name = zone.Leaf();
city_name.ReplaceAll("_IN", ", Indiana");
city_name.ReplaceAll("__Calif", ", Calif");
city_name.ReplaceAll("__", ", ");
city_name.ReplaceAll("_", " ");
city = new TZoneItem(city_name.String(), zone.Path());
fCityList->AddItem(city);
if (strcmp(fCurrentZone.Leaf(), zone.Leaf()) == 0)
index = fCityList->IndexOf(city);
}
}
}
} else {
city = new TZoneItem("Greenwich", "/boot/beos/etc/timezones/Greenwich");
fCityList->AddItem(city);
if (strcmp(fCurrentZone.Leaf(), "Greenwich") == 0) {
index = fCityList->IndexOf(city);
}
}
return index;
}
@ -363,13 +436,17 @@ TimeZoneView::ReadTimeZoneLink()
tzLink.SetTo("/boot/beos/etc/timezones/Pacific/fiji");
// do something like set to a default GMT???
}
else if (!tzLink.Exists()) { // link doesn't exists
tzLink.SetTo("/boot/beos/etc/timezones/Greenwich");
}
} else {
// set tzlink to a default
// directory doesn't exist
tzLink.SetTo("/boot/beos/etc/timezones/EST");
}
#endif
// we need something in the current zone
fCurrentZone.SetTo(&tzLink);
fOldZone.SetTo(&tzLink);
}
@ -449,7 +526,7 @@ TimeZoneView::SetTimeZone()
// update environment
SetTimeZone(target.Path());
// update display
time_t current = time(0);
struct tm *ltime = localtime(&current);

View File

@ -28,6 +28,7 @@ class TimeZoneView : public BView {
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message);
bool CheckCanRevert();
private:
void UpdateDateTime(BMessage *message);
@ -39,6 +40,7 @@ class TimeZoneView : public BView {
void InitView();
void ReadTimeZoneLink();
void BuildRegionMenu();
void _Revert();
// returns index of current zone
int32 FillCityList(const char *area);
@ -53,6 +55,7 @@ class TimeZoneView : public BView {
int32 fHour;
int32 fMinute;
BPath fCurrentZone;
BPath fOldZone;
bool fInitialized;
};