VirtualBox

Ignore:
Timestamp:
Mar 23, 2009 11:16:29 AM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4-OVF: Check all target files if they exists & get confirmation from the user to overwrite them.

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

Legend:

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

    r17450 r18132  
    2929
    3030class QIWidgetValidator;
     31class CAppliance;
    3132
    3233class VBoxExportApplianceWzd : public QIWithRetranslateUI<QIAbstractWizard>,
     
    5253private:
    5354    void addListViewVMItems (const QString& aSelectName);
    54     bool exportVMs();
     55    bool prepareForExportVMs (CAppliance &aAppliance);
     56    bool exportVMs (CAppliance &aAppliance);
    5557
    5658    /* Private member vars */
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxProblemReporter.h

    r18033 r18132  
    148148    /* Generic problem handlers */
    149149    bool askForOverridingFileIfExists (const QString& path, QWidget *aParent = NULL) const;
     150    bool askForOverridingFilesIfExists (const QStringList& aPaths, QWidget *aParent /* = NULL */) const;
    150151
    151152    /* Special problem handlers */
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxExportApplianceWzd.cpp

    r17867 r18132  
    131131void VBoxExportApplianceWzd::accept()
    132132{
    133     /* Check if the file exists already, if yes get confirmation for
    134      * overwriting from the user. */
    135     if (!vboxProblem().askForOverridingFileIfExists (mFileSelector->path(), this))
    136         return;
    137     /* Export the VMs, on success we are finished */
    138     if (exportVMs())
    139         QIAbstractWizard::accept();
     133    CAppliance appliance;
     134    /* Prepare the export of the VM's. */
     135    if (prepareForExportVMs (appliance))
     136    {
     137        QFileInfo fi (mFileSelector->path());
     138        QStringList files;
     139        files << mFileSelector->path();
     140        /* We need to know every filename which will be created, so that we can
     141         * ask the user for confirmation of overwriting. For that we iterating
     142         * over all virtual systems & fetch all descriptions of the type
     143         * HardDiskImage. */
     144        CVirtualSystemDescriptionVector vsds = appliance.GetVirtualSystemDescriptions();
     145        for (int i=0; i < vsds.size(); ++i)
     146        {
     147            QVector<KVirtualSystemDescriptionType> types;
     148            QVector<QString> refs, origValues, configValues, extraConfigValues;
     149
     150            vsds[i].GetDescriptionByType (KVirtualSystemDescriptionType_HardDiskImage, types, refs, origValues, configValues, extraConfigValues);
     151            foreach (const QString &s, origValues)
     152                files << QString ("%1/%2").arg (fi.absolutePath()).arg (s);
     153        }
     154        /* Check if the file exists already, if yes get confirmation for
     155         * overwriting from the user. */
     156        if (!vboxProblem().askForOverridingFilesIfExists (files, this))
     157            return;
     158        /* Export the VMs, on success we are finished */
     159        if (exportVMs(appliance))
     160            QIAbstractWizard::accept();
     161    }
    140162}
    141163
     
    214236}
    215237
    216 bool VBoxExportApplianceWzd::exportVMs()
     238bool VBoxExportApplianceWzd::prepareForExportVMs (CAppliance &aAppliance)
    217239{
    218240    CVirtualBox vbox = vboxGlobal().virtualBox();
    219241    /* Create a appliance object */
    220     CAppliance appliance = vbox.CreateAppliance();
    221     bool fResult = appliance.isOk();
     242    aAppliance = vbox.CreateAppliance();
     243    bool fResult = aAppliance.isOk();
    222244    if (fResult)
    223245    {
     
    234256            {
    235257                /* Add the export description to our appliance object */
    236                 m.Export (appliance);
     258                m.Export (aAppliance);
    237259                fResult = m.isOk();
    238260                if (!fResult)
    239261                {
    240                     vboxProblem().cannotExportAppliance (m, &appliance, this);
     262                    vboxProblem().cannotExportAppliance (m, &aAppliance, this);
    241263                    return false;
    242264                }
     
    245267                break;
    246268        }
    247         /* Proceed if there where no errors */
    248         if (fResult)
    249         {
    250             /* Write the appliance */
    251             CProgress progress = appliance.Write (mFileSelector->path());
    252             fResult = appliance.isOk();
    253             if (fResult)
    254             {
    255                 /* Show some progress, so the user know whats going on */
    256                 vboxProblem().showModalProgressDialog (progress, tr ("Exporting Appliance ..."), this);
    257                 if (!progress.isOk() || progress.GetResultCode() != 0)
    258                 {
    259                     vboxProblem().cannotExportAppliance (progress, &appliance, this);
    260                     return false;
    261                 }
    262                 else
    263                     return true;
    264             }
    265         }
    266269    }
    267270    if (!fResult)
    268         vboxProblem().cannotExportAppliance (&appliance, this);
    269 
     271        vboxProblem().cannotExportAppliance (&aAppliance, this);
     272    return fResult;
     273}
     274
     275bool VBoxExportApplianceWzd::exportVMs (CAppliance &aAppliance)
     276{
     277    /* Write the appliance */
     278    CProgress progress = aAppliance.Write (mFileSelector->path());
     279    bool fResult = aAppliance.isOk();
     280    if (fResult)
     281    {
     282        /* Show some progress, so the user know whats going on */
     283        vboxProblem().showModalProgressDialog (progress, tr ("Exporting Appliance ..."), this);
     284        if (!progress.isOk() || progress.GetResultCode() != 0)
     285        {
     286            vboxProblem().cannotExportAppliance (progress, &aAppliance, this);
     287            return false;
     288        }
     289        else
     290            return true;
     291    }
     292    if (!fResult)
     293        vboxProblem().cannotExportAppliance (&aAppliance, this);
    270294    return false;
    271295}
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp

    r18071 r18132  
    452452}
    453453
     454bool VBoxProblemReporter::askForOverridingFilesIfExists (const QStringList& aPaths, QWidget *aParent /* = NULL */) const
     455{
     456    QStringList existingFiles;
     457    foreach (const QString &file, aPaths)
     458    {
     459        QFileInfo fi (file);
     460        if (fi.exists())
     461            existingFiles << fi.absoluteFilePath();
     462    }
     463    if (existingFiles.size() == 1)
     464        /* If it is only one file use the single question versions above */
     465        return askForOverridingFileIfExists (existingFiles.at (0), aParent);
     466    else if (existingFiles.size() > 1)
     467        return messageYesNo (aParent, Question, tr ("The following files exists already:<br /><br />%1<br /><br />Are you sure you want to replace them? Replacing them will overwrite there contents.").arg (existingFiles.join ("<br />")));
     468    else
     469        return true;
     470}
    454471// Special Problem handlers
    455472/////////////////////////////////////////////////////////////////////////////
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