[31877] | 1 | /* $Id: VBoxLicenseViewer.cpp 104358 2024-04-18 05:33:40Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[52722] | 3 | * VBox Qt GUI - VBoxLicenseViewer class implementation.
|
---|
[31877] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[31877] | 8 | *
|
---|
[96407] | 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
|
---|
[31877] | 26 | */
|
---|
| 27 |
|
---|
[71552] | 28 | /* Qt includes: */
|
---|
[104358] | 29 | #include <QEvent>
|
---|
[76606] | 30 | #include <QFile>
|
---|
| 31 | #include <QPushButton>
|
---|
| 32 | #include <QScrollBar>
|
---|
| 33 | #include <QTextBrowser>
|
---|
| 34 | #include <QVBoxLayout>
|
---|
[71552] | 35 |
|
---|
| 36 | /* GUI includes: */
|
---|
[76606] | 37 | #include "QIDialogButtonBox.h"
|
---|
| 38 | #include "VBoxLicenseViewer.h"
|
---|
[100896] | 39 | #include "UIIconPool.h"
|
---|
[76606] | 40 | #include "UIMessageCenter.h"
|
---|
[91216] | 41 | #include "UINotificationCenter.h"
|
---|
[104358] | 42 | #include "UITranslationEventListener.h"
|
---|
[52722] | 43 |
|
---|
[35103] | 44 | VBoxLicenseViewer::VBoxLicenseViewer(QWidget *pParent /* = 0 */)
|
---|
[104358] | 45 | : QDialog(pParent)
|
---|
[71552] | 46 | , m_pLicenseBrowser(0)
|
---|
| 47 | , m_pButtonAgree(0)
|
---|
| 48 | , m_pButtonDisagree(0)
|
---|
[31877] | 49 | {
|
---|
[100896] | 50 | #ifndef VBOX_WS_MAC
|
---|
| 51 | /* Assign window icon: */
|
---|
| 52 | setWindowIcon(UIIconPool::iconSetFull(":/log_viewer_find_32px.png", ":/log_viewer_find_16px.png"));
|
---|
[31877] | 53 | #endif
|
---|
| 54 |
|
---|
[71552] | 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);
|
---|
[31877] | 67 |
|
---|
[71552] | 68 | /* Add into layout: */
|
---|
| 69 | pMainLayout->addWidget(m_pLicenseBrowser);
|
---|
| 70 | }
|
---|
[31877] | 71 |
|
---|
[71552] | 72 | /* Create agree button: */
|
---|
[71574] | 73 | /** @todo rework buttons to be a part of button-box itself */
|
---|
[71552] | 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);
|
---|
[31877] | 83 |
|
---|
[71552] | 84 | /* Add into button-box: */
|
---|
| 85 | pDialogButtonBox->addButton(m_pButtonAgree, QDialogButtonBox::AcceptRole);
|
---|
| 86 | }
|
---|
[31877] | 87 |
|
---|
[71552] | 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);
|
---|
[31877] | 94 |
|
---|
[71552] | 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: */
|
---|
[104358] | 108 | sltRetranslateUI();
|
---|
| 109 | connect(&translationEventListener(), &UITranslationEventListener::sigRetranslateUI,
|
---|
| 110 | this, &VBoxLicenseViewer::sltRetranslateUI);
|
---|
[31877] | 111 | }
|
---|
| 112 |
|
---|
[71552] | 113 | int VBoxLicenseViewer::showLicenseFromString(const QString &strLicenseText)
|
---|
| 114 | {
|
---|
| 115 | /* Set license text: */
|
---|
| 116 | m_pLicenseBrowser->setText(strLicenseText);
|
---|
| 117 | return exec();
|
---|
| 118 | }
|
---|
| 119 |
|
---|
[34811] | 120 | int VBoxLicenseViewer::showLicenseFromFile(const QString &strLicenseFileName)
|
---|
[31877] | 121 | {
|
---|
[34811] | 122 | /* Read license file: */
|
---|
| 123 | QFile file(strLicenseFileName);
|
---|
| 124 | if (file.open(QIODevice::ReadOnly))
|
---|
| 125 | return showLicenseFromString(file.readAll());
|
---|
[31877] | 126 | else
|
---|
| 127 | {
|
---|
[91216] | 128 | UINotificationMessage::cannotOpenLicenseFile(strLicenseFileName);
|
---|
[31877] | 129 | return QDialog::Rejected;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[71552] | 133 | bool VBoxLicenseViewer::eventFilter(QObject *pObject, QEvent *pEvent)
|
---|
[34811] | 134 | {
|
---|
[71552] | 135 | /* Handle known event types: */
|
---|
| 136 | switch (pEvent->type())
|
---|
| 137 | {
|
---|
| 138 | case QEvent::Hide:
|
---|
[103243] | 139 | {
|
---|
[71552] | 140 | if (pObject == m_pLicenseBrowser->verticalScrollBar())
|
---|
| 141 | /* Doesn't work on wm's like ion3 where the window starts maximized: isActiveWindow() */
|
---|
| 142 | sltUnlockButtons();
|
---|
[103243] | 143 | break;
|
---|
| 144 | }
|
---|
[71552] | 145 | default:
|
---|
| 146 | break;
|
---|
| 147 | }
|
---|
| 148 |
|
---|
| 149 | /* Call to base-class: */
|
---|
| 150 | return QDialog::eventFilter(pObject, pEvent);
|
---|
[34811] | 151 | }
|
---|
| 152 |
|
---|
[71552] | 153 | void VBoxLicenseViewer::showEvent(QShowEvent *pEvent)
|
---|
[31877] | 154 | {
|
---|
[71552] | 155 | /* Call to base-class: */
|
---|
| 156 | QDialog::showEvent(pEvent);
|
---|
[31877] | 157 |
|
---|
[71552] | 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);
|
---|
[31877] | 163 | }
|
---|
| 164 |
|
---|
[104358] | 165 | void VBoxLicenseViewer::sltRetranslateUI()
|
---|
[34811] | 166 | {
|
---|
[71552] | 167 | /* Translate dialog title: */
|
---|
| 168 | setWindowTitle(tr("VirtualBox License"));
|
---|
[34811] | 169 |
|
---|
[71552] | 170 | /* Translate buttons: */
|
---|
| 171 | m_pButtonAgree->setText(tr("I &Agree"));
|
---|
| 172 | m_pButtonDisagree->setText(tr("I &Disagree"));
|
---|
[31877] | 173 | }
|
---|
| 174 |
|
---|
[71552] | 175 | int VBoxLicenseViewer::exec()
|
---|
[31877] | 176 | {
|
---|
[71552] | 177 | /* Nothing wrong with that, just hiding slot: */
|
---|
| 178 | return QDialog::exec();
|
---|
[31877] | 179 | }
|
---|
| 180 |
|
---|
[71552] | 181 | void VBoxLicenseViewer::sltHandleScrollBarMoved(int iValue)
|
---|
[31877] | 182 | {
|
---|
[71552] | 183 | if (iValue == m_pLicenseBrowser->verticalScrollBar()->maximum())
|
---|
| 184 | sltUnlockButtons();
|
---|
[31877] | 185 | }
|
---|
| 186 |
|
---|
[71552] | 187 | void VBoxLicenseViewer::sltUnlockButtons()
|
---|
[31877] | 188 | {
|
---|
[71552] | 189 | m_pButtonAgree->setEnabled(true);
|
---|
| 190 | m_pButtonDisagree->setEnabled(true);
|
---|
[31877] | 191 | }
|
---|