2 * Copyright 2004-2007, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Mike Berg <mike@berg-net.us>
7 * Julun <host.haiku@gmx.de>
16 #include "TimeMessages.h"
19 TTimeBaseView::TTimeBaseView(const char* name
)
21 BGroupView(name
, B_VERTICAL
, 0),
22 fMessage(H_TIME_UPDATE
)
24 SetFlags(Flags() | B_PULSE_NEEDED
);
28 TTimeBaseView::~TTimeBaseView()
34 TTimeBaseView::Pulse()
42 TTimeBaseView::AttachedToWindow()
44 SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
45 SetLowUIColor(ViewUIColor());
50 TTimeBaseView::ChangeTime(BMessage
* message
)
53 if (message
->FindBool("time", &isTime
) != B_OK
)
56 BDateTime dateTime
= BDateTime::CurrentDateTime(B_LOCAL_TIME
);
59 BTime time
= dateTime
.Time();
61 if (message
->FindInt32("hour", &hour
) != B_OK
)
65 if (message
->FindInt32("minute", &minute
) != B_OK
)
66 minute
= time
.Minute();
69 if (message
->FindInt32("second", &second
) != B_OK
)
70 second
= time
.Second();
72 time
.SetTime(hour
, minute
, second
);
73 dateTime
.SetTime(time
);
75 BDate date
= dateTime
.Date();
77 if (message
->FindInt32("day", &day
) != B_OK
)
81 if (message
->FindInt32("year", &year
) != B_OK
)
85 if (message
->FindInt32("month", &month
) != B_OK
)
88 if (year
>= 1970 && year
<= 2037) {
89 date
.SetDate(year
, month
, day
);
90 dateTime
.SetDate(date
);
94 set_real_time_clock(dateTime
.Time_t());
99 TTimeBaseView::_SendNotices()
101 fMessage
.MakeEmpty();
103 BDate date
= BDate::CurrentDate(B_LOCAL_TIME
);
104 fMessage
.AddInt32("day", date
.Day());
105 fMessage
.AddInt32("year", date
.Year());
106 fMessage
.AddInt32("month", date
.Month());
108 BTime time
= BTime::CurrentTime(B_LOCAL_TIME
);
109 fMessage
.AddInt32("hour", time
.Hour());
110 fMessage
.AddInt32("minute", time
.Minute());
111 fMessage
.AddInt32("second", time
.Second());
113 SendNotices(H_TM_CHANGED
, &fMessage
);