1
/* $Id: VBoxLicenseViewer.cpp 35103 2010-12-14 16:33:26Z vboxsync $ */
4
* VBox frontends: Qt4 GUI ("VirtualBox"):
5
* VBoxLicenseViewer class implementation
9
* Copyright (C) 2006-2010 Oracle Corporation
11
* This file is part of VirtualBox Open Source Edition (OSE), as
12
* available from http://www.virtualbox.org. This file is free software;
13
* you can redistribute it and/or modify it under the terms of the GNU
14
* General Public License (GPL) as published by the Free Software
15
* Foundation, in version 2 as it comes in the "COPYING" file of the
16
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
#ifdef VBOX_WITH_PRECOMPILED_HEADERS
22
#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
23
#include "VBoxLicenseViewer.h"
24
#include "QIDialogButtonBox.h"
25
#include "VBoxGlobal.h"
26
#include "VBoxProblemReporter.h"
29
#include <QTextBrowser>
30
#include <QPushButton>
31
#include <QVBoxLayout>
34
#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
36
VBoxLicenseViewer::VBoxLicenseViewer(QWidget *pParent /* = 0 */)
37
: QIWithRetranslateUI2<QDialog>(pParent)
43
/* Application icon. On Win32, it's built-in to the executable. */
44
setWindowIcon (QIcon (":/VirtualBox_48px.png"));
47
mLicenseText = new QTextBrowser (this);
48
mAgreeButton = new QPushButton (this);
49
mDisagreeButton = new QPushButton (this);
50
QDialogButtonBox *dbb = new QIDialogButtonBox (this);
51
dbb->addButton (mAgreeButton, QDialogButtonBox::AcceptRole);
52
dbb->addButton (mDisagreeButton, QDialogButtonBox::RejectRole);
54
connect (mLicenseText->verticalScrollBar(), SIGNAL (valueChanged (int)),
55
SLOT (onScrollBarMoving (int)));
56
connect (mAgreeButton, SIGNAL (clicked()), SLOT (accept()));
57
connect (mDisagreeButton, SIGNAL (clicked()), SLOT (reject()));
59
QVBoxLayout *mainLayout = new QVBoxLayout (this);
60
mainLayout->setSpacing (10);
61
VBoxGlobal::setLayoutMargin (mainLayout, 10);
62
mainLayout->addWidget (mLicenseText);
63
mainLayout->addWidget (dbb);
65
mLicenseText->verticalScrollBar()->installEventFilter (this);
72
int VBoxLicenseViewer::showLicenseFromFile(const QString &strLicenseFileName)
74
/* Read license file: */
75
QFile file(strLicenseFileName);
76
if (file.open(QIODevice::ReadOnly))
78
return showLicenseFromString(file.readAll());
82
vboxProblem().cannotOpenLicenseFile(this, strLicenseFileName);
83
return QDialog::Rejected;
87
int VBoxLicenseViewer::showLicenseFromString(const QString &strLicenseText)
89
/* Set license text: */
90
mLicenseText->setText(strLicenseText);
94
void VBoxLicenseViewer::retranslateUi()
96
setWindowTitle (tr ("VirtualBox License"));
98
mAgreeButton->setText (tr ("I &Agree"));
99
mDisagreeButton->setText (tr ("I &Disagree"));
102
int VBoxLicenseViewer::exec()
104
return QDialog::exec();
107
void VBoxLicenseViewer::onScrollBarMoving (int aValue)
109
if (aValue == mLicenseText->verticalScrollBar()->maximum())
113
void VBoxLicenseViewer::unlockButtons()
115
mAgreeButton->setEnabled (true);
116
mDisagreeButton->setEnabled (true);
119
void VBoxLicenseViewer::showEvent (QShowEvent *aEvent)
121
QDialog::showEvent (aEvent);
122
bool isScrollBarHidden = !mLicenseText->verticalScrollBar()->isVisible()
123
&& !(windowState() & Qt::WindowMinimized);
124
mAgreeButton->setEnabled (isScrollBarHidden);
125
mDisagreeButton->setEnabled (isScrollBarHidden);
128
bool VBoxLicenseViewer::eventFilter (QObject *aObject, QEvent *aEvent)
130
switch (aEvent->type())
133
if (aObject == mLicenseText->verticalScrollBar())
134
/* Doesn't work on wm's like ion3 where the window starts
135
* maximized: isActiveWindow() */
140
return QDialog::eventFilter (aObject, aEvent);