* code cleanup, small refactoring

* make the panel font sensitve within the possible plain font range

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22633 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Karsten Heimrich
2007-10-21 12:40:57 +00:00
parent 9db35b6825
commit 85b69a9437
10 changed files with 133 additions and 188 deletions
+2 -2
View File
@@ -183,8 +183,8 @@ OffscreenClock::_DrawHands(float x, float y, float radius,
// #pragma mark - // #pragma mark -
TAnalogClock::TAnalogClock(BRect frame, const char *name, uint32 resizeMask, uint32 flags) TAnalogClock::TAnalogClock(BRect frame, const char *name)
: BView(frame, name, resizeMask, flags | B_DRAW_ON_CHILDREN), : BView(frame, name, B_FOLLOW_NONE, B_WILL_DRAW | B_DRAW_ON_CHILDREN),
fBitmap(NULL), fBitmap(NULL),
fClock(NULL) fClock(NULL)
{ {
+1 -2
View File
@@ -19,8 +19,7 @@ class OffscreenClock;
class TAnalogClock : public BView { class TAnalogClock : public BView {
public: public:
TAnalogClock(BRect frame, const char *name, TAnalogClock(BRect frame, const char *name);
uint32 resizeMask, uint32 flags);
virtual ~TAnalogClock(); virtual ~TAnalogClock();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
+1 -1
View File
@@ -16,7 +16,7 @@
TTimeBaseView::TTimeBaseView(BRect frame, const char *name) TTimeBaseView::TTimeBaseView(BRect frame, const char *name)
: BView(frame, name, B_FOLLOW_ALL_SIDES, B_PULSE_NEEDED), : BView(frame, name, B_FOLLOW_NONE, B_PULSE_NEEDED),
fMessage(H_TIME_UPDATE) fMessage(H_TIME_UPDATE)
{ {
} }
+56 -89
View File
@@ -27,9 +27,6 @@
#include <Window.h> #include <Window.h>
#include <stdlib.h>
#ifdef HAIKU_TARGET_PLATFORM_HAIKU #ifdef HAIKU_TARGET_PLATFORM_HAIKU
#include <syscalls.h> #include <syscalls.h>
#else #else
@@ -39,12 +36,13 @@ void _kset_tzfilename_(const char *name, size_t length, bool isGMT);
DateTimeView::DateTimeView(BRect frame) DateTimeView::DateTimeView(BRect frame)
: BView(frame,"Settings", B_FOLLOW_ALL, : BView(frame, "dateTimeView", B_FOLLOW_NONE, B_WILL_DRAW | B_NAVIGABLE_JUMP),
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP),
fGmtTime(NULL), fGmtTime(NULL),
fUseGmtTime(false),
fInitialized(false) fInitialized(false)
{ {
_ReadRTCSettings(); _ReadRTCSettings();
_InitView();
} }
@@ -61,8 +59,11 @@ DateTimeView::AttachedToWindow()
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
if (!fInitialized) { if (!fInitialized) {
_InitView();
fInitialized = true; fInitialized = true;
fGmtTime->SetTarget(this);
fLocalTime->SetTarget(this);
fCalendarView->SetTarget(this);
} }
} }
@@ -76,8 +77,8 @@ DateTimeView::Draw(BRect /*updateRect*/)
//draw a separator line //draw a separator line
BRect bounds(Bounds()); BRect bounds(Bounds());
BPoint start(bounds.Width() / 2.0f + 2.0f, bounds.top + 2.0f); BPoint start(bounds.Width() / 2.0f, bounds.top + 5.0f);
BPoint end(bounds.Width() / 2.0 + 2.0f, bounds.bottom - 2.0f); BPoint end(bounds.Width() / 2.0, bounds.bottom - 5.0f);
BeginLineArray(2); BeginLineArray(2);
AddLine(start, end, dark); AddLine(start, end, dark);
@@ -118,6 +119,7 @@ DateTimeView::MessageReceived(BMessage *message)
} break; } break;
case kRTCUpdate: case kRTCUpdate:
fUseGmtTime = !fUseGmtTime;
_UpdateGmtSettings(); _UpdateGmtSettings();
break; break;
@@ -128,95 +130,69 @@ DateTimeView::MessageReceived(BMessage *message)
} }
void
DateTimeView::GetPreferredSize(float *width, float *height)
{
// hardcode in TimeWindow ...
*width = 470.0f;
*height = 227.0f;
if (fInitialized) {
// we are initialized
*width = Bounds().Width();
*height = fGmtTime->Frame().bottom;
}
}
void void
DateTimeView::_InitView() DateTimeView::_InitView()
{ {
font_height fontHeight; font_height fontHeight;
be_plain_font->GetHeight(&fontHeight); be_plain_font->GetHeight(&fontHeight);
float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading; float textHeight = fontHeight.descent + fontHeight.ascent
+ fontHeight.leading + 6.0; // 6px border
// left side // left side
BRect frameLeft(Bounds()); BRect bounds = Bounds();
frameLeft.right = frameLeft.Width() / 2.0; bounds.InsetBy(10.0, 10.0);
frameLeft.InsetBy(10.0f, 10.0f); bounds.top += textHeight + 10.0;
frameLeft.bottom = frameLeft.top + textHeight + 6.0;
fDateEdit = new TDateEdit(frameLeft, "date_edit", 3); fCalendarView = new BCalendarView(bounds, "calendar");
AddChild(fDateEdit);
frameLeft.top = fDateEdit->Frame().bottom + 10;
frameLeft.bottom = Bounds().bottom - 10;
fCalendarView = new BCalendarView(frameLeft, "calendar");
fCalendarView->SetWeekNumberHeaderVisible(false); fCalendarView->SetWeekNumberHeaderVisible(false);
AddChild(fCalendarView); fCalendarView->ResizeToPreferred();
fCalendarView->SetSelectionMessage(new BMessage(kDayChanged)); fCalendarView->SetSelectionMessage(new BMessage(kDayChanged));
fCalendarView->SetInvocationMessage(new BMessage(kDayChanged)); fCalendarView->SetInvocationMessage(new BMessage(kDayChanged));
fCalendarView->SetTarget(this);
// right side bounds.top -= textHeight + 10.0;
BRect frameRight(Bounds()); bounds.bottom = bounds.top + textHeight;
frameRight.left = frameRight.Width() / 2.0; bounds.right = fCalendarView->Frame().right;
frameRight.InsetBy(10.0f, 10.0f);
frameRight.bottom = frameRight.top + textHeight + 6.0;
fTimeEdit = new TTimeEdit(frameRight, "time_edit", 4); fDateEdit = new TDateEdit(bounds, "dateEdit", 3);
AddChild(fDateEdit);
AddChild(fCalendarView);
// right side, 2px extra for separator
bounds.OffsetBy(bounds.Width() + 22.0, 0.0);
fTimeEdit = new TTimeEdit(bounds, "timeEdit", 4);
AddChild(fTimeEdit); AddChild(fTimeEdit);
frameRight.top = fTimeEdit->Frame().bottom + 10.0; bounds = fCalendarView->Frame();
frameRight.bottom = Bounds().bottom - 10.0; bounds.OffsetBy(bounds.Width() + 22.0, 0.0);
float left = fTimeEdit->Frame().left; fClock = new TAnalogClock(bounds, "analogClock");
float tmp = MIN(frameRight.Width(), frameRight.Height());
frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) / 2.0;
frameRight.bottom = frameRight.top + tmp;
frameRight.right = frameRight.left + tmp;
fClock = new TAnalogClock(frameRight, "analog clock", B_FOLLOW_NONE, B_WILL_DRAW);
AddChild(fClock); AddChild(fClock);
// clock radio buttons // clock radio buttons
frameRight.left = left; bounds.top = fClock->Frame().bottom + 10.0;
frameRight.top = fClock->Frame().bottom + 10.0; BStringView *text = new BStringView(bounds, "clockSetTo", "Clock set to:");
BStringView *text = new BStringView(frameRight, "clockis", "Clock set to:");
AddChild(text); AddChild(text);
text->ResizeToPreferred(); text->ResizeToPreferred();
frameRight.left += 10.0f; bounds.left += 10.0f;
frameRight.top = text->Frame().bottom + 5.0; bounds.top = text->Frame().bottom;
fLocalTime = new BRadioButton(bounds, "localTime", "Local Time",
fLocalTime = new BRadioButton(frameRight, "local", "Local time",
new BMessage(kRTCUpdate)); new BMessage(kRTCUpdate));
AddChild(fLocalTime); AddChild(fLocalTime);
fLocalTime->ResizeToPreferred(); fLocalTime->ResizeToPreferred();
fLocalTime->SetTarget(this);
frameRight.left = fLocalTime->Frame().right +10.0f; bounds.left = fLocalTime->Frame().right + 10.0;
fGmtTime = new BRadioButton(bounds, "greenwichMeanTime", "GMT",
fGmtTime = new BRadioButton(frameRight, "gmt", "GMT", new BMessage(kRTCUpdate)); new BMessage(kRTCUpdate));
AddChild(fGmtTime); AddChild(fGmtTime);
fGmtTime->ResizeToPreferred(); fGmtTime->ResizeToPreferred();
fGmtTime->SetTarget(this);
if (fIsLocalTime) if (fUseGmtTime)
fLocalTime->SetValue(B_CONTROL_ON);
else
fGmtTime->SetValue(B_CONTROL_ON); fGmtTime->SetValue(B_CONTROL_ON);
else
fLocalTime->SetValue(B_CONTROL_ON);
ResizeTo(fClock->Frame().right + 10.0, fGmtTime->Frame().bottom + 10.0);
} }
@@ -228,26 +204,18 @@ DateTimeView::_ReadRTCSettings()
return; return;
path.Append("RTC_time_settings"); path.Append("RTC_time_settings");
BFile file;
BEntry entry(path.Path()); BEntry entry(path.Path());
if (entry.Exists()) { if (entry.Exists()) {
file.SetTo(&entry, B_READ_ONLY); BFile file(&entry, B_READ_ONLY);
if (file.InitCheck() == B_OK) { if (file.InitCheck() == B_OK) {
char localTime[6]; char buffer[6];
file.Read(localTime, 6); file.Read(buffer, 6);
BString text(localTime); if (strncmp(buffer, "gmt", 3) == 0)
if (text.Compare("local", 4) == 0) fUseGmtTime = true;
fIsLocalTime = true;
else
fIsLocalTime = false;
} }
} else { } else
// create set to local _UpdateGmtSettings();
fIsLocalTime = true;
file.SetTo(&entry, B_CREATE_FILE | B_READ_WRITE);
file.Write("local", 5);
}
} }
@@ -262,10 +230,10 @@ DateTimeView::_WriteRTCSettings()
BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY); BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
if (file.InitCheck() == B_OK) { if (file.InitCheck() == B_OK) {
if (fLocalTime->Value() == B_CONTROL_ON) if (fUseGmtTime)
file.Write("local", 5);
else
file.Write("gmt", 3); file.Write("gmt", 3);
else
file.Write("local", 5);
} }
} }
@@ -288,8 +256,7 @@ DateTimeView::_UpdateGmtSettings()
entry.GetPath(&path); entry.GetPath(&path);
// take the existing timezone and set it's gmt use // take the existing timezone and set it's gmt use
_kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH _kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH, fUseGmtTime);
, fGmtTime->Value() == B_CONTROL_ON);
} }
@@ -314,7 +281,7 @@ DateTimeView::_UpdateDateTime(BMessage *message)
&& message->FindInt32("minute", &minute) == B_OK && message->FindInt32("minute", &minute) == B_OK
&& message->FindInt32("second", &second) == B_OK) && message->FindInt32("second", &second) == B_OK)
{ {
fTimeEdit->SetTime(hour, minute, second);
fClock->SetTime(hour, minute, second); fClock->SetTime(hour, minute, second);
fTimeEdit->SetTime(hour, minute, second);
} }
} }
+1 -2
View File
@@ -29,7 +29,6 @@ class DateTimeView : public BView {
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void Draw(BRect updaterect); virtual void Draw(BRect updaterect);
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
virtual void GetPreferredSize(float *width, float *height);
private: private:
void _InitView(); void _InitView();
@@ -46,7 +45,7 @@ class DateTimeView : public BView {
BCalendarView *fCalendarView; BCalendarView *fCalendarView;
TAnalogClock *fClock; TAnalogClock *fClock;
bool fIsLocalTime; bool fUseGmtTime;
bool fInitialized; bool fInitialized;
}; };
+15 -15
View File
@@ -19,8 +19,8 @@ namespace {
{ {
font_height fontHeight; font_height fontHeight;
be_plain_font->GetHeight(&fontHeight); be_plain_font->GetHeight(&fontHeight);
float height = ceil(fontHeight.descent) + ceil(fontHeight.ascent) float height = ceil(fontHeight.descent + fontHeight.ascent
+ ceil(fontHeight.leading); + fontHeight.leading);
return height; return height;
} }
} }
@@ -51,28 +51,28 @@ TTZDisplay::AttachedToWindow()
void void
TTZDisplay::ResizeToPreferred() TTZDisplay::ResizeToPreferred()
{ {
float height = _FontHeight(); ResizeTo(Bounds().Width(), _FontHeight() * 2.0 + 4.0);
ResizeTo(Bounds().Width(), height *2);
} }
void void
TTZDisplay::Draw(BRect /* updateRect */) TTZDisplay::Draw(BRect /* updateRect */)
{ {
BRect bounds(Bounds());
SetLowColor(ViewColor()); SetLowColor(ViewColor());
FillRect(bounds, B_SOLID_LOW);
float height = _FontHeight();
BPoint drawpt(bounds.left +2, height /2.0 +1); BRect bounds = Bounds();
DrawString(fLabel.String(), drawpt); FillRect(Bounds(), B_SOLID_LOW);
drawpt.y += height +2;
DrawString(fText.String(), drawpt);
drawpt.x = bounds.right -be_plain_font->StringWidth(fTime.String()) - 2; float fontHeight = _FontHeight();
DrawString(fTime.String(), drawpt);
BPoint pt(bounds.left + 2.0, fontHeight / 2.0 + 2.0);
DrawString(fLabel.String(), pt);
pt.y += fontHeight;
DrawString(fText.String(), pt);
pt.x = bounds.right - StringWidth(fTime.String()) - 2.0;
DrawString(fTime.String(), pt);
} }
+19 -24
View File
@@ -61,7 +61,7 @@ TTimeWindow::QuitRequested()
{ {
TimeSettings().SetLeftTop(Frame().LeftTop()); TimeSettings().SetLeftTop(Frame().LeftTop());
fBaseView->StopWatchingAll(fTimeZones); fBaseView->StopWatchingAll(fTimeZoneView);
fBaseView->StopWatchingAll(fDateTimeView); fBaseView->StopWatchingAll(fDateTimeView);
be_app->PostMessage(B_QUIT_REQUESTED); be_app->PostMessage(B_QUIT_REQUESTED);
@@ -75,40 +75,35 @@ TTimeWindow::_InitWindow()
{ {
SetPulseRate(500000); SetPulseRate(500000);
BRect bounds(Bounds()); fDateTimeView = new DateTimeView(Bounds());
fBaseView = new TTimeBaseView(bounds, "background view"); BRect bounds = fDateTimeView->Bounds();
fTimeZoneView = new TimeZoneView(bounds);
fBaseView = new TTimeBaseView(bounds, "baseView");
AddChild(fBaseView); AddChild(fBaseView);
bounds.top = 9;
BTabView *tabview = new BTabView(bounds, "tab_view");
bounds = tabview->Bounds();
bounds.InsetBy(4, 6);
bounds.bottom -= tabview->TabHeight();
fDateTimeView = new DateTimeView(bounds);
fBaseView->StartWatchingAll(fDateTimeView); fBaseView->StartWatchingAll(fDateTimeView);
fBaseView->StartWatchingAll(fTimeZoneView);
bounds.OffsetBy(10.0, 10.0);
BTabView *tabView = new BTabView(bounds.InsetByCopy(-5.0, -5.0),
"tabView" , B_WIDTH_AS_USUAL, B_FOLLOW_NONE);
BTab *tab = new BTab(); BTab *tab = new BTab();
tabview->AddTab(fDateTimeView, tab); tabView->AddTab(fDateTimeView, tab);
tab->SetLabel("Date & Time"); tab->SetLabel("Date & Time");
fTimeZones = new TZoneView(bounds);
fBaseView->StartWatchingAll(fTimeZones);
tab = new BTab(); tab = new BTab();
tabview->AddTab(fTimeZones, tab); tabView->AddTab(fTimeZoneView, tab);
tab->SetLabel("Time Zone"); tab->SetLabel("Timezone");
fBaseView->AddChild(tabview); fBaseView->AddChild(tabView);
tabView->ResizeBy(0.0, tabView->TabHeight());
fBaseView->ResizeTo(tabView->Bounds().Width() + 10.0,
tabView->Bounds().Height() + 10.0);
float width; ResizeTo(fBaseView->Bounds().Width(), fBaseView->Bounds().Height());
float height;
fDateTimeView->GetPreferredSize(&width, &height);
// width/ height from DateTimeView + all InsetBy etc..
ResizeTo(width +10, height + tabview->TabHeight() +25);
} }
+2 -2
View File
@@ -17,7 +17,7 @@
class BMessage; class BMessage;
class DateTimeView; class DateTimeView;
class TTimeBaseView; class TTimeBaseView;
class TZoneView; class TimeZoneView;
class TTimeWindow : public BWindow { class TTimeWindow : public BWindow {
@@ -35,7 +35,7 @@ class TTimeWindow : public BWindow {
private: private:
TTimeBaseView *fBaseView; TTimeBaseView *fBaseView;
DateTimeView *fDateTimeView; DateTimeView *fDateTimeView;
TZoneView *fTimeZones; TimeZoneView *fTimeZoneView;
}; };
#endif // TIME_WINDOW_H #endif // TIME_WINDOW_H
+32 -45
View File
@@ -58,32 +58,33 @@ class TZoneItem : public BStringItem {
}; };
TZoneView::TZoneView(BRect frame) TimeZoneView::TimeZoneView(BRect frame)
: BView(frame, B_EMPTY_STRING, B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE_JUMP), : BView(frame, "timeZoneView", B_FOLLOW_NONE, B_WILL_DRAW | B_NAVIGABLE_JUMP),
fNotInitialized(true) fInitialized(false)
{ {
ReadTimeZoneLink(); ReadTimeZoneLink();
InitView(); InitView();
} }
TZoneView::~TZoneView() TimeZoneView::~TimeZoneView()
{ {
} }
void void
TZoneView::AttachedToWindow() TimeZoneView::AttachedToWindow()
{ {
if (Parent()) if (Parent())
SetViewColor(Parent()->ViewColor()); SetViewColor(Parent()->ViewColor());
if (fNotInitialized) { if (!fInitialized) {
// stupid hack fInitialized = true;
fRegionPopUp->SetTargetForItems(this);
fSetZone->SetTarget(this); fSetZone->SetTarget(this);
fCityList->SetTarget(this); fCityList->SetTarget(this);
fRegionPopUp->SetTargetForItems(this);
// update displays // update displays
BPath parent; BPath parent;
fCurrentZone.GetParent(&parent); fCurrentZone.GetParent(&parent);
@@ -92,15 +93,13 @@ TZoneView::AttachedToWindow()
fCityList->Select(czone); fCityList->Select(czone);
fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text()); fCurrent->SetText(((TZoneItem *)fCityList->ItemAt(czone))->Text());
} }
fNotInitialized = false;
ResizeTo(Bounds().Width(), Bounds().Height() +40);
} }
fCityList->ScrollToSelection(); fCityList->ScrollToSelection();
} }
void void
TZoneView::MessageReceived(BMessage *message) TimeZoneView::MessageReceived(BMessage *message)
{ {
int32 change; int32 change;
switch(message->what) { switch(message->what) {
@@ -135,15 +134,8 @@ TZoneView::MessageReceived(BMessage *message)
} }
const char*
TZoneView::TimeZone()
{
return fCurrent->Text();
}
void void
TZoneView::UpdateDateTime(BMessage *message) TimeZoneView::UpdateDateTime(BMessage *message)
{ {
int32 hour; int32 hour;
int32 minute; int32 minute;
@@ -165,58 +157,53 @@ TZoneView::UpdateDateTime(BMessage *message)
void void
TZoneView::InitView() TimeZoneView::InitView()
{ {
font_height fontHeight;
be_plain_font->GetHeight(&fontHeight);
float textHeight = fontHeight.descent + fontHeight.ascent + fontHeight.leading;
// Zone menu // Zone menu
fRegionPopUp = new BPopUpMenu(B_EMPTY_STRING, true, true, B_ITEMS_IN_COLUMN); fRegionPopUp = new BPopUpMenu("", true, true, B_ITEMS_IN_COLUMN);
BuildRegionMenu(); BuildRegionMenu();
// left side // left side
BRect frameLeft(Bounds()); BRect frameLeft(Bounds());
frameLeft.right = frameLeft.Width() / 2; frameLeft.right = frameLeft.Width() / 2.0;
frameLeft.InsetBy(10.0f, 10.0f); frameLeft.InsetBy(10.0f, 10.0f);
BMenuField *menuField = new BMenuField(frameLeft, "regions", NULL, fRegionPopUp, false); BMenuField *menuField = new BMenuField(frameLeft, "regions", NULL, fRegionPopUp, false);
AddChild(menuField); AddChild(menuField);
menuField->ResizeToPreferred(); menuField->ResizeToPreferred();
frameLeft.top = menuField->Frame().bottom +10; frameLeft.top = menuField->Frame().bottom + 10.0;
frameLeft.right -= B_V_SCROLL_BAR_WIDTH; frameLeft.right -= B_V_SCROLL_BAR_WIDTH;
// City Listing // City Listing
fCityList = new BListView(frameLeft, "cityList", B_SINGLE_SELECTION_LIST, fCityList = new BListView(frameLeft, "cityList", B_SINGLE_SELECTION_LIST);
B_FOLLOW_ALL, B_WILL_DRAW | B_NAVIGABLE | B_FRAME_EVENTS);
fCityList->SetSelectionMessage(new BMessage(H_CITY_CHANGED)); fCityList->SetSelectionMessage(new BMessage(H_CITY_CHANGED));
fCityList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE)); fCityList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE));
BScrollView *scrollList = new BScrollView("scroll_list", fCityList, BScrollView *scrollList = new BScrollView("scrollList", fCityList,
B_FOLLOW_ALL, 0, false, true); B_FOLLOW_ALL, 0, false, true);
AddChild(scrollList); AddChild(scrollList);
// right side // right side
BRect frameRight(Bounds()); BRect frameRight(Bounds());
frameRight.left = frameRight.Width() / 2; frameRight.left = frameRight.Width() / 2.0;
frameRight.InsetBy(10.0f, 10.0f); frameRight.InsetBy(10.0f, 10.0f);
frameRight.top = frameLeft.top; frameRight.top = frameLeft.top;
// Time Displays // Time Displays
fCurrent = new TTZDisplay(frameRight, "current", "Current time:"); fCurrent = new TTZDisplay(frameRight, "currentTime", "Current time:");
AddChild(fCurrent); AddChild(fCurrent);
fCurrent->ResizeToPreferred(); fCurrent->ResizeToPreferred();
frameRight.OffsetBy(0, (textHeight) * 3 +10.0); frameRight.top = fCurrent->Frame().bottom + 10.0;
fPreview = new TTZDisplay(frameRight, "preview", "Preview time:"); fPreview = new TTZDisplay(frameRight, "previewTime", "Preview time:");
AddChild(fPreview); AddChild(fPreview);
fPreview->ResizeToPreferred(); fPreview->ResizeToPreferred();
// set button // set button
fSetZone = new BButton(frameRight, "set", "Set Timezone", fSetZone = new BButton(frameRight, "setTimeZone", "Set Time Zone",
new BMessage(H_SET_TIME_ZONE), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); new BMessage(H_SET_TIME_ZONE));
AddChild(fSetZone); AddChild(fSetZone);
fSetZone->SetEnabled(false); fSetZone->SetEnabled(false);
fSetZone->ResizeToPreferred(); fSetZone->ResizeToPreferred();
@@ -227,7 +214,7 @@ TZoneView::InitView()
void void
TZoneView::BuildRegionMenu() TimeZoneView::BuildRegionMenu()
{ {
BPath path; BPath path;
if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK) if (find_directory(B_BEOS_ETC_DIRECTORY, &path) != B_OK)
@@ -280,7 +267,7 @@ TZoneView::BuildRegionMenu()
int32 int32
TZoneView::FillCityList(const char *area) TimeZoneView::FillCityList(const char *area)
{ {
// clear list // clear list
int32 count = fCityList->CountItems(); int32 count = fCityList->CountItems();
@@ -334,7 +321,7 @@ TZoneView::FillCityList(const char *area)
void void
TZoneView::ChangeRegion(BMessage *message) TimeZoneView::ChangeRegion(BMessage *message)
{ {
BString area; BString area;
message->FindString("region", &area); message->FindString("region", &area);
@@ -344,7 +331,7 @@ TZoneView::ChangeRegion(BMessage *message)
void void
TZoneView::ReadTimeZoneLink() TimeZoneView::ReadTimeZoneLink()
{ {
BEntry tzLink; BEntry tzLink;
@@ -387,7 +374,7 @@ TZoneView::ReadTimeZoneLink()
void void
TZoneView::SetPreview() TimeZoneView::SetPreview()
{ {
int32 selection = fCityList->CurrentSelection(); int32 selection = fCityList->CurrentSelection();
if (selection >= 0) { if (selection >= 0) {
@@ -413,7 +400,7 @@ TZoneView::SetPreview()
void void
TZoneView::SetCurrent(const char *text) TimeZoneView::SetCurrent(const char *text)
{ {
SetTimeZone(fCurrentZone.Path()); SetTimeZone(fCurrentZone.Path());
@@ -426,7 +413,7 @@ TZoneView::SetCurrent(const char *text)
void void
TZoneView::SetTimeZone() TimeZoneView::SetTimeZone()
{ {
/* set time based on supplied timezone. How to do this? /* set time based on supplied timezone. How to do this?
1) replace symlink "timezone" in B_USER_SETTINGS_DIR with a link to the new timezone 1) replace symlink "timezone" in B_USER_SETTINGS_DIR with a link to the new timezone
@@ -486,7 +473,7 @@ TZoneView::SetTimeZone()
void void
TZoneView::SetTimeZone(const char *zone) TimeZoneView::SetTimeZone(const char *zone)
{ {
putenv(BString("TZ=").Append(zone).String()); putenv(BString("TZ=").Append(zone).String());
tzset(); tzset();
+4 -6
View File
@@ -21,15 +21,13 @@ class BButton;
class TTZDisplay; class TTZDisplay;
class TZoneView : public BView { class TimeZoneView : public BView {
public: public:
TZoneView(BRect frame); TimeZoneView(BRect frame);
virtual ~TZoneView(); virtual ~TimeZoneView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void MessageReceived(BMessage *message); virtual void MessageReceived(BMessage *message);
const char* TimeZone();
private: private:
void UpdateDateTime(BMessage *message); void UpdateDateTime(BMessage *message);
@@ -55,7 +53,7 @@ class TZoneView : public BView {
int32 fHour; int32 fHour;
int32 fMinute; int32 fMinute;
BPath fCurrentZone; BPath fCurrentZone;
bool fNotInitialized; bool fInitialized;
}; };
#endif //Zone_View_H #endif //Zone_View_H