usb_ecm: Use the current configuration instead of a fixed one.
[haiku.git] / src / preferences / time / TimeWindow.cpp
blobc248628f4e0487d8e34e496dcb326d6fef965a3d
1 /*
2 * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Andrew McCall <mccall@@digitalparadise.co.uk>
7 * Julun <host.haiku@gmx.de>
8 * Hamish Morrison <hamish@lavabit.com>
9 */
11 #include "TimeWindow.h"
13 #include <Application.h>
14 #include <Button.h>
15 #include <Catalog.h>
16 #include <LayoutBuilder.h>
17 #include <Message.h>
18 #include <Screen.h>
19 #include <SeparatorView.h>
20 #include <TabView.h>
22 #include "BaseView.h"
23 #include "ClockView.h"
24 #include "DateTimeView.h"
25 #include "NetworkTimeView.h"
26 #include "TimeMessages.h"
27 #include "TimeSettings.h"
28 #include "ZoneView.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)
39 _InitWindow();
40 _AlignWindow();
42 AddShortcut('A', B_COMMAND_KEY, new BMessage(B_ABOUT_REQUESTED));
46 TTimeWindow::~TTimeWindow()
51 bool
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();
65 void
66 TTimeWindow::MessageReceived(BMessage* message)
68 switch(message->what) {
69 case H_USER_CHANGE:
70 fBaseView->ChangeTime(message);
71 // To make sure no old time message is in the queue
72 _SendTimeChangeFinished();
73 _SetRevertStatus();
74 break;
76 case B_ABOUT_REQUESTED:
77 be_app->PostMessage(B_ABOUT_REQUESTED);
78 break;
80 case kMsgRevert:
81 fDateTimeView->MessageReceived(message);
82 fTimeZoneView->MessageReceived(message);
83 fNetworkTimeView->MessageReceived(message);
84 fClockView->MessageReceived(message);
85 fRevertButton->SetEnabled(false);
86 break;
88 case kRTCUpdate:
89 fDateTimeView->MessageReceived(message);
90 fTimeZoneView->MessageReceived(message);
91 _SetRevertStatus();
92 break;
94 case kMsgChange:
95 _SetRevertStatus();
96 break;
98 case kSelectClockTab:
99 // focus the clock tab (last one)
100 fTabView->Select(fTabView->CountTabs() - 1);
101 break;
103 case kShowHideTime:
104 fClockView->MessageReceived(message);
105 break;
107 default:
108 BWindow::MessageReceived(message);
109 break;
114 void
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)
146 .Add(fBaseView)
147 .Add(new BSeparatorView(B_HORIZONTAL))
148 .AddGroup(B_HORIZONTAL)
149 .Add(fRevertButton)
150 .SetInsets(B_USE_WINDOW_SPACING, B_USE_DEFAULT_SPACING,
151 B_USE_DEFAULT_SPACING, B_USE_WINDOW_SPACING);
155 void
156 TTimeWindow::_AlignWindow()
158 MoveTo(TimeSettings().LeftTop());
159 MoveOnScreen();
163 void
164 TTimeWindow::_SendTimeChangeFinished()
166 BMessenger messenger(fDateTimeView);
167 BMessage msg(kChangeTimeFinished);
168 messenger.SendMessage(&msg);
172 void
173 TTimeWindow::_SetRevertStatus()
175 fRevertButton->SetEnabled(fDateTimeView->CheckCanRevert()
176 || fTimeZoneView->CheckCanRevert()
177 || fNetworkTimeView->CheckCanRevert()
178 || fClockView->CheckCanRevert());