VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/VBoxLicenseViewer.cpp@ 104158

Last change on this file since 104158 was 103243, checked in by vboxsync, 9 months ago

FE/VirtualBox/VBoxLicenseViewer: Fixed implicit fallthrough (found by Parfait). bugref:3409

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.5 KB
Line 
1/* $Id: VBoxLicenseViewer.cpp 103243 2024-02-07 11:51:38Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - VBoxLicenseViewer class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-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#include <QFile>
30#include <QPushButton>
31#include <QScrollBar>
32#include <QTextBrowser>
33#include <QVBoxLayout>
34
35/* GUI includes: */
36#include "QIDialogButtonBox.h"
37#include "VBoxLicenseViewer.h"
38#include "UIIconPool.h"
39#include "UIMessageCenter.h"
40#include "UINotificationCenter.h"
41
42
43VBoxLicenseViewer::VBoxLicenseViewer(QWidget *pParent /* = 0 */)
44 : QIWithRetranslateUI2<QDialog>(pParent)
45 , m_pLicenseBrowser(0)
46 , m_pButtonAgree(0)
47 , m_pButtonDisagree(0)
48{
49#ifndef VBOX_WS_MAC
50 /* Assign window icon: */
51 setWindowIcon(UIIconPool::iconSetFull(":/log_viewer_find_32px.png", ":/log_viewer_find_16px.png"));
52#endif
53
54 /* Create main layout: */
55 QVBoxLayout *pMainLayout = new QVBoxLayout(this);
56 if (pMainLayout)
57 {
58 /* Create license browser: */
59 m_pLicenseBrowser = new QTextBrowser(this);
60 if (m_pLicenseBrowser)
61 {
62 /* Configure license browser: */
63 m_pLicenseBrowser->verticalScrollBar()->installEventFilter(this);
64 connect(m_pLicenseBrowser->verticalScrollBar(), &QScrollBar::valueChanged,
65 this, &VBoxLicenseViewer::sltHandleScrollBarMoved);
66
67 /* Add into layout: */
68 pMainLayout->addWidget(m_pLicenseBrowser);
69 }
70
71 /* Create agree button: */
72 /** @todo rework buttons to be a part of button-box itself */
73 QDialogButtonBox *pDialogButtonBox = new QIDialogButtonBox;
74 if (pDialogButtonBox)
75 {
76 /* Create agree button: */
77 m_pButtonAgree = new QPushButton;
78 if (m_pButtonAgree)
79 {
80 /* Configure button: */
81 connect(m_pButtonAgree, &QPushButton::clicked, this, &QDialog::accept);
82
83 /* Add into button-box: */
84 pDialogButtonBox->addButton(m_pButtonAgree, QDialogButtonBox::AcceptRole);
85 }
86
87 /* Create agree button: */
88 m_pButtonDisagree = new QPushButton;
89 if (m_pButtonDisagree)
90 {
91 /* Configure button: */
92 connect(m_pButtonDisagree, &QPushButton::clicked, this, &QDialog::reject);
93
94 /* Add into button-box: */
95 pDialogButtonBox->addButton(m_pButtonDisagree, QDialogButtonBox::RejectRole);
96 }
97 }
98
99 /* Add into layout: */
100 pMainLayout->addWidget(pDialogButtonBox);
101 }
102
103 /* Configure self: */
104 resize(600, 450);
105
106 /* Apply language settings: */
107 retranslateUi();
108}
109
110int VBoxLicenseViewer::showLicenseFromString(const QString &strLicenseText)
111{
112 /* Set license text: */
113 m_pLicenseBrowser->setText(strLicenseText);
114 return exec();
115}
116
117int VBoxLicenseViewer::showLicenseFromFile(const QString &strLicenseFileName)
118{
119 /* Read license file: */
120 QFile file(strLicenseFileName);
121 if (file.open(QIODevice::ReadOnly))
122 return showLicenseFromString(file.readAll());
123 else
124 {
125 UINotificationMessage::cannotOpenLicenseFile(strLicenseFileName);
126 return QDialog::Rejected;
127 }
128}
129
130bool VBoxLicenseViewer::eventFilter(QObject *pObject, QEvent *pEvent)
131{
132 /* Handle known event types: */
133 switch (pEvent->type())
134 {
135 case QEvent::Hide:
136 {
137 if (pObject == m_pLicenseBrowser->verticalScrollBar())
138 /* Doesn't work on wm's like ion3 where the window starts maximized: isActiveWindow() */
139 sltUnlockButtons();
140 break;
141 }
142 default:
143 break;
144 }
145
146 /* Call to base-class: */
147 return QDialog::eventFilter(pObject, pEvent);
148}
149
150void VBoxLicenseViewer::showEvent(QShowEvent *pEvent)
151{
152 /* Call to base-class: */
153 QDialog::showEvent(pEvent);
154
155 /* Enable/disable buttons accordingly: */
156 bool fScrollBarHidden = !m_pLicenseBrowser->verticalScrollBar()->isVisible()
157 && !(windowState() & Qt::WindowMinimized);
158 m_pButtonAgree->setEnabled(fScrollBarHidden);
159 m_pButtonDisagree->setEnabled(fScrollBarHidden);
160}
161
162void VBoxLicenseViewer::retranslateUi()
163{
164 /* Translate dialog title: */
165 setWindowTitle(tr("VirtualBox License"));
166
167 /* Translate buttons: */
168 m_pButtonAgree->setText(tr("I &Agree"));
169 m_pButtonDisagree->setText(tr("I &Disagree"));
170}
171
172int VBoxLicenseViewer::exec()
173{
174 /* Nothing wrong with that, just hiding slot: */
175 return QDialog::exec();
176}
177
178void VBoxLicenseViewer::sltHandleScrollBarMoved(int iValue)
179{
180 if (iValue == m_pLicenseBrowser->verticalScrollBar()->maximum())
181 sltUnlockButtons();
182}
183
184void VBoxLicenseViewer::sltUnlockButtons()
185{
186 m_pButtonAgree->setEnabled(true);
187 m_pButtonDisagree->setEnabled(true);
188}
189
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