1 | /* $Id: UIVMLogViewerDialog.cpp 101027 2023-09-06 11:21:36Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIVMLogViewerDialog class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 | /* Qt includes: */
|
---|
29 | #if defined(RT_OS_SOLARIS)
|
---|
30 | # include <QFontDatabase>
|
---|
31 | #endif
|
---|
32 | #include <QPushButton>
|
---|
33 | #include <QVBoxLayout>
|
---|
34 |
|
---|
35 | /* GUI includes: */
|
---|
36 | #include "UIDesktopWidgetWatchdog.h"
|
---|
37 | #include "UIExtraDataManager.h"
|
---|
38 | #include "UIIconPool.h"
|
---|
39 | #include "UIVMLogViewerDialog.h"
|
---|
40 | #include "UIVMLogViewerWidget.h"
|
---|
41 | #include "UICommon.h"
|
---|
42 | #ifdef VBOX_WS_MAC
|
---|
43 | # include "VBoxUtils-darwin.h"
|
---|
44 | #endif
|
---|
45 |
|
---|
46 |
|
---|
47 | /*********************************************************************************************************************************
|
---|
48 | * Class UIVMLogViewerDialogFactory implementation. *
|
---|
49 | *********************************************************************************************************************************/
|
---|
50 |
|
---|
51 | UIVMLogViewerDialogFactory::UIVMLogViewerDialogFactory(UIActionPool *pActionPool /* = 0 */,
|
---|
52 | const QUuid &uMachineId /* = QUuid()*/,
|
---|
53 | const QString &strMachineName /* = QString() */)
|
---|
54 | : m_pActionPool(pActionPool)
|
---|
55 | , m_uMachineId(uMachineId)
|
---|
56 | , m_strMachineName(strMachineName)
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | void UIVMLogViewerDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
|
---|
61 | {
|
---|
62 | pDialog = new UIVMLogViewerDialog(pCenterWidget, m_pActionPool, m_uMachineId, m_strMachineName);
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | /*********************************************************************************************************************************
|
---|
67 | * Class UIVMLogViewerDialog implementation. *
|
---|
68 | *********************************************************************************************************************************/
|
---|
69 |
|
---|
70 | UIVMLogViewerDialog::UIVMLogViewerDialog(QWidget *pCenterWidget, UIActionPool *pActionPool,
|
---|
71 | const QUuid &uMachineId /* = QUuid()*/,
|
---|
72 | const QString &strMachineName /* = QString() */)
|
---|
73 | : QIWithRetranslateUI<QIManagerDialog>(pCenterWidget)
|
---|
74 | , m_pActionPool(pActionPool)
|
---|
75 | , m_uMachineId(uMachineId)
|
---|
76 | , m_iGeometrySaveTimerId(-1)
|
---|
77 | , m_strMachineName(strMachineName)
|
---|
78 | {
|
---|
79 | }
|
---|
80 |
|
---|
81 | UIVMLogViewerDialog::~UIVMLogViewerDialog()
|
---|
82 | {
|
---|
83 | }
|
---|
84 |
|
---|
85 | void UIVMLogViewerDialog::setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items)
|
---|
86 | {
|
---|
87 | Q_UNUSED(items);
|
---|
88 | UIVMLogViewerWidget *pLogViewerWidget = qobject_cast<UIVMLogViewerWidget*>(widget());
|
---|
89 | if (pLogViewerWidget)
|
---|
90 | pLogViewerWidget->setSelectedVMListItems(items);
|
---|
91 | }
|
---|
92 |
|
---|
93 | void UIVMLogViewerDialog::addSelectedVMListItems(const QList<UIVirtualMachineItem*> &items)
|
---|
94 | {
|
---|
95 | Q_UNUSED(items);
|
---|
96 | UIVMLogViewerWidget *pLogViewerWidget = qobject_cast<UIVMLogViewerWidget*>(widget());
|
---|
97 | if (pLogViewerWidget)
|
---|
98 | pLogViewerWidget->addSelectedVMListItems(items);
|
---|
99 | }
|
---|
100 |
|
---|
101 | void UIVMLogViewerDialog::retranslateUi()
|
---|
102 | {
|
---|
103 | /* Translate window title: */
|
---|
104 | if (!m_strMachineName.isEmpty())
|
---|
105 | setWindowTitle(UIVMLogViewerWidget::tr("%1 - Log Viewer").arg(m_strMachineName));
|
---|
106 | else
|
---|
107 | setWindowTitle(UIVMLogViewerWidget::tr("Log Viewer"));
|
---|
108 |
|
---|
109 | /* Translate buttons: */
|
---|
110 | button(ButtonType_Close)->setText(UIVMLogViewerWidget::tr("Close"));
|
---|
111 | button(ButtonType_Help)->setText(UIVMLogViewerWidget::tr("Help"));
|
---|
112 | button(ButtonType_Close)->setStatusTip(UIVMLogViewerWidget::tr("Close dialog"));
|
---|
113 | button(ButtonType_Help)->setStatusTip(UIVMLogViewerWidget::tr("Show dialog help"));
|
---|
114 | button(ButtonType_Close)->setShortcut(Qt::Key_Escape);
|
---|
115 | button(ButtonType_Help)->setShortcut(QKeySequence::HelpContents);
|
---|
116 | button(ButtonType_Close)->setToolTip(UIVMLogViewerWidget::tr("Close Window (%1)").arg(button(ButtonType_Close)->shortcut().toString()));
|
---|
117 | button(ButtonType_Help)->setToolTip(UIVMLogViewerWidget::tr("Show Help (%1)").arg(button(ButtonType_Help)->shortcut().toString()));
|
---|
118 | }
|
---|
119 |
|
---|
120 | bool UIVMLogViewerDialog::event(QEvent *pEvent)
|
---|
121 | {
|
---|
122 | switch (pEvent->type())
|
---|
123 | {
|
---|
124 | case QEvent::Resize:
|
---|
125 | case QEvent::Move:
|
---|
126 | {
|
---|
127 | if (m_iGeometrySaveTimerId != -1)
|
---|
128 | killTimer(m_iGeometrySaveTimerId);
|
---|
129 | m_iGeometrySaveTimerId = startTimer(300);
|
---|
130 | break;
|
---|
131 | }
|
---|
132 | case QEvent::Timer:
|
---|
133 | {
|
---|
134 | QTimerEvent *pTimerEvent = static_cast<QTimerEvent*>(pEvent);
|
---|
135 | if (pTimerEvent->timerId() == m_iGeometrySaveTimerId)
|
---|
136 | {
|
---|
137 | killTimer(m_iGeometrySaveTimerId);
|
---|
138 | m_iGeometrySaveTimerId = -1;
|
---|
139 | saveDialogGeometry();
|
---|
140 | }
|
---|
141 | break;
|
---|
142 | }
|
---|
143 | default:
|
---|
144 | break;
|
---|
145 | }
|
---|
146 | return QIWithRetranslateUI<QIManagerDialog>::event(pEvent);
|
---|
147 | }
|
---|
148 |
|
---|
149 | void UIVMLogViewerDialog::configure()
|
---|
150 | {
|
---|
151 | #ifndef VBOX_WS_MAC
|
---|
152 | /* Assign window icon: */
|
---|
153 | setWindowIcon(UIIconPool::iconSetFull(":/vm_show_logs_32px.png", ":/vm_show_logs_16px.png"));
|
---|
154 | #endif
|
---|
155 | }
|
---|
156 |
|
---|
157 | void UIVMLogViewerDialog::configureCentralWidget()
|
---|
158 | {
|
---|
159 | /* Create widget: */
|
---|
160 | UIVMLogViewerWidget *pWidget = new UIVMLogViewerWidget(EmbedTo_Dialog, m_pActionPool, true /* show toolbar */, m_uMachineId, this);
|
---|
161 | if (pWidget)
|
---|
162 | {
|
---|
163 | /* Configure widget: */
|
---|
164 | setWidget(pWidget);
|
---|
165 | setWidgetMenu(pWidget->menu());
|
---|
166 | #ifdef VBOX_WS_MAC
|
---|
167 | setWidgetToolbar(pWidget->toolbar());
|
---|
168 | #endif
|
---|
169 | connect(pWidget, &UIVMLogViewerWidget::sigSetCloseButtonShortCut,
|
---|
170 | this, &UIVMLogViewerDialog::sltSetCloseButtonShortCut);
|
---|
171 |
|
---|
172 | /* Add into layout: */
|
---|
173 | centralWidget()->layout()->addWidget(pWidget);
|
---|
174 | }
|
---|
175 | }
|
---|
176 |
|
---|
177 | void UIVMLogViewerDialog::finalize()
|
---|
178 | {
|
---|
179 | /* Apply language settings: */
|
---|
180 | retranslateUi();
|
---|
181 | loadDialogGeometry();
|
---|
182 | }
|
---|
183 |
|
---|
184 | void UIVMLogViewerDialog::loadDialogGeometry()
|
---|
185 | {
|
---|
186 |
|
---|
187 | const QRect availableGeo = gpDesktop->availableGeometry(this);
|
---|
188 | int iDefaultWidth = availableGeo.width() / 2;
|
---|
189 | int iDefaultHeight = availableGeo.height() * 3 / 4;
|
---|
190 | /* Try obtain the default width of the current logviewer: */
|
---|
191 | const UIVMLogViewerWidget *pWidget = qobject_cast<const UIVMLogViewerWidget*>(widget());
|
---|
192 | if (pWidget)
|
---|
193 | {
|
---|
194 | const int iWidth = pWidget->defaultLogPageWidth();
|
---|
195 | if (iWidth != 0)
|
---|
196 | iDefaultWidth = iWidth;
|
---|
197 | }
|
---|
198 | QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
|
---|
199 |
|
---|
200 | /* Load geometry from extradata: */
|
---|
201 | const QRect geo = gEDataManager->logWindowGeometry(this, centerWidget(), defaultGeo);
|
---|
202 | LogRel2(("GUI: UIVMLogViewerDialog: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
|
---|
203 | geo.x(), geo.y(), geo.width(), geo.height()));
|
---|
204 | restoreGeometry(geo);
|
---|
205 | }
|
---|
206 |
|
---|
207 | void UIVMLogViewerDialog::saveDialogGeometry()
|
---|
208 | {
|
---|
209 | /* Save geometry to extradata: */
|
---|
210 | const QRect geo = currentGeometry();
|
---|
211 | LogRel2(("GUI: UIVMLogViewerDialog: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
|
---|
212 | geo.x(), geo.y(), geo.width(), geo.height()));
|
---|
213 | gEDataManager->setLogWindowGeometry(geo, isCurrentlyMaximized());
|
---|
214 | }
|
---|
215 |
|
---|
216 | bool UIVMLogViewerDialog::shouldBeMaximized() const
|
---|
217 | {
|
---|
218 | return gEDataManager->logWindowShouldBeMaximized();
|
---|
219 | }
|
---|
220 |
|
---|
221 | void UIVMLogViewerDialog::sltSetCloseButtonShortCut(QKeySequence shortcut)
|
---|
222 | {
|
---|
223 | if (!closeEmitted() && button(ButtonType_Close))
|
---|
224 | button(ButtonType_Close)->setShortcut(shortcut);
|
---|
225 | }
|
---|