VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIIndicatorsPool.cpp@ 35740

Last change on this file since 35740 was 33394, checked in by vboxsync, 14 years ago

VRDE: API changes for the VRDP server separation (build fix).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 26.3 KB
Line 
1/* $Id: UIIndicatorsPool.cpp 33394 2010-10-24 16:17:56Z vboxsync $ */
2/** @file
3 *
4 * VBox frontends: Qt GUI ("VirtualBox"):
5 * UIActionsPool class implementation
6 */
7
8/*
9 * Copyright (C) 2010 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20/* Global includes */
21#include <iprt/time.h>
22#include <QTimer>
23
24/* Local includes */
25#include "UIIndicatorsPool.h"
26#include "VBoxGlobal.h"
27#include "COMDefs.h"
28#include "UIMachineDefs.h"
29#include "QIWithRetranslateUI.h"
30
31class UIIndicatorHardDisks : public QIWithRetranslateUI<QIStateIndicator>
32{
33 Q_OBJECT;
34
35public:
36
37 UIIndicatorHardDisks(CSession &session)
38 : QIWithRetranslateUI<QIStateIndicator>()
39 , m_session(session)
40 {
41 setStateIcon(KDeviceActivity_Idle, QPixmap(":/hd_16px.png"));
42 setStateIcon(KDeviceActivity_Reading, QPixmap(":/hd_read_16px.png"));
43 setStateIcon(KDeviceActivity_Writing, QPixmap(":/hd_write_16px.png"));
44 setStateIcon(KDeviceActivity_Null, QPixmap(":/hd_disabled_16px.png"));
45
46 retranslateUi();
47 }
48
49 void retranslateUi()
50 {
51 updateAppearance();
52 }
53
54 void updateAppearance()
55 {
56 const CMachine &machine = m_session.GetMachine();
57
58 QString strToolTip = QApplication::translate("UIIndicatorsPool", "<p style='white-space:pre'><nobr>Indicates the activity "
59 "of the virtual hard disks:</nobr>%1</p>", "HDD tooltip");
60
61 QString strFullData;
62 bool fAttachmentsPresent = false;
63
64 const CStorageControllerVector &controllers = machine.GetStorageControllers();
65 foreach (const CStorageController &controller, controllers)
66 {
67 QString strAttData;
68 const CMediumAttachmentVector &attachments = machine.GetMediumAttachmentsOfController(controller.GetName());
69 foreach (const CMediumAttachment &attachment, attachments)
70 {
71 if (attachment.GetType() != KDeviceType_HardDisk)
72 continue;
73 strAttData += QString("<br>&nbsp;<nobr>%1:&nbsp;%2</nobr>")
74 .arg(vboxGlobal().toString(StorageSlot(controller.GetBus(), attachment.GetPort(), attachment.GetDevice())))
75 .arg(VBoxMedium(attachment.GetMedium(), VBoxDefs::MediumType_HardDisk).location());
76 fAttachmentsPresent = true;
77 }
78 if (!strAttData.isNull())
79 strFullData += QString("<br><nobr><b>%1</b></nobr>").arg(controller.GetName()) + strAttData;
80 }
81
82 /* For now we will hide that LED at all if there are no attachments! */
83 if (!fAttachmentsPresent)
84 setHidden(true);
85 //if (!fAttachmentsPresent)
86 // strFullData += QApplication::translate("UIIndicatorsPool", "<br><nobr><b>No hard disks attached</b></nobr>", "HDD tooltip");
87
88 setToolTip(strToolTip.arg(strFullData));
89 setState(fAttachmentsPresent ? KDeviceActivity_Idle : KDeviceActivity_Null);
90 }
91
92protected:
93 /* For compatibility reason we do it here, later this should be moved to
94 * QIStateIndicator. */
95 CSession &m_session;
96};
97
98class UIIndicatorOpticalDisks : public QIWithRetranslateUI<QIStateIndicator>
99{
100 Q_OBJECT;
101
102public:
103
104 UIIndicatorOpticalDisks(CSession &session)
105 : QIWithRetranslateUI<QIStateIndicator>()
106 , m_session(session)
107 {
108 setStateIcon(KDeviceActivity_Idle, QPixmap(":/cd_16px.png"));
109 setStateIcon(KDeviceActivity_Reading, QPixmap(":/cd_read_16px.png"));
110 setStateIcon(KDeviceActivity_Writing, QPixmap(":/cd_write_16px.png"));
111 setStateIcon(KDeviceActivity_Null, QPixmap(":/cd_disabled_16px.png"));
112
113 retranslateUi();
114 }
115
116 void retranslateUi()
117 {
118 updateAppearance();
119 }
120
121 void updateAppearance()
122 {
123 const CMachine &machine = m_session.GetMachine();
124
125 QString strToolTip = QApplication::translate("UIIndicatorsPool", "<p style='white-space:pre'><nobr>Indicates the activity "
126 "of the CD/DVD devices:</nobr>%1</p>", "CD/DVD tooltip");
127
128 QString strFullData;
129 bool fAttachmentsPresent = false;
130 bool fAttachmentsMounted = false;
131
132 const CStorageControllerVector &controllers = machine.GetStorageControllers();
133 foreach (const CStorageController &controller, controllers)
134 {
135 QString strAttData;
136 const CMediumAttachmentVector &attachments = machine.GetMediumAttachmentsOfController(controller.GetName());
137 foreach (const CMediumAttachment &attachment, attachments)
138 {
139 if (attachment.GetType() != KDeviceType_DVD)
140 continue;
141 VBoxMedium vboxMedium(attachment.GetMedium(), VBoxDefs::MediumType_DVD);
142 strAttData += QString("<br>&nbsp;<nobr>%1:&nbsp;%2</nobr>")
143 .arg(vboxGlobal().toString(StorageSlot(controller.GetBus(), attachment.GetPort(), attachment.GetDevice())))
144 .arg(vboxMedium.isNull() || vboxMedium.isHostDrive() ? vboxMedium.name() : vboxMedium.location());
145 fAttachmentsPresent = true;
146 if (!vboxMedium.isNull())
147 fAttachmentsMounted = true;
148 }
149 if (!strAttData.isNull())
150 strFullData += QString("<br><nobr><b>%1</b></nobr>").arg(controller.GetName()) + strAttData;
151 }
152
153 /* For now we will hide that LED at all if there are no attachments! */
154 if (!fAttachmentsPresent)
155 setHidden(true);
156 //if (!fAttachmentsPresent)
157 // strFullData = QApplication::translate("UIIndicatorsPool", "<br><nobr><b>No CD/DVD devices attached</b></nobr>", "CD/DVD tooltip");
158
159 setToolTip(strToolTip.arg(strFullData));
160 setState(fAttachmentsMounted ? KDeviceActivity_Idle : KDeviceActivity_Null);
161 }
162
163protected:
164 /* For compatibility reason we do it here, later this should be moved to
165 * QIStateIndicator. */
166 CSession &m_session;
167};
168
169class UIIndicatorFloppyDisks : public QIWithRetranslateUI<QIStateIndicator>
170{
171 Q_OBJECT;
172
173public:
174
175 UIIndicatorFloppyDisks(CSession &session)
176 : QIWithRetranslateUI<QIStateIndicator>()
177 , m_session(session)
178 {
179 setStateIcon(KDeviceActivity_Idle, QPixmap(":/fd_16px.png"));
180 setStateIcon(KDeviceActivity_Reading, QPixmap(":/fd_read_16px.png"));
181 setStateIcon(KDeviceActivity_Writing, QPixmap(":/fd_write_16px.png"));
182 setStateIcon(KDeviceActivity_Null, QPixmap(":/fd_disabled_16px.png"));
183
184 retranslateUi();
185 }
186
187 void retranslateUi()
188 {
189 updateAppearance();
190 }
191
192 void updateAppearance()
193 {
194 const CMachine &machine = m_session.GetMachine();
195
196 QString strToolTip = QApplication::translate("UIIndicatorsPool", "<p style='white-space:pre'><nobr>Indicates the activity "
197 "of the floppy devices:</nobr>%1</p>", "FD tooltip");
198
199 QString strFullData;
200 bool fAttachmentsPresent = false;
201 bool fAttachmentsMounted = false;
202
203 const CStorageControllerVector &controllers = machine.GetStorageControllers();
204 foreach (const CStorageController &controller, controllers)
205 {
206 QString strAttData;
207 const CMediumAttachmentVector &attachments = machine.GetMediumAttachmentsOfController(controller.GetName());
208 foreach (const CMediumAttachment &attachment, attachments)
209 {
210 if (attachment.GetType() != KDeviceType_Floppy)
211 continue;
212 VBoxMedium vboxMedium(attachment.GetMedium(), VBoxDefs::MediumType_Floppy);
213 strAttData += QString("<br>&nbsp;<nobr>%1:&nbsp;%2</nobr>")
214 .arg(vboxGlobal().toString(StorageSlot(controller.GetBus(), attachment.GetPort(), attachment.GetDevice())))
215 .arg(vboxMedium.isNull() || vboxMedium.isHostDrive() ? vboxMedium.name() : vboxMedium.location());
216 fAttachmentsPresent = true;
217 if (!vboxMedium.isNull())
218 fAttachmentsMounted = true;
219 }
220 if (!strAttData.isNull())
221 strFullData += QString("<br><nobr><b>%1</b></nobr>").arg(controller.GetName()) + strAttData;
222 }
223
224 /* For now we will hide that LED at all if there are no attachments! */
225 if (!fAttachmentsPresent)
226 setHidden(true);
227 //if (!fAttachmentsPresent)
228 // strFullData = QApplication::translate("UIIndicatorsPool", "<br><nobr><b>No floppy devices attached</b></nobr>", "FD tooltip");
229
230 setToolTip(strToolTip.arg(strFullData));
231 setState(fAttachmentsMounted ? KDeviceActivity_Idle : KDeviceActivity_Null);
232 }
233
234protected:
235 /* For compatibility reason we do it here, later this should be moved to
236 * QIStateIndicator. */
237 CSession &m_session;
238};
239
240class UIIndicatorNetworkAdapters : public QIWithRetranslateUI<QIStateIndicator>
241{
242 Q_OBJECT;
243
244public:
245
246 UIIndicatorNetworkAdapters(CSession &session)
247 : QIWithRetranslateUI<QIStateIndicator>()
248 , m_session(session)
249 , m_pUpdateTimer(new QTimer(this))
250 {
251 setStateIcon(KDeviceActivity_Idle, QPixmap(":/nw_16px.png"));
252 setStateIcon(KDeviceActivity_Reading, QPixmap(":/nw_read_16px.png"));
253 setStateIcon(KDeviceActivity_Writing, QPixmap(":/nw_write_16px.png"));
254 setStateIcon(KDeviceActivity_Null, QPixmap(":/nw_disabled_16px.png"));
255
256 connect(m_pUpdateTimer, SIGNAL(timeout()), SLOT(sltUpdateNetworkIPs()));
257 m_pUpdateTimer->start(5000);
258
259 retranslateUi();
260 }
261
262 void retranslateUi()
263 {
264 updateAppearance();
265 }
266
267 void updateAppearance()
268 {
269 const CMachine &machine = m_session.GetMachine();
270 QString strFullData;
271
272 ulong uMaxCount = vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount();
273
274 QString strToolTip = QApplication::translate("UIIndicatorsPool",
275 "<p style='white-space:pre'><nobr>Indicates the activity of the "
276 "network interfaces:</nobr>%1</p>", "Network adapters tooltip");
277
278 RTTIMESPEC time;
279 uint64_t u64Now = RTTimeSpecGetNano(RTTimeNow(&time));
280
281 QString strFlags, strCount;
282 LONG64 iTimestamp;
283 machine.GetGuestProperty("/VirtualBox/GuestInfo/Net/Count", strCount, iTimestamp, strFlags);
284 bool fPropsValid = (u64Now - iTimestamp < UINT64_C(60000000000)); /* timeout beacon */
285
286 QStringList ipList, macList;
287 if (fPropsValid)
288 {
289 int cAdapters = RT_MIN(strCount.toInt(), (int)uMaxCount);
290 for (int i = 0; i < cAdapters; ++i)
291 {
292 ipList << machine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/V4/IP").arg(i));
293 macList << machine.GetGuestPropertyValue(QString("/VirtualBox/GuestInfo/Net/%1/MAC").arg(i));
294 }
295 }
296
297 ulong uEnabled = 0;
298 for (ulong uSlot = 0; uSlot < uMaxCount; ++uSlot)
299 {
300 const CNetworkAdapter &adapter = machine.GetNetworkAdapter(uSlot);
301 if (adapter.GetEnabled())
302 {
303 QString strGuestIp;
304 if (fPropsValid)
305 {
306 QString strGuestMac = adapter.GetMACAddress();
307 int iIp = macList.indexOf(strGuestMac);
308 if (iIp >= 0)
309 strGuestIp = ipList[iIp];
310 }
311 strFullData += QApplication::translate("UIIndicatorsPool",
312 "<br><nobr><b>Adapter %1 (%2)</b>: %3 cable %4</nobr>", "Network adapters tooltip")
313 .arg(uSlot + 1)
314 .arg(vboxGlobal().toString(adapter.GetAttachmentType()))
315 .arg(strGuestIp.isEmpty() ? "" : "IP " + strGuestIp + ", ")
316 .arg(adapter.GetCableConnected() ?
317 QApplication::translate("UIIndicatorsPool", "connected", "Network adapters tooltip") :
318 QApplication::translate("UIIndicatorsPool", "disconnected", "Network adapters tooltip"));
319 ++uEnabled;
320 }
321 }
322
323 setState(uEnabled > 0 ? KDeviceActivity_Idle : KDeviceActivity_Null);
324 if (!uEnabled)
325 setHidden(true);
326
327 if (strFullData.isNull())
328 strFullData = QApplication::translate("UIIndicatorsPool",
329 "<br><nobr><b>All network adapters are disabled</b></nobr>", "Network adapters tooltip");
330
331 setToolTip(strToolTip.arg(strFullData));
332 }
333protected slots:
334
335 void sltUpdateNetworkIPs()
336 {
337 updateAppearance();
338 }
339
340protected:
341 /* For compatibility reason we do it here, later this should be moved to
342 * QIStateIndicator. */
343 CSession &m_session;
344 QTimer *m_pUpdateTimer;
345};
346
347class UIIndicatorUSBDevices : public QIWithRetranslateUI<QIStateIndicator>
348{
349 Q_OBJECT;
350
351public:
352
353 UIIndicatorUSBDevices(CSession &session)
354 : QIWithRetranslateUI<QIStateIndicator>()
355 , m_session(session)
356 {
357 setStateIcon(KDeviceActivity_Idle, QPixmap(":/usb_16px.png"));
358 setStateIcon(KDeviceActivity_Reading, QPixmap(":/usb_read_16px.png"));
359 setStateIcon(KDeviceActivity_Writing, QPixmap(":/usb_write_16px.png"));
360 setStateIcon(KDeviceActivity_Null, QPixmap(":/usb_disabled_16px.png"));
361
362 retranslateUi();
363 }
364
365 void retranslateUi()
366 {
367 updateAppearance();
368 }
369
370 void updateAppearance()
371 {
372 const CMachine &machine = m_session.GetMachine();
373
374 QString strToolTip = QApplication::translate("UIIndicatorsPool", "<p style='white-space:pre'><nobr>Indicates the activity of "
375 "the attached USB devices:</nobr>%1</p>", "USB device tooltip");
376 QString strFullData;
377
378 const CUSBController &usbctl = machine.GetUSBController();
379 setState(!usbctl.isNull() && usbctl.GetEnabled() && usbctl.GetProxyAvailable() ? KDeviceActivity_Idle : KDeviceActivity_Null);
380 if (!usbctl.isNull() && usbctl.GetEnabled())
381 {
382 const CConsole &console = m_session.GetConsole();
383
384 const CUSBDeviceVector &devsvec = console.GetUSBDevices();
385 for (int i = 0; i < devsvec.size(); ++ i)
386 {
387 CUSBDevice usb = devsvec[i];
388 strFullData += QString("<br><b><nobr>%1</nobr></b>").arg(vboxGlobal().details(usb));
389 }
390 if (strFullData.isNull())
391 strFullData = QApplication::translate("UIIndicatorsPool", "<br><nobr><b>No USB devices attached</b></nobr>", "USB device tooltip");
392 }
393 else
394 strFullData = QApplication::translate("UIIndicatorsPool", "<br><nobr><b>USB Controller is disabled</b></nobr>", "USB device tooltip");
395
396 setToolTip(strToolTip.arg(strFullData));
397 }
398
399protected:
400 /* For compatibility reason we do it here, later this should be moved to
401 * QIStateIndicator. */
402 CSession &m_session;
403};
404
405class UIIndicatorSharedFolders : public QIWithRetranslateUI<QIStateIndicator>
406{
407 Q_OBJECT;
408
409public:
410
411 UIIndicatorSharedFolders(CSession &session)
412 : QIWithRetranslateUI<QIStateIndicator>()
413 , m_session(session)
414 {
415 setStateIcon(KDeviceActivity_Idle, QPixmap(":/shared_folder_16px.png"));
416 setStateIcon(KDeviceActivity_Reading, QPixmap(":/shared_folder_read_16px.png"));
417 setStateIcon(KDeviceActivity_Writing, QPixmap(":/shared_folder_write_16px.png"));
418 setStateIcon(KDeviceActivity_Null, QPixmap(":/shared_folder_disabled_16px.png"));
419
420 retranslateUi();
421 }
422
423 void retranslateUi()
424 {
425 updateAppearance();
426 }
427
428 void updateAppearance()
429 {
430 const CMachine &machine = m_session.GetMachine();
431 const CConsole &console = m_session.GetConsole();
432
433 QString strToolTip = QApplication::translate("UIIndicatorsPool", "<p style='white-space:pre'><nobr>Indicates the activity of "
434 "the machine's shared folders:</nobr>%1</p>", "Shared folders tooltip");
435
436 QString strFullData;
437 QMap<QString, QString> sfs;
438
439 /* Permanent folders */
440 const CSharedFolderVector &psfvec = machine.GetSharedFolders();
441
442 for (int i = 0; i < psfvec.size(); ++ i)
443 {
444 const CSharedFolder &sf = psfvec[i];
445 sfs.insert(sf.GetName(), sf.GetHostPath());
446 }
447
448 /* Transient folders */
449 const CSharedFolderVector &tsfvec = console.GetSharedFolders();
450
451 for (int i = 0; i < tsfvec.size(); ++ i)
452 {
453 const CSharedFolder &sf = tsfvec[i];
454 sfs.insert(sf.GetName(), sf.GetHostPath());
455 }
456
457 for (QMap<QString, QString>::const_iterator it = sfs.constBegin(); it != sfs.constEnd(); ++ it)
458 {
459 /* Select slashes depending on the OS type */
460 if (VBoxGlobal::isDOSType(console.GetGuest().GetOSTypeId()))
461 strFullData += QString("<br><nobr><b>\\\\vboxsvr\\%1&nbsp;</b></nobr><nobr>%2</nobr>")
462 .arg(it.key(), it.value());
463 else
464 strFullData += QString("<br><nobr><b>%1&nbsp;</b></nobr><nobr>%2</nobr>")
465 .arg(it.key(), it.value());
466 }
467
468 if (sfs.count() == 0)
469 strFullData = QApplication::translate("UIIndicatorsPool", "<br><nobr><b>No shared folders</b></nobr>", "Shared folders tooltip");
470
471 setState(!sfs.isEmpty() ? KDeviceActivity_Idle : KDeviceActivity_Null);
472 setToolTip(strToolTip.arg(strFullData));
473 }
474
475protected:
476 /* For compatibility reason we do it here, later this should be moved to
477 * QIStateIndicator. */
478 CSession &m_session;
479};
480
481class UIIndicatorVRDEDisks : public QIWithRetranslateUI<QIStateIndicator>
482{
483 Q_OBJECT;
484
485public:
486
487 UIIndicatorVRDEDisks(CSession &session)
488 : QIWithRetranslateUI<QIStateIndicator>()
489 , m_session(session)
490 {
491 setStateIcon(0, QPixmap (":/vrdp_disabled_16px.png"));
492 setStateIcon(1, QPixmap (":/vrdp_16px.png"));
493
494 retranslateUi();
495 }
496
497 void retranslateUi()
498 {
499 updateAppearance();
500 }
501
502 void updateAppearance()
503 {
504 CVRDEServer srv = m_session.GetMachine().GetVRDEServer();
505 if (!srv.isNull())
506 {
507 /* update menu&status icon state */
508 bool fEnabled = srv.GetEnabled();
509
510 setState(fEnabled ? KDeviceActivity_Idle : KDeviceActivity_Null);
511
512 QString tip = QApplication::translate("UIIndicatorsPool", "Indicates whether the Remote Desktop Server "
513 "is enabled (<img src=:/vrdp_16px.png/>) or not "
514 "(<img src=:/vrdp_disabled_16px.png/>).");
515 if (srv.GetEnabled())
516 tip += QApplication::translate("UIIndicatorsPool", "<hr>The Remote Desktop Server is listening on port %1").arg(srv.GetVRDEProperty("TCP/Ports"));
517 setToolTip(tip);
518 }
519 }
520
521protected:
522 /* For compatibility reason we do it here, later this should be moved to
523 * QIStateIndicator. */
524 CSession &m_session;
525};
526
527class UIIndicatorVirtualization : public QIWithRetranslateUI<QIStateIndicator>
528{
529 Q_OBJECT;
530
531public:
532
533 UIIndicatorVirtualization(CSession &session)
534 : QIWithRetranslateUI<QIStateIndicator>()
535 , m_session(session)
536 {
537 setStateIcon(0, QPixmap(":/vtx_amdv_disabled_16px.png"));
538 setStateIcon(1, QPixmap(":/vtx_amdv_16px.png"));
539
540 retranslateUi();
541 }
542
543 void retranslateUi()
544 {
545 updateAppearance();
546 }
547
548 void updateAppearance()
549 {
550 const CConsole &console = m_session.GetConsole();
551 if (console.isNull())
552 return;
553
554 const CMachineDebugger &debugger = console.GetDebugger();
555 if (debugger.isNull())
556 return;
557
558 bool bVirtEnabled = debugger.GetHWVirtExEnabled();
559 QString virtualization = bVirtEnabled ?
560 VBoxGlobal::tr("Enabled", "details report (VT-x/AMD-V)") :
561 VBoxGlobal::tr("Disabled", "details report (VT-x/AMD-V)");
562
563 bool bNestEnabled = debugger.GetHWVirtExNestedPagingEnabled();
564 QString nestedPaging = bNestEnabled ?
565 VBoxGlobal::tr("Enabled", "nested paging") :
566 VBoxGlobal::tr("Disabled", "nested paging");
567
568 QString tip(QApplication::translate("UIIndicatorsPool", "Indicates the status of the hardware virtualization "
569 "features used by this virtual machine:"
570 "<br><nobr><b>%1:</b>&nbsp;%2</nobr>"
571 "<br><nobr><b>%3:</b>&nbsp;%4</nobr>",
572 "Virtualization Stuff LED")
573 .arg(VBoxGlobal::tr("VT-x/AMD-V", "details report"), virtualization)
574 .arg(VBoxGlobal::tr("Nested Paging"), nestedPaging));
575
576 int cpuCount = console.GetMachine().GetCPUCount();
577 if (cpuCount > 1)
578 tip += QApplication::translate("UIIndicatorsPool", "<br><nobr><b>%1:</b>&nbsp;%2</nobr>", "Virtualization Stuff LED")
579 .arg(VBoxGlobal::tr("Processor(s)", "details report")).arg(cpuCount);
580
581 setToolTip(tip);
582 setState(bVirtEnabled);
583 }
584
585protected:
586 /* For compatibility reason we do it here, later this should be moved to
587 * QIStateIndicator. */
588 CSession &m_session;
589};
590
591class UIIndicatorMouse : public QIWithRetranslateUI<QIStateIndicator>
592{
593 Q_OBJECT;
594
595public:
596
597 UIIndicatorMouse(CSession &session)
598 : QIWithRetranslateUI<QIStateIndicator>()
599 , m_session(session)
600 {
601 setStateIcon(0, QPixmap(":/mouse_disabled_16px.png"));
602 setStateIcon(1, QPixmap(":/mouse_16px.png"));
603 setStateIcon(2, QPixmap(":/mouse_seamless_16px.png"));
604 setStateIcon(3, QPixmap(":/mouse_can_seamless_16px.png"));
605 setStateIcon(4, QPixmap(":/mouse_can_seamless_uncaptured_16px.png"));
606
607 retranslateUi();
608 }
609
610 void retranslateUi()
611 {
612 setToolTip(QApplication::translate("UIIndicatorsPool", "Indicates whether the host mouse pointer is captured by the guest OS:<br>"
613 "<nobr><img src=:/mouse_disabled_16px.png/>&nbsp;&nbsp;pointer is not captured</nobr><br>"
614 "<nobr><img src=:/mouse_16px.png/>&nbsp;&nbsp;pointer is captured</nobr><br>"
615 "<nobr><img src=:/mouse_seamless_16px.png/>&nbsp;&nbsp;mouse integration (MI) is On</nobr><br>"
616 "<nobr><img src=:/mouse_can_seamless_16px.png/>&nbsp;&nbsp;MI is Off, pointer is captured</nobr><br>"
617 "<nobr><img src=:/mouse_can_seamless_uncaptured_16px.png/>&nbsp;&nbsp;MI is Off, pointer is not captured</nobr><br>"
618 "Note that the mouse integration feature requires Guest Additions to be installed in the guest OS."));
619 }
620
621public slots:
622
623 void setState(int iState)
624 {
625 if ((iState & UIMouseStateType_MouseAbsoluteDisabled) &&
626 (iState & UIMouseStateType_MouseAbsolute) &&
627 !(iState & UIMouseStateType_MouseCaptured))
628 {
629 QIStateIndicator::setState(4);
630 }
631 else
632 {
633 QIStateIndicator::setState(iState & (UIMouseStateType_MouseAbsolute | UIMouseStateType_MouseCaptured));
634 }
635 }
636
637protected:
638 /* For compatibility reason we do it here, later this should be moved to
639 * QIStateIndicator. */
640 CSession &m_session;
641};
642
643class UIIndicatorHostkey : public QIWithRetranslateUI<QIStateIndicator>
644{
645 Q_OBJECT;
646
647public:
648
649 UIIndicatorHostkey(CSession &session)
650 : QIWithRetranslateUI<QIStateIndicator>()
651 , m_session(session)
652 {
653 setStateIcon(0, QPixmap(":/hostkey_16px.png"));
654 setStateIcon(1, QPixmap(":/hostkey_captured_16px.png"));
655 setStateIcon(2, QPixmap(":/hostkey_pressed_16px.png"));
656 setStateIcon(3, QPixmap(":/hostkey_captured_pressed_16px.png"));
657
658 retranslateUi();
659 }
660
661 void retranslateUi()
662 {
663 setToolTip(QApplication::translate("UIIndicatorsPool", "Indicates whether the keyboard is captured by the guest OS "
664 "(<img src=:/hostkey_captured_16px.png/>) or not (<img src=:/hostkey_16px.png/>)."));
665 }
666
667protected:
668 /* For compatibility reason we do it here, later this should be moved to
669 * QIStateIndicator. */
670 CSession &m_session;
671};
672
673UIIndicatorsPool::UIIndicatorsPool(CSession &session, QObject *pParent)
674 : QObject(pParent)
675 , m_session(session)
676 , m_IndicatorsPool(UIIndicatorIndex_End, 0)
677{
678}
679
680UIIndicatorsPool::~UIIndicatorsPool()
681{
682 for (int i = 0; i < m_IndicatorsPool.size(); ++i)
683 {
684 delete m_IndicatorsPool[i];
685 m_IndicatorsPool[i] = 0;
686 }
687 m_IndicatorsPool.clear();
688}
689
690QIStateIndicator* UIIndicatorsPool::indicator(UIIndicatorIndex index)
691{
692 if (!m_IndicatorsPool.at(index))
693 {
694 switch (index)
695 {
696 case UIIndicatorIndex_HardDisks:
697 m_IndicatorsPool[index] = new UIIndicatorHardDisks(m_session);
698 break;
699 case UIIndicatorIndex_OpticalDisks:
700 m_IndicatorsPool[index] = new UIIndicatorOpticalDisks(m_session);
701 break;
702 case UIIndicatorIndex_FloppyDisks:
703 m_IndicatorsPool[index] = new UIIndicatorFloppyDisks(m_session);
704 break;
705 case UIIndicatorIndex_NetworkAdapters:
706 m_IndicatorsPool[index] = new UIIndicatorNetworkAdapters(m_session);
707 break;
708 case UIIndicatorIndex_USBDevices:
709 m_IndicatorsPool[index] = new UIIndicatorUSBDevices(m_session);
710 break;
711 case UIIndicatorIndex_SharedFolders:
712 m_IndicatorsPool[index] = new UIIndicatorSharedFolders(m_session);
713 break;
714 case UIIndicatorIndex_Virtualization:
715 m_IndicatorsPool[index] = new UIIndicatorVirtualization(m_session);
716 break;
717 case UIIndicatorIndex_Mouse:
718 m_IndicatorsPool[index] = new UIIndicatorMouse(m_session);
719 break;
720 case UIIndicatorIndex_Hostkey:
721 m_IndicatorsPool[index] = new UIIndicatorHostkey(m_session);
722 break;
723 default:
724 break;
725 }
726 }
727 return m_IndicatorsPool.at(index);
728}
729
730#include "UIIndicatorsPool.moc"
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use