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