VirtualBox

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

Last change on this file was 106061, checked in by vboxsync, 43 hours ago

Copyright year updates by scm.

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