Changeset 45452 in vbox
- Timestamp:
- Apr 10, 2013 10:19:38 AM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
r45432 r45452 70 70 #include <iprt/param.h> 71 71 #include <iprt/path.h> 72 73 /* static */ 74 UIMessageCenter* UIMessageCenter::m_spInstance = 0; 75 UIMessageCenter* UIMessageCenter::instance() { return m_spInstance; } 76 77 /* static */ 78 void UIMessageCenter::create() 79 { 80 /* Make sure instance is NOT created yet: */ 81 if (m_spInstance) 82 { 83 AssertMsgFailed(("UIMessageCenter instance is already created!")); 84 return; 85 } 86 87 /* Create instance: */ 88 new UIMessageCenter; 89 /* Prepare instance: */ 90 m_spInstance->prepare(); 91 } 92 93 /* static */ 94 void UIMessageCenter::destroy() 95 { 96 /* Make sure instance is NOT destroyed yet: */ 97 if (!m_spInstance) 98 { 99 AssertMsgFailed(("UIMessageCenter instance is already destroyed!")); 100 return; 101 } 102 103 /* Cleanup instance: */ 104 m_spInstance->cleanup(); 105 /* Destroy instance: */ 106 delete m_spInstance; 107 } 72 108 73 109 bool UIMessageCenter::warningShown(const QString &strWarningName) const … … 2534 2570 UIMessageCenter::UIMessageCenter() 2535 2571 { 2572 /* Assign instance: */ 2573 m_spInstance = this; 2574 } 2575 2576 UIMessageCenter::~UIMessageCenter() 2577 { 2578 /* Unassign instance: */ 2579 m_spInstance = 0; 2580 } 2581 2582 void UIMessageCenter::prepare() 2583 { 2536 2584 /* Register required objects as meta-types: */ 2537 2585 qRegisterMetaType<CProgress>(); … … 2570 2618 } 2571 2619 2572 /* Returns a reference to the global VirtualBox message center instance: */ 2573 UIMessageCenter &UIMessageCenter::instance() 2574 { 2575 static UIMessageCenter global_instance; 2576 return global_instance; 2620 void UIMessageCenter::cleanup() 2621 { 2622 /* Nothing for now... */ 2577 2623 } 2578 2624 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
r45432 r45452 73 73 AutoConfirmed = 0x8000 74 74 }; 75 76 /* Static API: Create/destroy stuff: */ 77 static void create(); 78 static void destroy(); 75 79 76 80 /* API: Warning registration stuff: */ … … 383 387 private: 384 388 385 /* Constructor : */389 /* Constructor/destructor: */ 386 390 UIMessageCenter(); 387 388 /* Instance stuff: */ 389 static UIMessageCenter &instance(); 390 friend UIMessageCenter &msgCenter(); 391 ~UIMessageCenter(); 392 393 /* Helpers: Prepare/cleanup stuff: */ 394 void prepare(); 395 void cleanup(); 391 396 392 397 /* Helper: */ … … 402 407 /* Variables: */ 403 408 mutable QStringList m_warnings; 409 410 /* API: Instance stuff: */ 411 static UIMessageCenter* m_spInstance; 412 static UIMessageCenter* instance(); 413 friend UIMessageCenter& msgCenter(); 404 414 }; 405 415 406 /* Shortcut to the static UIMessageCenter::instance() method , for convenience.*/407 inline UIMessageCenter &msgCenter() { returnUIMessageCenter::instance(); }416 /* Shortcut to the static UIMessageCenter::instance() method: */ 417 inline UIMessageCenter& msgCenter() { return *UIMessageCenter::instance(); } 408 418 409 419 #endif // __UIMessageCenter_h__ -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.cpp
r45441 r45452 29 29 30 30 /* static */ 31 UIModalWindowManager* UIModalWindowManager::m_spInstance = 0; 31 32 UIModalWindowManager* UIModalWindowManager::instance() { return m_spInstance; } 32 UIModalWindowManager* UIModalWindowManager::m_spInstance = 0;33 33 34 34 /* static */ 35 35 void UIModalWindowManager::create() 36 36 { 37 /* Make sure instance is not created: */37 /* Make sure instance is NOT created yet: */ 38 38 if (m_spInstance) 39 return; 39 { 40 AssertMsgFailed(("UIModalWindowManager instance is already created!")); 41 return; 42 } 40 43 41 44 /* Create instance: */ … … 46 49 void UIModalWindowManager::destroy() 47 50 { 48 /* Make sure instance is created: */51 /* Make sure instance is NOT destroyed yet: */ 49 52 if (!m_spInstance) 50 return; 51 52 /* Create instance: */ 53 { 54 AssertMsgFailed(("UIModalWindowManager instance is already destroyed!")); 55 return; 56 } 57 58 /* Destroy instance: */ 53 59 delete m_spInstance; 54 60 } … … 56 62 UIModalWindowManager::UIModalWindowManager() 57 63 { 58 /* Make sure instance is not assigned: */ 59 if (m_spInstance != this) 60 m_spInstance = this; 64 /* Assign instance: */ 65 m_spInstance = this; 61 66 } 62 67 63 68 UIModalWindowManager::~UIModalWindowManager() 64 69 { 65 /* Make sure instance still assigned: */ 66 if (m_spInstance == this) 67 m_spInstance = 0; 70 /* Unassign instance: */ 71 m_spInstance = 0; 68 72 } 69 73 70 74 QWidget* UIModalWindowManager::mainWindowShown() const 71 75 { 72 /* Later this function will be independent of VBoxGlobal at all, 73 * but for now VBoxGlobal creates all the main application windows, 74 * so we should honor this fact. 75 * 76 * It may happen that this method is called during VBoxGlobal 77 * initialization or even after it had failed (for example, to show some message). 78 * Return NULL pointer in this case: */ 79 if (!vboxGlobal().isValid()) 76 /* It may happen that this method is called before VBoxGlobal initialization 77 * or after initialization had failed (for example, to show some message). 78 * Return NULL pointer in such cases: */ 79 if (!VBoxGlobal::instance() || !vboxGlobal().isValid()) 80 80 return 0; 81 81 … … 88 88 return vboxGlobal().activeMachineWindow(); 89 89 } 90 /* Otherwise: */90 /* For VM selector process: */ 91 91 else 92 92 { … … 96 96 } 97 97 98 /* N othingby default: */98 /* NULL by default: */ 99 99 return 0; 100 100 } -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.h
r45432 r45452 2 2 * 3 3 * VBox frontends: Qt GUI ("VirtualBox"): 4 * UIModalWindowManager class de finition4 * UIModalWindowManager class declaration 5 5 */ 6 6 … … 66 66 /* Variables: */ 67 67 QList<QList<QWidget*> > m_windows; 68 static UIModalWindowManager* m_spInstance;69 68 70 69 /* Static API: Instance stuff: */ 70 static UIModalWindowManager* m_spInstance; 71 71 static UIModalWindowManager* instance(); 72 72 friend UIModalWindowManager& windowManager(); -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.cpp
r45431 r45452 32 32 33 33 /* static */ 34 void UIPopupCenter:: prepare()34 void UIPopupCenter::create() 35 35 { 36 /* Make sure instance is notcreated yet: */36 /* Make sure instance is NOT created yet: */ 37 37 if (m_spInstance) 38 38 return; … … 43 43 44 44 /* static */ 45 void UIPopupCenter:: cleanup()45 void UIPopupCenter::destroy() 46 46 { 47 /* Make sure instance is still created: */47 /* Make sure instance is NOT destroyed yet: */ 48 48 if (!m_spInstance) 49 49 return; 50 50 51 /* Createinstance: */51 /* Destroy instance: */ 52 52 delete m_spInstance; 53 53 } … … 55 55 UIPopupCenter::UIPopupCenter() 56 56 { 57 /* Prepare instance: */ 58 if (!m_spInstance) 59 m_spInstance = this; 57 /* Assign instance: */ 58 m_spInstance = this; 60 59 } 61 60 62 61 UIPopupCenter::~UIPopupCenter() 63 62 { 64 /* Cleanup instance: */ 65 if (m_spInstance) 66 m_spInstance = 0; 63 /* Unassign instance: */ 64 m_spInstance = 0; 67 65 } 68 66 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIPopupCenter.h
r45431 r45452 32 32 public: 33 33 34 /* Prepare/cleanupstuff: */35 static void prepare();36 static void cleanup();34 /* Static API: Create/destroy stuff: */ 35 static void create(); 36 static void destroy(); 37 37 38 38 /* API: Main message function, used directly only in exceptional cases: */ … … 90 90 ~UIPopupCenter(); 91 91 92 /* Instance stuff: */93 static UIPopupCenter* instance();94 friend UIPopupCenter& popupCenter();95 96 92 /* Helper: Popup-box stuff: */ 97 93 void showPopupBox(QWidget *pParent, … … 102 98 103 99 /* Variables: */ 100 mutable QMap<QString, QPointer<QWidget> > m_popups; 101 102 /* Instance stuff: */ 104 103 static UIPopupCenter* m_spInstance; 105 mutable QMap<QString, QPointer<QWidget> > m_popups; 104 static UIPopupCenter* instance(); 105 friend UIPopupCenter& popupCenter(); 106 106 }; 107 107 108 /* Shortcut to the static UIPopupCenter::instance() method , for convenience: */108 /* Shortcut to the static UIPopupCenter::instance() method: */ 109 109 inline UIPopupCenter& popupCenter() { return *UIPopupCenter::instance(); } 110 110 -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r45431 r45452 186 186 // VBoxGlobal 187 187 //////////////////////////////////////////////////////////////////////////////// 188 189 static bool sVBoxGlobalInited = false;190 static bool sVBoxGlobalInCleanup = false;191 192 /** @internal193 *194 * Special routine to do VBoxGlobal cleanup when the application is being195 * terminated. It is called before some essential Qt functionality (for196 * instance, QThread) becomes unavailable, allowing us to use it from197 * VBoxGlobal::cleanup() if necessary.198 */199 static void vboxGlobalCleanup()200 {201 Assert (!sVBoxGlobalInCleanup);202 sVBoxGlobalInCleanup = true;203 vboxGlobal().cleanup();204 }205 188 206 189 /** @internal … … 258 241 } 259 242 260 /** @class VBoxGlobal 261 * 262 * The VBoxGlobal class encapsulates the global VirtualBox data. 263 * 264 * There is only one instance of this class per VirtualBox application, 265 * the reference to it is returned by the static instance() method, or by 266 * the global vboxGlobal() function, that is just an inlined shortcut. 267 */ 243 /* static */ 244 bool VBoxGlobal::m_sfCleanupInProgress = false; 245 VBoxGlobal* VBoxGlobal::m_spInstance = 0; 246 VBoxGlobal* VBoxGlobal::instance() { return m_spInstance; } 247 248 /* static */ 249 void VBoxGlobal::create() 250 { 251 /* Make sure instance is NOT created yet: */ 252 if (m_spInstance) 253 { 254 AssertMsgFailed(("VBoxGlobal instance is already created!")); 255 return; 256 } 257 258 /* Create instance: */ 259 new VBoxGlobal; 260 /* Prepare instance: */ 261 m_spInstance->prepare(); 262 } 263 264 /* static */ 265 void VBoxGlobal::destroy() 266 { 267 /* Make sure instance is NOT destroyed yet: */ 268 if (!m_spInstance) 269 { 270 AssertMsgFailed(("VBoxGlobal instance is already destroyed!")); 271 return; 272 } 273 274 /* Cleanup instance: */ 275 /* Automatically on QApplication::aboutToQuit() signal: */ 276 /* Destroy instance: */ 277 delete m_spInstance; 278 } 268 279 269 280 VBoxGlobal::VBoxGlobal() … … 282 293 , mSettingsPwSet(false) 283 294 { 284 } 285 286 // 287 // Public members 288 ///////////////////////////////////////////////////////////////////////////// 289 290 /** 291 * Returns a reference to the global VirtualBox data, managed by this class. 292 * 293 * The main() function of the VBox GUI must call this function soon after 294 * creating a QApplication instance but before opening any of the main windows 295 * (to let the VBoxGlobal initialization procedure use various Qt facilities), 296 * and continue execution only when the isValid() method of the returned 297 * instancereturns true, i.e. do something like: 298 * 299 * @code 300 * if ( !VBoxGlobal::instance().isValid() ) 301 * return 1; 302 * @endcode 303 * or 304 * @code 305 * if ( !vboxGlobal().isValid() ) 306 * return 1; 307 * @endcode 308 * 309 * @note Some VBoxGlobal methods can be used on a partially constructed 310 * VBoxGlobal instance, i.e. from constructors and methods called 311 * from the VBoxGlobal::init() method, which obtain the instance 312 * using this instance() call or the ::vboxGlobal() function. Currently, such 313 * methods are: 314 * #vmStateText, #vmTypeIcon, #vmTypeText, #vmTypeTextList, #vmTypeFromText. 315 * 316 * @see ::vboxGlobal 317 */ 318 VBoxGlobal &VBoxGlobal::instance() 319 { 320 static VBoxGlobal vboxGlobal_instance; 321 322 if (!sVBoxGlobalInited) 323 { 324 /* check that a QApplication instance is created */ 325 if (qApp) 326 { 327 sVBoxGlobalInited = true; 328 vboxGlobal_instance.init(); 329 /* add our cleanup handler to the list of Qt post routines */ 330 qAddPostRoutine (vboxGlobalCleanup); 331 } 332 else 333 AssertMsgFailed (("Must construct a QApplication first!")); 334 } 335 return vboxGlobal_instance; 295 /* Assign instance: */ 296 m_spInstance = this; 336 297 } 337 298 338 299 VBoxGlobal::~VBoxGlobal() 339 300 { 340 qDeleteAll (mOsTypeIcons); 301 /* Unassign instance: */ 302 m_spInstance = 0; 341 303 } 342 304 … … 1780 1742 return; 1781 1743 1782 /* ignore the request during application termination*/1783 if ( sVBoxGlobalInCleanup)1744 /* Ignore the request during VBoxGlobal cleanup: */ 1745 if (m_sfCleanupInProgress) 1784 1746 return; 1785 1747 … … 1817 1779 1818 1780 /* Enumerate the list */ 1819 for (int i = 0; i < mVector.size() && ! sVBoxGlobalInCleanup; ++ i)1781 for (int i = 0; i < mVector.size() && !m_sfCleanupInProgress; ++ i) 1820 1782 { 1821 1783 mVector [i].blockAndQueryState(); … … 1827 1789 1828 1790 /* Post the end-of-enumeration event */ 1829 if (! sVBoxGlobalInCleanup)1791 if (!m_sfCleanupInProgress) 1830 1792 QApplication::postEvent (self, new VBoxMediaEnumEvent (mSavedIt)); 1831 1793 … … 4019 3981 } 4020 3982 4021 void VBoxGlobal::init() 4022 { 3983 void VBoxGlobal::prepare() 3984 { 3985 /* Make sure QApplication cleanup us on exit: */ 3986 connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanup())); 3987 3988 /* Create message-center: */ 3989 UIMessageCenter::create(); 4023 3990 /* Create popup-center: */ 4024 UIPopupCenter::prepare(); 3991 UIPopupCenter::create(); 3992 3993 /* Load translation based on the current locale: */ 3994 loadLanguage(); 4025 3995 4026 3996 #ifdef DEBUG … … 4068 4038 } 4069 4039 4070 /* Load the customized language as early as possible to get possible error 4071 * messages translated */ 4040 /* Load translation based on the user settings: */ 4072 4041 QString sLanguageId = gset.languageId(); 4073 4042 if (!sLanguageId.isNull()) … … 4460 4429 } 4461 4430 4462 4463 /** @internal4464 *4465 * This method should be never called directly. It is called automatically4466 * when the application terminates.4467 */4468 4431 void VBoxGlobal::cleanup() 4469 4432 { 4433 /* Preventing some unwanted stuff 4434 * which could de called from the other threads: */ 4435 m_sfCleanupInProgress = true; 4436 4470 4437 /* Shutdown update manager: */ 4471 4438 UIUpdateManager::shutdown(); … … 4479 4446 /* Destroy shortcut pool: */ 4480 4447 UIShortcutPool::destroy(); 4481 4482 /* sanity check */4483 if (!sVBoxGlobalInCleanup)4484 {4485 AssertMsgFailed (("Should never be called directly\n"));4486 return;4487 }4488 4448 4489 4449 #ifdef VBOX_GUI_WITH_PIDFILE … … 4497 4457 if (mMediaEnumThread) 4498 4458 { 4499 /* sVBoxGlobalInCleanup is true here, so just wait for the thread */4500 4459 mMediaEnumThread->wait(); 4501 4460 delete mMediaEnumThread; … … 4509 4468 4510 4469 UIConverter::cleanup(); 4470 4471 /* Ensure mOsTypeIcons is cleaned up: */ 4472 qDeleteAll(mOsTypeIcons); 4511 4473 4512 4474 /* ensure CGuestOSType objects are no longer used */ … … 4528 4490 4529 4491 /* Destroy popup-center: */ 4530 UIPopupCenter::cleanup(); 4492 UIPopupCenter::destroy(); 4493 /* Destroy message-center: */ 4494 UIMessageCenter::destroy(); 4531 4495 4532 4496 mValid = false; -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r45402 r45452 64 64 public: 65 65 66 static VBoxGlobal &instance(); 66 /* Static API: Create/destroy stuff: */ 67 static VBoxGlobal* instance(); 68 static void create(); 69 static void destroy(); 67 70 68 71 bool isValid() { return mValid; } … … 284 287 void retranslateUi(); 285 288 286 /** @internal made public for internal purposes */287 void cleanup();288 289 289 /* public static stuff */ 290 290 … … 422 422 void sltProcessGlobalSettingChange(); 423 423 424 protected slots: 425 426 /* Handlers: Prepare/cleanup stuff: */ 427 void prepare(); 428 void cleanup(); 429 424 430 protected: 425 431 … … 429 435 private: 430 436 437 /* Constructor/destructor: */ 431 438 VBoxGlobal(); 432 439 ~VBoxGlobal(); 433 440 434 void init();435 441 #ifdef VBOX_WITH_DEBUGGER_GUI 436 442 void initDebuggerVar(int *piDbgCfgVar, const char *pszEnvVar, const char *pszExtraDataName, bool fDefault = false); … … 522 528 bool mSettingsPwSet; 523 529 524 friend VBoxGlobal &vboxGlobal(); 530 /* API: Instance stuff: */ 531 static bool m_sfCleanupInProgress; 532 static VBoxGlobal* m_spInstance; 533 friend VBoxGlobal& vboxGlobal(); 525 534 }; 526 535 527 inline VBoxGlobal &vboxGlobal() { return VBoxGlobal::instance(); } 536 /* Shortcut to the static VBoxGlobal::instance() method: */ 537 inline VBoxGlobal& vboxGlobal() { return *VBoxGlobal::instance(); } 528 538 529 539 #endif /* __VBoxGlobal_h__ */ -
trunk/src/VBox/Frontends/VirtualBox/src/main.cpp
r45448 r45452 412 412 bool isCurrentScaleable = fontDataBase.isScalable(currentFamily); 413 413 414 QString subFamily (QFont::substitute(currentFamily));415 bool isSubScaleable = fontDataBase.isScalable 414 QString subFamily(QFont::substitute(currentFamily)); 415 bool isSubScaleable = fontDataBase.isScalable(subFamily); 416 416 417 417 if (isCurrentScaleable && !isSubScaleable) 418 QFont::removeSubstitution 418 QFont::removeSubstitution(currentFamily); 419 419 # endif /* Q_OS_SOLARIS */ 420 420 #endif /* Q_WS_X11 */ … … 446 446 strMsg, QMessageBox::Abort, 0); 447 447 qFatal("%s", strMsg.toAscii().constData()); 448 break; 448 449 } 449 450 #endif /* Q_WS_X11 */ … … 452 453 UIModalWindowManager::create(); 453 454 454 /* Load a translation based on the current locale: */455 VBoxGlobal:: loadLanguage();455 /* Create global UI instance: */ 456 VBoxGlobal::create(); 456 457 457 458 /* Simulate try-catch block: */ … … 519 520 while (0); 520 521 522 /* Destroy global UI instance: */ 523 VBoxGlobal::destroy(); 524 521 525 /* Destroy modal-window manager: */ 522 526 UIModalWindowManager::destroy();
Note:
See TracChangeset
for help on using the changeset viewer.