VirtualBox

Changeset 89585 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jun 9, 2021 4:03:51 PM (4 years ago)
Author:
vboxsync
Message:

FE/Qt:bugref:9315. Avoiding multiple UILogViewerDialog instances in manager UI

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.cpp

    r89049 r89585  
    7474    if (pWidget)
    7575        pWidget->setDialogBeingClosed(true);
     76}
     77
     78void UIVMLogViewerDialog::setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items)
     79{
     80    Q_UNUSED(items);
     81    UIVMLogViewerWidget *pLogViewerWidget = qobject_cast<UIVMLogViewerWidget*>(widget());
     82    if (pLogViewerWidget)
     83        pLogViewerWidget->setSelectedVMListItems(items);
     84}
     85
     86void UIVMLogViewerDialog::addSelectedVMListItems(const QList<UIVirtualMachineItem*> &items)
     87{
     88    Q_UNUSED(items);
     89    UIVMLogViewerWidget *pLogViewerWidget = qobject_cast<UIVMLogViewerWidget*>(widget());
     90    if (pLogViewerWidget)
     91        pLogViewerWidget->addSelectedVMListItems(items);
    7692}
    7793
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.h

    r89049 r89585  
    4040class UIActionPool;
    4141class UIVMLogViewerDialog;
     42class UIVirtualMachineItem;
    4243class CMachine;
    4344
     
    7980    UIVMLogViewerDialog(QWidget *pCenterWidget, UIActionPool *pActionPool, const CMachine &comMachine);
    8081    ~UIVMLogViewerDialog();
     82    void setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items);
     83    void addSelectedVMListItems(const QList<UIVirtualMachineItem*> &items);
    8184
    8285protected:
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r89315 r89585  
    222222}
    223223
     224void UIVMLogViewerWidget::addSelectedVMListItems(const QList<UIVirtualMachineItem*> &items)
     225{
     226    QVector<QUuid> selectedMachines(m_machines);
     227
     228    foreach (const UIVirtualMachineItem *item, items)
     229    {
     230        if (!item)
     231            continue;
     232        selectedMachines << item->id();
     233    }
     234    setMachines(selectedMachines);
     235}
     236
    224237void UIVMLogViewerWidget::setMachines(const QVector<QUuid> &machineIDs)
    225238{
     
    960973        QString strMachineName = comMachine.GetName();
    961974
    962         if (m_enmEmbedding == EmbedTo_Stack)
     975        if (uiCommon().uiType() == UICommon::UIType_SelectorUI)
    963976            m_pTabWidget->addTab(new UILabelTab(this, uMachineId), strMachineName);
    964977
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r89105 r89585  
    8888
    8989    void setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items);
     90    void addSelectedVMListItems(const QList<UIVirtualMachineItem*> &items);
    9091    QFont currentFont() const;
    9192
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.cpp

    r89515 r89585  
    467467    , m_fFirstMediumEnumerationHandled(false)
    468468    , m_pActionPool(0)
     469    , m_pLogViewerDialog(0)
     470    , m_pWidget(0)
    469471    , m_iGeometrySaveTimerId(-1)
    470472{
     
    20012003    }
    20022004
     2005    QList<UIVirtualMachineItem*> itemsToShowLogs;
     2006
    20032007    /* For each selected item: */
    20042008    foreach (UIVirtualMachineItem *pItem, items)
     
    20122016        if (!isActionEnabled(UIActionIndexMN_M_Group_S_ShowLogDialog, QList<UIVirtualMachineItem*>() << pItem))
    20132017            continue;
    2014 
    2015         QIManagerDialog *pLogViewerDialog = 0;
    2016         /* Create and Show VM Log Viewer: */
    2017         if (!m_logViewers[pItemLocal->machine().GetHardwareUUID().toString()])
    2018         {
    2019             UIVMLogViewerDialogFactory dialogFactory(actionPool(), pItemLocal->machine());
    2020             dialogFactory.prepare(pLogViewerDialog, this);
    2021             if (pLogViewerDialog)
    2022             {
    2023                 m_logViewers[pItemLocal->machine().GetHardwareUUID().toString()] = pLogViewerDialog;
    2024                 connect(pLogViewerDialog, &QIManagerDialog::sigClose,
    2025                         this, &UIVirtualBoxManager::sltCloseLogViewerWindow);
    2026             }
    2027         }
    2028         else
    2029         {
    2030             pLogViewerDialog = m_logViewers[pItemLocal->machine().GetHardwareUUID().toString()];
    2031         }
    2032         if (pLogViewerDialog)
    2033         {
    2034             /* Show instance: */
    2035             pLogViewerDialog->show();
    2036             pLogViewerDialog->setWindowState(pLogViewerDialog->windowState() & ~Qt::WindowMinimized);
    2037             pLogViewerDialog->activateWindow();
    2038         }
    2039     }
     2018        itemsToShowLogs << pItem;
     2019    }
     2020
     2021    if (itemsToShowLogs.isEmpty())
     2022        return;
     2023    if (!m_pLogViewerDialog)
     2024    {
     2025        UIVMLogViewerDialogFactory dialogFactory(actionPool(), CMachine());
     2026        dialogFactory.prepare(m_pLogViewerDialog, this);
     2027        if (m_pLogViewerDialog)
     2028            connect(m_pLogViewerDialog, &QIManagerDialog::sigClose,
     2029                    this, &UIVirtualBoxManager::sltCloseLogViewerWindow);
     2030    }
     2031    AssertPtrReturnVoid(m_pLogViewerDialog);
     2032    UIVMLogViewerDialog *pDialog = qobject_cast<UIVMLogViewerDialog*>(m_pLogViewerDialog);
     2033    if (pDialog)
     2034        pDialog->addSelectedVMListItems(itemsToShowLogs);
     2035    m_pLogViewerDialog->show();
     2036    m_pLogViewerDialog->setWindowState(m_pLogViewerDialog->windowState() & ~Qt::WindowMinimized);
     2037    m_pLogViewerDialog->activateWindow();
    20402038}
    20412039
    20422040void UIVirtualBoxManager::sltCloseLogViewerWindow()
    20432041{
    2044     /* If there is a proper sender: */
    2045     if (qobject_cast<QIManagerDialog*>(sender()))
    2046     {
    2047         /* Search for the sender of the signal within the m_logViewers map: */
    2048         QMap<QString, QIManagerDialog*>::iterator sendersIterator = m_logViewers.begin();
    2049         while (sendersIterator != m_logViewers.end() && sendersIterator.value() != sender())
    2050             ++sendersIterator;
    2051         /* Do nothing if we cannot find it with the map: */
    2052         if (sendersIterator == m_logViewers.end())
    2053             return;
    2054 
    2055         /* Check whether we have found the proper dialog: */
    2056         QIManagerDialog *pDialog = qobject_cast<QIManagerDialog*>(sendersIterator.value());
    2057         if (!pDialog)
    2058             return;
    2059 
    2060         /* First remove this log-viewer dialog from the map.
    2061          * This should be done before closing the dialog which will incur
    2062          * a second call to this function and result in double delete!!! */
    2063         m_logViewers.erase(sendersIterator);
    2064         UIVMLogViewerDialogFactory().cleanup(pDialog);
    2065     }
    2066     /* Otherwise: */
    2067     else
    2068     {
    2069         /* Just wipe out everything: */
    2070         foreach (const QString &strKey, m_logViewers.keys())
    2071         {
    2072             /* First remove each log-viewer dialog from the map.
    2073              * This should be done before closing the dialog which will incur
    2074              * a second call to this function and result in double delete!!! */
    2075             QIManagerDialog *pDialog = m_logViewers.value(strKey);
    2076             m_logViewers.remove(strKey);
    2077             UIVMLogViewerDialogFactory().cleanup(pDialog);
    2078         }
    2079     }
    2080 }
    2081 
     2042    if (!m_pLogViewerDialog)
     2043        return;
     2044
     2045    QIManagerDialog* pDialog = m_pLogViewerDialog;
     2046    m_pLogViewerDialog = 0;
     2047    pDialog->close();
     2048    UIVMLogViewerDialogFactory().cleanup(pDialog);
     2049}
    20822050
    20832051void UIVirtualBoxManager::sltPerformRefreshMachine()
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r89515 r89585  
    4444typedef QIWithRestorableGeometry<QMainWindow> QMainWindowWithRestorableGeometry;
    4545typedef QIWithRetranslateUI<QMainWindowWithRestorableGeometry> QMainWindowWithRestorableGeometryAndRetranslateUi;
    46 typedef QMap<QString, QIManagerDialog*> VMLogViewerMap;
    4746
    4847/** Singleton QMainWindow extension used as VirtualBox Manager instance. */
     
    453452    QMap<UIToolType, QIManagerDialog*>  m_managers;
    454453
    455     /** Holds a map of (machineUUID, UIVMLogViewerDialog). */
    456     VMLogViewerMap   m_logViewers;
     454    /** Holds the instance of UIVMLogViewerDialog. */
     455    QIManagerDialog   *m_pLogViewerDialog;
    457456
    458457    /** Holds the central-widget instance. */
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