1 | /* $Id: UIVMLogViewerDialog.cpp 81357 2019-10-18 14:13:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMLogViewerDialog class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /* Qt includes: */
|
---|
19 | #if defined(RT_OS_SOLARIS)
|
---|
20 | # include <QFontDatabase>
|
---|
21 | #endif
|
---|
22 | #include <QDialogButtonBox>
|
---|
23 | #include <QKeyEvent>
|
---|
24 | #include <QLabel>
|
---|
25 | #include <QPlainTextEdit>
|
---|
26 | #include <QPushButton>
|
---|
27 | #include <QScrollBar>
|
---|
28 | #include <QVBoxLayout>
|
---|
29 |
|
---|
30 | /* GUI includes: */
|
---|
31 | #include "UIDesktopWidgetWatchdog.h"
|
---|
32 | #include "UIExtraDataManager.h"
|
---|
33 | #include "UIIconPool.h"
|
---|
34 | #include "UIVMLogViewerDialog.h"
|
---|
35 | #include "UIVMLogViewerWidget.h"
|
---|
36 | #include "UICommon.h"
|
---|
37 | #ifdef VBOX_WS_MAC
|
---|
38 | # include "VBoxUtils-darwin.h"
|
---|
39 | #endif
|
---|
40 |
|
---|
41 |
|
---|
42 | /*********************************************************************************************************************************
|
---|
43 | * Class UIVMLogViewerDialogFactory implementation. *
|
---|
44 | *********************************************************************************************************************************/
|
---|
45 |
|
---|
46 | UIVMLogViewerDialogFactory::UIVMLogViewerDialogFactory(UIActionPool *pActionPool /* = 0 */,
|
---|
47 | const CMachine &comMachine /* = CMachine() */)
|
---|
48 | : m_pActionPool(pActionPool)
|
---|
49 | , m_comMachine(comMachine)
|
---|
50 | {
|
---|
51 | }
|
---|
52 |
|
---|
53 | void UIVMLogViewerDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
|
---|
54 | {
|
---|
55 | pDialog = new UIVMLogViewerDialog(pCenterWidget, m_pActionPool, m_comMachine);
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | /*********************************************************************************************************************************
|
---|
60 | * Class UIVMLogViewerDialog implementation. *
|
---|
61 | *********************************************************************************************************************************/
|
---|
62 |
|
---|
63 | UIVMLogViewerDialog::UIVMLogViewerDialog(QWidget *pCenterWidget, UIActionPool *pActionPool, const CMachine &comMachine)
|
---|
64 | : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
|
---|
65 | , m_pActionPool(pActionPool)
|
---|
66 | , m_comMachine(comMachine)
|
---|
67 | {
|
---|
68 | }
|
---|
69 |
|
---|
70 | void UIVMLogViewerDialog::retranslateUi()
|
---|
71 | {
|
---|
72 | /* Translate window title: */
|
---|
73 | if (!m_comMachine.isNull())
|
---|
74 | setWindowTitle(tr("%1 - Log Viewer").arg(m_comMachine.GetName()));
|
---|
75 | else
|
---|
76 | setWindowTitle(UIVMLogViewerWidget::tr("Log Viewer"));
|
---|
77 |
|
---|
78 | /* Translate buttons: */
|
---|
79 | button(ButtonType_Close)->setText(UIVMLogViewerWidget::tr("Close"));
|
---|
80 | }
|
---|
81 |
|
---|
82 | void UIVMLogViewerDialog::configure()
|
---|
83 | {
|
---|
84 | /* Apply window icons: */
|
---|
85 | setWindowIcon(UIIconPool::iconSetFull(":/vm_show_logs_32px.png", ":/vm_show_logs_16px.png"));
|
---|
86 | }
|
---|
87 |
|
---|
88 | void UIVMLogViewerDialog::configureCentralWidget()
|
---|
89 | {
|
---|
90 | /* Create widget: */
|
---|
91 | UIVMLogViewerWidget *pWidget = new UIVMLogViewerWidget(EmbedTo_Dialog, m_pActionPool, true /* show toolbar */, m_comMachine, this);
|
---|
92 | if (pWidget)
|
---|
93 | {
|
---|
94 | /* Configure widget: */
|
---|
95 | setWidget(pWidget);
|
---|
96 | setWidgetMenu(pWidget->menu());
|
---|
97 | #ifdef VBOX_WS_MAC
|
---|
98 | setWidgetToolbar(pWidget->toolbar());
|
---|
99 | #endif
|
---|
100 | connect(pWidget, &UIVMLogViewerWidget::sigSetCloseButtonShortCut,
|
---|
101 | this, &UIVMLogViewerDialog::sltSetCloseButtonShortCut);
|
---|
102 |
|
---|
103 | /* Add into layout: */
|
---|
104 | centralWidget()->layout()->addWidget(pWidget);
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | void UIVMLogViewerDialog::finalize()
|
---|
109 | {
|
---|
110 | /* Apply language settings: */
|
---|
111 | retranslateUi();
|
---|
112 | manageEscapeShortCut();
|
---|
113 | }
|
---|
114 |
|
---|
115 | void UIVMLogViewerDialog::loadSettings()
|
---|
116 | {
|
---|
117 | /* Invent default window geometry: */
|
---|
118 | const QRect availableGeo = gpDesktop->availableGeometry(this);
|
---|
119 | int iDefaultWidth = availableGeo.width() / 2;
|
---|
120 | int iDefaultHeight = availableGeo.height() * 3 / 4;
|
---|
121 | /* Try obtain the default width of the current logviewer: */
|
---|
122 | const UIVMLogViewerWidget *pWidget = qobject_cast<const UIVMLogViewerWidget*>(widget());
|
---|
123 | if (pWidget)
|
---|
124 | {
|
---|
125 | const int iWidth = pWidget->defaultLogPageWidth();
|
---|
126 | if (iWidth != 0)
|
---|
127 | iDefaultWidth = iWidth;
|
---|
128 | }
|
---|
129 | QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
|
---|
130 |
|
---|
131 | /* Load geometry from extradata: */
|
---|
132 | const QRect geo = gEDataManager->logWindowGeometry(this, centerWidget(), defaultGeo);
|
---|
133 | LogRel2(("GUI: UIVMLogViewerDialog: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
|
---|
134 | geo.x(), geo.y(), geo.width(), geo.height()));
|
---|
135 | restoreGeometry(geo);
|
---|
136 | }
|
---|
137 |
|
---|
138 | void UIVMLogViewerDialog::saveSettings() const
|
---|
139 | {
|
---|
140 | /* Save geometry to extradata: */
|
---|
141 | const QRect geo = currentGeometry();
|
---|
142 | LogRel2(("GUI: UIVMLogViewerDialog: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
|
---|
143 | geo.x(), geo.y(), geo.width(), geo.height()));
|
---|
144 | gEDataManager->setLogWindowGeometry(geo, isCurrentlyMaximized());
|
---|
145 | }
|
---|
146 |
|
---|
147 | bool UIVMLogViewerDialog::shouldBeMaximized() const
|
---|
148 | {
|
---|
149 | return gEDataManager->logWindowShouldBeMaximized();
|
---|
150 | }
|
---|
151 |
|
---|
152 | void UIVMLogViewerDialog::sltSetCloseButtonShortCut(QKeySequence shortcut)
|
---|
153 | {
|
---|
154 | if (button(ButtonType_Close))
|
---|
155 | button(ButtonType_Close)->setShortcut(shortcut);
|
---|
156 | }
|
---|
157 |
|
---|
158 | void UIVMLogViewerDialog::manageEscapeShortCut()
|
---|
159 | {
|
---|
160 | UIVMLogViewerWidget *pWidget = qobject_cast<UIVMLogViewerWidget*>(widget());
|
---|
161 | if (!pWidget)
|
---|
162 | return;
|
---|
163 | pWidget->manageEscapeShortCut();
|
---|
164 | }
|
---|