VirtualBox

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

Last change on this file since 100347 was 100300, checked in by vboxsync, 19 months ago

FE/Qt: bugref:9080. Build fix.

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