VirtualBox

Changeset 24564 in vbox


Ignore:
Timestamp:
Nov 10, 2009 7:08:40 PM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: VBoxConsoleWND: Take Snapshot name generation now takes into account whole snapshots tree.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r24559 r24564  
    212212};
    213213Q_DECLARE_METATYPE (MountTarget);
     214
     215int searchMaxSnapshotIndex (const CMachine &aMachine, const CSnapshot &aSnapshot, const QString &aNameTemplate)
     216{
     217    int maxIndex = 0;
     218    QRegExp regExp (QString ("^") + aNameTemplate.arg ("([0-9]+)") + QString ("$"));
     219    if (!aSnapshot.isNull())
     220    {
     221        /* Check the current snapshot name */
     222        QString name = aSnapshot.GetName();
     223        int pos = regExp.indexIn (name);
     224        if (pos != -1)
     225            maxIndex = regExp.cap (1).toInt() > maxIndex ? regExp.cap (1).toInt() : maxIndex;
     226        /* Traversing all the snapshot children */
     227        foreach (const CSnapshot &child, aSnapshot.GetChildren())
     228        {
     229            int maxIndexOfChildren = searchMaxSnapshotIndex (aMachine, child, aNameTemplate);
     230            maxIndex = maxIndexOfChildren > maxIndex ? maxIndexOfChildren : maxIndex;
     231        }
     232    }
     233    return maxIndex;
     234}
    214235
    215236/** \class VBoxConsoleWnd
     
    20102031
    20112032    /* search for the max available filter index */
    2012     int maxSnapShotIndex = 0;
    2013     QString snapShotName = tr ("Snapshot %1");
    2014     QRegExp regExp (QString ("^") + snapShotName.arg ("([0-9]+)") + QString ("$"));
    2015     CSnapshot index = machine.GetSnapshot (QString::null);
    2016     while (!index.isNull())
    2017     {
    2018         /* Check the current snapshot name */
    2019         QString name = index.GetName();
    2020         int pos = regExp.indexIn (name);
    2021         if (pos != -1)
    2022             maxSnapShotIndex = regExp.cap (1).toInt() > maxSnapShotIndex ?
    2023                                regExp.cap (1).toInt() : maxSnapShotIndex;
    2024         /* Traversing to the next child */
    2025         CSnapshotVector c = index.GetChildren();
    2026         if (c.size() > 0)
    2027             index = c [0];
    2028         else
    2029             break;
    2030     }
    2031     dlg.mLeName->setText (snapShotName.arg (maxSnapShotIndex + 1));
     2033    QString nameTemplate = tr ("Snapshot %1");
     2034    int maxSnapshotIndex = searchMaxSnapshotIndex (machine, machine.GetSnapshot (QString()), nameTemplate);
     2035    dlg.mLeName->setText (nameTemplate.arg (++ maxSnapshotIndex));
    20322036
    20332037    if (dlg.exec() == QDialog::Accepted)
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