VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/logviewer/UIVMLogViewerDialog.cpp@ 103977

Last change on this file since 103977 was 103923, checked in by vboxsync, 9 months ago

FE/Qt. bugref:10622. Using new UITranslationEventListener in log viewer classes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
1/* $Id: UIVMLogViewerDialog.cpp 103923 2024-03-19 17:01:11Z 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 <QAbstractButton>
33#include <QPushButton>
34#include <QVBoxLayout>
35
36/* GUI includes: */
37#include "QIDialogButtonBox.h"
38#include "UIDesktopWidgetWatchdog.h"
39#include "UIExtraDataManager.h"
40#include "UIIconPool.h"
41#include "UILoggingDefs.h"
42#include "UIShortcutPool.h"
43#include "UITranslationEventListener.h"
44#include "UIVMLogViewerDialog.h"
45#include "UIVMLogViewerDialog.h"
46#include "UIVMLogViewerWidget.h"
47#ifdef VBOX_WS_MAC
48# include "VBoxUtils-darwin.h"
49#endif
50
51
52/*********************************************************************************************************************************
53* Class UIVMLogViewerDialogFactory implementation. *
54*********************************************************************************************************************************/
55
56UIVMLogViewerDialogFactory::UIVMLogViewerDialogFactory(UIActionPool *pActionPool /* = 0 */,
57 const QList<QUuid> &machineIDs /* = QList<QUuid>() */,
58 const QString &strMachineName /* = QString() */)
59 : m_pActionPool(pActionPool)
60 , m_machineIDs(machineIDs)
61 , m_strMachineName(strMachineName)
62{
63}
64
65void UIVMLogViewerDialogFactory::create(QIManagerDialog *&pDialog, QWidget *pCenterWidget)
66{
67 pDialog = new UIVMLogViewerDialog(pCenterWidget, m_pActionPool, m_machineIDs, m_strMachineName);
68}
69
70
71/*********************************************************************************************************************************
72* Class UIVMLogViewerDialog implementation. *
73*********************************************************************************************************************************/
74
75UIVMLogViewerDialog::UIVMLogViewerDialog(QWidget *pCenterWidget, UIActionPool *pActionPool,
76 const QList<QUuid> &machineIDs /* = QList<QUuid>() */,
77 const QString &strMachineName /* = QString() */)
78 : QIManagerDialog(pCenterWidget)
79 , m_pActionPool(pActionPool)
80 , m_machineIDs(machineIDs)
81 , m_iGeometrySaveTimerId(-1)
82 , m_strMachineName(strMachineName)
83{
84 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
85 this, &UIVMLogViewerDialog::sltRetranslateUI);
86}
87
88UIVMLogViewerDialog::~UIVMLogViewerDialog()
89{
90}
91
92void UIVMLogViewerDialog::setSelectedVMListItems(const QList<UIVirtualMachineItem*> &items)
93{
94 Q_UNUSED(items);
95 UIVMLogViewerWidget *pLogViewerWidget = qobject_cast<UIVMLogViewerWidget*>(widget());
96 if (pLogViewerWidget)
97 pLogViewerWidget->setSelectedVMListItems(items);
98}
99
100void UIVMLogViewerDialog::sltRetranslateUI()
101{
102 /* Translate window title: */
103 if (!m_strMachineName.isEmpty())
104 setWindowTitle(UIVMLogViewerWidget::tr("%1 - Log Viewer").arg(m_strMachineName));
105 else
106 setWindowTitle(UIVMLogViewerWidget::tr("Log Viewer"));
107
108 /* Translate buttons: */
109 button(ButtonType_Close)->setText(UIVMLogViewerWidget::tr("Close"));
110 button(ButtonType_Help)->setText(UIVMLogViewerWidget::tr("Help"));
111 button(ButtonType_Embed)->setText(UIVMLogViewerWidget::tr("Embed"));
112 button(ButtonType_Close)->setStatusTip(UIVMLogViewerWidget::tr("Close dialog"));
113 button(ButtonType_Help)->setStatusTip(UIVMLogViewerWidget::tr("Show dialog help"));
114 button(ButtonType_Embed)->setStatusTip(UIVMLogViewerWidget::tr("Embed to manager window"));
115 button(ButtonType_Close)->setShortcut(Qt::Key_Escape);
116 button(ButtonType_Help)->setShortcut(UIShortcutPool::standardSequence(QKeySequence::HelpContents));
117 button(ButtonType_Close)->setToolTip(UIVMLogViewerWidget::tr("Close Window (%1)").arg(button(ButtonType_Close)->shortcut().toString()));
118 button(ButtonType_Help)->setToolTip(UIVMLogViewerWidget::tr("Show Help (%1)").arg(button(ButtonType_Help)->shortcut().toString()));
119 button(ButtonType_Embed)->setToolTip(UIVMLogViewerWidget::tr("Embed to Manager Window"));
120}
121
122bool UIVMLogViewerDialog::event(QEvent *pEvent)
123{
124 switch (pEvent->type())
125 {
126 case QEvent::Resize:
127 case QEvent::Move:
128 {
129 if (m_iGeometrySaveTimerId != -1)
130 killTimer(m_iGeometrySaveTimerId);
131 m_iGeometrySaveTimerId = startTimer(300);
132 break;
133 }
134 case QEvent::Timer:
135 {
136 QTimerEvent *pTimerEvent = static_cast<QTimerEvent*>(pEvent);
137 if (pTimerEvent->timerId() == m_iGeometrySaveTimerId)
138 {
139 killTimer(m_iGeometrySaveTimerId);
140 m_iGeometrySaveTimerId = -1;
141 saveDialogGeometry();
142 }
143 break;
144 }
145 default:
146 break;
147 }
148 return QIManagerDialog::event(pEvent);
149}
150
151void UIVMLogViewerDialog::configure()
152{
153#ifndef VBOX_WS_MAC
154 /* Assign window icon: */
155 setWindowIcon(UIIconPool::iconSetFull(":/vm_show_logs_32px.png", ":/vm_show_logs_16px.png"));
156#endif
157}
158
159void UIVMLogViewerDialog::configureCentralWidget()
160{
161 /* Create widget: */
162 UIVMLogViewerWidget *pWidget = new UIVMLogViewerWidget(EmbedTo_Dialog, m_pActionPool, true /* show toolbar */, m_machineIDs, this);
163 if (pWidget)
164 {
165 /* Configure widget: */
166 setWidget(pWidget);
167 setWidgetMenu(pWidget->menu());
168#ifdef VBOX_WS_MAC
169 setWidgetToolbar(pWidget->toolbar());
170#endif
171 connect(pWidget, &UIVMLogViewerWidget::sigSetCloseButtonShortCut,
172 this, &UIVMLogViewerDialog::sltSetCloseButtonShortCut);
173
174 /* Add into layout: */
175 centralWidget()->layout()->addWidget(pWidget);
176 }
177}
178
179void UIVMLogViewerDialog::configureButtonBox()
180{
181 /* General handler for the button being clicked: */
182 connect(buttonBox(), &QIDialogButtonBox::clicked,
183 this, &UIVMLogViewerDialog::sltHandleButtonBoxClick);
184
185 /* Show/Enable Embed button depending for Manager, not for Runtime: */
186 button(ButtonType_Embed)->setVisible(m_strMachineName.isEmpty());
187 button(ButtonType_Embed)->setEnabled(m_strMachineName.isEmpty());
188}
189
190void UIVMLogViewerDialog::finalize()
191{
192 /* Apply language settings: */
193 sltRetranslateUI();
194 loadDialogGeometry();
195}
196
197void UIVMLogViewerDialog::loadDialogGeometry()
198{
199
200 const QRect availableGeo = gpDesktop->availableGeometry(this);
201 int iDefaultWidth = availableGeo.width() / 2;
202 int iDefaultHeight = availableGeo.height() * 3 / 4;
203 /* Try obtain the default width of the current logviewer: */
204 const UIVMLogViewerWidget *pWidget = qobject_cast<const UIVMLogViewerWidget*>(widget());
205 if (pWidget)
206 {
207 const int iWidth = pWidget->defaultLogPageWidth();
208 if (iWidth != 0)
209 iDefaultWidth = iWidth;
210 }
211 QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
212
213 /* Load geometry from extradata: */
214 const QRect geo = gEDataManager->logWindowGeometry(this, centerWidget(), defaultGeo);
215 LogRel2(("GUI: UIVMLogViewerDialog: Restoring geometry to: Origin=%dx%d, Size=%dx%d\n",
216 geo.x(), geo.y(), geo.width(), geo.height()));
217 restoreGeometry(geo);
218}
219
220void UIVMLogViewerDialog::saveDialogGeometry()
221{
222 /* Save geometry to extradata: */
223 const QRect geo = currentGeometry();
224 LogRel2(("GUI: UIVMLogViewerDialog: Saving geometry as: Origin=%dx%d, Size=%dx%d\n",
225 geo.x(), geo.y(), geo.width(), geo.height()));
226 gEDataManager->setLogWindowGeometry(geo, isCurrentlyMaximized());
227}
228
229bool UIVMLogViewerDialog::shouldBeMaximized() const
230{
231 return gEDataManager->logWindowShouldBeMaximized();
232}
233
234void UIVMLogViewerDialog::sltSetCloseButtonShortCut(QKeySequence shortcut)
235{
236 if (!closeEmitted() && button(ButtonType_Close))
237 button(ButtonType_Close)->setShortcut(shortcut);
238}
239
240void UIVMLogViewerDialog::sltHandleButtonBoxClick(QAbstractButton *pButton)
241{
242 /* Disable all buttons first of all: */
243 button(ButtonType_Embed)->setEnabled(false);
244
245 /* Compare with known buttons: */
246 if (pButton == button(ButtonType_Embed))
247 emit sigEmbed();
248}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette