patch by Julun:

* write the RTC settings (GMT versus Local time)
* small cleanups


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22251 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2007-09-19 07:12:08 +00:00
parent e7b0402927
commit 062aea5c40
2 changed files with 41 additions and 20 deletions
+39 -18
View File
@@ -23,18 +23,21 @@
#include <String.h> #include <String.h>
#include <StringView.h> #include <StringView.h>
#include <stdio.h>
#include <stdlib.h>
TSettingsView::TSettingsView(BRect frame) TSettingsView::TSettingsView(BRect frame)
: BView(frame,"Settings", B_FOLLOW_ALL, : BView(frame,"Settings", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP), B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP),
fGmtTime(NULL) fGmtTime(NULL)
{ {
InitView(); InitView();
} }
TSettingsView::~TSettingsView() TSettingsView::~TSettingsView()
{ {
WriteRTCSettings();
} }
@@ -58,13 +61,13 @@ TSettingsView::MessageReceived(BMessage *message)
case H_TM_CHANGED: case H_TM_CHANGED:
UpdateDateTime(message); UpdateDateTime(message);
break; break;
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
break; break;
} }
break; break;
default: default:
BView::MessageReceived(message); BView::MessageReceived(message);
break; break;
@@ -91,7 +94,7 @@ void
TSettingsView::InitView() TSettingsView::InitView()
{ {
ReadRTCSettings(); ReadRTCSettings();
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;
@@ -125,13 +128,13 @@ TSettingsView::InitView()
float left = fTimeEdit->Frame().left; float left = fTimeEdit->Frame().left;
float tmp = MIN(frameRight.Width(), frameRight.Height()); float tmp = MIN(frameRight.Width(), frameRight.Height());
frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) /2; frameRight.left = left + (fTimeEdit->Bounds().Width() - tmp) /2;
frameRight.bottom = frameRight.top + tmp; frameRight.bottom = frameRight.top + tmp;
frameRight.right = frameRight.left + tmp; frameRight.right = frameRight.left + tmp;
fClock = new TAnalogClock(frameRight, "analog clock", B_FOLLOW_NONE, B_WILL_DRAW); 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; frameRight.left = left;
frameRight.top = fClock->Frame().bottom + 10; frameRight.top = fClock->Frame().bottom + 10;
@@ -139,7 +142,7 @@ TSettingsView::InitView()
AddChild(text); AddChild(text);
text->ResizeToPreferred(); text->ResizeToPreferred();
frameRight.left += 10.0f; frameRight.left += 10.0f;
frameRight.top = text->Frame().bottom + 5; frameRight.top = text->Frame().bottom + 5;
fLocalTime = new BRadioButton(frameRight, "local", "Local time", fLocalTime = new BRadioButton(frameRight, "local", "Local time",
@@ -165,21 +168,21 @@ TSettingsView::Draw(BRect /*updateRect*/)
{ {
//draw a separator line //draw a separator line
BRect bounds(Bounds()); BRect bounds(Bounds());
rgb_color viewcolor = ViewColor(); rgb_color viewcolor = ViewColor();
rgb_color dark = tint_color(viewcolor, B_DARKEN_4_TINT); rgb_color dark = tint_color(viewcolor, B_DARKEN_4_TINT);
rgb_color light = tint_color(viewcolor, B_LIGHTEN_MAX_TINT); rgb_color light = tint_color(viewcolor, B_LIGHTEN_MAX_TINT);
BPoint start(bounds.Width() / 2.0f +2.0f, bounds.top +1.0f); BPoint start(bounds.Width() / 2.0f +2.0f, bounds.top +1.0f);
BPoint end(bounds.Width() / 2.0 +2.0f, bounds.bottom -1.0f); BPoint end(bounds.Width() / 2.0 +2.0f, bounds.bottom -1.0f);
BeginLineArray(2); BeginLineArray(2);
AddLine(start, end, dark); AddLine(start, end, dark);
start.x++; start.x++;
end.x++; end.x++;
AddLine(start, end, light); AddLine(start, end, light);
EndLineArray(); EndLineArray();
fTimeEdit->Draw(bounds); fTimeEdit->Draw(bounds);
fDateEdit->Draw(bounds); fDateEdit->Draw(bounds);
} }
@@ -195,7 +198,7 @@ TSettingsView::GMTime()
void void
TSettingsView::UpdateDateTime(BMessage *message) TSettingsView::UpdateDateTime(BMessage *message)
{ {
int32 day; int32 day;
int32 month; int32 month;
int32 year; int32 year;
if (message->FindInt32("month", &month) == B_OK if (message->FindInt32("month", &month) == B_OK
@@ -205,7 +208,7 @@ TSettingsView::UpdateDateTime(BMessage *message)
fDateEdit->SetDate(year, month, day); fDateEdit->SetDate(year, month, day);
fCalendar->SetTo(year, month, day); fCalendar->SetTo(year, month, day);
} }
int32 hour; int32 hour;
int32 minute; int32 minute;
int32 second; int32 second;
@@ -227,7 +230,7 @@ TSettingsView::ReadRTCSettings()
return; return;
path.Append("RTC_time_settings"); path.Append("RTC_time_settings");
BFile file; BFile file;
BEntry entry(path.Path()); BEntry entry(path.Path());
if (entry.Exists()) { if (entry.Exists()) {
@@ -236,7 +239,7 @@ TSettingsView::ReadRTCSettings()
char localTime[6]; char localTime[6];
file.Read(localTime, 6); file.Read(localTime, 6);
BString text(localTime); BString text(localTime);
if (text.Compare("local\n", 5) == 0) if (text.Compare("local", 4) == 0)
fIsLocalTime = true; fIsLocalTime = true;
else else
fIsLocalTime = false; fIsLocalTime = false;
@@ -245,7 +248,25 @@ TSettingsView::ReadRTCSettings()
// create set to local // create set to local
fIsLocalTime = true; fIsLocalTime = true;
file.SetTo(&entry, B_CREATE_FILE | B_READ_WRITE); file.SetTo(&entry, B_CREATE_FILE | B_READ_WRITE);
file.Write("local\n", 6); file.Write("local", 5);
} }
} }
void
TSettingsView::WriteRTCSettings()
{
BPath path;
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
return;
path.Append("RTC_time_settings");
BFile file(path.Path(), B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY);
if (file.InitCheck() == B_OK) {
if (fLocalTime->Value() == B_CONTROL_ON)
file.Write("local", 5);
else
file.Write("gmt", 3);
}
}
+2 -2
View File
@@ -25,18 +25,18 @@ class TSettingsView : public BView {
public: public:
TSettingsView(BRect frame); TSettingsView(BRect frame);
virtual ~TSettingsView(); virtual ~TSettingsView();
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); virtual void GetPreferredSize(float *width, float *height);
void ChangeRTCSetting();
bool GMTime(); bool GMTime();
private: private:
void InitView(); void InitView();
void ReadRTCSettings(); void ReadRTCSettings();
void WriteRTCSettings();
void UpdateDateTime(BMessage *message); void UpdateDateTime(BMessage *message);
BRadioButton *fLocalTime; BRadioButton *fLocalTime;