VirtualBox

Changeset 18198 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Mar 24, 2009 3:45:22 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4-OVF: added support for license confirmation on OVF import

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxImportApplianceWgt.h

    r17053 r18198  
    3939
    4040    bool setFile (const QString& aFile);
     41    void prepareImport();
    4142    bool import();
    4243
    4344    bool isValid() const { return mAppliance != NULL; }
     45    QList < QPair <QString, QString> > licenseAgreements() const;
    4446
    4547    static int minGuestRAM() { return mMinGuestRAM; }
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxImportApplianceWzd.h

    r17053 r18198  
    2727#include "QIAbstractWizard.h"
    2828#include "QIWithRetranslateUI.h"
     29#include "QIDialog.h"
    2930
    3031class QIWidgetValidator;
     32
     33class QDialogButtonBox;
     34
     35class VBoxImportLicenseViewer: public QIDialog
     36{
     37    Q_OBJECT;
     38
     39public:
     40    VBoxImportLicenseViewer (QWidget *aParent = NULL);
     41
     42    void setContent (const QString &aName, const QString &aText);
     43
     44protected:
     45    void retranslateUi();
     46
     47private slots:
     48    void print();
     49    void save();
     50
     51private:
     52    QLabel *mCaption;
     53    QTextEdit *mLicenseText;
     54    QDialogButtonBox *mButtonBox;
     55    QPushButton *mPrintBtn;
     56    QPushButton *mSaveBtn;
     57    QString mName;
     58    QString mText;
     59};
    3160
    3261class VBoxImportApplianceWzd : public QIWithRetranslateUI<QIAbstractWizard>,
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxImportApplianceWgt.cpp

    r18009 r18198  
    5353
    5454protected:
     55    bool filterAcceptsRow (int aSourceRow, const QModelIndex & aSourceParent) const;
    5556    bool lessThan (const QModelIndex &aLeft, const QModelIndex &aRight) const;
    5657
     
    754755    KVirtualSystemDescriptionType_Description,
    755756    KVirtualSystemDescriptionType_OS,
     757    KVirtualSystemDescriptionType_License,
    756758    KVirtualSystemDescriptionType_CPU,
    757759    KVirtualSystemDescriptionType_Memory,
     
    770772{}
    771773
     774bool VirtualSystemSortProxyModel::filterAcceptsRow (int aSourceRow, const QModelIndex & aSourceParent) const
     775{
     776    /* By default enable all, we will explicitly filter out below */
     777    if (aSourceParent.isValid())
     778    {
     779        QModelIndex i = aSourceParent.child (aSourceRow, 0);
     780        if (i.isValid())
     781        {
     782            ModelItem *item = static_cast<ModelItem*> (i.internalPointer());
     783            /* We filter hardware types only */
     784            if (item->type() == HardwareType)
     785            {
     786                HardwareItem *hwItem = static_cast<HardwareItem*> (item);
     787                /* The license type shouldn't be displayed */
     788                if (hwItem->mType == KVirtualSystemDescriptionType_License)
     789                    return false;
     790            }
     791        }
     792    }
     793    return true;
     794}
     795
    772796bool VirtualSystemSortProxyModel::lessThan (const QModelIndex &aLeft, const QModelIndex &aRight) const
    773797{
     
    10601084                    mTvSettings->setColumnHidden (OriginalValueSection, true);
    10611085                    mTvSettings->expandAll();
    1062 
    1063 // @todo can the warnings also be shown when an error occurs? I have the case here that
    1064 // interpret() failes because there's 16 hard disks attached to four SCSI controllers,
    1065 // and we support only one SCSI controller, and the warnings about the additional SCSI
    1066 // controllers are not shown. Instead there's only the error message that disk X cannot
    1067 // be attached to controller Y. I have fixed VBoxManage accordingly, but the GUI should
    1068 // have that too. Thanks!
    10691086
    10701087                    /* Check for warnings & if there are one display them. */
     
    10921109}
    10931110
     1111void VBoxImportApplianceWgt::prepareImport()
     1112{
     1113    if (mAppliance)
     1114        mModel->putBack();
     1115}
     1116
    10941117bool VBoxImportApplianceWgt::import()
    10951118{
    10961119    if (mAppliance)
    10971120    {
    1098         mModel->putBack();
    10991121        /* Start the import asynchronously */
    11001122        CProgress progress;
     
    11171139    }
    11181140    return false;
     1141}
     1142
     1143QList < QPair<QString, QString> > VBoxImportApplianceWgt::licenseAgreements() const
     1144{
     1145    QList < QPair<QString, QString> > list;
     1146
     1147    CVirtualSystemDescriptionVector vsds = mAppliance->GetVirtualSystemDescriptions();
     1148    for (int i=0; i < vsds.size(); ++i)
     1149    {
     1150        QVector<QString> license;
     1151        vsds[i].GetValuesByType (KVirtualSystemDescriptionType_License,
     1152                                 KVirtualSystemDescriptionValueType_Original,
     1153                                 license);
     1154        if (!license.isEmpty())
     1155        {
     1156            QVector<QString> name;
     1157            vsds[i].GetValuesByType (KVirtualSystemDescriptionType_Name,
     1158                                     KVirtualSystemDescriptionValueType_Auto,
     1159                                     name);
     1160            list << QPair<QString, QString> (name.first(), license.first());
     1161        }
     1162    }
     1163
     1164    return list;
    11191165}
    11201166
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxImportApplianceWzd.cpp

    r17714 r18198  
    2626#include "VBoxProblemReporter.h"
    2727
     28/* Qt includes */
    2829#include <QFileInfo>
     30#include <QDialogButtonBox>
     31#include <QPrinter>
     32#include <QPrintDialog>
     33#include <QTextStream>
     34
     35////////////////////////////////////////////////////////////////////////////////
     36// VBoxImportLicenseViewer
     37
     38VBoxImportLicenseViewer::VBoxImportLicenseViewer (QWidget *aParent /* = NULL */)
     39  : QIDialog (aParent)
     40{
     41    QVBoxLayout *pMainLayout = new QVBoxLayout (this);
     42    pMainLayout->setMargin (12);
     43
     44    mCaption = new QLabel (this);
     45    mCaption->setWordWrap (true);
     46    pMainLayout->addWidget (mCaption);
     47
     48    mLicenseText = new QTextEdit (this);
     49    mLicenseText->setReadOnly (true);
     50    pMainLayout->addWidget (mLicenseText);
     51
     52    mButtonBox = new QDialogButtonBox (QDialogButtonBox::No | QDialogButtonBox::Yes, Qt::Horizontal, this);
     53    mPrintBtn = new QPushButton (this);
     54    mButtonBox->addButton (mPrintBtn, QDialogButtonBox::ActionRole);
     55    mSaveBtn = new QPushButton (this);
     56    mButtonBox->addButton (mSaveBtn, QDialogButtonBox::ActionRole);
     57    mButtonBox->button (QDialogButtonBox::Yes)->setDefault (true);
     58    connect (mButtonBox, SIGNAL (rejected()),
     59             this, SLOT (reject()));
     60    connect (mButtonBox, SIGNAL (accepted()),
     61             this, SLOT (accept()));
     62    connect (mPrintBtn, SIGNAL (clicked()),
     63             this, SLOT (print()));
     64    connect (mSaveBtn, SIGNAL (clicked()),
     65             this, SLOT (save()));
     66    pMainLayout->addWidget (mButtonBox);
     67
     68    retranslateUi();
     69}
     70
     71void VBoxImportLicenseViewer::setContent (const QString &aName, const QString &aText)
     72{
     73    mName = aName;
     74    mText = aText;
     75    mCaption->setText (tr ("<b>To continue importing the Appliance you must agree to the terms of the software license agreement for the Virtual System \"%1\".</b><br /><br />Click <b>Agree</b> to continue or click <b>Disagree</b> to cancel the import.").arg (mName));
     76    mLicenseText->setText (mText);
     77
     78}
     79
     80void VBoxImportLicenseViewer::retranslateUi()
     81{
     82    setWindowTitle (tr ("Software License Agreement"));
     83    mButtonBox->button (QDialogButtonBox::No)->setText (tr ("&Disagree"));
     84    mButtonBox->button (QDialogButtonBox::Yes)->setText (tr ("&Agree"));
     85    mPrintBtn->setText (tr ("&Print..."));
     86    mSaveBtn->setText (tr ("&Save..."));
     87
     88    setContent (mName, mText);
     89}
     90
     91void VBoxImportLicenseViewer::print()
     92{
     93    QPrinter printer;
     94    QPrintDialog pd (&printer, this);
     95    if (pd.exec() == QDialog::Accepted)
     96        mLicenseText->print (&printer);
     97}
     98
     99void VBoxImportLicenseViewer::save()
     100{
     101    QString fileName = vboxGlobal().getSaveFileName (vboxGlobal().documentsPath(), tr("Text (*.txt)"), this, tr("Select a file to save into..."));
     102    if (!fileName.isEmpty())
     103    {
     104        QFile file (fileName);
     105        if (file.open(QFile::WriteOnly | QFile::Truncate))
     106        {
     107            QTextStream out (&file);
     108            out << mLicenseText->toPlainText();
     109        }
     110    }
     111}
    29112
    30113////////////////////////////////////////////////////////////////////////////////
     
    97180void VBoxImportApplianceWzd::accept()
    98181{
     182    /* Make sure the final values are puted back. */
     183    mImportSettingsWgt->prepareImport();
     184    /* Check if there are license agreements the use must confirm */
     185    QList < QPair <QString, QString> > licAgreements = mImportSettingsWgt->licenseAgreements();
     186    if (!licAgreements.isEmpty())
     187    {
     188        VBoxImportLicenseViewer ilv (this);
     189        for (int i=0; i < licAgreements.size(); ++i)
     190        {
     191            const QPair <QString, QString> &lic = licAgreements.at (i);
     192            ilv.setContent (lic.first, lic.second);
     193            if (ilv.exec() == QDialog::Rejected)
     194                return;
     195        }
     196    }
     197    /* Now import all virtual systems */
    99198    if (mImportSettingsWgt->import())
    100199        QIAbstractWizard::accept();
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette