Dialogs/*: add "override" and "final"
[xcsoar.git] / src / Dialogs / Device / ManageFlarmDialog.cpp
blobe22e18e7f8a4a047501fbd360ae35b95c7ec39d5
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "ManageFlarmDialog.hpp"
25 #include "FLARM/ConfigWidget.hpp"
26 #include "Dialogs/WidgetDialog.hpp"
27 #include "Widget/RowFormWidget.hpp"
28 #include "UIGlobals.hpp"
29 #include "Language/Language.hpp"
30 #include "Operation/MessageOperationEnvironment.hpp"
31 #include "Device/Driver/FLARM/Device.hpp"
32 #include "FLARM/Version.hpp"
34 class ManageFLARMWidget final
35 : public RowFormWidget, private ActionListener {
36 enum Controls {
37 Setup,
38 Reboot,
41 FlarmDevice &device;
42 const FlarmVersion version;
44 public:
45 ManageFLARMWidget(const DialogLook &look, FlarmDevice &_device,
46 const FlarmVersion &version)
47 :RowFormWidget(look), device(_device), version(version) {}
49 /* virtual methods from Widget */
50 virtual void Prepare(ContainerWindow &parent, const PixelRect &rc) override;
52 private:
53 /* virtual methods from ActionListener */
54 virtual void OnAction(int id) override;
57 void
58 ManageFLARMWidget::Prepare(ContainerWindow &parent, const PixelRect &rc)
60 if (version.available) {
61 StaticString<64> buffer;
63 if (!version.hardware_version.empty()) {
64 buffer.clear();
65 buffer.UnsafeAppendASCII(version.hardware_version.c_str());
66 AddReadOnly(_("Hardware version"), NULL, buffer.c_str());
69 if (!version.software_version.empty()) {
70 buffer.clear();
71 buffer.UnsafeAppendASCII(version.software_version.c_str());
72 AddReadOnly(_("Firmware version"), NULL, buffer.c_str());
75 if (!version.obstacle_version.empty()) {
76 buffer.clear();
77 buffer.UnsafeAppendASCII(version.obstacle_version.c_str());
78 AddReadOnly(_("Obstacle database"), NULL, buffer.c_str());
82 AddButton(_("Setup"), *this, Setup);
83 AddButton(_("Reboot"), *this, Reboot);
86 void
87 ManageFLARMWidget::OnAction(int id)
89 switch (id) {
90 case Setup:
92 FLARMConfigWidget widget(GetLook(), device);
93 DefaultWidgetDialog(UIGlobals::GetMainWindow(), GetLook(),
94 _T("FLARM"), widget);
96 break;
98 case Reboot:
100 MessageOperationEnvironment env;
101 device.Restart(env);
103 break;
107 void
108 ManageFlarmDialog(Device &device, const FlarmVersion &version)
110 WidgetDialog dialog(UIGlobals::GetDialogLook());
111 dialog.CreateAuto(UIGlobals::GetMainWindow(), _T("FLARM"),
112 new ManageFLARMWidget(UIGlobals::GetDialogLook(),
113 (FlarmDevice &)device, version));
114 dialog.AddButton(_("Close"), mrCancel);
115 dialog.ShowModal();