Index: /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIManagerDialog.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIManagerDialog.cpp	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIManagerDialog.cpp	(revision 70029)
@@ -175,4 +175,6 @@
 void QIManagerDialog::prepareMenuBar()
 {
+    if (!m_pWidgetMenu)
+        return;
     /* Add widget menu: */
     menuBar()->addMenu(m_pWidgetMenu);
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.cpp	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.cpp	(revision 70029)
@@ -33,87 +33,51 @@
 
 /* GUI includes: */
+# include "UIIconPool.h"
 # include "UIVMLogViewerDialog.h"
 # include "UIVMLogViewerWidget.h"
 
-/* COM includes: */
-# include "COMEnums.h"
-
 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
 
-/** Holds the VM Log-Viewer array. */
-VMLogViewerMap UIVMLogViewerDialog::m_viewers = VMLogViewerMap();
-
-
-UIVMLogViewerDialog::UIVMLogViewerDialog(QWidget *pParent, const CMachine &machine)
-    : QIWithRetranslateUI<QIDialog>(pParent)
-    , m_strMachineUUID(machine.GetHardwareUUID())
+UIVMLogViewerDialogFactory::UIVMLogViewerDialogFactory(const CMachine &machine)
+    :m_comMachine(machine)
 {
-    prepare(machine);
 }
 
-UIVMLogViewerDialog::~UIVMLogViewerDialog()
+void UIVMLogViewerDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
 {
-    cleanup();
+    pDialog = new UIVMLogViewerDialog(pCenterWidget, m_comMachine);
 }
 
-void UIVMLogViewerDialog::showLogViewerFor(QWidget* parent, const CMachine &machine)
+UIVMLogViewerDialog::UIVMLogViewerDialog(QWidget *pCenterWidget, const CMachine &machine)
+    : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
+    , m_comMachine(machine)
 {
-    if (m_viewers.contains(machine.GetHardwareUUID()))
-    {
-        showLogViewerDialog(m_viewers[machine.GetHardwareUUID()]);
-        return;
-    }
-    UIVMLogViewerDialog dialog(parent, machine);
-    dialog.exec();
 }
 
 void UIVMLogViewerDialog::retranslateUi()
 {
-    m_pCloseButton->setText(UIVMLogViewerWidget::tr("Close"));
+    button(ButtonType_Close)->setText(UIVMLogViewerWidget::tr("Close"));
 }
 
-void UIVMLogViewerDialog::prepare(const CMachine& machine)
+void UIVMLogViewerDialog::configureCentralWidget()
 {
-    setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
-    /* According to QDoc passing widget to layout's ctor also handles setLayout(..) call: */
-    m_pMainLayout = new QVBoxLayout(this);
-
-    UIVMLogViewerWidget *viewerWidget = new UIVMLogViewerWidget(this, machine);
-    m_pMainLayout->addWidget(viewerWidget);
-
-    m_pButtonBox = new QDialogButtonBox(this);
-    m_pCloseButton = m_pButtonBox->addButton("Close", QDialogButtonBox::RejectRole);
-    m_pMainLayout->addWidget(m_pButtonBox);
-    connect(m_pCloseButton, &QPushButton::clicked, this, &UIVMLogViewerDialog::close);
-
-    m_viewers[m_strMachineUUID] = this;
-
-    /* Load settings: */
-    loadSettings();
-
-    showLogViewerDialog(this);
+    /* Create widget: */
+    UIVMLogViewerWidget *pWidget = new UIVMLogViewerWidget(this, m_comMachine);
+    AssertPtrReturnVoid(pWidget);
+    {
+        /* Configure widget: */
+        setWidget(pWidget);
+        //setWidgetMenu(pWidget->menu());
+#ifdef VBOX_WS_MAC
+        //setWidgetToolbar(pWidget->toolbar());
+#endif
+        /* Add into layout: */
+        centralWidget()->layout()->addWidget(pWidget);
+    }
 }
 
-void UIVMLogViewerDialog::showLogViewerDialog(UIVMLogViewerDialog *logViewerDialog)
+void UIVMLogViewerDialog::configure()
 {
-    logViewerDialog->show();
-    logViewerDialog->raise();
-    logViewerDialog->setWindowState(logViewerDialog->windowState() & ~Qt::WindowMinimized);
-    logViewerDialog->activateWindow();
+    /* Apply window icons: */
+    setWindowIcon(UIIconPool::iconSetFull(":/diskimage_32px.png", ":/diskimage_16px.png"));
 }
-
-void UIVMLogViewerDialog::cleanup()
-{
-    saveSettings();
-    /* Remove log-viewer: */
-    if (!m_strMachineUUID.isNull())
-        m_viewers.remove(m_strMachineUUID);
-}
-
-void UIVMLogViewerDialog::loadSettings()
-{
-}
-
-void UIVMLogViewerDialog::saveSettings()
-{
-}
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.h	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.h	(revision 70029)
@@ -24,6 +24,10 @@
 
 /* GUI includes: */
-#include "QIDialog.h"
+#include "QIManagerDialog.h"
 #include "QIWithRetranslateUI.h"
+
+/* COM includes: */
+# include "COMEnums.h"
+#include "CMachine.h"
 
 /* Forward declarations: */
@@ -33,42 +37,37 @@
 class UIVMLogViewerDialog;
 
-/* Type definitions: */
-typedef QMap<QString, UIVMLogViewerDialog*> VMLogViewerMap;
+
+/** QIManagerDialogFactory  used as a factory for Virtual Media Manager dialog. */
+class UIVMLogViewerDialogFactory : public QIManagerDialogFactory
+{
+public:
+    UIVMLogViewerDialogFactory(const CMachine &machine);
+
+protected:
+    /** Creates derived @a pDialog instance.
+      * @param  pCenterWidget  Brings the widget to center wrt. pCenterWidget. */
+    virtual void create(QIManagerDialog *&pDialog, QWidget *pCenterWidget) /* override */;
+
+    CMachine m_comMachine;
+};
 
 /** A QIDialog to display machine logs. */
-class UIVMLogViewerDialog : public QIWithRetranslateUI<QIDialog>
+class UIVMLogViewerDialog : public QIWithRetranslateUI<QIManagerDialog>
 {
     Q_OBJECT;
 
 public:
-    UIVMLogViewerDialog(QWidget *pParent, const CMachine &machine);
-    ~UIVMLogViewerDialog();
+    UIVMLogViewerDialog(QWidget *pCenterWidget, const CMachine &machine);
 
-    /** Static method to create/show VM Log Viewer by passing @a pParent to QWidget base-class constructor.
-     * @param  machine  Specifies the machine for which VM Log-Viewer is requested. */
-    static void showLogViewerFor(QWidget* parent, const CMachine &machine);
+protected:
+    virtual void configure() /* override */;
+    virtual void configureCentralWidget() /* override */;
 
 private:
+    void retranslateUi();
 
-    static void showLogViewerDialog(UIVMLogViewerDialog *logViewerDialog);
-    void retranslateUi();
-    void prepare(const CMachine& machine);
-    void cleanup();
-
-    /** Load settings helper. */
-    void loadSettings();
-    /** Save settings helper. */
-    void saveSettings();
-
-    QPushButton      *m_pCloseButton;
-    QDialogButtonBox *m_pButtonBox;
-    QVBoxLayout      *m_pMainLayout;
-
-    /** Holds the UUID of the machine instance. */
-    QString m_strMachineUUID;
-
-    /** Holds the list of all VM Log Viewers. */
-    static VMLogViewerMap m_viewers;
+    CMachine m_comMachine;
 };
 
 #endif /* !___UIVMLogViewerDialog_h___ */
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.cpp	(revision 70029)
@@ -51,5 +51,5 @@
     : QIWithRetranslateUI<QWidget>(pParent)
     , m_fIsPolished(false)
-    , m_machine(machine)
+    , m_comMachine(machine)
     , m_pButtonBox(0)
     , m_pMainLayout(0)
@@ -119,5 +119,5 @@
     {
         /* Query the log file name for index i: */
-        QString strFileName = m_machine.QueryLogFilename(i);
+        QString strFileName = m_comMachine.QueryLogFilename(i);
         if (!strFileName.isEmpty())
         {
@@ -127,5 +127,5 @@
             while (true)
             {
-                QVector<BYTE> data = m_machine.ReadLog(i, uOffset, _1M);
+                QVector<BYTE> data = m_comMachine.ReadLog(i, uOffset, _1M);
                 if (data.size() == 0)
                     break;
@@ -160,5 +160,5 @@
                               "<b>Refresh</b> button to rescan the log folder "
                               "<nobr><b>%1</b></nobr>.</p>")
-                              .arg(m_machine.GetLogFolder()));
+                              .arg(m_comMachine.GetLogFolder()));
         /* We don't want it to remain white: */
         QPalette pal = pDummyLog->palette();
@@ -190,5 +190,5 @@
     const QDateTime dtInfo = fileInfo.lastModified();
     const QString strDtString = dtInfo.toString("yyyy-MM-dd-hh-mm-ss");
-    const QString strDefaultFileName = QString("%1-%2.log").arg(m_machine.GetName()).arg(strDtString);
+    const QString strDefaultFileName = QString("%1-%2.log").arg(m_comMachine.GetName()).arg(strDtString);
     const QString strDefaultFullName = QDir::toNativeSeparators(QDir::home().absolutePath() + "/" + strDefaultFileName);
     /* Show "save as" dialog: */
@@ -207,5 +207,5 @@
             QFile::remove(strNewFileName);
         /* Copy log into the file: */
-        QFile::copy(m_machine.QueryLogFilename(m_pViewerContainer->currentIndex()), strNewFileName);
+        QFile::copy(m_comMachine.QueryLogFilename(m_pViewerContainer->currentIndex()), strNewFileName);
     }
 }
