1 | /* $Id: UIMachineSettingsSerial.cpp 103771 2024-03-11 15:16:04Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIMachineSettingsSerial class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #include <QVBoxLayout>
|
---|
30 |
|
---|
31 | /* GUI includes: */
|
---|
32 | #include "QITabWidget.h"
|
---|
33 | #include "UIErrorString.h"
|
---|
34 | #include "UIGlobalSession.h"
|
---|
35 | #include "UIMachineSettingsSerial.h"
|
---|
36 | #include "UISerialSettingsEditor.h"
|
---|
37 | #include "UITranslator.h"
|
---|
38 |
|
---|
39 | /* COM includes: */
|
---|
40 | #include "CPlatformProperties.h"
|
---|
41 | #include "CSerialPort.h"
|
---|
42 |
|
---|
43 |
|
---|
44 | /** Machine settings: Serial Port tab data structure. */
|
---|
45 | struct UIDataSettingsMachineSerialPort
|
---|
46 | {
|
---|
47 | /** Constructs data. */
|
---|
48 | UIDataSettingsMachineSerialPort()
|
---|
49 | : m_iSlot(-1)
|
---|
50 | , m_fPortEnabled(false)
|
---|
51 | , m_uIRQ(0)
|
---|
52 | , m_uIOAddress(0)
|
---|
53 | , m_hostMode(KPortMode_Disconnected)
|
---|
54 | , m_fServer(false)
|
---|
55 | , m_strPath(QString())
|
---|
56 | {}
|
---|
57 |
|
---|
58 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
59 | bool equal(const UIDataSettingsMachineSerialPort &other) const
|
---|
60 | {
|
---|
61 | return true
|
---|
62 | && (m_iSlot == other.m_iSlot)
|
---|
63 | && (m_fPortEnabled == other.m_fPortEnabled)
|
---|
64 | && (m_uIRQ == other.m_uIRQ)
|
---|
65 | && (m_uIOAddress == other.m_uIOAddress)
|
---|
66 | && (m_hostMode == other.m_hostMode)
|
---|
67 | && (m_fServer == other.m_fServer)
|
---|
68 | && (m_strPath == other.m_strPath)
|
---|
69 | ;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
73 | bool operator==(const UIDataSettingsMachineSerialPort &other) const { return equal(other); }
|
---|
74 | /** Returns whether the @a other passed data is different from this one. */
|
---|
75 | bool operator!=(const UIDataSettingsMachineSerialPort &other) const { return !equal(other); }
|
---|
76 |
|
---|
77 | /** Holds the serial port slot number. */
|
---|
78 | int m_iSlot;
|
---|
79 | /** Holds whether the serial port is enabled. */
|
---|
80 | bool m_fPortEnabled;
|
---|
81 | /** Holds the serial port IRQ. */
|
---|
82 | ulong m_uIRQ;
|
---|
83 | /** Holds the serial port IO address. */
|
---|
84 | ulong m_uIOAddress;
|
---|
85 | /** Holds the serial port host mode. */
|
---|
86 | KPortMode m_hostMode;
|
---|
87 | /** Holds whether the serial port is server. */
|
---|
88 | bool m_fServer;
|
---|
89 | /** Holds the serial port path. */
|
---|
90 | QString m_strPath;
|
---|
91 | };
|
---|
92 |
|
---|
93 |
|
---|
94 | /** Machine settings: Serial page data structure. */
|
---|
95 | struct UIDataSettingsMachineSerial
|
---|
96 | {
|
---|
97 | /** Constructs data. */
|
---|
98 | UIDataSettingsMachineSerial() {}
|
---|
99 |
|
---|
100 | /** Returns whether the @a other passed data is equal to this one. */
|
---|
101 | bool operator==(const UIDataSettingsMachineSerial & /* other */) const { return true; }
|
---|
102 | /** Returns whether the @a other passed data is different from this one. */
|
---|
103 | bool operator!=(const UIDataSettingsMachineSerial & /* other */) const { return false; }
|
---|
104 | };
|
---|
105 |
|
---|
106 |
|
---|
107 | /*********************************************************************************************************************************
|
---|
108 | * Class UIMachineSettingsSerial implementation. *
|
---|
109 | *********************************************************************************************************************************/
|
---|
110 |
|
---|
111 | UIMachineSettingsSerial::UIMachineSettingsSerial()
|
---|
112 | : m_pCache(0)
|
---|
113 | , m_pTabWidget(0)
|
---|
114 | {
|
---|
115 | prepare();
|
---|
116 | }
|
---|
117 |
|
---|
118 | UIMachineSettingsSerial::~UIMachineSettingsSerial()
|
---|
119 | {
|
---|
120 | cleanup();
|
---|
121 | }
|
---|
122 |
|
---|
123 | bool UIMachineSettingsSerial::changed() const
|
---|
124 | {
|
---|
125 | return m_pCache ? m_pCache->wasChanged() : false;
|
---|
126 | }
|
---|
127 |
|
---|
128 | void UIMachineSettingsSerial::loadToCacheFrom(QVariant &data)
|
---|
129 | {
|
---|
130 | /* Sanity check: */
|
---|
131 | if ( !m_pCache
|
---|
132 | || !m_pTabWidget)
|
---|
133 | return;
|
---|
134 |
|
---|
135 | /* Fetch data to machine: */
|
---|
136 | UISettingsPageMachine::fetchData(data);
|
---|
137 |
|
---|
138 | /* Clear cache initially: */
|
---|
139 | m_pCache->clear();
|
---|
140 |
|
---|
141 | /* Cache lists: */
|
---|
142 | refreshPorts();
|
---|
143 | refreshPaths();
|
---|
144 |
|
---|
145 | /* Prepare old data: */
|
---|
146 | UIDataSettingsMachineSerial oldSerialData;
|
---|
147 |
|
---|
148 | /* For each serial port: */
|
---|
149 | for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
150 | {
|
---|
151 | /* Prepare old data: */
|
---|
152 | UIDataSettingsMachineSerialPort oldPortData;
|
---|
153 |
|
---|
154 | /* Check whether port is valid: */
|
---|
155 | const CSerialPort &comPort = m_machine.GetSerialPort(iSlot);
|
---|
156 | if (!comPort.isNull())
|
---|
157 | {
|
---|
158 | /* Gather old data: */
|
---|
159 | oldPortData.m_iSlot = iSlot;
|
---|
160 | oldPortData.m_fPortEnabled = comPort.GetEnabled();
|
---|
161 | oldPortData.m_uIRQ = comPort.GetIRQ();
|
---|
162 | oldPortData.m_uIOAddress = comPort.GetIOAddress();
|
---|
163 | oldPortData.m_hostMode = comPort.GetHostMode();
|
---|
164 | oldPortData.m_fServer = comPort.GetServer();
|
---|
165 | oldPortData.m_strPath = comPort.GetPath();
|
---|
166 | }
|
---|
167 |
|
---|
168 | /* Cache old data: */
|
---|
169 | m_pCache->child(iSlot).cacheInitialData(oldPortData);
|
---|
170 | }
|
---|
171 |
|
---|
172 | /* Cache old data: */
|
---|
173 | m_pCache->cacheInitialData(oldSerialData);
|
---|
174 |
|
---|
175 | /* Upload machine to data: */
|
---|
176 | UISettingsPageMachine::uploadData(data);
|
---|
177 | }
|
---|
178 |
|
---|
179 | void UIMachineSettingsSerial::getFromCache()
|
---|
180 | {
|
---|
181 | /* Sanity check: */
|
---|
182 | if ( !m_pCache
|
---|
183 | || !m_pTabWidget)
|
---|
184 | return;
|
---|
185 |
|
---|
186 | /* Load old data from cache: */
|
---|
187 | for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
188 | getFromCache(iSlot, m_pCache->child(iSlot));
|
---|
189 |
|
---|
190 | /* Apply language settings: */
|
---|
191 | retranslateUi();
|
---|
192 |
|
---|
193 | /* Polish page finally: */
|
---|
194 | polishPage();
|
---|
195 |
|
---|
196 | /* Revalidate: */
|
---|
197 | revalidate();
|
---|
198 | }
|
---|
199 |
|
---|
200 | void UIMachineSettingsSerial::putToCache()
|
---|
201 | {
|
---|
202 | /* Sanity check: */
|
---|
203 | if ( !m_pCache
|
---|
204 | || !m_pTabWidget)
|
---|
205 | return;
|
---|
206 |
|
---|
207 | /* Prepare new data: */
|
---|
208 | UIDataSettingsMachineSerial newSerialData;
|
---|
209 |
|
---|
210 | /* Gather new data to cache: */
|
---|
211 | for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
212 | putToCache(iSlot, m_pCache->child(iSlot));
|
---|
213 |
|
---|
214 | /* Cache new data: */
|
---|
215 | m_pCache->cacheCurrentData(newSerialData);
|
---|
216 | }
|
---|
217 |
|
---|
218 | void UIMachineSettingsSerial::saveFromCacheTo(QVariant &data)
|
---|
219 | {
|
---|
220 | /* Fetch data to machine: */
|
---|
221 | UISettingsPageMachine::fetchData(data);
|
---|
222 |
|
---|
223 | /* Update data and failing state: */
|
---|
224 | setFailed(!saveData());
|
---|
225 |
|
---|
226 | /* Upload machine to data: */
|
---|
227 | UISettingsPageMachine::uploadData(data);
|
---|
228 | }
|
---|
229 |
|
---|
230 | bool UIMachineSettingsSerial::validate(QList<UIValidationMessage> &messages)
|
---|
231 | {
|
---|
232 | /* Sanity check: */
|
---|
233 | if (!m_pTabWidget)
|
---|
234 | return false;
|
---|
235 |
|
---|
236 | /* Pass by default: */
|
---|
237 | bool fValid = true;
|
---|
238 |
|
---|
239 | /* Delegate validation to adapter tabs: */
|
---|
240 | for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
241 | if (!validate(iSlot, messages))
|
---|
242 | fValid = false;
|
---|
243 |
|
---|
244 | /* Return result: */
|
---|
245 | return fValid;
|
---|
246 | }
|
---|
247 |
|
---|
248 | void UIMachineSettingsSerial::retranslateUi()
|
---|
249 | {
|
---|
250 | /* Sanity check: */
|
---|
251 | if (!m_pTabWidget)
|
---|
252 | return;
|
---|
253 |
|
---|
254 | for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
255 | m_pTabWidget->setTabText(iSlot, tabTitle(iSlot));
|
---|
256 | }
|
---|
257 |
|
---|
258 | void UIMachineSettingsSerial::polishPage()
|
---|
259 | {
|
---|
260 | /* Sanity check: */
|
---|
261 | if ( !m_pCache
|
---|
262 | || !m_pTabWidget)
|
---|
263 | return;
|
---|
264 |
|
---|
265 | for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
266 | {
|
---|
267 | m_pTabWidget->setTabEnabled(iSlot,
|
---|
268 | isMachineOffline() ||
|
---|
269 | (isMachineInValidMode() &&
|
---|
270 | m_pCache->childCount() > iSlot &&
|
---|
271 | m_pCache->child(iSlot).base().m_fPortEnabled));
|
---|
272 | polishTab(iSlot);
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | void UIMachineSettingsSerial::sltHandlePortChange()
|
---|
277 | {
|
---|
278 | refreshPorts();
|
---|
279 | revalidate();
|
---|
280 | }
|
---|
281 |
|
---|
282 | void UIMachineSettingsSerial::sltHandlePathChange()
|
---|
283 | {
|
---|
284 | refreshPaths();
|
---|
285 | revalidate();
|
---|
286 | }
|
---|
287 |
|
---|
288 | void UIMachineSettingsSerial::prepare()
|
---|
289 | {
|
---|
290 | /* Prepare cache: */
|
---|
291 | m_pCache = new UISettingsCacheMachineSerial;
|
---|
292 | AssertPtrReturnVoid(m_pCache);
|
---|
293 |
|
---|
294 | /* Prepare everything: */
|
---|
295 | prepareWidgets();
|
---|
296 |
|
---|
297 | /* Apply language settings: */
|
---|
298 | retranslateUi();
|
---|
299 | }
|
---|
300 |
|
---|
301 | void UIMachineSettingsSerial::prepareWidgets()
|
---|
302 | {
|
---|
303 | /* Prepare main layout: */
|
---|
304 | QVBoxLayout *pLayoutMain = new QVBoxLayout(this);
|
---|
305 | if (pLayoutMain)
|
---|
306 | {
|
---|
307 | /* Prepare tab-widget: */
|
---|
308 | m_pTabWidget = new QITabWidget(this);
|
---|
309 | if (m_pTabWidget)
|
---|
310 | {
|
---|
311 | /* How many ports to display: */
|
---|
312 | const ulong uCount = gpGlobalSession->virtualBox().GetPlatformProperties(KPlatformArchitecture_x86).GetSerialPortCount();
|
---|
313 |
|
---|
314 | /* Create corresponding port tabs: */
|
---|
315 | for (ulong uSlot = 0; uSlot < uCount; ++uSlot)
|
---|
316 | prepareTab();
|
---|
317 |
|
---|
318 | pLayoutMain->addWidget(m_pTabWidget);
|
---|
319 | }
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 | void UIMachineSettingsSerial::prepareTab()
|
---|
324 | {
|
---|
325 | /* Prepare tab: */
|
---|
326 | UIEditor *pTab = new UIEditor(m_pTabWidget);
|
---|
327 | if (pTab)
|
---|
328 | {
|
---|
329 | /* Prepare tab layout: */
|
---|
330 | QVBoxLayout *pLayout = new QVBoxLayout(pTab);
|
---|
331 | if (pLayout)
|
---|
332 | {
|
---|
333 | #ifdef VBOX_WS_MAC
|
---|
334 | /* On Mac OS X we can do a bit of smoothness: */
|
---|
335 | int iLeft, iTop, iRight, iBottom;
|
---|
336 | pLayout->getContentsMargins(&iLeft, &iTop, &iRight, &iBottom);
|
---|
337 | pLayout->setContentsMargins(iLeft / 2, iTop / 2, iRight / 2, iBottom / 2);
|
---|
338 | #endif
|
---|
339 |
|
---|
340 | /* Create port tab-editor: */
|
---|
341 | UISerialSettingsEditor *pEditor = new UISerialSettingsEditor(this);
|
---|
342 | if (pEditor)
|
---|
343 | {
|
---|
344 | m_tabEditors << pEditor;
|
---|
345 | prepareConnections(pEditor);
|
---|
346 | pTab->addEditor(pEditor);
|
---|
347 | pLayout->addWidget(pEditor);
|
---|
348 | }
|
---|
349 |
|
---|
350 | pLayout->addStretch();
|
---|
351 | }
|
---|
352 |
|
---|
353 | addEditor(pTab);
|
---|
354 | m_pTabWidget->addTab(pTab, QString());
|
---|
355 | }
|
---|
356 | }
|
---|
357 |
|
---|
358 | void UIMachineSettingsSerial::prepareConnections(UISerialSettingsEditor *pTabEditor)
|
---|
359 | {
|
---|
360 | /* Tab connections: */
|
---|
361 | connect(pTabEditor, &UISerialSettingsEditor::sigPortAvailabilityChanged,
|
---|
362 | this, &UIMachineSettingsSerial::sltHandlePortChange);
|
---|
363 | connect(pTabEditor, &UISerialSettingsEditor::sigPortAvailabilityChanged,
|
---|
364 | this, &UIMachineSettingsSerial::sltHandlePathChange);
|
---|
365 | connect(pTabEditor, &UISerialSettingsEditor::sigStandardPortOptionChanged,
|
---|
366 | this, &UIMachineSettingsSerial::revalidate);
|
---|
367 | connect(pTabEditor, &UISerialSettingsEditor::sigPortIRQChanged,
|
---|
368 | this, &UIMachineSettingsSerial::sltHandlePortChange);
|
---|
369 | connect(pTabEditor, &UISerialSettingsEditor::sigPortIOAddressChanged,
|
---|
370 | this, &UIMachineSettingsSerial::sltHandlePortChange);
|
---|
371 | connect(pTabEditor, &UISerialSettingsEditor::sigModeChanged,
|
---|
372 | this, &UIMachineSettingsSerial::revalidate);
|
---|
373 | connect(pTabEditor, &UISerialSettingsEditor::sigPathChanged,
|
---|
374 | this, &UIMachineSettingsSerial::sltHandlePathChange);
|
---|
375 | }
|
---|
376 |
|
---|
377 | void UIMachineSettingsSerial::cleanup()
|
---|
378 | {
|
---|
379 | /* Cleanup cache: */
|
---|
380 | delete m_pCache;
|
---|
381 | m_pCache = 0;
|
---|
382 | }
|
---|
383 |
|
---|
384 | void UIMachineSettingsSerial::polishTab(int iSlot)
|
---|
385 | {
|
---|
386 | /* Acquire tab-editor: */
|
---|
387 | UISerialSettingsEditor *pTabEditor = m_tabEditors.at(iSlot);
|
---|
388 | AssertPtrReturnVoid(pTabEditor);
|
---|
389 |
|
---|
390 | /* Polish port page: */
|
---|
391 | const bool fStd = pTabEditor->isPortStandardOne();
|
---|
392 | const KPortMode enmMode = pTabEditor->hostMode();
|
---|
393 | pTabEditor->setPortOptionsAvailable(isMachineOffline());
|
---|
394 | pTabEditor->setIRQAndIOAddressOptionsAvailable(!fStd && isMachineOffline());
|
---|
395 | pTabEditor->setHostModeOptionsAvailable(isMachineOffline());
|
---|
396 | pTabEditor->setPipeOptionsAvailable( (enmMode == KPortMode_HostPipe || enmMode == KPortMode_TCP)
|
---|
397 | && isMachineOffline());
|
---|
398 | pTabEditor->setPathOptionsAvailable( enmMode != KPortMode_Disconnected
|
---|
399 | && isMachineOffline());
|
---|
400 | }
|
---|
401 |
|
---|
402 | void UIMachineSettingsSerial::getFromCache(int iSlot, const UISettingsCacheMachineSerialPort &portCache)
|
---|
403 | {
|
---|
404 | /* Acquire tab-editor: */
|
---|
405 | UISerialSettingsEditor *pTabEditor = m_tabEditors.at(iSlot);
|
---|
406 | AssertPtrReturnVoid(pTabEditor);
|
---|
407 |
|
---|
408 | /* Get old data: */
|
---|
409 | const UIDataSettingsMachineSerialPort &oldPortData = portCache.base();
|
---|
410 |
|
---|
411 | /* Load port data: */
|
---|
412 | pTabEditor->setPortByIRQAndIOAddress(oldPortData.m_uIRQ, oldPortData.m_uIOAddress);
|
---|
413 | pTabEditor->setIRQ(oldPortData.m_uIRQ);
|
---|
414 | pTabEditor->setIOAddress(oldPortData.m_uIOAddress);
|
---|
415 | pTabEditor->setHostMode(oldPortData.m_hostMode);
|
---|
416 | pTabEditor->setServerEnabled(oldPortData.m_fServer);
|
---|
417 | pTabEditor->setPath(oldPortData.m_strPath);
|
---|
418 | // Should be done in th end to finalize availability:
|
---|
419 | pTabEditor->setPortEnabled(oldPortData.m_fPortEnabled);
|
---|
420 | }
|
---|
421 |
|
---|
422 | void UIMachineSettingsSerial::putToCache(int iSlot, UISettingsCacheMachineSerialPort &portCache)
|
---|
423 | {
|
---|
424 | /* Acquire tab-editor: */
|
---|
425 | UISerialSettingsEditor *pTabEditor = m_tabEditors.at(iSlot);
|
---|
426 | AssertPtrReturnVoid(pTabEditor);
|
---|
427 |
|
---|
428 | /* Prepare new data: */
|
---|
429 | UIDataSettingsMachineSerialPort newPortData;
|
---|
430 |
|
---|
431 | /* Save port number: */
|
---|
432 | newPortData.m_iSlot = iSlot;
|
---|
433 |
|
---|
434 | /* Save port data: */
|
---|
435 | newPortData.m_fPortEnabled = pTabEditor->isPortEnabled();
|
---|
436 | newPortData.m_uIRQ = pTabEditor->irq();
|
---|
437 | newPortData.m_uIOAddress = pTabEditor->ioAddress();
|
---|
438 | newPortData.m_fServer = pTabEditor->isServerEnabled();
|
---|
439 | newPortData.m_hostMode = pTabEditor->hostMode();
|
---|
440 | newPortData.m_strPath = pTabEditor->path();
|
---|
441 |
|
---|
442 | /* Cache new data: */
|
---|
443 | portCache.cacheCurrentData(newPortData);
|
---|
444 | }
|
---|
445 |
|
---|
446 | QString UIMachineSettingsSerial::irq(int iSlot) const
|
---|
447 | {
|
---|
448 | /* Acquire tab-editor: */
|
---|
449 | UISerialSettingsEditor *pTabEditor = m_tabEditors.at(iSlot);
|
---|
450 | AssertPtrReturn(pTabEditor, QString());
|
---|
451 | return QString::number(pTabEditor->irq());
|
---|
452 | }
|
---|
453 |
|
---|
454 | QString UIMachineSettingsSerial::ioAddress(int iSlot) const
|
---|
455 | {
|
---|
456 | /* Acquire tab-editor: */
|
---|
457 | UISerialSettingsEditor *pTabEditor = m_tabEditors.at(iSlot);
|
---|
458 | AssertPtrReturn(pTabEditor, QString());
|
---|
459 | return QString::number(pTabEditor->ioAddress());
|
---|
460 | }
|
---|
461 |
|
---|
462 | bool UIMachineSettingsSerial::validate(int iSlot, QList<UIValidationMessage> &messages)
|
---|
463 | {
|
---|
464 | /* Acquire tab-editor: */
|
---|
465 | UISerialSettingsEditor *pTabEditor = m_tabEditors.at(iSlot);
|
---|
466 | AssertPtrReturn(pTabEditor, false);
|
---|
467 |
|
---|
468 | /* Pass by default: */
|
---|
469 | bool fPass = true;
|
---|
470 |
|
---|
471 | /* Prepare message: */
|
---|
472 | UIValidationMessage message;
|
---|
473 | message.first = UITranslator::removeAccelMark(tabTitle(iSlot));
|
---|
474 |
|
---|
475 | /* Validate enabled port only: */
|
---|
476 | if (pTabEditor->isPortEnabled())
|
---|
477 | {
|
---|
478 | /* Check the port attribute emptiness & uniqueness: */
|
---|
479 | const QString strIRQ = irq(iSlot);
|
---|
480 | const QString strIOAddress = ioAddress(iSlot);
|
---|
481 | const QPair<QString, QString> port = qMakePair(strIRQ, strIOAddress);
|
---|
482 |
|
---|
483 | if (strIRQ.isEmpty())
|
---|
484 | {
|
---|
485 | message.second << tr("No IRQ is currently specified.");
|
---|
486 | fPass = false;
|
---|
487 | }
|
---|
488 | if (strIOAddress.isEmpty())
|
---|
489 | {
|
---|
490 | message.second << tr("No I/O port is currently specified.");
|
---|
491 | fPass = false;
|
---|
492 | }
|
---|
493 | if ( !strIRQ.isEmpty()
|
---|
494 | && !strIOAddress.isEmpty())
|
---|
495 | {
|
---|
496 | QVector<QPair<QString, QString> > currentPorts;
|
---|
497 | currentPorts = ports();
|
---|
498 | currentPorts.removeAt(iSlot);
|
---|
499 | if (currentPorts.contains(port))
|
---|
500 | {
|
---|
501 | message.second << tr("Two or more ports have the same settings.");
|
---|
502 | fPass = false;
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | const KPortMode enmMode = pTabEditor->hostMode();
|
---|
507 | if (enmMode != KPortMode_Disconnected)
|
---|
508 | {
|
---|
509 | const QString strPath = pTabEditor->path();
|
---|
510 |
|
---|
511 | if (strPath.isEmpty())
|
---|
512 | {
|
---|
513 | message.second << tr("No port path is currently specified.");
|
---|
514 | fPass = false;
|
---|
515 | }
|
---|
516 | else
|
---|
517 | {
|
---|
518 | QVector<QString> currentPaths;
|
---|
519 | currentPaths = paths();
|
---|
520 | currentPaths.removeAt(iSlot);
|
---|
521 | if (currentPaths.contains(strPath))
|
---|
522 | {
|
---|
523 | message.second << tr("There are currently duplicate port paths specified.");
|
---|
524 | fPass = false;
|
---|
525 | }
|
---|
526 | }
|
---|
527 | }
|
---|
528 | }
|
---|
529 |
|
---|
530 | /* Serialize message: */
|
---|
531 | if (!message.second.isEmpty())
|
---|
532 | messages << message;
|
---|
533 |
|
---|
534 | /* Return result: */
|
---|
535 | return fPass;
|
---|
536 | }
|
---|
537 |
|
---|
538 | void UIMachineSettingsSerial::refreshPorts()
|
---|
539 | {
|
---|
540 | /* Sanity check: */
|
---|
541 | if (!m_pTabWidget)
|
---|
542 | return;
|
---|
543 |
|
---|
544 | /* Reload port list: */
|
---|
545 | m_ports.clear();
|
---|
546 | m_ports.resize(m_pTabWidget->count());
|
---|
547 | /* Append port list with data from all the tabs: */
|
---|
548 | for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
549 | {
|
---|
550 | UISerialSettingsEditor *pTabEditor = m_tabEditors.at(iSlot);
|
---|
551 | AssertPtrReturnVoid(pTabEditor);
|
---|
552 | m_ports[iSlot] = pTabEditor->isPortEnabled() ? qMakePair(irq(iSlot), ioAddress(iSlot)) : qMakePair(QString(), QString());
|
---|
553 | }
|
---|
554 | }
|
---|
555 |
|
---|
556 | void UIMachineSettingsSerial::refreshPaths()
|
---|
557 | {
|
---|
558 | /* Sanity check: */
|
---|
559 | if (!m_pTabWidget)
|
---|
560 | return;
|
---|
561 |
|
---|
562 | /* Reload path list: */
|
---|
563 | m_paths.clear();
|
---|
564 | m_paths.resize(m_pTabWidget->count());
|
---|
565 | /* Append path list with data from all the tabs: */
|
---|
566 | for (int iSlot = 0; iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
567 | {
|
---|
568 | UISerialSettingsEditor *pTabEditor = m_tabEditors.at(iSlot);
|
---|
569 | AssertPtrReturnVoid(pTabEditor);
|
---|
570 | m_paths[iSlot] = pTabEditor->isPortEnabled() ? pTabEditor->path() : QString();
|
---|
571 | }
|
---|
572 | }
|
---|
573 |
|
---|
574 | /* static */
|
---|
575 | QString UIMachineSettingsSerial::tabTitle(int iSlot)
|
---|
576 | {
|
---|
577 | return QString(tr("Port %1", "serial ports")).arg(QString("&%1").arg(iSlot + 1));
|
---|
578 | }
|
---|
579 |
|
---|
580 | bool UIMachineSettingsSerial::saveData()
|
---|
581 | {
|
---|
582 | /* Sanity check: */
|
---|
583 | if ( !m_pCache
|
---|
584 | || !m_pTabWidget)
|
---|
585 | return false;
|
---|
586 |
|
---|
587 | /* Prepare result: */
|
---|
588 | bool fSuccess = true;
|
---|
589 | /* Save serial settings from cache: */
|
---|
590 | if (fSuccess && isMachineInValidMode() && m_pCache->wasChanged())
|
---|
591 | {
|
---|
592 | /* For each port: */
|
---|
593 | for (int iSlot = 0; fSuccess && iSlot < m_pTabWidget->count(); ++iSlot)
|
---|
594 | fSuccess = savePortData(iSlot);
|
---|
595 | }
|
---|
596 | /* Return result: */
|
---|
597 | return fSuccess;
|
---|
598 | }
|
---|
599 |
|
---|
600 | bool UIMachineSettingsSerial::savePortData(int iSlot)
|
---|
601 | {
|
---|
602 | /* Sanity check: */
|
---|
603 | if (!m_pCache)
|
---|
604 | return false;
|
---|
605 |
|
---|
606 | /* Prepare result: */
|
---|
607 | bool fSuccess = true;
|
---|
608 | /* Save adapter settings from cache: */
|
---|
609 | if (fSuccess && m_pCache->child(iSlot).wasChanged())
|
---|
610 | {
|
---|
611 | /* Get old data from cache: */
|
---|
612 | const UIDataSettingsMachineSerialPort &oldPortData = m_pCache->child(iSlot).base();
|
---|
613 | /* Get new data from cache: */
|
---|
614 | const UIDataSettingsMachineSerialPort &newPortData = m_pCache->child(iSlot).data();
|
---|
615 |
|
---|
616 | /* Get serial port for further activities: */
|
---|
617 | CSerialPort comPort = m_machine.GetSerialPort(iSlot);
|
---|
618 | fSuccess = m_machine.isOk() && comPort.isNotNull();
|
---|
619 |
|
---|
620 | /* Show error message if necessary: */
|
---|
621 | if (!fSuccess)
|
---|
622 | notifyOperationProgressError(UIErrorString::formatErrorInfo(m_machine));
|
---|
623 | else
|
---|
624 | {
|
---|
625 | // This *must* be first.
|
---|
626 | // If the requested host mode is changed to disconnected we should do it first.
|
---|
627 | // That allows to automatically fulfill the requirements for some of the settings below.
|
---|
628 | /* Save port host mode: */
|
---|
629 | if ( fSuccess && isMachineOffline()
|
---|
630 | && newPortData.m_hostMode != oldPortData.m_hostMode
|
---|
631 | && newPortData.m_hostMode == KPortMode_Disconnected)
|
---|
632 | {
|
---|
633 | comPort.SetHostMode(newPortData.m_hostMode);
|
---|
634 | fSuccess = comPort.isOk();
|
---|
635 | }
|
---|
636 | /* Save whether the port is enabled: */
|
---|
637 | if (fSuccess && isMachineOffline() && newPortData.m_fPortEnabled != oldPortData.m_fPortEnabled)
|
---|
638 | {
|
---|
639 | comPort.SetEnabled(newPortData.m_fPortEnabled);
|
---|
640 | fSuccess = comPort.isOk();
|
---|
641 | }
|
---|
642 | /* Save port IRQ: */
|
---|
643 | if (fSuccess && isMachineOffline() && newPortData.m_uIRQ != oldPortData.m_uIRQ)
|
---|
644 | {
|
---|
645 | comPort.SetIRQ(newPortData.m_uIRQ);
|
---|
646 | fSuccess = comPort.isOk();
|
---|
647 | }
|
---|
648 | /* Save port IO address: */
|
---|
649 | if (fSuccess && isMachineOffline() && newPortData.m_uIOAddress != oldPortData.m_uIOAddress)
|
---|
650 | {
|
---|
651 | comPort.SetIOAddress(newPortData.m_uIOAddress);
|
---|
652 | fSuccess = comPort.isOk();
|
---|
653 | }
|
---|
654 | /* Save whether the port is server: */
|
---|
655 | if (fSuccess && isMachineOffline() && newPortData.m_fServer != oldPortData.m_fServer)
|
---|
656 | {
|
---|
657 | comPort.SetServer(newPortData.m_fServer);
|
---|
658 | fSuccess = comPort.isOk();
|
---|
659 | }
|
---|
660 | /* Save port path: */
|
---|
661 | if (fSuccess && isMachineOffline() && newPortData.m_strPath != oldPortData.m_strPath)
|
---|
662 | {
|
---|
663 | comPort.SetPath(newPortData.m_strPath);
|
---|
664 | fSuccess = comPort.isOk();
|
---|
665 | }
|
---|
666 | // This *must* be last.
|
---|
667 | // The host mode will be changed to disconnected if some of the necessary
|
---|
668 | // settings above will not meet the requirements for the selected mode.
|
---|
669 | /* Save port host mode: */
|
---|
670 | if ( fSuccess && isMachineOffline()
|
---|
671 | && newPortData.m_hostMode != oldPortData.m_hostMode
|
---|
672 | && newPortData.m_hostMode != KPortMode_Disconnected)
|
---|
673 | {
|
---|
674 | comPort.SetHostMode(newPortData.m_hostMode);
|
---|
675 | fSuccess = comPort.isOk();
|
---|
676 | }
|
---|
677 |
|
---|
678 | /* Show error message if necessary: */
|
---|
679 | if (!fSuccess)
|
---|
680 | notifyOperationProgressError(UIErrorString::formatErrorInfo(comPort));
|
---|
681 | }
|
---|
682 | }
|
---|
683 | /* Return result: */
|
---|
684 | return fSuccess;
|
---|
685 | }
|
---|