Changeset 63835 in vbox
- Timestamp:
- Sep 14, 2016 3:01:23 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r63834 r63835 413 413 , m_pSnapshotItemActionGroup(new QActionGroup(this)) 414 414 , m_pCurrentStateItemActionGroup(new QActionGroup(this)) 415 , m_pActionTakeSnapshot(new QAction(m_pCurrentStateItemActionGroup)) 415 416 , m_pActionRestoreSnapshot(new QAction(m_pSnapshotItemActionGroup)) 416 417 , m_pActionDeleteSnapshot(new QAction(m_pSnapshotItemActionGroup)) 417 418 , m_pActionShowSnapshotDetails(new QAction(m_pSnapshotItemActionGroup)) 418 , m_pActionTakeSnapshot(new QAction(m_pCurrentStateItemActionGroup))419 419 , m_pActionCloneSnapshot(new QAction(m_pCurrentStateItemActionGroup)) 420 420 , m_fShapshotOperationsAllowed(false) … … 466 466 467 467 /* Setup action icons: */ 468 m_pActionTakeSnapshot->setIcon(UIIconPool::iconSetFull( 469 ":/snapshot_take_22px.png", ":/snapshot_take_16px.png", 470 ":/snapshot_take_disabled_22px.png", ":/snapshot_take_disabled_16px.png")); 468 471 m_pActionRestoreSnapshot->setIcon(UIIconPool::iconSetFull( 469 472 ":/snapshot_restore_22px.png", ":/snapshot_restore_16px.png", … … 475 478 ":/snapshot_show_details_22px.png", ":/snapshot_show_details_16px.png", 476 479 ":/snapshot_show_details_disabled_22px.png", ":/snapshot_details_show_disabled_16px.png")); 477 m_pActionTakeSnapshot->setIcon(UIIconPool::iconSetFull(478 ":/snapshot_take_22px.png", ":/snapshot_take_16px.png",479 ":/snapshot_take_disabled_22px.png", ":/snapshot_take_disabled_16px.png"));480 480 m_pActionCloneSnapshot->setIcon(UIIconPool::iconSetFull( 481 481 ":/vm_clone_22px.png", ":/vm_clone_16px.png", 482 482 ":/vm_clone_disabled_22px.png", ":/vm_clone_disabled_16px.png")); 483 483 /* Setup action shortcuts: */ 484 m_pActionTakeSnapshot->setShortcut(QString("Ctrl+Shift+S")); 484 485 m_pActionRestoreSnapshot->setShortcut(QString("Ctrl+Shift+R")); 485 486 m_pActionDeleteSnapshot->setShortcut(QString("Ctrl+Shift+D")); 486 487 m_pActionShowSnapshotDetails->setShortcut(QString("Ctrl+Space")); 487 m_pActionTakeSnapshot->setShortcut(QString("Ctrl+Shift+S"));488 488 m_pActionCloneSnapshot->setShortcut(QString("Ctrl+Shift+C")); 489 489 … … 549 549 550 550 /* Translate actions names: */ 551 m_pActionTakeSnapshot->setText(tr("Take &Snapshot")); 551 552 m_pActionRestoreSnapshot->setText(tr("&Restore Snapshot")); 552 553 m_pActionDeleteSnapshot->setText(tr("&Delete Snapshot")); 553 554 m_pActionShowSnapshotDetails->setText(tr("S&how Details")); 554 m_pActionTakeSnapshot->setText(tr("Take &Snapshot"));555 555 m_pActionCloneSnapshot->setText(tr("&Clone...")); 556 556 /* Translate actions status-tips: */ 557 m_pActionTakeSnapshot->setStatusTip(tr("Take a snapshot of the current virtual machine state")); 557 558 m_pActionRestoreSnapshot->setStatusTip(tr("Restore selected snapshot of the virtual machine")); 558 559 m_pActionDeleteSnapshot->setStatusTip(tr("Delete selected snapshot of the virtual machine")); 559 560 m_pActionShowSnapshotDetails->setStatusTip(tr("Display a window with selected snapshot details")); 560 m_pActionTakeSnapshot->setStatusTip(tr("Take a snapshot of the current virtual machine state"));561 561 m_pActionCloneSnapshot->setStatusTip(tr("Clone selected virtual machine")); 562 562 } … … 592 592 593 593 /* Enable/disable snapshot operations: */ 594 m_pActionTakeSnapshot->setEnabled( 595 m_fShapshotOperationsAllowed 596 && ( ( fCanTakeDeleteSnapshot 597 && m_pCurrentSnapshotItem 598 && pSnapshotItem 599 && pSnapshotItem->isCurrentStateItem()) 600 || ( pSnapshotItem 601 && !m_pCurrentSnapshotItem)) 602 ); 594 603 m_pActionRestoreSnapshot->setEnabled( 595 604 !fBusy … … 610 619 && !pSnapshotItem->isCurrentStateItem() 611 620 ); 612 m_pActionTakeSnapshot->setEnabled(613 m_fShapshotOperationsAllowed614 && ( ( fCanTakeDeleteSnapshot615 && m_pCurrentSnapshotItem616 && pSnapshotItem617 && pSnapshotItem->isCurrentStateItem())618 || ( pSnapshotItem619 && !m_pCurrentSnapshotItem))620 );621 621 m_pActionCloneSnapshot->setEnabled( 622 622 !fBusy … … 688 688 { 689 689 /* As snapshot-restore procedure: */ 690 sltRestoreSnapshot(true /* suppress non-critical warnings */); 691 } 692 } 693 694 void UISnapshotPane::sltRestoreSnapshot(bool fSuppressNonCriticalWarnings /* = false */) 690 restoreSnapshot(true /* suppress non-critical warnings */); 691 } 692 } 693 694 void UISnapshotPane::sltMachineDataChange(QString strMachineID) 695 { 696 /* Make sure it's our VM: */ 697 if (strMachineID != m_strMachineID) 698 return; 699 700 /* Prevent snapshot editing in the meantime: */ 701 QWriteLocker locker(&m_lockReadWrite); 702 703 /* Recache state current item: */ 704 currentStateItem()->recache(); 705 } 706 707 void UISnapshotPane::sltMachineStateChange(QString strMachineID, KMachineState enmState) 708 { 709 /* Make sure it's our VM: */ 710 if (strMachineID != m_strMachineID) 711 return; 712 713 /* Prevent snapshot editing in the meantime: */ 714 QWriteLocker locker(&m_lockReadWrite); 715 716 /* Recache new machine state: */ 717 currentStateItem()->recache(); 718 currentStateItem()->updateCurrentState(enmState); 719 } 720 721 void UISnapshotPane::sltSessionStateChange(QString strMachineID, KSessionState enmState) 722 { 723 /* Make sure it's our VM: */ 724 if (strMachineID != m_strMachineID) 725 return; 726 727 /* Prevent snapshot editing in the meantime: */ 728 QWriteLocker locker(&m_lockReadWrite); 729 730 /* Recache new session state: */ 731 m_enmSessionState = enmState; 732 sltCurrentItemChanged(m_pTreeWidget->currentItem()); 733 } 734 735 void UISnapshotPane::sltUpdateSnapshotsAge() 736 { 737 /* Stop timer if active: */ 738 if (m_ageUpdateTimer.isActive()) 739 m_ageUpdateTimer.stop(); 740 741 /* Search for smallest snapshot age to optimize timer timeout: */ 742 const SnapshotAgeFormat age = traverseSnapshotAge(m_pTreeWidget->invisibleRootItem()); 743 switch (age) 744 { 745 case SnapshotAgeFormat_InSeconds: m_ageUpdateTimer.setInterval(5 * 1000); break; 746 case SnapshotAgeFormat_InMinutes: m_ageUpdateTimer.setInterval(60 * 1000); break; 747 case SnapshotAgeFormat_InHours: m_ageUpdateTimer.setInterval(60 * 60 * 1000); break; 748 case SnapshotAgeFormat_InDays: m_ageUpdateTimer.setInterval(24 * 60 * 60 * 1000); break; 749 default: m_ageUpdateTimer.setInterval(0); break; 750 } 751 752 /* Restart timer if necessary: */ 753 if (m_ageUpdateTimer.interval() > 0) 754 m_ageUpdateTimer.start(); 755 } 756 757 bool UISnapshotPane::takeSnapshot() 758 { 759 /* Simulate try-catch block: */ 760 bool fSuccess = false; 761 do 762 { 763 /* Open a session (this call will handle all errors): */ 764 CSession comSession; 765 if (m_enmSessionState != KSessionState_Unlocked) 766 comSession = vboxGlobal().openExistingSession(m_strMachineID); 767 else 768 comSession = vboxGlobal().openSession(m_strMachineID); 769 if (comSession.isNull()) 770 break; 771 772 /* Simulate try-catch block: */ 773 do 774 { 775 /* Get corresponding machine object: */ 776 CMachine comMachine = comSession.GetMachine(); 777 778 /* Create take-snapshot dialog: */ 779 QWidget *pDlgParent = windowManager().realParentWindow(this); 780 QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(pDlgParent, m_comMachine); 781 windowManager().registerNewParent(pDlg, pDlgParent); 782 783 // TODO: Assign corresponding icon through sub-dialog API: */ 784 pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m_comMachine.GetOSTypeId())); 785 786 /* Search for the max available snapshot index: */ 787 int iMaxSnapShotIndex = 0; 788 QString strSnapshotName = tr("Snapshot %1"); 789 QRegExp regExp(QString("^") + strSnapshotName.arg("([0-9]+)") + QString("$")); 790 QTreeWidgetItemIterator iterator(m_pTreeWidget); 791 while (*iterator) 792 { 793 QString strSnapshot = static_cast<SnapshotWgtItem*>(*iterator)->text(0); 794 int iPos = regExp.indexIn(strSnapshot); 795 if (iPos != -1) 796 iMaxSnapShotIndex = regExp.cap(1).toInt() > iMaxSnapShotIndex ? regExp.cap(1).toInt() : iMaxSnapShotIndex; 797 ++iterator; 798 } 799 // TODO: Assign corresponding snapshot name through sub-dialog API: */ 800 pDlg->mLeName->setText(strSnapshotName.arg(iMaxSnapShotIndex + 1)); 801 802 /* Show Take Snapshot dialog: */ 803 if (pDlg->exec() != QDialog::Accepted) 804 { 805 /* Cleanup dialog if it wasn't destroyed in own loop: */ 806 if (pDlg) 807 delete pDlg; 808 break; 809 } 810 811 /* Acquire real snapshot name/description: */ 812 const QString strRealSnapshotName = pDlg->mLeName->text().trimmed(); 813 const QString strRealSnapshotDescription = pDlg->mTeDescription->toPlainText(); 814 815 /* Cleanup dialog: */ 816 delete pDlg; 817 818 /* Take snapshot: */ 819 QString strSnapshotID; 820 CProgress comProgress = comMachine.TakeSnapshot(strRealSnapshotName, strRealSnapshotDescription, true, strSnapshotID); 821 if (!comMachine.isOk()) 822 { 823 msgCenter().cannotTakeSnapshot(comMachine, m_comMachine.GetName()); 824 break; 825 } 826 827 /* Show snapshot taking progress: */ 828 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_create_90px.png"); 829 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 830 { 831 msgCenter().cannotTakeSnapshot(comProgress, m_comMachine.GetName()); 832 break; 833 } 834 835 /* Mark snapshot restoring successful: */ 836 fSuccess = true; 837 } 838 while (0); 839 840 /* Cleanup try-catch block: */ 841 comSession.UnlockMachine(); 842 } 843 while (0); 844 845 /* Return result: */ 846 return fSuccess; 847 } 848 849 bool UISnapshotPane::restoreSnapshot(bool fSuppressNonCriticalWarnings /* = false */) 850 { 851 /* Simulate try-catch block: */ 852 bool fSuccess = false; 853 do 854 { 855 /* Acquire currently chosen snapshot item: */ 856 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem()); 857 AssertPtr(pSnapshotItem); 858 if (!pSnapshotItem) 859 break; 860 861 /* Get corresponding snapshot: */ 862 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 863 Assert(!comSnapshot.isNull()); 864 if (comSnapshot.isNull()) 865 break; 866 867 /* If non-critical warnings are not hidden or current state is changed: */ 868 if (!fSuppressNonCriticalWarnings || m_comMachine.GetCurrentStateModified()) 869 { 870 /* Ask if user really wants to restore the selected snapshot: */ 871 int iResultCode = msgCenter().confirmSnapshotRestoring(comSnapshot.GetName(), m_comMachine.GetCurrentStateModified()); 872 if (iResultCode & AlertButton_Cancel) 873 break; 874 875 /* Ask if user also wants to create new snapshot of current state which is changed: */ 876 if (iResultCode & AlertOption_CheckBox) 877 { 878 /* Take snapshot of changed current state: */ 879 m_pTreeWidget->setCurrentItem(currentStateItem()); 880 if (!takeSnapshot()) 881 break; 882 } 883 } 884 885 /* Open a direct session (this call will handle all errors): */ 886 CSession comSession = vboxGlobal().openSession(m_strMachineID); 887 if (comSession.isNull()) 888 break; 889 890 /* Simulate try-catch block: */ 891 do 892 { 893 /* Restore chosen snapshot: */ 894 CMachine comMachine = comSession.GetMachine(); 895 CProgress comProgress = comMachine.RestoreSnapshot(comSnapshot); 896 if (!comMachine.isOk()) 897 { 898 msgCenter().cannotRestoreSnapshot(comMachine, comSnapshot.GetName(), m_comMachine.GetName()); 899 break; 900 } 901 902 /* Show snapshot restoring progress: */ 903 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_restore_90px.png"); 904 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 905 { 906 msgCenter().cannotRestoreSnapshot(comProgress, comSnapshot.GetName(), m_comMachine.GetName()); 907 break; 908 } 909 910 /* Mark snapshot restoring successful: */ 911 fSuccess = true; 912 } 913 while (0); 914 915 /* Cleanup try-catch block: */ 916 comSession.UnlockMachine(); 917 } 918 while (0); 919 920 /* Return result: */ 921 return fSuccess; 922 } 923 924 bool UISnapshotPane::deleteSnapshot() 925 { 926 /* Simulate try-catch block: */ 927 bool fSuccess = false; 928 do 929 { 930 /* Acquire currently chosen snapshot item: */ 931 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem()); 932 AssertPtr(pSnapshotItem); 933 if (!pSnapshotItem) 934 break; 935 936 /* Get corresponding snapshot: */ 937 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 938 Assert(!comSnapshot.isNull()); 939 if (comSnapshot.isNull()) 940 break; 941 942 /* Ask if user really wants to remove the selected snapshot: */ 943 if (!msgCenter().confirmSnapshotRemoval(comSnapshot.GetName())) 944 break; 945 946 /** @todo check available space on the target filesystem etc etc. */ 947 #if 0 948 if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(comSnapshot.GetName(), 949 "/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi", 950 "59 GiB", 951 "15 GiB")) 952 break; 953 #endif 954 955 /* Open a session (this call will handle all errors): */ 956 CSession comSession; 957 if (m_enmSessionState != KSessionState_Unlocked) 958 comSession = vboxGlobal().openExistingSession(m_strMachineID); 959 else 960 comSession = vboxGlobal().openSession(m_strMachineID); 961 if (comSession.isNull()) 962 break; 963 964 /* Simulate try-catch block: */ 965 do 966 { 967 /* Remove chosen snapshot: */ 968 CMachine comMachine = comSession.GetMachine(); 969 CProgress comProgress = comMachine.DeleteSnapshot(pSnapshotItem->snapshotID()); 970 if (!comMachine.isOk()) 971 { 972 msgCenter().cannotRemoveSnapshot(comMachine, comSnapshot.GetName(), m_comMachine.GetName()); 973 break; 974 } 975 976 /* Show snapshot removing progress: */ 977 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_discard_90px.png"); 978 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 979 { 980 msgCenter().cannotRemoveSnapshot(comProgress, comSnapshot.GetName(), m_comMachine.GetName()); 981 break; 982 } 983 984 /* Mark snapshot removing successful: */ 985 fSuccess = true; 986 } 987 while (0); 988 989 /* Cleanup try-catch block: */ 990 comSession.UnlockMachine(); 991 } 992 while (0); 993 994 /* Return result: */ 995 return fSuccess; 996 } 997 998 void UISnapshotPane::showSnapshotDetails() 695 999 { 696 1000 /* Acquire currently chosen snapshot item: */ … … 698 1002 AssertReturnVoid(pSnapshotItem); 699 1003 700 /* Get desired snapshot: */ 701 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 702 AssertReturnVoid(!comSnapshot.isNull()); 703 704 /* Ask the user if he really wants to restore the snapshot: */ 705 int iResultCode = AlertButton_Ok; 706 if (!fSuppressNonCriticalWarnings || m_comMachine.GetCurrentStateModified()) 707 { 708 iResultCode = msgCenter().confirmSnapshotRestoring(comSnapshot.GetName(), m_comMachine.GetCurrentStateModified()); 709 if (iResultCode & AlertButton_Cancel) 710 return; 711 } 712 713 /* If user also confirmed new snapshot creation: */ 714 if (iResultCode & AlertOption_CheckBox) 715 { 716 /* Take snapshot of changed current state: */ 717 m_pTreeWidget->setCurrentItem(currentStateItem()); 718 if (!takeSnapshot()) 719 return; 720 } 721 722 /* Open a direct session (this call will handle all errors): */ 723 CSession comSession = vboxGlobal().openSession(m_strMachineID); 724 if (comSession.isNull()) 725 return; 726 727 /* Restore chosen snapshot: */ 728 CMachine comMachine = comSession.GetMachine(); 729 CProgress comProgress = comMachine.RestoreSnapshot(comSnapshot); 730 if (comMachine.isOk()) 731 { 732 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_restore_90px.png"); 733 if (comProgress.GetResultCode() != 0) 734 msgCenter().cannotRestoreSnapshot(comProgress, comSnapshot.GetName(), m_comMachine.GetName()); 735 } 736 else 737 msgCenter().cannotRestoreSnapshot(comMachine, comSnapshot.GetName(), m_comMachine.GetName()); 738 739 /* Unlock machine finally: */ 740 comSession.UnlockMachine(); 741 } 742 743 void UISnapshotPane::sltDeleteSnapshot() 744 { 745 /* Acquire currently chosen snapshot item: */ 746 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem()); 747 AssertReturnVoid(pSnapshotItem); 748 749 /* Get desired snapshot: */ 750 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 751 AssertReturnVoid(!comSnapshot.isNull()); 752 753 /* Confirm snapshot removal: */ 754 if (!msgCenter().confirmSnapshotRemoval(comSnapshot.GetName())) 755 return; 756 757 /** @todo check available space on the target filesystem etc etc. */ 758 #if 0 759 if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(comSnapshot.GetName(), 760 "/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi", 761 "59 GiB", 762 "15 GiB")) 763 return; 764 #endif 765 766 /* Open a session (this call will handle all errors): */ 767 bool fBusy = m_enmSessionState != KSessionState_Unlocked; 768 CSession comSession; 769 if (fBusy) 770 comSession = vboxGlobal().openExistingSession(m_strMachineID); 771 else 772 comSession = vboxGlobal().openSession(m_strMachineID); 773 if (comSession.isNull()) 774 return; 775 776 /* Remove chosen snapshot: */ 777 CMachine comMachine = comSession.GetMachine(); 778 CProgress comProgress = comMachine.DeleteSnapshot(pSnapshotItem->snapshotID()); 779 if (comMachine.isOk()) 780 { 781 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_discard_90px.png"); 782 if (comProgress.GetResultCode() != 0) 783 msgCenter().cannotRemoveSnapshot(comProgress, comSnapshot.GetName(), m_comMachine.GetName()); 784 } 785 else 786 msgCenter().cannotRemoveSnapshot(comMachine, comSnapshot.GetName(), m_comMachine.GetName()); 787 788 /* Unlock machine finally: */ 789 comSession.UnlockMachine(); 790 } 791 792 void UISnapshotPane::sltShowSnapshotDetails() 793 { 794 /* Acquire currently chosen snapshot item: */ 795 const SnapshotWgtItem *pSnapshotItem = toSnapshotItem(m_pTreeWidget->currentItem()); 796 AssertReturnVoid(pSnapshotItem); 797 798 /* Get desired snapshot: */ 1004 /* Get corresponding snapshot: */ 799 1005 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 800 1006 AssertReturnVoid(!comSnapshot.isNull()); … … 809 1015 } 810 1016 811 void UISnapshotPane:: sltCloneSnapshot()1017 void UISnapshotPane::cloneSnapshot() 812 1018 { 813 1019 /* Acquire currently chosen snapshot item: */ … … 836 1042 } 837 1043 838 void UISnapshotPane::sltMachineDataChange(QString strMachineID)839 {840 /* Make sure it's our VM: */841 if (strMachineID != m_strMachineID)842 return;843 844 /* Prevent snapshot editing in the meantime: */845 QWriteLocker locker(&m_lockReadWrite);846 847 /* Recache state current item: */848 currentStateItem()->recache();849 }850 851 void UISnapshotPane::sltMachineStateChange(QString strMachineID, KMachineState enmState)852 {853 /* Make sure it's our VM: */854 if (strMachineID != m_strMachineID)855 return;856 857 /* Prevent snapshot editing in the meantime: */858 QWriteLocker locker(&m_lockReadWrite);859 860 /* Recache new machine state: */861 currentStateItem()->recache();862 currentStateItem()->updateCurrentState(enmState);863 }864 865 void UISnapshotPane::sltSessionStateChange(QString strMachineID, KSessionState enmState)866 {867 /* Make sure it's our VM: */868 if (strMachineID != m_strMachineID)869 return;870 871 /* Prevent snapshot editing in the meantime: */872 QWriteLocker locker(&m_lockReadWrite);873 874 /* Recache new session state: */875 m_enmSessionState = enmState;876 sltCurrentItemChanged(m_pTreeWidget->currentItem());877 }878 879 void UISnapshotPane::sltUpdateSnapshotsAge()880 {881 /* Stop timer if active: */882 if (m_ageUpdateTimer.isActive())883 m_ageUpdateTimer.stop();884 885 /* Search for smallest snapshot age to optimize timer timeout: */886 const SnapshotAgeFormat age = traverseSnapshotAge(m_pTreeWidget->invisibleRootItem());887 switch (age)888 {889 case SnapshotAgeFormat_InSeconds: m_ageUpdateTimer.setInterval(5 * 1000); break;890 case SnapshotAgeFormat_InMinutes: m_ageUpdateTimer.setInterval(60 * 1000); break;891 case SnapshotAgeFormat_InHours: m_ageUpdateTimer.setInterval(60 * 60 * 1000); break;892 case SnapshotAgeFormat_InDays: m_ageUpdateTimer.setInterval(24 * 60 * 60 * 1000); break;893 default: m_ageUpdateTimer.setInterval(0); break;894 }895 896 /* Restart timer if necessary: */897 if (m_ageUpdateTimer.interval() > 0)898 m_ageUpdateTimer.start();899 }900 901 bool UISnapshotPane::takeSnapshot()902 {903 /* Prepare result: */904 bool fIsValid = true;905 906 /* Open a session (this call will handle all errors): */907 CSession comSession;908 if (m_enmSessionState != KSessionState_Unlocked)909 comSession = vboxGlobal().openExistingSession(m_strMachineID);910 else911 comSession = vboxGlobal().openSession(m_strMachineID);912 fIsValid = !comSession.isNull();913 914 if (fIsValid)915 {916 /* Get corresponding machine object also: */917 CMachine comMachine = comSession.GetMachine();918 919 /* Create take-snapshot dialog: */920 QWidget *pDlgParent = windowManager().realParentWindow(this);921 QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(pDlgParent, m_comMachine);922 windowManager().registerNewParent(pDlg, pDlgParent);923 924 // TODO: Assign corresponding icon through sub-dialog API: */925 pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m_comMachine.GetOSTypeId()));926 927 /* Search for the max available snapshot index: */928 int iMaxSnapShotIndex = 0;929 QString strSnapshotName = tr("Snapshot %1");930 QRegExp regExp(QString("^") + strSnapshotName.arg("([0-9]+)") + QString("$"));931 QTreeWidgetItemIterator iterator(m_pTreeWidget);932 while (*iterator)933 {934 QString strSnapshot = static_cast<SnapshotWgtItem*>(*iterator)->text(0);935 int iPos = regExp.indexIn(strSnapshot);936 if (iPos != -1)937 iMaxSnapShotIndex = regExp.cap(1).toInt() > iMaxSnapShotIndex ? regExp.cap(1).toInt() : iMaxSnapShotIndex;938 ++iterator;939 }940 // TODO: Assign corresponding snapshot name through sub-dialog API: */941 pDlg->mLeName->setText(strSnapshotName.arg(iMaxSnapShotIndex + 1));942 943 /* Show Take Snapshot dialog: */944 if (pDlg->exec() == QDialog::Accepted)945 {946 /* Acquire snapshot name/description: */947 const QString strSnapshotName = pDlg->mLeName->text().trimmed();948 const QString strSnapshotDescription = pDlg->mTeDescription->toPlainText();949 950 /* Take snapshot: */951 QString strSnapshotID;952 CProgress comProgress = comMachine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotID);953 if (comMachine.isOk())954 {955 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_create_90px.png");956 if (!comProgress.isOk() || comProgress.GetResultCode() != 0)957 {958 msgCenter().cannotTakeSnapshot(comProgress, m_comMachine.GetName());959 fIsValid = false;960 }961 }962 else963 {964 msgCenter().cannotTakeSnapshot(comMachine, m_comMachine.GetName());965 fIsValid = false;966 }967 }968 else969 fIsValid = false;970 if (pDlg)971 {972 delete pDlg;973 /* Unlock machine finally: */974 comSession.UnlockMachine();975 }976 }977 978 /* Return result: */979 return fIsValid;980 }981 982 1044 void UISnapshotPane::refreshAll() 983 1045 { -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h
r63834 r63835 82 82 /** @} */ 83 83 84 /** @name Snapshot operations85 * @{ */86 /** Proposes to take a snapshot. */87 void sltTakeSnapshot() { takeSnapshot(); }88 /** Proposes to restore the snapshot. */89 void sltRestoreSnapshot(bool fSuppressNonCriticalWarnings = false);90 /** Proposes to delete the snapshot. */91 void sltDeleteSnapshot();92 /** Displays the snapshot details dialog. */93 void sltShowSnapshotDetails();94 /** Proposes to clone the snapshot. */95 void sltCloneSnapshot();96 /** @} */97 98 84 /** @name Main event handlers 99 85 * @{ */ … … 112 98 /** @} */ 113 99 100 /** @name Snapshot operations 101 * @{ */ 102 /** Proposes to take a snapshot. */ 103 void sltTakeSnapshot() { takeSnapshot(); } 104 /** Proposes to restore the snapshot. */ 105 void sltRestoreSnapshot() { restoreSnapshot(); } 106 /** Proposes to delete the snapshot. */ 107 void sltDeleteSnapshot() { deleteSnapshot(); } 108 /** Displays the snapshot details dialog. */ 109 void sltShowSnapshotDetails() { showSnapshotDetails(); } 110 /** Proposes to clone the snapshot. */ 111 void sltCloneSnapshot() { cloneSnapshot(); } 112 /** @} */ 113 114 114 private: 115 115 … … 119 119 bool takeSnapshot(); 120 120 /** Proposes to restore the snapshot. */ 121 //bool restoreSnapshot();121 bool restoreSnapshot(bool fSuppressNonCriticalWarnings = false); 122 122 /** Proposes to delete the snapshot. */ 123 //bool deleteSnapshot();123 bool deleteSnapshot(); 124 124 /** Displays the snapshot details dialog. */ 125 //boolshowSnapshotDetails();125 void showSnapshotDetails(); 126 126 /** Proposes to clone the snapshot. */ 127 //boolcloneSnapshot();127 void cloneSnapshot(); 128 128 /** @} */ 129 129 … … 163 163 QActionGroup *m_pCurrentStateItemActionGroup; 164 164 165 /** Holds the snapshot take action instance. */ 166 QAction *m_pActionTakeSnapshot; 165 167 /** Holds the snapshot restore action instance. */ 166 168 QAction *m_pActionRestoreSnapshot; … … 169 171 /** Holds the show snapshot details action instance. */ 170 172 QAction *m_pActionShowSnapshotDetails; 171 /** Holds the snapshot take action instance. */172 QAction *m_pActionTakeSnapshot;173 173 /** Holds the snapshot clone action instance. */ 174 174 QAction *m_pActionCloneSnapshot;
Note:
See TracChangeset
for help on using the changeset viewer.