@@ -243,5 +243,4 @@
 {
     /* Create VM Log-Viewer container: */
-    //m_pViewerContainer = new QITabWidget(centralWidget());
     m_pViewerContainer = new QITabWidget(this);
     AssertPtrReturnVoid(m_pViewerContainer);
@@ -256,5 +255,5 @@
     {
         /* Configure VM Log-Viewer search-panel: */
-        //centralWidget()->installEventFilter(m_pSearchPanel);
+        installEventFilter(m_pSearchPanel);
         m_pSearchPanel->hide();
         /* Add VM Log-Viewer search-panel to main-layout: */
@@ -267,5 +266,5 @@
     {
         /* Configure VM Log-Viewer filter-panel: */
-        //centralWidget()->installEventFilter(m_pFilterPanel);
+        installEventFilter(m_pFilterPanel);
         m_pFilterPanel->hide();
         /* Add VM Log-Viewer filter-panel to main-layout: */
@@ -305,6 +304,6 @@
 {
     /* Setup a dialog caption: */
-    if (!m_machine.isNull())
-        setWindowTitle(tr("%1 - VirtualBox Log Viewer").arg(m_machine.GetName()));
+    if (!m_comMachine.isNull())
+        setWindowTitle(tr("%1 - VirtualBox Log Viewer").arg(m_comMachine.GetName()));
 
     /* Translate other tags: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerWidget.h	(revision 70029)
@@ -115,5 +115,5 @@
 
     /** Holds the machine instance. */
-    CMachine m_machine;
+    CMachine m_comMachine;
 
     /** Holds container for log-pages. */
@@ -149,2 +149,3 @@
 
 #endif /* !___UIVMLogViewerWidget_h___ */
+
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 70029)
@@ -844,4 +844,5 @@
     , m_pHostLedsState(NULL)
     , m_fIsHidLedsSyncEnabled(false)
+    , m_pLogViewerDialog(0)
 {
 }
@@ -2382,6 +2383,37 @@
 void UIMachineLogic::sltShowLogDialog()
 {
-    /* Show VM Log Viewer: */
-    UIVMLogViewerDialog::showLogViewerFor(activeMachineWindow(), machine());
+    if (machine().isNull() || !activeMachineWindow())
+        return;
+
+    /* Create a logviewer only if we don't have one already */
+    if (m_pLogViewerDialog)
+        return;
+
+    QIManagerDialog *pLogViewerDialog;
+    UIVMLogViewerDialogFactory dialogFactory(machine());
+    dialogFactory.prepare(pLogViewerDialog, activeMachineWindow());
+    if (pLogViewerDialog)
+    {
+        m_pLogViewerDialog = pLogViewerDialog;
+
+        /* Show instance: */
+        pLogViewerDialog->show();
+        pLogViewerDialog->setWindowState(pLogViewerDialog->windowState() & ~Qt::WindowMinimized);
+        pLogViewerDialog->activateWindow();
+        connect(pLogViewerDialog, &QIManagerDialog::sigClose,
+                this, &UIMachineLogic::sltCloseLogViewerWindow);
+    }
+}
+
+void UIMachineLogic::sltCloseLogViewerWindow()
+{
+    QIManagerDialog* pDialog = qobject_cast<QIManagerDialog*>(sender());
+    if (m_pLogViewerDialog != pDialog || !pDialog)
+        return;
+
+    /* Set the m_pLogViewerDialog to NULL before closing the dialog. or we will have redundant deletes*/
+    m_pLogViewerDialog = 0;
+    pDialog->close();
+    UIVMLogViewerDialogFactory(CMachine()).cleanup(pDialog);
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 70029)
@@ -29,4 +29,5 @@
 class QAction;
 class QActionGroup;
+class QIManagerDialog;
 class UISession;
 class UIActionPool;
@@ -194,4 +195,7 @@
     /** Handles host-screen available-area change. */
     virtual void sltHostScreenAvailableAreaChange();
+
+    /** Handles close signal from the log viewer dialog. */
+    void sltCloseLogViewerWindow();
 
 protected:
@@ -419,4 +423,7 @@
     bool m_fIsHidLedsSyncEnabled;
 
+    /** Holds the log viewer dialog instance. */
+    QIManagerDialog *m_pLogViewerDialog;
+
     /* Friend classes: */
     friend class UIMachineWindow;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp	(revision 70029)
@@ -1025,6 +1025,45 @@
 
         /* Show VM Log Viewer: */
-        UIVMLogViewerDialog::showLogViewerFor(this, pItem->machine());
-    }
+        if (!m_logViewers[pItem->machine().GetHardwareUUID()])
+        {
+            QIManagerDialog *pLogViewerDialog;
+            UIVMLogViewerDialogFactory dialogFactory(pItem->machine());
+            dialogFactory.prepare(pLogViewerDialog, this);
+            if (pLogViewerDialog)
+            {
+                m_logViewers[pItem->machine().GetHardwareUUID()] = pLogViewerDialog;
+
+                /* Show instance: */
+                pLogViewerDialog->show();
+                pLogViewerDialog->setWindowState(pLogViewerDialog->windowState() & ~Qt::WindowMinimized);
+                pLogViewerDialog->activateWindow();
+                connect(pLogViewerDialog, &QIManagerDialog::sigClose,
+                        this, &UISelectorWindow::sltCloseLogViewerWindow);
+            }
+        }
+    }
+}
+
+void UISelectorWindow::sltCloseLogViewerWindow()
+{
+    QMap<QString, QIManagerDialog*>::iterator sendersIterator = m_logViewers.begin();
+
+    /* Search for the sender of the signal within the m_logViewers map: */
+    while (sendersIterator != m_logViewers.end() && sendersIterator.value() != sender())
+        ++sendersIterator;
+    /* Do nothing if we cannot find it with the map: */
+    if (sendersIterator == m_logViewers.end())
+        return;
+
+    QIManagerDialog* pDialog = qobject_cast<QIManagerDialog*>(sendersIterator.value());
+    if (!pDialog)
+        return;
+    
+    /* First remove this log viewer dialog from the map. This should be
+       done before closing the dialog which will incur a second call to
+       this function and result in double delete!!!: */
+    m_logViewers.erase(sendersIterator);
+    pDialog->close();
+    UIVMLogViewerDialogFactory(CMachine()).cleanup(pDialog);
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h	(revision 70028)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h	(revision 70029)
@@ -42,4 +42,6 @@
 class UIVMItem;
 
+/* Type definitions: */
+typedef QMap<QString, QIManagerDialog*> VMLogViewerMap;
 
 /** Singleton QIMainWindow extension
@@ -123,4 +125,6 @@
         /** Handles call to close Host Network Manager window. */
         void sltCloseHostNetworkManagerWindow();
+        /** Handles call to close a Machine LogViewer window. */
+        void sltCloseLogViewerWindow();
         /** Handles call to open Import Appliance wizard.
           * @param strFileName can bring the name of file to import appliance from. */
@@ -375,4 +379,6 @@
     /** Holds the Host Network Manager window instance. */
     QIManagerDialog *m_pManagerHostNetwork;
+    /** Holds a map of (machineUUID, UIVMLogViewerDialog). */
+    VMLogViewerMap m_logViewers;
 };
 
