- Timestamp:
- Sep 14, 2016 1:03:07 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
r63821 r63832 107 107 case Qt::DisplayRole: 108 108 { 109 /* Call to the base-class for "current state" item, compose ourselves otherwise: */ 110 return m_fCurrentState ? QTreeWidgetItem::data(iColumn, iRole) : QVariant(QString("%1%2") 111 .arg(QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString()) 112 .arg(QTreeWidgetItem::data(iColumn, Qt::UserRole).toString())); 109 /* Call to base-class for "current state" item, compose ourselves otherwise: */ 110 return m_fCurrentState ? QTreeWidgetItem::data(iColumn, iRole) : 111 QString("%1%2") 112 .arg(QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString()) 113 .arg(QTreeWidgetItem::data(iColumn, Qt::UserRole).toString()); 113 114 } 114 115 case Qt::SizeHintRole: … … 159 160 160 161 /** Returns whether the font is bold. */ 161 bool bold() const { return font 162 bool bold() const { return font(0).bold(); } 162 163 /** Defines whether the font is @a fBold. */ 163 164 void setBold(bool fBold) … … 173 174 174 175 /** Returns whether the font is italic. */ 175 bool italic() const { return font 176 bool italic() const { return font(0).italic(); } 176 177 /** Defines whether the font is @a fItalic. */ 177 178 void setItalic(bool fItalic) … … 199 200 if (m_fCurrentState) 200 201 { 202 /* Fetch machine information: */ 201 203 AssertReturnVoid(!m_comMachine.isNull()); 202 204 m_fCurrentStateModified = m_comMachine.GetCurrentStateModified(); … … 213 215 else 214 216 { 217 /* Fetch snapshot information: */ 215 218 AssertReturnVoid(!m_comSnapshot.isNull()); 216 219 m_strSnapshotID = m_comSnapshot.GetId(); … … 305 308 void adjustText() 306 309 { 307 if (!treeWidget()) return; /* only for initialised items */ 310 /* Make sure item is initialised: */ 311 if (!treeWidget()) 312 return; 313 314 /* Calculate metrics: */ 308 315 QFontMetrics metrics(font(0)); 309 316 int iHei0 = (metrics.height() > 16 ? … … 322 329 { 323 330 /* Is the saved date today? */ 324 const QString strName = text(0);331 const bool fDateTimeToday = m_timestamp.date() == QDate::currentDate(); 325 332 326 333 /* Compose date time: */ 327 const bool fDateTimeToday = m_timestamp.date() == QDate::currentDate();328 334 QString strDateTime = fDateTimeToday ? 329 335 m_timestamp.time().toString(Qt::LocalDate) : … … 361 367 /* Prepare tool-tip: */ 362 368 QString strToolTip = QString("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>") 363 .arg(strName).arg(strDetails).arg(strDateTime);369 .arg(text(0)).arg(strDetails).arg(strDateTime); 364 370 365 371 /* Append description if any: */ … … 409 415 410 416 /** Constructs edit blocker. */ 411 SnapshotEditBlocker(bool &fProtector) 412 : m_fProtector(fProtector) 413 { 414 m_fProtector = true; 415 } 416 417 SnapshotEditBlocker(bool &fProtector) : m_fProtector(fProtector) { m_fProtector = true; } 417 418 /** Destructs edit blocker. */ 418 virtual ~SnapshotEditBlocker() 419 { 420 m_fProtector = false; 421 } 419 virtual ~SnapshotEditBlocker() { m_fProtector = false; } 422 420 423 421 private: … … 581 579 m_pActionTakeSnapshot->setStatusTip(tr("Take a snapshot of the current virtual machine state")); 582 580 m_pActionCloneSnapshot->setStatusTip(tr("Clone selected virtual machine")); 583 /* Translate actions tool-tips: */584 m_pActionRestoreSnapshot->setToolTip(m_pActionRestoreSnapshot->statusTip() +585 QString(" (%1)").arg(m_pActionRestoreSnapshot->shortcut().toString()));586 m_pActionDeleteSnapshot->setToolTip(m_pActionDeleteSnapshot->statusTip() +587 QString(" (%1)").arg(m_pActionDeleteSnapshot->shortcut().toString()));588 m_pActionShowSnapshotDetails->setToolTip(m_pActionShowSnapshotDetails->statusTip() +589 QString(" (%1)").arg(m_pActionShowSnapshotDetails->shortcut().toString()));590 m_pActionTakeSnapshot->setToolTip(m_pActionTakeSnapshot->statusTip() +591 QString(" (%1)").arg(m_pActionTakeSnapshot->shortcut().toString()));592 m_pActionCloneSnapshot->setToolTip(m_pActionCloneSnapshot->statusTip() +593 QString(" (%1)").arg(m_pActionCloneSnapshot->shortcut().toString()));594 581 } 595 582 … … 605 592 } 606 593 607 /* Whether another direct session is open or not: */594 /* Check whether another direct session is open or not: */ 608 595 const bool fBusy = m_enmSessionState != KSessionState_Unlocked; 609 596 … … 614 601 615 602 /* Whether taking or deleting snapshots is possible right now: */ 616 const bool canTakeDeleteSnapshot = !fBusy617 || enmState == KMachineState_PoweredOff618 || enmState == KMachineState_Saved619 || enmState == KMachineState_Aborted620 || enmState == KMachineState_Running621 || enmState == KMachineState_Paused;603 const bool fCanTakeDeleteSnapshot = !fBusy 604 || enmState == KMachineState_PoweredOff 605 || enmState == KMachineState_Saved 606 || enmState == KMachineState_Aborted 607 || enmState == KMachineState_Running 608 || enmState == KMachineState_Paused; 622 609 623 610 /* Enable/disable snapshot operations: */ 624 m_pActionRestoreSnapshot->setEnabled(!fBusy && m_pCurrentSnapshotItem && pSnapshotItem && !pSnapshotItem->isCurrentStateItem()); 625 m_pActionDeleteSnapshot->setEnabled(m_fShapshotOperationsAllowed && 626 canTakeDeleteSnapshot && m_pCurrentSnapshotItem && pSnapshotItem && !pSnapshotItem->isCurrentStateItem()); 627 m_pActionShowSnapshotDetails->setEnabled(m_pCurrentSnapshotItem && pSnapshotItem && !pSnapshotItem->isCurrentStateItem()); 628 m_pActionTakeSnapshot->setEnabled(m_fShapshotOperationsAllowed && 629 ((canTakeDeleteSnapshot && m_pCurrentSnapshotItem && pSnapshotItem && pSnapshotItem->isCurrentStateItem()) || 630 (pSnapshotItem && !m_pCurrentSnapshotItem))); 631 m_pActionCloneSnapshot->setEnabled(!fBusy && pSnapshotItem); 611 m_pActionRestoreSnapshot->setEnabled( 612 !fBusy 613 && m_pCurrentSnapshotItem 614 && pSnapshotItem 615 && !pSnapshotItem->isCurrentStateItem() 616 ); 617 m_pActionDeleteSnapshot->setEnabled( 618 m_fShapshotOperationsAllowed 619 && fCanTakeDeleteSnapshot 620 && m_pCurrentSnapshotItem 621 && pSnapshotItem 622 && !pSnapshotItem->isCurrentStateItem() 623 ); 624 m_pActionShowSnapshotDetails->setEnabled( 625 m_pCurrentSnapshotItem 626 && pSnapshotItem 627 && !pSnapshotItem->isCurrentStateItem() 628 ); 629 m_pActionTakeSnapshot->setEnabled( 630 m_fShapshotOperationsAllowed 631 && ( ( fCanTakeDeleteSnapshot 632 && m_pCurrentSnapshotItem 633 && pSnapshotItem 634 && pSnapshotItem->isCurrentStateItem()) 635 || ( pSnapshotItem 636 && !m_pCurrentSnapshotItem)) 637 ); 638 m_pActionCloneSnapshot->setEnabled( 639 !fBusy 640 && pSnapshotItem 641 ); 632 642 } 633 643 … … 671 681 /* Make sure snapshot item was changed: */ 672 682 const SnapshotWgtItem *pSnapshotItem = pItem ? static_cast<const SnapshotWgtItem*>(pItem) : 0; 673 674 if (pSnapshotItem) 675 { 676 /* Rename corresponding snapshot: */ 677 CSnapshot comSnapshot = pSnapshotItem->snapshotID().isNull() ? CSnapshot() : m_comMachine.FindSnapshot(pSnapshotItem->snapshotID()); 678 if (!comSnapshot.isNull() && comSnapshot.isOk() && comSnapshot.GetName() != pSnapshotItem->text(0)) 679 comSnapshot.SetName(pSnapshotItem->text(0)); 680 } 683 if (!pSnapshotItem) 684 return; 685 686 /* Rename corresponding snapshot: */ 687 CSnapshot comSnapshot = pSnapshotItem->snapshotID().isNull() ? CSnapshot() : m_comMachine.FindSnapshot(pSnapshotItem->snapshotID()); 688 if (!comSnapshot.isNull() && comSnapshot.isOk() && comSnapshot.GetName() != pSnapshotItem->text(0)) 689 comSnapshot.SetName(pSnapshotItem->text(0)); 681 690 } 682 691 … … 700 709 } 701 710 702 void UISnapshotPane::sltTakeSnapshot()703 {704 takeSnapshot();705 }706 707 711 void UISnapshotPane::sltRestoreSnapshot(bool fSuppressNonCriticalWarnings /* = false */) 708 712 { … … 711 715 AssertReturnVoid(pSnapshotItem); 712 716 713 /* Detemine snapshot id: */ 714 const QString strSnapshotID = pSnapshotItem->snapshotID(); 715 AssertReturnVoid(!strSnapshotID.isNull()); 716 /* Get currently desired snapshot: */ 717 const CSnapshot comSnapshot = m_comMachine.FindSnapshot(strSnapshotID); 717 /* Get desired snapshot: */ 718 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 719 AssertReturnVoid(!comSnapshot.isNull()); 718 720 719 721 /* Ask the user if he really wants to restore the snapshot: */ … … 763 765 AssertReturnVoid(pSnapshotItem); 764 766 765 /* Detemine snapshot id: */ 766 const QString strSnapshotID = pSnapshotItem->snapshotID(); 767 AssertReturnVoid(!strSnapshotID.isNull()); 768 /* Get currently desired snapshot: */ 769 const CSnapshot comSnapshot = m_comMachine.FindSnapshot(strSnapshotID); 767 /* Get desired snapshot: */ 768 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 769 AssertReturnVoid(!comSnapshot.isNull()); 770 770 771 771 /* Confirm snapshot removal: */ … … 794 794 /* Remove chosen snapshot: */ 795 795 CMachine comMachine = comSession.GetMachine(); 796 CProgress comProgress = comMachine.DeleteSnapshot( strSnapshotID);796 CProgress comProgress = comMachine.DeleteSnapshot(pSnapshotItem->snapshotID()); 797 797 if (comMachine.isOk()) 798 798 { … … 819 819 AssertReturnVoid(!comSnapshot.isNull()); 820 820 821 // WTF?822 CMachine comMachine = comSnapshot.GetMachine();823 824 821 /* Show Snapshot Details dialog: */ 825 VBoxSnapshotDetailsDlg pDlg(this); 826 pDlg.getFromSnapshot(comSnapshot); 827 828 if (pDlg.exec() == QDialog::Accepted) 829 pDlg.putBackToSnapshot(); 822 QPointer<VBoxSnapshotDetailsDlg> pDlg = new VBoxSnapshotDetailsDlg(this); 823 pDlg->getFromSnapshot(comSnapshot); 824 if (pDlg->exec() == QDialog::Accepted) 825 pDlg->putBackToSnapshot(); 826 if (pDlg) 827 delete pDlg; 830 828 } 831 829 … … 909 907 switch (age) 910 908 { 911 case SnapshotAgeFormat_InSeconds: 912 m_ageUpdateTimer.setInterval(5 * 1000); 913 break; 914 case SnapshotAgeFormat_InMinutes: 915 m_ageUpdateTimer.setInterval(60 * 1000); 916 break; 917 case SnapshotAgeFormat_InHours: 918 m_ageUpdateTimer.setInterval(60 * 60 * 1000); 919 break; 920 case SnapshotAgeFormat_InDays: 921 m_ageUpdateTimer.setInterval(24 * 60 * 60 * 1000); 922 break; 923 default: 924 m_ageUpdateTimer.setInterval(0); 925 break; 909 case SnapshotAgeFormat_InSeconds: m_ageUpdateTimer.setInterval(5 * 1000); break; 910 case SnapshotAgeFormat_InMinutes: m_ageUpdateTimer.setInterval(60 * 1000); break; 911 case SnapshotAgeFormat_InHours: m_ageUpdateTimer.setInterval(60 * 60 * 1000); break; 912 case SnapshotAgeFormat_InDays: m_ageUpdateTimer.setInterval(24 * 60 * 60 * 1000); break; 913 default: m_ageUpdateTimer.setInterval(0); break; 926 914 } 927 915 … … 935 923 /* Prepare result: */ 936 924 bool fIsValid = true; 937 938 // WTF?939 const SnapshotWgtItem *pSnapshotItem = m_pTreeWidget->currentItem() ? static_cast<const SnapshotWgtItem*>(m_pTreeWidget->currentItem()) : 0;940 AssertReturn(pSnapshotItem, (bool)0);941 925 942 926 /* Open a session (this call will handle all errors): */ … … 978 962 979 963 /* Show Take Snapshot dialog: */ 980 bool fDialogAccepted = pDlg->exec() == QDialog::Accepted; 981 982 /* Is the dialog still valid? */ 983 if (pDlg) 964 if (pDlg->exec() == QDialog::Accepted) 984 965 { 985 966 /* Acquire snapshot name/description: */ … … 987 968 const QString strSnapshotDescription = pDlg->mTeDescription->toPlainText(); 988 969 989 /* Destroy dialog early: */ 990 delete pDlg; 991 992 /* Was the dialog accepted? */ 993 if (fDialogAccepted) 970 /* Take snapshot: */ 971 QString strSnapshotID; 972 CProgress comProgress = comMachine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotID); 973 if (comMachine.isOk()) 994 974 { 995 /* Take snapshot: */ 996 QString strSnapshotID; 997 CProgress comProgress = comMachine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotID); 998 if (comMachine.isOk()) 975 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_create_90px.png"); 976 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 999 977 { 1000 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_create_90px.png"); 1001 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 1002 { 1003 msgCenter().cannotTakeSnapshot(comProgress, m_comMachine.GetName()); 1004 fIsValid = false; 1005 } 1006 } 1007 else 1008 { 1009 msgCenter().cannotTakeSnapshot(comMachine, m_comMachine.GetName()); 978 msgCenter().cannotTakeSnapshot(comProgress, m_comMachine.GetName()); 1010 979 fIsValid = false; 1011 980 } 1012 981 } 1013 982 else 983 { 984 msgCenter().cannotTakeSnapshot(comMachine, m_comMachine.GetName()); 1014 985 fIsValid = false; 986 } 1015 987 } 1016 988 else 1017 989 fIsValid = false; 1018 1019 /* Unlock machine finally: */ 1020 comSession.UnlockMachine(); 990 if (pDlg) 991 { 992 delete pDlg; 993 /* Unlock machine finally: */ 994 comSession.UnlockMachine(); 995 } 1021 996 } 1022 997 … … 1144 1119 1145 1120 /* Walk through the children recursively: */ 1146 const CSnapshotVector snapshots = comSnapshot.GetChildren(); 1147 foreach (const CSnapshot &comIteratedSnapshot, snapshots) 1121 foreach (const CSnapshot &comIteratedSnapshot, comSnapshot.GetChildren()) 1148 1122 populateSnapshots(comIteratedSnapshot, pSnapshotItem); 1149 1123 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h
r63821 r63832 47 47 48 48 /** QWidget extension providing GUI with the pane to control snapshot related functionality. */ 49 class UISnapshotPane : public QIWithRetranslateUI 49 class UISnapshotPane : public QIWithRetranslateUI<QWidget>, public Ui::UISnapshotPane 50 50 { 51 51 Q_OBJECT; … … 84 84 * @{ */ 85 85 /** Proposes to take a snapshot. */ 86 void sltTakeSnapshot() ;86 void sltTakeSnapshot() { takeSnapshot(); } 87 87 /** Proposes to restore the snapshot. */ 88 88 void sltRestoreSnapshot(bool fSuppressNonCriticalWarnings = false);
Note:
See TracChangeset
for help on using the changeset viewer.