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