VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/helpbrowser/UIHelpBrowserDialog.cpp

Last change on this file was 104358, checked in by vboxsync, 5 weeks ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.1 KB
Line 
1/* $Id: UIHelpBrowserDialog.cpp 104358 2024-04-18 05:33:40Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIHelpBrowserDialog 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 <QLabel>
33#include <QMenuBar>
34#include <QStatusBar>
35
36/* GUI includes: */
37#include "UICommon.h"
38#include "UIDesktopWidgetWatchdog.h"
39#include "UIExtraDataManager.h"
40#include "UIGlobalSession.h"
41#include "UIIconPool.h"
42#include "UIHelpBrowserDialog.h"
43#include "UIHelpBrowserWidget.h"
44#include "UINotificationObjects.h"
45#include "UITranslationEventListener.h"
46#ifdef VBOX_WS_MAC
47# include "VBoxUtils-darwin.h"
48#endif
49
50/* Other VBox includes: */
51#include <iprt/assert.h>
52
53QPointer<UIHelpBrowserDialog> UIHelpBrowserDialog::m_pInstance;
54
55
56/*********************************************************************************************************************************
57* Class UIHelpBrowserDialog implementation. *
58*********************************************************************************************************************************/
59
60UIHelpBrowserDialog::UIHelpBrowserDialog(QWidget *pParent, QWidget *pCenterWidget, const QString &strHelpFilePath)
61 : QIWithRestorableGeometry<QMainWindow>(pParent)
62 , m_strHelpFilePath(strHelpFilePath)
63 , m_pWidget(0)
64 , m_pCenterWidget(pCenterWidget)
65 , m_iGeometrySaveTimerId(-1)
66 , m_pZoomLabel(0)
67{
68#ifndef VBOX_WS_MAC
69 /* Assign window icon: */
70 setWindowIcon(UIIconPool::iconSetFull(":/log_viewer_find_32px.png", ":/log_viewer_find_16px.png"));
71#endif
72
73 setAttribute(Qt::WA_DeleteOnClose);
74 statusBar()->show();
75 m_pZoomLabel = new QLabel;
76 statusBar()->addPermanentWidget(m_pZoomLabel);
77
78 prepareCentralWidget();
79 loadSettings();
80 sltRetranslateUI();
81 connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
82 this, &UIHelpBrowserDialog::sltRetranslateUI);
83}
84
85void UIHelpBrowserDialog::showHelpForKeyword(const QString &strKeyword)
86{
87 if (m_pWidget)
88 m_pWidget->showHelpForKeyword(strKeyword);
89}
90
91void UIHelpBrowserDialog::sltRetranslateUI()
92{
93 setWindowTitle(UIHelpBrowserWidget::tr("Oracle VM VirtualBox User Manual"));
94}
95
96bool UIHelpBrowserDialog::event(QEvent *pEvent)
97{
98 switch (pEvent->type())
99 {
100 case QEvent::Resize:
101 case QEvent::Move:
102 {
103 if (m_iGeometrySaveTimerId != -1)
104 killTimer(m_iGeometrySaveTimerId);
105 m_iGeometrySaveTimerId = startTimer(300);
106 break;
107 }
108 case QEvent::Timer:
109 {
110 QTimerEvent *pTimerEvent = static_cast<QTimerEvent*>(pEvent);
111 if (pTimerEvent->timerId() == m_iGeometrySaveTimerId)
112 {
113 killTimer(m_iGeometrySaveTimerId);
114 m_iGeometrySaveTimerId = -1;
115 saveDialogGeometry();
116 }
117 break;
118 }
119 default:
120 break;
121 }
122 return QIWithRestorableGeometry<QMainWindow>::event(pEvent);
123}
124
125void UIHelpBrowserDialog::prepareCentralWidget()
126{
127 m_pWidget = new UIHelpBrowserWidget(EmbedTo_Dialog, m_strHelpFilePath);
128 AssertPtrReturnVoid(m_pWidget);
129 setCentralWidget((m_pWidget));
130 sltZoomPercentageChanged(m_pWidget->zoomPercentage());
131 connect(m_pWidget, &UIHelpBrowserWidget::sigCloseDialog,
132 this, &UIHelpBrowserDialog::close);
133 connect(m_pWidget, &UIHelpBrowserWidget::sigStatusBarMessage,
134 this, &UIHelpBrowserDialog::sltStatusBarMessage);
135 connect(m_pWidget, &UIHelpBrowserWidget::sigStatusBarVisible,
136 this, &UIHelpBrowserDialog::sltStatusBarVisibilityChange);
137 connect(m_pWidget, &UIHelpBrowserWidget::sigZoomPercentageChanged,
138 this, &UIHelpBrowserDialog::sltZoomPercentageChanged);
139
140 const QList<QMenu*> menuList = m_pWidget->menus();
141 foreach (QMenu *pMenu, menuList)
142 menuBar()->addMenu(pMenu);
143}
144
145void UIHelpBrowserDialog::loadSettings()
146{
147 const QRect availableGeo = gpDesktop->availableGeometry(this);
148 int iDefaultWidth = availableGeo.width() / 2;
149 int iDefaultHeight = availableGeo.height() * 3 / 4;
150 QRect defaultGeo(0, 0, iDefaultWidth, iDefaultHeight);
151
152 const QRect geo = gEDataManager->helpBrowserDialogGeometry(this, m_pCenterWidget, defaultGeo);
153 restoreGeometry(geo);
154}
155
156void UIHelpBrowserDialog::saveDialogGeometry()
157{
158 const QRect geo = currentGeometry();
159 gEDataManager->setHelpBrowserDialogGeometry(geo, isCurrentlyMaximized());
160}
161
162bool UIHelpBrowserDialog::shouldBeMaximized() const
163{
164 return gEDataManager->helpBrowserDialogShouldBeMaximized();
165}
166
167void UIHelpBrowserDialog::sltStatusBarMessage(const QString& strLink, int iTimeOut)
168{
169 statusBar()->showMessage(strLink, iTimeOut);
170}
171
172void UIHelpBrowserDialog::sltStatusBarVisibilityChange(bool fVisible)
173{
174 statusBar()->setVisible(fVisible);
175}
176
177void UIHelpBrowserDialog::sltZoomPercentageChanged(int iPercentage)
178{
179 if (m_pZoomLabel)
180 m_pZoomLabel->setText(QString("%1%").arg(QString::number(iPercentage)));
181}
182
183/* static */
184void UIHelpBrowserDialog::findManualFileAndShow(const QString &strKeyword /*= QString() */)
185{
186#ifndef VBOX_OSE
187 /* For non-OSE version we just open it: */
188 showUserManual(uiCommon().helpFile(), strKeyword);
189#else /* #ifndef VBOX_OSE */
190#if 0
191 /* For OSE version we have to check if it present first: */
192 QString strUserManualFileName1 = uiCommon().helpFile();
193 QString strShortFileName = QFileInfo(strUserManualFileName1).fileName();
194 QString strUserManualFileName2 = QDir(gpGlobalSession->homeFolder()).absoluteFilePath(strShortFileName);
195 /* Show if user manual already present: */
196 if (QFile::exists(strUserManualFileName1))
197 showUserManual(strUserManualFileName1, strKeyword);
198 else if (QFile::exists(strUserManualFileName2))
199 showUserManual(strUserManualFileName2, strKeyword);
200# ifdef VBOX_GUI_WITH_NETWORK_MANAGER
201 /* If downloader is running already: */
202 if (UINotificationDownloaderUserManual::exists())
203 gpNotificationCenter->invoke();
204 /* Else propose to download user manual: */
205 else if (confirmLookingForUserManual(strUserManualFileName1))
206 {
207 /* Download user manual: */
208 UINotificationDownloaderUserManual *pNotification = UINotificationDownloaderUserManual::instance(UICommon::helpFile());
209 /* After downloading finished => show User Manual: */
210 /// @todo
211 // connect(pNotification, &UINotificationDownloaderUserManual::sigUserManualDownloaded,
212 // this, &UIMessageCenter::showUserManual);
213 /* Append and start notification: */
214 gpNotificationCenter->append(pNotification);
215 }
216# endif /* VBOX_GUI_WITH_NETWORK_MANAGER */
217#endif // 0
218#endif /* #ifdef VBOX_OSE */
219}
220
221/* static */
222void UIHelpBrowserDialog::showUserManual(const QString &strHelpFilePath, const QString &strKeyword)
223{
224 if (!QFileInfo(strHelpFilePath).exists())
225 {
226 UINotificationMessage::cannotFindHelpFile(strHelpFilePath);
227 return;
228 }
229 if (!m_pInstance)
230 {
231 m_pInstance = new UIHelpBrowserDialog(0 /* parent */, 0 /* Center Widget */, strHelpFilePath);
232 AssertReturnVoid(m_pInstance);
233 }
234
235 if (!strKeyword.isEmpty())
236 m_pInstance->showHelpForKeyword(strKeyword);
237 m_pInstance->show();
238 m_pInstance->setWindowState(m_pInstance->windowState() & ~Qt::WindowMinimized);
239 m_pInstance->activateWindow();
240}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use