Applied patch by Philippe Saint-Pierre with some changes by myself:
* Added Revert button and Revert feature. The time at which the preflet is started is remembered, the uptime of the preflet is calculated via system_time(). TODO: Better placement for the Revert button. Currently it looks like it can only revert date changes. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25210 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
fe2edb706d
commit
1cae077af9
@ -6,6 +6,7 @@
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
* Philippe Saint-Pierre <stpere@gmail.com>
|
||||
*/
|
||||
|
||||
#include "DateTimeView.h"
|
||||
@ -13,8 +14,10 @@
|
||||
#include "CalendarView.h"
|
||||
#include "DateTimeEdit.h"
|
||||
#include "TimeMessages.h"
|
||||
#include "DateTime.h"
|
||||
|
||||
|
||||
#include <Button.h>
|
||||
#include <CheckBox.h>
|
||||
#include <Entry.h>
|
||||
#include <File.h>
|
||||
@ -25,6 +28,7 @@
|
||||
#include <String.h>
|
||||
#include <StringView.h>
|
||||
#include <Window.h>
|
||||
#include <time.h>
|
||||
|
||||
|
||||
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
||||
@ -39,10 +43,14 @@ DateTimeView::DateTimeView(BRect frame)
|
||||
: BView(frame, "dateTimeView", B_FOLLOW_NONE, B_WILL_DRAW | B_NAVIGABLE_JUMP),
|
||||
fGmtTime(NULL),
|
||||
fUseGmtTime(false),
|
||||
fInitialized(false)
|
||||
fInitialized(false),
|
||||
fSystemTimeAtStart(system_time())
|
||||
{
|
||||
_ReadRTCSettings();
|
||||
_InitView();
|
||||
|
||||
// record the current time to enable revert.
|
||||
time(&fTimeAtStart);
|
||||
}
|
||||
|
||||
|
||||
@ -63,7 +71,8 @@ DateTimeView::AttachedToWindow()
|
||||
|
||||
fGmtTime->SetTarget(this);
|
||||
fLocalTime->SetTarget(this);
|
||||
fCalendarView->SetTarget(this);
|
||||
fCalendarView->SetTarget(this);
|
||||
fRevertButton->SetTarget(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,11 +111,11 @@ DateTimeView::MessageReceived(BMessage *message)
|
||||
switch(change) {
|
||||
case H_TM_CHANGED:
|
||||
_UpdateDateTime(message);
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -116,13 +125,20 @@ DateTimeView::MessageReceived(BMessage *message)
|
||||
msg.what = H_USER_CHANGE;
|
||||
msg.AddBool("time", false);
|
||||
Window()->PostMessage(&msg);
|
||||
} break;
|
||||
break;
|
||||
}
|
||||
|
||||
case kRTCUpdate:
|
||||
fUseGmtTime = !fUseGmtTime;
|
||||
fUseGmtTime = fGmtTime->Value() == B_CONTROL_ON;
|
||||
_UpdateGmtSettings();
|
||||
CheckCanRevert();
|
||||
break;
|
||||
|
||||
case kMsgRevert:
|
||||
_Revert();
|
||||
fRevertButton->SetEnabled(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
break;
|
||||
@ -130,6 +146,62 @@ DateTimeView::MessageReceived(BMessage *message)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DateTimeView::CheckCanRevert()
|
||||
{
|
||||
// check GMT vs Local setting
|
||||
bool enable = fUseGmtTime != fOldUseGmtTime;
|
||||
|
||||
// check for changed time
|
||||
time_t unchangedNow = fTimeAtStart + _PrefletUptime();
|
||||
time_t changedNow;
|
||||
time(&changedNow);
|
||||
|
||||
enable = enable || (changedNow != unchangedNow);
|
||||
|
||||
fRevertButton->SetEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DateTimeView::_Revert()
|
||||
{
|
||||
// Set the clock and calendar as they were at launch time +
|
||||
// time ellapsed since application launch.
|
||||
|
||||
fUseGmtTime = fOldUseGmtTime;
|
||||
_UpdateGmtSettings();
|
||||
|
||||
if (fUseGmtTime)
|
||||
fGmtTime->SetValue(B_CONTROL_ON);
|
||||
else
|
||||
fLocalTime->SetValue(B_CONTROL_ON);
|
||||
|
||||
time_t timeNow = fTimeAtStart + _PrefletUptime();
|
||||
struct tm result;
|
||||
struct tm* timeInfo;
|
||||
timeInfo = localtime_r(&timeNow, &result);
|
||||
|
||||
BDateTime dateTime = BDateTime::CurrentDateTime(B_LOCAL_TIME);
|
||||
BTime time = dateTime.Time();
|
||||
BDate date = dateTime.Date();
|
||||
time.SetTime(timeInfo->tm_hour, timeInfo->tm_min, timeInfo->tm_sec % 60);
|
||||
date.SetDate(timeInfo->tm_year + 1900, timeInfo->tm_mon + 1,
|
||||
timeInfo->tm_mday);
|
||||
dateTime.SetTime(time);
|
||||
dateTime.SetDate(date);
|
||||
|
||||
set_real_time_clock(dateTime.Time_t());
|
||||
}
|
||||
|
||||
|
||||
time_t
|
||||
DateTimeView::_PrefletUptime() const
|
||||
{
|
||||
return (time_t)((system_time() - fSystemTimeAtStart) / 1000000);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DateTimeView::_InitView()
|
||||
{
|
||||
@ -192,6 +264,22 @@ DateTimeView::_InitView()
|
||||
else
|
||||
fLocalTime->SetValue(B_CONTROL_ON);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
* Andrew McCall <mccall@@digitalparadise.co.uk>
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
* Philippe Saint-Pierre <stpere@gmail.com>
|
||||
*/
|
||||
#ifndef DATE_TIME_VIEW_H
|
||||
#define DATE_TIME_VIEW_H
|
||||
@ -19,6 +20,7 @@ class TTimeEdit;
|
||||
class BCalendarView;
|
||||
class BRadioButton;
|
||||
class TAnalogClock;
|
||||
class BButton;
|
||||
|
||||
|
||||
class DateTimeView : public BView {
|
||||
@ -30,12 +32,16 @@ class DateTimeView : public BView {
|
||||
virtual void Draw(BRect updaterect);
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
|
||||
void CheckCanRevert();
|
||||
|
||||
private:
|
||||
void _InitView();
|
||||
void _ReadRTCSettings();
|
||||
void _WriteRTCSettings();
|
||||
void _UpdateGmtSettings();
|
||||
void _UpdateDateTime(BMessage *message);
|
||||
void _Revert();
|
||||
time_t _PrefletUptime() const;
|
||||
|
||||
private:
|
||||
BRadioButton *fLocalTime;
|
||||
@ -45,8 +51,14 @@ class DateTimeView : public BView {
|
||||
BCalendarView *fCalendarView;
|
||||
TAnalogClock *fClock;
|
||||
|
||||
BButton *fRevertButton;
|
||||
|
||||
bool fUseGmtTime;
|
||||
bool fOldUseGmtTime;
|
||||
bool fInitialized;
|
||||
|
||||
time_t fTimeAtStart;
|
||||
bigtime_t fSystemTimeAtStart;
|
||||
};
|
||||
|
||||
#endif // DATE_TIME_VIEW_H
|
||||
|
@ -6,6 +6,7 @@
|
||||
* Andrew McCall, mccall@digitalparadise.co.uk
|
||||
* Mike Berg <mike@berg-net.us>
|
||||
* Julun <host.haiku@gmx.de>
|
||||
* Philippe Saint-Pierre <stpere@gmail.com>
|
||||
*/
|
||||
#ifndef TIME_MESSAGES_H
|
||||
#define TIME_MESSAGES_H
|
||||
@ -40,5 +41,8 @@ const uint32 kWeekStart = '_kws';
|
||||
// clicked on day in calendar
|
||||
const uint32 kDayChanged = '_kdc';
|
||||
|
||||
// clicked on revert button
|
||||
const uint32 kMsgRevert = 'rvrt';
|
||||
|
||||
#endif //TIME_MESSAGES_H
|
||||
|
||||
|
@ -43,6 +43,7 @@ TTimeWindow::MessageReceived(BMessage *message)
|
||||
switch(message->what) {
|
||||
case H_USER_CHANGE:
|
||||
fBaseView->ChangeTime(message);
|
||||
fDateTimeView->CheckCanRevert();
|
||||
break;
|
||||
|
||||
case B_ABOUT_REQUESTED:
|
||||
|
Loading…
Reference in New Issue
Block a user