VirtualBox

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

Last change on this file was 104358, checked in by vboxsync, 12 days ago

FE/Qt. bugref:10622. More refactoring around the retranslation functionality.

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

© 2023 Oracle
ContactPrivacy policyTerms of Use