VirtualBox

Ignore:
Timestamp:
Nov 10, 2009 3:49:35 PM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: Force-remounting support.

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

Legend:

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

    r24500 r24557  
    256256                             KStorageBus aBus, LONG aChannel, LONG aDevice);
    257257
    258     void cannotMountMedium (QWidget *aParent, const CMachine &aMachine, const VBoxMedium &aMedium);
    259     void cannotUnmountMedium (QWidget *aParent, const CMachine &aMachine, const VBoxMedium &aMedium);
     258    int cannotRemountMedium (QWidget *aParent, const CMachine &aMachine, const VBoxMedium &aMedium, bool aMount, bool aRetry);
    260259    void cannotOpenMedium (QWidget *aParent, const CVirtualBox &aVBox,
    261260                           VBoxDefs::MediumType aType, const QString &aLocation);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r24511 r24557  
    198198struct MountTarget
    199199{
    200     MountTarget() : name (QString ("")), port (0), device (0), id (QString ("")), type (VBoxDefs::MediumType_Invalid) {}
     200    MountTarget() : name (QString ("")), port (0), device (0), id (QString()), type (VBoxDefs::MediumType_Invalid) {}
    201201    MountTarget (const QString &aName, LONG aPort, LONG aDevice)
    202         : name (aName), port (aPort), device (aDevice), id (QString ("")), type (VBoxDefs::MediumType_Invalid) {}
     202        : name (aName), port (aPort), device (aDevice), id (QString()), type (VBoxDefs::MediumType_Invalid) {}
    203203    MountTarget (const QString &aName, LONG aPort, LONG aDevice, const QString &aId)
    204204        : name (aName), port (aPort), device (aDevice), id (aId), type (VBoxDefs::MediumType_Invalid) {}
    205     MountTarget (const QString &aName, LONG aPort, LONG aDevice, const QString &aId, VBoxDefs::MediumType aType)
    206         : name (aName), port (aPort), device (aDevice), id (aId), type (aType) {}
     205    MountTarget (const QString &aName, LONG aPort, LONG aDevice, VBoxDefs::MediumType aType)
     206        : name (aName), port (aPort), device (aDevice), id (QString()), type (aType) {}
    207207    QString name;
    208208    LONG port;
     
    327327        *aSelf = this;
    328328
     329    /* Cache IMedium data! */
     330    vboxGlobal().startEnumeratingMedia();
     331
    329332#if !(defined (Q_WS_WIN) || defined (Q_WS_MAC))
    330333    /* The default application icon (will change to the VM-specific icon in
     
    10541057
    10551058    if (!vbox.isOk())
    1056         return vboxProblem().cannotOpenMedium (this, vbox,
    1057                                                VBoxDefs::MediumType_DVD, aSource);
     1059        return vboxProblem().cannotOpenMedium (this, vbox, VBoxDefs::MediumType_DVD, aSource);
    10581060
    10591061    Assert (!uuid.isNull());
     
    10881090    if (!ctrName.isNull())
    10891091    {
     1092        bool isMounted = false;
     1093
     1094        /* Mount medium to the predefined port/device */
    10901095        m.MountMedium (ctrName, ctrPort, ctrDevice, uuid, false /* force */);
    1091         AssertWrapperOk (m);
    10921096        if (m.isOk())
    1093         {
    1094             if (mIsAutoSaveMedia)
     1097            isMounted = true;
     1098        else
     1099        {
     1100            /* Ask for force mounting */
     1101            if (vboxProblem().cannotRemountMedium (this, m, VBoxMedium (image, VBoxDefs::MediumType_DVD), true /* mount? */, true /* retry? */) == QIMessageBox::Ok)
    10951102            {
    1096                 m.SaveSettings();
    1097                 if (!m.isOk())
    1098                     vboxProblem().cannotSaveMachineSettings (m);
     1103                /* Force mount medium to the predefined port/device */
     1104                m.MountMedium (ctrName, ctrPort, ctrDevice, uuid, true /* force */);
     1105                if (m.isOk())
     1106                    isMounted = true;
     1107                else
     1108                    vboxProblem().cannotRemountMedium (this, m, VBoxMedium (image, VBoxDefs::MediumType_DVD), true /* mount? */, false /* retry? */);
    10991109            }
    11001110        }
     1111
     1112        /* Save medium mounted at runtime */
     1113        if (isMounted && mIsAutoSaveMedia)
     1114        {
     1115            m.SaveSettings();
     1116            if (!m.isOk())
     1117                vboxProblem().cannotSaveMachineSettings (m);
     1118        }
    11011119    }
    11021120    else
    1103     {
    11041121        vboxProblem().cannotMountGuestAdditions (m.GetName());
    1105     }
    11061122}
    11071123
     
    22702286                                                                      attachment.GetPort(),
    22712287                                                                      attachment.GetDevice(),
    2272                                                                       QString (""),
    22732288                                                                      mediumType)));
    22742289            connect (callVMMAction, SIGNAL (triggered (bool)), this, SLOT (mountMedium()));
     
    23442359void VBoxConsoleWnd::mountMedium()
    23452360{
     2361    /* Get sender action */
    23462362    QAction *action = qobject_cast <QAction*> (sender());
    23472363    Assert (action);
    23482364
     2365    /* Get current machine */
     2366    CMachine machine = mSession.GetMachine();
     2367
     2368    /* Get mount-target */
    23492369    MountTarget target = action->data().value <MountTarget>();
    2350     CMachine machine = mSession.GetMachine();
    2351     CMediumAttachment attachment = machine.GetMediumAttachment (target.name, target.port, target.device);
    2352     CMedium medium = attachment.GetMedium();
    2353 
    2354     if (target.type != VBoxDefs::MediumType_Invalid)
     2370
     2371    /* Current mount-target attributes */
     2372    CMediumAttachment currentAttachment = machine.GetMediumAttachment (target.name, target.port, target.device);
     2373    CMedium currentMedium = currentAttachment.GetMedium();
     2374    QString currentId = currentMedium.isNull() ? QString ("") : currentMedium.GetId();
     2375
     2376    /* New mount-target attributes */
     2377    QString newId = QString ("");
     2378    bool selectWithMediaManager = target.type != VBoxDefs::MediumType_Invalid;
     2379
     2380    /* Open Virtual Media Manager to select image id */
     2381    if (selectWithMediaManager)
    23552382    {
    23562383        /* Search for already used images */
    23572384        QStringList usedImages;
    2358         const CMediumAttachmentVector &attachments = mSession.GetMachine().GetMediumAttachments();
    2359         foreach (const CMediumAttachment &index, attachments)
    2360         {
    2361             if (index != attachment && !index.GetMedium().isNull() && !index.GetMedium().GetHostDrive())
    2362                 usedImages << index.GetMedium().GetId();
     2385        foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments())
     2386        {
     2387            CMedium medium = attachment.GetMedium();
     2388            if (attachment != currentAttachment && !medium.isNull() && !medium.GetHostDrive())
     2389                usedImages << medium.GetId();
    23632390        }
    23642391        /* Open VMM Dialog */
    23652392        VBoxMediaManagerDlg dlg (this);
    2366         dlg.setup (target.type, true /* do select? */, true /* do refresh? */,
    2367                    mSession.GetMachine(), QString(), true, usedImages);
     2393        dlg.setup (target.type, true /* select? */, true /* refresh? */, machine, currentId, true, usedImages);
    23682394        if (dlg.exec() == QDialog::Accepted)
    2369             target.id = dlg.selectedId();
     2395            newId = dlg.selectedId();
    23702396        else return;
    23712397    }
    2372 
    2373     machine.MountMedium (target.name, target.port, target.device,
    2374                          target.id.isEmpty() || medium.isNull() || medium.GetId() != target.id ||
    2375                          target.type != VBoxDefs::MediumType_Invalid ? target.id : QString (""), false /* force */);
     2398    /* Use medium which was sent */
     2399    else if (!target.id.isNull() && target.id != currentId)
     2400        newId = target.id;
     2401
     2402    bool mount = !newId.isEmpty();
     2403
     2404    /* Remount medium to the predefined port/device */
     2405    machine.MountMedium (target.name, target.port, target.device, newId, false /* force */);
     2406    if (!machine.isOk())
     2407    {
     2408        /* Ask for force remounting */
     2409        if (vboxProblem().cannotRemountMedium (this, machine, vboxGlobal().findMedium (mount ? newId : currentId), mount, true /* retry? */) == QIMessageBox::Ok)
     2410        {
     2411            /* Force remount medium to the predefined port/device. */
     2412            machine.MountMedium (target.name, target.port, target.device, newId, true /* force */);
     2413            if (!machine.isOk())
     2414                vboxProblem().cannotRemountMedium (this, machine, vboxGlobal().findMedium (mount ? newId : currentId), mount, false /* retry? */);
     2415        }
     2416    }
    23762417}
    23772418
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp

    r24511 r24557  
    12051205                    if (!machine.isOk())
    12061206                    {
    1207                         CStorageController controller = machine.GetStorageControllerByName (attachment.GetController());
    1208                         vboxProblem().cannotUnmountMedium (this, machine, aMedium);
     1207                        vboxProblem().cannotRemountMedium (this, machine, aMedium, false /* mount? */, false /* retry? */);
    12091208                        success = false;
    12101209                        break;
     
    12271226                    if (!machine.isOk())
    12281227                    {
    1229                         CStorageController controller = machine.GetStorageControllerByName (attachment.GetController());
    1230                         vboxProblem().cannotUnmountMedium (this, machine, aMedium);
     1228                        vboxProblem().cannotRemountMedium (this, machine, aMedium, false /* mount? */, false /* retry? */);
    12311229                        success = false;
    12321230                        break;
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxProblemReporter.cpp

    r24500 r24557  
    11871187}
    11881188
    1189 void VBoxProblemReporter::cannotMountMedium (QWidget *aParent, const CMachine &aMachine,
    1190                                              const VBoxMedium &aMedium)
     1189int VBoxProblemReporter::cannotRemountMedium (QWidget *aParent, const CMachine &aMachine,
     1190                                              const VBoxMedium &aMedium, bool aMount, bool aRetry)
    11911191{
    11921192    /** @todo (translation-related): the gender of "the" in translations
    11931193     * will depend on the gender of aMedium.type(). */
    1194     message (aParent, Error,
    1195              tr ("Failed to mount the %1 <nobr><b>%2</b></nobr> "
    1196                  "to the machine <b>%3</b>.")
    1197                  .arg (mediumToAccusative (aMedium.type(), aMedium.isHostDrive()))
    1198                  .arg (aMedium.isHostDrive() ? aMedium.name() : aMedium.location())
    1199                  .arg (CMachine (aMachine).GetName()),
    1200              formatErrorInfo (aMachine));
    1201 }
    1202 
    1203 void VBoxProblemReporter::cannotUnmountMedium (QWidget *aParent, const CMachine &aMachine,
    1204                                                const VBoxMedium &aMedium)
    1205 {
    1206     /** @todo (translation-related): the gender of "the" in translations
    1207      * will depend on the gender of aMedium.type(). */
    1208     message (aParent, Error,
    1209              tr ("Failed to unmount the %1 <nobr><b>%2</b></nobr> "
    1210                  "from the machine <b>%3</b>.")
    1211                  .arg (mediumToAccusative (aMedium.type(), aMedium.isHostDrive()))
    1212                  .arg (aMedium.isHostDrive() ? aMedium.name() : aMedium.location())
    1213                  .arg (CMachine (aMachine).GetName()),
    1214              formatErrorInfo (aMachine));
     1194    QString text;
     1195    if (aMount)
     1196    {
     1197        text = tr ("Unable to mount the %1 <nobr><b>%2</b></nobr> to the machine <b>%3</b>.");
     1198        if (aRetry) text += tr (" Would you like to forcedly mount this medium?");
     1199    }
     1200    else
     1201    {
     1202        text = tr ("Unable to unmount the %1 <nobr><b>%2</b></nobr> from the machine <b>%3</b>.");
     1203        if (aRetry) text += tr (" Would you like to forcedly unmount this medium?");
     1204    }
     1205    if (aRetry)
     1206    {
     1207        return messageOkCancel (aParent, Question, text
     1208            .arg (mediumToAccusative (aMedium.type(), aMedium.isHostDrive()))
     1209            .arg (aMedium.isHostDrive() ? aMedium.name() : aMedium.location())
     1210            .arg (CMachine (aMachine).GetName()),
     1211            formatErrorInfo (aMachine),
     1212            0 /* Auto Confirm ID */,
     1213            tr ("Force Unmount"));
     1214    }
     1215    else
     1216    {
     1217        return message (aParent, Error, text
     1218            .arg (mediumToAccusative (aMedium.type(), aMedium.isHostDrive()))
     1219            .arg (aMedium.isHostDrive() ? aMedium.name() : aMedium.location())
     1220            .arg (CMachine (aMachine).GetName()),
     1221            formatErrorInfo (aMachine));
     1222    }
    12151223}
    12161224
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxVMFirstRunWzd.cpp

    r24493 r24557  
    110110        QIAbstractWizard::accept();
    111111    else
    112         vboxProblem().cannotMountMedium (this, mMachine, vboxGlobal().findMedium (mCbMedia->id()));
     112        vboxProblem().cannotRemountMedium (this, mMachine, vboxGlobal().findMedium (mCbMedia->id()), true /* mount? */, false /* retry? */);
    113113}
    114114
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