VirtualBox

Ignore:
Timestamp:
Sep 21, 2015 4:26:00 PM (9 years ago)
Author:
vboxsync
Message:

FE/Qt: Selector-window cleanup/rework (step 6): Representing selector-window as singleton.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIModalWindowManager.cpp

    r52730 r57844  
    100100    {
    101101        /* It will be the selector window if visible: */
    102         if (vboxGlobal().selectorWnd().isVisible())
    103             return &vboxGlobal().selectorWnd();
     102        if (gpSelectorWindow &&
     103            gpSelectorWindow->isVisible())
     104            return gpSelectorWindow;
    104105    }
    105106
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r57842 r57844  
    233233    : mValid (false)
    234234    , m_fVBoxSVCAvailable(true)
    235     , mSelectorWnd (NULL)
    236235    , m_fSeparateProcess(false)
    237236    , m_pMediumEnumerator(0)
     
    428427
    429428    return true;
    430 }
    431 
    432 /**
    433  *  Returns a reference to the main VBox VM Selector window.
    434  *  The reference is valid until application termination.
    435  *
    436  *  There is only one such a window per VirtualBox application.
    437  */
    438 UISelectorWindow &VBoxGlobal::selectorWnd()
    439 {
    440     AssertMsg (!vboxGlobal().isVMConsoleProcess(),
    441                ("Must NOT be a VM console process"));
    442     Assert (mValid);
    443 
    444     if (!mSelectorWnd)
    445     {
    446         /*
    447          *  We pass the address of mSelectorWnd to the constructor to let it be
    448          *  initialized right after the constructor is called. It is necessary
    449          *  to avoid recursion, since this method may be (and will be) called
    450          *  from the below constructor or from constructors/methods it calls.
    451          */
    452         UISelectorWindow *w = new UISelectorWindow (&mSelectorWnd);
    453         Assert (w == mSelectorWnd);
    454         NOREF(w);
    455     }
    456 
    457     return *mSelectorWnd;
    458429}
    459430
     
    39973968    {
    39983969        m_ArgUrlList = list;
    3999         QTimer::singleShot(0, &vboxGlobal().selectorWnd(), SLOT(sltOpenUrls()));
     3970        UISelectorWindow::create();
     3971        QTimer::singleShot(0, gpSelectorWindow, SLOT(sltOpenUrls()));
    40003972    }
    40013973    return fResult;
     
    44324404    /* Destroy the GUI root windows _BEFORE_ the media-mess, because there is
    44334405       code in the GUI that's using the media code an will be racing us! */
    4434     if (mSelectorWnd)
    4435     {
    4436         delete mSelectorWnd;
    4437         mSelectorWnd = NULL;
    4438     }
     4406    if (gpSelectorWindow)
     4407        UISelectorWindow::destroy();
    44394408    if (gpMachine)
    44404409        UIMachine::destroy();
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r57805 r57844  
    7373////////////////////////////////////////////////////////////////////////////////
    7474
    75 class UISelectorWindow;
    7675class VBoxUpdateDlg;
    7776
     
    174173    VBoxGlobalSettings &settings() { return gset; }
    175174    bool setSettings (VBoxGlobalSettings &gs);
    176 
    177     UISelectorWindow &selectorWnd();
    178175
    179176    /** Returns currently active virtual machine window. */
     
    536533
    537534    VBoxGlobalSettings gset;
    538 
    539     UISelectorWindow *mSelectorWnd;
    540535
    541536    /** Holds whether GUI is separate (from VM) process. */
  • trunk/src/VBox/Frontends/VirtualBox/src/main.cpp

    r57780 r57844  
    511511
    512512                /* Create/show selector window: */
    513                 vboxGlobal().selectorWnd().show();
     513                UISelectorWindow::create();
    514514
    515515                /* Start application: */
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r57842 r57844  
    7878
    7979
    80 UISelectorWindow::UISelectorWindow(UISelectorWindow **ppSelf)
     80/* static */
     81UISelectorWindow* UISelectorWindow::m_spInstance = 0;
     82
     83/* static */
     84void UISelectorWindow::create()
     85{
     86    /* Make sure selector-window is not created: */
     87    AssertReturnVoid(!m_spInstance);
     88
     89    /* Create selector-window: */
     90    new UISelectorWindow;
     91    /* Prepare selector-window: */
     92    m_spInstance->prepare();
     93    /* Show selector-window: */
     94    m_spInstance->show();
     95}
     96
     97/* static */
     98void UISelectorWindow::destroy()
     99{
     100    /* Make sure selector-window is created: */
     101    AssertPtrReturnVoid(m_spInstance);
     102
     103    /* Cleanup selector-window: */
     104    m_spInstance->cleanup();
     105    /* Destroy machine UI: */
     106    delete m_spInstance;
     107}
     108
     109UISelectorWindow::UISelectorWindow()
    81110    : m_fPolished(false)
    82111    , m_fWarningAboutInaccessibleMediaShown(false)
     
    94123    , m_pMachineMenuAction(0)
    95124{
    96     /* Remember self: */
    97     if (ppSelf)
    98         *ppSelf = this;
    99 
    100     /* Prepare: */
    101     prepare();
     125    m_spInstance = this;
    102126}
    103127
    104128UISelectorWindow::~UISelectorWindow()
    105129{
    106     /* Cleanup: */
    107     cleanup();
     130    m_spInstance = 0;
    108131}
    109132
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h

    r57842 r57844  
    4040class QStackedWidget;
    4141
    42 /** QMainWindow extension
     42/** Singleton QMainWindow extension
    4343  * used as VirtualBox Manager (selector-window) instance. */
    4444class UISelectorWindow : public QIWithRetranslateUI<QMainWindow>
     
    4848public:
    4949
    50     /** Constructs selector-window passing @a pParent to the QMainWindow base-class.
     50    /** Static constructor. */
     51    static void create();
     52    /** Static destructor. */
     53    static void destroy();
     54    /** Static instance. */
     55    static UISelectorWindow* instance() { return m_spInstance; }
     56
     57    /** Returns the action-pool instance. */
     58    UIActionPool* actionPool() const { return m_pActionPool; }
     59
     60protected:
     61
     62    /** Constructs selector-window.
    5163      * @param ppSelf brings the pointer to pointer to this window instance used by the external caller.
    5264      * @param flags  brings the selector-window flags dialogs should have. */
    53     UISelectorWindow(UISelectorWindow **ppSelf);
     65    UISelectorWindow();
    5466    /** Destructs selector-window. */
    5567    ~UISelectorWindow();
    56 
    57     /** Returns the action-pool instance. */
    58     UIActionPool* actionPool() const { return m_pActionPool; }
    5968
    6069private slots:
     
    250259    /** @} */
    251260
     261    /** Static instance. */
     262    static UISelectorWindow *m_spInstance;
     263
    252264    /** Holds whether the dialog is polished. */
    253265    bool m_fPolished : 1;
     
    292304};
    293305
     306#define gpSelectorWindow UISelectorWindow::instance()
     307
    294308#endif /* !___UISelectorWindow_h___ */
    295309
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/graphics/chooser/UIGChooserModel.cpp

    r57039 r57844  
    883883
    884884    /* Prepare the new VM wizard: */
    885     UISafePointerWizardNewVM pWizard = new UIWizardNewVM(&vboxGlobal().selectorWnd(), strGroupName);
     885    UISafePointerWizardNewVM pWizard = new UIWizardNewVM(m_pChooser->selector(), strGroupName);
    886886    pWizard->prepare();
    887887
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette