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>
19 #include <SeparatorView.h>
23 #include "ClockView.h"
24 #include "DateTimeView.h"
25 #include "NetworkTimeView.h"
26 #include "TimeMessages.h"
27 #include "TimeSettings.h"
31 #undef B_TRANSLATION_CONTEXT
32 #define B_TRANSLATION_CONTEXT "Time"
34 TTimeWindow::TTimeWindow()
36 BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Time"), B_TITLED_WINDOW
,
37 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS
)
42 AddShortcut('A', B_COMMAND_KEY
, new BMessage(B_ABOUT_REQUESTED
));
46 TTimeWindow::~TTimeWindow()
52 TTimeWindow::QuitRequested()
54 TimeSettings().SetLeftTop(Frame().LeftTop());
56 fBaseView
->StopWatchingAll(fTimeZoneView
);
57 fBaseView
->StopWatchingAll(fDateTimeView
);
59 be_app
->PostMessage(B_QUIT_REQUESTED
);
61 return BWindow::QuitRequested();
66 TTimeWindow::MessageReceived(BMessage
* message
)
68 switch(message
->what
) {
70 fBaseView
->ChangeTime(message
);
71 // To make sure no old time message is in the queue
72 _SendTimeChangeFinished();
76 case B_ABOUT_REQUESTED
:
77 be_app
->PostMessage(B_ABOUT_REQUESTED
);
81 fDateTimeView
->MessageReceived(message
);
82 fTimeZoneView
->MessageReceived(message
);
83 fNetworkTimeView
->MessageReceived(message
);
84 fClockView
->MessageReceived(message
);
85 fRevertButton
->SetEnabled(false);
89 fDateTimeView
->MessageReceived(message
);
90 fTimeZoneView
->MessageReceived(message
);
99 // focus the clock tab (last one)
100 fTabView
->Select(fTabView
->CountTabs() - 1);
104 fClockView
->MessageReceived(message
);
108 BWindow::MessageReceived(message
);
115 TTimeWindow::_InitWindow()
117 SetPulseRate(500000);
119 fDateTimeView
= new DateTimeView(B_TRANSLATE("Date and time"));
120 fTimeZoneView
= new TimeZoneView(B_TRANSLATE("Time zone"));
121 fNetworkTimeView
= new NetworkTimeView(B_TRANSLATE("Network time"));
122 fClockView
= new ClockView(B_TRANSLATE("Clock"));
124 fBaseView
= new TTimeBaseView("baseView");
125 fBaseView
->StartWatchingAll(fDateTimeView
);
126 fBaseView
->StartWatchingAll(fTimeZoneView
);
128 fTabView
= new BTabView("tabView", B_WIDTH_FROM_WIDEST
);
129 fTabView
->AddTab(fDateTimeView
);
130 fTabView
->AddTab(fTimeZoneView
);
131 fTabView
->AddTab(fNetworkTimeView
);
132 fTabView
->AddTab(fClockView
);
133 fTabView
->SetBorder(B_NO_BORDER
);
135 fBaseView
->AddChild(fTabView
);
137 fRevertButton
= new BButton("revert", B_TRANSLATE("Revert"),
138 new BMessage(kMsgRevert
));
139 fRevertButton
->SetEnabled(false);
140 fRevertButton
->SetTarget(this);
141 fRevertButton
->SetExplicitAlignment(
142 BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
144 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
145 .SetInsets(0, B_USE_DEFAULT_SPACING
, 0, 0)
147 .Add(new BSeparatorView(B_HORIZONTAL
))
148 .AddGroup(B_HORIZONTAL
)
150 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_DEFAULT_SPACING
,
151 B_USE_DEFAULT_SPACING
, B_USE_WINDOW_SPACING
);
156 TTimeWindow::_AlignWindow()
158 MoveTo(TimeSettings().LeftTop());
164 TTimeWindow::_SendTimeChangeFinished()
166 BMessenger
messenger(fDateTimeView
);
167 BMessage
msg(kChangeTimeFinished
);
168 messenger
.SendMessage(&msg
);
173 TTimeWindow::_SetRevertStatus()
175 fRevertButton
->SetEnabled(fDateTimeView
->CheckCanRevert()
176 || fTimeZoneView
->CheckCanRevert()
177 || fNetworkTimeView
->CheckCanRevert()
178 || fClockView
->CheckCanRevert());