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>
17 #include <LocaleRoster.h>
20 #include <SeparatorView.h>
24 #include "ClockView.h"
25 #include "DateTimeView.h"
26 #include "NetworkTimeView.h"
27 #include "TimeMessages.h"
28 #include "TimeSettings.h"
32 #undef B_TRANSLATION_CONTEXT
33 #define B_TRANSLATION_CONTEXT "Time"
35 TTimeWindow::TTimeWindow()
37 BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Time"), B_TITLED_WINDOW
,
38 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
| B_AUTO_UPDATE_SIZE_LIMITS
)
43 AddShortcut('A', B_COMMAND_KEY
, new BMessage(B_ABOUT_REQUESTED
));
47 TTimeWindow::~TTimeWindow()
53 TTimeWindow::QuitRequested()
55 TimeSettings().SetLeftTop(Frame().LeftTop());
57 fBaseView
->StopWatchingAll(fTimeZoneView
);
58 fBaseView
->StopWatchingAll(fDateTimeView
);
60 be_app
->PostMessage(B_QUIT_REQUESTED
);
62 return BWindow::QuitRequested();
67 TTimeWindow::MessageReceived(BMessage
* message
)
69 switch(message
->what
) {
71 fBaseView
->ChangeTime(message
);
72 // To make sure no old time message is in the queue
73 _SendTimeChangeFinished();
77 case B_ABOUT_REQUESTED
:
78 be_app
->PostMessage(B_ABOUT_REQUESTED
);
81 case B_LOCALE_CHANGED
:
83 BLocaleRoster::Default()->Refresh();
84 fDateTimeView
->MessageReceived(message
);
89 fDateTimeView
->MessageReceived(message
);
90 fTimeZoneView
->MessageReceived(message
);
91 fNetworkTimeView
->MessageReceived(message
);
92 fClockView
->MessageReceived(message
);
93 fRevertButton
->SetEnabled(false);
97 fDateTimeView
->MessageReceived(message
);
98 fTimeZoneView
->MessageReceived(message
);
106 case kSelectClockTab
:
107 // focus the clock tab (last one)
108 fTabView
->Select(fTabView
->CountTabs() - 1);
112 fClockView
->MessageReceived(message
);
116 BWindow::MessageReceived(message
);
123 TTimeWindow::_InitWindow()
125 SetPulseRate(500000);
127 fDateTimeView
= new DateTimeView(B_TRANSLATE("Date and time"));
128 fTimeZoneView
= new TimeZoneView(B_TRANSLATE("Time zone"));
129 fNetworkTimeView
= new NetworkTimeView(B_TRANSLATE("Network time"));
130 fClockView
= new ClockView(B_TRANSLATE("Clock"));
132 fBaseView
= new TTimeBaseView("baseView");
133 fBaseView
->StartWatchingAll(fDateTimeView
);
134 fBaseView
->StartWatchingAll(fTimeZoneView
);
136 fTabView
= new BTabView("tabView", B_WIDTH_FROM_WIDEST
);
137 fTabView
->AddTab(fDateTimeView
);
138 fTabView
->AddTab(fTimeZoneView
);
139 fTabView
->AddTab(fNetworkTimeView
);
140 fTabView
->AddTab(fClockView
);
141 fTabView
->SetBorder(B_NO_BORDER
);
143 fBaseView
->AddChild(fTabView
);
145 fRevertButton
= new BButton("revert", B_TRANSLATE("Revert"),
146 new BMessage(kMsgRevert
));
147 fRevertButton
->SetEnabled(false);
148 fRevertButton
->SetTarget(this);
149 fRevertButton
->SetExplicitAlignment(
150 BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
152 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0)
153 .SetInsets(0, B_USE_DEFAULT_SPACING
, 0, 0)
155 .Add(new BSeparatorView(B_HORIZONTAL
))
156 .AddGroup(B_HORIZONTAL
)
158 .SetInsets(B_USE_WINDOW_SPACING
, B_USE_DEFAULT_SPACING
,
159 B_USE_DEFAULT_SPACING
, B_USE_WINDOW_SPACING
);
164 TTimeWindow::_AlignWindow()
166 MoveTo(TimeSettings().LeftTop());
172 TTimeWindow::_SendTimeChangeFinished()
174 BMessenger
messenger(fDateTimeView
);
175 BMessage
msg(kChangeTimeFinished
);
176 messenger
.SendMessage(&msg
);
181 TTimeWindow::_SetRevertStatus()
183 fRevertButton
->SetEnabled(fDateTimeView
->CheckCanRevert()
184 || fTimeZoneView
->CheckCanRevert()
185 || fNetworkTimeView
->CheckCanRevert()
186 || fClockView
->CheckCanRevert());