* DateTimeView::_UpdateGmtSettings() will now update the GMT setting even if
there is no timezone link yet. This also fixes the time jump when setting the timezone for the first time. * _ReadRTCSettings() will no longer write the defaults. * _WriteRTCSettings() will now also make sure the settings directory exists. * ZoneView::MessageReceived() will no longer post an kRTCUpdate message on changes - no idea what that was for (and that also caused the time jump). * Now uses localtime_r() instead of localtime() everywhere. * Minor cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31372 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
|
* Copyright 2004-2009, Haiku, Inc. All Rights Reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -107,10 +107,10 @@ void
|
|||||||
DateTimeView::MessageReceived(BMessage *message)
|
DateTimeView::MessageReceived(BMessage *message)
|
||||||
{
|
{
|
||||||
int32 change;
|
int32 change;
|
||||||
switch(message->what) {
|
switch (message->what) {
|
||||||
case B_OBSERVER_NOTICE_CHANGE:
|
case B_OBSERVER_NOTICE_CHANGE:
|
||||||
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||||
switch(change) {
|
switch (change) {
|
||||||
case H_TM_CHANGED:
|
case H_TM_CHANGED:
|
||||||
_UpdateDateTime(message);
|
_UpdateDateTime(message);
|
||||||
break;
|
break;
|
||||||
@@ -119,7 +119,7 @@ DateTimeView::MessageReceived(BMessage *message)
|
|||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kDayChanged:
|
case kDayChanged:
|
||||||
{
|
{
|
||||||
@@ -144,6 +144,7 @@ DateTimeView::MessageReceived(BMessage *message)
|
|||||||
fTimeEdit->MakeFocus(false);
|
fTimeEdit->MakeFocus(false);
|
||||||
fClock->ChangeTimeFinished();
|
fClock->ChangeTimeFinished();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(message);
|
BView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
@@ -170,7 +171,7 @@ void
|
|||||||
DateTimeView::_Revert()
|
DateTimeView::_Revert()
|
||||||
{
|
{
|
||||||
// Set the clock and calendar as they were at launch time +
|
// Set the clock and calendar as they were at launch time +
|
||||||
// time ellapsed since application launch.
|
// time elapsed since application launch.
|
||||||
|
|
||||||
fUseGmtTime = fOldUseGmtTime;
|
fUseGmtTime = fOldUseGmtTime;
|
||||||
_UpdateGmtSettings();
|
_UpdateGmtSettings();
|
||||||
@@ -293,8 +294,7 @@ DateTimeView::_ReadRTCSettings()
|
|||||||
if (strncmp(buffer, "gmt", 3) == 0)
|
if (strncmp(buffer, "gmt", 3) == 0)
|
||||||
fUseGmtTime = true;
|
fUseGmtTime = true;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
_UpdateGmtSettings();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -302,7 +302,7 @@ void
|
|||||||
DateTimeView::_WriteRTCSettings()
|
DateTimeView::_WriteRTCSettings()
|
||||||
{
|
{
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path.Append("RTC_time_settings");
|
path.Append("RTC_time_settings");
|
||||||
@@ -323,19 +323,20 @@ DateTimeView::_UpdateGmtSettings()
|
|||||||
_WriteRTCSettings();
|
_WriteRTCSettings();
|
||||||
|
|
||||||
BPath path;
|
BPath path;
|
||||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
||||||
return;
|
path.Append("timezone");
|
||||||
|
BEntry entry(path.Path(), true);
|
||||||
|
if (entry.Exists()) {
|
||||||
|
entry.GetPath(&path);
|
||||||
|
|
||||||
path.Append("timezone");
|
// take the existing timezone and set it's gmt use
|
||||||
BEntry entry(path.Path(), true);
|
_kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH, fUseGmtTime);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!entry.Exists())
|
// Only update GMT
|
||||||
return;
|
_kern_set_tzfilename(NULL, 0, fUseGmtTime);
|
||||||
|
|
||||||
entry.GetPath(&path);
|
|
||||||
|
|
||||||
// take the existing timezone and set it's gmt use
|
|
||||||
_kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH, fUseGmtTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -347,8 +348,7 @@ DateTimeView::_UpdateDateTime(BMessage *message)
|
|||||||
int32 year;
|
int32 year;
|
||||||
if (message->FindInt32("month", &month) == B_OK
|
if (message->FindInt32("month", &month) == B_OK
|
||||||
&& message->FindInt32("day", &day) == B_OK
|
&& message->FindInt32("day", &day) == B_OK
|
||||||
&& message->FindInt32("year", &year) == B_OK)
|
&& message->FindInt32("year", &year) == B_OK) {
|
||||||
{
|
|
||||||
fDateEdit->SetDate(year, month, day);
|
fDateEdit->SetDate(year, month, day);
|
||||||
fCalendarView->SetDate(year, month, day);
|
fCalendarView->SetDate(year, month, day);
|
||||||
}
|
}
|
||||||
@@ -358,8 +358,7 @@ DateTimeView::_UpdateDateTime(BMessage *message)
|
|||||||
int32 second;
|
int32 second;
|
||||||
if (message->FindInt32("hour", &hour) == B_OK
|
if (message->FindInt32("hour", &hour) == B_OK
|
||||||
&& message->FindInt32("minute", &minute) == B_OK
|
&& message->FindInt32("minute", &minute) == B_OK
|
||||||
&& message->FindInt32("second", &second) == B_OK)
|
&& message->FindInt32("second", &second) == B_OK) {
|
||||||
{
|
|
||||||
fClock->SetTime(hour, minute, second);
|
fClock->SetTime(hour, minute, second);
|
||||||
fTimeEdit->SetTime(hour, minute, second);
|
fTimeEdit->SetTime(hour, minute, second);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -168,9 +168,6 @@ TimeZoneView::MessageReceived(BMessage *message)
|
|||||||
case H_SET_TIME_ZONE:
|
case H_SET_TIME_ZONE:
|
||||||
{
|
{
|
||||||
SetTimeZone();
|
SetTimeZone();
|
||||||
BMessage msg(*message);
|
|
||||||
msg.what = kRTCUpdate;
|
|
||||||
Window()->PostMessage(&msg);
|
|
||||||
((TTimeWindow*)Window())->SetRevertStatus();
|
((TTimeWindow*)Window())->SetRevertStatus();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -437,12 +434,13 @@ TimeZoneView::SetPreview()
|
|||||||
SetTimeZone(item->Path());
|
SetTimeZone(item->Path());
|
||||||
|
|
||||||
// calc preview time
|
// calc preview time
|
||||||
time_t current = time(0);
|
time_t current = time(NULL);
|
||||||
struct tm *ltime = localtime(¤t);
|
struct tm localTime;
|
||||||
|
localtime_r(¤t, &localTime);
|
||||||
|
|
||||||
// update prview
|
// update prview
|
||||||
fPreview->SetText(item->Text());
|
fPreview->SetText(item->Text());
|
||||||
fPreview->SetTime(ltime->tm_hour, ltime->tm_min);
|
fPreview->SetTime(localTime.tm_hour, localTime.tm_min);
|
||||||
|
|
||||||
// set timezone back to current
|
// set timezone back to current
|
||||||
SetTimeZone(fCurrentZone.Path());
|
SetTimeZone(fCurrentZone.Path());
|
||||||
@@ -457,11 +455,12 @@ TimeZoneView::SetCurrent(const char *text)
|
|||||||
{
|
{
|
||||||
SetTimeZone(fCurrentZone.Path());
|
SetTimeZone(fCurrentZone.Path());
|
||||||
|
|
||||||
time_t current = time(0);
|
time_t current = time(NULL);
|
||||||
struct tm *ltime = localtime(¤t);
|
struct tm localTime;
|
||||||
|
localtime_r(¤t, &localTime);
|
||||||
|
|
||||||
fCurrent->SetText(text);
|
fCurrent->SetText(text);
|
||||||
fCurrent->SetTime(ltime->tm_hour, ltime->tm_min);
|
fCurrent->SetTime(localTime.tm_hour, localTime.tm_min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -504,22 +503,21 @@ TimeZoneView::SetTimeZone()
|
|||||||
SetTimeZone(target.Path());
|
SetTimeZone(target.Path());
|
||||||
|
|
||||||
// update display
|
// update display
|
||||||
time_t current = time(0);
|
time_t current = time(NULL);
|
||||||
struct tm *ltime = localtime(¤t);
|
struct tm localTime;
|
||||||
|
localtime_r(¤t, &localTime);
|
||||||
|
|
||||||
char tza[B_PATH_NAME_LENGTH];
|
set_timezone(target.Path());
|
||||||
sprintf(tza, "%s", target.Path());
|
|
||||||
set_timezone(tza);
|
|
||||||
|
|
||||||
// disable button
|
// disable button
|
||||||
fSetZone->SetEnabled(false);
|
fSetZone->SetEnabled(false);
|
||||||
|
|
||||||
time_t newtime = mktime(ltime);
|
time_t newTime = mktime(&localTime);
|
||||||
ltime = localtime(&newtime);
|
localtime_r(&newTime, &localTime);
|
||||||
stime(&newtime);
|
stime(&newTime);
|
||||||
|
|
||||||
fHour = ltime->tm_hour;
|
fHour = localTime.tm_hour;
|
||||||
fMinute = ltime->tm_min;
|
fMinute = localTime.tm_min;
|
||||||
fCurrentZone.SetTo(target.Path());
|
fCurrentZone.SetTo(target.Path());
|
||||||
SetCurrent(((TZoneItem *)fCityList->ItemAt(selection))->Text());
|
SetCurrent(((TZoneItem *)fCityList->ItemAt(selection))->Text());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user