VirtualBox

Ignore:
Timestamp:
Dec 8, 2017 1:52:37 PM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:9072 Migrating UIVMLogViewerDialog to QIManagerDialog

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIManagerDialog.cpp

    r69726 r70029  
    175175void QIManagerDialog::prepareMenuBar()
    176176{
     177    if (!m_pWidgetMenu)
     178        return;
    177179    /* Add widget menu: */
    178180    menuBar()->addMenu(m_pWidgetMenu);
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.cpp

    r70027 r70029  
    3333
    3434/* GUI includes: */
     35# include "UIIconPool.h"
    3536# include "UIVMLogViewerDialog.h"
    3637# include "UIVMLogViewerWidget.h"
    3738
    38 /* COM includes: */
    39 # include "COMEnums.h"
    40 
    4139#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4240
    43 /** Holds the VM Log-Viewer array. */
    44 VMLogViewerMap UIVMLogViewerDialog::m_viewers = VMLogViewerMap();
    45 
    46 
    47 UIVMLogViewerDialog::UIVMLogViewerDialog(QWidget *pParent, const CMachine &machine)
    48     : QIWithRetranslateUI<QIDialog>(pParent)
    49     , m_strMachineUUID(machine.GetHardwareUUID())
     41UIVMLogViewerDialogFactory::UIVMLogViewerDialogFactory(const CMachine &machine)
     42    :m_comMachine(machine)
    5043{
    51     prepare(machine);
    5244}
    5345
    54 UIVMLogViewerDialog::~UIVMLogViewerDialog()
     46void UIVMLogViewerDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
    5547{
    56     cleanup();
     48    pDialog = new UIVMLogViewerDialog(pCenterWidget, m_comMachine);
    5749}
    5850
    59 void UIVMLogViewerDialog::showLogViewerFor(QWidget* parent, const CMachine &machine)
     51UIVMLogViewerDialog::UIVMLogViewerDialog(QWidget *pCenterWidget, const CMachine &machine)
     52    : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
     53    , m_comMachine(machine)
    6054{
    61     if (m_viewers.contains(machine.GetHardwareUUID()))
    62     {
    63         showLogViewerDialog(m_viewers[machine.GetHardwareUUID()]);
    64         return;
    65     }
    66     UIVMLogViewerDialog dialog(parent, machine);
    67     dialog.exec();
    6855}
    6956
    7057void UIVMLogViewerDialog::retranslateUi()
    7158{
    72     m_pCloseButton->setText(UIVMLogViewerWidget::tr("Close"));
     59    button(ButtonType_Close)->setText(UIVMLogViewerWidget::tr("Close"));
    7360}
    7461
    75 void UIVMLogViewerDialog::prepare(const CMachine& machine)
     62void UIVMLogViewerDialog::configureCentralWidget()
    7663{
    77     setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
    78     /* According to QDoc passing widget to layout's ctor also handles setLayout(..) call: */
    79     m_pMainLayout = new QVBoxLayout(this);
    80 
    81     UIVMLogViewerWidget *viewerWidget = new UIVMLogViewerWidget(this, machine);
    82     m_pMainLayout->addWidget(viewerWidget);
    83 
    84     m_pButtonBox = new QDialogButtonBox(this);
    85     m_pCloseButton = m_pButtonBox->addButton("Close", QDialogButtonBox::RejectRole);
    86     m_pMainLayout->addWidget(m_pButtonBox);
    87     connect(m_pCloseButton, &QPushButton::clicked, this, &UIVMLogViewerDialog::close);
    88 
    89     m_viewers[m_strMachineUUID] = this;
    90 
    91     /* Load settings: */
    92     loadSettings();
    93 
    94     showLogViewerDialog(this);
     64    /* Create widget: */
     65    UIVMLogViewerWidget *pWidget = new UIVMLogViewerWidget(this, m_comMachine);
     66    AssertPtrReturnVoid(pWidget);
     67    {
     68        /* Configure widget: */
     69        setWidget(pWidget);
     70        //setWidgetMenu(pWidget->menu());
     71#ifdef VBOX_WS_MAC
     72        //setWidgetToolbar(pWidget->toolbar());
     73#endif
     74        /* Add into layout: */
     75        centralWidget()->layout()->addWidget(pWidget);
     76    }
    9577}
    9678
    97 void UIVMLogViewerDialog::showLogViewerDialog(UIVMLogViewerDialog *logViewerDialog)
     79void UIVMLogViewerDialog::configure()
    9880{
    99     logViewerDialog->show();
    100     logViewerDialog->raise();
    101     logViewerDialog->setWindowState(logViewerDialog->windowState() & ~Qt::WindowMinimized);
    102     logViewerDialog->activateWindow();
     81    /* Apply window icons: */
     82    setWindowIcon(UIIconPool::iconSetFull(":/diskimage_32px.png", ":/diskimage_16px.png"));
    10383}
    104 
    105 void UIVMLogViewerDialog::cleanup()
    106 {
    107     saveSettings();
    108     /* Remove log-viewer: */
    109     if (!m_strMachineUUID.isNull())
    110         m_viewers.remove(m_strMachineUUID);
    111 }
    112 
    113 void UIVMLogViewerDialog::loadSettings()
    114 {
    115 }
    116 
    117 void UIVMLogViewerDialog::saveSettings()
    118 {
    119 }
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.h

    r70027 r70029  
    2424
    2525/* GUI includes: */
    26 #include "QIDialog.h"
     26#include "QIManagerDialog.h"
    2727#include "QIWithRetranslateUI.h"
     28
     29/* COM includes: */
     30# include "COMEnums.h"
     31#include "CMachine.h"
    2832
    2933/* Forward declarations: */
     
    3337class UIVMLogViewerDialog;
    3438
    35 /* Type definitions: */
    36 typedef QMap<QString, UIVMLogViewerDialog*> VMLogViewerMap;
     39
     40/** QIManagerDialogFactory  used as a factory for Virtual Media Manager dialog. */
     41class UIVMLogViewerDialogFactory : public QIManagerDialogFactory
     42{
     43public:
     44    UIVMLogViewerDialogFactory(const CMachine &machine);
     45
     46protected:
     47    /** Creates derived @a pDialog instance.
     48      * @param  pCenterWidget  Brings the widget to center wrt. pCenterWidget. */
     49    virtual void create(QIManagerDialog *&pDialog, QWidget *pCenterWidget) /* override */;
     50
     51    CMachine m_comMachine;
     52};
    3753
    3854/** A QIDialog to display machine logs. */
    39 class UIVMLogViewerDialog : public QIWithRetranslateUI<QIDialog>
     55class UIVMLogViewerDialog : public QIWithRetranslateUI<QIManagerDialog>
    4056{
    4157    Q_OBJECT;
    4258
    4359public:
    44     UIVMLogViewerDialog(QWidget *pParent, const CMachine &machine);
    45     ~UIVMLogViewerDialog();
     60    UIVMLogViewerDialog(QWidget *pCenterWidget, const CMachine &machine);
    4661
    47     /** Static method to create/show VM Log Viewer by passing @a pParent to QWidget base-class constructor.
    48      * @param  machine  Specifies the machine for which VM Log-Viewer is requested. */
    49     static void showLogViewerFor(QWidget* parent, const CMachine &machine);
     62protected:
     63    virtual void configure() /* override */;
     64    virtual void configureCentralWidget() /* override */;
    5065
    5166private:
     67    void retranslateUi();
    5268
    53     static void showLogViewerDialog(UIVMLogViewerDialog *logViewerDialog);
    54     void retranslateUi();
    55     void prepare(const CMachine& machine);
    56     void cleanup();
    57 
    58     /** Load settings helper. */
    59     void loadSettings();
    60     /** Save settings helper. */
    61     void saveSettings();
    62 
    63     QPushButton      *m_pCloseButton;
    64     QDialogButtonBox *m_pButtonBox;
    65     QVBoxLayout      *m_pMainLayout;
    66 
    67     /** Holds the UUID of the machine instance. */
    68     QString m_strMachineUUID;
    69 
    70     /** Holds the list of all VM Log Viewers. */
    71     static VMLogViewerMap m_viewers;
     69    CMachine m_comMachine;
    7270};
    7371
    7472#endif /* !___UIVMLogViewerDialog_h___ */
     73
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp

    r70027 r70029  
    5151    : QIWithRetranslateUI<QWidget>(pParent)
    5252    , m_fIsPolished(false)
    53     , m_machine(machine)
     53    , m_comMachine(machine)
    5454    , m_pButtonBox(0)
    5555    , m_pMainLayout(0)
     
    119119    {
    120120        /* Query the log file name for index i: */
    121         QString strFileName = m_machine.QueryLogFilename(i);
     121        QString strFileName = m_comMachine.QueryLogFilename(i);
    122122        if (!strFileName.isEmpty())
    123123        {
     
    127127            while (true)
    128128            {
    129                 QVector<BYTE> data = m_machine.ReadLog(i, uOffset, _1M);
     129                QVector<BYTE> data = m_comMachine.ReadLog(i, uOffset, _1M);
    130130                if (data.size() == 0)
    131131                    break;
     
    160160                              "<b>Refresh</b> button to rescan the log folder "
    161161                              "<nobr><b>%1</b></nobr>.</p>")
    162                               .arg(m_machine.GetLogFolder()));
     162                              .arg(m_comMachine.GetLogFolder()));
    163163        /* We don't want it to remain white: */
    164164        QPalette pal = pDummyLog->palette();
     
    190190    const QDateTime dtInfo = fileInfo.lastModified();
    191191    const QString strDtString = dtInfo.toString("yyyy-MM-dd-hh-mm-ss");
    192     const QString strDefaultFileName = QString("%1-%2.log").arg(m_machine.GetName()).arg(strDtString);
     192    const QString strDefaultFileName = QString("%1-%2.log").arg(m_comMachine.GetName()).arg(strDtString);
    193193    const QString strDefaultFullName = QDir::toNativeSeparators(QDir::home().absolutePath() + "/" + strDefaultFileName);
    194194    /* Show "save as" dialog: */
     
    207207            QFile::remove(strNewFileName);
    208208        /* Copy log into the file: */
    209         QFile::copy(m_machine.QueryLogFilename(m_pViewerContainer->currentIndex()), strNewFileName);
     209        QFile::copy(m_comMachine.QueryLogFilename(m_pViewerContainer->currentIndex()), strNewFileName);
    210210    }
    211211}
     
    243243{
    244244    /* Create VM Log-Viewer container: */
    245     //m_pViewerContainer = new QITabWidget(centralWidget());
    246245    m_pViewerContainer = new QITabWidget(this);
    247246    AssertPtrReturnVoid(m_pViewerContainer);
     
    256255    {
    257256        /* Configure VM Log-Viewer search-panel: */
    258         //centralWidget()->installEventFilter(m_pSearchPanel);
     257        installEventFilter(m_pSearchPanel);
    259258        m_pSearchPanel->hide();
    260259        /* Add VM Log-Viewer search-panel to main-layout: */
     
    267266    {
    268267        /* Configure VM Log-Viewer filter-panel: */
    269         //centralWidget()->installEventFilter(m_pFilterPanel);
     268        installEventFilter(m_pFilterPanel);
    270269        m_pFilterPanel->hide();
    271270        /* Add VM Log-Viewer filter-panel to main-layout: */
     
    305304{
    306305    /* Setup a dialog caption: */
    307     if (!m_machine.isNull())
    308         setWindowTitle(tr("%1 - VirtualBox Log Viewer").arg(m_machine.GetName()));
     306    if (!m_comMachine.isNull())
     307        setWindowTitle(tr("%1 - VirtualBox Log Viewer").arg(m_comMachine.GetName()));
    309308
    310309    /* Translate other tags: */
  • trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h

    r70027 r70029  
    115115
    116116    /** Holds the machine instance. */
    117     CMachine m_machine;
     117    CMachine m_comMachine;
    118118
    119119    /** Holds container for log-pages. */
     
    149149
    150150#endif /* !___UIVMLogViewerWidget_h___ */
     151
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r69958 r70029  
    844844    , m_pHostLedsState(NULL)
    845845    , m_fIsHidLedsSyncEnabled(false)
     846    , m_pLogViewerDialog(0)
    846847{
    847848}
     
    23822383void UIMachineLogic::sltShowLogDialog()
    23832384{
    2384     /* Show VM Log Viewer: */
    2385     UIVMLogViewerDialog::showLogViewerFor(activeMachineWindow(), machine());
     2385    if (machine().isNull() || !activeMachineWindow())
     2386        return;
     2387
     2388    /* Create a logviewer only if we don't have one already */
     2389    if (m_pLogViewerDialog)
     2390        return;
     2391
     2392    QIManagerDialog *pLogViewerDialog;
     2393    UIVMLogViewerDialogFactory dialogFactory(machine());
     2394    dialogFactory.prepare(pLogViewerDialog, activeMachineWindow());
     2395    if (pLogViewerDialog)
     2396    {
     2397        m_pLogViewerDialog = pLogViewerDialog;
     2398
     2399        /* Show instance: */
     2400        pLogViewerDialog->show();
     2401        pLogViewerDialog->setWindowState(pLogViewerDialog->windowState() & ~Qt::WindowMinimized);
     2402        pLogViewerDialog->activateWindow();
     2403        connect(pLogViewerDialog, &QIManagerDialog::sigClose,
     2404                this, &UIMachineLogic::sltCloseLogViewerWindow);
     2405    }
     2406}
     2407
     2408void UIMachineLogic::sltCloseLogViewerWindow()
     2409{
     2410    QIManagerDialog* pDialog = qobject_cast<QIManagerDialog*>(sender());
     2411    if (m_pLogViewerDialog != pDialog || !pDialog)
     2412        return;
     2413
     2414    /* Set the m_pLogViewerDialog to NULL before closing the dialog. or we will have redundant deletes*/
     2415    m_pLogViewerDialog = 0;
     2416    pDialog->close();
     2417    UIVMLogViewerDialogFactory(CMachine()).cleanup(pDialog);
    23862418}
    23872419
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r69958 r70029  
    2929class QAction;
    3030class QActionGroup;
     31class QIManagerDialog;
    3132class UISession;
    3233class UIActionPool;
     
    194195    /** Handles host-screen available-area change. */
    195196    virtual void sltHostScreenAvailableAreaChange();
     197
     198    /** Handles close signal from the log viewer dialog. */
     199    void sltCloseLogViewerWindow();
    196200
    197201protected:
     
    419423    bool m_fIsHidLedsSyncEnabled;
    420424
     425    /** Holds the log viewer dialog instance. */
     426    QIManagerDialog *m_pLogViewerDialog;
     427
    421428    /* Friend classes: */
    422429    friend class UIMachineWindow;
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp

    r70024 r70029  
    10251025
    10261026        /* Show VM Log Viewer: */
    1027         UIVMLogViewerDialog::showLogViewerFor(this, pItem->machine());
    1028     }
     1027        if (!m_logViewers[pItem->machine().GetHardwareUUID()])
     1028        {
     1029            QIManagerDialog *pLogViewerDialog;
     1030            UIVMLogViewerDialogFactory dialogFactory(pItem->machine());
     1031            dialogFactory.prepare(pLogViewerDialog, this);
     1032            if (pLogViewerDialog)
     1033            {
     1034                m_logViewers[pItem->machine().GetHardwareUUID()] = pLogViewerDialog;
     1035
     1036                /* Show instance: */
     1037                pLogViewerDialog->show();
     1038                pLogViewerDialog->setWindowState(pLogViewerDialog->windowState() & ~Qt::WindowMinimized);
     1039                pLogViewerDialog->activateWindow();
     1040                connect(pLogViewerDialog, &QIManagerDialog::sigClose,
     1041                        this, &UISelectorWindow::sltCloseLogViewerWindow);
     1042            }
     1043        }
     1044    }
     1045}
     1046
     1047void UISelectorWindow::sltCloseLogViewerWindow()
     1048{
     1049    QMap<QString, QIManagerDialog*>::iterator sendersIterator = m_logViewers.begin();
     1050
     1051    /* Search for the sender of the signal within the m_logViewers map: */
     1052    while (sendersIterator != m_logViewers.end() && sendersIterator.value() != sender())
     1053        ++sendersIterator;
     1054    /* Do nothing if we cannot find it with the map: */
     1055    if (sendersIterator == m_logViewers.end())
     1056        return;
     1057
     1058    QIManagerDialog* pDialog = qobject_cast<QIManagerDialog*>(sendersIterator.value());
     1059    if (!pDialog)
     1060        return;
     1061   
     1062    /* First remove this log viewer dialog from the map. This should be
     1063       done before closing the dialog which will incur a second call to
     1064       this function and result in double delete!!!: */
     1065    m_logViewers.erase(sendersIterator);
     1066    pDialog->close();
     1067    UIVMLogViewerDialogFactory(CMachine()).cleanup(pDialog);
    10291068}
    10301069
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h

    r68392 r70029  
    4242class UIVMItem;
    4343
     44/* Type definitions: */
     45typedef QMap<QString, QIManagerDialog*> VMLogViewerMap;
    4446
    4547/** Singleton QIMainWindow extension
     
    123125        /** Handles call to close Host Network Manager window. */
    124126        void sltCloseHostNetworkManagerWindow();
     127        /** Handles call to close a Machine LogViewer window. */
     128        void sltCloseLogViewerWindow();
    125129        /** Handles call to open Import Appliance wizard.
    126130          * @param strFileName can bring the name of file to import appliance from. */
     
    375379    /** Holds the Host Network Manager window instance. */
    376380    QIManagerDialog *m_pManagerHostNetwork;
     381    /** Holds a map of (machineUUID, UIVMLogViewerDialog). */
     382    VMLogViewerMap m_logViewers;
    377383};
    378384
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