- Timestamp:
- Jun 15, 2010 12:35:56 PM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 27 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r30188 r30192 390 390 src/globals/VBoxGlobal.cpp \ 391 391 src/globals/VBoxProblemReporter.cpp \ 392 src/globals/UIIconPool.cpp \ 392 393 src/extensions/QIAdvancedSlider.cpp \ 393 394 src/extensions/QIArrowButtonPress.cpp \ -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxHelpActions.cpp
r28800 r30192 24 24 #include "VBoxGlobal.h" 25 25 #include "VBoxProblemReporter.h" 26 #include "UIIconPool.h" 26 27 27 28 /* Qt includes */ … … 34 35 35 36 contentsAction = new QAction (aParent); 36 contentsAction->setIcon ( VBoxGlobal::iconSet (":/help_16px.png"));37 contentsAction->setIcon (UIIconPool::iconSet (":/help_16px.png")); 37 38 38 39 webAction = new QAction (aParent); 39 webAction->setIcon ( VBoxGlobal::iconSet (":/site_16px.png"));40 webAction->setIcon (UIIconPool::iconSet (":/site_16px.png")); 40 41 41 42 resetMessagesAction = new QAction (aParent); 42 resetMessagesAction->setIcon ( VBoxGlobal::iconSet (":/reset_16px.png"));43 resetMessagesAction->setIcon (UIIconPool::iconSet (":/reset_16px.png")); 43 44 44 45 registerAction = new QAction (aParent); 45 registerAction->setIcon ( VBoxGlobal::iconSet (":/register_16px.png",46 registerAction->setIcon (UIIconPool::iconSet (":/register_16px.png", 46 47 ":/register_disabled_16px.png")); 47 48 updateAction = new QAction (aParent); 48 49 updateAction->setMenuRole(QAction::ApplicationSpecificRole); 49 updateAction->setIcon ( VBoxGlobal::iconSet (":/refresh_16px.png",50 updateAction->setIcon (UIIconPool::iconSet (":/refresh_16px.png", 50 51 ":/refresh_disabled_16px.png")); 51 52 aboutAction = new QAction (aParent); 52 53 aboutAction->setMenuRole (QAction::AboutRole); 53 aboutAction->setIcon ( VBoxGlobal::iconSet (":/about_16px.png"));54 aboutAction->setIcon (UIIconPool::iconSet (":/about_16px.png")); 54 55 55 56 QObject::connect (contentsAction, SIGNAL (triggered()), -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp
r29975 r30192 42 42 #include "QIFileDialog.h" 43 43 #include "QILabel.h" 44 #include "UIIconPool.h" 44 45 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 45 46 … … 202 203 203 204 /* Apply window icons */ 204 setWindowIcon (vboxGlobal().iconSetFull(QSize (32, 32), QSize (16, 16),205 205 setWindowIcon(UIIconPool::iconSetFull(QSize (32, 32), QSize (16, 16), 206 ":/diskimage_32px.png", ":/diskimage_16px.png")); 206 207 207 208 mVBox = vboxGlobal().virtualBox(); … … 212 213 mFloppyImagesInaccessible = false; 213 214 214 mHardDiskIcon = VBoxGlobal::iconSet(":/hd_16px.png", ":/hd_disabled_16px.png");215 mDVDImageIcon = VBoxGlobal::iconSet(":/cd_16px.png", ":/cd_disabled_16px.png");216 mFloppyImageIcon = VBoxGlobal::iconSet(":/fd_16px.png", ":/fd_disabled_16px.png");215 mHardDiskIcon = UIIconPool::iconSet(":/hd_16px.png", ":/hd_disabled_16px.png"); 216 mDVDImageIcon = UIIconPool::iconSet(":/cd_16px.png", ":/cd_disabled_16px.png"); 217 mFloppyImageIcon = UIIconPool::iconSet(":/fd_16px.png", ":/fd_disabled_16px.png"); 217 218 218 219 /* Setup tab-widget icons */ … … 291 292 connect (mRefreshAction, SIGNAL (triggered()), this, SLOT (refreshAll())); 292 293 293 mNewAction->setIcon (VBoxGlobal::iconSetFull (294 mNewAction->setIcon(UIIconPool::iconSetFull ( 294 295 QSize (22, 22), QSize (16, 16), 295 296 ":/hd_new_22px.png", ":/hd_new_16px.png", 296 297 ":/hd_new_disabled_22px.png", ":/hd_new_disabled_16px.png")); 297 mAddAction->setIcon (VBoxGlobal::iconSetFull (298 mAddAction->setIcon(UIIconPool::iconSetFull ( 298 299 QSize (22, 22), QSize (16, 16), 299 300 ":/hd_add_22px.png", ":/hd_add_16px.png", 300 301 ":/hd_add_disabled_22px.png", ":/hd_add_disabled_16px.png")); 301 mRemoveAction->setIcon (VBoxGlobal::iconSetFull (302 mRemoveAction->setIcon(UIIconPool::iconSetFull ( 302 303 QSize (22, 22), QSize (16, 16), 303 304 ":/hd_remove_22px.png", ":/hd_remove_16px.png", 304 305 ":/hd_remove_disabled_22px.png", ":/hd_remove_disabled_16px.png")); 305 mReleaseAction->setIcon (VBoxGlobal::iconSetFull (306 mReleaseAction->setIcon(UIIconPool::iconSetFull ( 306 307 QSize (22, 22), QSize (16, 16), 307 308 ":/hd_release_22px.png", ":/hd_release_16px.png", 308 309 ":/hd_release_disabled_22px.png", ":/hd_release_disabled_16px.png")); 309 mRefreshAction->setIcon (VBoxGlobal::iconSetFull (310 mRefreshAction->setIcon(UIIconPool::iconSetFull ( 310 311 QSize (22, 22), QSize (16, 16), 311 312 ":/refresh_22px.png", ":/refresh_16px.png", -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSelectorWnd.cpp
r30031 r30192 20 20 # include "precomp.h" 21 21 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 22 #include "VBoxProblemReporter.h"23 22 #include "VBoxSelectorWnd.h" 24 #include "UIVMListView.h"25 #include "VBoxToolBar.h"26 27 #include "VBoxSnapshotsWgt.h"28 #include "UINewVMWzd.h"29 #include "VBoxMediaManagerDlg.h"30 #include "UIImportApplianceWzd.h"31 #include "UIExportApplianceWzd.h"32 #include "VBoxSettingsDialogSpecific.h"33 #include "VBoxVMLogViewer.h"34 #include "VBoxGlobal.h"35 #include "VBoxUtils.h"36 23 #include "QISplitter.h" 37 24 #include "QITabWidget.h" 25 #include "UIExportApplianceWzd.h" 26 #include "UIIconPool.h" 27 #include "UIImportApplianceWzd.h" 28 #include "UINewVMWzd.h" 29 #include "UISpacerWidgets.h" 30 #include "UIVMListView.h" 31 #include "VBoxGlobal.h" 32 #include "VBoxMediaManagerDlg.h" 33 #include "VBoxProblemReporter.h" 34 #include "VBoxSettingsDialogSpecific.h" 35 #include "VBoxSnapshotsWgt.h" 36 #include "VBoxSpecialControls.h" 37 #include "VBoxToolBar.h" 38 #include "VBoxUtils.h" 39 #include "VBoxVMLogViewer.h" 38 40 39 41 #include "UIDownloaderUserManual.h" … … 284 286 mBtnEdit->setSizePolicy (QSizePolicy::Preferred, QSizePolicy::Fixed); 285 287 mBtnEdit->setFocusPolicy (Qt::StrongFocus); 286 mBtnEdit->setIcon (VBoxGlobal::iconSet(":/edit_description_16px.png",287 288 mBtnEdit->setIcon(UIIconPool::iconSet(":/edit_description_16px.png", 289 ":/edit_description_disabled_16px.png")); 288 290 mBtnEdit->setToolButtonStyle (Qt::ToolButtonTextBesideIcon); 289 291 connect (mBtnEdit, SIGNAL (clicked()), this, SLOT (goToSettings())); … … 413 415 414 416 mFileMediaMgrAction = new QAction (this); 415 mFileMediaMgrAction->setIcon (VBoxGlobal::iconSet(":/diskimage_16px.png"));417 mFileMediaMgrAction->setIcon(UIIconPool::iconSet(":/diskimage_16px.png")); 416 418 417 419 mFileApplianceImportAction = new QAction (this); 418 mFileApplianceImportAction->setIcon (VBoxGlobal::iconSet(":/import_16px.png"));420 mFileApplianceImportAction->setIcon(UIIconPool::iconSet(":/import_16px.png")); 419 421 420 422 mFileApplianceExportAction = new QAction (this); 421 mFileApplianceExportAction->setIcon (VBoxGlobal::iconSet(":/export_16px.png"));423 mFileApplianceExportAction->setIcon(UIIconPool::iconSet(":/export_16px.png")); 422 424 423 425 mFileSettingsAction = new QAction(this); 424 426 mFileSettingsAction->setMenuRole (QAction::PreferencesRole); 425 mFileSettingsAction->setIcon (VBoxGlobal::iconSet(":/global_settings_16px.png"));427 mFileSettingsAction->setIcon(UIIconPool::iconSet(":/global_settings_16px.png")); 426 428 mFileExitAction = new QAction (this); 427 429 mFileExitAction->setMenuRole (QAction::QuitRole); 428 mFileExitAction->setIcon (VBoxGlobal::iconSet(":/exit_16px.png"));430 mFileExitAction->setIcon(UIIconPool::iconSet(":/exit_16px.png")); 429 431 430 432 mVmNewAction = new QAction (this); 431 mVmNewAction->setIcon (VBoxGlobal::iconSetFull(433 mVmNewAction->setIcon(UIIconPool::iconSetFull( 432 434 QSize (32, 32), QSize (16, 16), 433 435 ":/vm_new_32px.png", ":/new_16px.png")); 434 436 mVmConfigAction = new QAction (this); 435 mVmConfigAction->setIcon (VBoxGlobal::iconSetFull(437 mVmConfigAction->setIcon(UIIconPool::iconSetFull( 436 438 QSize (32, 32), QSize (16, 16), 437 439 ":/vm_settings_32px.png", ":/settings_16px.png", 438 440 ":/vm_settings_disabled_32px.png", ":/settings_dis_16px.png")); 439 441 mVmDeleteAction = new QAction (this); 440 mVmDeleteAction->setIcon (VBoxGlobal::iconSetFull(442 mVmDeleteAction->setIcon(UIIconPool::iconSetFull( 441 443 QSize (32, 32), QSize (16, 16), 442 444 ":/vm_delete_32px.png", ":/delete_16px.png", 443 445 ":/vm_delete_disabled_32px.png", ":/delete_dis_16px.png")); 444 446 mVmStartAction = new QAction (this); 445 mVmStartAction->setIcon (VBoxGlobal::iconSetFull(447 mVmStartAction->setIcon(UIIconPool::iconSetFull( 446 448 QSize (32, 32), QSize (16, 16), 447 449 ":/vm_start_32px.png", ":/start_16px.png", 448 450 ":/vm_start_disabled_32px.png", ":/start_dis_16px.png")); 449 451 mVmDiscardAction = new QAction (this); 450 mVmDiscardAction->setIcon (VBoxGlobal::iconSetFull(452 mVmDiscardAction->setIcon(UIIconPool::iconSetFull( 451 453 QSize (32, 32), QSize (16, 16), 452 454 ":/vm_discard_32px.png", ":/discard_16px.png", … … 454 456 mVmPauseAction = new QAction (this); 455 457 mVmPauseAction->setCheckable (true); 456 mVmPauseAction->setIcon (VBoxGlobal::iconSetFull(458 mVmPauseAction->setIcon(UIIconPool::iconSetFull( 457 459 QSize (32, 32), QSize (16, 16), 458 460 ":/vm_pause_32px.png", ":/pause_16px.png", 459 461 ":/vm_pause_disabled_32px.png", ":/pause_disabled_16px.png")); 460 462 mVmRefreshAction = new QAction (this); 461 mVmRefreshAction->setIcon (VBoxGlobal::iconSetFull(463 mVmRefreshAction->setIcon(UIIconPool::iconSetFull( 462 464 QSize (32, 32), QSize (16, 16), 463 465 ":/refresh_32px.png", ":/refresh_16px.png", 464 466 ":/refresh_disabled_32px.png", ":/refresh_disabled_16px.png")); 465 467 mVmShowLogsAction = new QAction (this); 466 mVmShowLogsAction->setIcon (VBoxGlobal::iconSetFull(468 mVmShowLogsAction->setIcon(UIIconPool::iconSetFull( 467 469 QSize (32, 32), QSize (16, 16), 468 470 ":/vm_show_logs_32px.png", ":/show_logs_16px.png", … … 514 516 515 517 /* VM tab widget containing details and snapshots tabs */ 516 mVmTabWidget = new QITabWidget();517 518 pSplitter->addWidget (mVmTabWidget); 518 519 … … 524 525 /* VM details view */ 525 526 mVmDetailsView = new VBoxVMDetailsView (NULL, mVmRefreshAction); 526 mVmTabWidget->addTab 527 VBoxGlobal::iconSet(":/settings_16px.png"),528 527 mVmTabWidget->addTab(mVmDetailsView, 528 UIIconPool::iconSet(":/settings_16px.png"), 529 QString::null); 529 530 530 531 /* VM snapshots list */ 531 532 mVmSnapshotsWgt = new VBoxSnapshotsWgt (NULL); 532 mVmTabWidget->addTab 533 VBoxGlobal::iconSet(":/take_snapshot_16px.png",534 535 533 mVmTabWidget->addTab(mVmSnapshotsWgt, 534 UIIconPool::iconSet(":/take_snapshot_16px.png", 535 ":/take_snapshot_dis_16px.png"), 536 QString::null); 536 537 mVmSnapshotsWgt->setContentsMargins (10, 10, 10, 10); 537 538 538 539 /* VM comments page */ 539 540 mVmDescriptionPage = new VBoxVMDescriptionPage (this); 540 mVmTabWidget->addTab 541 VBoxGlobal::iconSet(":/description_16px.png",542 543 541 mVmTabWidget->addTab(mVmDescriptionPage, 542 UIIconPool::iconSet(":/description_16px.png", 543 ":/description_disabled_16px.png"), 544 QString::null); 544 545 mVmDescriptionPage->setContentsMargins (10, 10, 10, 10); 545 546 … … 1839 1840 mShowSelectorAction = new QAction (this); 1840 1841 Assert (mShowSelectorAction); 1841 mShowSelectorAction->setIcon (VBoxGlobal::iconSet ( 1842 ":/VirtualBox_16px.png")); 1842 mShowSelectorAction->setIcon(UIIconPool::iconSet(":/VirtualBox_16px.png")); 1843 1843 1844 1844 mHideSystrayMenuAction = new QAction (this); 1845 1845 Assert (mHideSystrayMenuAction); 1846 mHideSystrayMenuAction->setIcon (VBoxGlobal::iconSet ( 1847 ":/exit_16px.png")); 1846 mHideSystrayMenuAction->setIcon(UIIconPool::iconSet(":/exit_16px.png")); 1848 1847 1849 1848 /* reuse parent action data */ -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotsWgt.cpp
r29031 r30192 21 21 # include "precomp.h" 22 22 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 23 /* Local includes */ 24 #include "UIIconPool.h" 25 #include "VBoxProblemReporter.h" 26 #include "VBoxSnapshotDetailsDlg.h" 27 #include "VBoxSnapshotsWgt.h" 28 #include "VBoxTakeSnapshotDlg.h" 29 #include "VBoxToolBar.h" 30 23 31 /* Global includes */ 24 32 #include <QDateTime> … … 27 35 #include <QScrollBar> 28 36 29 /* Local includes */30 #include <VBoxSnapshotsWgt.h>31 #include <VBoxProblemReporter.h>32 #include <VBoxSnapshotDetailsDlg.h>33 #include <VBoxTakeSnapshotDlg.h>34 #include <VBoxToolBar.h>35 37 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 36 38 … … 361 363 362 364 /* Setup actions */ 363 mRestoreSnapshotAction->setIcon (VBoxGlobal::iconSetFull(365 mRestoreSnapshotAction->setIcon(UIIconPool::iconSetFull( 364 366 QSize (22, 22), QSize (16, 16), 365 367 ":/discard_cur_state_22px.png", ":/discard_cur_state_16px.png", // TODO: Update Icons! 366 368 ":/discard_cur_state_dis_22px.png", ":/discard_cur_state_dis_16px.png")); // TODO: Update Icons! 367 mDeleteSnapshotAction->setIcon (VBoxGlobal::iconSetFull(369 mDeleteSnapshotAction->setIcon(UIIconPool::iconSetFull( 368 370 QSize (22, 22), QSize (16, 16), 369 371 ":/delete_snapshot_22px.png", ":/delete_snapshot_16px.png", 370 372 ":/delete_snapshot_dis_22px.png", ":/delete_snapshot_dis_16px.png")); 371 mShowSnapshotDetailsAction->setIcon (VBoxGlobal::iconSetFull(373 mShowSnapshotDetailsAction->setIcon(UIIconPool::iconSetFull( 372 374 QSize (22, 22), QSize (16, 16), 373 375 ":/show_snapshot_details_22px.png", ":/show_snapshot_details_16px.png", 374 376 ":/show_snapshot_details_dis_22px.png", ":/show_snapshot_details_dis_16px.png")); 375 mTakeSnapshotAction->setIcon (VBoxGlobal::iconSetFull(377 mTakeSnapshotAction->setIcon(UIIconPool::iconSetFull( 376 378 QSize (22, 22), QSize (16, 16), 377 379 ":/take_snapshot_22px.png", ":/take_snapshot_16px.png", -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxUpdateDlg.cpp
r28800 r30192 27 27 #include "VBoxProblemReporter.h" 28 28 #include "VBoxUpdateDlg.h" 29 #include "UIIconPool.h" 29 30 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 30 31 … … 253 254 254 255 /* Apply window icons */ 255 setWindowIcon (vboxGlobal().iconSetFull(QSize (32, 32), QSize (16, 16),256 256 setWindowIcon(UIIconPool::iconSetFull(QSize (32, 32), QSize (16, 16), 257 ":/refresh_32px.png", ":/refresh_16px.png")); 257 258 258 259 /* Setup other connections */ -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMInformationDlg.cpp
r29794 r30192 21 21 # include "precomp.h" 22 22 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 23 24 /* Local Includes */ 25 #include "UIIconPool.h" 26 #include "UIMachineLogic.h" 27 #include "UIMachineView.h" 28 #include "UIMachineWindow.h" 29 #include "UISession.h" 30 #include "VBoxGlobal.h" 31 #include "VBoxVMInformationDlg.h" 32 23 33 /* Global Includes */ 24 34 #include <QTimer> 25 35 #include <QScrollBar> 26 36 27 /* Local Includes */28 #include <VBoxVMInformationDlg.h>29 #include <VBoxGlobal.h>30 37 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 31 32 #include "UIMachineLogic.h"33 #include "UIMachineWindow.h"34 #include "UIMachineView.h"35 #include "UISession.h"36 38 37 39 VBoxVMInformationDlg::InfoDlgMap VBoxVMInformationDlg::mSelfArray = InfoDlgMap(); … … 72 74 #ifdef Q_WS_MAC 73 75 /* No icon for this window on the mac, cause this would act as proxy icon which isn't necessary here. */ 74 setWindowIcon 76 setWindowIcon(QIcon()); 75 77 #else 76 78 /* Apply window icons */ 77 setWindowIcon (vboxGlobal().iconSetFull(QSize (32, 32), QSize (16, 16),78 79 setWindowIcon(UIIconPool::iconSetFull(QSize (32, 32), QSize (16, 16), 80 ":/session_info_32px.png", ":/session_info_16px.png")); 79 81 #endif 80 82 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMLogViewer.cpp
r30188 r30192 21 21 # include "precomp.h" 22 22 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */ 23 #include "VBoxVMLogViewer.h" 23 #include "QITabWidget.h" 24 #include "UIIconPool.h" 24 25 #include "VBoxGlobal.h" 25 26 #include "VBoxProblemReporter.h" 26 27 #include "VBoxSpecialControls.h" 27 28 #include "VBoxUtils.h" 28 #include " QITabWidget.h"29 #include "VBoxVMLogViewer.h" 29 30 30 31 /* Qt includes */ 32 #include <QCheckBox> 33 #include <QDateTime> 34 #include <QDir> 35 #include <QFileDialog> 36 #include <QKeyEvent> 37 #include <QLabel> 38 #include <QLineEdit> 39 #include <QPushButton> 40 #include <QScrollBar> 31 41 #include <QStyle> 32 42 #include <QTextEdit> 33 #include <QLineEdit>34 #include <QLabel>35 #include <QCheckBox>36 #include <QDir>37 #include <QScrollBar>38 #include <QFileDialog>39 #include <QDateTime>40 #include <QPushButton>41 #include <QKeyEvent>42 43 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */ 43 44 … … 81 82 82 83 /* Apply window icons */ 83 setWindowIcon (vboxGlobal().iconSetFull(QSize (32, 32), QSize (16, 16),84 84 setWindowIcon(UIIconPool::iconSetFull(QSize (32, 32), QSize (16, 16), 85 ":/vm_show_logs_32px.png", ":/show_logs_16px.png")); 85 86 86 87 /* Enable size grip without using a status bar. */ … … 362 363 #ifndef Q_WS_MAC 363 364 /* No icons on the Mac */ 364 mButtonsNextPrev->setIcon (0, VBoxGlobal::iconSet(":/list_movedown_16px.png",365 366 mButtonsNextPrev->setIcon (1, VBoxGlobal::iconSet(":/list_moveup_16px.png",367 365 mButtonsNextPrev->setIcon(0, UIIconPool::iconSet(":/list_movedown_16px.png", 366 ":/list_movedown_disabled_16px.png")); 367 mButtonsNextPrev->setIcon(1, UIIconPool::iconSet(":/list_moveup_16px.png", 368 ":/list_moveup_disabled_16px.png")); 368 369 #endif /* !Q_WS_MAC */ 369 370 connect (mButtonsNextPrev, SIGNAL (clicked (int)), this, SLOT (find (int))); … … 376 377 mWarningIcon->hide(); 377 378 378 QIcon icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxWarning);379 QIcon icon = UIIconPool::defaultIcon(UIIconPool::MessageBoxWarningIcon, this); 379 380 if (!icon.isNull()) 380 381 mWarningIcon->setPixmap (icon.pixmap (16, 16)); -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIArrowButtonPress.cpp
r28800 r30192 19 19 20 20 /* VBox includes */ 21 #include "VBoxGlobal.h"22 21 #include "QIArrowButtonPress.h" 22 #include "UIIconPool.h" 23 23 24 24 /* Qt includes */ … … 49 49 void QIArrowButtonPress::updateIcon() 50 50 { 51 mButton->setIcon (VBoxGlobal::iconSet(mNext ?52 ":/arrow_right_10px.png" : ":/arrow_left_10px.png"));51 mButton->setIcon(UIIconPool::iconSet(mNext ? 52 ":/arrow_right_10px.png" : ":/arrow_left_10px.png")); 53 53 } 54 54 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIArrowButtonSwitch.cpp
r28800 r30192 19 19 20 20 /* VBox includes */ 21 #include "VBoxGlobal.h"22 21 #include "QIArrowButtonSwitch.h" 22 #include "UIIconPool.h" 23 23 24 24 /* Qt includes */ … … 56 56 void QIArrowButtonSwitch::updateIcon() 57 57 { 58 mButton->setIcon (VBoxGlobal::iconSet(mIsExpanded ?59 ":/arrow_down_10px.png" : ":/arrow_right_10px.png"));58 mButton->setIcon(UIIconPool::iconSet(mIsExpanded ? 59 ":/arrow_down_10px.png" : ":/arrow_right_10px.png")); 60 60 } 61 61 -
trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.cpp
r29794 r30192 25 25 #include "QILabel.h" 26 26 #include "QIDialogButtonBox.h" 27 #include "UIIconPool.h" 27 28 #ifdef Q_WS_MAC 28 29 # include "VBoxSelectorWnd.h" … … 322 323 { 323 324 case QIMessageBox::Information: 324 icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxInformation, this);325 icon = UIIconPool::defaultIcon(UIIconPool::MessageBoxInformationIcon, this); 325 326 break; 326 327 case QMessageBox::Warning: 327 icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxWarning, this);328 icon = UIIconPool::defaultIcon(UIIconPool::MessageBoxWarningIcon, this); 328 329 break; 329 330 case QIMessageBox::Critical: 330 icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxCritical, this);331 icon = UIIconPool::defaultIcon(UIIconPool::MessageBoxCriticalIcon, this); 331 332 break; 332 333 case QIMessageBox::Question: 333 icon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxQuestion, this);334 icon = UIIconPool::defaultIcon(UIIconPool::MessageBoxQuestionIcon, this); 334 335 break; 335 336 case QIMessageBox::GuruMeditation: 336 icon = QIcon 337 icon = QIcon(":/meditation_32px.png"); 337 338 break; 338 339 default: -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIIconPool.cpp
r30187 r30192 3 3 * 4 4 * VBox frontends: Qt GUI ("VirtualBox"): 5 * VBoxGlobal class implementation5 * UIIconPool class implementation 6 6 */ 7 7 8 8 /* 9 * Copyright (C) 20 06-2010 Oracle Corporation9 * Copyright (C) 2010 Oracle Corporation 10 10 * 11 11 * This file is part of VirtualBox Open Source Edition (OSE), as … … 18 18 */ 19 19 20 #include "VBoxGlobal.h" 21 #include <VBox/VBoxHDD.h> 22 #include <VBox/version.h> 20 /* Local includes */ 21 #include "UIIconPool.h" 23 22 24 #include "VBoxDefs.h" 25 #include "VBoxSelectorWnd.h" 26 #include "VBoxProblemReporter.h" 27 #include "QIHotKeyEdit.h" 28 #include "QIMessageBox.h" 29 #include "QIDialogButtonBox.h" 23 /* Global includes */ 24 #include <iprt/assert.h> 30 25 31 #include "UIMachine.h" 32 #include "UISession.h" 33 #ifdef VBOX_WITH_REGISTRATION 34 # include "UIRegistrationWzd.h" 35 #endif 36 #include "VBoxUpdateDlg.h" 37 #ifdef VBOX_WITH_VIDEOHWACCEL 38 # include "VBoxFBOverlay.h" 39 #endif /* VBOX_WITH_VIDEOHWACCEL */ 40 41 /* Qt includes */ 42 #include <QProgressDialog> 43 #include <QLibraryInfo> 44 #include <QFileDialog> 45 #include <QToolTip> 46 #include <QTranslator> 47 #include <QDesktopWidget> 48 #include <QDesktopServices> 49 #include <QMutex> 50 #include <QToolButton> 51 #include <QProcess> 52 #include <QThread> 53 #include <QPainter> 54 #include <QSettings> 55 #include <QTimer> 56 #include <QDir> 57 #include <QHelpEvent> 58 #include <QLocale> 59 60 #include <math.h> 61 62 #ifdef Q_WS_X11 63 # ifndef VBOX_OSE 64 # include "VBoxLicenseViewer.h" 65 # endif /* VBOX_OSE */ 66 # include <QTextBrowser> 67 # include <QScrollBar> 68 # include <QX11Info> 69 # include "VBoxX11Helper.h" 70 #endif 71 72 #ifdef Q_WS_MAC 73 # include "VBoxUtils-darwin.h" 74 #endif /* Q_WS_MAC */ 75 76 #if defined (Q_WS_WIN) 77 #include "shlobj.h" 78 #include <QEventLoop> 79 #endif 80 81 #if defined (Q_WS_X11) 82 #undef BOOL /* typedef CARD8 BOOL in Xmd.h conflicts with #define BOOL PRBool 83 * in COMDefs.h. A better fix would be to isolate X11-specific 84 * stuff by placing XX* helpers below to a separate source file. */ 85 #include <X11/X.h> 86 #include <X11/Xmd.h> 87 #include <X11/Xlib.h> 88 #include <X11/Xatom.h> 89 #include <X11/extensions/Xinerama.h> 90 #define BOOL PRBool 91 #endif 92 93 #include <VBox/sup.h> 94 #include <VBox/com/Guid.h> 95 96 #include <iprt/asm.h> 97 #include <iprt/err.h> 98 #include <iprt/param.h> 99 #include <iprt/path.h> 100 #include <iprt/env.h> 101 #include <iprt/file.h> 102 #include <iprt/ldr.h> 103 #include <iprt/system.h> 104 105 #ifdef VBOX_GUI_WITH_SYSTRAY 106 #include <iprt/process.h> 107 108 #if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) 109 #define HOSTSUFF_EXE ".exe" 110 #else /* !RT_OS_WINDOWS */ 111 #define HOSTSUFF_EXE "" 112 #endif /* !RT_OS_WINDOWS */ 113 #endif 114 115 #if defined (Q_WS_X11) 116 #include <iprt/mem.h> 117 #endif 118 119 //#define VBOX_WITH_FULL_DETAILS_REPORT /* hidden for now */ 120 121 //#warning "port me: check this" 122 /// @todo bird: Use (U)INT_PTR, (U)LONG_PTR, DWORD_PTR, or (u)intptr_t. 123 #if defined(Q_OS_WIN64) 124 typedef __int64 Q_LONG; /* word up to 64 bit signed */ 125 typedef unsigned __int64 Q_ULONG; /* word up to 64 bit unsigned */ 126 #else 127 typedef long Q_LONG; /* word up to 64 bit signed */ 128 typedef unsigned long Q_ULONG; /* word up to 64 bit unsigned */ 129 #endif 130 131 // VBoxMediaEnumEvent 132 ///////////////////////////////////////////////////////////////////////////// 133 134 class VBoxMediaEnumEvent : public QEvent 135 { 136 public: 137 138 /** Constructs a regular enum event */ 139 VBoxMediaEnumEvent (const VBoxMedium &aMedium, 140 VBoxMediaList::iterator &aIterator) 141 : QEvent ((QEvent::Type) VBoxDefs::MediaEnumEventType) 142 , mMedium (aMedium), mIterator (aIterator), mLast (false) 143 {} 144 /** Constructs the last enum event */ 145 VBoxMediaEnumEvent (VBoxMediaList::iterator &aIterator) 146 : QEvent ((QEvent::Type) VBoxDefs::MediaEnumEventType) 147 , mIterator (aIterator), mLast (true) 148 {} 149 150 /** Last enumerated medium (not valid when #last is true) */ 151 const VBoxMedium mMedium; 152 /** Opaque iterator provided by the event sender (guaranteed to be 153 * the same variable for all media in the single enumeration procedure) */ 154 VBoxMediaList::iterator &mIterator; 155 /** Whether this is the last event for the given enumeration or not */ 156 const bool mLast; 157 }; 158 159 // VirtualBox callback class 160 ///////////////////////////////////////////////////////////////////////////// 161 162 class VBoxCallback : VBOX_SCRIPTABLE_IMPL(IVirtualBoxCallback) 163 { 164 public: 165 166 VBoxCallback (VBoxGlobal &aGlobal) 167 : mGlobal (aGlobal) 168 , mIsRegDlgOwner (false) 169 , mIsUpdDlgOwner (false) 170 #ifdef VBOX_GUI_WITH_SYSTRAY 171 , mIsTrayIconOwner (false) 172 #endif 173 { 174 #if defined (Q_OS_WIN32) 175 refcnt = 0; 176 #endif 177 } 178 179 virtual ~VBoxCallback() {} 180 181 NS_DECL_ISUPPORTS 182 183 #if defined (Q_OS_WIN32) 184 STDMETHOD_(ULONG, AddRef)() 185 { 186 return ::InterlockedIncrement (&refcnt); 187 } 188 STDMETHOD_(ULONG, Release)() 189 { 190 long cnt = ::InterlockedDecrement (&refcnt); 191 if (cnt == 0) 192 delete this; 193 return cnt; 194 } 195 #endif 196 VBOX_SCRIPTABLE_DISPATCH_IMPL(IVirtualBoxCallback) 197 198 // IVirtualBoxCallback methods 199 200 // Note: we need to post custom events to the GUI event queue 201 // instead of doing what we need directly from here because on Win32 202 // these callback methods are never called on the main GUI thread. 203 // Another reason to handle events asynchronously is that internally 204 // most callback interface methods are called from under the initiator 205 // object's lock, so accessing the initiator object (for example, reading 206 // some property) directly from the callback method will definitely cause 207 // a deadlock. 208 209 STDMETHOD(OnMachineStateChange) (IN_BSTR id, MachineState_T state) 210 { 211 postEvent (new VBoxMachineStateChangeEvent (QString::fromUtf16(id), 212 (KMachineState) state)); 213 return S_OK; 214 } 215 216 STDMETHOD(OnMachineDataChange) (IN_BSTR id) 217 { 218 postEvent (new VBoxMachineDataChangeEvent (QString::fromUtf16(id))); 219 return S_OK; 220 } 221 222 STDMETHOD(OnExtraDataCanChange)(IN_BSTR id, 223 IN_BSTR key, IN_BSTR value, 224 BSTR *error, BOOL *allowChange) 225 { 226 if (!error || !allowChange) 227 return E_INVALIDARG; 228 229 if (com::asGuidStr(id).isEmpty()) 230 { 231 /* it's a global extra data key someone wants to change */ 232 QString sKey = QString::fromUtf16 (key); 233 QString sVal = QString::fromUtf16 (value); 234 if (sKey.startsWith ("GUI/")) 235 { 236 if (sKey == VBoxDefs::GUI_RegistrationDlgWinID) 237 { 238 if (mIsRegDlgOwner) 239 { 240 if (sVal.isEmpty() || 241 sVal == QString ("%1") 242 .arg ((qulonglong) vboxGlobal().mainWindow()->winId())) 243 *allowChange = TRUE; 244 else 245 *allowChange = FALSE; 246 } 247 else 248 *allowChange = TRUE; 249 return S_OK; 250 } 251 252 if (sKey == VBoxDefs::GUI_UpdateDlgWinID) 253 { 254 if (mIsUpdDlgOwner) 255 { 256 if (sVal.isEmpty() || 257 sVal == QString ("%1") 258 .arg ((qulonglong) vboxGlobal().mainWindow()->winId())) 259 *allowChange = TRUE; 260 else 261 *allowChange = FALSE; 262 } 263 else 264 *allowChange = TRUE; 265 return S_OK; 266 } 267 #ifdef VBOX_GUI_WITH_SYSTRAY 268 if (sKey == VBoxDefs::GUI_TrayIconWinID) 269 { 270 if (mIsTrayIconOwner) 271 { 272 if (sVal.isEmpty() || 273 sVal == QString ("%1") 274 .arg ((qulonglong) vboxGlobal().mainWindow()->winId())) 275 *allowChange = TRUE; 276 else 277 *allowChange = FALSE; 278 } 279 else 280 *allowChange = TRUE; 281 return S_OK; 282 } 283 #endif 284 /* try to set the global setting to check its syntax */ 285 VBoxGlobalSettings gs (false /* non-null */); 286 if (gs.setPublicProperty (sKey, sVal)) 287 { 288 /* this is a known GUI property key */ 289 if (!gs) 290 { 291 /* disallow the change when there is an error*/ 292 *error = SysAllocString ((const OLECHAR *) 293 (gs.lastError().isNull() ? 0 : gs.lastError().utf16())); 294 *allowChange = FALSE; 295 } 296 else 297 *allowChange = TRUE; 298 return S_OK; 299 } 300 } 301 } 302 303 /* not interested in this key -- never disagree */ 304 *allowChange = TRUE; 305 return S_OK; 306 } 307 308 STDMETHOD(OnExtraDataChange) (IN_BSTR id, 309 IN_BSTR key, IN_BSTR value) 310 { 311 if (com::asGuidStr(id).isEmpty()) 312 { 313 QString sKey = QString::fromUtf16 (key); 314 QString sVal = QString::fromUtf16 (value); 315 if (sKey.startsWith ("GUI/")) 316 { 317 if (sKey == VBoxDefs::GUI_RegistrationDlgWinID) 318 { 319 if (sVal.isEmpty()) 320 { 321 mIsRegDlgOwner = false; 322 QApplication::postEvent (&mGlobal, new VBoxCanShowRegDlgEvent (true)); 323 } 324 else if (sVal == QString ("%1") 325 .arg ((qulonglong) vboxGlobal().mainWindow()->winId())) 326 { 327 mIsRegDlgOwner = true; 328 QApplication::postEvent (&mGlobal, new VBoxCanShowRegDlgEvent (true)); 329 } 330 else 331 QApplication::postEvent (&mGlobal, new VBoxCanShowRegDlgEvent (false)); 332 } 333 if (sKey == VBoxDefs::GUI_UpdateDlgWinID) 334 { 335 if (sVal.isEmpty()) 336 { 337 mIsUpdDlgOwner = false; 338 QApplication::postEvent (&mGlobal, new VBoxCanShowUpdDlgEvent (true)); 339 } 340 else if (sVal == QString ("%1") 341 .arg ((qulonglong) vboxGlobal().mainWindow()->winId())) 342 { 343 mIsUpdDlgOwner = true; 344 QApplication::postEvent (&mGlobal, new VBoxCanShowUpdDlgEvent (true)); 345 } 346 else 347 QApplication::postEvent (&mGlobal, new VBoxCanShowUpdDlgEvent (false)); 348 } 349 if (sKey == "GUI/LanguageID") 350 QApplication::postEvent (&mGlobal, new VBoxChangeGUILanguageEvent (sVal)); 351 #ifdef VBOX_GUI_WITH_SYSTRAY 352 if (sKey == "GUI/MainWindowCount") 353 QApplication::postEvent (&mGlobal, new VBoxMainWindowCountChangeEvent (sVal.toInt())); 354 if (sKey == VBoxDefs::GUI_TrayIconWinID) 355 { 356 if (sVal.isEmpty()) 357 { 358 mIsTrayIconOwner = false; 359 QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (true)); 360 } 361 else if (sVal == QString ("%1") 362 .arg ((qulonglong) vboxGlobal().mainWindow()->winId())) 363 { 364 mIsTrayIconOwner = true; 365 QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (true)); 366 } 367 else 368 QApplication::postEvent (&mGlobal, new VBoxCanShowTrayIconEvent (false)); 369 } 370 if (sKey == "GUI/TrayIcon/Enabled") 371 QApplication::postEvent (&mGlobal, new VBoxChangeTrayIconEvent ((sVal.toLower() == "true") ? true : false)); 372 #endif 373 #ifdef Q_WS_MAC 374 if (sKey == VBoxDefs::GUI_PresentationModeEnabled) 375 { 376 /* Default to true if it is an empty value */ 377 QString testStr = sVal.toLower(); 378 bool f = (testStr.isEmpty() || testStr == "false"); 379 QApplication::postEvent (&mGlobal, new VBoxChangePresentationModeEvent (f)); 380 } 381 #endif 382 383 mMutex.lock(); 384 mGlobal.gset.setPublicProperty (sKey, sVal); 385 mMutex.unlock(); 386 Assert (!!mGlobal.gset); 387 } 388 } 389 #ifdef Q_WS_MAC 390 else if (mGlobal.isVMConsoleProcess()) 391 { 392 /* Check for the currently running machine */ 393 if (QString::fromUtf16(id) == mGlobal.vmUuid) 394 { 395 QString strKey = QString::fromUtf16(key); 396 QString strVal = QString::fromUtf16(value); 397 // TODO_NEW_CORE: we should cleanup 398 // VBoxChangeDockIconUpdateEvent to have no parameters. So it 399 // could really be use for both events and the consumer should 400 // ask per GetExtraData how the current values are. 401 if ( strKey == VBoxDefs::GUI_RealtimeDockIconUpdateEnabled 402 || strKey == VBoxDefs::GUI_RealtimeDockIconUpdateMonitor) 403 { 404 /* Default to true if it is an empty value */ 405 bool f = strVal.toLower() == "false" ? false : true; 406 QApplication::postEvent(&mGlobal, new VBoxChangeDockIconUpdateEvent(f)); 407 } 408 } 409 } 410 #endif /* Q_WS_MAC */ 411 return S_OK; 412 } 413 414 STDMETHOD(OnMediumRegistered) (IN_BSTR id, DeviceType_T type, 415 BOOL registered) 416 { 417 /** @todo */ 418 Q_UNUSED (id); 419 Q_UNUSED (type); 420 Q_UNUSED (registered); 421 return VBOX_E_DONT_CALL_AGAIN; 422 } 423 424 STDMETHOD(OnMachineRegistered) (IN_BSTR id, BOOL registered) 425 { 426 postEvent (new VBoxMachineRegisteredEvent (QString::fromUtf16(id), 427 registered)); 428 return S_OK; 429 } 430 431 STDMETHOD(OnSessionStateChange) (IN_BSTR id, SessionState_T state) 432 { 433 postEvent (new VBoxSessionStateChangeEvent (QString::fromUtf16(id), 434 (KSessionState) state)); 435 return S_OK; 436 } 437 438 STDMETHOD(OnSnapshotTaken) (IN_BSTR aMachineId, IN_BSTR aSnapshotId) 439 { 440 postEvent (new VBoxSnapshotEvent (QString::fromUtf16(aMachineId), 441 QString::fromUtf16(aSnapshotId), 442 VBoxSnapshotEvent::Taken)); 443 return S_OK; 444 } 445 446 STDMETHOD(OnSnapshotDeleted) (IN_BSTR aMachineId, IN_BSTR aSnapshotId) 447 { 448 postEvent (new VBoxSnapshotEvent (QString::fromUtf16(aMachineId), 449 QString::fromUtf16(aSnapshotId), 450 VBoxSnapshotEvent::Deleted)); 451 return S_OK; 452 } 453 454 STDMETHOD(OnSnapshotChange) (IN_BSTR aMachineId, IN_BSTR aSnapshotId) 455 { 456 postEvent (new VBoxSnapshotEvent (QString::fromUtf16(aMachineId), 457 QString::fromUtf16(aSnapshotId), 458 VBoxSnapshotEvent::Changed)); 459 return S_OK; 460 } 461 462 STDMETHOD(OnGuestPropertyChange) (IN_BSTR /* id */, 463 IN_BSTR /* key */, 464 IN_BSTR /* value */, 465 IN_BSTR /* flags */) 466 { 467 return VBOX_E_DONT_CALL_AGAIN; 468 } 469 470 private: 471 472 void postEvent (QEvent *e) 473 { 474 // currently, we don't post events if we are in the VM execution 475 // console mode, to save some CPU ticks (so far, there was no need 476 // to handle VirtualBox callback events in the execution console mode) 477 if (!mGlobal.isVMConsoleProcess()) 478 QApplication::postEvent (&mGlobal, e); 479 } 480 481 VBoxGlobal &mGlobal; 482 483 /** protects #OnExtraDataChange() */ 484 QMutex mMutex; 485 486 bool mIsRegDlgOwner; 487 bool mIsUpdDlgOwner; 488 #ifdef VBOX_GUI_WITH_SYSTRAY 489 bool mIsTrayIconOwner; 490 #endif 491 492 #if defined (Q_OS_WIN32) 493 private: 494 long refcnt; 495 #endif 496 }; 497 498 #if !defined (Q_OS_WIN32) 499 NS_DECL_CLASSINFO (VBoxCallback) 500 NS_IMPL_THREADSAFE_ISUPPORTS1_CI (VBoxCallback, IVirtualBoxCallback) 501 #endif 502 503 // VBoxGlobal 504 //////////////////////////////////////////////////////////////////////////////// 505 506 static bool sVBoxGlobalInited = false; 507 static bool sVBoxGlobalInCleanup = false; 508 509 /** @internal 510 * 511 * Special routine to do VBoxGlobal cleanup when the application is being 512 * terminated. It is called before some essential Qt functionality (for 513 * instance, QThread) becomes unavailable, allowing us to use it from 514 * VBoxGlobal::cleanup() if necessary. 515 */ 516 static void vboxGlobalCleanup() 517 { 518 Assert (!sVBoxGlobalInCleanup); 519 sVBoxGlobalInCleanup = true; 520 vboxGlobal().cleanup(); 521 } 522 523 /** @internal 524 * 525 * Determines the rendering mode from the argument. Sets the appropriate 526 * default rendering mode if the argumen is NULL. 527 */ 528 static VBoxDefs::RenderMode vboxGetRenderMode (const char *aModeStr) 529 { 530 VBoxDefs::RenderMode mode = VBoxDefs::InvalidRenderMode; 531 532 #if defined (Q_WS_MAC) && defined (VBOX_GUI_USE_QUARTZ2D) 533 mode = VBoxDefs::Quartz2DMode; 534 # ifdef RT_ARCH_X86 535 /* Quartz2DMode doesn't refresh correctly on 32-bit Snow Leopard, use image mode. */ 536 // char szRelease[80]; 537 // if ( RT_SUCCESS (RTSystemQueryOSInfo (RTSYSOSINFO_RELEASE, szRelease, sizeof (szRelease))) 538 // && !strncmp (szRelease, "10.", 3)) 539 // mode = VBoxDefs::QImageMode; 540 # endif 541 #elif (defined (Q_WS_WIN32) || defined (Q_WS_PM) || defined (Q_WS_X11)) && defined (VBOX_GUI_USE_QIMAGE) 542 mode = VBoxDefs::QImageMode; 543 #elif defined (Q_WS_X11) && defined (VBOX_GUI_USE_SDL) 544 mode = VBoxDefs::SDLMode; 545 #elif defined (VBOX_GUI_USE_QIMAGE) 546 mode = VBoxDefs::QImageMode; 547 #else 548 # error "Cannot determine the default render mode!" 549 #endif 550 551 if (aModeStr) 552 { 553 if (0) ; 554 #if defined (VBOX_GUI_USE_QIMAGE) 555 else if (::strcmp (aModeStr, "image") == 0) 556 mode = VBoxDefs::QImageMode; 557 #endif 558 #if defined (VBOX_GUI_USE_SDL) 559 else if (::strcmp (aModeStr, "sdl") == 0) 560 mode = VBoxDefs::SDLMode; 561 #endif 562 #if defined (VBOX_GUI_USE_DDRAW) 563 else if (::strcmp (aModeStr, "ddraw") == 0) 564 mode = VBoxDefs::DDRAWMode; 565 #endif 566 #if defined (VBOX_GUI_USE_QUARTZ2D) 567 else if (::strcmp (aModeStr, "quartz2d") == 0) 568 mode = VBoxDefs::Quartz2DMode; 569 #endif 570 #if defined (VBOX_GUI_USE_QGLFB) 571 else if (::strcmp (aModeStr, "qgl") == 0) 572 mode = VBoxDefs::QGLMode; 573 #endif 574 //#if defined (VBOX_GUI_USE_QGL) 575 // else if (::strcmp (aModeStr, "qgloverlay") == 0) 576 // mode = VBoxDefs::QGLOverlayMode; 577 //#endif 578 579 } 580 581 return mode; 582 } 583 584 /** @class VBoxGlobal 585 * 586 * The VBoxGlobal class incapsulates the global VirtualBox data. 587 * 588 * There is only one instance of this class per VirtualBox application, 589 * the reference to it is returned by the static instance() method, or by 590 * the global vboxGlobal() function, that is just an inlined shortcut. 591 */ 592 593 VBoxGlobal::VBoxGlobal() 594 : mValid (false) 595 , mSelectorWnd (NULL) 596 , m_pVirtualMachine(0) 597 , mMainWindow (NULL) 598 #ifdef VBOX_WITH_REGISTRATION 599 , mRegDlg (NULL) 600 #endif 601 , mUpdDlg (NULL) 602 #ifdef VBOX_GUI_WITH_SYSTRAY 603 , mIsTrayMenu (false) 604 , mIncreasedWindowCounter (false) 605 #endif 606 , mMediaEnumThread (NULL) 607 , mIsKWinManaged (false) 608 , mVerString ("1.0") 609 { 610 } 611 612 // 613 // Public members 614 ///////////////////////////////////////////////////////////////////////////// 615 616 /** 617 * Returns a reference to the global VirtualBox data, managed by this class. 618 * 619 * The main() function of the VBox GUI must call this function soon after 620 * creating a QApplication instance but before opening any of the main windows 621 * (to let the VBoxGlobal initialization procedure use various Qt facilities), 622 * and continue execution only when the isValid() method of the returned 623 * instancereturns true, i.e. do something like: 624 * 625 * @code 626 * if ( !VBoxGlobal::instance().isValid() ) 627 * return 1; 628 * @endcode 629 * or 630 * @code 631 * if ( !vboxGlobal().isValid() ) 632 * return 1; 633 * @endcode 634 * 635 * @note Some VBoxGlobal methods can be used on a partially constructed 636 * VBoxGlobal instance, i.e. from constructors and methods called 637 * from the VBoxGlobal::init() method, which obtain the instance 638 * using this instance() call or the ::vboxGlobal() function. Currently, such 639 * methods are: 640 * #vmStateText, #vmTypeIcon, #vmTypeText, #vmTypeTextList, #vmTypeFromText. 641 * 642 * @see ::vboxGlobal 643 */ 644 VBoxGlobal &VBoxGlobal::instance() 645 { 646 static VBoxGlobal vboxGlobal_instance; 647 648 if (!sVBoxGlobalInited) 649 { 650 /* check that a QApplication instance is created */ 651 if (qApp) 652 { 653 sVBoxGlobalInited = true; 654 vboxGlobal_instance.init(); 655 /* add our cleanup handler to the list of Qt post routines */ 656 qAddPostRoutine (vboxGlobalCleanup); 657 } 658 else 659 AssertMsgFailed (("Must construct a QApplication first!")); 660 } 661 return vboxGlobal_instance; 662 } 663 664 VBoxGlobal::~VBoxGlobal() 665 { 666 qDeleteAll (mOsTypeIcons); 667 qDeleteAll (mVMStateIcons); 668 qDeleteAll (mVMStateColors); 669 } 26 #include <QApplication> 27 #include <QWidget> 670 28 671 29 /* static */ 672 QString VBoxGlobal::qtRTVersionString() 673 { 674 return QString::fromLatin1 (qVersion()); 675 } 676 677 /* static */ 678 uint VBoxGlobal::qtRTVersion() 679 { 680 QString rt_ver_str = VBoxGlobal::qtRTVersionString(); 681 return (rt_ver_str.section ('.', 0, 0).toInt() << 16) + 682 (rt_ver_str.section ('.', 1, 1).toInt() << 8) + 683 rt_ver_str.section ('.', 2, 2).toInt(); 684 } 685 686 /* static */ 687 QString VBoxGlobal::qtCTVersionString() 688 { 689 return QString::fromLatin1 (QT_VERSION_STR); 690 } 691 692 /* static */ 693 uint VBoxGlobal::qtCTVersion() 694 { 695 QString ct_ver_str = VBoxGlobal::qtCTVersionString(); 696 return (ct_ver_str.section ('.', 0, 0).toInt() << 16) + 697 (ct_ver_str.section ('.', 1, 1).toInt() << 8) + 698 ct_ver_str.section ('.', 2, 2).toInt(); 699 } 700 701 /** 702 * Sets the new global settings and saves them to the VirtualBox server. 703 */ 704 bool VBoxGlobal::setSettings (const VBoxGlobalSettings &gs) 705 { 706 gs.save (mVBox); 707 708 if (!mVBox.isOk()) 709 { 710 vboxProblem().cannotSaveGlobalConfig (mVBox); 711 return false; 712 } 713 714 /* We don't assign gs to our gset member here, because VBoxCallback 715 * will update gset as necessary when new settings are successfullly 716 * sent to the VirtualBox server by gs.save(). */ 717 718 return true; 719 } 720 721 /** 722 * Returns a reference to the main VBox VM Selector window. 723 * The reference is valid until application termination. 724 * 725 * There is only one such a window per VirtualBox application. 726 */ 727 VBoxSelectorWnd &VBoxGlobal::selectorWnd() 728 { 729 AssertMsg (!vboxGlobal().isVMConsoleProcess(), 730 ("Must NOT be a VM console process")); 731 Assert (mValid); 732 733 if (!mSelectorWnd) 734 { 735 /* 736 * We pass the address of mSelectorWnd to the constructor to let it be 737 * initialized right after the constructor is called. It is necessary 738 * to avoid recursion, since this method may be (and will be) called 739 * from the below constructor or from constructors/methods it calls. 740 */ 741 VBoxSelectorWnd *w = new VBoxSelectorWnd (&mSelectorWnd, 0); 742 Assert (w == mSelectorWnd); 743 NOREF(w); 744 } 745 746 return *mSelectorWnd; 747 } 748 749 750 QWidget *VBoxGlobal::vmWindow() 751 { 752 if (isVMConsoleProcess()) 753 { 754 if (m_pVirtualMachine) 755 return m_pVirtualMachine->mainWindow(); 756 } 757 return NULL; 758 } 759 760 bool VBoxGlobal::createVirtualMachine(const CSession &session) 761 { 762 if (!m_pVirtualMachine && !session.isNull()) 763 { 764 UIMachine *pVirtualMachine = new UIMachine(&m_pVirtualMachine, session); 765 Assert(pVirtualMachine == m_pVirtualMachine); 766 NOREF(pVirtualMachine); 767 return true; 768 } 769 return false; 770 } 771 772 UIMachine* VBoxGlobal::virtualMachine() 773 { 774 return m_pVirtualMachine; 775 } 776 777 bool VBoxGlobal::brandingIsActive (bool aForce /* = false*/) 778 { 779 if (aForce) 780 return true; 781 782 if (mBrandingConfig.isEmpty()) 783 { 784 mBrandingConfig = QDir(QApplication::applicationDirPath()).absolutePath(); 785 mBrandingConfig += "/custom/custom.ini"; 786 } 787 return QFile::exists (mBrandingConfig); 788 } 789 790 /** 791 * Gets a value from the custom .ini file 792 */ 793 QString VBoxGlobal::brandingGetKey (QString aKey) 794 { 795 QSettings s(mBrandingConfig, QSettings::IniFormat); 796 return s.value(QString("%1").arg(aKey)).toString(); 797 } 798 799 #ifdef VBOX_GUI_WITH_SYSTRAY 800 801 /** 802 * Returns true if the current instance a systray menu only (started with 803 * "-systray" parameter). 804 */ 805 bool VBoxGlobal::isTrayMenu() const 806 { 807 return mIsTrayMenu; 808 } 809 810 void VBoxGlobal::setTrayMenu(bool aIsTrayMenu) 811 { 812 mIsTrayMenu = aIsTrayMenu; 813 } 814 815 /** 816 * Spawns a new selector window (process). 817 */ 818 void VBoxGlobal::trayIconShowSelector() 819 { 820 /* Get the path to the executable. */ 821 char path [RTPATH_MAX]; 822 RTPathAppPrivateArch (path, RTPATH_MAX); 823 size_t sz = strlen (path); 824 path [sz++] = RTPATH_DELIMITER; 825 path [sz] = 0; 826 char *cmd = path + sz; 827 sz = RTPATH_MAX - sz; 828 829 int rc = 0; 830 RTPROCESS pid = NIL_RTPROCESS; 831 RTENV env = RTENV_DEFAULT; 832 833 const char VirtualBox_exe[] = "VirtualBox" HOSTSUFF_EXE; 834 Assert (sz >= sizeof (VirtualBox_exe)); 835 strcpy (cmd, VirtualBox_exe); 836 const char * args[] = {path, 0 }; 837 # ifdef RT_OS_WINDOWS 838 rc = RTProcCreate (path, args, env, 0, &pid); 839 # else 840 rc = RTProcCreate (path, args, env, RTPROC_FLAGS_DAEMONIZE_DEPRECATED, &pid); 841 # endif 842 if (RT_FAILURE (rc)) 843 LogRel(("Systray: Failed to start new selector window! Path=%s, rc=%Rrc\n", path, rc)); 844 } 845 846 /** 847 * Tries to install the tray icon using the current instance (singleton). 848 * Returns true if this instance is the tray icon, false if not. 849 */ 850 bool VBoxGlobal::trayIconInstall() 851 { 852 int rc = 0; 853 QString strTrayWinID = mVBox.GetExtraData (VBoxDefs::GUI_TrayIconWinID); 854 if (false == strTrayWinID.isEmpty()) 855 { 856 /* Check if current tray icon is alive by writing some bogus value. */ 857 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, "0"); 858 if (mVBox.isOk()) 859 { 860 /* Current tray icon died - clean up. */ 861 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, NULL); 862 strTrayWinID.clear(); 863 } 864 } 865 866 /* Is there already a tray icon or is tray icon not active? */ 867 if ( (mIsTrayMenu == false) 868 && (vboxGlobal().settings().trayIconEnabled()) 869 && (QSystemTrayIcon::isSystemTrayAvailable()) 870 && (strTrayWinID.isEmpty())) 871 { 872 /* Get the path to the executable. */ 873 char path [RTPATH_MAX]; 874 RTPathAppPrivateArch (path, RTPATH_MAX); 875 size_t sz = strlen (path); 876 path [sz++] = RTPATH_DELIMITER; 877 path [sz] = 0; 878 char *cmd = path + sz; 879 sz = RTPATH_MAX - sz; 880 881 RTPROCESS pid = NIL_RTPROCESS; 882 RTENV env = RTENV_DEFAULT; 883 884 const char VirtualBox_exe[] = "VirtualBox" HOSTSUFF_EXE; 885 Assert (sz >= sizeof (VirtualBox_exe)); 886 strcpy (cmd, VirtualBox_exe); 887 const char * args[] = {path, "-systray", 0 }; 888 # ifdef RT_OS_WINDOWS /** @todo drop this once the RTProcCreate bug has been fixed */ 889 rc = RTProcCreate (path, args, env, 0, &pid); 890 # else 891 rc = RTProcCreate (path, args, env, RTPROC_FLAGS_DAEMONIZE_DEPRECATED, &pid); 892 # endif 893 894 if (RT_FAILURE (rc)) 895 { 896 LogRel(("Systray: Failed to start systray window! Path=%s, rc=%Rrc\n", path, rc)); 897 return false; 898 } 899 } 900 901 if (mIsTrayMenu) 902 { 903 // Use this selector for displaying the tray icon 904 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, 905 QString ("%1").arg ((qulonglong) vboxGlobal().mainWindow()->winId())); 906 907 /* The first process which can grab this "mutex" will win -> 908 * It will be the tray icon menu then. */ 909 if (mVBox.isOk()) 910 { 911 emit trayIconShow (*(new VBoxShowTrayIconEvent (true))); 912 return true; 913 } 914 } 915 916 return false; 917 } 918 919 #endif 920 921 #ifdef Q_WS_X11 922 QList<QRect> XGetDesktopList() 923 { 924 /* Prepare empty resulting list: */ 925 QList<QRect> result; 926 927 /* Get current display: */ 928 Display* pDisplay = QX11Info::display(); 929 930 /* If thats Xinerama desktop: */ 931 if (XineramaIsActive(pDisplay)) 932 { 933 /* Reading Xinerama data: */ 934 int iScreens = 0; 935 XineramaScreenInfo *pScreensData = XineramaQueryScreens(pDisplay, &iScreens); 936 937 /* Fill resulting list: */ 938 for (int i = 0; i < iScreens; ++ i) 939 result << QRect(pScreensData[i].x_org, pScreensData[i].y_org, 940 pScreensData[i].width, pScreensData[i].height); 941 942 /* Free screens data: */ 943 XFree(pScreensData); 944 } 945 946 /* Return resulting list: */ 947 return result; 948 } 949 950 QList<Window> XGetWindowIDList() 951 { 952 /* Get current display: */ 953 Display *pDisplay = QX11Info::display(); 954 955 /* Get virtual desktop window: */ 956 Window window = QX11Info::appRootWindow(); 957 958 /* Get 'client list' atom: */ 959 Atom propNameAtom = XInternAtom(pDisplay, "_NET_CLIENT_LIST", True /* only if exists */); 960 961 /* Prepare empty resulting list: */ 962 QList<Window> result; 963 964 /* If atom does not exists return empty list: */ 965 if (propNameAtom == None) 966 return result; 967 968 /* Get atom value: */ 969 Atom realAtomType = None; 970 int iRealFormat = 0; 971 unsigned long uItemsCount = 0; 972 unsigned long uBytesAfter = 0; 973 unsigned char *pData = 0; 974 int rc = XGetWindowProperty(pDisplay, window, propNameAtom, 975 0, 0x7fffffff /*LONG_MAX*/, False /* delete */, 976 XA_WINDOW, &realAtomType, &iRealFormat, 977 &uItemsCount, &uBytesAfter, &pData); 978 979 /* If get property is failed return empty list: */ 980 if (rc != Success) 981 return result; 982 983 /* Fill resulting list with win ids: */ 984 Window *pWindowData = reinterpret_cast<Window*>(pData); 985 for (ulong i = 0; i < uItemsCount; ++ i) 986 result << pWindowData[i]; 987 988 /* Releasing resources: */ 989 XFree(pData); 990 991 /* Return resulting list: */ 992 return result; 993 } 994 995 QList<ulong> XGetStrut(Window window) 996 { 997 /* Get current display: */ 998 Display *pDisplay = QX11Info::display(); 999 1000 /* Get 'strut' atom: */ 1001 Atom propNameAtom = XInternAtom(pDisplay, "_NET_WM_STRUT_PARTIAL", True /* only if exists */); 1002 1003 /* Prepare empty resulting list: */ 1004 QList<ulong> result; 1005 1006 /* If atom does not exists return empty list: */ 1007 if (propNameAtom == None) 1008 return result; 1009 1010 /* Get atom value: */ 1011 Atom realAtomType = None; 1012 int iRealFormat = 0; 1013 ulong uItemsCount = 0; 1014 ulong uBytesAfter = 0; 1015 unsigned char *pData = 0; 1016 int rc = XGetWindowProperty(pDisplay, window, propNameAtom, 1017 0, LONG_MAX, False /* delete */, 1018 XA_CARDINAL, &realAtomType, &iRealFormat, 1019 &uItemsCount, &uBytesAfter, &pData); 1020 1021 /* If get property is failed return empty list: */ 1022 if (rc != Success) 1023 return result; 1024 1025 /* Fill resulting list with strut shifts: */ 1026 ulong *pStrutsData = reinterpret_cast<ulong*>(pData); 1027 for (ulong i = 0; i < uItemsCount; ++ i) 1028 result << pStrutsData[i]; 1029 1030 /* Releasing resources: */ 1031 XFree(pData); 1032 1033 /* Return resulting list: */ 1034 return result; 1035 } 1036 #endif /* ifdef Q_WS_X11 */ 1037 1038 const QRect VBoxGlobal::availableGeometry(int iScreen) const 1039 { 1040 /* Prepare empty result: */ 1041 QRect result; 1042 1043 #ifdef Q_WS_X11 1044 1045 /* Get current display: */ 1046 Display* pDisplay = QX11Info::display(); 1047 1048 /* Get current application desktop: */ 1049 QDesktopWidget *pDesktopWidget = QApplication::desktop(); 1050 1051 /* If thats virtual desktop: */ 1052 if (pDesktopWidget->isVirtualDesktop()) 1053 { 1054 /* If thats Xinerama desktop: */ 1055 if (XineramaIsActive(pDisplay)) 1056 { 1057 /* Get desktops list: */ 1058 QList<QRect> desktops = XGetDesktopList(); 1059 1060 /* Combine to get full virtual region: */ 1061 QRegion virtualRegion; 1062 foreach (QRect desktop, desktops) 1063 virtualRegion += desktop; 1064 virtualRegion = virtualRegion.boundingRect(); 1065 1066 /* Remember initial virtual desktop: */ 1067 QRect virtualDesktop = virtualRegion.boundingRect(); 1068 //AssertMsgFailed(("LOG... Virtual desktop is: %dx%dx%dx%d\n", virtualDesktop.x(), virtualDesktop.y(), 1069 // virtualDesktop.width(), virtualDesktop.height())); 1070 1071 /* Set available geometry to screen geometry initially: */ 1072 result = desktops[iScreen]; 1073 1074 /* Feat available geometry of virtual desktop to respect all the struts: */ 1075 QList<Window> list = XGetWindowIDList(); 1076 for (int i = 0; i < list.size(); ++ i) 1077 { 1078 /* Get window: */ 1079 Window wid = list[i]; 1080 QList<ulong> struts = XGetStrut(wid); 1081 1082 /* If window has strut: */ 1083 if (struts.size()) 1084 { 1085 ulong uLeftShift = struts[0]; 1086 ulong uLeftFromY = struts[4]; 1087 ulong uLeftToY = struts[5]; 1088 1089 ulong uRightShift = struts[1]; 1090 ulong uRightFromY = struts[6]; 1091 ulong uRightToY = struts[7]; 1092 1093 ulong uTopShift = struts[2]; 1094 ulong uTopFromX = struts[8]; 1095 ulong uTopToX = struts[9]; 1096 1097 ulong uBottomShift = struts[3]; 1098 ulong uBottomFromX = struts[10]; 1099 ulong uBottomToX = struts[11]; 1100 1101 if (uLeftShift) 1102 { 1103 QRect sr(QPoint(0, uLeftFromY), 1104 QSize(uLeftShift, uLeftToY - uLeftFromY + 1)); 1105 1106 //AssertMsgFailed(("LOG... Subtract left strut: top-left: %dx%d, size: %dx%d\n", sr.x(), sr.y(), sr.width(), sr.height())); 1107 virtualRegion -= sr; 1108 } 1109 1110 if (uRightShift) 1111 { 1112 QRect sr(QPoint(virtualDesktop.x() + virtualDesktop.width() - uRightShift, uRightFromY), 1113 QSize(virtualDesktop.x() + virtualDesktop.width(), uRightToY - uRightFromY + 1)); 1114 1115 //AssertMsgFailed(("LOG... Subtract right strut: top-left: %dx%d, size: %dx%d\n", sr.x(), sr.y(), sr.width(), sr.height())); 1116 virtualRegion -= sr; 1117 } 1118 1119 if (uTopShift) 1120 { 1121 QRect sr(QPoint(uTopFromX, 0), 1122 QSize(uTopToX - uTopFromX + 1, uTopShift)); 1123 1124 //AssertMsgFailed(("LOG... Subtract top strut: top-left: %dx%d, size: %dx%d\n", sr.x(), sr.y(), sr.width(), sr.height())); 1125 virtualRegion -= sr; 1126 } 1127 1128 if (uBottomShift) 1129 { 1130 QRect sr(QPoint(uBottomFromX, virtualDesktop.y() + virtualDesktop.height() - uBottomShift), 1131 QSize(uBottomToX - uBottomFromX + 1, uBottomShift)); 1132 1133 //AssertMsgFailed(("LOG... Subtract bottom strut: top-left: %dx%d, size: %dx%d\n", sr.x(), sr.y(), sr.width(), sr.height())); 1134 virtualRegion -= sr; 1135 } 1136 } 1137 } 1138 1139 /* Get final available geometry: */ 1140 result = (virtualRegion & result).boundingRect(); 1141 } 1142 } 1143 1144 /* If result is still NULL: */ 1145 if (result.isNull()) 1146 { 1147 /* Use QT default functionality: */ 1148 result = pDesktopWidget->availableGeometry(iScreen); 1149 } 1150 1151 //AssertMsgFailed(("LOG... Final geometry: %dx%dx%dx%d\n", result.x(), result.y(), result.width(), result.height())); 1152 1153 #else /* ifdef Q_WS_X11 */ 1154 1155 result = QApplication::desktop()->availableGeometry(iScreen); 1156 1157 #endif /* ifndef Q_WS_X11 */ 1158 1159 return result; 1160 } 1161 1162 /** 1163 * Returns the list of few guest OS types, queried from 1164 * IVirtualBox corresponding to every family id. 1165 */ 1166 QList <CGuestOSType> VBoxGlobal::vmGuestOSFamilyList() const 1167 { 1168 QList <CGuestOSType> result; 1169 for (int i = 0 ; i < mFamilyIDs.size(); ++ i) 1170 result << mTypes [i][0]; 1171 return result; 1172 } 1173 1174 /** 1175 * Returns the list of all guest OS types, queried from 1176 * IVirtualBox corresponding to passed family id. 1177 */ 1178 QList <CGuestOSType> VBoxGlobal::vmGuestOSTypeList (const QString &aFamilyId) const 1179 { 1180 AssertMsg (mFamilyIDs.contains (aFamilyId), ("Family ID incorrect: '%s'.", aFamilyId.toLatin1().constData())); 1181 return mFamilyIDs.contains (aFamilyId) ? 1182 mTypes [mFamilyIDs.indexOf (aFamilyId)] : QList <CGuestOSType>(); 1183 } 1184 1185 /** 1186 * Returns the icon corresponding to the given guest OS type id. 1187 */ 1188 QPixmap VBoxGlobal::vmGuestOSTypeIcon (const QString &aTypeId) const 1189 { 1190 static const QPixmap none; 1191 QPixmap *p = mOsTypeIcons.value (aTypeId); 1192 AssertMsg (p, ("Icon for type '%s' must be defined.", aTypeId.toLatin1().constData())); 1193 return p ? *p : none; 1194 } 1195 1196 /** 1197 * Returns the guest OS type object corresponding to the given type id of list 1198 * containing OS types related to OS family determined by family id attribute. 1199 * If the index is invalid a null object is returned. 1200 */ 1201 CGuestOSType VBoxGlobal::vmGuestOSType (const QString &aTypeId, 1202 const QString &aFamilyId /* = QString::null */) const 1203 { 1204 QList <CGuestOSType> list; 1205 if (mFamilyIDs.contains (aFamilyId)) 1206 { 1207 list = mTypes [mFamilyIDs.indexOf (aFamilyId)]; 1208 } 1209 else 1210 { 1211 for (int i = 0; i < mFamilyIDs.size(); ++ i) 1212 list += mTypes [i]; 1213 } 1214 for (int j = 0; j < list.size(); ++ j) 1215 if (!list [j].GetId().compare (aTypeId)) 1216 return list [j]; 1217 AssertMsgFailed (("Type ID incorrect: '%s'.", aTypeId.toLatin1().constData())); 1218 return CGuestOSType(); 1219 } 1220 1221 /** 1222 * Returns the description corresponding to the given guest OS type id. 1223 */ 1224 QString VBoxGlobal::vmGuestOSTypeDescription (const QString &aTypeId) const 1225 { 1226 for (int i = 0; i < mFamilyIDs.size(); ++ i) 1227 { 1228 QList <CGuestOSType> list (mTypes [i]); 1229 for ( int j = 0; j < list.size(); ++ j) 1230 if (!list [j].GetId().compare (aTypeId)) 1231 return list [j].GetDescription(); 1232 } 1233 return QString::null; 1234 } 1235 1236 /** 1237 * Returns a string representation of the given channel number on the given storage bus. 1238 * Complementary to #toStorageChannel (KStorageBus, const QString &) const. 1239 */ 1240 QString VBoxGlobal::toString (KStorageBus aBus, LONG aChannel) const 1241 { 1242 QString channel; 1243 1244 switch (aBus) 1245 { 1246 case KStorageBus_IDE: 1247 { 1248 if (aChannel == 0 || aChannel == 1) 1249 { 1250 channel = mStorageBusChannels [aChannel]; 1251 break; 1252 } 1253 AssertMsgFailed (("Invalid IDE channel %d\n", aChannel)); 1254 break; 1255 } 1256 case KStorageBus_SATA: 1257 case KStorageBus_SCSI: 1258 { 1259 channel = mStorageBusChannels [2].arg (aChannel); 1260 break; 1261 } 1262 case KStorageBus_Floppy: 1263 { 1264 AssertMsgFailed (("Floppy have no channels, only devices\n")); 1265 break; 1266 } 1267 default: 1268 { 1269 AssertMsgFailed (("Invalid bus type %d\n", aBus)); 1270 break; 1271 } 1272 } 1273 1274 Assert (!channel.isNull()); 1275 return channel; 1276 } 1277 1278 /** 1279 * Returns a channel number on the given storage bus corresponding to the given string representation. 1280 * Complementary to #toString (KStorageBus, LONG) const. 1281 */ 1282 LONG VBoxGlobal::toStorageChannel (KStorageBus aBus, const QString &aChannel) const 1283 { 1284 LONG channel = 0; 1285 1286 switch (aBus) 1287 { 1288 case KStorageBus_IDE: 1289 { 1290 QLongStringHash::const_iterator it = qFind (mStorageBusChannels.begin(), mStorageBusChannels.end(), aChannel); 1291 AssertMsgBreak (it != mStorageBusChannels.end(), ("No value for {%s}\n", aChannel.toLatin1().constData())); 1292 channel = it.key(); 1293 break; 1294 } 1295 case KStorageBus_SATA: 1296 case KStorageBus_SCSI: 1297 { 1298 QString tpl = mStorageBusChannels [2].arg (""); 1299 if (aChannel.startsWith (tpl)) 1300 { 1301 channel = aChannel.right (aChannel.length() - tpl.length()).toLong(); 1302 break; 1303 } 1304 AssertMsgFailed (("Invalid channel {%s}\n", aChannel.toLatin1().constData())); 1305 break; 1306 } 1307 case KStorageBus_Floppy: 1308 { 1309 channel = 0; 1310 break; 1311 } 1312 default: 1313 { 1314 AssertMsgFailed (("Invalid bus type %d\n", aBus)); 1315 break; 1316 } 1317 } 1318 1319 return channel; 1320 } 1321 1322 /** 1323 * Returns a string representation of the given device number of the given channel on the given storage bus. 1324 * Complementary to #toStorageDevice (KStorageBus, LONG, const QString &) const. 1325 */ 1326 QString VBoxGlobal::toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const 1327 { 1328 NOREF (aChannel); 1329 1330 QString device; 1331 1332 switch (aBus) 1333 { 1334 case KStorageBus_IDE: 1335 { 1336 if (aDevice == 0 || aDevice == 1) 1337 { 1338 device = mStorageBusDevices [aDevice]; 1339 break; 1340 } 1341 AssertMsgFailed (("Invalid device %d\n", aDevice)); 1342 break; 1343 } 1344 case KStorageBus_SATA: 1345 case KStorageBus_SCSI: 1346 { 1347 AssertMsgFailed (("SATA & SCSI have no devices, only channels\n")); 1348 break; 1349 } 1350 case KStorageBus_Floppy: 1351 { 1352 AssertMsgBreak (aChannel == 0, ("Invalid channel %d\n", aChannel)); 1353 device = mStorageBusDevices [2].arg (aDevice); 1354 break; 1355 } 1356 default: 1357 { 1358 AssertMsgFailed (("Invalid bus type %d\n", aBus)); 1359 break; 1360 } 1361 } 1362 1363 Assert (!device.isNull()); 1364 return device; 1365 } 1366 1367 /** 1368 * Returns a device number of the given channel on the given storage bus corresponding to the given string representation. 1369 * Complementary to #toString (KStorageBus, LONG, LONG) const. 1370 */ 1371 LONG VBoxGlobal::toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const 1372 { 1373 NOREF (aChannel); 1374 1375 LONG device = 0; 1376 1377 switch (aBus) 1378 { 1379 case KStorageBus_IDE: 1380 { 1381 QLongStringHash::const_iterator it = qFind (mStorageBusDevices.begin(), mStorageBusDevices.end(), aDevice); 1382 AssertMsgBreak (it != mStorageBusDevices.end(), ("No value for {%s}", aDevice.toLatin1().constData())); 1383 device = it.key(); 1384 break; 1385 } 1386 case KStorageBus_SATA: 1387 case KStorageBus_SCSI: 1388 { 1389 device = 0; 1390 break; 1391 } 1392 case KStorageBus_Floppy: 1393 { 1394 AssertMsgBreak (aChannel == 0, ("Invalid channel %d\n", aChannel)); 1395 QString tpl = mStorageBusDevices [2].arg (""); 1396 if (aDevice.startsWith (tpl)) 1397 { 1398 device = aDevice.right (aDevice.length() - tpl.length()).toLong(); 1399 break; 1400 } 1401 AssertMsgFailed (("Invalid device {%s}\n", aDevice.toLatin1().constData())); 1402 break; 1403 } 1404 default: 1405 { 1406 AssertMsgFailed (("Invalid bus type %d\n", aBus)); 1407 break; 1408 } 1409 } 1410 1411 return device; 1412 } 1413 1414 /** 1415 * Returns a full string representation of the given device of the given channel on the given storage bus. 1416 * This method does not uses any separate string tags related to bus, channel, device, it has own 1417 * separately translated string tags allowing to translate a full slot name into human readable format 1418 * to be consistent with i18n. 1419 * Complementary to #toStorageSlot (const QString &) const. 1420 */ 1421 QString VBoxGlobal::toString (StorageSlot aSlot) const 1422 { 1423 switch (aSlot.bus) 1424 { 1425 case KStorageBus_IDE: 1426 case KStorageBus_SATA: 1427 case KStorageBus_SCSI: 1428 case KStorageBus_SAS: 1429 case KStorageBus_Floppy: 1430 break; 1431 1432 default: 1433 { 1434 AssertMsgFailed (("Invalid bus type %d\n", aSlot.bus)); 1435 break; 1436 } 1437 } 1438 1439 int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (aSlot.bus); 1440 int maxDevice = virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus (aSlot.bus); 1441 if (aSlot.port < 0 || aSlot.port > maxPort) 1442 AssertMsgFailed (("Invalid port %d\n", aSlot.port)); 1443 if (aSlot.device < 0 || aSlot.device > maxDevice) 1444 AssertMsgFailed (("Invalid device %d\n", aSlot.device)); 1445 1446 QString result; 1447 switch (aSlot.bus) 1448 { 1449 case KStorageBus_IDE: 1450 { 1451 result = mSlotTemplates [aSlot.port * maxDevice + aSlot.device]; 1452 break; 1453 } 1454 case KStorageBus_SATA: 1455 { 1456 result = mSlotTemplates [4].arg (aSlot.port); 1457 break; 1458 } 1459 case KStorageBus_SCSI: 1460 { 1461 result = mSlotTemplates [5].arg (aSlot.port); 1462 break; 1463 } 1464 case KStorageBus_SAS: 1465 { 1466 result = mSlotTemplates [6].arg (aSlot.port); 1467 break; 1468 } 1469 case KStorageBus_Floppy: 1470 { 1471 result = mSlotTemplates [7].arg (aSlot.device); 1472 break; 1473 } 1474 default: 1475 { 1476 AssertMsgFailed (("Invalid bus type %d\n", aSlot.bus)); 1477 break; 1478 } 1479 } 1480 return result; 1481 } 1482 1483 /** 1484 * Returns a StorageSlot based on the given device of the given channel on the given storage bus. 1485 * Complementary to #toFullString (StorageSlot) const. 1486 */ 1487 StorageSlot VBoxGlobal::toStorageSlot (const QString &aSlot) const 1488 { 1489 int index = -1; 1490 QRegExp regExp; 1491 for (int i = 0; i < mSlotTemplates.size(); ++ i) 1492 { 1493 regExp = QRegExp (i >= 0 && i <= 3 ? mSlotTemplates [i] : mSlotTemplates [i].arg ("(\\d+)")); 1494 if (regExp.indexIn (aSlot) != -1) 1495 { 1496 index = i; 1497 break; 1498 } 1499 } 1500 1501 StorageSlot result; 1502 switch (index) 1503 { 1504 case 0: 1505 case 1: 1506 case 2: 1507 case 3: 1508 { 1509 result.bus = KStorageBus_IDE; 1510 int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (result.bus); 1511 result.port = index / maxPort; 1512 result.device = index % maxPort; 1513 break; 1514 } 1515 case 4: 1516 { 1517 result.bus = KStorageBus_SATA; 1518 int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (result.bus); 1519 result.port = regExp.cap (1).toInt(); 1520 if (result.port < 0 || result.port > maxPort) 1521 AssertMsgFailed (("Invalid port %d\n", result.port)); 1522 break; 1523 } 1524 case 5: 1525 { 1526 result.bus = KStorageBus_SCSI; 1527 int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (result.bus); 1528 result.port = regExp.cap (1).toInt(); 1529 if (result.port < 0 || result.port > maxPort) 1530 AssertMsgFailed (("Invalid port %d\n", result.port)); 1531 break; 1532 } 1533 case 6: 1534 { 1535 result.bus = KStorageBus_SAS; 1536 int maxPort = virtualBox().GetSystemProperties().GetMaxPortCountForStorageBus (result.bus); 1537 result.port = regExp.cap (1).toInt(); 1538 if (result.port < 0 || result.port > maxPort) 1539 AssertMsgFailed (("Invalid port %d\n", result.port)); 1540 break; 1541 } 1542 case 7: 1543 { 1544 result.bus = KStorageBus_Floppy; 1545 int maxDevice = virtualBox().GetSystemProperties().GetMaxDevicesPerPortForStorageBus (result.bus); 1546 result.device = regExp.cap (1).toInt(); 1547 if (result.device < 0 || result.device > maxDevice) 1548 AssertMsgFailed (("Invalid device %d\n", result.device)); 1549 break; 1550 } 1551 default: 1552 break; 1553 } 1554 return result; 1555 } 1556 1557 /** 1558 * Returns the list of all device types (VirtualBox::DeviceType COM enum). 1559 */ 1560 QStringList VBoxGlobal::deviceTypeStrings() const 1561 { 1562 static QStringList list; 1563 if (list.empty()) 1564 for (QULongStringHash::const_iterator it = mDeviceTypes.begin(); 1565 it != mDeviceTypes.end(); ++ it) 1566 list += it.value(); 1567 return list; 1568 } 1569 1570 struct PortConfig 1571 { 1572 const char *name; 1573 const ulong IRQ; 1574 const ulong IOBase; 1575 }; 1576 1577 static const PortConfig kComKnownPorts[] = 1578 { 1579 { "COM1", 4, 0x3F8 }, 1580 { "COM2", 3, 0x2F8 }, 1581 { "COM3", 4, 0x3E8 }, 1582 { "COM4", 3, 0x2E8 }, 1583 /* must not contain an element with IRQ=0 and IOBase=0 used to cause 1584 * toCOMPortName() to return the "User-defined" string for these values. */ 1585 }; 1586 1587 static const PortConfig kLptKnownPorts[] = 1588 { 1589 { "LPT1", 7, 0x3BC }, 1590 { "LPT2", 5, 0x378 }, 1591 { "LPT3", 5, 0x278 }, 1592 /* must not contain an element with IRQ=0 and IOBase=0 used to cause 1593 * toLPTPortName() to return the "User-defined" string for these values. */ 1594 }; 1595 1596 /** 1597 * Returns the list of the standard COM port names (i.e. "COMx"). 1598 */ 1599 QStringList VBoxGlobal::COMPortNames() const 1600 { 1601 QStringList list; 1602 for (size_t i = 0; i < RT_ELEMENTS (kComKnownPorts); ++ i) 1603 list << kComKnownPorts [i].name; 1604 1605 return list; 1606 } 1607 1608 /** 1609 * Returns the list of the standard LPT port names (i.e. "LPTx"). 1610 */ 1611 QStringList VBoxGlobal::LPTPortNames() const 1612 { 1613 QStringList list; 1614 for (size_t i = 0; i < RT_ELEMENTS (kLptKnownPorts); ++ i) 1615 list << kLptKnownPorts [i].name; 1616 1617 return list; 1618 } 1619 1620 /** 1621 * Returns the name of the standard COM port corresponding to the given 1622 * parameters, or "User-defined" (which is also returned when both 1623 * @a aIRQ and @a aIOBase are 0). 1624 */ 1625 QString VBoxGlobal::toCOMPortName (ulong aIRQ, ulong aIOBase) const 1626 { 1627 for (size_t i = 0; i < RT_ELEMENTS (kComKnownPorts); ++ i) 1628 if (kComKnownPorts [i].IRQ == aIRQ && 1629 kComKnownPorts [i].IOBase == aIOBase) 1630 return kComKnownPorts [i].name; 1631 1632 return mUserDefinedPortName; 1633 } 1634 1635 /** 1636 * Returns the name of the standard LPT port corresponding to the given 1637 * parameters, or "User-defined" (which is also returned when both 1638 * @a aIRQ and @a aIOBase are 0). 1639 */ 1640 QString VBoxGlobal::toLPTPortName (ulong aIRQ, ulong aIOBase) const 1641 { 1642 for (size_t i = 0; i < RT_ELEMENTS (kLptKnownPorts); ++ i) 1643 if (kLptKnownPorts [i].IRQ == aIRQ && 1644 kLptKnownPorts [i].IOBase == aIOBase) 1645 return kLptKnownPorts [i].name; 1646 1647 return mUserDefinedPortName; 1648 } 1649 1650 /** 1651 * Returns port parameters corresponding to the given standard COM name. 1652 * Returns @c true on success, or @c false if the given port name is not one 1653 * of the standard names (i.e. "COMx"). 1654 */ 1655 bool VBoxGlobal::toCOMPortNumbers (const QString &aName, ulong &aIRQ, 1656 ulong &aIOBase) const 1657 { 1658 for (size_t i = 0; i < RT_ELEMENTS (kComKnownPorts); ++ i) 1659 if (strcmp (kComKnownPorts [i].name, aName.toUtf8().data()) == 0) 1660 { 1661 aIRQ = kComKnownPorts [i].IRQ; 1662 aIOBase = kComKnownPorts [i].IOBase; 1663 return true; 1664 } 1665 1666 return false; 1667 } 1668 1669 /** 1670 * Returns port parameters corresponding to the given standard LPT name. 1671 * Returns @c true on success, or @c false if the given port name is not one 1672 * of the standard names (i.e. "LPTx"). 1673 */ 1674 bool VBoxGlobal::toLPTPortNumbers (const QString &aName, ulong &aIRQ, 1675 ulong &aIOBase) const 1676 { 1677 for (size_t i = 0; i < RT_ELEMENTS (kLptKnownPorts); ++ i) 1678 if (strcmp (kLptKnownPorts [i].name, aName.toUtf8().data()) == 0) 1679 { 1680 aIRQ = kLptKnownPorts [i].IRQ; 1681 aIOBase = kLptKnownPorts [i].IOBase; 1682 return true; 1683 } 1684 1685 return false; 1686 } 1687 1688 /** 1689 * Searches for the given hard disk in the list of known media descriptors and 1690 * calls VBoxMedium::details() on the found desriptor. 1691 * 1692 * If the requeststed hard disk is not found (for example, it's a new hard disk 1693 * for a new VM created outside our UI), then media enumeration is requested and 1694 * the search is repeated. We assume that the secont attempt always succeeds and 1695 * assert otherwise. 1696 * 1697 * @note Technically, the second attempt may fail if, for example, the new hard 1698 * passed to this method disk gets removed before #startEnumeratingMedia() 1699 * succeeds. This (unexpected object uninitialization) is a generic 1700 * problem though and needs to be addressed using exceptions (see also the 1701 * @todo in VBoxMedium::details()). 1702 */ 1703 QString VBoxGlobal::details (const CMedium &aMedium, bool aPredictDiff) 1704 { 1705 CMedium cmedium (aMedium); 1706 VBoxMedium medium; 1707 1708 if (!findMedium (cmedium, medium)) 1709 { 1710 /* Medium may be new and not already in the media list, request refresh */ 1711 startEnumeratingMedia(); 1712 if (!findMedium (cmedium, medium)) 1713 /* Medium might be deleted already, return null string */ 1714 return QString(); 1715 } 1716 1717 return medium.detailsHTML (true /* aNoDiffs */, aPredictDiff); 1718 } 1719 1720 /** 1721 * Returns the details of the given USB device as a single-line string. 1722 */ 1723 QString VBoxGlobal::details (const CUSBDevice &aDevice) const 1724 { 1725 QString sDetails; 1726 if (aDevice.isNull()) 1727 sDetails = tr("Unknown device", "USB device details"); 1728 else 1729 { 1730 QString m = aDevice.GetManufacturer().trimmed(); 1731 QString p = aDevice.GetProduct().trimmed(); 1732 1733 if (m.isEmpty() && p.isEmpty()) 1734 { 1735 sDetails = 1736 tr ("Unknown device %1:%2", "USB device details") 1737 .arg (QString().sprintf ("%04hX", aDevice.GetVendorId())) 1738 .arg (QString().sprintf ("%04hX", aDevice.GetProductId())); 1739 } 1740 else 1741 { 1742 if (p.toUpper().startsWith (m.toUpper())) 1743 sDetails = p; 1744 else 1745 sDetails = m + " " + p; 1746 } 1747 ushort r = aDevice.GetRevision(); 1748 if (r != 0) 1749 sDetails += QString().sprintf (" [%04hX]", r); 1750 } 1751 1752 return sDetails.trimmed(); 1753 } 1754 1755 /** 1756 * Returns the multi-line description of the given USB device. 1757 */ 1758 QString VBoxGlobal::toolTip (const CUSBDevice &aDevice) const 1759 { 1760 QString tip = 1761 tr ("<nobr>Vendor ID: %1</nobr><br>" 1762 "<nobr>Product ID: %2</nobr><br>" 1763 "<nobr>Revision: %3</nobr>", "USB device tooltip") 1764 .arg (QString().sprintf ("%04hX", aDevice.GetVendorId())) 1765 .arg (QString().sprintf ("%04hX", aDevice.GetProductId())) 1766 .arg (QString().sprintf ("%04hX", aDevice.GetRevision())); 1767 1768 QString ser = aDevice.GetSerialNumber(); 1769 if (!ser.isEmpty()) 1770 tip += QString (tr ("<br><nobr>Serial No. %1</nobr>", "USB device tooltip")) 1771 .arg (ser); 1772 1773 /* add the state field if it's a host USB device */ 1774 CHostUSBDevice hostDev (aDevice); 1775 if (!hostDev.isNull()) 1776 { 1777 tip += QString (tr ("<br><nobr>State: %1</nobr>", "USB device tooltip")) 1778 .arg (vboxGlobal().toString (hostDev.GetState())); 1779 } 1780 1781 return tip; 1782 } 1783 1784 /** 1785 * Returns the multi-line description of the given USB filter 1786 */ 1787 QString VBoxGlobal::toolTip (const CUSBDeviceFilter &aFilter) const 1788 { 1789 QString tip; 1790 1791 QString vendorId = aFilter.GetVendorId(); 1792 if (!vendorId.isEmpty()) 1793 tip += tr ("<nobr>Vendor ID: %1</nobr>", "USB filter tooltip") 1794 .arg (vendorId); 1795 1796 QString productId = aFilter.GetProductId(); 1797 if (!productId.isEmpty()) 1798 tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Product ID: %2</nobr>", "USB filter tooltip") 1799 .arg (productId); 1800 1801 QString revision = aFilter.GetRevision(); 1802 if (!revision.isEmpty()) 1803 tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Revision: %3</nobr>", "USB filter tooltip") 1804 .arg (revision); 1805 1806 QString product = aFilter.GetProduct(); 1807 if (!product.isEmpty()) 1808 tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Product: %4</nobr>", "USB filter tooltip") 1809 .arg (product); 1810 1811 QString manufacturer = aFilter.GetManufacturer(); 1812 if (!manufacturer.isEmpty()) 1813 tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Manufacturer: %5</nobr>", "USB filter tooltip") 1814 .arg (manufacturer); 1815 1816 QString serial = aFilter.GetSerialNumber(); 1817 if (!serial.isEmpty()) 1818 tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Serial No.: %1</nobr>", "USB filter tooltip") 1819 .arg (serial); 1820 1821 QString port = aFilter.GetPort(); 1822 if (!port.isEmpty()) 1823 tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>Port: %1</nobr>", "USB filter tooltip") 1824 .arg (port); 1825 1826 /* add the state field if it's a host USB device */ 1827 CHostUSBDevice hostDev (aFilter); 1828 if (!hostDev.isNull()) 1829 { 1830 tip += tip.isEmpty() ? "":"<br/>" + tr ("<nobr>State: %1</nobr>", "USB filter tooltip") 1831 .arg (vboxGlobal().toString (hostDev.GetState())); 1832 } 1833 1834 return tip; 1835 } 1836 1837 /** 1838 * Returns a details report on a given VM represented as a HTML table. 1839 * 1840 * @param aMachine Machine to create a report for. 1841 * @param aWithLinks @c true if section titles should be hypertext links. 1842 */ 1843 QString VBoxGlobal::detailsReport (const CMachine &aMachine, bool aWithLinks) 1844 { 1845 /* Details templates */ 1846 static const char *sTableTpl = 1847 "<table border=0 cellspacing=1 cellpadding=0>%1</table>"; 1848 static const char *sSectionHrefTpl = 1849 "<tr><td width=22 rowspan=%1 align=left><img src='%2'></td>" 1850 "<td colspan=3><b><a href='%3'><nobr>%4</nobr></a></b></td></tr>" 1851 "%5" 1852 "<tr><td colspan=3><font size=1> </font></td></tr>"; 1853 static const char *sSectionBoldTpl = 1854 "<tr><td width=22 rowspan=%1 align=left><img src='%2'></td>" 1855 "<td colspan=3><!-- %3 --><b><nobr>%4</nobr></b></td></tr>" 1856 "%5" 1857 "<tr><td colspan=3><font size=1> </font></td></tr>"; 1858 static const char *sSectionItemTpl1 = 1859 "<tr><td width=40%><nobr><i>%1</i></nobr></td><td/><td/></tr>"; 1860 static const char *sSectionItemTpl2 = 1861 "<tr><td width=40%><nobr>%1:</nobr></td><td/><td>%2</td></tr>"; 1862 static const char *sSectionItemTpl3 = 1863 "<tr><td width=40%><nobr>%1</nobr></td><td/><td/></tr>"; 1864 1865 const QString §ionTpl = aWithLinks ? sSectionHrefTpl : sSectionBoldTpl; 1866 1867 /* Compose details report */ 1868 QString report; 1869 1870 /* General */ 1871 { 1872 QString item = QString (sSectionItemTpl2).arg (tr ("Name", "details report"), 1873 aMachine.GetName()) 1874 + QString (sSectionItemTpl2).arg (tr ("OS Type", "details report"), 1875 vmGuestOSTypeDescription (aMachine.GetOSTypeId())); 1876 1877 report += sectionTpl 1878 .arg (2 + 2) /* rows */ 1879 .arg (":/machine_16px.png", /* icon */ 1880 "#general", /* link */ 1881 tr ("General", "details report"), /* title */ 1882 item); /* items */ 1883 } 1884 1885 /* System */ 1886 { 1887 /* BIOS Settings holder */ 1888 CBIOSSettings biosSettings = aMachine.GetBIOSSettings(); 1889 1890 /* System details row count: */ 1891 int iRowCount = 2; /* Memory & CPU details rows initially. */ 1892 1893 /* Boot order */ 1894 QString bootOrder; 1895 for (ulong i = 1; i <= mVBox.GetSystemProperties().GetMaxBootPosition(); ++ i) 1896 { 1897 KDeviceType device = aMachine.GetBootOrder (i); 1898 if (device == KDeviceType_Null) 1899 continue; 1900 if (!bootOrder.isEmpty()) 1901 bootOrder += ", "; 1902 bootOrder += toString (device); 1903 } 1904 if (bootOrder.isEmpty()) 1905 bootOrder = toString (KDeviceType_Null); 1906 1907 iRowCount += 1; /* Boot-order row. */ 1908 1909 #ifdef VBOX_WITH_FULL_DETAILS_REPORT 1910 /* ACPI */ 1911 QString acpi = biosSettings.GetACPIEnabled() 1912 ? tr ("Enabled", "details report (ACPI)") 1913 : tr ("Disabled", "details report (ACPI)"); 1914 1915 /* IO APIC */ 1916 QString ioapic = biosSettings.GetIOAPICEnabled() 1917 ? tr ("Enabled", "details report (IO APIC)") 1918 : tr ("Disabled", "details report (IO APIC)"); 1919 1920 /* PAE/NX */ 1921 QString pae = aMachine.GetCpuProperty(KCpuPropertyType_PAE) 1922 ? tr ("Enabled", "details report (PAE/NX)") 1923 : tr ("Disabled", "details report (PAE/NX)"); 1924 1925 iRowCount += 3; /* Full report rows. */ 1926 #endif /* VBOX_WITH_FULL_DETAILS_REPORT */ 1927 1928 /* VT-x/AMD-V */ 1929 QString virt = aMachine.GetHWVirtExProperty(KHWVirtExPropertyType_Enabled) 1930 ? tr ("Enabled", "details report (VT-x/AMD-V)") 1931 : tr ("Disabled", "details report (VT-x/AMD-V)"); 1932 1933 /* Nested Paging */ 1934 QString nested = aMachine.GetHWVirtExProperty(KHWVirtExPropertyType_NestedPaging) 1935 ? tr ("Enabled", "details report (Nested Paging)") 1936 : tr ("Disabled", "details report (Nested Paging)"); 1937 1938 /* VT-x/AMD-V availability: */ 1939 bool fVTxAMDVSupported = virtualBox().GetHost().GetProcessorFeature(KProcessorFeature_HWVirtEx); 1940 1941 if (fVTxAMDVSupported) 1942 iRowCount += 2; /* VT-x/AMD-V items. */ 1943 1944 QString item = QString (sSectionItemTpl2).arg (tr ("Base Memory", "details report"), 1945 tr ("<nobr>%1 MB</nobr>", "details report")) 1946 .arg (aMachine.GetMemorySize()) 1947 + QString (sSectionItemTpl2).arg (tr ("Processor(s)", "details report"), 1948 tr ("<nobr>%1</nobr>", "details report")) 1949 .arg (aMachine.GetCPUCount()) 1950 + QString (sSectionItemTpl2).arg (tr ("Boot Order", "details report"), bootOrder) 1951 #ifdef VBOX_WITH_FULL_DETAILS_REPORT 1952 + QString (sSectionItemTpl2).arg (tr ("ACPI", "details report"), acpi) 1953 + QString (sSectionItemTpl2).arg (tr ("IO APIC", "details report"), ioapic) 1954 + QString (sSectionItemTpl2).arg (tr ("PAE/NX", "details report"), pae) 1955 #endif /* VBOX_WITH_FULL_DETAILS_REPORT */ 1956 ; 1957 1958 if (fVTxAMDVSupported) 1959 item += QString (sSectionItemTpl2).arg (tr ("VT-x/AMD-V", "details report"), virt) 1960 + QString (sSectionItemTpl2).arg (tr ("Nested Paging", "details report"), nested); 1961 1962 report += sectionTpl 1963 .arg (2 + iRowCount) /* rows */ 1964 .arg (":/chipset_16px.png", /* icon */ 1965 "#system", /* link */ 1966 tr ("System", "details report"), /* title */ 1967 item); /* items */ 1968 } 1969 1970 /* Display */ 1971 { 1972 /* Rows including section header and footer */ 1973 int rows = 2; 1974 1975 /* Video tab */ 1976 QString item = QString(sSectionItemTpl2) 1977 .arg(tr ("Video Memory", "details report"), 1978 tr ("<nobr>%1 MB</nobr>", "details report")) 1979 .arg(aMachine.GetVRAMSize()); 1980 ++rows; 1981 1982 int cGuestScreens = aMachine.GetMonitorCount(); 1983 if (cGuestScreens > 1) 1984 { 1985 item += QString(sSectionItemTpl2) 1986 .arg(tr("Screens", "details report")) 1987 .arg(cGuestScreens); 1988 ++rows; 1989 } 1990 1991 QString acc3d = aMachine.GetAccelerate3DEnabled() 1992 ? tr ("Enabled", "details report (3D Acceleration)") 1993 : tr ("Disabled", "details report (3D Acceleration)"); 1994 1995 item += QString(sSectionItemTpl2) 1996 .arg(tr("3D Acceleration", "details report"), acc3d); 1997 ++rows; 1998 1999 #ifdef VBOX_WITH_VIDEOHWACCEL 2000 QString acc2dVideo = aMachine.GetAccelerate2DVideoEnabled() 2001 ? tr ("Enabled", "details report (2D Video Acceleration)") 2002 : tr ("Disabled", "details report (2D Video Acceleration)"); 2003 2004 item += QString (sSectionItemTpl2) 2005 .arg (tr ("2D Video Acceleration", "details report"), acc2dVideo); 2006 ++ rows; 2007 #endif 2008 2009 /* VRDP tab */ 2010 CVRDPServer srv = aMachine.GetVRDPServer(); 2011 if (!srv.isNull()) 2012 { 2013 if (srv.GetEnabled()) 2014 item += QString (sSectionItemTpl2) 2015 .arg (tr ("Remote Display Server Port", "details report (VRDP Server)")) 2016 .arg (srv.GetPorts()); 2017 else 2018 item += QString (sSectionItemTpl2) 2019 .arg (tr ("Remote Display Server", "details report (VRDP Server)")) 2020 .arg (tr ("Disabled", "details report (VRDP Server)")); 2021 ++ rows; 2022 } 2023 2024 report += sectionTpl 2025 .arg (rows) /* rows */ 2026 .arg (":/vrdp_16px.png", /* icon */ 2027 "#display", /* link */ 2028 tr ("Display", "details report"), /* title */ 2029 item); /* items */ 2030 } 2031 2032 /* Storage */ 2033 { 2034 /* Rows including section header and footer */ 2035 int rows = 2; 2036 2037 QString item; 2038 2039 /* Iterate over the all machine controllers: */ 2040 CStorageControllerVector controllers = aMachine.GetStorageControllers(); 2041 for (int i = 0; i < controllers.size(); ++i) 2042 { 2043 /* Get current controller: */ 2044 const CStorageController &controller = controllers[i]; 2045 /* Add controller information: */ 2046 item += QString(sSectionItemTpl3).arg(controller.GetName()); 2047 ++ rows; 2048 2049 /* Populate sorted map with attachments information: */ 2050 QMap<StorageSlot,QString> attachmentsMap; 2051 CMediumAttachmentVector attachments = aMachine.GetMediumAttachmentsOfController(controller.GetName()); 2052 for (int j = 0; j < attachments.size(); ++j) 2053 { 2054 /* Get current attachment: */ 2055 const CMediumAttachment &attachment = attachments[j]; 2056 /* Prepare current storage slot: */ 2057 StorageSlot attachmentSlot(controller.GetBus(), attachment.GetPort(), attachment.GetDevice()); 2058 /* Append 'device slot name' with 'device type name' for CD/DVD devices only: */ 2059 QString strDeviceType = attachment.GetType() == KDeviceType_DVD ? tr("(CD/DVD)") : QString(); 2060 if (!strDeviceType.isNull()) 2061 strDeviceType.prepend(' '); 2062 /* Prepare current medium object: */ 2063 const CMedium &medium = attachment.GetMedium(); 2064 /* Prepare information about current medium & attachment: */ 2065 QString strAttachmentInfo = !attachment.isOk() ? QString() : 2066 QString(sSectionItemTpl2) 2067 .arg(QString(" ") + 2068 toString(StorageSlot(controller.GetBus(), 2069 attachment.GetPort(), 2070 attachment.GetDevice())) + strDeviceType) 2071 .arg(details(medium, false)); 2072 /* Insert that attachment into map: */ 2073 if (!strAttachmentInfo.isNull()) 2074 attachmentsMap.insert(attachmentSlot, strAttachmentInfo); 2075 } 2076 2077 /* Iterate over the sorted map with attachments information: */ 2078 QMapIterator<StorageSlot,QString> it(attachmentsMap); 2079 while (it.hasNext()) 2080 { 2081 /* Add controller information: */ 2082 it.next(); 2083 item += it.value(); 2084 ++rows; 2085 } 2086 } 2087 2088 if (item.isNull()) 2089 { 2090 item = QString (sSectionItemTpl1) 2091 .arg (tr ("Not Attached", "details report (Storage)")); 2092 ++ rows; 2093 } 2094 2095 report += sectionTpl 2096 .arg (rows) /* rows */ 2097 .arg (":/attachment_16px.png", /* icon */ 2098 "#storage", /* link */ 2099 tr ("Storage", "details report"), /* title */ 2100 item); /* items */ 2101 } 2102 2103 /* Audio */ 2104 { 2105 QString item; 2106 2107 CAudioAdapter audio = aMachine.GetAudioAdapter(); 2108 int rows = audio.GetEnabled() ? 3 : 2; 2109 if (audio.GetEnabled()) 2110 item = QString (sSectionItemTpl2) 2111 .arg (tr ("Host Driver", "details report (audio)"), 2112 toString (audio.GetAudioDriver())) + 2113 QString (sSectionItemTpl2) 2114 .arg (tr ("Controller", "details report (audio)"), 2115 toString (audio.GetAudioController())); 2116 else 2117 item = QString (sSectionItemTpl1) 2118 .arg (tr ("Disabled", "details report (audio)")); 2119 2120 report += sectionTpl 2121 .arg (rows + 1) /* rows */ 2122 .arg (":/sound_16px.png", /* icon */ 2123 "#audio", /* link */ 2124 tr ("Audio", "details report"), /* title */ 2125 item); /* items */ 2126 } 2127 2128 /* Network */ 2129 { 2130 QString item; 2131 2132 ulong count = mVBox.GetSystemProperties().GetNetworkAdapterCount(); 2133 int rows = 2; /* including section header and footer */ 2134 for (ulong slot = 0; slot < count; slot ++) 2135 { 2136 CNetworkAdapter adapter = aMachine.GetNetworkAdapter (slot); 2137 if (adapter.GetEnabled()) 2138 { 2139 KNetworkAttachmentType type = adapter.GetAttachmentType(); 2140 QString attType = toString (adapter.GetAdapterType()) 2141 .replace (QRegExp ("\\s\\(.+\\)"), " (%1)"); 2142 /* don't use the adapter type string for types that have 2143 * an additional symbolic network/interface name field, use 2144 * this name instead */ 2145 if (type == KNetworkAttachmentType_Bridged) 2146 attType = attType.arg (tr ("Bridged adapter, %1", 2147 "details report (network)").arg (adapter.GetHostInterface())); 2148 else if (type == KNetworkAttachmentType_Internal) 2149 attType = attType.arg (tr ("Internal network, '%1'", 2150 "details report (network)").arg (adapter.GetInternalNetwork())); 2151 else if (type == KNetworkAttachmentType_HostOnly) 2152 attType = attType.arg (tr ("Host-only adapter, '%1'", 2153 "details report (network)").arg (adapter.GetHostInterface())); 2154 #ifdef VBOX_WITH_VDE 2155 else if (type == KNetworkAttachmentType_VDE) 2156 attType = attType.arg (tr ("VDE network, '%1'", 2157 "details report (network)").arg (adapter.GetVDENetwork())); 2158 #endif 2159 else 2160 attType = attType.arg (vboxGlobal().toString (type)); 2161 2162 item += QString (sSectionItemTpl2) 2163 .arg (tr ("Adapter %1", "details report (network)") 2164 .arg (adapter.GetSlot() + 1)) 2165 .arg (attType); 2166 ++ rows; 2167 } 2168 } 2169 if (item.isNull()) 2170 { 2171 item = QString (sSectionItemTpl1) 2172 .arg (tr ("Disabled", "details report (network)")); 2173 ++ rows; 2174 } 2175 2176 report += sectionTpl 2177 .arg (rows) /* rows */ 2178 .arg (":/nw_16px.png", /* icon */ 2179 "#network", /* link */ 2180 tr ("Network", "details report"), /* title */ 2181 item); /* items */ 2182 } 2183 2184 /* Serial Ports */ 2185 { 2186 QString item; 2187 2188 ulong count = mVBox.GetSystemProperties().GetSerialPortCount(); 2189 int rows = 2; /* including section header and footer */ 2190 for (ulong slot = 0; slot < count; slot ++) 2191 { 2192 CSerialPort port = aMachine.GetSerialPort (slot); 2193 if (port.GetEnabled()) 2194 { 2195 KPortMode mode = port.GetHostMode(); 2196 QString data = 2197 toCOMPortName (port.GetIRQ(), port.GetIOBase()) + ", "; 2198 if (mode == KPortMode_HostPipe || 2199 mode == KPortMode_HostDevice || 2200 mode == KPortMode_RawFile) 2201 data += QString ("%1 (<nobr>%2</nobr>)") 2202 .arg (vboxGlobal().toString (mode)) 2203 .arg (QDir::toNativeSeparators (port.GetPath())); 2204 else 2205 data += toString (mode); 2206 2207 item += QString (sSectionItemTpl2) 2208 .arg (tr ("Port %1", "details report (serial ports)") 2209 .arg (port.GetSlot() + 1)) 2210 .arg (data); 2211 ++ rows; 2212 } 2213 } 2214 if (item.isNull()) 2215 { 2216 item = QString (sSectionItemTpl1) 2217 .arg (tr ("Disabled", "details report (serial ports)")); 2218 ++ rows; 2219 } 2220 2221 report += sectionTpl 2222 .arg (rows) /* rows */ 2223 .arg (":/serial_port_16px.png", /* icon */ 2224 "#serialPorts", /* link */ 2225 tr ("Serial Ports", "details report"), /* title */ 2226 item); /* items */ 2227 } 2228 2229 /* Parallel Ports */ 2230 { 2231 QString item; 2232 2233 ulong count = mVBox.GetSystemProperties().GetParallelPortCount(); 2234 int rows = 2; /* including section header and footer */ 2235 for (ulong slot = 0; slot < count; slot ++) 2236 { 2237 CParallelPort port = aMachine.GetParallelPort (slot); 2238 if (port.GetEnabled()) 2239 { 2240 QString data = 2241 toLPTPortName (port.GetIRQ(), port.GetIOBase()) + 2242 QString (" (<nobr>%1</nobr>)") 2243 .arg (QDir::toNativeSeparators (port.GetPath())); 2244 2245 item += QString (sSectionItemTpl2) 2246 .arg (tr ("Port %1", "details report (parallel ports)") 2247 .arg (port.GetSlot() + 1)) 2248 .arg (data); 2249 ++ rows; 2250 } 2251 } 2252 if (item.isNull()) 2253 { 2254 item = QString (sSectionItemTpl1) 2255 .arg (tr ("Disabled", "details report (parallel ports)")); 2256 ++ rows; 2257 } 2258 2259 /* Temporary disabled */ 2260 QString dummy = sectionTpl /* report += sectionTpl */ 2261 .arg (rows) /* rows */ 2262 .arg (":/parallel_port_16px.png", /* icon */ 2263 "#parallelPorts", /* link */ 2264 tr ("Parallel Ports", "details report"), /* title */ 2265 item); /* items */ 2266 } 2267 2268 /* USB */ 2269 { 2270 QString item; 2271 2272 CUSBController ctl = aMachine.GetUSBController(); 2273 if ( !ctl.isNull() 2274 && ctl.GetProxyAvailable()) 2275 { 2276 /* the USB controller may be unavailable (i.e. in VirtualBox OSE) */ 2277 2278 if (ctl.GetEnabled()) 2279 { 2280 CUSBDeviceFilterVector coll = ctl.GetDeviceFilters(); 2281 uint active = 0; 2282 for (int i = 0; i < coll.size(); ++i) 2283 if (coll[i].GetActive()) 2284 active ++; 2285 2286 item = QString (sSectionItemTpl2) 2287 .arg (tr ("Device Filters", "details report (USB)"), 2288 tr ("%1 (%2 active)", "details report (USB)") 2289 .arg (coll.size()).arg (active)); 2290 } 2291 else 2292 item = QString (sSectionItemTpl1) 2293 .arg (tr ("Disabled", "details report (USB)")); 2294 2295 report += sectionTpl 2296 .arg (2 + 1) /* rows */ 2297 .arg (":/usb_16px.png", /* icon */ 2298 "#usb", /* link */ 2299 tr ("USB", "details report"), /* title */ 2300 item); /* items */ 2301 } 2302 } 2303 2304 /* Shared Folders */ 2305 { 2306 QString item; 2307 2308 ulong count = aMachine.GetSharedFolders().size(); 2309 if (count > 0) 2310 { 2311 item = QString (sSectionItemTpl2) 2312 .arg (tr ("Shared Folders", "details report (shared folders)")) 2313 .arg (count); 2314 } 2315 else 2316 item = QString (sSectionItemTpl1) 2317 .arg (tr ("None", "details report (shared folders)")); 2318 2319 report += sectionTpl 2320 .arg (2 + 1) /* rows */ 2321 .arg (":/shared_folder_16px.png", /* icon */ 2322 "#sfolders", /* link */ 2323 tr ("Shared Folders", "details report"), /* title */ 2324 item); /* items */ 2325 } 2326 2327 return QString (sTableTpl). arg (report); 2328 } 2329 2330 QString VBoxGlobal::platformInfo() 2331 { 2332 QString platform; 2333 2334 #if defined (Q_OS_WIN) 2335 platform = "win"; 2336 #elif defined (Q_OS_LINUX) 2337 platform = "linux"; 2338 #elif defined (Q_OS_MACX) 2339 platform = "macosx"; 2340 #elif defined (Q_OS_OS2) 2341 platform = "os2"; 2342 #elif defined (Q_OS_FREEBSD) 2343 platform = "freebsd"; 2344 #elif defined (Q_OS_SOLARIS) 2345 platform = "solaris"; 2346 #else 2347 platform = "unknown"; 2348 #endif 2349 2350 /* The format is <system>.<bitness> */ 2351 platform += QString (".%1").arg (ARCH_BITS); 2352 2353 /* Add more system information */ 2354 #if defined (Q_OS_WIN) 2355 OSVERSIONINFO versionInfo; 2356 ZeroMemory (&versionInfo, sizeof (OSVERSIONINFO)); 2357 versionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); 2358 GetVersionEx (&versionInfo); 2359 int major = versionInfo.dwMajorVersion; 2360 int minor = versionInfo.dwMinorVersion; 2361 int build = versionInfo.dwBuildNumber; 2362 QString sp = QString::fromUtf16 ((ushort*)versionInfo.szCSDVersion); 2363 2364 QString distrib; 2365 if (major == 6) 2366 distrib = QString ("Windows Vista %1"); 2367 else if (major == 5) 2368 { 2369 if (minor == 2) 2370 distrib = QString ("Windows Server 2003 %1"); 2371 else if (minor == 1) 2372 distrib = QString ("Windows XP %1"); 2373 else if (minor == 0) 2374 distrib = QString ("Windows 2000 %1"); 2375 else 2376 distrib = QString ("Unknown %1"); 2377 } 2378 else if (major == 4) 2379 { 2380 if (minor == 90) 2381 distrib = QString ("Windows Me %1"); 2382 else if (minor == 10) 2383 distrib = QString ("Windows 98 %1"); 2384 else if (minor == 0) 2385 distrib = QString ("Windows 95 %1"); 2386 else 2387 distrib = QString ("Unknown %1"); 2388 } 2389 else /** @todo Windows Server 2008 == vista? Probably not... */ 2390 distrib = QString ("Unknown %1"); 2391 distrib = distrib.arg (sp); 2392 QString version = QString ("%1.%2").arg (major).arg (minor); 2393 QString kernel = QString ("%1").arg (build); 2394 platform += QString (" [Distribution: %1 | Version: %2 | Build: %3]") 2395 .arg (distrib).arg (version).arg (kernel); 2396 #elif defined (Q_OS_LINUX) 2397 /* Get script path */ 2398 char szAppPrivPath [RTPATH_MAX]; 2399 int rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath)); NOREF(rc); 2400 AssertRC (rc); 2401 /* Run script */ 2402 QByteArray result = 2403 Process::singleShot (QString (szAppPrivPath) + "/VBoxSysInfo.sh"); 2404 if (!result.isNull()) 2405 platform += QString (" [%1]").arg (QString (result).trimmed()); 2406 #else 2407 /* Use RTSystemQueryOSInfo. */ 2408 char szTmp[256]; 2409 QStringList components; 2410 int vrc = RTSystemQueryOSInfo (RTSYSOSINFO_PRODUCT, szTmp, sizeof (szTmp)); 2411 if ((RT_SUCCESS (vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0') 2412 components << QString ("Product: %1").arg (szTmp); 2413 vrc = RTSystemQueryOSInfo (RTSYSOSINFO_RELEASE, szTmp, sizeof (szTmp)); 2414 if ((RT_SUCCESS (vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0') 2415 components << QString ("Release: %1").arg (szTmp); 2416 vrc = RTSystemQueryOSInfo (RTSYSOSINFO_VERSION, szTmp, sizeof (szTmp)); 2417 if ((RT_SUCCESS (vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0') 2418 components << QString ("Version: %1").arg (szTmp); 2419 vrc = RTSystemQueryOSInfo (RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof (szTmp)); 2420 if ((RT_SUCCESS (vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0') 2421 components << QString ("SP: %1").arg (szTmp); 2422 if (!components.isEmpty()) 2423 platform += QString (" [%1]").arg (components.join (" | ")); 2424 #endif 2425 2426 return platform; 2427 } 2428 2429 #if defined(Q_WS_X11) && !defined(VBOX_OSE) 2430 double VBoxGlobal::findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const 2431 { 2432 double maxVersionNumber = 0; 2433 aLicenseFile = ""; 2434 for (int index = 0; index < aFilesList.count(); ++ index) 2435 { 2436 aPattern.indexIn (aFilesList [index]); 2437 QString version = aPattern.cap (1); 2438 if (maxVersionNumber < version.toDouble()) 2439 { 2440 maxVersionNumber = version.toDouble(); 2441 aLicenseFile = aFilesList [index]; 2442 } 2443 } 2444 return maxVersionNumber; 2445 } 2446 2447 bool VBoxGlobal::showVirtualBoxLicense() 2448 { 2449 /* get the apps doc path */ 2450 int size = 256; 2451 char *buffer = (char*) RTMemTmpAlloc (size); 2452 RTPathAppDocs (buffer, size); 2453 QString path (buffer); 2454 RTMemTmpFree (buffer); 2455 QDir docDir (path); 2456 docDir.setFilter (QDir::Files); 2457 docDir.setNameFilters (QStringList ("License-*.html")); 2458 2459 /* Make sure that the language is in two letter code. 2460 * Note: if languageId() returns an empty string lang.name() will 2461 * return "C" which is an valid language code. */ 2462 QLocale lang (VBoxGlobal::languageId()); 2463 2464 QStringList filesList = docDir.entryList(); 2465 QString licenseFile; 2466 /* First try to find a localized version of the license file. */ 2467 double versionNumber = findLicenseFile (filesList, QRegExp (QString ("License-([\\d\\.]+)-%1.html").arg (lang.name())), licenseFile); 2468 /* If there wasn't a localized version of the currently selected language, 2469 * search for the generic one. */ 2470 if (versionNumber == 0) 2471 versionNumber = findLicenseFile (filesList, QRegExp ("License-([\\d\\.]+).html"), licenseFile); 2472 /* Check the version again. */ 2473 if (!versionNumber) 2474 { 2475 vboxProblem().cannotFindLicenseFiles (path); 2476 return false; 2477 } 2478 2479 /* compose the latest license file full path */ 2480 QString latestVersion = QString::number (versionNumber); 2481 QString latestFilePath = docDir.absoluteFilePath (licenseFile); 2482 2483 /* check for the agreed license version */ 2484 QStringList strList = virtualBox().GetExtraData (VBoxDefs::GUI_LicenseKey).split(","); 2485 for (int i=0; i < strList.size(); ++i) 2486 if (strList.at(i) == latestVersion) 2487 return true; 2488 2489 VBoxLicenseViewer licenseDialog (latestFilePath); 2490 bool result = licenseDialog.exec() == QDialog::Accepted; 2491 if (result) 2492 virtualBox().SetExtraData (VBoxDefs::GUI_LicenseKey, (strList << latestVersion).join(",")); 2493 return result; 2494 } 2495 #endif /* defined(Q_WS_X11) && !defined(VBOX_OSE) */ 2496 2497 /** 2498 * Opens a direct session for a machine with the given ID. 2499 * This method does user-friendly error handling (display error messages, etc.). 2500 * and returns a null CSession object in case of any error. 2501 * If this method succeeds, don't forget to close the returned session when 2502 * it is no more necessary. 2503 * 2504 * @param aId Machine ID. 2505 * @param aExisting @c true to open an existing session with the machine 2506 * which is already running, @c false to open a new direct 2507 * session. 2508 */ 2509 CSession VBoxGlobal::openSession (const QString &aId, bool aExisting /* = false */) 2510 { 2511 CSession session; 2512 session.createInstance (CLSID_Session); 2513 if (session.isNull()) 2514 { 2515 vboxProblem().cannotOpenSession (session); 2516 return session; 2517 } 2518 2519 if (aExisting) 2520 mVBox.OpenExistingSession (session, aId); 2521 else 2522 { 2523 mVBox.OpenSession (session, aId); 2524 CMachine machine = session.GetMachine (); 2525 /* Make sure that the language is in two letter code. 2526 * Note: if languageId() returns an empty string lang.name() will 2527 * return "C" which is an valid language code. */ 2528 QLocale lang (VBoxGlobal::languageId()); 2529 machine.SetGuestPropertyValue ("/VirtualBox/HostInfo/GUI/LanguageID", lang.name()); 2530 } 2531 2532 if (!mVBox.isOk()) 2533 { 2534 CMachine machine = CVirtualBox (mVBox).GetMachine (aId); 2535 vboxProblem().cannotOpenSession (mVBox, machine); 2536 session.detach(); 2537 } 2538 2539 return session; 2540 } 2541 2542 /** 2543 * Starts a machine with the given ID. 2544 */ 2545 bool VBoxGlobal::startMachine(const QString &strId) 2546 { 2547 AssertReturn(mValid, false); 2548 2549 CSession session = vboxGlobal().openSession(strId); 2550 if (session.isNull()) 2551 return false; 2552 2553 return createVirtualMachine(session); 2554 } 2555 2556 /** 2557 * Appends the NULL medium to the media list. 2558 * For using with VBoxGlobal::startEnumeratingMedia() only. 2559 */ 2560 static void addNullMediumToList (VBoxMediaList &aList, VBoxMediaList::iterator aWhere) 2561 { 2562 VBoxMedium medium; 2563 aList.insert (aWhere, medium); 2564 } 2565 2566 /** 2567 * Appends the given list of mediums to the media list. 2568 * For using with VBoxGlobal::startEnumeratingMedia() only. 2569 */ 2570 static void addMediumsToList (const CMediumVector &aVector, 2571 VBoxMediaList &aList, 2572 VBoxMediaList::iterator aWhere, 2573 VBoxDefs::MediumType aType, 2574 VBoxMedium *aParent = 0) 2575 { 2576 VBoxMediaList::iterator first = aWhere; 2577 2578 for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++ it) 2579 { 2580 CMedium cmedium (*it); 2581 VBoxMedium medium (cmedium, aType, aParent); 2582 2583 /* Search for a proper alphabetic position */ 2584 VBoxMediaList::iterator jt = first; 2585 for (; jt != aWhere; ++ jt) 2586 if ((*jt).name().localeAwareCompare (medium.name()) > 0) 2587 break; 2588 2589 aList.insert (jt, medium); 2590 2591 /* Adjust the first item if inserted before it */ 2592 if (jt == first) 2593 -- first; 2594 } 2595 } 2596 2597 /** 2598 * Appends the given list of hard disks and all their children to the media list. 2599 * For using with VBoxGlobal::startEnumeratingMedia() only. 2600 */ 2601 static void addHardDisksToList (const CMediumVector &aVector, 2602 VBoxMediaList &aList, 2603 VBoxMediaList::iterator aWhere, 2604 VBoxMedium *aParent = 0) 2605 { 2606 VBoxMediaList::iterator first = aWhere; 2607 2608 /* First pass: Add siblings sorted */ 2609 for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++ it) 2610 { 2611 CMedium cmedium (*it); 2612 VBoxMedium medium (cmedium, VBoxDefs::MediumType_HardDisk, aParent); 2613 2614 /* Search for a proper alphabetic position */ 2615 VBoxMediaList::iterator jt = first; 2616 for (; jt != aWhere; ++ jt) 2617 if ((*jt).name().localeAwareCompare (medium.name()) > 0) 2618 break; 2619 2620 aList.insert (jt, medium); 2621 2622 /* Adjust the first item if inserted before it */ 2623 if (jt == first) 2624 -- first; 2625 } 2626 2627 /* Second pass: Add children */ 2628 for (VBoxMediaList::iterator it = first; it != aWhere;) 2629 { 2630 CMediumVector children = (*it).medium().GetChildren(); 2631 VBoxMedium *parent = &(*it); 2632 2633 ++ it; /* go to the next sibling before inserting children */ 2634 addHardDisksToList (children, aList, it, parent); 2635 } 2636 } 2637 2638 /** 2639 * Starts a thread that asynchronously enumerates all currently registered 2640 * media. 2641 * 2642 * Before the enumeration is started, the current media list (a list returned by 2643 * #currentMediaList()) is populated with all registered media and the 2644 * #mediumEnumStarted() signal is emitted. The enumeration thread then walks this 2645 * list, checks for media acessiblity and emits #mediumEnumerated() signals of 2646 * each checked medium. When all media are checked, the enumeration thread is 2647 * stopped and the #mediumEnumFinished() signal is emitted. 2648 * 2649 * If the enumeration is already in progress, no new thread is started. 2650 * 2651 * The media list returned by #currentMediaList() is always sorted 2652 * alphabetically by the location attribute and comes in the following order: 2653 * <ol> 2654 * <li>All hard disks. If a hard disk has children, these children 2655 * (alphabetically sorted) immediately follow their parent and terefore 2656 * appear before its next sibling hard disk.</li> 2657 * <li>All CD/DVD images.</li> 2658 * <li>All Floppy images.</li> 2659 * </ol> 2660 * 2661 * Note that #mediumEnumerated() signals are emitted in the same order as 2662 * described above. 2663 * 2664 * @sa #currentMediaList() 2665 * @sa #isMediaEnumerationStarted() 2666 */ 2667 void VBoxGlobal::startEnumeratingMedia() 2668 { 2669 AssertReturnVoid (mValid); 2670 2671 /* check if already started but not yet finished */ 2672 if (mMediaEnumThread != NULL) 2673 return; 2674 2675 /* ignore the request during application termination */ 2676 if (sVBoxGlobalInCleanup) 2677 return; 2678 2679 /* composes a list of all currently known media & their children */ 2680 mMediaList.clear(); 2681 addNullMediumToList (mMediaList, mMediaList.end()); 2682 addHardDisksToList (mVBox.GetHardDisks(), mMediaList, mMediaList.end()); 2683 addMediumsToList (mVBox.GetHost().GetDVDDrives(), mMediaList, mMediaList.end(), VBoxDefs::MediumType_DVD); 2684 addMediumsToList (mVBox.GetDVDImages(), mMediaList, mMediaList.end(), VBoxDefs::MediumType_DVD); 2685 addMediumsToList (mVBox.GetHost().GetFloppyDrives(), mMediaList, mMediaList.end(), VBoxDefs::MediumType_Floppy); 2686 addMediumsToList (mVBox.GetFloppyImages(), mMediaList, mMediaList.end(), VBoxDefs::MediumType_Floppy); 2687 2688 /* enumeration thread class */ 2689 class MediaEnumThread : public QThread 2690 { 2691 public: 2692 2693 MediaEnumThread (VBoxMediaList &aList) 2694 : mVector (aList.size()) 2695 , mSavedIt (aList.begin()) 2696 { 2697 int i = 0; 2698 for (VBoxMediaList::const_iterator it = aList.begin(); 2699 it != aList.end(); ++ it) 2700 mVector [i ++] = *it; 2701 } 2702 2703 virtual void run() 2704 { 2705 LogFlow (("MediaEnumThread started.\n")); 2706 COMBase::InitializeCOM(); 2707 2708 CVirtualBox mVBox = vboxGlobal().virtualBox(); 2709 QObject *self = &vboxGlobal(); 2710 2711 /* Enumerate the list */ 2712 for (int i = 0; i < mVector.size() && !sVBoxGlobalInCleanup; ++ i) 2713 { 2714 mVector [i].blockAndQueryState(); 2715 QApplication:: 2716 postEvent (self, 2717 new VBoxMediaEnumEvent (mVector [i], mSavedIt)); 2718 } 2719 2720 /* Post the end-of-enumeration event */ 2721 if (!sVBoxGlobalInCleanup) 2722 QApplication::postEvent (self, new VBoxMediaEnumEvent (mSavedIt)); 2723 2724 COMBase::CleanupCOM(); 2725 LogFlow (("MediaEnumThread finished.\n")); 2726 } 2727 2728 private: 2729 2730 QVector <VBoxMedium> mVector; 2731 VBoxMediaList::iterator mSavedIt; 2732 }; 2733 2734 mMediaEnumThread = new MediaEnumThread (mMediaList); 2735 AssertReturnVoid (mMediaEnumThread); 2736 2737 /* emit mediumEnumStarted() after we set mMediaEnumThread to != NULL 2738 * to cause isMediaEnumerationStarted() to return TRUE from slots */ 2739 emit mediumEnumStarted(); 2740 2741 mMediaEnumThread->start(); 2742 } 2743 2744 /** 2745 * Adds a new medium to the current media list and emits the #mediumAdded() 2746 * signal. 2747 * 2748 * @sa #currentMediaList() 2749 */ 2750 void VBoxGlobal::addMedium (const VBoxMedium &aMedium) 2751 { 2752 /* Note that we maitain the same order here as #startEnumeratingMedia() */ 2753 2754 VBoxMediaList::iterator it = mMediaList.begin(); 2755 2756 if (aMedium.type() == VBoxDefs::MediumType_HardDisk) 2757 { 2758 VBoxMediaList::iterator itParent = mMediaList.end(); 2759 2760 for (; it != mMediaList.end(); ++ it) 2761 { 2762 /* skip null medium that come first */ 2763 if ((*it).isNull()) continue; 2764 2765 if ((*it).type() != VBoxDefs::MediumType_HardDisk) 2766 break; 2767 2768 if (aMedium.parent() != NULL && itParent == mMediaList.end()) 2769 { 2770 if (&*it == aMedium.parent()) 2771 itParent = it; 2772 } 2773 else 2774 { 2775 /* break if met a parent's sibling (will insert before it) */ 2776 if (aMedium.parent() != NULL && 2777 (*it).parent() == (*itParent).parent()) 2778 break; 2779 2780 /* compare to aMedium's siblings */ 2781 if ((*it).parent() == aMedium.parent() && 2782 (*it).name().localeAwareCompare (aMedium.name()) > 0) 2783 break; 2784 } 2785 } 2786 2787 AssertReturnVoid (aMedium.parent() == NULL || itParent != mMediaList.end()); 2788 } 2789 else 2790 { 2791 for (; it != mMediaList.end(); ++ it) 2792 { 2793 /* skip null medium that come first */ 2794 if ((*it).isNull()) continue; 2795 2796 /* skip HardDisks that come first */ 2797 if ((*it).type() == VBoxDefs::MediumType_HardDisk) 2798 continue; 2799 2800 /* skip DVD when inserting Floppy */ 2801 if (aMedium.type() == VBoxDefs::MediumType_Floppy && 2802 (*it).type() == VBoxDefs::MediumType_DVD) 2803 continue; 2804 2805 if ((*it).name().localeAwareCompare (aMedium.name()) > 0 || 2806 (aMedium.type() == VBoxDefs::MediumType_DVD && 2807 (*it).type() == VBoxDefs::MediumType_Floppy)) 2808 break; 2809 } 2810 } 2811 2812 it = mMediaList.insert (it, aMedium); 2813 2814 emit mediumAdded (*it); 2815 } 2816 2817 /** 2818 * Updates the medium in the current media list and emits the #mediumUpdated() 2819 * signal. 2820 * 2821 * @sa #currentMediaList() 2822 */ 2823 void VBoxGlobal::updateMedium (const VBoxMedium &aMedium) 2824 { 2825 VBoxMediaList::Iterator it; 2826 for (it = mMediaList.begin(); it != mMediaList.end(); ++ it) 2827 if ((*it).id() == aMedium.id()) 2828 break; 2829 2830 AssertReturnVoid (it != mMediaList.end()); 2831 2832 if (&*it != &aMedium) 2833 *it = aMedium; 2834 2835 emit mediumUpdated (*it); 2836 } 2837 2838 /** 2839 * Removes the medium from the current media list and emits the #mediumRemoved() 2840 * signal. 2841 * 2842 * @sa #currentMediaList() 2843 */ 2844 void VBoxGlobal::removeMedium (VBoxDefs::MediumType aType, const QString &aId) 2845 { 2846 VBoxMediaList::Iterator it; 2847 for (it = mMediaList.begin(); it != mMediaList.end(); ++ it) 2848 if ((*it).id() == aId) 2849 break; 2850 2851 AssertReturnVoid (it != mMediaList.end()); 2852 2853 #if DEBUG 2854 /* sanity: must be no children */ 2855 { 2856 VBoxMediaList::Iterator jt = it; 2857 ++ jt; 2858 AssertReturnVoid (jt == mMediaList.end() || (*jt).parent() != &*it); 2859 } 2860 #endif 2861 2862 VBoxMedium *pParent = (*it).parent(); 2863 2864 /* remove the medium from the list to keep it in sync with the server "for 2865 * free" when the medium is deleted from one of our UIs */ 2866 mMediaList.erase (it); 2867 2868 emit mediumRemoved (aType, aId); 2869 2870 /* also emit the parent update signal because some attributes like 2871 * isReadOnly() may have been changed after child removal */ 2872 if (pParent != NULL) 2873 { 2874 pParent->refresh(); 2875 emit mediumUpdated (*pParent); 2876 } 2877 } 2878 2879 /** 2880 * Searches for a VBoxMedum object representing the given COM medium object. 2881 * 2882 * @return true if found and false otherwise. 2883 */ 2884 bool VBoxGlobal::findMedium (const CMedium &aObj, VBoxMedium &aMedium) const 2885 { 2886 for (VBoxMediaList::ConstIterator it = mMediaList.begin(); it != mMediaList.end(); ++ it) 2887 { 2888 if (((*it).medium().isNull() && aObj.isNull()) || 2889 (!(*it).medium().isNull() && !aObj.isNull() && (*it).medium().GetId() == aObj.GetId())) 2890 { 2891 aMedium = (*it); 2892 return true; 2893 } 2894 } 2895 return false; 2896 } 2897 2898 /** 2899 * Searches for a VBoxMedum object with the given medium id attribute. 2900 * 2901 * @return VBoxMedum if found which is invalid otherwise. 2902 */ 2903 VBoxMedium VBoxGlobal::findMedium (const QString &aMediumId) const 2904 { 2905 for (VBoxMediaList::ConstIterator it = mMediaList.begin(); it != mMediaList.end(); ++ it) 2906 if ((*it).id() == aMediumId) 2907 return *it; 2908 return VBoxMedium(); 2909 } 2910 2911 #ifdef VBOX_GUI_WITH_SYSTRAY 2912 /** 2913 * Returns the number of current running Fe/Qt4 main windows. 2914 * 2915 * @return Number of running main windows. 2916 */ 2917 int VBoxGlobal::mainWindowCount () 2918 { 2919 return mVBox.GetExtraData (VBoxDefs::GUI_MainWindowCount).toInt(); 2920 } 2921 #endif 2922 2923 /** 2924 * Native language name of the currently installed translation. 2925 * Returns "English" if no translation is installed 2926 * or if the translation file is invalid. 2927 */ 2928 QString VBoxGlobal::languageName() const 2929 { 2930 2931 return qApp->translate ("@@@", "English", 2932 "Native language name"); 2933 } 2934 2935 /** 2936 * Native language country name of the currently installed translation. 2937 * Returns "--" if no translation is installed or if the translation file is 2938 * invalid, or if the language is independent on the country. 2939 */ 2940 QString VBoxGlobal::languageCountry() const 2941 { 2942 return qApp->translate ("@@@", "--", 2943 "Native language country name " 2944 "(empty if this language is for all countries)"); 2945 } 2946 2947 /** 2948 * Language name of the currently installed translation, in English. 2949 * Returns "English" if no translation is installed 2950 * or if the translation file is invalid. 2951 */ 2952 QString VBoxGlobal::languageNameEnglish() const 2953 { 2954 2955 return qApp->translate ("@@@", "English", 2956 "Language name, in English"); 2957 } 2958 2959 /** 2960 * Language country name of the currently installed translation, in English. 2961 * Returns "--" if no translation is installed or if the translation file is 2962 * invalid, or if the language is independent on the country. 2963 */ 2964 QString VBoxGlobal::languageCountryEnglish() const 2965 { 2966 return qApp->translate ("@@@", "--", 2967 "Language country name, in English " 2968 "(empty if native country name is empty)"); 2969 } 2970 2971 /** 2972 * Comma-separated list of authors of the currently installed translation. 2973 * Returns "Oracle Corporation" if no translation is installed or if the 2974 * translation file is invalid, or if the translation is supplied by Sun 2975 * Microsystems, inc. 2976 */ 2977 QString VBoxGlobal::languageTranslators() const 2978 { 2979 return qApp->translate ("@@@", "Oracle Corporation", 2980 "Comma-separated list of translators"); 2981 } 2982 2983 /** 2984 * Changes the language of all global string constants according to the 2985 * currently installed translations tables. 2986 */ 2987 void VBoxGlobal::retranslateUi() 2988 { 2989 mMachineStates [KMachineState_PoweredOff] = tr ("Powered Off", "MachineState"); 2990 mMachineStates [KMachineState_Saved] = tr ("Saved", "MachineState"); 2991 mMachineStates [KMachineState_Teleported] = tr ("Teleported", "MachineState"); 2992 mMachineStates [KMachineState_Aborted] = tr ("Aborted", "MachineState"); 2993 mMachineStates [KMachineState_Running] = tr ("Running", "MachineState"); 2994 mMachineStates [KMachineState_Paused] = tr ("Paused", "MachineState"); 2995 mMachineStates [KMachineState_Stuck] = tr ("Guru Meditation", "MachineState"); 2996 mMachineStates [KMachineState_Teleporting] = tr ("Teleporting", "MachineState"); 2997 mMachineStates [KMachineState_LiveSnapshotting] = tr ("Taking Live Snapshot", "MachineState"); 2998 mMachineStates [KMachineState_Starting] = tr ("Starting", "MachineState"); 2999 mMachineStates [KMachineState_Stopping] = tr ("Stopping", "MachineState"); 3000 mMachineStates [KMachineState_Saving] = tr ("Saving", "MachineState"); 3001 mMachineStates [KMachineState_Restoring] = tr ("Restoring", "MachineState"); 3002 mMachineStates [KMachineState_TeleportingPausedVM] = tr ("Teleporting Paused VM", "MachineState"); 3003 mMachineStates [KMachineState_TeleportingIn] = tr ("Teleporting", "MachineState"); 3004 mMachineStates [KMachineState_RestoringSnapshot] = tr ("Restoring Snapshot", "MachineState"); 3005 mMachineStates [KMachineState_DeletingSnapshot] = tr ("Deleting Snapshot", "MachineState"); 3006 mMachineStates [KMachineState_DeletingSnapshotOnline] = tr ("Deleting Snapshot", "MachineState"); 3007 mMachineStates [KMachineState_DeletingSnapshotPaused] = tr ("Deleting Snapshot", "MachineState"); 3008 mMachineStates [KMachineState_SettingUp] = tr ("Setting Up", "MachineState"); 3009 3010 mSessionStates [KSessionState_Closed] = tr ("Closed", "SessionState"); 3011 mSessionStates [KSessionState_Open] = tr ("Open", "SessionState"); 3012 mSessionStates [KSessionState_Spawning] = tr ("Spawning", "SessionState"); 3013 mSessionStates [KSessionState_Closing] = tr ("Closing", "SessionState"); 3014 3015 mDeviceTypes [KDeviceType_Null] = tr ("None", "DeviceType"); 3016 mDeviceTypes [KDeviceType_Floppy] = tr ("Floppy", "DeviceType"); 3017 mDeviceTypes [KDeviceType_DVD] = tr ("CD/DVD-ROM", "DeviceType"); 3018 mDeviceTypes [KDeviceType_HardDisk] = tr ("Hard Disk", "DeviceType"); 3019 mDeviceTypes [KDeviceType_Network] = tr ("Network", "DeviceType"); 3020 mDeviceTypes [KDeviceType_USB] = tr ("USB", "DeviceType"); 3021 mDeviceTypes [KDeviceType_SharedFolder] = tr ("Shared Folder", "DeviceType"); 3022 3023 mStorageBuses [KStorageBus_IDE] = tr ("IDE", "StorageBus"); 3024 mStorageBuses [KStorageBus_SATA] = tr ("SATA", "StorageBus"); 3025 mStorageBuses [KStorageBus_SCSI] = tr ("SCSI", "StorageBus"); 3026 mStorageBuses [KStorageBus_Floppy] = tr ("Floppy", "StorageBus"); 3027 mStorageBuses [KStorageBus_SAS] = tr ("SAS", "StorageBus"); 3028 3029 mStorageBusChannels [0] = tr ("Primary", "StorageBusChannel"); 3030 mStorageBusChannels [1] = tr ("Secondary", "StorageBusChannel"); 3031 mStorageBusChannels [2] = tr ("Port %1", "StorageBusChannel"); 3032 3033 mStorageBusDevices [0] = tr ("Master", "StorageBusDevice"); 3034 mStorageBusDevices [1] = tr ("Slave", "StorageBusDevice"); 3035 mStorageBusDevices [2] = tr ("Device %1", "StorageBusDevice"); 3036 3037 mSlotTemplates [0] = tr ("IDE Primary Master", "New Storage UI : Slot Name"); 3038 mSlotTemplates [1] = tr ("IDE Primary Slave", "New Storage UI : Slot Name"); 3039 mSlotTemplates [2] = tr ("IDE Secondary Master", "New Storage UI : Slot Name"); 3040 mSlotTemplates [3] = tr ("IDE Secondary Slave", "New Storage UI : Slot Name"); 3041 mSlotTemplates [4] = tr ("SATA Port %1", "New Storage UI : Slot Name"); 3042 mSlotTemplates [5] = tr ("SCSI Port %1", "New Storage UI : Slot Name"); 3043 mSlotTemplates [6] = tr ("SAS Port %1", "New Storage UI : Slot Name"); 3044 mSlotTemplates [7] = tr ("Floppy Device %1", "New Storage UI : Slot Name"); 3045 3046 mDiskTypes [KMediumType_Normal] = tr ("Normal", "DiskType"); 3047 mDiskTypes [KMediumType_Immutable] = tr ("Immutable", "DiskType"); 3048 mDiskTypes [KMediumType_Writethrough] = tr ("Writethrough", "DiskType"); 3049 mDiskTypes [KMediumType_Shareable] = tr ("Shareable", "DiskType"); 3050 mDiskTypes_Differencing = tr ("Differencing", "DiskType"); 3051 3052 mVRDPAuthTypes [KVRDPAuthType_Null] = tr ("Null", "VRDPAuthType"); 3053 mVRDPAuthTypes [KVRDPAuthType_External] = tr ("External", "VRDPAuthType"); 3054 mVRDPAuthTypes [KVRDPAuthType_Guest] = tr ("Guest", "VRDPAuthType"); 3055 3056 mPortModeTypes [KPortMode_Disconnected] = tr ("Disconnected", "PortMode"); 3057 mPortModeTypes [KPortMode_HostPipe] = tr ("Host Pipe", "PortMode"); 3058 mPortModeTypes [KPortMode_HostDevice] = tr ("Host Device", "PortMode"); 3059 mPortModeTypes [KPortMode_RawFile] = tr ("Raw File", "PortMode"); 3060 3061 mUSBFilterActionTypes [KUSBDeviceFilterAction_Ignore] = 3062 tr ("Ignore", "USBFilterActionType"); 3063 mUSBFilterActionTypes [KUSBDeviceFilterAction_Hold] = 3064 tr ("Hold", "USBFilterActionType"); 3065 3066 mAudioDriverTypes [KAudioDriverType_Null] = 3067 tr ("Null Audio Driver", "AudioDriverType"); 3068 mAudioDriverTypes [KAudioDriverType_WinMM] = 3069 tr ("Windows Multimedia", "AudioDriverType"); 3070 mAudioDriverTypes [KAudioDriverType_SolAudio] = 3071 tr ("Solaris Audio", "AudioDriverType"); 3072 mAudioDriverTypes [KAudioDriverType_OSS] = 3073 tr ("OSS Audio Driver", "AudioDriverType"); 3074 mAudioDriverTypes [KAudioDriverType_ALSA] = 3075 tr ("ALSA Audio Driver", "AudioDriverType"); 3076 mAudioDriverTypes [KAudioDriverType_DirectSound] = 3077 tr ("Windows DirectSound", "AudioDriverType"); 3078 mAudioDriverTypes [KAudioDriverType_CoreAudio] = 3079 tr ("CoreAudio", "AudioDriverType"); 3080 mAudioDriverTypes [KAudioDriverType_Pulse] = 3081 tr ("PulseAudio", "AudioDriverType"); 3082 3083 mAudioControllerTypes [KAudioControllerType_AC97] = 3084 tr ("ICH AC97", "AudioControllerType"); 3085 mAudioControllerTypes [KAudioControllerType_SB16] = 3086 tr ("SoundBlaster 16", "AudioControllerType"); 3087 3088 mNetworkAdapterTypes [KNetworkAdapterType_Am79C970A] = 3089 tr ("PCnet-PCI II (Am79C970A)", "NetworkAdapterType"); 3090 mNetworkAdapterTypes [KNetworkAdapterType_Am79C973] = 3091 tr ("PCnet-FAST III (Am79C973)", "NetworkAdapterType"); 3092 mNetworkAdapterTypes [KNetworkAdapterType_I82540EM] = 3093 tr ("Intel PRO/1000 MT Desktop (82540EM)", "NetworkAdapterType"); 3094 mNetworkAdapterTypes [KNetworkAdapterType_I82543GC] = 3095 tr ("Intel PRO/1000 T Server (82543GC)", "NetworkAdapterType"); 3096 mNetworkAdapterTypes [KNetworkAdapterType_I82545EM] = 3097 tr ("Intel PRO/1000 MT Server (82545EM)", "NetworkAdapterType"); 3098 #ifdef VBOX_WITH_VIRTIO 3099 mNetworkAdapterTypes [KNetworkAdapterType_Virtio] = 3100 tr ("Paravirtualized Network (virtio-net)", "NetworkAdapterType"); 3101 #endif /* VBOX_WITH_VIRTIO */ 3102 3103 mNetworkAttachmentTypes [KNetworkAttachmentType_Null] = 3104 tr ("Not attached", "NetworkAttachmentType"); 3105 mNetworkAttachmentTypes [KNetworkAttachmentType_NAT] = 3106 tr ("NAT", "NetworkAttachmentType"); 3107 mNetworkAttachmentTypes [KNetworkAttachmentType_Bridged] = 3108 tr ("Bridged Adapter", "NetworkAttachmentType"); 3109 mNetworkAttachmentTypes [KNetworkAttachmentType_Internal] = 3110 tr ("Internal Network", "NetworkAttachmentType"); 3111 mNetworkAttachmentTypes [KNetworkAttachmentType_HostOnly] = 3112 tr ("Host-only Adapter", "NetworkAttachmentType"); 3113 #ifdef VBOX_WITH_VDE 3114 mNetworkAttachmentTypes [KNetworkAttachmentType_VDE] = 3115 tr ("VDE Adapter", "NetworkAttachmentType"); 3116 #endif 3117 3118 mClipboardTypes [KClipboardMode_Disabled] = 3119 tr ("Disabled", "ClipboardType"); 3120 mClipboardTypes [KClipboardMode_HostToGuest] = 3121 tr ("Host To Guest", "ClipboardType"); 3122 mClipboardTypes [KClipboardMode_GuestToHost] = 3123 tr ("Guest To Host", "ClipboardType"); 3124 mClipboardTypes [KClipboardMode_Bidirectional] = 3125 tr ("Bidirectional", "ClipboardType"); 3126 3127 mStorageControllerTypes [KStorageControllerType_PIIX3] = 3128 tr ("PIIX3", "StorageControllerType"); 3129 mStorageControllerTypes [KStorageControllerType_PIIX4] = 3130 tr ("PIIX4", "StorageControllerType"); 3131 mStorageControllerTypes [KStorageControllerType_ICH6] = 3132 tr ("ICH6", "StorageControllerType"); 3133 mStorageControllerTypes [KStorageControllerType_IntelAhci] = 3134 tr ("AHCI", "StorageControllerType"); 3135 mStorageControllerTypes [KStorageControllerType_LsiLogic] = 3136 tr ("Lsilogic", "StorageControllerType"); 3137 mStorageControllerTypes [KStorageControllerType_BusLogic] = 3138 tr ("BusLogic", "StorageControllerType"); 3139 mStorageControllerTypes [KStorageControllerType_I82078] = 3140 tr ("I82078", "StorageControllerType"); 3141 mStorageControllerTypes [KStorageControllerType_LsiLogicSas] = 3142 tr ("LsiLogic SAS", "StorageControllerType"); 3143 3144 mUSBDeviceStates [KUSBDeviceState_NotSupported] = 3145 tr ("Not supported", "USBDeviceState"); 3146 mUSBDeviceStates [KUSBDeviceState_Unavailable] = 3147 tr ("Unavailable", "USBDeviceState"); 3148 mUSBDeviceStates [KUSBDeviceState_Busy] = 3149 tr ("Busy", "USBDeviceState"); 3150 mUSBDeviceStates [KUSBDeviceState_Available] = 3151 tr ("Available", "USBDeviceState"); 3152 mUSBDeviceStates [KUSBDeviceState_Held] = 3153 tr ("Held", "USBDeviceState"); 3154 mUSBDeviceStates [KUSBDeviceState_Captured] = 3155 tr ("Captured", "USBDeviceState"); 3156 3157 mUserDefinedPortName = tr ("User-defined", "serial port"); 3158 3159 mWarningIcon = standardIcon (QStyle::SP_MessageBoxWarning, 0).pixmap (16, 16); 3160 Assert (!mWarningIcon.isNull()); 3161 3162 mErrorIcon = standardIcon (QStyle::SP_MessageBoxCritical, 0).pixmap (16, 16); 3163 Assert (!mErrorIcon.isNull()); 3164 3165 /* refresh media properties since they contain some translations too */ 3166 for (VBoxMediaList::iterator it = mMediaList.begin(); 3167 it != mMediaList.end(); ++ it) 3168 it->refresh(); 3169 3170 #if defined (Q_WS_PM) || defined (Q_WS_X11) 3171 /* As PM and X11 do not (to my knowledge) have functionality for providing 3172 * human readable key names, we keep a table of them, which must be 3173 * updated when the language is changed. */ 3174 QIHotKeyEdit::retranslateUi(); 3175 #endif 3176 } 3177 3178 // public static stuff 3179 //////////////////////////////////////////////////////////////////////////////// 3180 3181 /* static */ 3182 bool VBoxGlobal::isDOSType (const QString &aOSTypeId) 3183 { 3184 if (aOSTypeId.left (3) == "dos" || 3185 aOSTypeId.left (3) == "win" || 3186 aOSTypeId.left (3) == "os2") 3187 return true; 3188 3189 return false; 3190 } 3191 3192 const char *gVBoxLangSubDir = "/nls"; 3193 const char *gVBoxLangFileBase = "VirtualBox_"; 3194 const char *gVBoxLangFileExt = ".qm"; 3195 const char *gVBoxLangIDRegExp = "(([a-z]{2})(?:_([A-Z]{2}))?)|(C)"; 3196 const char *gVBoxBuiltInLangName = "C"; 3197 3198 class VBoxTranslator : public QTranslator 3199 { 3200 public: 3201 3202 VBoxTranslator (QObject *aParent = 0) 3203 : QTranslator (aParent) {} 3204 3205 bool loadFile (const QString &aFileName) 3206 { 3207 QFile file (aFileName); 3208 if (!file.open (QIODevice::ReadOnly)) 3209 return false; 3210 mData = file.readAll(); 3211 return load ((uchar*) mData.data(), mData.size()); 3212 } 3213 3214 private: 3215 3216 QByteArray mData; 3217 }; 3218 3219 static VBoxTranslator *sTranslator = 0; 3220 static QString sLoadedLangId = gVBoxBuiltInLangName; 3221 3222 /** 3223 * Returns the loaded (active) language ID. 3224 * Note that it may not match with VBoxGlobalSettings::languageId() if the 3225 * specified language cannot be loaded. 3226 * If the built-in language is active, this method returns "C". 3227 * 3228 * @note "C" is treated as the built-in language for simplicity -- the C 3229 * locale is used in unix environments as a fallback when the requested 3230 * locale is invalid. This way we don't need to process both the "built_in" 3231 * language and the "C" language (which is a valid environment setting) 3232 * separately. 3233 */ 3234 /* static */ 3235 QString VBoxGlobal::languageId() 3236 { 3237 return sLoadedLangId; 3238 } 3239 3240 /** 3241 * Loads the language by language ID. 3242 * 3243 * @param aLangId Language ID in in form of xx_YY. QString::null means the 3244 * system default language. 3245 */ 3246 /* static */ 3247 void VBoxGlobal::loadLanguage (const QString &aLangId) 3248 { 3249 QString langId = aLangId.isEmpty() ? 3250 VBoxGlobal::systemLanguageId() : aLangId; 3251 QString languageFileName; 3252 QString selectedLangId = gVBoxBuiltInLangName; 3253 3254 /* If C is selected we change it temporary to en. This makes sure any extra 3255 * "en" translation file will be loaded. This is necessary for loading the 3256 * plural forms of some of our translations. */ 3257 bool fResetToC = false; 3258 if (langId == "C") 3259 { 3260 langId = "en"; 3261 fResetToC = true; 3262 } 3263 3264 char szNlsPath[RTPATH_MAX]; 3265 int rc; 3266 3267 rc = RTPathAppPrivateNoArch(szNlsPath, sizeof(szNlsPath)); 3268 AssertRC (rc); 3269 3270 QString nlsPath = QString(szNlsPath) + gVBoxLangSubDir; 3271 QDir nlsDir (nlsPath); 3272 3273 Assert (!langId.isEmpty()); 3274 if (!langId.isEmpty() && langId != gVBoxBuiltInLangName) 3275 { 3276 QRegExp regExp (gVBoxLangIDRegExp); 3277 int pos = regExp.indexIn (langId); 3278 /* the language ID should match the regexp completely */ 3279 AssertReturnVoid (pos == 0); 3280 3281 QString lang = regExp.cap (2); 3282 3283 if (nlsDir.exists (gVBoxLangFileBase + langId + gVBoxLangFileExt)) 3284 { 3285 languageFileName = nlsDir.absoluteFilePath (gVBoxLangFileBase + langId + 3286 gVBoxLangFileExt); 3287 selectedLangId = langId; 3288 } 3289 else if (nlsDir.exists (gVBoxLangFileBase + lang + gVBoxLangFileExt)) 3290 { 3291 languageFileName = nlsDir.absoluteFilePath (gVBoxLangFileBase + lang + 3292 gVBoxLangFileExt); 3293 selectedLangId = lang; 3294 } 3295 else 3296 { 3297 /* Never complain when the default language is requested. In any 3298 * case, if no explicit language file exists, we will simply 3299 * fall-back to English (built-in). */ 3300 if (!aLangId.isNull() && langId != "en") 3301 vboxProblem().cannotFindLanguage (langId, nlsPath); 3302 /* selectedLangId remains built-in here */ 3303 AssertReturnVoid (selectedLangId == gVBoxBuiltInLangName); 3304 } 3305 } 3306 3307 /* delete the old translator if there is one */ 3308 if (sTranslator) 3309 { 3310 /* QTranslator destructor will call qApp->removeTranslator() for 3311 * us. It will also delete all its child translations we attach to it 3312 * below, so we don't have to care about them specially. */ 3313 delete sTranslator; 3314 } 3315 3316 /* load new language files */ 3317 sTranslator = new VBoxTranslator (qApp); 3318 Assert (sTranslator); 3319 bool loadOk = true; 3320 if (sTranslator) 3321 { 3322 if (selectedLangId != gVBoxBuiltInLangName) 3323 { 3324 Assert (!languageFileName.isNull()); 3325 loadOk = sTranslator->loadFile (languageFileName); 3326 } 3327 /* we install the translator in any case: on failure, this will 3328 * activate an empty translator that will give us English 3329 * (built-in) */ 3330 qApp->installTranslator (sTranslator); 3331 } 3332 else 3333 loadOk = false; 3334 3335 if (loadOk) 3336 sLoadedLangId = selectedLangId; 3337 else 3338 { 3339 vboxProblem().cannotLoadLanguage (languageFileName); 3340 sLoadedLangId = gVBoxBuiltInLangName; 3341 } 3342 3343 /* Try to load the corresponding Qt translation */ 3344 if (sLoadedLangId != gVBoxBuiltInLangName) 3345 { 3346 #ifdef Q_OS_UNIX 3347 /* We use system installations of Qt on Linux systems, so first, try 3348 * to load the Qt translation from the system location. */ 3349 languageFileName = QLibraryInfo::location(QLibraryInfo::TranslationsPath) + "/qt_" + 3350 sLoadedLangId + gVBoxLangFileExt; 3351 QTranslator *qtSysTr = new QTranslator (sTranslator); 3352 Assert (qtSysTr); 3353 if (qtSysTr && qtSysTr->load (languageFileName)) 3354 qApp->installTranslator (qtSysTr); 3355 /* Note that the Qt translation supplied by Sun is always loaded 3356 * afterwards to make sure it will take precedence over the system 3357 * translation (it may contain more decent variants of translation 3358 * that better correspond to VirtualBox UI). We need to load both 3359 * because a newer version of Qt may be installed on the user computer 3360 * and the Sun version may not fully support it. We don't do it on 3361 * Win32 because we supply a Qt library there and therefore the 3362 * Sun translation is always the best one. */ 3363 #endif 3364 languageFileName = nlsDir.absoluteFilePath (QString ("qt_") + 3365 sLoadedLangId + 3366 gVBoxLangFileExt); 3367 QTranslator *qtTr = new QTranslator (sTranslator); 3368 Assert (qtTr); 3369 if (qtTr && (loadOk = qtTr->load (languageFileName))) 3370 qApp->installTranslator (qtTr); 3371 /* The below message doesn't fit 100% (because it's an additional 3372 * language and the main one won't be reset to built-in on failure) 3373 * but the load failure is so rare here that it's not worth a separate 3374 * message (but still, having something is better than having none) */ 3375 if (!loadOk && !aLangId.isNull()) 3376 vboxProblem().cannotLoadLanguage (languageFileName); 3377 } 3378 if (fResetToC) 3379 sLoadedLangId = "C"; 3380 } 3381 3382 QString VBoxGlobal::helpFile() const 3383 { 3384 #if defined (Q_WS_WIN32) 3385 const QString name = "VirtualBox"; 3386 const QString suffix = "chm"; 3387 #elif defined (Q_WS_MAC) 3388 const QString name = "UserManual"; 3389 const QString suffix = "pdf"; 3390 #elif defined (Q_WS_X11) 3391 # if defined VBOX_OSE 3392 const QString name = "UserManual"; 3393 const QString suffix = "pdf"; 3394 # else 3395 const QString name = "VirtualBox"; 3396 const QString suffix = "chm"; 3397 # endif 3398 #endif 3399 /* Where are the docs located? */ 3400 char szDocsPath[RTPATH_MAX]; 3401 int rc = RTPathAppDocs (szDocsPath, sizeof (szDocsPath)); 3402 AssertRC (rc); 3403 /* Make sure that the language is in two letter code. 3404 * Note: if languageId() returns an empty string lang.name() will 3405 * return "C" which is an valid language code. */ 3406 QLocale lang (VBoxGlobal::languageId()); 3407 3408 /* Construct the path and the filename */ 3409 QString manual = QString ("%1/%2_%3.%4").arg (szDocsPath) 3410 .arg (name) 3411 .arg (lang.name()) 3412 .arg (suffix); 3413 /* Check if a help file with that name exists */ 3414 QFileInfo fi (manual); 3415 if (fi.exists()) 3416 return manual; 3417 3418 /* Fall back to the standard */ 3419 manual = QString ("%1/%2.%4").arg (szDocsPath) 3420 .arg (name) 3421 .arg (suffix); 3422 return manual; 3423 } 3424 3425 QIcon VBoxGlobal::iconSet (const QPixmap &aNormal, 3426 const QPixmap &aDisabled, 3427 const QPixmap &aActive) 30 QIcon UIIconPool::iconSet(const QPixmap &normal, 31 const QPixmap &disabled /* = QPixmap() */, 32 const QPixmap &active /* = QPixmap() */) 3428 33 { 3429 34 QIcon iconSet; 3430 35 3431 Assert (aNormal);3432 iconSet.addPixmap (aNormal, QIcon::Normal);36 Assert(!normal.isNull()); 37 iconSet.addPixmap(normal, QIcon::Normal); 3433 38 3434 if (! aDisabled.isNull())3435 iconSet.addPixmap (aDisabled, QIcon::Disabled);39 if (!disabled.isNull()) 40 iconSet.addPixmap(disabled, QIcon::Disabled); 3436 41 3437 if (!a Active.isNull())3438 iconSet.addPixmap (aActive, QIcon::Active);42 if (!active.isNull()) 43 iconSet.addPixmap(active, QIcon::Active); 3439 44 3440 45 return iconSet; … … 3442 47 3443 48 /* static */ 3444 QIcon VBoxGlobal::iconSet (const char *aNormal,3445 const char *aDisabled /* = NULL*/,3446 const char *aActive /* = NULL*/)49 QIcon UIIconPool::iconSet(const QString &strNormal, 50 const QString &strDisabled /* = QString() */, 51 const QString &strActive /* = QString() */) 3447 52 { 3448 53 QIcon iconSet; 3449 54 3450 Assert (aNormal != NULL);3451 iconSet.addFile (aNormal, QSize(),3452 3453 if ( aDisabled != NULL)3454 iconSet.addFile (aDisabled, QSize(),3455 3456 if ( aActive != NULL)3457 iconSet.addFile (aActive, QSize(),3458 55 Assert(!strNormal.isEmpty()); 56 iconSet.addFile(strNormal, QSize(), 57 QIcon::Normal); 58 if (!strDisabled.isEmpty()) 59 iconSet.addFile(strDisabled, QSize(), 60 QIcon::Disabled); 61 if (!strActive.isEmpty()) 62 iconSet.addFile(strActive, QSize(), 63 QIcon::Active); 3459 64 return iconSet; 3460 65 } 3461 66 3462 67 /* static */ 3463 QIcon VBoxGlobal::iconSetOnOff (const char *aNormal, const char *aNormalOff,3464 const char *aDisabled /* = NULL*/,3465 const char *aDisabledOff /* = NULL*/,3466 const char *aActive /* = NULL*/,3467 const char *aActiveOff /* = NULL*/)68 QIcon UIIconPool::iconSetOnOff(const QString &strNormal, const QString strNormalOff, 69 const QString &strDisabled /* = QString() */, 70 const QString &strDisabledOff /* = QString() */, 71 const QString &strActive /* = QString() */, 72 const QString &strActiveOff /* = QString() */) 3468 73 { 3469 74 QIcon iconSet; 3470 75 3471 Assert (aNormal != NULL);3472 iconSet.addFile (aNormal, QSize(), QIcon::Normal, QIcon::On);3473 if ( aNormalOff != NULL)3474 iconSet.addFile (aNormalOff, QSize(), QIcon::Normal, QIcon::Off);76 Assert(!strNormal.isEmpty()); 77 iconSet.addFile(strNormal, QSize(), QIcon::Normal, QIcon::On); 78 if (!strNormalOff.isEmpty()) 79 iconSet.addFile(strNormalOff, QSize(), QIcon::Normal, QIcon::Off); 3475 80 3476 if ( aDisabled != NULL)3477 iconSet.addFile (aDisabled, QSize(), QIcon::Disabled, QIcon::On);3478 if ( aDisabledOff != NULL)3479 iconSet.addFile (aDisabledOff, QSize(), QIcon::Disabled, QIcon::Off);81 if (!strDisabled.isEmpty()) 82 iconSet.addFile(strDisabled, QSize(), QIcon::Disabled, QIcon::On); 83 if (!strDisabledOff.isEmpty()) 84 iconSet.addFile(strDisabledOff, QSize(), QIcon::Disabled, QIcon::Off); 3480 85 3481 if ( aActive != NULL)3482 iconSet.addFile (aActive, QSize(), QIcon::Active, QIcon::On);3483 if ( aActiveOff != NULL)3484 iconSet.addFile (aActive, QSize(), QIcon::Active, QIcon::Off);86 if (!strActive.isEmpty()) 87 iconSet.addFile(strActive, QSize(), QIcon::Active, QIcon::On); 88 if (!strActiveOff.isEmpty()) 89 iconSet.addFile(strActive, QSize(), QIcon::Active, QIcon::Off); 3485 90 3486 91 return iconSet; … … 3488 93 3489 94 /* static */ 3490 QIcon VBoxGlobal::iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize,3491 const char *aNormal, const char *aSmallNormal,3492 const char *aDisabled /* = NULL*/,3493 const char *aSmallDisabled /* = NULL*/,3494 const char *aActive /* = NULL*/,3495 const char *aSmallActive /* = NULL*/)95 QIcon UIIconPool::iconSetFull(const QSize &normalSize, const QSize &smallSize, 96 const QString &strNormal, const QString &strSmallNormal, 97 const QString &strDisabled /* = QString() */, 98 const QString &strSmallDisabled /* = QString() */, 99 const QString &strActive /* = QString() */, 100 const QString &strSmallActive /* = QString() */) 3496 101 { 3497 102 QIcon iconSet; 3498 103 3499 Assert (aNormal != NULL);3500 Assert (aSmallNormal != NULL);3501 iconSet.addFile (aNormal, aNormalSize, QIcon::Normal);3502 iconSet.addFile (aSmallNormal, aSmallSize, QIcon::Normal);104 Assert(!strNormal.isEmpty()); 105 Assert(!strSmallNormal.isEmpty()); 106 iconSet.addFile(strNormal, normalSize, QIcon::Normal); 107 iconSet.addFile(strSmallNormal, smallSize, QIcon::Normal); 3503 108 3504 if ( aSmallDisabled != NULL)109 if (!strSmallDisabled.isEmpty()) 3505 110 { 3506 iconSet.addFile (aDisabled, aNormalSize, QIcon::Disabled);3507 iconSet.addFile (aSmallDisabled, aSmallSize, QIcon::Disabled);111 iconSet.addFile(strDisabled, normalSize, QIcon::Disabled); 112 iconSet.addFile(strSmallDisabled, smallSize, QIcon::Disabled); 3508 113 } 3509 114 3510 if ( aSmallActive != NULL)115 if (!strSmallActive.isEmpty()) 3511 116 { 3512 iconSet.addFile (aActive, aNormalSize, QIcon::Active);3513 iconSet.addFile (aSmallActive, aSmallSize, QIcon::Active);117 iconSet.addFile(strActive, normalSize, QIcon::Active); 118 iconSet.addFile(strSmallActive, smallSize, QIcon::Active); 3514 119 } 3515 120 … … 3517 122 } 3518 123 3519 QIcon VBoxGlobal::standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget /* = NULL */) 124 /* static */ 125 QIcon UIIconPool::defaultIcon(UIDefaultIcon def, const QWidget *pWidget /* = 0 */) 3520 126 { 3521 QStyle *style = aWidget ? aWidget->style(): QApplication::style(); 3522 if (!style) 3523 return QIcon(); 127 QIcon icon; 128 QStyle *pStyle = pWidget ? pWidget->style() : QApplication::style(); 129 switch (def) 130 { 131 case MessageBoxInformationIcon: 132 { 133 icon = pStyle->standardIcon(QStyle::SP_MessageBoxInformation, 0, pWidget); 134 break; 135 } 136 case MessageBoxQuestionIcon: 137 { 138 icon = pStyle->standardIcon(QStyle::SP_MessageBoxQuestion, 0, pWidget); 139 break; 140 } 141 case MessageBoxWarningIcon: 142 { 3524 143 #ifdef Q_WS_MAC 3525 /* At least in Qt 4.3.4/4.4 RC1 SP_MessageBoxWarning is the application 3526 * icon. So change this to the critical icon. (Maybe this would be 3527 * fixed in a later Qt version) */ 3528 if (aStandard == QStyle::SP_MessageBoxWarning) 3529 return style->standardIcon (QStyle::SP_MessageBoxCritical, 0, aWidget); 3530 #endif /* Q_WS_MAC */ 3531 return style->standardIcon (aStandard, 0, aWidget); 144 /* At least in Qt 4.3.4/4.4 RC1 SP_MessageBoxWarning is the application 145 * icon. So change this to the critical icon. (Maybe this would be 146 * fixed in a later Qt version) */ 147 icon = pStyle->standardIcon(QStyle::SP_MessageBoxCritical, 0, pWidget); 148 #else /* Q_WS_MAC */ 149 icon = pStyle->standardIcon(QStyle::SP_MessageBoxWarning, 0, pWidget); 150 #endif /* !Q_WS_MAC */ 151 break; 152 } 153 case MessageBoxCriticalIcon: 154 { 155 icon = pStyle->standardIcon(QStyle::SP_MessageBoxCritical, 0, pWidget); 156 break; 157 } 158 case ArrowBackIcon: 159 { 160 icon = pStyle->standardIcon(QStyle::SP_ArrowBack, 0, pWidget); 161 if (icon.isNull()) 162 icon = iconSet(":/list_moveup_16px.png", 163 ":/list_moveup_disabled_16px.png"); 164 break; 165 } 166 case ArrowForwardIcon: 167 { 168 icon = pStyle->standardIcon(QStyle::SP_ArrowForward, 0, pWidget); 169 if (icon.isNull()) 170 icon = iconSet(":/list_movedown_16px.png", 171 ":/list_movedown_disabled_16px.png"); 172 break; 173 } 174 default: 175 { 176 AssertMsgFailed(("Unknown default icon type!")); 177 break; 178 } 179 } 180 return icon; 3532 181 } 3533 182 3534 /**3535 * Replacement for QToolButton::setTextLabel() that handles the shortcut3536 * letter (if it is present in the argument string) as if it were a setText()3537 * call: the shortcut letter is used to automatically assign an "Alt+<letter>"3538 * accelerator key sequence to the given tool button.3539 *3540 * @note This method preserves the icon set if it was assigned before. Only3541 * the text label and the accelerator are changed.3542 *3543 * @param aToolButton Tool button to set the text label on.3544 * @param aTextLabel Text label to set.3545 */3546 /* static */3547 void VBoxGlobal::setTextLabel (QToolButton *aToolButton,3548 const QString &aTextLabel)3549 {3550 AssertReturnVoid (aToolButton != NULL);3551 3552 /* remember the icon set as setText() will kill it */3553 QIcon iset = aToolButton->icon();3554 /* re-use the setText() method to detect and set the accelerator */3555 aToolButton->setText (aTextLabel);3556 QKeySequence accel = aToolButton->shortcut();3557 aToolButton->setText (aTextLabel);3558 aToolButton->setIcon (iset);3559 /* set the accel last as setIconSet() would kill it */3560 aToolButton->setShortcut (accel);3561 }3562 3563 /**3564 * Performs direct and flipped search of position for \a aRectangle to make sure3565 * it is fully contained inside \a aBoundRegion region by moving & resizing3566 * \a aRectangle if necessary. Selects the minimum shifted result between direct3567 * and flipped variants.3568 */3569 /* static */3570 QRect VBoxGlobal::normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion,3571 bool aCanResize /* = true */)3572 {3573 /* Direct search for normalized rectangle */3574 QRect var1 (getNormalized (aRectangle, aBoundRegion, aCanResize));3575 3576 /* Flipped search for normalized rectangle */3577 QRect var2 (flip (getNormalized (flip (aRectangle).boundingRect(),3578 flip (aBoundRegion), aCanResize)).boundingRect());3579 3580 /* Calculate shift from starting position for both variants */3581 double length1 = sqrt (pow ((double) (var1.x() - aRectangle.x()), (double) 2) +3582 pow ((double) (var1.y() - aRectangle.y()), (double) 2));3583 double length2 = sqrt (pow ((double) (var2.x() - aRectangle.x()), (double) 2) +3584 pow ((double) (var2.y() - aRectangle.y()), (double) 2));3585 3586 /* Return minimum shifted variant */3587 return length1 > length2 ? var2 : var1;3588 }3589 3590 /**3591 * Ensures that the given rectangle \a aRectangle is fully contained within the3592 * region \a aBoundRegion by moving \a aRectangle if necessary. If \a aRectangle is3593 * larger than \a aBoundRegion, top left corner of \a aRectangle is aligned with the3594 * top left corner of maximum available rectangle and, if \a aCanResize is true,3595 * \a aRectangle is shrinked to become fully visible.3596 */3597 /* static */3598 QRect VBoxGlobal::getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion,3599 bool /* aCanResize = true */)3600 {3601 /* Storing available horizontal sub-rectangles & vertical shifts */3602 int windowVertical = aRectangle.center().y();3603 QVector <QRect> rectanglesVector (aBoundRegion.rects());3604 QList <QRect> rectanglesList;3605 QList <int> shiftsList;3606 foreach (QRect currentItem, rectanglesVector)3607 {3608 int currentDelta = qAbs (windowVertical - currentItem.center().y());3609 int shift2Top = currentItem.top() - aRectangle.top();3610 int shift2Bot = currentItem.bottom() - aRectangle.bottom();3611 3612 int itemPosition = 0;3613 foreach (QRect item, rectanglesList)3614 {3615 int delta = qAbs (windowVertical - item.center().y());3616 if (delta > currentDelta) break; else ++ itemPosition;3617 }3618 rectanglesList.insert (itemPosition, currentItem);3619 3620 int shift2TopPos = 0;3621 foreach (int shift, shiftsList)3622 if (qAbs (shift) > qAbs (shift2Top)) break; else ++ shift2TopPos;3623 shiftsList.insert (shift2TopPos, shift2Top);3624 3625 int shift2BotPos = 0;3626 foreach (int shift, shiftsList)3627 if (qAbs (shift) > qAbs (shift2Bot)) break; else ++ shift2BotPos;3628 shiftsList.insert (shift2BotPos, shift2Bot);3629 }3630 3631 /* Trying to find the appropriate place for window */3632 QRect result;3633 for (int i = -1; i < shiftsList.size(); ++ i)3634 {3635 /* Move to appropriate vertical */3636 QRect rectangle (aRectangle);3637 if (i >= 0) rectangle.translate (0, shiftsList [i]);3638 3639 /* Search horizontal shift */3640 int maxShift = 0;3641 foreach (QRect item, rectanglesList)3642 {3643 QRect trectangle (rectangle.translated (item.left() - rectangle.left(), 0));3644 if (!item.intersects (trectangle))3645 continue;3646 3647 if (rectangle.left() < item.left())3648 {3649 int shift = item.left() - rectangle.left();3650 maxShift = qAbs (shift) > qAbs (maxShift) ? shift : maxShift;3651 }3652 else if (rectangle.right() > item.right())3653 {3654 int shift = item.right() - rectangle.right();3655 maxShift = qAbs (shift) > qAbs (maxShift) ? shift : maxShift;3656 }3657 }3658 3659 /* Shift across the horizontal direction */3660 rectangle.translate (maxShift, 0);3661 3662 /* Check the translated rectangle to feat the rules */3663 if (aBoundRegion.united (rectangle) == aBoundRegion)3664 result = rectangle;3665 3666 if (!result.isNull()) break;3667 }3668 3669 if (result.isNull())3670 {3671 /* Resize window to feat desirable size3672 * using max of available rectangles */3673 QRect maxRectangle;3674 quint64 maxSquare = 0;3675 foreach (QRect item, rectanglesList)3676 {3677 quint64 square = item.width() * item.height();3678 if (square > maxSquare)3679 {3680 maxSquare = square;3681 maxRectangle = item;3682 }3683 }3684 3685 result = aRectangle;3686 result.moveTo (maxRectangle.x(), maxRectangle.y());3687 if (maxRectangle.right() < result.right())3688 result.setRight (maxRectangle.right());3689 if (maxRectangle.bottom() < result.bottom())3690 result.setBottom (maxRectangle.bottom());3691 }3692 3693 return result;3694 }3695 3696 /**3697 * Returns the flipped (transposed) region.3698 */3699 /* static */3700 QRegion VBoxGlobal::flip (const QRegion &aRegion)3701 {3702 QRegion result;3703 QVector <QRect> rectangles (aRegion.rects());3704 foreach (QRect rectangle, rectangles)3705 result += QRect (rectangle.y(), rectangle.x(),3706 rectangle.height(), rectangle.width());3707 return result;3708 }3709 3710 /**3711 * Aligns the center of \a aWidget with the center of \a aRelative.3712 *3713 * If necessary, \a aWidget's position is adjusted to make it fully visible3714 * within the available desktop area. If \a aWidget is bigger then this area,3715 * it will also be resized unless \a aCanResize is false or there is an3716 * inappropriate minimum size limit (in which case the top left corner will be3717 * simply aligned with the top left corner of the available desktop area).3718 *3719 * \a aWidget must be a top-level widget. \a aRelative may be any widget, but3720 * if it's not top-level itself, its top-level widget will be used for3721 * calculations. \a aRelative can also be NULL, in which case \a aWidget will3722 * be centered relative to the available desktop area.3723 */3724 /* static */3725 void VBoxGlobal::centerWidget (QWidget *aWidget, QWidget *aRelative,3726 bool aCanResize /* = true */)3727 {3728 AssertReturnVoid (aWidget);3729 AssertReturnVoid (aWidget->isTopLevel());3730 3731 QRect deskGeo, parentGeo;3732 QWidget *w = aRelative;3733 if (w)3734 {3735 w = w->window();3736 deskGeo = QApplication::desktop()->availableGeometry (w);3737 parentGeo = w->frameGeometry();3738 /* On X11/Gnome, geo/frameGeo.x() and y() are always 0 for top level3739 * widgets with parents, what a shame. Use mapToGlobal() to workaround. */3740 QPoint d = w->mapToGlobal (QPoint (0, 0));3741 d.rx() -= w->geometry().x() - w->x();3742 d.ry() -= w->geometry().y() - w->y();3743 parentGeo.moveTopLeft (d);3744 }3745 else3746 {3747 deskGeo = QApplication::desktop()->availableGeometry();3748 parentGeo = deskGeo;3749 }3750 3751 /* On X11, there is no way to determine frame geometry (including WM3752 * decorations) before the widget is shown for the first time. Stupidly3753 * enumerate other top level widgets to find the thickest frame. The code3754 * is based on the idea taken from QDialog::adjustPositionInternal(). */3755 3756 int extraw = 0, extrah = 0;3757 3758 QWidgetList list = QApplication::topLevelWidgets();3759 QListIterator<QWidget*> it (list);3760 while ((extraw == 0 || extrah == 0) && it.hasNext())3761 {3762 int framew, frameh;3763 QWidget *current = it.next();3764 if (!current->isVisible())3765 continue;3766 3767 framew = current->frameGeometry().width() - current->width();3768 frameh = current->frameGeometry().height() - current->height();3769 3770 extraw = qMax (extraw, framew);3771 extrah = qMax (extrah, frameh);3772 }3773 3774 /// @todo (r=dmik) not sure if we really need this3775 #if 03776 /* sanity check for decoration frames. With embedding, we3777 * might get extraordinary values */3778 if (extraw == 0 || extrah == 0 || extraw > 20 || extrah > 50)3779 {3780 extrah = 50;3781 extraw = 20;3782 }3783 #endif3784 3785 /* On non-X11 platforms, the following would be enough instead of the3786 * above workaround: */3787 // QRect geo = frameGeometry();3788 QRect geo = QRect (0, 0, aWidget->width() + extraw,3789 aWidget->height() + extrah);3790 3791 geo.moveCenter (QPoint (parentGeo.x() + (parentGeo.width() - 1) / 2,3792 parentGeo.y() + (parentGeo.height() - 1) / 2));3793 3794 /* ensure the widget is within the available desktop area */3795 QRect newGeo = normalizeGeometry (geo, deskGeo, aCanResize);3796 #ifdef Q_WS_MAC3797 /* No idea why, but Qt doesn't respect if there is a unified toolbar on the3798 * ::move call. So manually add the height of the toolbar before setting3799 * the position. */3800 if (w)3801 newGeo.translate (0, ::darwinWindowToolBarHeight (aWidget));3802 #endif /* Q_WS_MAC */3803 3804 aWidget->move (newGeo.topLeft());3805 3806 if (aCanResize &&3807 (geo.width() != newGeo.width() || geo.height() != newGeo.height()))3808 aWidget->resize (newGeo.width() - extraw, newGeo.height() - extrah);3809 }3810 3811 /**3812 * Returns the decimal separator for the current locale.3813 */3814 /* static */3815 QChar VBoxGlobal::decimalSep()3816 {3817 return QLocale::system().decimalPoint();3818 }3819 3820 /**3821 * Returns the regexp string that defines the format of the human-readable3822 * size representation, <tt>####[.##] B|KB|MB|GB|TB|PB</tt>.3823 *3824 * This regexp will capture 5 groups of text:3825 * - cap(1): integer number in case when no decimal point is present3826 * (if empty, it means that decimal point is present)3827 * - cap(2): size suffix in case when no decimal point is present (may be empty)3828 * - cap(3): integer number in case when decimal point is present (may be empty)3829 * - cap(4): fraction number (hundredth) in case when decimal point is present3830 * - cap(5): size suffix in case when decimal point is present (note that3831 * B cannot appear there)3832 */3833 /* static */3834 QString VBoxGlobal::sizeRegexp()3835 {3836 QString regexp =3837 tr ("^(?:(?:(\\d+)(?:\\s?(B|KB|MB|GB|TB|PB))?)|(?:(\\d*)%1(\\d{1,2})(?:\\s?(KB|MB|GB|TB|PB))))$", "regexp for matching ####[.##] B|KB|MB|GB|TB|PB, %1=decimal point")3838 .arg (decimalSep());3839 return regexp;3840 }3841 3842 /**3843 * Parses the given size string that should be in form of3844 * <tt>####[.##] B|KB|MB|GB|TB|PB</tt> and returns3845 * the size value in bytes. Zero is returned on error.3846 */3847 /* static */3848 quint64 VBoxGlobal::parseSize (const QString &aText)3849 {3850 QRegExp regexp (sizeRegexp());3851 int pos = regexp.indexIn (aText);3852 if (pos != -1)3853 {3854 QString intgS = regexp.cap (1);3855 QString hundS;3856 QString suff = regexp.cap (2);3857 if (intgS.isEmpty())3858 {3859 intgS = regexp.cap (3);3860 hundS = regexp.cap (4);3861 suff = regexp.cap (5);3862 }3863 3864 quint64 denom = 0;3865 if (suff.isEmpty() || suff == tr ("B", "size suffix Bytes"))3866 denom = 1;3867 else if (suff == tr ("KB", "size suffix KBytes=1024 Bytes"))3868 denom = _1K;3869 else if (suff == tr ("MB", "size suffix MBytes=1024 KBytes"))3870 denom = _1M;3871 else if (suff == tr ("GB", "size suffix GBytes=1024 MBytes"))3872 denom = _1G;3873 else if (suff == tr ("TB", "size suffix TBytes=1024 GBytes"))3874 denom = _1T;3875 else if (suff == tr ("PB", "size suffix PBytes=1024 TBytes"))3876 denom = _1P;3877 3878 quint64 intg = intgS.toULongLong();3879 if (denom == 1)3880 return intg;3881 3882 quint64 hund = hundS.leftJustified (2, '0').toULongLong();3883 hund = hund * denom / 100;3884 intg = intg * denom + hund;3885 return intg;3886 }3887 else3888 return 0;3889 }3890 3891 /**3892 * Formats the given @a aSize value in bytes to a human readable string3893 * in form of <tt>####[.##] B|KB|MB|GB|TB|PB</tt>.3894 *3895 * The @a aMode and @a aDecimal parameters are used for rounding the resulting3896 * number when converting the size value to KB, MB, etc gives a fractional part:3897 * <ul>3898 * <li>When \a aMode is FormatSize_Round, the result is rounded to the3899 * closest number containing \a aDecimal decimal digits.3900 * </li>3901 * <li>When \a aMode is FormatSize_RoundDown, the result is rounded to the3902 * largest number with \a aDecimal decimal digits that is not greater than3903 * the result. This guarantees that converting the resulting string back to3904 * the integer value in bytes will not produce a value greater that the3905 * initial size parameter.3906 * </li>3907 * <li>When \a aMode is FormatSize_RoundUp, the result is rounded to the3908 * smallest number with \a aDecimal decimal digits that is not less than the3909 * result. This guarantees that converting the resulting string back to the3910 * integer value in bytes will not produce a value less that the initial3911 * size parameter.3912 * </li>3913 * </ul>3914 *3915 * @param aSize Size value in bytes.3916 * @param aMode Conversion mode.3917 * @param aDecimal Number of decimal digits in result.3918 * @return Human-readable size string.3919 */3920 /* static */3921 QString VBoxGlobal::formatSize (quint64 aSize, uint aDecimal /* = 2 */,3922 VBoxDefs::FormatSize aMode /* = FormatSize_Round */)3923 {3924 static QString Suffixes [7];3925 Suffixes[0] = tr ("B", "size suffix Bytes");3926 Suffixes[1] = tr ("KB", "size suffix KBytes=1024 Bytes");3927 Suffixes[2] = tr ("MB", "size suffix MBytes=1024 KBytes");3928 Suffixes[3] = tr ("GB", "size suffix GBytes=1024 MBytes");3929 Suffixes[4] = tr ("TB", "size suffix TBytes=1024 GBytes");3930 Suffixes[5] = tr ("PB", "size suffix PBytes=1024 TBytes");3931 Suffixes[6] = (const char *)NULL;3932 AssertCompile(6 < RT_ELEMENTS (Suffixes));3933 3934 quint64 denom = 0;3935 int suffix = 0;3936 3937 if (aSize < _1K)3938 {3939 denom = 1;3940 suffix = 0;3941 }3942 else if (aSize < _1M)3943 {3944 denom = _1K;3945 suffix = 1;3946 }3947 else if (aSize < _1G)3948 {3949 denom = _1M;3950 suffix = 2;3951 }3952 else if (aSize < _1T)3953 {3954 denom = _1G;3955 suffix = 3;3956 }3957 else if (aSize < _1P)3958 {3959 denom = _1T;3960 suffix = 4;3961 }3962 else3963 {3964 denom = _1P;3965 suffix = 5;3966 }3967 3968 quint64 intg = aSize / denom;3969 quint64 decm = aSize % denom;3970 quint64 mult = 1;3971 for (uint i = 0; i < aDecimal; ++ i) mult *= 10;3972 3973 QString number;3974 if (denom > 1)3975 {3976 if (decm)3977 {3978 decm *= mult;3979 /* not greater */3980 if (aMode == VBoxDefs::FormatSize_RoundDown)3981 decm = decm / denom;3982 /* not less */3983 else if (aMode == VBoxDefs::FormatSize_RoundUp)3984 decm = (decm + denom - 1) / denom;3985 /* nearest */3986 else decm = (decm + denom / 2) / denom;3987 }3988 /* check for the fractional part overflow due to rounding */3989 if (decm == mult)3990 {3991 decm = 0;3992 ++ intg;3993 /* check if we've got 1024 XB after rounding and scale down if so */3994 if (intg == 1024 && Suffixes [suffix + 1] != NULL)3995 {3996 intg /= 1024;3997 ++ suffix;3998 }3999 }4000 number = QString::number (intg);4001 if (aDecimal) number += QString ("%1%2").arg (decimalSep())4002 .arg (QString::number (decm).rightJustified (aDecimal, '0'));4003 }4004 else4005 {4006 number = QString::number (intg);4007 }4008 4009 return QString ("%1 %2").arg (number).arg (Suffixes [suffix]);4010 }4011 4012 /**4013 * Returns the required video memory in bytes for the current desktop4014 * resolution at maximum possible screen depth in bpp.4015 */4016 /* static */4017 quint64 VBoxGlobal::requiredVideoMemory (CMachine *aMachine /* = 0 */, int cMonitors /* = 1 */)4018 {4019 QSize desktopRes = QApplication::desktop()->screenGeometry().size();4020 QDesktopWidget *pDW = QApplication::desktop();4021 /* We create a list of the size of all available host monitors. This list4022 * is sorted by value and by starting with the biggest one, we calculate4023 * the memory requirements for every guest screen. This is of course not4024 * correct, but as we can't predict on which host screens the user will4025 * open the guest windows, this is the best assumption we can do, cause it4026 * is the worst case. */4027 QVector<int> screenSize(qMax(cMonitors, pDW->numScreens()), 0);4028 for (int i = 0; i < pDW->numScreens(); ++i)4029 {4030 QRect r = pDW->screenGeometry(i);4031 screenSize[i] = r.width() * r.height();4032 }4033 /* Now sort the vector */4034 qSort(screenSize.begin(), screenSize.end(), qGreater<int>());4035 /* For the case that there are more guest screens configured then host4036 * screens available, replace all zeros with the greatest value in the4037 * vector. */4038 for (int i = 0; i < screenSize.size(); ++i)4039 if (screenSize.at(i) == 0)4040 screenSize.replace(i, screenSize.at(0));4041 4042 quint64 needBits = 0;4043 for (int i = 0; i < cMonitors; ++i)4044 {4045 /* Calculate summary required memory amount in bits */4046 needBits += (screenSize.at(i) * /* with x height */4047 32 + /* we will take the maximum possible bpp for now */4048 8 * _1M) + /* current cache per screen - may be changed in future */4049 8 * 4096; /* adapter info */4050 }4051 /* Translate value into megabytes with rounding to highest side */4052 quint64 needMBytes = needBits % (8 * _1M) ? needBits / (8 * _1M) + 1 :4053 needBits / (8 * _1M) /* convert to megabytes */;4054 4055 if (aMachine && !aMachine->isNull())4056 {4057 QString typeId = aMachine->GetOSTypeId();4058 if (typeId.startsWith("Windows"))4059 {4060 /* Windows guests need offscreen VRAM too for graphics acceleration features. */4061 needMBytes *= 2;4062 }4063 }4064 4065 return needMBytes * _1M;4066 }4067 4068 /**4069 * Puts soft hyphens after every path component in the given file name.4070 *4071 * @param aFileName File name (must be a full path name).4072 */4073 /* static */4074 QString VBoxGlobal::locationForHTML (const QString &aFileName)4075 {4076 /// @todo (dmik) remove?4077 // QString result = QDir::toNativeSeparators (fn);4078 //#ifdef Q_OS_LINUX4079 // result.replace ('/', "/<font color=red>­</font>");4080 //#else4081 // result.replace ('\\', "\\<font color=red>­</font>");4082 //#endif4083 // return result;4084 QFileInfo fi (aFileName);4085 return fi.fileName();4086 }4087 4088 /**4089 * Reformats the input string @a aStr so that:4090 * - strings in single quotes will be put inside <nobr> and marked4091 * with blue color;4092 * - UUIDs be put inside <nobr> and marked4093 * with green color;4094 * - replaces new line chars with </p><p> constructs to form paragraphs4095 * (note that <p> and </p> are not appended to the beginnign and to the4096 * end of the string respectively, to allow the result be appended4097 * or prepended to the existing paragraph).4098 *4099 * If @a aToolTip is true, colouring is not applied, only the <nobr> tag4100 * is added. Also, new line chars are replaced with <br> instead of <p>.4101 */4102 /* static */4103 QString VBoxGlobal::highlight (const QString &aStr, bool aToolTip /* = false */)4104 {4105 QString strFont;4106 QString uuidFont;4107 QString endFont;4108 if (!aToolTip)4109 {4110 strFont = "<font color=#0000CC>";4111 uuidFont = "<font color=#008000>";4112 endFont = "</font>";4113 }4114 4115 QString text = aStr;4116 4117 /* replace special entities, '&' -- first! */4118 text.replace ('&', "&");4119 text.replace ('<', "<");4120 text.replace ('>', ">");4121 text.replace ('\"', """);4122 4123 /* mark strings in single quotes with color */4124 QRegExp rx = QRegExp ("((?:^|\\s)[(]?)'([^']*)'(?=[:.-!);]?(?:\\s|$))");4125 rx.setMinimal (true);4126 text.replace (rx,4127 QString ("\\1%1<nobr>'\\2'</nobr>%2").arg (strFont).arg (endFont));4128 4129 /* mark UUIDs with color */4130 text.replace (QRegExp (4131 "((?:^|\\s)[(]?)"4132 "(\\{[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\})"4133 "(?=[:.-!);]?(?:\\s|$))"),4134 QString ("\\1%1<nobr>\\2</nobr>%2").arg (uuidFont).arg (endFont));4135 4136 /* split to paragraphs at \n chars */4137 if (!aToolTip)4138 text.replace ('\n', "</p><p>");4139 else4140 text.replace ('\n', "<br>");4141 4142 return text;4143 }4144 4145 /* static */4146 QString VBoxGlobal::replaceHtmlEntities(QString strText)4147 {4148 return strText4149 .replace('&', "&")4150 .replace('<', "<")4151 .replace('>', ">")4152 .replace('\"', """);4153 }4154 4155 /**4156 * Reformats the input string @a aStr so that:4157 * - strings in single quotes will be put inside <nobr> and marked4158 * with bold style;4159 * - UUIDs be put inside <nobr> and marked4160 * with italic style;4161 * - replaces new line chars with </p><p> constructs to form paragraphs4162 * (note that <p> and </p> are not appended to the beginnign and to the4163 * end of the string respectively, to allow the result be appended4164 * or prepended to the existing paragraph).4165 */4166 /* static */4167 QString VBoxGlobal::emphasize (const QString &aStr)4168 {4169 QString strEmphStart ("<b>");4170 QString strEmphEnd ("</b>");4171 QString uuidEmphStart ("<i>");4172 QString uuidEmphEnd ("</i>");4173 4174 QString text = aStr;4175 4176 /* replace special entities, '&' -- first! */4177 text.replace ('&', "&");4178 text.replace ('<', "<");4179 text.replace ('>', ">");4180 text.replace ('\"', """);4181 4182 /* mark strings in single quotes with bold style */4183 QRegExp rx = QRegExp ("((?:^|\\s)[(]?)'([^']*)'(?=[:.-!);]?(?:\\s|$))");4184 rx.setMinimal (true);4185 text.replace (rx,4186 QString ("\\1%1<nobr>'\\2'</nobr>%2").arg (strEmphStart).arg (strEmphEnd));4187 4188 /* mark UUIDs with italic style */4189 text.replace (QRegExp (4190 "((?:^|\\s)[(]?)"4191 "(\\{[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\})"4192 "(?=[:.-!);]?(?:\\s|$))"),4193 QString ("\\1%1<nobr>\\2</nobr>%2").arg (uuidEmphStart).arg (uuidEmphEnd));4194 4195 /* split to paragraphs at \n chars */4196 text.replace ('\n', "</p><p>");4197 4198 return text;4199 }4200 4201 /**4202 * This does exactly the same as QLocale::system().name() but corrects its4203 * wrong behavior on Linux systems (LC_NUMERIC for some strange reason takes4204 * precedence over any other locale setting in the QLocale::system()4205 * implementation). This implementation first looks at LC_ALL (as defined by4206 * SUS), then looks at LC_MESSAGES which is designed to define a language for4207 * program messages in case if it differs from the language for other locale4208 * categories. Then it looks for LANG and finally falls back to4209 * QLocale::system().name().4210 *4211 * The order of precedence is well defined here:4212 * http://opengroup.org/onlinepubs/007908799/xbd/envvar.html4213 *4214 * @note This method will return "C" when the requested locale is invalid or4215 * when the "C" locale is set explicitly.4216 */4217 /* static */4218 QString VBoxGlobal::systemLanguageId()4219 {4220 #if defined (Q_WS_MAC)4221 /* QLocale return the right id only if the user select the format of the4222 * language also. So we use our own implementation */4223 return ::darwinSystemLanguage();4224 #elif defined (Q_OS_UNIX)4225 const char *s = RTEnvGet ("LC_ALL");4226 if (s == 0)4227 s = RTEnvGet ("LC_MESSAGES");4228 if (s == 0)4229 s = RTEnvGet ("LANG");4230 if (s != 0)4231 return QLocale (s).name();4232 #endif4233 return QLocale::system().name();4234 }4235 4236 #if defined (Q_WS_X11)4237 4238 static char *XXGetProperty (Display *aDpy, Window aWnd,4239 Atom aPropType, const char *aPropName)4240 {4241 Atom propNameAtom = XInternAtom (aDpy, aPropName,4242 True /* only_if_exists */);4243 if (propNameAtom == None)4244 return NULL;4245 4246 Atom actTypeAtom = None;4247 int actFmt = 0;4248 unsigned long nItems = 0;4249 unsigned long nBytesAfter = 0;4250 unsigned char *propVal = NULL;4251 int rc = XGetWindowProperty (aDpy, aWnd, propNameAtom,4252 0, LONG_MAX, False /* delete */,4253 aPropType, &actTypeAtom, &actFmt,4254 &nItems, &nBytesAfter, &propVal);4255 if (rc != Success)4256 return NULL;4257 4258 return reinterpret_cast <char *> (propVal);4259 }4260 4261 static Bool XXSendClientMessage (Display *aDpy, Window aWnd, const char *aMsg,4262 unsigned long aData0 = 0, unsigned long aData1 = 0,4263 unsigned long aData2 = 0, unsigned long aData3 = 0,4264 unsigned long aData4 = 0)4265 {4266 Atom msgAtom = XInternAtom (aDpy, aMsg, True /* only_if_exists */);4267 if (msgAtom == None)4268 return False;4269 4270 XEvent ev;4271 4272 ev.xclient.type = ClientMessage;4273 ev.xclient.serial = 0;4274 ev.xclient.send_event = True;4275 ev.xclient.display = aDpy;4276 ev.xclient.window = aWnd;4277 ev.xclient.message_type = msgAtom;4278 4279 /* always send as 32 bit for now */4280 ev.xclient.format = 32;4281 ev.xclient.data.l [0] = aData0;4282 ev.xclient.data.l [1] = aData1;4283 ev.xclient.data.l [2] = aData2;4284 ev.xclient.data.l [3] = aData3;4285 ev.xclient.data.l [4] = aData4;4286 4287 return XSendEvent (aDpy, DefaultRootWindow (aDpy), False,4288 SubstructureRedirectMask, &ev) != 0;4289 }4290 4291 #endif4292 4293 /**4294 * Activates the specified window. If necessary, the window will be4295 * de-iconified activation.4296 *4297 * @note On X11, it is implied that @a aWid represents a window of the same4298 * display the application was started on.4299 *4300 * @param aWId Window ID to activate.4301 * @param aSwitchDesktop @c true to switch to the window's desktop before4302 * activation.4303 *4304 * @return @c true on success and @c false otherwise.4305 */4306 /* static */4307 bool VBoxGlobal::activateWindow (WId aWId, bool aSwitchDesktop /* = true */)4308 {4309 bool result = true;4310 4311 #if defined (Q_WS_WIN32)4312 4313 if (IsIconic (aWId))4314 result &= !!ShowWindow (aWId, SW_RESTORE);4315 else if (!IsWindowVisible (aWId))4316 result &= !!ShowWindow (aWId, SW_SHOW);4317 4318 result &= !!SetForegroundWindow (aWId);4319 4320 #elif defined (Q_WS_X11)4321 4322 Display *dpy = QX11Info::display();4323 4324 if (aSwitchDesktop)4325 {4326 /* try to find the desktop ID using the NetWM property */4327 CARD32 *desktop = (CARD32 *) XXGetProperty (dpy, aWId, XA_CARDINAL,4328 "_NET_WM_DESKTOP");4329 if (desktop == NULL)4330 /* if the NetWM propery is not supported try to find the desktop4331 * ID using the GNOME WM property */4332 desktop = (CARD32 *) XXGetProperty (dpy, aWId, XA_CARDINAL,4333 "_WIN_WORKSPACE");4334 4335 if (desktop != NULL)4336 {4337 Bool ok = XXSendClientMessage (dpy, DefaultRootWindow (dpy),4338 "_NET_CURRENT_DESKTOP",4339 *desktop);4340 if (!ok)4341 {4342 LogWarningFunc (("Couldn't switch to desktop=%08X\n",4343 desktop));4344 result = false;4345 }4346 XFree (desktop);4347 }4348 else4349 {4350 LogWarningFunc (("Couldn't find a desktop ID for aWId=%08X\n",4351 aWId));4352 result = false;4353 }4354 }4355 4356 Bool ok = XXSendClientMessage (dpy, aWId, "_NET_ACTIVE_WINDOW");4357 result &= !!ok;4358 4359 XRaiseWindow (dpy, aWId);4360 4361 #else4362 4363 NOREF (aWId);4364 NOREF (aSwitchDesktop);4365 AssertFailed();4366 result = false;4367 4368 #endif4369 4370 if (!result)4371 LogWarningFunc (("Couldn't activate aWId=%08X\n", aWId));4372 4373 return result;4374 }4375 4376 /**4377 * Removes the acceletartor mark (the ampersand symbol) from the given string4378 * and returns the result. The string is supposed to be a menu item's text4379 * that may (or may not) contain the accelerator mark.4380 *4381 * In order to support accelerators used in non-alphabet languages4382 * (e.g. Japanese) that has a form of "(&<L>)" (where <L> is a latin letter),4383 * this method first searches for this pattern and, if found, removes it as a4384 * whole. If such a pattern is not found, then the '&' character is simply4385 * removed from the string.4386 *4387 * @note This function removes only the first occurense of the accelerator4388 * mark.4389 *4390 * @param aText Menu item's text to remove the acceletaror mark from.4391 *4392 * @return The resulting string.4393 */4394 /* static */4395 QString VBoxGlobal::removeAccelMark (const QString &aText)4396 {4397 QString result = aText;4398 4399 QRegExp accel ("\\(&[a-zA-Z]\\)");4400 int pos = accel.indexIn (result);4401 if (pos >= 0)4402 result.remove (pos, accel.cap().length());4403 else4404 {4405 pos = result.indexOf ('&');4406 if (pos >= 0)4407 result.remove (pos, 1);4408 }4409 4410 return result;4411 }4412 4413 /* static */4414 QString VBoxGlobal::insertKeyToActionText (const QString &aText, const QString &aKey)4415 {4416 #ifdef Q_WS_MAC4417 QString key ("%1 (Host+%2)");4418 #else4419 QString key ("%1 \tHost+%2");4420 #endif4421 return key.arg (aText).arg (QKeySequence (aKey).toString (QKeySequence::NativeText));4422 }4423 4424 /* static */4425 QString VBoxGlobal::extractKeyFromActionText (const QString &aText)4426 {4427 QString key;4428 #ifdef Q_WS_MAC4429 QRegExp re (".* \\(Host\\+(.+)\\)");4430 #else4431 QRegExp re (".* \\t\\Host\\+(.+)");4432 #endif4433 if (re.exactMatch (aText))4434 key = re.cap (1);4435 return key;4436 }4437 4438 /**4439 * Joins two pixmaps horizontally with 2px space between them and returns the4440 * result.4441 *4442 * @param aPM1 Left pixmap.4443 * @param aPM2 Right pixmap.4444 */4445 /* static */4446 QPixmap VBoxGlobal::joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2)4447 {4448 if (aPM1.isNull())4449 return aPM2;4450 if (aPM2.isNull())4451 return aPM1;4452 4453 QPixmap result (aPM1.width() + aPM2.width() + 2,4454 qMax (aPM1.height(), aPM2.height()));4455 result.fill (Qt::transparent);4456 4457 QPainter painter (&result);4458 painter.drawPixmap (0, 0, aPM1);4459 painter.drawPixmap (aPM1.width() + 2, result.height() - aPM2.height(), aPM2);4460 painter.end();4461 4462 return result;4463 }4464 4465 /**4466 * Searches for a widget that with @a aName (if it is not NULL) which inherits4467 * @a aClassName (if it is not NULL) and among children of @a aParent. If @a4468 * aParent is NULL, all top-level widgets are searched. If @a aRecursive is4469 * true, child widgets are recursively searched as well.4470 */4471 /* static */4472 QWidget *VBoxGlobal::findWidget (QWidget *aParent, const char *aName,4473 const char *aClassName /* = NULL */,4474 bool aRecursive /* = false */)4475 {4476 if (aParent == NULL)4477 {4478 QWidgetList list = QApplication::topLevelWidgets();4479 foreach(QWidget *w, list)4480 {4481 if ((!aName || strcmp (w->objectName().toAscii().constData(), aName) == 0) &&4482 (!aClassName || strcmp (w->metaObject()->className(), aClassName) == 0))4483 return w;4484 if (aRecursive)4485 {4486 w = findWidget (w, aName, aClassName, aRecursive);4487 if (w)4488 return w;4489 }4490 }4491 return NULL;4492 }4493 4494 /* Find the first children of aParent with the appropriate properties.4495 * Please note that this call is recursivly. */4496 QList<QWidget *> list = qFindChildren<QWidget *> (aParent, aName);4497 foreach(QWidget *child, list)4498 {4499 if (!aClassName || strcmp (child->metaObject()->className(), aClassName) == 0)4500 return child;4501 }4502 return NULL;4503 }4504 4505 /**4506 * Figures out which hard disk formats are currently supported by VirtualBox.4507 * Returned is a list of pairs with the form4508 * <tt>{"Backend Name", "*.suffix1 .suffix2 ..."}</tt>.4509 */4510 /* static */4511 QList <QPair <QString, QString> > VBoxGlobal::HDDBackends()4512 {4513 CSystemProperties systemProperties = vboxGlobal().virtualBox().GetSystemProperties();4514 QVector<CMediumFormat> mediumFormats = systemProperties.GetMediumFormats();4515 QList< QPair<QString, QString> > backendPropList;4516 for (int i = 0; i < mediumFormats.size(); ++ i)4517 {4518 /* File extensions */4519 QVector <QString> fileExtensions = mediumFormats [i].GetFileExtensions();4520 QStringList f;4521 for (int a = 0; a < fileExtensions.size(); ++ a)4522 f << QString ("*.%1").arg (fileExtensions [a]);4523 /* Create a pair out of the backend description and all suffix's. */4524 if (!f.isEmpty())4525 backendPropList << QPair<QString, QString> (mediumFormats [i].GetName(), f.join(" "));4526 }4527 return backendPropList;4528 }4529 4530 /* static */4531 QString VBoxGlobal::documentsPath()4532 {4533 QString path;4534 #if QT_VERSION < 0x0404004535 path = QDir::homePath();4536 #else4537 path = QDesktopServices::storageLocation (QDesktopServices::DocumentsLocation);4538 #endif4539 4540 /* Make sure the path exists */4541 QDir dir (path);4542 if (dir.exists())4543 return QDir::cleanPath (dir.canonicalPath());4544 else4545 {4546 dir.setPath (QDir::homePath() + "/Documents");4547 if (dir.exists())4548 return QDir::cleanPath (dir.canonicalPath());4549 else4550 return QDir::homePath();4551 }4552 }4553 4554 #ifdef VBOX_WITH_VIDEOHWACCEL4555 /* static */4556 bool VBoxGlobal::isAcceleration2DVideoAvailable()4557 {4558 return VBoxQGLOverlay::isAcceleration2DVideoAvailable();4559 }4560 4561 /** additional video memory required for the best 2D support performance4562 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */4563 /* static */4564 quint64 VBoxGlobal::required2DOffscreenVideoMemory()4565 {4566 return VBoxQGLOverlay::required2DOffscreenVideoMemory();4567 }4568 4569 #endif4570 4571 // Public slots4572 ////////////////////////////////////////////////////////////////////////////////4573 4574 /**4575 * Opens the specified URL using OS/Desktop capabilities.4576 *4577 * @param aURL URL to open4578 *4579 * @return true on success and false otherwise4580 */4581 bool VBoxGlobal::openURL (const QString &aURL)4582 {4583 /* Service event */4584 class ServiceEvent : public QEvent4585 {4586 public:4587 4588 ServiceEvent (bool aResult) : QEvent (QEvent::User), mResult (aResult) {}4589 4590 bool result() const { return mResult; }4591 4592 private:4593 4594 bool mResult;4595 };4596 4597 /* Service-Client object */4598 class ServiceClient : public QEventLoop4599 {4600 public:4601 4602 ServiceClient() : mResult (false) {}4603 4604 bool result() const { return mResult; }4605 4606 private:4607 4608 bool event (QEvent *aEvent)4609 {4610 if (aEvent->type() == QEvent::User)4611 {4612 ServiceEvent *pEvent = static_cast <ServiceEvent*> (aEvent);4613 mResult = pEvent->result();4614 pEvent->accept();4615 quit();4616 return true;4617 }4618 return false;4619 }4620 4621 bool mResult;4622 };4623 4624 /* Service-Server object */4625 class ServiceServer : public QThread4626 {4627 public:4628 4629 ServiceServer (ServiceClient &aClient, const QString &sURL)4630 : mClient (aClient), mURL (sURL) {}4631 4632 private:4633 4634 void run()4635 {4636 QApplication::postEvent (&mClient, new ServiceEvent (QDesktopServices::openUrl (mURL)));4637 }4638 4639 ServiceClient &mClient;4640 const QString &mURL;4641 };4642 4643 ServiceClient client;4644 ServiceServer server (client, aURL);4645 server.start();4646 client.exec();4647 server.wait();4648 4649 bool result = client.result();4650 4651 if (!result)4652 vboxProblem().cannotOpenURL (aURL);4653 4654 return result;4655 }4656 4657 /**4658 * Shows the VirtualBox registration dialog.4659 *4660 * @note that this method is not part of VBoxProblemReporter (like e.g.4661 * VBoxProblemReporter::showHelpAboutDialog()) because it is tied to4662 * VBoxCallback::OnExtraDataChange() handling performed by VBoxGlobal.4663 *4664 * @param aForce4665 */4666 void VBoxGlobal::showRegistrationDialog (bool aForce)4667 {4668 NOREF(aForce);4669 #ifdef VBOX_WITH_REGISTRATION4670 if (!aForce && !UIRegistrationWzd::hasToBeShown())4671 return;4672 4673 if (mRegDlg)4674 {4675 /* Show the already opened registration dialog */4676 mRegDlg->setWindowState (mRegDlg->windowState() & ~Qt::WindowMinimized);4677 mRegDlg->raise();4678 mRegDlg->activateWindow();4679 }4680 else4681 {4682 /* Store the ID of the main window to ensure that only one4683 * registration dialog is shown at a time. Due to manipulations with4684 * OnExtraDataCanChange() and OnExtraDataChange() signals, this extra4685 * data item acts like an inter-process mutex, so the first process4686 * that attempts to set it will win, the rest will get a failure from4687 * the SetExtraData() call. */4688 mVBox.SetExtraData (VBoxDefs::GUI_RegistrationDlgWinID,4689 QString ("%1").arg ((qulonglong) mMainWindow->winId()));4690 4691 if (mVBox.isOk())4692 {4693 /* We've got the "mutex", create a new registration dialog */4694 UIRegistrationWzd *dlg = new UIRegistrationWzd (&mRegDlg);4695 dlg->setAttribute (Qt::WA_DeleteOnClose);4696 Assert (dlg == mRegDlg);4697 mRegDlg->show();4698 }4699 }4700 #endif4701 }4702 4703 /**4704 * Shows the VirtualBox version check & update dialog.4705 *4706 * @note that this method is not part of VBoxProblemReporter (like e.g.4707 * VBoxProblemReporter::showHelpAboutDialog()) because it is tied to4708 * VBoxCallback::OnExtraDataChange() handling performed by VBoxGlobal.4709 *4710 * @param aForce4711 */4712 void VBoxGlobal::showUpdateDialog (bool aForce)4713 {4714 /* Silently check in one day after current time-stamp */4715 QTimer::singleShot (24 /* hours */ * 60 /* minutes */ *4716 60 /* seconds */ * 1000 /* milliseconds */,4717 this, SLOT (perDayNewVersionNotifier()));4718 4719 bool isNecessary = VBoxUpdateDlg::isNecessary();4720 4721 if (!aForce && !isNecessary)4722 return;4723 4724 if (mUpdDlg)4725 {4726 if (!mUpdDlg->isHidden())4727 {4728 mUpdDlg->setWindowState (mUpdDlg->windowState() & ~Qt::WindowMinimized);4729 mUpdDlg->raise();4730 mUpdDlg->activateWindow();4731 }4732 }4733 else4734 {4735 /* Store the ID of the main window to ensure that only one4736 * update dialog is shown at a time. Due to manipulations with4737 * OnExtraDataCanChange() and OnExtraDataChange() signals, this extra4738 * data item acts like an inter-process mutex, so the first process4739 * that attempts to set it will win, the rest will get a failure from4740 * the SetExtraData() call. */4741 mVBox.SetExtraData (VBoxDefs::GUI_UpdateDlgWinID,4742 QString ("%1").arg ((qulonglong) mMainWindow->winId()));4743 4744 if (mVBox.isOk())4745 {4746 /* We've got the "mutex", create a new update dialog */4747 VBoxUpdateDlg *dlg = new VBoxUpdateDlg (&mUpdDlg, aForce, 0);4748 dlg->setAttribute (Qt::WA_DeleteOnClose);4749 Assert (dlg == mUpdDlg);4750 4751 /* Update dialog always in background mode for now.4752 * if (!aForce && isAutomatic) */4753 mUpdDlg->search();4754 /* else mUpdDlg->show(); */4755 }4756 }4757 }4758 4759 void VBoxGlobal::perDayNewVersionNotifier()4760 {4761 showUpdateDialog (false /* force show? */);4762 }4763 4764 // Protected members4765 ////////////////////////////////////////////////////////////////////////////////4766 4767 bool VBoxGlobal::event (QEvent *e)4768 {4769 switch (e->type())4770 {4771 case VBoxDefs::AsyncEventType:4772 {4773 VBoxAsyncEvent *ev = (VBoxAsyncEvent *) e;4774 ev->handle();4775 return true;4776 }4777 4778 case VBoxDefs::MediaEnumEventType:4779 {4780 VBoxMediaEnumEvent *ev = (VBoxMediaEnumEvent*) e;4781 4782 if (!ev->mLast)4783 {4784 if (ev->mMedium.state() == KMediumState_Inaccessible &&4785 !ev->mMedium.result().isOk())4786 vboxProblem().cannotGetMediaAccessibility (ev->mMedium);4787 Assert (ev->mIterator != mMediaList.end());4788 *(ev->mIterator) = ev->mMedium;4789 emit mediumEnumerated (*ev->mIterator);4790 ++ ev->mIterator;4791 }4792 else4793 {4794 /* the thread has posted the last message, wait for termination */4795 mMediaEnumThread->wait();4796 delete mMediaEnumThread;4797 mMediaEnumThread = 0;4798 emit mediumEnumFinished (mMediaList);4799 }4800 4801 return true;4802 }4803 4804 /* VirtualBox callback events */4805 4806 case VBoxDefs::MachineStateChangeEventType:4807 {4808 emit machineStateChanged (*(VBoxMachineStateChangeEvent *) e);4809 return true;4810 }4811 case VBoxDefs::MachineDataChangeEventType:4812 {4813 emit machineDataChanged (*(VBoxMachineDataChangeEvent *) e);4814 return true;4815 }4816 case VBoxDefs::MachineRegisteredEventType:4817 {4818 emit machineRegistered (*(VBoxMachineRegisteredEvent *) e);4819 return true;4820 }4821 case VBoxDefs::SessionStateChangeEventType:4822 {4823 emit sessionStateChanged (*(VBoxSessionStateChangeEvent *) e);4824 return true;4825 }4826 case VBoxDefs::SnapshotEventType:4827 {4828 emit snapshotChanged (*(VBoxSnapshotEvent *) e);4829 return true;4830 }4831 case VBoxDefs::CanShowRegDlgEventType:4832 {4833 emit canShowRegDlg (((VBoxCanShowRegDlgEvent *) e)->mCanShow);4834 return true;4835 }4836 case VBoxDefs::CanShowUpdDlgEventType:4837 {4838 emit canShowUpdDlg (((VBoxCanShowUpdDlgEvent *) e)->mCanShow);4839 return true;4840 }4841 case VBoxDefs::ChangeGUILanguageEventType:4842 {4843 loadLanguage (static_cast<VBoxChangeGUILanguageEvent*> (e)->mLangId);4844 return true;4845 }4846 #ifdef VBOX_GUI_WITH_SYSTRAY4847 case VBoxDefs::MainWindowCountChangeEventType:4848 4849 emit mainWindowCountChanged (*(VBoxMainWindowCountChangeEvent *) e);4850 return true;4851 4852 case VBoxDefs::CanShowTrayIconEventType:4853 {4854 emit trayIconCanShow (*(VBoxCanShowTrayIconEvent *) e);4855 return true;4856 }4857 case VBoxDefs::ShowTrayIconEventType:4858 {4859 emit trayIconShow (*(VBoxShowTrayIconEvent *) e);4860 return true;4861 }4862 case VBoxDefs::TrayIconChangeEventType:4863 {4864 emit trayIconChanged (*(VBoxChangeTrayIconEvent *) e);4865 return true;4866 }4867 #endif4868 #if defined(Q_WS_MAC)4869 case VBoxDefs::ChangeDockIconUpdateEventType:4870 {4871 emit dockIconUpdateChanged (*(VBoxChangeDockIconUpdateEvent *) e);4872 return true;4873 }4874 case VBoxDefs::ChangePresentationmodeEventType:4875 {4876 emit presentationModeChanged (*(VBoxChangePresentationModeEvent *) e);4877 return true;4878 }4879 #endif4880 default:4881 break;4882 }4883 4884 return QObject::event (e);4885 }4886 4887 bool VBoxGlobal::eventFilter (QObject *aObject, QEvent *aEvent)4888 {4889 if (aEvent->type() == QEvent::LanguageChange &&4890 aObject->isWidgetType() &&4891 static_cast <QWidget *> (aObject)->isTopLevel())4892 {4893 /* Catch the language change event before any other widget gets it in4894 * order to invalidate cached string resources (like the details view4895 * templates) that may be used by other widgets. */4896 QWidgetList list = QApplication::topLevelWidgets();4897 if (list.first() == aObject)4898 {4899 /* call this only once per every language change (see4900 * QApplication::installTranslator() for details) */4901 retranslateUi();4902 }4903 }4904 4905 return QObject::eventFilter (aObject, aEvent);4906 }4907 4908 // Private members4909 ////////////////////////////////////////////////////////////////////////////////4910 4911 void VBoxGlobal::init()4912 {4913 #ifdef DEBUG4914 mVerString += " [DEBUG]";4915 #endif4916 4917 #ifdef Q_WS_WIN4918 /* COM for the main thread is initialized in main() */4919 #else4920 HRESULT rc = COMBase::InitializeCOM();4921 if (FAILED (rc))4922 {4923 vboxProblem().cannotInitCOM (rc);4924 return;4925 }4926 #endif4927 4928 mVBox.createInstance (CLSID_VirtualBox);4929 if (!mVBox.isOk())4930 {4931 vboxProblem().cannotCreateVirtualBox (mVBox);4932 return;4933 }4934 4935 /* create default non-null global settings */4936 gset = VBoxGlobalSettings (false);4937 4938 /* try to load global settings */4939 gset.load (mVBox);4940 if (!mVBox.isOk() || !gset)4941 {4942 vboxProblem().cannotLoadGlobalConfig (mVBox, gset.lastError());4943 return;4944 }4945 4946 /* Load the customized language as early as possible to get possible error4947 * messages translated */4948 QString sLanguageId = gset.languageId();4949 if (!sLanguageId.isNull())4950 loadLanguage (sLanguageId);4951 4952 retranslateUi();4953 4954 #ifdef VBOX_GUI_WITH_SYSTRAY4955 {4956 /* Increase open Fe/Qt4 windows reference count. */4957 int c = mVBox.GetExtraData (VBoxDefs::GUI_MainWindowCount).toInt() + 1;4958 AssertMsgReturnVoid ((c >= 0) || (mVBox.isOk()),4959 ("Something went wrong with the window reference count!"));4960 mVBox.SetExtraData (VBoxDefs::GUI_MainWindowCount, QString ("%1").arg (c));4961 mIncreasedWindowCounter = mVBox.isOk();4962 AssertReturnVoid (mIncreasedWindowCounter);4963 }4964 #endif4965 4966 /* Initialize guest OS Type list. */4967 CGuestOSTypeVector coll = mVBox.GetGuestOSTypes();4968 int osTypeCount = coll.size();4969 AssertMsg (osTypeCount > 0, ("Number of OS types must not be zero"));4970 if (osTypeCount > 0)4971 {4972 /* Here we assume the 'Other' type is always the first, so we4973 * remember it and will append it to the list when finished. */4974 CGuestOSType otherType = coll[0];4975 QString otherFamilyId (otherType.GetFamilyId());4976 4977 /* Fill the lists with all the available OS Types except4978 * the 'Other' type, which will be appended. */4979 for (int i = 1; i < coll.size(); ++i)4980 {4981 CGuestOSType os = coll[i];4982 QString familyId (os.GetFamilyId());4983 if (!mFamilyIDs.contains (familyId))4984 {4985 mFamilyIDs << familyId;4986 mTypes << QList <CGuestOSType> ();4987 }4988 mTypes [mFamilyIDs.indexOf (familyId)].append (os);4989 }4990 4991 /* Append the 'Other' OS Type to the end of list. */4992 if (!mFamilyIDs.contains (otherFamilyId))4993 {4994 mFamilyIDs << otherFamilyId;4995 mTypes << QList <CGuestOSType> ();4996 }4997 mTypes [mFamilyIDs.indexOf (otherFamilyId)].append (otherType);4998 }4999 5000 /* Fill in OS type icon dictionary. */5001 static const char *kOSTypeIcons [][2] =5002 {5003 {"Other", ":/os_other.png"},5004 {"DOS", ":/os_dos.png"},5005 {"Netware", ":/os_netware.png"},5006 {"L4", ":/os_l4.png"},5007 {"Windows31", ":/os_win31.png"},5008 {"Windows95", ":/os_win95.png"},5009 {"Windows98", ":/os_win98.png"},5010 {"WindowsMe", ":/os_winme.png"},5011 {"WindowsNT4", ":/os_winnt4.png"},5012 {"Windows2000", ":/os_win2k.png"},5013 {"WindowsXP", ":/os_winxp.png"},5014 {"WindowsXP_64", ":/os_winxp_64.png"},5015 {"Windows2003", ":/os_win2k3.png"},5016 {"Windows2003_64", ":/os_win2k3_64.png"},5017 {"WindowsVista", ":/os_winvista.png"},5018 {"WindowsVista_64", ":/os_winvista_64.png"},5019 {"Windows2008", ":/os_win2k8.png"},5020 {"Windows2008_64", ":/os_win2k8_64.png"},5021 {"Windows7", ":/os_win7.png"},5022 {"Windows7_64", ":/os_win7_64.png"},5023 {"WindowsNT", ":/os_win_other.png"},5024 {"OS2Warp3", ":/os_os2warp3.png"},5025 {"OS2Warp4", ":/os_os2warp4.png"},5026 {"OS2Warp45", ":/os_os2warp45.png"},5027 {"OS2eCS", ":/os_os2ecs.png"},5028 {"OS2", ":/os_os2_other.png"},5029 {"Linux22", ":/os_linux22.png"},5030 {"Linux24", ":/os_linux24.png"},5031 {"Linux24_64", ":/os_linux24_64.png"},5032 {"Linux26", ":/os_linux26.png"},5033 {"Linux26_64", ":/os_linux26_64.png"},5034 {"ArchLinux", ":/os_archlinux.png"},5035 {"ArchLinux_64", ":/os_archlinux_64.png"},5036 {"Debian", ":/os_debian.png"},5037 {"Debian_64", ":/os_debian_64.png"},5038 {"OpenSUSE", ":/os_opensuse.png"},5039 {"OpenSUSE_64", ":/os_opensuse_64.png"},5040 {"Fedora", ":/os_fedora.png"},5041 {"Fedora_64", ":/os_fedora_64.png"},5042 {"Gentoo", ":/os_gentoo.png"},5043 {"Gentoo_64", ":/os_gentoo_64.png"},5044 {"Mandriva", ":/os_mandriva.png"},5045 {"Mandriva_64", ":/os_mandriva_64.png"},5046 {"RedHat", ":/os_redhat.png"},5047 {"RedHat_64", ":/os_redhat_64.png"},5048 {"Turbolinux", ":/os_turbolinux.png"},5049 {"Turbolinux_64", ":/os_turbolinux_64.png"},5050 {"Ubuntu", ":/os_ubuntu.png"},5051 {"Ubuntu_64", ":/os_ubuntu_64.png"},5052 {"Xandros", ":/os_xandros.png"},5053 {"Xandros_64", ":/os_xandros_64.png"},5054 {"Oracle", ":/os_oracle.png"},5055 {"Oracle_64", ":/os_oracle_64.png"},5056 {"Linux", ":/os_linux_other.png"},5057 {"FreeBSD", ":/os_freebsd.png"},5058 {"FreeBSD_64", ":/os_freebsd_64.png"},5059 {"OpenBSD", ":/os_openbsd.png"},5060 {"OpenBSD_64", ":/os_openbsd_64.png"},5061 {"NetBSD", ":/os_netbsd.png"},5062 {"NetBSD_64", ":/os_netbsd_64.png"},5063 {"Solaris", ":/os_solaris.png"},5064 {"Solaris_64", ":/os_solaris_64.png"},5065 {"OpenSolaris", ":/os_opensolaris.png"},5066 {"OpenSolaris_64", ":/os_opensolaris_64.png"},5067 {"QNX", ":/os_qnx.png"},5068 {"MacOS", ":/os_macosx.png"},5069 {"MacOS_64", ":/os_macosx_64.png"},5070 };5071 for (uint n = 0; n < SIZEOF_ARRAY (kOSTypeIcons); ++ n)5072 {5073 mOsTypeIcons.insert (kOSTypeIcons [n][0],5074 new QPixmap (kOSTypeIcons [n][1]));5075 }5076 5077 /* fill in VM state icon map */5078 static const struct5079 {5080 KMachineState state;5081 const char *name;5082 }5083 kVMStateIcons[] =5084 {5085 {KMachineState_Null, NULL},5086 {KMachineState_PoweredOff, ":/state_powered_off_16px.png"},5087 {KMachineState_Saved, ":/state_saved_16px.png"},5088 {KMachineState_Aborted, ":/state_aborted_16px.png"},5089 {KMachineState_Teleported, ":/state_saved_16px.png"}, /** @todo Live Migration: New icon? (not really important) */5090 {KMachineState_Running, ":/state_running_16px.png"},5091 {KMachineState_Paused, ":/state_paused_16px.png"},5092 {KMachineState_Teleporting, ":/state_running_16px.png"}, /** @todo Live Migration: New icon? (not really important) */5093 {KMachineState_LiveSnapshotting, ":/state_running_16px.png"}, /** @todo Live Migration: New icon? (not really important) */5094 {KMachineState_Stuck, ":/state_stuck_16px.png"},5095 {KMachineState_Starting, ":/state_running_16px.png"}, /// @todo (dmik) separate icon?5096 {KMachineState_Stopping, ":/state_running_16px.png"}, /// @todo (dmik) separate icon?5097 {KMachineState_Saving, ":/state_saving_16px.png"},5098 {KMachineState_Restoring, ":/state_restoring_16px.png"},5099 {KMachineState_TeleportingPausedVM, ":/state_saving_16px.png"}, /** @todo Live Migration: New icon? (not really important) */5100 {KMachineState_TeleportingIn, ":/state_restoring_16px.png"}, /** @todo Live Migration: New icon? (not really important) */5101 {KMachineState_RestoringSnapshot, ":/state_discarding_16px.png"},5102 {KMachineState_DeletingSnapshot, ":/state_discarding_16px.png"},5103 {KMachineState_DeletingSnapshotOnline, ":/state_discarding_16px.png"}, /// @todo live snapshot deletion: new icon?5104 {KMachineState_DeletingSnapshotPaused, ":/state_discarding_16px.png"}, /// @todo live snapshot deletion: new icon?5105 {KMachineState_SettingUp, ":/settings_16px.png"},5106 };5107 for (uint n = 0; n < SIZEOF_ARRAY (kVMStateIcons); n ++)5108 {5109 mVMStateIcons.insert (kVMStateIcons [n].state,5110 new QPixmap (kVMStateIcons [n].name));5111 }5112 5113 /* initialize state colors map */5114 mVMStateColors.insert (KMachineState_Null, new QColor (Qt::red));5115 mVMStateColors.insert (KMachineState_PoweredOff, new QColor (Qt::gray));5116 mVMStateColors.insert (KMachineState_Saved, new QColor (Qt::yellow));5117 mVMStateColors.insert (KMachineState_Aborted, new QColor (Qt::darkRed));5118 mVMStateColors.insert (KMachineState_Teleported, new QColor (Qt::red));5119 mVMStateColors.insert (KMachineState_Running, new QColor (Qt::green));5120 mVMStateColors.insert (KMachineState_Paused, new QColor (Qt::darkGreen));5121 mVMStateColors.insert (KMachineState_Stuck, new QColor (Qt::darkMagenta));5122 mVMStateColors.insert (KMachineState_Teleporting, new QColor (Qt::blue));5123 mVMStateColors.insert (KMachineState_LiveSnapshotting, new QColor (Qt::green));5124 mVMStateColors.insert (KMachineState_Starting, new QColor (Qt::green));5125 mVMStateColors.insert (KMachineState_Stopping, new QColor (Qt::green));5126 mVMStateColors.insert (KMachineState_Saving, new QColor (Qt::green));5127 mVMStateColors.insert (KMachineState_Restoring, new QColor (Qt::green));5128 mVMStateColors.insert (KMachineState_TeleportingPausedVM, new QColor (Qt::blue));5129 mVMStateColors.insert (KMachineState_TeleportingIn, new QColor (Qt::blue));5130 mVMStateColors.insert (KMachineState_RestoringSnapshot, new QColor (Qt::green));5131 mVMStateColors.insert (KMachineState_DeletingSnapshot, new QColor (Qt::green));5132 mVMStateColors.insert (KMachineState_DeletingSnapshotOnline, new QColor (Qt::green));5133 mVMStateColors.insert (KMachineState_DeletingSnapshotPaused, new QColor (Qt::darkGreen));5134 mVMStateColors.insert (KMachineState_SettingUp, new QColor (Qt::green));5135 5136 /* online/offline snapshot icons */5137 mOfflineSnapshotIcon = QPixmap (":/offline_snapshot_16px.png");5138 mOnlineSnapshotIcon = QPixmap (":/online_snapshot_16px.png");5139 5140 qApp->installEventFilter (this);5141 5142 /* process command line */5143 5144 bool bForceSeamless = false;5145 bool bForceFullscreen = false;5146 5147 vm_render_mode_str = RTStrDup (virtualBox()5148 .GetExtraData (VBoxDefs::GUI_RenderMode).toAscii().constData());5149 5150 #ifdef Q_WS_X115151 mIsKWinManaged = X11IsWindowManagerKWin();5152 #endif5153 5154 #ifdef VBOX_WITH_DEBUGGER_GUI5155 # ifdef VBOX_WITH_DEBUGGER_GUI_MENU5156 mDbgEnabled = true;5157 # else5158 mDbgEnabled = RTEnvExist("VBOX_GUI_DBG_ENABLED");5159 # endif5160 mDbgAutoShow = mDbgAutoShowCommandLine = mDbgAutoShowStatistics5161 = RTEnvExist("VBOX_GUI_DBG_AUTO_SHOW");5162 mStartPaused = false;5163 #endif5164 5165 mShowStartVMErrors = true;5166 bool startVM = false;5167 QString vmNameOrUuid;5168 5169 int argc = qApp->argc();5170 int i = 1;5171 while (i < argc)5172 {5173 const char *arg = qApp->argv() [i];5174 /* NOTE: the check here must match the corresponding check for the5175 * options to start a VM in main.cpp and hardenedmain.cpp exactly,5176 * otherwise there will be weird error messages. */5177 if ( !::strcmp (arg, "--startvm")5178 || !::strcmp (arg, "-startvm"))5179 {5180 if (++i < argc)5181 {5182 vmNameOrUuid = QString (qApp->argv() [i]);5183 startVM = true;5184 }5185 }5186 else if (!::strcmp(arg, "-seamless") || !::strcmp(arg, "--seamless"))5187 {5188 bForceSeamless = true;5189 }5190 else if (!::strcmp(arg, "-fullscreen") || !::strcmp(arg, "--fullscreen"))5191 {5192 bForceFullscreen = true;5193 }5194 #ifdef VBOX_GUI_WITH_SYSTRAY5195 else if (!::strcmp (arg, "-systray") || !::strcmp (arg, "--systray"))5196 {5197 mIsTrayMenu = true;5198 }5199 #endif5200 else if (!::strcmp (arg, "-comment") || !::strcmp (arg, "--comment"))5201 {5202 ++i;5203 }5204 else if (!::strcmp (arg, "-rmode") || !::strcmp (arg, "--rmode"))5205 {5206 if (++i < argc)5207 vm_render_mode_str = qApp->argv() [i];5208 }5209 else if (!::strcmp (arg, "--no-startvm-errormsgbox"))5210 {5211 mShowStartVMErrors = false;5212 }5213 #ifdef VBOX_WITH_DEBUGGER_GUI5214 else if (!::strcmp (arg, "-dbg") || !::strcmp (arg, "--dbg"))5215 {5216 mDbgEnabled = true;5217 }5218 else if (!::strcmp( arg, "-debug") || !::strcmp (arg, "--debug"))5219 {5220 mDbgEnabled = true;5221 mDbgAutoShow = mDbgAutoShowCommandLine = mDbgAutoShowStatistics = true;5222 mStartPaused = true;5223 }5224 else if (!::strcmp (arg, "--debug-command-line"))5225 {5226 mDbgEnabled = true;5227 mDbgAutoShow = mDbgAutoShowCommandLine = true;5228 mStartPaused = true;5229 }5230 else if (!::strcmp (arg, "--debug-statistics"))5231 {5232 mDbgEnabled = true;5233 mDbgAutoShow = mDbgAutoShowStatistics = true;5234 mStartPaused = true;5235 }5236 else if (!::strcmp (arg, "-no-debug") || !::strcmp (arg, "--no-debug"))5237 {5238 mDbgEnabled = false;5239 mDbgAutoShow = false;5240 mDbgAutoShowCommandLine = false;5241 mDbgAutoShowStatistics = false;5242 }5243 /* Not quite debug options, but they're only useful with the debugger bits. */5244 else if (!::strcmp (arg, "--start-paused"))5245 {5246 mStartPaused = true;5247 }5248 else if (!::strcmp (arg, "--start-running"))5249 {5250 mStartPaused = false;5251 }5252 #endif5253 /** @todo add an else { msgbox(syntax error); exit(1); } here, pretty please... */5254 i++;5255 }5256 5257 if (startVM)5258 {5259 QUuid uuid = QUuid(vmNameOrUuid);5260 if (!uuid.isNull())5261 {5262 vmUuid = vmNameOrUuid;5263 }5264 else5265 {5266 CMachine m = mVBox.FindMachine (vmNameOrUuid);5267 if (m.isNull())5268 {5269 if (showStartVMErrors())5270 vboxProblem().cannotFindMachineByName (mVBox, vmNameOrUuid);5271 return;5272 }5273 vmUuid = m.GetId();5274 }5275 }5276 5277 if (bForceSeamless && !vmUuid.isEmpty())5278 {5279 mVBox.GetMachine(vmUuid).SetExtraData(VBoxDefs::GUI_Seamless, "on");5280 }5281 else if (bForceFullscreen && !vmUuid.isEmpty())5282 {5283 mVBox.GetMachine(vmUuid).SetExtraData(VBoxDefs::GUI_Fullscreen, "on");5284 }5285 5286 vm_render_mode = vboxGetRenderMode (vm_render_mode_str);5287 5288 /* setup the callback */5289 callback = CVirtualBoxCallback (new VBoxCallback (*this));5290 mVBox.RegisterCallback (callback);5291 AssertWrapperOk (mVBox);5292 if (!mVBox.isOk())5293 return;5294 5295 #ifdef VBOX_WITH_DEBUGGER_GUI5296 /* setup the debugger gui. */5297 if (RTEnvExist("VBOX_GUI_NO_DEBUGGER"))5298 mDbgEnabled = mDbgAutoShow = mDbgAutoShowCommandLine = mDbgAutoShowStatistics = false;5299 if (mDbgEnabled)5300 {5301 int vrc = SUPR3HardenedLdrLoadAppPriv("VBoxDbg", &mhVBoxDbg);5302 if (RT_FAILURE(vrc))5303 {5304 mhVBoxDbg = NIL_RTLDRMOD;5305 mDbgAutoShow = mDbgAutoShowCommandLine = mDbgAutoShowStatistics = false;5306 LogRel(("Failed to load VBoxDbg, rc=%Rrc\n", vrc));5307 }5308 }5309 #endif5310 5311 mValid = true;5312 }5313 5314 /** @internal5315 *5316 * This method should be never called directly. It is called automatically5317 * when the application terminates.5318 */5319 void VBoxGlobal::cleanup()5320 {5321 /* sanity check */5322 if (!sVBoxGlobalInCleanup)5323 {5324 AssertMsgFailed (("Should never be called directly\n"));5325 return;5326 }5327 5328 #ifdef VBOX_GUI_WITH_SYSTRAY5329 if (mIncreasedWindowCounter)5330 {5331 /* Decrease open Fe/Qt4 windows reference count. */5332 int c = mVBox.GetExtraData (VBoxDefs::GUI_MainWindowCount).toInt() - 1;5333 AssertMsg ((c >= 0) || (mVBox.isOk()),5334 ("Something went wrong with the window reference count!"));5335 if (c < 0)5336 c = 0; /* Clean up the mess. */5337 mVBox.SetExtraData (VBoxDefs::GUI_MainWindowCount,5338 (c > 0) ? QString ("%1").arg (c) : NULL);5339 AssertWrapperOk (mVBox);5340 if (c == 0)5341 {5342 mVBox.SetExtraData (VBoxDefs::GUI_TrayIconWinID, NULL);5343 AssertWrapperOk (mVBox);5344 }5345 }5346 #endif5347 5348 if (!callback.isNull())5349 {5350 mVBox.UnregisterCallback (callback);5351 AssertWrapperOk (mVBox);5352 callback.detach();5353 }5354 5355 if (mMediaEnumThread)5356 {5357 /* sVBoxGlobalInCleanup is true here, so just wait for the thread */5358 mMediaEnumThread->wait();5359 delete mMediaEnumThread;5360 mMediaEnumThread = 0;5361 }5362 5363 #ifdef VBOX_WITH_REGISTRATION5364 if (mRegDlg)5365 mRegDlg->close();5366 #endif5367 5368 if (mSelectorWnd)5369 delete mSelectorWnd;5370 if (m_pVirtualMachine)5371 delete m_pVirtualMachine;5372 5373 /* ensure CGuestOSType objects are no longer used */5374 mFamilyIDs.clear();5375 mTypes.clear();5376 5377 /* media list contains a lot of CUUnknown, release them */5378 mMediaList.clear();5379 /* the last step to ensure we don't use COM any more */5380 mVBox.detach();5381 5382 /* There may be VBoxMediaEnumEvent instances still in the message5383 * queue which reference COM objects. Remove them to release those objects5384 * before uninitializing the COM subsystem. */5385 QApplication::removePostedEvents (this);5386 5387 #ifdef Q_WS_WIN5388 /* COM for the main thread is shutdown in main() */5389 #else5390 COMBase::CleanupCOM();5391 #endif5392 5393 mValid = false;5394 }5395 5396 /** @fn vboxGlobal5397 *5398 * Shortcut to the static VBoxGlobal::instance() method, for convenience.5399 */5400 5401 5402 /**5403 * USB Popup Menu class methods5404 * This class provides the list of USB devices attached to the host.5405 */5406 VBoxUSBMenu::VBoxUSBMenu (QWidget *aParent) : QMenu (aParent)5407 {5408 connect (this, SIGNAL (aboutToShow()),5409 this, SLOT (processAboutToShow()));5410 // connect (this, SIGNAL (hovered (QAction *)),5411 // this, SLOT (processHighlighted (QAction *)));5412 }5413 5414 const CUSBDevice& VBoxUSBMenu::getUSB (QAction *aAction)5415 {5416 return mUSBDevicesMap [aAction];5417 }5418 5419 void VBoxUSBMenu::setConsole (const CConsole &aConsole)5420 {5421 mConsole = aConsole;5422 }5423 5424 void VBoxUSBMenu::processAboutToShow()5425 {5426 clear();5427 mUSBDevicesMap.clear();5428 5429 CHost host = vboxGlobal().virtualBox().GetHost();5430 5431 bool isUSBEmpty = host.GetUSBDevices().size() == 0;5432 if (isUSBEmpty)5433 {5434 QAction *action = addAction (tr ("<no devices available>", "USB devices"));5435 action->setEnabled (false);5436 action->setToolTip (tr ("No supported devices connected to the host PC",5437 "USB device tooltip"));5438 }5439 else5440 {5441 CHostUSBDeviceVector devvec = host.GetUSBDevices();5442 for (int i = 0; i < devvec.size(); ++i)5443 {5444 CHostUSBDevice dev = devvec[i];5445 CUSBDevice usb (dev);5446 QAction *action = addAction (vboxGlobal().details (usb));5447 action->setCheckable (true);5448 mUSBDevicesMap [action] = usb;5449 /* check if created item was alread attached to this session */5450 if (!mConsole.isNull())5451 {5452 CUSBDevice attachedUSB =5453 mConsole.FindUSBDeviceById (usb.GetId());5454 action->setChecked (!attachedUSB.isNull());5455 action->setEnabled (dev.GetState() !=5456 KUSBDeviceState_Unavailable);5457 }5458 }5459 }5460 }5461 5462 bool VBoxUSBMenu::event(QEvent *aEvent)5463 {5464 /* We provide dynamic tooltips for the usb devices */5465 if (aEvent->type() == QEvent::ToolTip)5466 {5467 QHelpEvent *helpEvent = static_cast<QHelpEvent *> (aEvent);5468 QAction *action = actionAt (helpEvent->pos());5469 if (action)5470 {5471 CUSBDevice usb = mUSBDevicesMap [action];5472 if (!usb.isNull())5473 {5474 QToolTip::showText (helpEvent->globalPos(), vboxGlobal().toolTip (usb));5475 return true;5476 }5477 }5478 }5479 return QMenu::event (aEvent);5480 }5481 5482 /**5483 * Enable/Disable Menu class.5484 * This class provides enable/disable menu items.5485 */5486 VBoxSwitchMenu::VBoxSwitchMenu (QWidget *aParent, QAction *aAction,5487 bool aInverted)5488 : QMenu (aParent), mAction (aAction), mInverted (aInverted)5489 {5490 /* this menu works only with toggle action */5491 Assert (aAction->isCheckable());5492 addAction(aAction);5493 connect (this, SIGNAL (aboutToShow()),5494 this, SLOT (processAboutToShow()));5495 }5496 5497 void VBoxSwitchMenu::setToolTip (const QString &aTip)5498 {5499 mAction->setToolTip (aTip);5500 }5501 5502 void VBoxSwitchMenu::processAboutToShow()5503 {5504 QString text = mAction->isChecked() ^ mInverted ? tr ("Disable") : tr ("Enable");5505 mAction->setText (text);5506 }5507 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIIconPool.h
r30187 r30192 2 2 * 3 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * VBoxGlobal class declaration4 * UIIconPool class declarations 5 5 */ 6 6 7 7 /* 8 * Copyright (C) 20 06-2010 Oracle Corporation8 * Copyright (C) 2010 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 17 17 */ 18 18 19 #ifndef __ VBoxGlobal_h__20 #define __ VBoxGlobal_h__19 #ifndef __UIIconPool_h__ 20 #define __UIIconPool_h__ 21 21 22 #include "COMDefs.h" 23 #include "VBox/com/Guid.h" 22 /* Global includes */ 23 #include <QIcon> 24 #include <QStyle> 24 25 25 #include "VBoxGlobalSettings.h" 26 #include "VBoxMedium.h" 27 28 /* Qt includes */ 29 #include <QApplication> 30 #include <QLayout> 31 #include <QMenu> 32 #include <QStyle> 33 #include <QProcess> 34 #include <QHash> 35 36 #ifdef Q_WS_X11 37 # include <sys/wait.h> 38 #endif 39 40 class QAction; 41 class QLabel; 42 class QToolButton; 43 class UIMachine; 44 45 // VirtualBox callback events 46 //////////////////////////////////////////////////////////////////////////////// 47 48 class VBoxMachineStateChangeEvent : public QEvent 49 { 50 public: 51 VBoxMachineStateChangeEvent (const QString &aId, KMachineState aState) 52 : QEvent ((QEvent::Type) VBoxDefs::MachineStateChangeEventType) 53 , id (aId), state (aState) 54 {} 55 56 const QString id; 57 const KMachineState state; 58 }; 59 60 class VBoxMachineDataChangeEvent : public QEvent 61 { 62 public: 63 VBoxMachineDataChangeEvent (const QString &aId) 64 : QEvent ((QEvent::Type) VBoxDefs::MachineDataChangeEventType) 65 , id (aId) 66 {} 67 68 const QString id; 69 }; 70 71 class VBoxMachineRegisteredEvent : public QEvent 72 { 73 public: 74 VBoxMachineRegisteredEvent (const QString &aId, bool aRegistered) 75 : QEvent ((QEvent::Type) VBoxDefs::MachineRegisteredEventType) 76 , id (aId), registered (aRegistered) 77 {} 78 79 const QString id; 80 const bool registered; 81 }; 82 83 class VBoxSessionStateChangeEvent : public QEvent 84 { 85 public: 86 VBoxSessionStateChangeEvent (const QString &aId, KSessionState aState) 87 : QEvent ((QEvent::Type) VBoxDefs::SessionStateChangeEventType) 88 , id (aId), state (aState) 89 {} 90 91 const QString id; 92 const KSessionState state; 93 }; 94 95 class VBoxSnapshotEvent : public QEvent 26 class UIIconPool 96 27 { 97 28 public: 98 29 99 enum What { Taken, Deleted, Changed }; 30 enum UIDefaultIcon 31 { 32 MessageBoxInformationIcon, 33 MessageBoxQuestionIcon, 34 MessageBoxWarningIcon, 35 MessageBoxCriticalIcon, 36 ArrowBackIcon, 37 ArrowForwardIcon 38 }; 100 39 101 VBoxSnapshotEvent (const QString &aMachineId, const QString &aSnapshotId, 102 What aWhat) 103 : QEvent ((QEvent::Type) VBoxDefs::SnapshotEventType) 104 , what (aWhat) 105 , machineId (aMachineId), snapshotId (aSnapshotId) 106 {} 40 static QIcon iconSet(const QPixmap &normal, 41 const QPixmap &disabled = QPixmap(), 42 const QPixmap &active = QPixmap()); 43 static QIcon iconSet(const QString &strNormal, 44 const QString &strDisabled = QString(), 45 const QString &strActive = QString()); 46 static QIcon iconSetOnOff(const QString &strNormal, const QString strNormalOff, 47 const QString &strDisabled = QString(), 48 const QString &strDisabledOff = QString(), 49 const QString &strActive = QString(), 50 const QString &strActiveOff = QString()); 51 static QIcon iconSetFull(const QSize &normalSize, const QSize &smallSize, 52 const QString &strNormal, const QString &strSmallNormal, 53 const QString &strDisabled = QString(), 54 const QString &strSmallDisabled = QString(), 55 const QString &strActive = QString(), 56 const QString &strSmallActive = QString()); 107 57 108 const What what; 109 110 const QString machineId; 111 const QString snapshotId; 112 }; 113 114 class VBoxCanShowRegDlgEvent : public QEvent 115 { 116 public: 117 VBoxCanShowRegDlgEvent (bool aCanShow) 118 : QEvent ((QEvent::Type) VBoxDefs::CanShowRegDlgEventType) 119 , mCanShow (aCanShow) 120 {} 121 122 const bool mCanShow; 123 }; 124 125 class VBoxCanShowUpdDlgEvent : public QEvent 126 { 127 public: 128 VBoxCanShowUpdDlgEvent (bool aCanShow) 129 : QEvent ((QEvent::Type) VBoxDefs::CanShowUpdDlgEventType) 130 , mCanShow (aCanShow) 131 {} 132 133 const bool mCanShow; 134 }; 135 136 class VBoxChangeGUILanguageEvent : public QEvent 137 { 138 public: 139 VBoxChangeGUILanguageEvent (QString aLangId) 140 : QEvent ((QEvent::Type) VBoxDefs::ChangeGUILanguageEventType) 141 , mLangId (aLangId) 142 {} 143 144 const QString mLangId; 145 }; 146 147 #ifdef VBOX_GUI_WITH_SYSTRAY 148 class VBoxMainWindowCountChangeEvent : public QEvent 149 { 150 public: 151 VBoxMainWindowCountChangeEvent (int aCount) 152 : QEvent ((QEvent::Type) VBoxDefs::MainWindowCountChangeEventType) 153 , mCount (aCount) 154 {} 155 156 const int mCount; 157 }; 158 159 class VBoxCanShowTrayIconEvent : public QEvent 160 { 161 public: 162 VBoxCanShowTrayIconEvent (bool aCanShow) 163 : QEvent ((QEvent::Type) VBoxDefs::CanShowTrayIconEventType) 164 , mCanShow (aCanShow) 165 {} 166 167 const bool mCanShow; 168 }; 169 170 class VBoxShowTrayIconEvent : public QEvent 171 { 172 public: 173 VBoxShowTrayIconEvent (bool aShow) 174 : QEvent ((QEvent::Type) VBoxDefs::ShowTrayIconEventType) 175 , mShow (aShow) 176 {} 177 178 const bool mShow; 179 }; 180 181 class VBoxChangeTrayIconEvent : public QEvent 182 { 183 public: 184 VBoxChangeTrayIconEvent (bool aChanged) 185 : QEvent ((QEvent::Type) VBoxDefs::TrayIconChangeEventType) 186 , mChanged (aChanged) 187 {} 188 189 const bool mChanged; 190 }; 191 #endif 192 193 class VBoxChangeDockIconUpdateEvent : public QEvent 194 { 195 public: 196 VBoxChangeDockIconUpdateEvent (bool aChanged) 197 : QEvent ((QEvent::Type) VBoxDefs::ChangeDockIconUpdateEventType) 198 , mChanged (aChanged) 199 {} 200 201 const bool mChanged; 202 }; 203 204 class VBoxChangePresentationModeEvent : public QEvent 205 { 206 public: 207 VBoxChangePresentationModeEvent (bool aChanged) 208 : QEvent ((QEvent::Type) VBoxDefs::ChangePresentationmodeEventType) 209 , mChanged (aChanged) 210 {} 211 212 const bool mChanged; 213 }; 214 215 class Process : public QProcess 216 { 217 Q_OBJECT; 218 219 public: 220 221 static QByteArray singleShot (const QString &aProcessName, 222 int aTimeout = 5000 223 /* wait for data maximum 5 seconds */) 224 { 225 /* Why is it really needed is because of Qt4.3 bug with QProcess. 226 * This bug is about QProcess sometimes (~70%) do not receive 227 * notification about process was finished, so this makes 228 * 'bool QProcess::waitForFinished (int)' block the GUI thread and 229 * never dismissed with 'true' result even if process was really 230 * started&finished. So we just waiting for some information 231 * on process output and destroy the process with force. Due to 232 * QProcess::~QProcess() has the same 'waitForFinished (int)' blocker 233 * we have to change process state to QProcess::NotRunning. */ 234 235 QByteArray result; 236 Process process; 237 process.start (aProcessName); 238 bool firstShotReady = process.waitForReadyRead (aTimeout); 239 if (firstShotReady) 240 result = process.readAllStandardOutput(); 241 process.setProcessState (QProcess::NotRunning); 242 #ifdef Q_WS_X11 243 int status; 244 if (process.pid() > 0) 245 waitpid(process.pid(), &status, 0); 246 #endif 247 return result; 248 } 249 250 protected: 251 252 Process (QWidget *aParent = 0) : QProcess (aParent) {} 253 }; 254 255 struct StorageSlot 256 { 257 StorageSlot() : bus (KStorageBus_Null), port (0), device (0) {} 258 StorageSlot (const StorageSlot &aOther) : bus (aOther.bus), port (aOther.port), device (aOther.device) {} 259 StorageSlot (KStorageBus aBus, LONG aPort, LONG aDevice) : bus (aBus), port (aPort), device (aDevice) {} 260 StorageSlot& operator= (const StorageSlot &aOther) { bus = aOther.bus; port = aOther.port; device = aOther.device; return *this; } 261 bool operator== (const StorageSlot &aOther) const { return bus == aOther.bus && port == aOther.port && device == aOther.device; } 262 bool operator!= (const StorageSlot &aOther) const { return bus != aOther.bus || port != aOther.port || device != aOther.device; } 263 bool operator< (const StorageSlot &aOther) const { return (bus < aOther.bus) || 264 (bus == aOther.bus && port < aOther.port) || 265 (bus == aOther.bus && port == aOther.port && device < aOther.device); } 266 bool operator> (const StorageSlot &aOther) const { return (bus > aOther.bus) || 267 (bus == aOther.bus && port > aOther.port) || 268 (bus == aOther.bus && port == aOther.port && device > aOther.device); } 269 bool isNull() { return bus == KStorageBus_Null; } 270 KStorageBus bus; LONG port; LONG device; 271 }; 272 Q_DECLARE_METATYPE (StorageSlot); 273 274 // VBoxGlobal class 275 //////////////////////////////////////////////////////////////////////////////// 276 277 class VBoxSelectorWnd; 278 class UIRegistrationWzd; 279 class VBoxUpdateDlg; 280 281 class VBoxGlobal : public QObject 282 { 283 Q_OBJECT 284 285 public: 286 287 typedef QHash <ulong, QString> QULongStringHash; 288 typedef QHash <long, QString> QLongStringHash; 289 290 static VBoxGlobal &instance(); 291 292 bool isValid() { return mValid; } 293 294 static QString qtRTVersionString(); 295 static uint qtRTVersion(); 296 static QString qtCTVersionString(); 297 static uint qtCTVersion(); 298 299 QString versionString() { return mVerString; } 300 301 CVirtualBox virtualBox() const { return mVBox; } 302 303 const VBoxGlobalSettings &settings() const { return gset; } 304 bool setSettings (const VBoxGlobalSettings &gs); 305 306 VBoxSelectorWnd &selectorWnd(); 307 308 QWidget *vmWindow(); 309 310 bool createVirtualMachine(const CSession &session); 311 UIMachine* virtualMachine(); 312 313 /* main window handle storage */ 314 void setMainWindow (QWidget *aMainWindow) { mMainWindow = aMainWindow; } 315 QWidget *mainWindow() const { return mMainWindow; } 316 317 /* branding */ 318 bool brandingIsActive (bool aForce = false); 319 QString brandingGetKey (QString aKey); 320 321 bool isVMConsoleProcess() const { return !vmUuid.isNull(); } 322 bool showStartVMErrors() const { return mShowStartVMErrors; } 323 #ifdef VBOX_GUI_WITH_SYSTRAY 324 bool isTrayMenu() const; 325 void setTrayMenu(bool aIsTrayMenu); 326 void trayIconShowSelector(); 327 bool trayIconInstall(); 328 #endif 329 QString managedVMUuid() const { return vmUuid; } 330 331 VBoxDefs::RenderMode vmRenderMode() const { return vm_render_mode; } 332 const char *vmRenderModeStr() const { return vm_render_mode_str; } 333 bool isKWinManaged() const { return mIsKWinManaged; } 334 335 const QRect availableGeometry(int iScreen = 0) const; 336 337 #ifdef VBOX_WITH_DEBUGGER_GUI 338 bool isDebuggerEnabled() const { return mDbgEnabled; } 339 bool isDebuggerAutoShowEnabled() const { return mDbgAutoShow; } 340 bool isDebuggerAutoShowCommandLineEnabled() const { return mDbgAutoShowCommandLine; } 341 bool isDebuggerAutoShowStatisticsEnabled() const { return mDbgAutoShowStatistics; } 342 RTLDRMOD getDebuggerModule() const { return mhVBoxDbg; } 343 344 bool isStartPausedEnabled() const { return mStartPaused; } 345 #else 346 bool isDebuggerAutoShowEnabled() const { return false; } 347 bool isDebuggerAutoShowCommandLineEnabled() const { return false; } 348 bool isDebuggerAutoShowStatisticsEnabled() const { return false; } 349 350 bool isStartPausedEnabled() const { return false; } 351 #endif 352 353 /* VBox enum to/from string/icon/color convertors */ 354 355 QList <CGuestOSType> vmGuestOSFamilyList() const; 356 QList <CGuestOSType> vmGuestOSTypeList (const QString &aFamilyId) const; 357 QPixmap vmGuestOSTypeIcon (const QString &aTypeId) const; 358 CGuestOSType vmGuestOSType (const QString &aTypeId, 359 const QString &aFamilyId = QString::null) const; 360 QString vmGuestOSTypeDescription (const QString &aTypeId) const; 361 362 QPixmap toIcon (KMachineState s) const 363 { 364 QPixmap *pm = mVMStateIcons.value (s); 365 AssertMsg (pm, ("Icon for VM state %d must be defined", s)); 366 return pm ? *pm : QPixmap(); 367 } 368 369 static inline QString yearsToString (uint32_t cVal) 370 { 371 return tr("%n year(s)", "", cVal); 372 } 373 374 static inline QString monthsToString (uint32_t cVal) 375 { 376 return tr("%n month(s)", "", cVal); 377 } 378 379 static inline QString daysToString (uint32_t cVal) 380 { 381 return tr("%n day(s)", "", cVal); 382 } 383 384 static inline QString hoursToString (uint32_t cVal) 385 { 386 return tr("%n hour(s)", "", cVal); 387 } 388 389 static inline QString minutesToString (uint32_t cVal) 390 { 391 return tr("%n minute(s)", "", cVal); 392 } 393 394 static inline QString secondsToString (uint32_t cVal) 395 { 396 return tr("%n second(s)", "", cVal); 397 } 398 399 const QColor &toColor (KMachineState s) const 400 { 401 static const QColor none; 402 AssertMsg (mVMStateColors.value (s), ("No color for %d", s)); 403 return mVMStateColors.value (s) ? *mVMStateColors.value (s) : none; 404 } 405 406 QString toString (KMachineState s) const 407 { 408 AssertMsg (!mMachineStates.value (s).isNull(), ("No text for %d", s)); 409 return mMachineStates.value (s); 410 } 411 412 QString toString (KSessionState s) const 413 { 414 AssertMsg (!mSessionStates.value (s).isNull(), ("No text for %d", s)); 415 return mSessionStates.value (s); 416 } 417 418 /** 419 * Returns a string representation of the given KStorageBus enum value. 420 * Complementary to #toStorageBusType (const QString &) const. 421 */ 422 QString toString (KStorageBus aBus) const 423 { 424 AssertMsg (!mStorageBuses.value (aBus).isNull(), ("No text for %d", aBus)); 425 return mStorageBuses [aBus]; 426 } 427 428 /** 429 * Returns a KStorageBus enum value corresponding to the given string 430 * representation. Complementary to #toString (KStorageBus) const. 431 */ 432 KStorageBus toStorageBusType (const QString &aBus) const 433 { 434 QULongStringHash::const_iterator it = 435 qFind (mStorageBuses.begin(), mStorageBuses.end(), aBus); 436 AssertMsg (it != mStorageBuses.end(), ("No value for {%s}", 437 aBus.toLatin1().constData())); 438 return KStorageBus (it.key()); 439 } 440 441 KStorageBus toStorageBusType (KStorageControllerType aControllerType) const 442 { 443 KStorageBus sb = KStorageBus_Null; 444 switch (aControllerType) 445 { 446 case KStorageControllerType_Null: sb = KStorageBus_Null; break; 447 case KStorageControllerType_PIIX3: 448 case KStorageControllerType_PIIX4: 449 case KStorageControllerType_ICH6: sb = KStorageBus_IDE; break; 450 case KStorageControllerType_IntelAhci: sb = KStorageBus_SATA; break; 451 case KStorageControllerType_LsiLogic: 452 case KStorageControllerType_BusLogic: sb = KStorageBus_SCSI; break; 453 case KStorageControllerType_I82078: sb = KStorageBus_Floppy; break; 454 default: 455 AssertMsgFailed (("toStorageBusType: %d not handled\n", aControllerType)); break; 456 } 457 return sb; 458 } 459 460 QString toString (KStorageBus aBus, LONG aChannel) const; 461 LONG toStorageChannel (KStorageBus aBus, const QString &aChannel) const; 462 463 QString toString (KStorageBus aBus, LONG aChannel, LONG aDevice) const; 464 LONG toStorageDevice (KStorageBus aBus, LONG aChannel, const QString &aDevice) const; 465 466 QString toString (StorageSlot aSlot) const; 467 StorageSlot toStorageSlot (const QString &aSlot) const; 468 469 QString toString (KMediumType t) const 470 { 471 AssertMsg (!mDiskTypes.value (t).isNull(), ("No text for %d", t)); 472 return mDiskTypes.value (t); 473 } 474 475 /** 476 * Similar to toString (KMediumType), but returns 'Differencing' for 477 * normal hard disks that have a parent. 478 */ 479 QString mediumTypeString (const CMedium &aHD) const 480 { 481 if (!aHD.GetParent().isNull()) 482 { 483 Assert (aHD.GetType() == KMediumType_Normal); 484 return mDiskTypes_Differencing; 485 } 486 return toString (aHD.GetType()); 487 } 488 489 QString toString (KVRDPAuthType t) const 490 { 491 AssertMsg (!mVRDPAuthTypes.value (t).isNull(), ("No text for %d", t)); 492 return mVRDPAuthTypes.value (t); 493 } 494 495 QString toString (KPortMode t) const 496 { 497 AssertMsg (!mPortModeTypes.value (t).isNull(), ("No text for %d", t)); 498 return mPortModeTypes.value (t); 499 } 500 501 QString toString (KUSBDeviceFilterAction t) const 502 { 503 AssertMsg (!mUSBFilterActionTypes.value (t).isNull(), ("No text for %d", t)); 504 return mUSBFilterActionTypes.value (t); 505 } 506 507 QString toString (KClipboardMode t) const 508 { 509 AssertMsg (!mClipboardTypes.value (t).isNull(), ("No text for %d", t)); 510 return mClipboardTypes.value (t); 511 } 512 513 KClipboardMode toClipboardModeType (const QString &s) const 514 { 515 QULongStringHash::const_iterator it = 516 qFind (mClipboardTypes.begin(), mClipboardTypes.end(), s); 517 AssertMsg (it != mClipboardTypes.end(), ("No value for {%s}", 518 s.toLatin1().constData())); 519 return KClipboardMode (it.key()); 520 } 521 522 QString toString (KStorageControllerType t) const 523 { 524 AssertMsg (!mStorageControllerTypes.value (t).isNull(), ("No text for %d", t)); 525 return mStorageControllerTypes.value (t); 526 } 527 528 KStorageControllerType toControllerType (const QString &s) const 529 { 530 QULongStringHash::const_iterator it = 531 qFind (mStorageControllerTypes.begin(), mStorageControllerTypes.end(), s); 532 AssertMsg (it != mStorageControllerTypes.end(), ("No value for {%s}", 533 s.toLatin1().constData())); 534 return KStorageControllerType (it.key()); 535 } 536 537 KVRDPAuthType toVRDPAuthType (const QString &s) const 538 { 539 QULongStringHash::const_iterator it = 540 qFind (mVRDPAuthTypes.begin(), mVRDPAuthTypes.end(), s); 541 AssertMsg (it != mVRDPAuthTypes.end(), ("No value for {%s}", 542 s.toLatin1().constData())); 543 return KVRDPAuthType (it.key()); 544 } 545 546 KPortMode toPortMode (const QString &s) const 547 { 548 QULongStringHash::const_iterator it = 549 qFind (mPortModeTypes.begin(), mPortModeTypes.end(), s); 550 AssertMsg (it != mPortModeTypes.end(), ("No value for {%s}", 551 s.toLatin1().constData())); 552 return KPortMode (it.key()); 553 } 554 555 KUSBDeviceFilterAction toUSBDevFilterAction (const QString &s) const 556 { 557 QULongStringHash::const_iterator it = 558 qFind (mUSBFilterActionTypes.begin(), mUSBFilterActionTypes.end(), s); 559 AssertMsg (it != mUSBFilterActionTypes.end(), ("No value for {%s}", 560 s.toLatin1().constData())); 561 return KUSBDeviceFilterAction (it.key()); 562 } 563 564 QString toString (KDeviceType t) const 565 { 566 AssertMsg (!mDeviceTypes.value (t).isNull(), ("No text for %d", t)); 567 return mDeviceTypes.value (t); 568 } 569 570 KDeviceType toDeviceType (const QString &s) const 571 { 572 QULongStringHash::const_iterator it = 573 qFind (mDeviceTypes.begin(), mDeviceTypes.end(), s); 574 AssertMsg (it != mDeviceTypes.end(), ("No value for {%s}", 575 s.toLatin1().constData())); 576 return KDeviceType (it.key()); 577 } 578 579 QStringList deviceTypeStrings() const; 580 581 QString toString (KAudioDriverType t) const 582 { 583 AssertMsg (!mAudioDriverTypes.value (t).isNull(), ("No text for %d", t)); 584 return mAudioDriverTypes.value (t); 585 } 586 587 KAudioDriverType toAudioDriverType (const QString &s) const 588 { 589 QULongStringHash::const_iterator it = 590 qFind (mAudioDriverTypes.begin(), mAudioDriverTypes.end(), s); 591 AssertMsg (it != mAudioDriverTypes.end(), ("No value for {%s}", 592 s.toLatin1().constData())); 593 return KAudioDriverType (it.key()); 594 } 595 596 QString toString (KAudioControllerType t) const 597 { 598 AssertMsg (!mAudioControllerTypes.value (t).isNull(), ("No text for %d", t)); 599 return mAudioControllerTypes.value (t); 600 } 601 602 KAudioControllerType toAudioControllerType (const QString &s) const 603 { 604 QULongStringHash::const_iterator it = 605 qFind (mAudioControllerTypes.begin(), mAudioControllerTypes.end(), s); 606 AssertMsg (it != mAudioControllerTypes.end(), ("No value for {%s}", 607 s.toLatin1().constData())); 608 return KAudioControllerType (it.key()); 609 } 610 611 QString toString (KNetworkAdapterType t) const 612 { 613 AssertMsg (!mNetworkAdapterTypes.value (t).isNull(), ("No text for %d", t)); 614 return mNetworkAdapterTypes.value (t); 615 } 616 617 KNetworkAdapterType toNetworkAdapterType (const QString &s) const 618 { 619 QULongStringHash::const_iterator it = 620 qFind (mNetworkAdapterTypes.begin(), mNetworkAdapterTypes.end(), s); 621 AssertMsg (it != mNetworkAdapterTypes.end(), ("No value for {%s}", 622 s.toLatin1().constData())); 623 return KNetworkAdapterType (it.key()); 624 } 625 626 QString toString (KNetworkAttachmentType t) const 627 { 628 AssertMsg (!mNetworkAttachmentTypes.value (t).isNull(), ("No text for %d", t)); 629 return mNetworkAttachmentTypes.value (t); 630 } 631 632 KNetworkAttachmentType toNetworkAttachmentType (const QString &s) const 633 { 634 QULongStringHash::const_iterator it = 635 qFind (mNetworkAttachmentTypes.begin(), mNetworkAttachmentTypes.end(), s); 636 AssertMsg (it != mNetworkAttachmentTypes.end(), ("No value for {%s}", 637 s.toLatin1().constData())); 638 return KNetworkAttachmentType (it.key()); 639 } 640 641 QString toString (KUSBDeviceState aState) const 642 { 643 AssertMsg (!mUSBDeviceStates.value (aState).isNull(), ("No text for %d", aState)); 644 return mUSBDeviceStates.value (aState); 645 } 646 647 QStringList COMPortNames() const; 648 QString toCOMPortName (ulong aIRQ, ulong aIOBase) const; 649 bool toCOMPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const; 650 651 QStringList LPTPortNames() const; 652 QString toLPTPortName (ulong aIRQ, ulong aIOBase) const; 653 bool toLPTPortNumbers (const QString &aName, ulong &aIRQ, ulong &aIOBase) const; 654 655 QPixmap snapshotIcon (bool online) const 656 { 657 return online ? mOnlineSnapshotIcon : mOfflineSnapshotIcon; 658 } 659 660 QPixmap warningIcon() const { return mWarningIcon; } 661 QPixmap errorIcon() const { return mErrorIcon; } 662 663 /* details generators */ 664 665 QString details (const CMedium &aHD, bool aPredictDiff); 666 667 QString details (const CUSBDevice &aDevice) const; 668 QString toolTip (const CUSBDevice &aDevice) const; 669 QString toolTip (const CUSBDeviceFilter &aFilter) const; 670 671 QString detailsReport (const CMachine &aMachine, bool aWithLinks); 672 673 QString platformInfo(); 674 675 /* VirtualBox helpers */ 676 677 #if defined(Q_WS_X11) && !defined(VBOX_OSE) 678 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const; 679 bool showVirtualBoxLicense(); 680 #endif 681 682 CSession openSession (const QString &aId, bool aExisting = false); 683 684 /** Shortcut to openSession (aId, true). */ 685 CSession openExistingSession (const QString &aId) { return openSession (aId, true); } 686 687 bool startMachine(const QString &strId); 688 689 void startEnumeratingMedia(); 690 691 /** 692 * Returns a list of all currently registered media. This list is used to 693 * globally track the accessiblity state of all media on a dedicated thread. 694 * 695 * Note that the media list is initially empty (i.e. before the enumeration 696 * process is started for the first time using #startEnumeratingMedia()). 697 * See #startEnumeratingMedia() for more information about how meida are 698 * sorted in the returned list. 699 */ 700 const VBoxMediaList ¤tMediaList() const { return mMediaList; } 701 702 /** Returns true if the media enumeration is in progress. */ 703 bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; } 704 705 void addMedium (const VBoxMedium &); 706 void updateMedium (const VBoxMedium &); 707 void removeMedium (VBoxDefs::MediumType, const QString &); 708 709 bool findMedium (const CMedium &, VBoxMedium &) const; 710 VBoxMedium findMedium (const QString &aMediumId) const; 711 712 /** Compact version of #findMediumTo(). Asserts if not found. */ 713 VBoxMedium getMedium (const CMedium &aObj) const 714 { 715 VBoxMedium medium; 716 if (!findMedium (aObj, medium)) 717 AssertFailed(); 718 return medium; 719 } 720 721 /* Returns the number of current running Fe/Qt4 main windows. */ 722 int mainWindowCount(); 723 724 /* various helpers */ 725 726 QString languageName() const; 727 QString languageCountry() const; 728 QString languageNameEnglish() const; 729 QString languageCountryEnglish() const; 730 QString languageTranslators() const; 731 732 void retranslateUi(); 733 734 /** @internal made public for internal purposes */ 735 void cleanup(); 736 737 /* public static stuff */ 738 739 static bool isDOSType (const QString &aOSTypeId); 740 741 static QString languageId(); 742 static void loadLanguage (const QString &aLangId = QString::null); 743 QString helpFile() const; 744 745 static QIcon iconSet (const QPixmap &aNormal, 746 const QPixmap &aDisabled = QPixmap(), 747 const QPixmap &aActive = QPixmap()); 748 static QIcon iconSet (const char *aNormal, 749 const char *aDisabled = NULL, 750 const char *aActive = NULL); 751 static QIcon iconSetOnOff (const char *aNormal, const char *aNormalOff, 752 const char *aDisabled = NULL, 753 const char *aDisabledOff = NULL, 754 const char *aActive = NULL, 755 const char *aActiveOff = NULL); 756 static QIcon iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize, 757 const char *aNormal, const char *aSmallNormal, 758 const char *aDisabled = NULL, 759 const char *aSmallDisabled = NULL, 760 const char *aActive = NULL, 761 const char *aSmallActive = NULL); 762 763 static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL); 764 765 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel); 766 767 static QRect normalizeGeometry (const QRect &aRectangle, const QRegion &aBoundRegion, 768 bool aCanResize = true); 769 static QRect getNormalized (const QRect &aRectangle, const QRegion &aBoundRegion, 770 bool aCanResize = true); 771 static QRegion flip (const QRegion &aRegion); 772 773 static void centerWidget (QWidget *aWidget, QWidget *aRelative, 774 bool aCanResize = true); 775 776 static QChar decimalSep(); 777 static QString sizeRegexp(); 778 779 static quint64 parseSize (const QString &); 780 static QString formatSize (quint64 aSize, uint aDecimal = 2, 781 VBoxDefs::FormatSize aMode = VBoxDefs::FormatSize_Round); 782 783 static quint64 requiredVideoMemory (CMachine *aMachine = 0, int cMonitors = 1); 784 785 static QString locationForHTML (const QString &aFileName); 786 787 static QString highlight (const QString &aStr, bool aToolTip = false); 788 789 static QString replaceHtmlEntities(QString strText); 790 static QString emphasize (const QString &aStr); 791 792 static QString systemLanguageId(); 793 794 static bool activateWindow (WId aWId, bool aSwitchDesktop = true); 795 796 static QString removeAccelMark (const QString &aText); 797 798 static QString insertKeyToActionText (const QString &aText, const QString &aKey); 799 static QString extractKeyFromActionText (const QString &aText); 800 801 static QPixmap joinPixmaps (const QPixmap &aPM1, const QPixmap &aPM2); 802 803 static QWidget *findWidget (QWidget *aParent, const char *aName, 804 const char *aClassName = NULL, 805 bool aRecursive = false); 806 807 static QList <QPair <QString, QString> > HDDBackends(); 808 809 /* Qt 4.2.0 support function */ 810 static inline void setLayoutMargin (QLayout *aLayout, int aMargin) 811 { 812 #if QT_VERSION < 0x040300 813 /* Deprecated since > 4.2 */ 814 aLayout->setMargin (aMargin); 815 #else 816 /* New since > 4.2 */ 817 aLayout->setContentsMargins (aMargin, aMargin, aMargin, aMargin); 818 #endif 819 } 820 821 static QString documentsPath(); 822 823 #ifdef VBOX_WITH_VIDEOHWACCEL 824 static bool isAcceleration2DVideoAvailable(); 825 826 /** additional video memory required for the best 2D support performance 827 * total amount of VRAM required is thus calculated as requiredVideoMemory + required2DOffscreenVideoMemory */ 828 static quint64 required2DOffscreenVideoMemory(); 829 #endif 830 831 signals: 832 833 /** 834 * Emitted at the beginning of the enumeration process started by 835 * #startEnumeratingMedia(). 836 */ 837 void mediumEnumStarted(); 838 839 /** 840 * Emitted when a new medium item from the list has updated its 841 * accessibility state. 842 */ 843 void mediumEnumerated (const VBoxMedium &aMedum); 844 845 /** 846 * Emitted at the end of the enumeration process started by 847 * #startEnumeratingMedia(). The @a aList argument is passed for 848 * convenience, it is exactly the same as returned by #currentMediaList(). 849 */ 850 void mediumEnumFinished (const VBoxMediaList &aList); 851 852 /** Emitted when a new media is added using #addMedia(). */ 853 void mediumAdded (const VBoxMedium &); 854 855 /** Emitted when the media is updated using #updateMedia(). */ 856 void mediumUpdated (const VBoxMedium &); 857 858 /** Emitted when the media is removed using #removeMedia(). */ 859 void mediumRemoved (VBoxDefs::MediumType, const QString &); 860 861 /* signals emitted when the VirtualBox callback is called by the server 862 * (note that currently these signals are emitted only when the application 863 * is the in the VM selector mode) */ 864 865 void machineStateChanged (const VBoxMachineStateChangeEvent &e); 866 void machineDataChanged (const VBoxMachineDataChangeEvent &e); 867 void machineRegistered (const VBoxMachineRegisteredEvent &e); 868 void sessionStateChanged (const VBoxSessionStateChangeEvent &e); 869 void snapshotChanged (const VBoxSnapshotEvent &e); 870 #ifdef VBOX_GUI_WITH_SYSTRAY 871 void mainWindowCountChanged (const VBoxMainWindowCountChangeEvent &e); 872 void trayIconCanShow (const VBoxCanShowTrayIconEvent &e); 873 void trayIconShow (const VBoxShowTrayIconEvent &e); 874 void trayIconChanged (const VBoxChangeTrayIconEvent &e); 875 #endif 876 void dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &e); 877 void presentationModeChanged (const VBoxChangePresentationModeEvent &e); 878 879 void canShowRegDlg (bool aCanShow); 880 void canShowUpdDlg (bool aCanShow); 881 882 public slots: 883 884 bool openURL (const QString &aURL); 885 886 void showRegistrationDialog (bool aForce = true); 887 void showUpdateDialog (bool aForce = true); 888 void perDayNewVersionNotifier(); 889 890 protected: 891 892 bool event (QEvent *e); 893 bool eventFilter (QObject *, QEvent *); 58 static QIcon defaultIcon(UIDefaultIcon def, const QWidget *pWidget = 0); 894 59 895 60 private: 896 61 897 VBoxGlobal(); 898 ~VBoxGlobal(); 899 900 void init(); 901 902 bool mValid; 903 904 CVirtualBox mVBox; 905 906 VBoxGlobalSettings gset; 907 908 VBoxSelectorWnd *mSelectorWnd; 909 UIMachine *m_pVirtualMachine; 910 QWidget* mMainWindow; 911 912 #ifdef VBOX_WITH_REGISTRATION 913 UIRegistrationWzd *mRegDlg; 914 #endif 915 VBoxUpdateDlg *mUpdDlg; 916 917 QString vmUuid; 918 919 #ifdef VBOX_GUI_WITH_SYSTRAY 920 bool mIsTrayMenu : 1; /*< Tray icon active/desired? */ 921 bool mIncreasedWindowCounter : 1; 922 #endif 923 924 /** Whether to show error message boxes for VM start errors. */ 925 bool mShowStartVMErrors; 926 927 QThread *mMediaEnumThread; 928 VBoxMediaList mMediaList; 929 930 VBoxDefs::RenderMode vm_render_mode; 931 const char * vm_render_mode_str; 932 bool mIsKWinManaged; 933 934 #ifdef VBOX_WITH_DEBUGGER_GUI 935 /** Whether the debugger should be accessible or not. 936 * Use --dbg, the env.var. VBOX_GUI_DBG_ENABLED, --debug or the env.var. 937 * VBOX_GUI_DBG_AUTO_SHOW to enable. */ 938 bool mDbgEnabled; 939 /** Whether to show the debugger automatically with the console. 940 * Use --debug or the env.var. VBOX_GUI_DBG_AUTO_SHOW to enable. */ 941 bool mDbgAutoShow; 942 /** Whether to show the command line window when mDbgAutoShow is set. */ 943 bool mDbgAutoShowCommandLine; 944 /** Whether to show the statistics window when mDbgAutoShow is set. */ 945 bool mDbgAutoShowStatistics; 946 /** VBoxDbg module handle. */ 947 RTLDRMOD mhVBoxDbg; 948 949 /** Whether to start the VM in paused state or not. */ 950 bool mStartPaused; 951 #endif 952 953 #if defined (Q_WS_WIN32) 954 DWORD dwHTMLHelpCookie; 955 #endif 956 957 CVirtualBoxCallback callback; 958 959 QString mVerString; 960 QString mBrandingConfig; 961 962 QList <QString> mFamilyIDs; 963 QList <QList <CGuestOSType> > mTypes; 964 QHash <QString, QPixmap *> mOsTypeIcons; 965 966 QHash <ulong, QPixmap *> mVMStateIcons; 967 QHash <ulong, QColor *> mVMStateColors; 968 969 QPixmap mOfflineSnapshotIcon, mOnlineSnapshotIcon; 970 971 QULongStringHash mMachineStates; 972 QULongStringHash mSessionStates; 973 QULongStringHash mDeviceTypes; 974 975 QULongStringHash mStorageBuses; 976 QLongStringHash mStorageBusChannels; 977 QLongStringHash mStorageBusDevices; 978 QULongStringHash mSlotTemplates; 979 980 QULongStringHash mDiskTypes; 981 QString mDiskTypes_Differencing; 982 983 QULongStringHash mVRDPAuthTypes; 984 QULongStringHash mPortModeTypes; 985 QULongStringHash mUSBFilterActionTypes; 986 QULongStringHash mAudioDriverTypes; 987 QULongStringHash mAudioControllerTypes; 988 QULongStringHash mNetworkAdapterTypes; 989 QULongStringHash mNetworkAttachmentTypes; 990 QULongStringHash mClipboardTypes; 991 QULongStringHash mStorageControllerTypes; 992 QULongStringHash mUSBDeviceStates; 993 994 QString mUserDefinedPortName; 995 996 QPixmap mWarningIcon, mErrorIcon; 997 998 friend VBoxGlobal &vboxGlobal(); 999 friend class VBoxCallback; 62 UIIconPool() {}; 63 UIIconPool(const UIIconPool& /* pool */) {}; 64 ~UIIconPool() {}; 1000 65 }; 1001 66 1002 inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); } 67 #endif /* !__UIIconPool_h__ */ 1003 68 1004 // Helper classes1005 ////////////////////////////////////////////////////////////////////////////////1006 1007 /**1008 * Generic asyncronous event.1009 *1010 * This abstract class is intended to provide a conveinent way to execute1011 * code on the main GUI thread asynchronously to the calling party. This is1012 * done by putting necessary actions to the #handle() function in a subclass1013 * and then posting an instance of the subclass using #post(). The instance1014 * must be allocated on the heap using the <tt>new</tt> operation and will be1015 * automatically deleted after processing. Note that if you don't call #post()1016 * on the created instance, you have to delete it yourself.1017 */1018 class VBoxAsyncEvent : public QEvent1019 {1020 public:1021 1022 VBoxAsyncEvent() : QEvent ((QEvent::Type) VBoxDefs::AsyncEventType) {}1023 1024 /**1025 * Worker function. Gets executed on the GUI thread when the posted event1026 * is processed by the main event loop.1027 */1028 virtual void handle() = 0;1029 1030 /**1031 * Posts this event to the main event loop.1032 * The caller loses ownership of this object after this method returns1033 * and must not delete the object.1034 */1035 void post()1036 {1037 QApplication::postEvent (&vboxGlobal(), this);1038 }1039 };1040 1041 /**1042 * USB Popup Menu class.1043 * This class provides the list of USB devices attached to the host.1044 */1045 class VBoxUSBMenu : public QMenu1046 {1047 Q_OBJECT1048 1049 public:1050 1051 VBoxUSBMenu (QWidget *);1052 1053 const CUSBDevice& getUSB (QAction *aAction);1054 1055 void setConsole (const CConsole &);1056 1057 private slots:1058 1059 void processAboutToShow();1060 1061 private:1062 bool event(QEvent *aEvent);1063 1064 QMap <QAction *, CUSBDevice> mUSBDevicesMap;1065 CConsole mConsole;1066 };1067 1068 /**1069 * Enable/Disable Menu class.1070 * This class provides enable/disable menu items.1071 */1072 class VBoxSwitchMenu : public QMenu1073 {1074 Q_OBJECT1075 1076 public:1077 1078 VBoxSwitchMenu (QWidget *, QAction *, bool aInverted = false);1079 1080 void setToolTip (const QString &);1081 1082 private slots:1083 1084 void processAboutToShow();1085 1086 private:1087 1088 QAction *mAction;1089 bool mInverted;1090 };1091 1092 #endif /* __VBoxGlobal_h__ */1093 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r30025 r30192 28 28 #include "QIMessageBox.h" 29 29 #include "QIDialogButtonBox.h" 30 #include "UIIconPool.h" 30 31 31 32 #include "UIMachine.h" … … 3157 3158 mUserDefinedPortName = tr ("User-defined", "serial port"); 3158 3159 3159 mWarningIcon = standardIcon (QStyle::SP_MessageBoxWarning, 0).pixmap (16, 16);3160 mWarningIcon = UIIconPool::defaultIcon(UIIconPool::MessageBoxWarningIcon).pixmap (16, 16); 3160 3161 Assert (!mWarningIcon.isNull()); 3161 3162 3162 mErrorIcon = standardIcon (QStyle::SP_MessageBoxCritical, 0).pixmap (16, 16);3163 mErrorIcon = UIIconPool::defaultIcon(UIIconPool::MessageBoxCriticalIcon).pixmap (16, 16); 3163 3164 Assert (!mErrorIcon.isNull()); 3164 3165 … … 3421 3422 .arg (suffix); 3422 3423 return manual; 3423 }3424 3425 QIcon VBoxGlobal::iconSet (const QPixmap &aNormal,3426 const QPixmap &aDisabled,3427 const QPixmap &aActive)3428 {3429 QIcon iconSet;3430 3431 Assert (aNormal);3432 iconSet.addPixmap (aNormal, QIcon::Normal);3433 3434 if (!aDisabled.isNull())3435 iconSet.addPixmap (aDisabled, QIcon::Disabled);3436 3437 if (!aActive.isNull())3438 iconSet.addPixmap (aActive, QIcon::Active);3439 3440 return iconSet;3441 }3442 3443 /* static */3444 QIcon VBoxGlobal::iconSet (const char *aNormal,3445 const char *aDisabled /* = NULL */,3446 const char *aActive /* = NULL */)3447 {3448 QIcon iconSet;3449 3450 Assert (aNormal != NULL);3451 iconSet.addFile (aNormal, QSize(),3452 QIcon::Normal);3453 if (aDisabled != NULL)3454 iconSet.addFile (aDisabled, QSize(),3455 QIcon::Disabled);3456 if (aActive != NULL)3457 iconSet.addFile (aActive, QSize(),3458 QIcon::Active);3459 return iconSet;3460 }3461 3462 /* static */3463 QIcon VBoxGlobal::iconSetOnOff (const char *aNormal, const char *aNormalOff,3464 const char *aDisabled /* = NULL */,3465 const char *aDisabledOff /* = NULL */,3466 const char *aActive /* = NULL */,3467 const char *aActiveOff /* = NULL */)3468 {3469 QIcon iconSet;3470 3471 Assert (aNormal != NULL);3472 iconSet.addFile (aNormal, QSize(), QIcon::Normal, QIcon::On);3473 if (aNormalOff != NULL)3474 iconSet.addFile (aNormalOff, QSize(), QIcon::Normal, QIcon::Off);3475 3476 if (aDisabled != NULL)3477 iconSet.addFile (aDisabled, QSize(), QIcon::Disabled, QIcon::On);3478 if (aDisabledOff != NULL)3479 iconSet.addFile (aDisabledOff, QSize(), QIcon::Disabled, QIcon::Off);3480 3481 if (aActive != NULL)3482 iconSet.addFile (aActive, QSize(), QIcon::Active, QIcon::On);3483 if (aActiveOff != NULL)3484 iconSet.addFile (aActive, QSize(), QIcon::Active, QIcon::Off);3485 3486 return iconSet;3487 }3488 3489 /* static */3490 QIcon VBoxGlobal::iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize,3491 const char *aNormal, const char *aSmallNormal,3492 const char *aDisabled /* = NULL */,3493 const char *aSmallDisabled /* = NULL */,3494 const char *aActive /* = NULL */,3495 const char *aSmallActive /* = NULL */)3496 {3497 QIcon iconSet;3498 3499 Assert (aNormal != NULL);3500 Assert (aSmallNormal != NULL);3501 iconSet.addFile (aNormal, aNormalSize, QIcon::Normal);3502 iconSet.addFile (aSmallNormal, aSmallSize, QIcon::Normal);3503 3504 if (aSmallDisabled != NULL)3505 {3506 iconSet.addFile (aDisabled, aNormalSize, QIcon::Disabled);3507 iconSet.addFile (aSmallDisabled, aSmallSize, QIcon::Disabled);3508 }3509 3510 if (aSmallActive != NULL)3511 {3512 iconSet.addFile (aActive, aNormalSize, QIcon::Active);3513 iconSet.addFile (aSmallActive, aSmallSize, QIcon::Active);3514 }3515 3516 return iconSet;3517 }3518 3519 QIcon VBoxGlobal::standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget /* = NULL */)3520 {3521 QStyle *style = aWidget ? aWidget->style(): QApplication::style();3522 if (!style)3523 return QIcon();3524 #ifdef Q_WS_MAC3525 /* At least in Qt 4.3.4/4.4 RC1 SP_MessageBoxWarning is the application3526 * icon. So change this to the critical icon. (Maybe this would be3527 * fixed in a later Qt version) */3528 if (aStandard == QStyle::SP_MessageBoxWarning)3529 return style->standardIcon (QStyle::SP_MessageBoxCritical, 0, aWidget);3530 #endif /* Q_WS_MAC */3531 return style->standardIcon (aStandard, 0, aWidget);3532 3424 } 3533 3425 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r29794 r30192 743 743 QString helpFile() const; 744 744 745 static QIcon iconSet (const QPixmap &aNormal,746 const QPixmap &aDisabled = QPixmap(),747 const QPixmap &aActive = QPixmap());748 static QIcon iconSet (const char *aNormal,749 const char *aDisabled = NULL,750 const char *aActive = NULL);751 static QIcon iconSetOnOff (const char *aNormal, const char *aNormalOff,752 const char *aDisabled = NULL,753 const char *aDisabledOff = NULL,754 const char *aActive = NULL,755 const char *aActiveOff = NULL);756 static QIcon iconSetFull (const QSize &aNormalSize, const QSize &aSmallSize,757 const char *aNormal, const char *aSmallNormal,758 const char *aDisabled = NULL,759 const char *aSmallDisabled = NULL,760 const char *aActive = NULL,761 const char *aSmallActive = NULL);762 763 static QIcon standardIcon (QStyle::StandardPixmap aStandard, QWidget *aWidget = NULL);764 765 745 static void setTextLabel (QToolButton *aToolButton, const QString &aTextLabel); 766 746 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionsPool.cpp
r29964 r30192 18 18 */ 19 19 20 /* Local includes */ 21 #include "UIActionsPool.h" 22 #include "UIIconPool.h" 23 #include "VBoxGlobal.h" 24 20 25 /* Global includes */ 21 #include <QtGlobal>22 26 #include <QHelpEvent> 23 27 #include <QToolTip> 24 25 /* Local includes */ 26 #include "UIActionsPool.h" 27 #include "VBoxGlobal.h" 28 #include <QtGlobal> 28 29 29 30 /* Extended QMenu class used in UIActions */ … … 109 110 { 110 111 if (!strIcon.isNull()) 111 setIcon(VBoxGlobal::iconSet(strIcon.toLatin1().data(), strIconDis.toLatin1().data())); 112 setIcon(UIIconPool::iconSet(strIcon.toLatin1().data(), 113 strIconDis.toLatin1().data())); 112 114 } 113 115 }; … … 124 126 { 125 127 if (!strIcon.isNull()) 126 setIcon(VBoxGlobal::iconSet(strIcon.toLatin1().data(), strIconDis.toLatin1().data())); 128 setIcon(UIIconPool::iconSet(strIcon.toLatin1().data(), 129 strIconDis.toLatin1().data())); 127 130 init(); 128 131 } … … 133 136 : UIAction(pParent, UIActionType_Toggle) 134 137 { 135 setIcon( VBoxGlobal::iconSetOnOff(strIconOn.toLatin1().data(), strIconOff.toLatin1().data(),138 setIcon(UIIconPool::iconSetOnOff(strIconOn.toLatin1().data(), strIconOff.toLatin1().data(), 136 139 strIconOnDis.toLatin1().data(), strIconOffDis.toLatin1().data())); 137 140 init(); … … 165 168 { 166 169 if (!strIcon.isNull()) 167 setIcon(VBoxGlobal::iconSet(strIcon, strIconDis)); 170 setIcon(UIIconPool::iconSet(strIcon, 171 strIconDis)); 168 172 setMenu(new QIMenu); 169 173 } -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
r30001 r30192 18 18 */ 19 19 20 /* Local includes */ 21 #include "COMDefs.h" 22 #include "QIFileDialog.h" 23 #include "UIActionsPool.h" 24 #include "UIDownloaderAdditions.h" 25 #include "UIIconPool.h" 26 #include "UIMachineLogic.h" 27 #include "UIMachineLogicFullscreen.h" 28 #include "UIMachineLogicNormal.h" 29 #include "UIMachineLogicSeamless.h" 30 #include "UIMachineView.h" 31 #include "UIMachineWindow.h" 32 #include "UISession.h" 33 #include "VBoxMediaManagerDlg.h" 34 #include "VBoxProblemReporter.h" 35 #include "VBoxTakeSnapshotDlg.h" 36 #include "VBoxVMInformationDlg.h" 37 #include "VBoxVMSettingsNetwork.h" 38 #include "VBoxVMSettingsSF.h" 39 #ifdef Q_WS_MAC 40 # include "DockIconPreview.h" 41 #endif /* Q_WS_MAC */ 42 20 43 /* Global includes */ 44 #include <iprt/path.h> 45 #include <VBox/VMMDev.h> 46 47 #ifdef VBOX_WITH_DEBUGGER_GUI 48 # include <iprt/ldr.h> 49 #endif /* VBOX_WITH_DEBUGGER_GUI */ 50 51 #ifdef Q_WS_X11 52 # include <XKeyboard.h> 53 # include <QX11Info> 54 #endif /* Q_WS_X11 */ 55 21 56 #include <QDir> 22 57 #include <QFileInfo> 23 58 #include <QDesktopWidget> 24 59 #include <QTimer> 25 26 /* Local includes */27 #include "COMDefs.h"28 #include "VBoxProblemReporter.h"29 30 #include "VBoxMediaManagerDlg.h"31 #include "VBoxTakeSnapshotDlg.h"32 #include "VBoxVMInformationDlg.h"33 #include "VBoxVMSettingsNetwork.h"34 #include "VBoxVMSettingsSF.h"35 #include "UIDownloaderAdditions.h"36 #ifdef Q_WS_MAC37 # include "DockIconPreview.h"38 #endif /* Q_WS_MAC */39 40 #include "QIFileDialog.h"41 42 #include "UISession.h"43 #include "UIActionsPool.h"44 #include "UIMachineLogic.h"45 #include "UIMachineLogicNormal.h"46 #include "UIMachineLogicFullscreen.h"47 #include "UIMachineLogicSeamless.h"48 #include "UIMachineWindow.h"49 #include "UIMachineView.h"50 51 #include <iprt/path.h>52 #include <VBox/VMMDev.h>53 54 #ifdef VBOX_WITH_DEBUGGER_GUI55 # include <iprt/ldr.h>56 #endif /* VBOX_WITH_DEBUGGER_GUI */57 58 #ifdef Q_WS_X1159 # include <XKeyboard.h>60 # include <QX11Info>61 #endif /* Q_WS_X11 */62 60 63 61 struct MediumTarget … … 1196 1194 callVMMAction->setText(QApplication::translate("UIMachineLogic", "More CD/DVD Images...")); 1197 1195 unmountMediumAction->setText(QApplication::translate("UIMachineLogic", "Unmount CD/DVD Device")); 1198 unmountMediumAction->setIcon( VBoxGlobal::iconSet(":/cd_unmount_16px.png",1196 unmountMediumAction->setIcon(UIIconPool::iconSet(":/cd_unmount_16px.png", 1199 1197 ":/cd_unmount_dis_16px.png")); 1200 1198 break; … … 1202 1200 callVMMAction->setText(QApplication::translate("UIMachineLogic", "More Floppy Images...")); 1203 1201 unmountMediumAction->setText(QApplication::translate("UIMachineLogic", "Unmount Floppy Device")); 1204 unmountMediumAction->setIcon( VBoxGlobal::iconSet(":/fd_unmount_16px.png",1202 unmountMediumAction->setIcon(UIIconPool::iconSet(":/fd_unmount_16px.png", 1205 1203 ":/fd_unmount_dis_16px.png")); 1206 1204 break; … … 1230 1228 break; 1231 1229 } 1232 pEmptyMenuAction->setIcon( VBoxGlobal::iconSet(":/delete_16px.png", ":/delete_dis_16px.png"));1230 pEmptyMenuAction->setIcon(UIIconPool::iconSet(":/delete_16px.png", ":/delete_dis_16px.png")); 1233 1231 pMenu->addAction(pEmptyMenuAction); 1234 1232 } … … 1332 1330 pEmptyMenuAction->setEnabled(false); 1333 1331 pEmptyMenuAction->setText(QApplication::translate("UIMachineLogic", "No USB Devices Connected")); 1334 pEmptyMenuAction->setIcon( VBoxGlobal::iconSet(":/delete_16px.png", ":/delete_dis_16px.png"));1332 pEmptyMenuAction->setIcon(UIIconPool::iconSet(":/delete_16px.png", ":/delete_dis_16px.png")); 1335 1333 pEmptyMenuAction->setToolTip(QApplication::translate("UIMachineLogic", "No supported devices connected to the host PC")); 1336 1334 } -
trunk/src/VBox/Frontends/VirtualBox/src/settings/VBoxSettingsDialog.cpp
r28800 r30192 25 25 #include "VBoxSettingsPage.h" 26 26 #include "VBoxToolBar.h" 27 #include "UIIconPool.h" 27 28 28 29 #ifdef Q_WS_MAC … … 104 105 /* Setup error & warning stuff */ 105 106 mButtonBox->addExtraWidget (mIconLabel); 106 mErrorIcon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxCritical, this).pixmap (16, 16);107 mWarnIcon = vboxGlobal().standardIcon (QStyle::SP_MessageBoxWarning, this).pixmap (16, 16);107 mErrorIcon = UIIconPool::defaultIcon(UIIconPool::MessageBoxCriticalIcon, this).pixmap (16, 16); 108 mWarnIcon = UIIconPool::defaultIcon(UIIconPool::MessageBoxWarningIcon, this).pixmap (16, 16); 108 109 109 110 /* Set the default button */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/VBoxGLSettingsNetwork.cpp
r28800 r30192 18 18 */ 19 19 20 /* Local includes */ 20 21 #include "QIWidgetValidator.h" 21 #include " VBoxGlobal.h"22 #include "UIIconPool.h" 22 23 #include "VBoxGLSettingsNetwork.h" 23 24 #include "VBoxGLSettingsNetworkDetails.h" 25 #include "VBoxGlobal.h" 24 26 #include "VBoxProblemReporter.h" 25 27 … … 278 280 << QKeySequence ("F2")); 279 281 280 mAddInterface->setIcon (VBoxGlobal::iconSet(":/add_host_iface_16px.png",281 282 mRemInterface->setIcon (VBoxGlobal::iconSet(":/remove_host_iface_16px.png",283 284 mEditInterface->setIcon (VBoxGlobal::iconSet(":/guesttools_16px.png",285 282 mAddInterface->setIcon(UIIconPool::iconSet(":/add_host_iface_16px.png", 283 ":/add_host_iface_disabled_16px.png")); 284 mRemInterface->setIcon(UIIconPool::iconSet(":/remove_host_iface_16px.png", 285 ":/remove_host_iface_disabled_16px.png")); 286 mEditInterface->setIcon(UIIconPool::iconSet(":/guesttools_16px.png", 287 ":/guesttools_disabled_16px.png")); 286 288 287 289 mTbActions->setUsesTextLabel (false); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsHD.cpp
r29896 r30192 18 18 */ 19 19 20 /* Local Includes */ 21 #include "QIWidgetValidator.h" 22 #include "UIIconPool.h" 23 #include "UINewHDWzd.h" 24 #include "VBoxGlobal.h" 25 #include "VBoxMediaManagerDlg.h" 26 #include "VBoxProblemReporter.h" 27 #include "VBoxToolBar.h" 28 #include "VBoxVMSettingsHD.h" 29 20 30 /* Global Includes */ 21 31 #include <QHeaderView> … … 26 36 #include <QStylePainter> 27 37 #include <QTimer> 28 29 /* Local Includes */30 #include "VBoxVMSettingsHD.h"31 #include "VBoxGlobal.h"32 #include "VBoxProblemReporter.h"33 #include "QIWidgetValidator.h"34 #include "VBoxToolBar.h"35 #include "VBoxMediaManagerDlg.h"36 #include "UINewHDWzd.h"37 38 38 39 /* String Tags */ … … 1642 1643 /* Controller Actions */ 1643 1644 mAddCtrAction = new QAction (this); 1644 mAddCtrAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::ControllerAddEn),1645 1645 mAddCtrAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::ControllerAddEn), 1646 PixmapPool::pool()->pixmap (PixmapPool::ControllerAddDis))); 1646 1647 1647 1648 mAddIDECtrAction = new QAction (this); 1648 mAddIDECtrAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::IDEControllerAddEn),1649 1649 mAddIDECtrAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::IDEControllerAddEn), 1650 PixmapPool::pool()->pixmap (PixmapPool::IDEControllerAddDis))); 1650 1651 1651 1652 mAddSATACtrAction = new QAction (this); 1652 mAddSATACtrAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::SATAControllerAddEn),1653 1653 mAddSATACtrAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::SATAControllerAddEn), 1654 PixmapPool::pool()->pixmap (PixmapPool::SATAControllerAddDis))); 1654 1655 1655 1656 mAddSCSICtrAction = new QAction (this); 1656 mAddSCSICtrAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::SCSIControllerAddEn),1657 1657 mAddSCSICtrAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::SCSIControllerAddEn), 1658 PixmapPool::pool()->pixmap (PixmapPool::SCSIControllerAddDis))); 1658 1659 1659 1660 mAddFloppyCtrAction = new QAction (this); 1660 mAddFloppyCtrAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::FloppyControllerAddEn),1661 1661 mAddFloppyCtrAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::FloppyControllerAddEn), 1662 PixmapPool::pool()->pixmap (PixmapPool::FloppyControllerAddDis))); 1662 1663 1663 1664 mAddSASCtrAction = new QAction (this); 1664 mAddSASCtrAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::SATAControllerAddEn),1665 1665 mAddSASCtrAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::SATAControllerAddEn), 1666 PixmapPool::pool()->pixmap (PixmapPool::SATAControllerAddDis))); 1666 1667 1667 1668 mDelCtrAction = new QAction (this); 1668 mDelCtrAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::ControllerDelEn),1669 1669 mDelCtrAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::ControllerDelEn), 1670 PixmapPool::pool()->pixmap (PixmapPool::ControllerDelDis))); 1670 1671 1671 1672 /* Attachment Actions */ 1672 1673 mAddAttAction = new QAction (this); 1673 mAddAttAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::AttachmentAddEn),1674 1674 mAddAttAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::AttachmentAddEn), 1675 PixmapPool::pool()->pixmap (PixmapPool::AttachmentAddDis))); 1675 1676 1676 1677 mAddHDAttAction = new QAction (this); 1677 mAddHDAttAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::HDAttachmentAddEn),1678 1678 mAddHDAttAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::HDAttachmentAddEn), 1679 PixmapPool::pool()->pixmap (PixmapPool::HDAttachmentAddDis))); 1679 1680 1680 1681 mAddCDAttAction = new QAction (this); 1681 mAddCDAttAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::CDAttachmentAddEn),1682 1682 mAddCDAttAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::CDAttachmentAddEn), 1683 PixmapPool::pool()->pixmap (PixmapPool::CDAttachmentAddDis))); 1683 1684 1684 1685 mAddFDAttAction = new QAction (this); 1685 mAddFDAttAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::FDAttachmentAddEn),1686 1686 mAddFDAttAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::FDAttachmentAddEn), 1687 PixmapPool::pool()->pixmap (PixmapPool::FDAttachmentAddDis))); 1687 1688 1688 1689 mDelAttAction = new QAction (this); 1689 mDelAttAction->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::AttachmentDelEn),1690 1690 mDelAttAction->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::AttachmentDelEn), 1691 PixmapPool::pool()->pixmap (PixmapPool::AttachmentDelDis))); 1691 1692 1692 1693 /* Storage Model/View */ … … 1718 1719 1719 1720 /* Vmm Button */ 1720 mTbVmm->setIcon (VBoxGlobal::iconSet(PixmapPool::pool()->pixmap (PixmapPool::VMMEn),1721 1721 mTbVmm->setIcon(UIIconPool::iconSet(PixmapPool::pool()->pixmap (PixmapPool::VMMEn), 1722 PixmapPool::pool()->pixmap (PixmapPool::VMMDis))); 1722 1723 1723 1724 /* Info Pane initialization */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSF.cpp
r28800 r30192 18 18 */ 19 19 20 /* Local includes */ 21 #include "UIIconPool.h" 22 #include "VBoxGlobal.h" 23 #include "VBoxProblemReporter.h" 24 #include "VBoxUtils.h" 25 #include "VBoxVMSettingsSF.h" 26 #include "VBoxVMSettingsSFDetails.h" 27 20 28 /* Global includes */ 21 29 #include <QHeaderView> 22 30 #include <QTimer> 23 24 /* Local includes */25 #include "VBoxVMSettingsSF.h"26 #include "VBoxVMSettingsSFDetails.h"27 #include "VBoxGlobal.h"28 #include "VBoxProblemReporter.h"29 #include "VBoxUtils.h"30 31 31 32 class SFTreeViewItem : public QTreeWidgetItem … … 181 182 mDelAction->setShortcut (QKeySequence ("Del")); 182 183 183 mNewAction->setIcon (VBoxGlobal::iconSet(":/add_shared_folder_16px.png",184 185 mEdtAction->setIcon (VBoxGlobal::iconSet(":/edit_shared_folder_16px.png",186 187 mDelAction->setIcon (VBoxGlobal::iconSet(":/revome_shared_folder_16px.png",188 184 mNewAction->setIcon(UIIconPool::iconSet(":/add_shared_folder_16px.png", 185 ":/add_shared_folder_disabled_16px.png")); 186 mEdtAction->setIcon(UIIconPool::iconSet(":/edit_shared_folder_16px.png", 187 ":/edit_shared_folder_disabled_16px.png")); 188 mDelAction->setIcon(UIIconPool::iconSet(":/revome_shared_folder_16px.png", 189 ":/revome_shared_folder_disabled_16px.png")); 189 190 190 191 /* Prepare toolbar */ -
trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsSystem.cpp
r28939 r30192 18 18 */ 19 19 20 /* Local includes */ 21 #include "QIWidgetValidator.h" 22 #include "UIIconPool.h" 23 #include "VBoxGlobal.h" 24 #include "VBoxVMSettingsSystem.h" 25 20 26 /* Global includes */ 27 #include <iprt/cdefs.h> 21 28 #include <QHeaderView> 22 23 /* Local includes */24 #include "VBoxVMSettingsSystem.h"25 #include "VBoxGlobal.h"26 #include "QIWidgetValidator.h"27 #include <iprt/cdefs.h>28 29 29 30 #define ITEM_TYPE_ROLE Qt::UserRole + 1 … … 71 72 72 73 /* Setup iconsets */ 73 mTbBootItemUp->setIcon (VBoxGlobal::iconSet(":/list_moveup_16px.png",74 75 mTbBootItemDown->setIcon (VBoxGlobal::iconSet(":/list_movedown_16px.png",76 74 mTbBootItemUp->setIcon(UIIconPool::iconSet(":/list_moveup_16px.png", 75 ":/list_moveup_disabled_16px.png")); 76 mTbBootItemDown->setIcon(UIIconPool::iconSet(":/list_movedown_16px.png", 77 ":/list_movedown_disabled_16px.png")); 77 78 78 79 #ifdef Q_WS_MAC -
trunk/src/VBox/Frontends/VirtualBox/src/settings/vm/VBoxVMSettingsUSB.cpp
r28939 r30192 18 18 */ 19 19 20 /* Local includes */ 21 #include "QIWidgetValidator.h" 22 #include "UIIconPool.h" 23 #include "VBoxGlobal.h" 24 #include "VBoxToolBar.h" 20 25 #include "VBoxVMSettingsUSB.h" 21 26 #include "VBoxVMSettingsUSBFilterDetails.h" 22 #include "QIWidgetValidator.h" 23 #include "VBoxToolBar.h" 24 #include "VBoxGlobal.h" 25 27 28 /* Global includes */ 26 29 #include <QHeaderView> 27 30 … … 54 57 mMdnAction->setShortcut (QKeySequence ("Ctrl+Down")); 55 58 56 mNewAction->setIcon (VBoxGlobal::iconSet(":/usb_new_16px.png",57 58 mAddAction->setIcon (VBoxGlobal::iconSet(":/usb_add_16px.png",59 60 mEdtAction->setIcon (VBoxGlobal::iconSet(":/usb_filter_edit_16px.png",61 62 mDelAction->setIcon (VBoxGlobal::iconSet(":/usb_remove_16px.png",63 64 mMupAction->setIcon (VBoxGlobal::iconSet(":/usb_moveup_16px.png",65 66 mMdnAction->setIcon (VBoxGlobal::iconSet(":/usb_movedown_16px.png",67 59 mNewAction->setIcon(UIIconPool::iconSet(":/usb_new_16px.png", 60 ":/usb_new_disabled_16px.png")); 61 mAddAction->setIcon(UIIconPool::iconSet(":/usb_add_16px.png", 62 ":/usb_add_disabled_16px.png")); 63 mEdtAction->setIcon(UIIconPool::iconSet(":/usb_filter_edit_16px.png", 64 ":/usb_filter_edit_disabled_16px.png")); 65 mDelAction->setIcon(UIIconPool::iconSet(":/usb_remove_16px.png", 66 ":/usb_remove_disabled_16px.png")); 67 mMupAction->setIcon(UIIconPool::iconSet(":/usb_moveup_16px.png", 68 ":/usb_moveup_disabled_16px.png")); 69 mMdnAction->setIcon(UIIconPool::iconSet(":/usb_movedown_16px.png", 70 ":/usb_movedown_disabled_16px.png")); 68 71 69 72 /* Prepare menu and toolbar */ -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxFilePathSelectorWidget.cpp
r28800 r30192 18 18 */ 19 19 20 /* VBox includes */ 21 #include "VBoxFilePathSelectorWidget.h" 22 #include "VBoxGlobal.h" 20 /* Local includes */ 23 21 #include "QIFileDialog.h" 24 22 #include "QILabel.h" 25 23 #include "QILineEdit.h" 26 27 /* Qt includes */ 24 #include "UIIconPool.h" 25 #include "VBoxFilePathSelectorWidget.h" 26 27 /* Global includes */ 28 #include <iprt/assert.h> 28 29 #include <QAction> 29 30 #include <QApplication> … … 32 33 #include <QFileIconProvider> 33 34 #include <QFocusEvent> 35 #include <QHBoxLayout> 34 36 #include <QLineEdit> 35 37 #include <QPushButton> … … 79 81 80 82 /* Attaching known icons */ 81 setItemIcon (SelectId, VBoxGlobal::iconSet(":/select_file_16px.png"));82 setItemIcon (ResetId, VBoxGlobal::iconSet(":/eraser_16px.png"));83 setItemIcon(SelectId, UIIconPool::iconSet(":/select_file_16px.png")); 84 setItemIcon(ResetId, UIIconPool::iconSet(":/eraser_16px.png")); 83 85 84 86 /* Setup context menu */ … … 156 158 { 157 159 insertItem (ResetId, ""); 158 setItemIcon (ResetId, VBoxGlobal::iconSet(":/eraser_16px.png"));160 setItemIcon(ResetId, UIIconPool::iconSet(":/eraser_16px.png")); 159 161 } 160 162 retranslateUi(); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMiniToolBar.cpp
r29083 r30192 18 18 */ 19 19 20 /* Local includes */ 21 #include "UIIconPool.h" 22 #include "VBoxGlobal.h" 23 #include "VBoxMiniToolBar.h" 24 20 25 /* Global includes */ 21 26 #include <QCursor> … … 23 28 #include <QLabel> 24 29 #include <QMenu> 30 #include <QPaintEvent> 25 31 #include <QPainter> 26 #include <QPaintEvent>27 32 #include <QPolygon> 28 33 #include <QRect> … … 30 35 #include <QTimer> 31 36 #include <QToolButton> 32 33 /* Local includes */34 #include "VBoxMiniToolBar.h"35 #include "VBoxGlobal.h"36 37 37 38 /* Mini-toolbar constructor */ … … 70 71 /* Add pushpin: */ 71 72 m_pAutoHideAction = new QAction(this); 72 m_pAutoHideAction->setIcon( VBoxGlobal::iconSet(":/pin_16px.png"));73 m_pAutoHideAction->setIcon(UIIconPool::iconSet(":/pin_16px.png")); 73 74 m_pAutoHideAction->setToolTip(tr("Always show the toolbar")); 74 75 m_pAutoHideAction->setCheckable(true); … … 97 98 /* Exit action: */ 98 99 m_pRestoreAction = new QAction(this); 99 m_pRestoreAction->setIcon( VBoxGlobal::iconSet(":/restore_16px.png"));100 m_pRestoreAction->setIcon(UIIconPool::iconSet(":/restore_16px.png")); 100 101 m_pRestoreAction->setToolTip(tr("Exit Full Screen or Seamless Mode")); 101 102 connect(m_pRestoreAction, SIGNAL(triggered()), this, SIGNAL(exitAction())); … … 104 105 /* Close action: */ 105 106 m_pCloseAction = new QAction(this); 106 m_pCloseAction->setIcon( VBoxGlobal::iconSet(":/close_16px.png"));107 m_pCloseAction->setIcon(UIIconPool::iconSet(":/close_16px.png")); 107 108 m_pCloseAction->setToolTip(tr("Close VM")); 108 109 connect(m_pCloseAction, SIGNAL(triggered()), this, SIGNAL(closeAction())); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxSpecialControls.cpp
r30189 r30192 19 19 20 20 /* VBox includes */ 21 #include "UIIconPool.h" 21 22 #include "VBoxSpecialControls.h" 22 23 23 /* VBoxincludes */24 #include "VBoxGlobal.h"24 /* Global includes */ 25 #include <QHBoxLayout> 25 26 26 27 #ifdef VBOX_DARWIN_USE_NATIVE_CONTROLS … … 120 121 QIcon cancelIcon = style()->standardIcon (QStyle::SP_DialogCancelButton); 121 122 if (cancelIcon.isNull()) 122 cancelIcon = VBoxGlobal::iconSet(":/delete_16px.png",123 123 cancelIcon = UIIconPool::iconSet(":/delete_16px.png", 124 ":/delete_dis_16px.png"); 124 125 setIcon (cancelIcon); 125 126 } -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/firstrun/UIFirstRunWzd.cpp
r29942 r30192 20 20 /* Local includes */ 21 21 #include "UIFirstRunWzd.h" 22 #include "VBoxGlobal.h" 22 #include "UIIconPool.h" 23 #include "VBoxMediaManagerDlg.h" 23 24 #include "VBoxProblemReporter.h" 24 #include "VBoxMediaManagerDlg.h"25 25 #include "VBoxVMSettingsHD.h" 26 26 … … 163 163 164 164 /* Setup contents */ 165 m_pSelectMediaButton->setIcon(VBoxGlobal::iconSet(":/select_file_16px.png", ":/select_file_dis_16px.png")); 165 m_pSelectMediaButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", 166 ":/select_file_dis_16px.png")); 166 167 167 168 /* Setup connections */ -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWzd.cpp
r29730 r30192 18 18 */ 19 19 20 /* Global includes */21 #include <QFileDialog>22 #include <QRegExpValidator>23 24 20 /* Local includes */ 21 #include "UIIconPool.h" 25 22 #include "UINewHDWzd.h" 26 23 #include "VBoxGlobal.h" 27 24 #include "VBoxProblemReporter.h" 25 26 /* Global includes */ 28 27 #include "iprt/path.h" 28 #include <QFileDialog> 29 #include <QRegExpValidator> 30 29 31 30 32 UINewHDWzd::UINewHDWzd(QWidget *pParent) : QIWizard(pParent) … … 234 236 235 237 /* Attach button icon */ 236 m_pLocationSelector->setIcon(vboxGlobal().iconSet(":/select_file_16px.png", "select_file_dis_16px.png")); 238 m_pLocationSelector->setIcon(UIIconPool::iconSet(":/select_file_16px.png", 239 "select_file_dis_16px.png")); 237 240 238 241 /* Setup page connections */ -
trunk/src/VBox/Frontends/VirtualBox/src/wizards/newvm/UINewVMWzd.cpp
r30179 r30192 19 19 20 20 /* Local includes */ 21 #include "UIIconPool.h" 22 #include "UINewHDWzd.h" 21 23 #include "UINewVMWzd.h" 22 #include "UINewHDWzd.h" 23 #include "VBoxGlobal.h" 24 #include "VBoxMediaManagerDlg.h" 24 25 #include "VBoxProblemReporter.h" 25 #include "VBoxMediaManagerDlg.h"26 26 #include "VBoxVMSettingsHD.h" 27 27 … … 349 349 350 350 /* Setup medium-manager button */ 351 m_pVMMButton->setIcon(VBoxGlobal::iconSet(":/select_file_16px.png", ":/select_file_dis_16px.png")); 351 m_pVMMButton->setIcon(UIIconPool::iconSet(":/select_file_16px.png", 352 ":/select_file_dis_16px.png")); 352 353 353 354 /* Setup page connections */
Note:
See TracChangeset
for help on using the changeset viewer.