VirtualBox

Changeset 37406 in vbox


Ignore:
Timestamp:
Jun 10, 2011 1:04:03 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
72203
Message:

FE/Qt: 4908: Create New Virtual Disk wizard: support for copying virtual disks implemented; copying wizard Integrated into Virtual Medium Manager.

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

Legend:

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

    r37374 r37406  
    289289    mNewAction     = new QAction (this);
    290290    mAddAction     = new QAction (this);
     291    mCopyAction    = new QAction (this);
    291292    mRemoveAction  = new QAction (this);
    292293    mReleaseAction = new QAction (this);
     
    295296    connect (mNewAction, SIGNAL (triggered()), this, SLOT (doNewMedium()));
    296297    connect (mAddAction, SIGNAL (triggered()), this, SLOT (doAddMedium()));
     298    connect (mCopyAction, SIGNAL (triggered()), this, SLOT (doCopyMedium()));
    297299    connect (mRemoveAction, SIGNAL (triggered()), this, SLOT (doRemoveMedium()));
    298300    connect (mReleaseAction, SIGNAL (triggered()), this, SLOT (doReleaseMedium()));
     
    307309        ":/hd_add_22px.png", ":/hd_add_16px.png",
    308310        ":/hd_add_disabled_22px.png", ":/hd_add_disabled_16px.png"));
     311    mCopyAction->setIcon(UIIconPool::iconSetFull (
     312        QSize (22, 22), QSize (16, 16),
     313        ":/hd_new_22px.png", ":/hd_new_16px.png",
     314        ":/hd_new_disabled_22px.png", ":/hd_new_disabled_16px.png"));
    309315    mRemoveAction->setIcon(UIIconPool::iconSetFull (
    310316        QSize (22, 22), QSize (16, 16),
     
    320326        ":/refresh_disabled_22px.png", ":/refresh_disabled_16px.png"));
    321327
     328    mActionsContextMenu->addAction (mCopyAction);
    322329    mActionsContextMenu->addAction (mRemoveAction);
    323330    mActionsContextMenu->addAction (mReleaseAction);
     
    348355//    mToolBar->addAction (mNewAction);
    349356//    mToolBar->addAction (mAddAction);
     357    mToolBar->addAction (mCopyAction);
    350358//    mToolBar->addSeparator();
    351359    mToolBar->addAction (mRemoveAction);
     
    358366//    mActionsMenu->addAction (mNewAction);
    359367//    mActionsMenu->addAction (mAddAction);
     368    mActionsMenu->addAction (mCopyAction);
    360369//    mActionsMenu->addSeparator();
    361370    mActionsMenu->addAction (mRemoveAction);
     
    591600    mNewAction->setText (tr ("&New..."));
    592601    mAddAction->setText (tr ("&Add..."));
     602    mCopyAction->setText (tr ("&Copy..."));
    593603    mRemoveAction->setText (tr ("R&emove"));
    594604    mReleaseAction->setText (tr ("Re&lease"));
     
    597607    mNewAction->setShortcut (QKeySequence (QKeySequence::New));
    598608    mAddAction->setShortcut (QKeySequence ("Ins"));
     609    mCopyAction->setShortcut (QKeySequence ("Ctrl+C"));
    599610    mRemoveAction->setShortcut (QKeySequence (QKeySequence::Delete));
    600611    mReleaseAction->setShortcut (QKeySequence ("Ctrl+L"));
     
    603614    mNewAction->setStatusTip (tr ("Create a new virtual hard disk"));
    604615    mAddAction->setStatusTip (tr ("Add an existing medium"));
     616    mCopyAction->setStatusTip (tr ("Copy an existing medium"));
    605617    mRemoveAction->setStatusTip (tr ("Remove the selected medium"));
    606618    mReleaseAction->setStatusTip (tr ("Release the selected medium by detaching it from the machines"));
     
    611623    mAddAction->setToolTip (mAddAction->text().remove ('&') +
    612624        QString (" (%1)").arg (mAddAction->shortcut().toString()));
     625    mCopyAction->setToolTip (mCopyAction->text().remove ('&') +
     626        QString (" (%1)").arg (mCopyAction->shortcut().toString()));
    613627    mRemoveAction->setToolTip (mRemoveAction->text().remove ('&') +
    614628        QString (" (%1)").arg (mRemoveAction->shortcut().toString()));
     
    10291043}
    10301044
     1045void VBoxMediaManagerDlg::doCopyMedium()
     1046{
     1047    /* Get current tree: */
     1048    QTreeWidget *pTree = currentTreeWidget();
     1049    /* Get current item of current tree: */
     1050    MediaItem *pItem = toMediaItem(pTree->currentItem());
     1051
     1052    UINewHDWizard wizard(this /* parent dialog */,
     1053                         tr("%1_copy", "copied virtual disk name").arg(QFileInfo(pItem->text(0)).baseName()) /* default name */,
     1054                         QFileInfo(pItem->location()).absolutePath() /* default path */,
     1055                         0 /* default size, not important for copying */,
     1056                         pItem->medium().medium() /* base medium for copying */);
     1057
     1058    if (wizard.exec() == QDialog::Accepted)
     1059    {
     1060        /* Search for the newly created hard disk: */
     1061        MediaItem *pItem = searchItem(mTwHD, wizard.hardDisk().GetId());
     1062        AssertReturnVoid(pItem);
     1063        /* Select the newly created hard disk: */
     1064        mTwHD->setCurrentItem(pItem);
     1065    }
     1066}
     1067
    10311068void VBoxMediaManagerDlg::doRemoveMedium()
    10321069{
     
    13831420    bool newEnabled     = currentTreeWidgetType() == VBoxDefs::MediumType_HardDisk;
    13841421    bool addEnabled     = true;
     1422    bool copyEnabled    = notInEnum && item && checkMediumFor (item, Action_Copy);
    13851423    bool removeEnabled  = notInEnum && item && checkMediumFor (item, Action_Remove);
    13861424    bool releaseEnabled = item && checkMediumFor (item, Action_Release);
     
    13881426    mNewAction->setEnabled (newEnabled);
    13891427    mAddAction->setEnabled (addEnabled);
     1428    mCopyAction->setEnabled (copyEnabled);
    13901429    mRemoveAction->setEnabled (removeEnabled);
    13911430    mReleaseAction->setEnabled (releaseEnabled);
     
    17061745            }
    17071746            return true;
     1747        }
     1748        case Action_Copy:
     1749        {
     1750            /* False for children: */
     1751            return !aItem->medium().parent();
    17081752        }
    17091753        case Action_Remove:
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.h

    r32760 r37406  
    4040    enum TabIndex { HDTab = 0, CDTab, FDTab };
    4141    enum ItemAction { ItemAction_Added, ItemAction_Updated, ItemAction_Removed };
    42     enum Action { Action_Select, Action_Edit, Action_Remove, Action_Release };
     42    enum Action { Action_Select, Action_Edit, Action_Copy, Action_Remove, Action_Release };
    4343
    4444public:
     
    8585    void doNewMedium();
    8686    void doAddMedium();
     87    void doCopyMedium();
    8788    void doRemoveMedium();
    8889    void doReleaseMedium();
     
    155156    QAction     *mNewAction;
    156157    QAction     *mAddAction;
     158    QAction     *mCopyAction;
    157159    QAction     *mRemoveAction;
    158160    QAction     *mReleaseAction;
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWizard.cpp

    r37374 r37406  
    186186};
    187187
    188 UINewHDWizard::UINewHDWizard(QWidget *pParent, const QString &strDefaultName, const QString &strDefaultPath, qulonglong uDefaultSize)
     188UINewHDWizard::UINewHDWizard(QWidget *pParent, const QString &strDefaultName, const QString &strDefaultPath, qulonglong uDefaultSize, const CMedium &initialHardDisk)
    189189    : QIWizard(pParent)
     190    , m_wizardType(initialHardDisk.isNull() ? UINewHDWizardType_Creating : UINewHDWizardType_Copying)
    190191{
    191192    /* Create & add pages: */
     
    194195    addPage(new UINewHDWizardPageVariant);
    195196    addPage(new UINewHDWizardPageOptions(strDefaultName, strDefaultPath, uDefaultSize));
    196     addPage(new UINewHDWizardPageSummary);
     197    addPage(new UINewHDWizardPageSummary(initialHardDisk));
    197198
    198199    /* Translate wizard: */
     
    222223void UINewHDWizard::retranslateUi()
    223224{
    224     /* Assign wizard title: */
    225     setWindowTitle(tr("Create New Virtual Disk"));
     225    /* Translate wizard: */
     226    switch (wizardType())
     227    {
     228        case UINewHDWizardType_Creating:
     229            setWindowTitle(tr("Create New Virtual Disk"));
     230            break;
     231        case UINewHDWizardType_Copying:
     232            setWindowTitle(tr("Copy Virtual Disk"));
     233            break;
     234        default:
     235            break;
     236    }
    226237}
    227238
     
    237248    Ui::UINewHDWizardPageWelcome::retranslateUi(this);
    238249
    239     /* Set 'welcome' page title: */
    240     setTitle(tr("Welcome to the virtual disk creation wizard"));
     250    /* Translate 'welcome' page: */
     251    switch (wizardType())
     252    {
     253        case UINewHDWizardType_Creating:
     254            setTitle(tr("Welcome to the virtual disk creation wizard"));
     255            m_pLabel->setText("This wizard will help you to create a new virtual disk for your virtual machine.");
     256            break;
     257        case UINewHDWizardType_Copying:
     258            setTitle(tr("Welcome to the virtual disk copying wizard"));
     259            m_pLabel->setText("This wizard will help you to copy a virtual disk.");
     260            break;
     261        default:
     262            break;
     263    }
    241264
    242265    /* Append page text with common part: */
     
    335358    Ui::UINewHDWizardPageFormat::retranslateUi(this);
    336359
    337     /* Set 'format' page title: */
     360    /* Translate 'format' page: */
    338361    setTitle(tr("Virtual disk file type"));
     362    m_pLabel->setText("Please choose the type of file that you would like to use for the new virtual disk. "
     363                      "If you do not need to use it with other virtualization software you can leave this setting unchanged.");
    339364
    340365    /* Translate 'format' buttons: */
     
    429454    Ui::UINewHDWizardPageVariant::retranslateUi(this);
    430455
    431     /* Set 'variant' page title: */
     456    /* Translate 'variant' page: */
    432457    setTitle(tr("Virtual disk storage details"));
     458    m_pLabel->setText("Please choose whether the new virtual disk file should expand as it is used or be created fully expanded.");
    433459
    434460    /* Translate other text: */
     
    542568    Ui::UINewHDWizardPageOptions::retranslateUi(this);
    543569
    544     /* Set 'options' page title: */
    545     setTitle(tr("Virtual disk file location and size"));
     570    /* Translate 'options' page: */
     571    switch (wizardType())
     572    {
     573        case UINewHDWizardType_Creating:
     574            setTitle(tr("Virtual disk file location and size"));
     575            m_pLabel2->setText(tr("Select the size of the virtual disk in megabytes. This size will be reported to the Guest OS as the maximum size of this virtual disk."));
     576            break;
     577        case UINewHDWizardType_Copying:
     578            setTitle(tr("Virtual disk file location"));
     579            m_pLabel2->setText(QString());
     580            break;
     581        default:
     582            break;
     583    }
     584    m_pLabel1->setText(tr("Press the <b>Select</b> button to select the location of a file to store the virtual disk data or type a file name in the entry field."));
    546585}
    547586
     
    550589    /* Retranslate page: */
    551590    retranslateUi();
     591
     592    /* Setup 'options' page: */
     593    switch (wizardType())
     594    {
     595        case UINewHDWizardType_Creating:
     596            m_pLabel2->setVisible(true);
     597            m_pSizeCnt->setVisible(true);
     598            break;
     599        case UINewHDWizardType_Copying:
     600            m_pLabel2->setHidden(true);
     601            m_pSizeCnt->setHidden(true);
     602            break;
     603        default:
     604            break;
     605    }
    552606
    553607    /* Initialize name: */
     
    769823}
    770824
    771 UINewHDWizardPageSummary::UINewHDWizardPageSummary()
     825UINewHDWizardPageSummary::UINewHDWizardPageSummary(const CMedium &initialHardDisk)
     826    : m_initialHardDisk(initialHardDisk)
    772827{
    773828    /* Decorate page: */
     
    789844    Ui::UINewHDWizardPageSummary::retranslateUi(this);
    790845
    791     /* Set 'summary' page title: */
     846    /* Translate 'options' page: */
    792847    setTitle(tr("Summary"));
     848    switch (wizardType())
     849    {
     850        case UINewHDWizardType_Creating:
     851            m_pLabel1->setText(tr("You are going to create a new virtual disk with the following parameters:"));
     852            break;
     853        case UINewHDWizardType_Copying:
     854            m_pLabel1->setText(tr("You are going to create a copied virtual disk with the following parameters:"));
     855            break;
     856        default:
     857            break;
     858    }
     859    m_pLabel2->setText(tr("If the above settings are correct, press the <b>%1</b> button. "
     860                          "Once you press it the new virtual disk file will be created.")
     861                          .arg(VBoxGlobal::replaceHtmlEntities(VBoxGlobal::removeAccelMark(wizard()->buttonText(QWizard::FinishButton)))));
    793862
    794863    /* Compose common summary: */
     
    817886
    818887    m_pSummaryText->setText("<table cellspacing=0 cellpadding=0>" + strSummary + "</table>");
    819 
    820     m_pLabel2->setText(tr("If the above settings are correct, press the <b>%1</b> button. "
    821                           "Once you press it a new virtual disk file will be created.")
    822                           .arg(VBoxGlobal::replaceHtmlEntities(VBoxGlobal::removeAccelMark(wizard()->buttonText(QWizard::FinishButton)))));
    823888}
    824889
     
    852917    qulonglong uSize = field("mediumSize").toULongLong();
    853918
     919    /* Check attributes: */
    854920    AssertReturn(!strMediumPath.isNull(), false);
    855921    AssertReturn(uSize > 0, false);
    856922
     923    /* Get vbox object: */
    857924    CVirtualBox vbox = vboxGlobal().virtualBox();
    858925
     926    /* Create new hard disk: */
     927    CMedium hardDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath);
    859928    CProgress progress;
    860 
    861     CMedium hardDisk = vbox.CreateHardDisk(mediumFormat.GetName(), strMediumPath);
    862 
    863929    if (!vbox.isOk())
    864930    {
     
    867933    }
    868934
    869     progress = hardDisk.CreateBaseStorage(uSize, uVariant);
    870 
     935    /* Depending on dialog type: */
     936    switch (wizardType())
     937    {
     938        case UINewHDWizardType_Creating:
     939        {
     940            /* Create base storage for the new hard disk: */
     941            progress = hardDisk.CreateBaseStorage(uSize, uVariant);
     942            break;
     943        }
     944        case UINewHDWizardType_Copying:
     945        {
     946            /* Copy existing hard disk to the new hard disk: */
     947            progress = m_initialHardDisk.CloneTo(hardDisk, uVariant, CMedium() /* parent */);
     948            break;
     949        }
     950        default:
     951            return false;
     952    }
     953
     954    /* Check for errors: */
    871955    if (!hardDisk.isOk())
    872956    {
     
    874958        return false;
    875959    }
    876 
    877960    vboxProblem().showModalProgressDialog(progress, windowTitle(), ":/progress_media_create_90px.png", this, true);
    878 
    879961    if (progress.GetCanceled())
    880962        return false;
    881 
    882963    if (!progress.isOk() || progress.GetResultCode() != 0)
    883964    {
     
    887968
    888969    /* Inform everybody there is a new medium: */
    889     vboxGlobal().addMedium(VBoxMedium(CMedium(hardDisk), VBoxDefs::MediumType_HardDisk, KMediumState_Created));
    890 
    891     m_HardDisk = hardDisk;
     970    m_hardDisk = hardDisk;
     971    vboxGlobal().addMedium(VBoxMedium(m_hardDisk, VBoxDefs::MediumType_HardDisk, KMediumState_Created));
     972
    892973    return true;
    893974}
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWizard.h

    r37374 r37406  
    3636class UIExclusivenessManager;
    3737
     38/* Wizard type: */
     39enum UINewHDWizardType
     40{
     41    UINewHDWizardType_Creating,
     42    UINewHDWizardType_Copying
     43};
     44
    3845/* New hard disk wizard class: */
    3946class UINewHDWizard : public QIWizard
     
    4451
    4552    /* Constructor: */
    46     UINewHDWizard(QWidget *pParent, const QString &strDefaultName = QString(), const QString &strDefaultPath = QString(), qulonglong uDefaultSize = 0);
     53    UINewHDWizard(QWidget *pParent,
     54                  const QString &strDefaultName = QString(), const QString &strDefaultPath = QString(),
     55                  qulonglong uDefaultSize = 0, const CMedium &initialHardDisk = CMedium());
     56
     57    /* Stuff for wizard type: */
     58    UINewHDWizardType wizardType() const { return m_wizardType; }
    4759
    4860    /* Returns created hard disk: */
     
    5365    /* Translation stuff: */
    5466    void retranslateUi();
     67
     68    /* Wizard type: */
     69    UINewHDWizardType m_wizardType;
    5570};
    5671
     
    6984
    7085    /* Returns parent wizard object: */
    71     UINewHDWizard* wizard() { return qobject_cast<UINewHDWizard*>(QIWizardPage::wizard()); }
     86    UINewHDWizard* wizard() const { return qobject_cast<UINewHDWizard*>(QIWizardPage::wizard()); }
     87
     88    /* Returns parent wizard type: */
     89    UINewHDWizardType wizardType() const { return wizard()->wizardType(); }
    7290};
    7391
     
    267285
    268286    /* Constructor: */
    269     UINewHDWizardPageSummary();
     287    UINewHDWizardPageSummary(const CMedium &initialHardDisk);
    270288
    271289protected:
     
    285303    bool createHardDisk();
    286304
     305    /* Initial hard disk: */
     306    CMedium m_initialHardDisk;
     307
    287308    /* Stuff for 'hardDisk' field: */
    288     CMedium hardDisk() const { return m_HardDisk; }
    289     void setHardDisk(const CMedium &hardDisk) { m_HardDisk = hardDisk; }
    290     CMedium m_HardDisk;
     309    CMedium hardDisk() const { return m_hardDisk; }
     310    void setHardDisk(const CMedium &hardDisk) { m_hardDisk = hardDisk; }
     311    CMedium m_hardDisk;
    291312};
    292313
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWizardPageFormat.ui

    r37331 r37406  
    3939      <bool>true</bool>
    4040     </property>
    41      <property name="text">
    42       <string>&lt;p&gt;Please choose the type of file that you would like to use for the new virtual disk. If you do not need to use this virtual machine with other virtualization software you can leave this setting unchanged.&lt;/p&gt;</string>
    43      </property>
    4441    </widget>
    4542   </item>
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWizardPageOptions.ui

    r37331 r37406  
    3939      <bool>true</bool>
    4040     </property>
    41      <property name="text">
    42       <string>&lt;p&gt;Press the &lt;b&gt;Select&lt;/b&gt; button to select the location of a file to store the virtual disk data or type a file name in the entry field.&lt;/p&gt;</string>
    43      </property>
    4441    </widget>
    4542   </item>
     
    6764     <property name="wordWrap">
    6865      <bool>true</bool>
    69      </property>
    70      <property name="text">
    71       <string>&lt;p&gt;Select the size of the virtual disk in megabytes. This size will be reported to the Guest OS as the maximum size of this virtual disk.&lt;/p&gt;</string>
    7266     </property>
    7367    </widget>
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWizardPageSummary.ui

    r37331 r37406  
    3838     <property name="wordWrap">
    3939      <bool>true</bool>
    40      </property>
    41      <property name="text">
    42       <string>You are going to create a new virtual disk with the following parameters:</string>
    4340     </property>
    4441    </widget>
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWizardPageVariant.ui

    r37331 r37406  
    3939      <bool>true</bool>
    4040     </property>
    41      <property name="text">
    42       <string>&lt;p&gt;Please choose whether the new virtual disk file should expand as it is used or be created fully expanded.&lt;/p&gt;</string>
    43      </property>
    4441    </widget>
    4542   </item>
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/newhd/UINewHDWizardPageWelcome.ui

    r37331 r37406  
    3939      <bool>true</bool>
    4040     </property>
    41      <property name="text">
    42       <string>&lt;p&gt;This wizard will help you to create a new virtual disk for your virtual machine.&lt;/p&gt;</string>
    43      </property>
    4441    </widget>
    4542   </item>
Note: See TracChangeset for help on using the changeset viewer.

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