2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Andrew McCall <mccall@@digitalparadise.co.uk>
7 * Julun <host.haiku@gmx.de>
8 * Hamish Morrison <hamish@lavabit.com>
11 #include "TimeWindow.h"
13 #include <Application.h>
16 #include <LayoutBuilder.h>
22 #include "ClockView.h"
23 #include "DateTimeView.h"
24 #include "NetworkTimeView.h"
25 #include "TimeMessages.h"
26 #include "TimeSettings.h"
30 #undef B_TRANSLATION_CONTEXT
31 #define B_TRANSLATION_CONTEXT "Time"
33 TTimeWindow::TTimeWindow()
35 BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Time"), B_TITLED_WINDOW
,
36 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS
)
41 AddShortcut('A', B_COMMAND_KEY
, new BMessage(B_ABOUT_REQUESTED
));
45 TTimeWindow::~TTimeWindow()
51 TTimeWindow::QuitRequested()
53 TimeSettings().SetLeftTop(Frame().LeftTop());
55 fBaseView
->StopWatchingAll(fTimeZoneView
);
56 fBaseView
->StopWatchingAll(fDateTimeView
);
58 be_app
->PostMessage(B_QUIT_REQUESTED
);
60 return BWindow::QuitRequested();
65 TTimeWindow::MessageReceived(BMessage
* message
)
67 switch(message
->what
) {
69 fBaseView
->ChangeTime(message
);
70 // To make sure no old time message is in the queue
71 _SendTimeChangeFinished();
75 case B_ABOUT_REQUESTED
:
76 be_app
->PostMessage(B_ABOUT_REQUESTED
);
80 fDateTimeView
->MessageReceived(message
);
81 fTimeZoneView
->MessageReceived(message
);
82 fNetworkTimeView
->MessageReceived(message
);
83 fClockView
->MessageReceived(message
);
84 fRevertButton
->SetEnabled(false);
88 fDateTimeView
->MessageReceived(message
);
89 fTimeZoneView
->MessageReceived(message
);
98 // focus the clock tab (last one)
99 fTabView
->Select(fTabView
->CountTabs() - 1);
103 fClockView
->MessageReceived(message
);
107 BWindow::MessageReceived(message
);
114 TTimeWindow::_InitWindow()
116 SetPulseRate(500000);
118 fDateTimeView
= new DateTimeView(B_TRANSLATE("Date and time"));
119 fTimeZoneView
= new TimeZoneView(B_TRANSLATE("Time zone"));
120 fNetworkTimeView
= new NetworkTimeView(B_TRANSLATE("Network time"));
121 fClockView
= new ClockView(B_TRANSLATE("Clock"));
123 fBaseView
= new TTimeBaseView("baseView");
124 fBaseView
->StartWatchingAll(fDateTimeView
);
125 fBaseView
->StartWatchingAll(fTimeZoneView
);
127 fTabView
= new BTabView("tabView", B_WIDTH_FROM_WIDEST
);
128 fTabView
->AddTab(fDateTimeView
);
129 fTabView
->AddTab(fTimeZoneView
);
130 fTabView
->AddTab(fNetworkTimeView
);
131 fTabView
->AddTab(fClockView
);
133 fBaseView
->AddChild(fTabView
);
135 fRevertButton
= new BButton("revert", B_TRANSLATE("Revert"),
136 new BMessage(kMsgRevert
));
137 fRevertButton
->SetEnabled(false);
138 fRevertButton
->SetTarget(this);
139 fRevertButton
->SetExplicitAlignment(
140 BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
142 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
143 .SetInsets(B_USE_DEFAULT_SPACING
)
150 TTimeWindow::_AlignWindow()
152 BPoint pt
= TimeSettings().LeftTop();
155 BRect frame
= Frame();
156 BRect screen
= BScreen().Frame();
157 if (!frame
.Intersects(screen
.InsetByCopy(50.0, 50.0))) {
158 BRect
bounds(Bounds());
159 BPoint
leftTop((screen
.Width() - bounds
.Width()) / 2.0,
160 (screen
.Height() - bounds
.Height()) / 2.0);
168 TTimeWindow::_SendTimeChangeFinished()
170 BMessenger
messenger(fDateTimeView
);
171 BMessage
msg(kChangeTimeFinished
);
172 messenger
.SendMessage(&msg
);
177 TTimeWindow::_SetRevertStatus()
179 fRevertButton
->SetEnabled(fDateTimeView
->CheckCanRevert()
180 || fTimeZoneView
->CheckCanRevert()
181 || fNetworkTimeView
->CheckCanRevert()
182 || fClockView
->CheckCanRevert());