* 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:
parent
7af3465eb5
commit
d3bde5de44
|
@ -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.
|
||||
*
|
||||
* Authors:
|
||||
|
@ -107,10 +107,10 @@ void
|
|||
DateTimeView::MessageReceived(BMessage *message)
|
||||
{
|
||||
int32 change;
|
||||
switch(message->what) {
|
||||
switch (message->what) {
|
||||
case B_OBSERVER_NOTICE_CHANGE:
|
||||
message->FindInt32(B_OBSERVE_WHAT_CHANGE, &change);
|
||||
switch(change) {
|
||||
switch (change) {
|
||||
case H_TM_CHANGED:
|
||||
_UpdateDateTime(message);
|
||||
break;
|
||||
|
@ -119,7 +119,7 @@ DateTimeView::MessageReceived(BMessage *message)
|
|||
BView::MessageReceived(message);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case kDayChanged:
|
||||
{
|
||||
|
@ -144,6 +144,7 @@ DateTimeView::MessageReceived(BMessage *message)
|
|||
fTimeEdit->MakeFocus(false);
|
||||
fClock->ChangeTimeFinished();
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
|
@ -170,7 +171,7 @@ void
|
|||
DateTimeView::_Revert()
|
||||
{
|
||||
// Set the clock and calendar as they were at launch time +
|
||||
// time ellapsed since application launch.
|
||||
// time elapsed since application launch.
|
||||
|
||||
fUseGmtTime = fOldUseGmtTime;
|
||||
_UpdateGmtSettings();
|
||||
|
@ -293,8 +294,7 @@ DateTimeView::_ReadRTCSettings()
|
|||
if (strncmp(buffer, "gmt", 3) == 0)
|
||||
fUseGmtTime = true;
|
||||
}
|
||||
} else
|
||||
_UpdateGmtSettings();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -302,7 +302,7 @@ void
|
|||
DateTimeView::_WriteRTCSettings()
|
||||
{
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path, true) != B_OK)
|
||||
return;
|
||||
|
||||
path.Append("RTC_time_settings");
|
||||
|
@ -323,19 +323,20 @@ DateTimeView::_UpdateGmtSettings()
|
|||
_WriteRTCSettings();
|
||||
|
||||
BPath path;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK)
|
||||
return;
|
||||
if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) {
|
||||
path.Append("timezone");
|
||||
BEntry entry(path.Path(), true);
|
||||
if (entry.Exists()) {
|
||||
entry.GetPath(&path);
|
||||
|
||||
path.Append("timezone");
|
||||
BEntry entry(path.Path(), true);
|
||||
// take the existing timezone and set it's gmt use
|
||||
_kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH, fUseGmtTime);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!entry.Exists())
|
||||
return;
|
||||
|
||||
entry.GetPath(&path);
|
||||
|
||||
// take the existing timezone and set it's gmt use
|
||||
_kern_set_tzfilename(path.Path(), B_PATH_NAME_LENGTH, fUseGmtTime);
|
||||
// Only update GMT
|
||||
_kern_set_tzfilename(NULL, 0, fUseGmtTime);
|
||||
}
|
||||
|
||||
|
||||
|
@ -347,8 +348,7 @@ DateTimeView::_UpdateDateTime(BMessage *message)
|
|||
int32 year;
|
||||
if (message->FindInt32("month", &month) == 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);
|
||||
fCalendarView->SetDate(year, month, day);
|
||||
}
|
||||
|
@ -358,8 +358,7 @@ DateTimeView::_UpdateDateTime(BMessage *message)
|
|||
int32 second;
|
||||
if (message->FindInt32("hour", &hour) == 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);
|
||||
fTimeEdit->SetTime(hour, minute, second);
|
||||
}
|
||||
|
|
|
@ -168,9 +168,6 @@ TimeZoneView::MessageReceived(BMessage *message)
|
|||
case H_SET_TIME_ZONE:
|
||||
{
|
||||
SetTimeZone();
|
||||
BMessage msg(*message);
|
||||
msg.what = kRTCUpdate;
|
||||
Window()->PostMessage(&msg);
|
||||
((TTimeWindow*)Window())->SetRevertStatus();
|
||||
break;
|
||||
}
|
||||
|
@ -437,12 +434,13 @@ TimeZoneView::SetPreview()
|
|||
SetTimeZone(item->Path());
|
||||
|
||||
// calc preview time
|
||||
time_t current = time(0);
|
||||
struct tm *ltime = localtime(¤t);
|
||||
time_t current = time(NULL);
|
||||
struct tm localTime;
|
||||
localtime_r(¤t, &localTime);
|
||||
|
||||
// update prview
|
||||
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
|
||||
SetTimeZone(fCurrentZone.Path());
|
||||
|
@ -457,11 +455,12 @@ TimeZoneView::SetCurrent(const char *text)
|
|||
{
|
||||
SetTimeZone(fCurrentZone.Path());
|
||||
|
||||
time_t current = time(0);
|
||||
struct tm *ltime = localtime(¤t);
|
||||
time_t current = time(NULL);
|
||||
struct tm localTime;
|
||||
localtime_r(¤t, &localTime);
|
||||
|
||||
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());
|
||||
|
||||
// update display
|
||||
time_t current = time(0);
|
||||
struct tm *ltime = localtime(¤t);
|
||||
time_t current = time(NULL);
|
||||
struct tm localTime;
|
||||
localtime_r(¤t, &localTime);
|
||||
|
||||
char tza[B_PATH_NAME_LENGTH];
|
||||
sprintf(tza, "%s", target.Path());
|
||||
set_timezone(tza);
|
||||
set_timezone(target.Path());
|
||||
|
||||
// disable button
|
||||
fSetZone->SetEnabled(false);
|
||||
|
||||
time_t newtime = mktime(ltime);
|
||||
ltime = localtime(&newtime);
|
||||
stime(&newtime);
|
||||
time_t newTime = mktime(&localTime);
|
||||
localtime_r(&newTime, &localTime);
|
||||
stime(&newTime);
|
||||
|
||||
fHour = ltime->tm_hour;
|
||||
fMinute = ltime->tm_min;
|
||||
fHour = localTime.tm_hour;
|
||||
fMinute = localTime.tm_min;
|
||||
fCurrentZone.SetTo(target.Path());
|
||||
SetCurrent(((TZoneItem *)fCityList->ItemAt(selection))->Text());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue