- Timestamp:
- Aug 10, 2011 10:25:56 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp
r38311 r38393 765 765 bool VBoxSnapshotsWgt::takeSnapshot() 766 766 { 767 /* Prepare result: */ 768 bool fIsValid = true; 769 767 770 /* Get currently chosen item: */ 768 SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast 771 SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0; 769 772 AssertReturn(pItem, (bool)0); 770 773 771 /* Create 'take new snapshot' dialog: */ 772 VBoxTakeSnapshotDlg dlg(this, mMachine); 773 dlg.mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(mMachine.GetOSTypeId())); 774 775 /* Search for the max available filter index: */ 776 int iMaxSnapShotIndex = 0; 777 QString snapShotName = tr("Snapshot %1"); 778 QRegExp regExp(QString("^") + snapShotName.arg("([0-9]+)") + QString("$")); 779 QTreeWidgetItemIterator iterator(mTreeWidget); 780 while (*iterator) 781 { 782 QString snapShot = static_cast<SnapshotWgtItem*>(*iterator)->text(0); 783 int pos = regExp.indexIn(snapShot); 784 if (pos != -1) 785 iMaxSnapShotIndex = regExp.cap(1).toInt() > iMaxSnapShotIndex ? regExp.cap(1).toInt() : iMaxSnapShotIndex; 786 ++iterator; 787 } 788 dlg.mLeName->setText(snapShotName.arg(iMaxSnapShotIndex + 1)); 789 790 /* Show 'take new snapshot' dialog: */ 791 if (dlg.exec() == QDialog::Accepted) 792 { 793 /* Open a direct session (this call will handle all errors): */ 794 bool busy = mSessionState != KSessionState_Unlocked; 795 CSession session = vboxGlobal().openSession(mMachineId, busy /* aExisting */); 796 if (session.isNull()) 797 return false; 798 799 /* Take new snapshot: */ 774 /* Open a session to work with corresponding VM: */ 775 CSession session = vboxGlobal().openSession(mMachineId, 776 mSessionState != KSessionState_Unlocked /* connect to existing */); 777 fIsValid = !session.isNull(); 778 779 if (fIsValid) 780 { 781 /* Get corresponding console object also: */ 800 782 CConsole console = session.GetConsole(); 801 CProgress progress = console.TakeSnapshot(dlg.mLeName->text().trimmed(), dlg.mTeDescription->toPlainText()); 802 if (console.isOk()) 803 { 804 /* Show the progress dialog */ 805 msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_create_90px.png", 806 msgCenter().mainWindowShown(), true); 807 if (progress.GetResultCode() != 0) 808 msgCenter().cannotTakeSnapshot(progress); 809 } 810 else 811 msgCenter().cannotTakeSnapshot(console); 783 /* Remember runtime state: */ 784 bool fAtRuntime = mMachine.GetState() == KMachineState_Running; 785 /* Remember paused state: */ 786 bool fWasPaused = mMachine.GetState() == KMachineState_Paused || 787 mMachine.GetState() == KMachineState_TeleportingPausedVM; 788 789 /* Pause VM if necessary: */ 790 if (fIsValid && fAtRuntime && !fWasPaused) 791 { 792 /* Pausing VM: */ 793 console.Pause(); 794 if (!console.isOk()) 795 { 796 msgCenter().cannotPauseMachine(console); 797 fIsValid = false; 798 } 799 } 800 801 /* Create 'take new snapshot' dialog: */ 802 if (fIsValid) 803 { 804 /* Prepare dialog: */ 805 VBoxTakeSnapshotDlg dlg(this, mMachine); 806 dlg.mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(mMachine.GetOSTypeId())); 807 808 /* Search for the max available snapshot index: */ 809 int iMaxSnapShotIndex = 0; 810 QString snapShotName = tr("Snapshot %1"); 811 QRegExp regExp(QString("^") + snapShotName.arg("([0-9]+)") + QString("$")); 812 QTreeWidgetItemIterator iterator(mTreeWidget); 813 while (*iterator) 814 { 815 QString snapShot = static_cast<SnapshotWgtItem*>(*iterator)->text(0); 816 int pos = regExp.indexIn(snapShot); 817 if (pos != -1) 818 iMaxSnapShotIndex = regExp.cap(1).toInt() > iMaxSnapShotIndex ? regExp.cap(1).toInt() : iMaxSnapShotIndex; 819 ++iterator; 820 } 821 dlg.mLeName->setText(snapShotName.arg(iMaxSnapShotIndex + 1)); 822 823 /* Show 'take new snapshot' dialog: */ 824 if (dlg.exec() == QDialog::Accepted) 825 { 826 /* Take new snapshot: */ 827 CProgress progress = console.TakeSnapshot(dlg.mLeName->text().trimmed(), dlg.mTeDescription->toPlainText()); 828 if (console.isOk()) 829 { 830 /* Show the progress dialog: */ 831 msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_create_90px.png", 832 msgCenter().mainWindowShown(), true); 833 if (progress.GetResultCode() != 0) 834 { 835 msgCenter().cannotTakeSnapshot(progress); 836 fIsValid = false; 837 } 838 } 839 else 840 { 841 msgCenter().cannotTakeSnapshot(console); 842 fIsValid = false; 843 } 844 } 845 } 846 847 /* Resume VM if necessary: */ 848 if (fIsValid && fAtRuntime && !fWasPaused) 849 { 850 /* Resuming VM: */ 851 console.Resume(); 852 if (!console.isOk()) 853 { 854 msgCenter().cannotResumeMachine(console); 855 fIsValid = false; 856 } 857 } 812 858 813 859 /* Unlock machine finally: */ 814 860 session.UnlockMachine(); 815 816 return true; 817 }818 return f alse;861 } 862 863 /* Return result: */ 864 return fIsValid; 819 865 } 820 866
Note:
See TracChangeset
for help on using the changeset viewer.