VirtualBox

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

Last change on this file since 100347 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

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