- Timestamp:
- Sep 13, 2016 4:43:16 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
r63804 r63818 52 52 53 53 54 /** 55 * QTreeWidgetItem subclass for snapshots items 56 */ 54 /** QTreeWidgetItem subclass for snapshots items. */ 57 55 class SnapshotWgtItem : public QTreeWidgetItem 58 56 { 59 57 public: 60 58 59 /** Item type for SnapshotWgtItem. */ 61 60 enum { ItemType = QTreeWidgetItem::UserType + 1 }; 62 61 63 /* Normal snapshot item (child of tree-widget)*/62 /** Constructs normal snapshot item (child of tree-widget). */ 64 63 SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidget *aTreeWidget, const CSnapshot &aSnapshot) 65 64 : QTreeWidgetItem (aTreeWidget, ItemType) … … 70 69 } 71 70 72 /* Normal snapshot item (child of tree-widget-item)*/71 /** Constructs normal snapshot item (child of tree-widget-item). */ 73 72 SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *aRootItem, const CSnapshot &aSnapshot) 74 73 : QTreeWidgetItem (aRootItem, ItemType) … … 79 78 } 80 79 81 /* Current state item (child of tree-widget)*/80 /** Constructs "current state" item (child of tree-widget). */ 82 81 SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidget *aTreeWidget, const CMachine &aMachine) 83 82 : QTreeWidgetItem (aTreeWidget, ItemType) … … 86 85 , mMachine (aMachine) 87 86 { 87 /* Fetch current machine state: */ 88 88 updateCurrentState (mMachine.GetState()); 89 89 } 90 90 91 /* Current state item (child of tree-widget-item)*/91 /** Constructs "current state" item (child of tree-widget-item). */ 92 92 SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *aRootItem, const CMachine &aMachine) 93 93 : QTreeWidgetItem (aRootItem, ItemType) … … 96 96 , mMachine (aMachine) 97 97 { 98 /* Fetch current machine state: */ 98 99 updateCurrentState (mMachine.GetState()); 99 100 } 100 101 102 /** Returns item data for corresponding @a iColumn and @a iRole. */ 101 103 QVariant data (int aColumn, int aRole) const 102 104 { … … 104 106 { 105 107 case Qt::DisplayRole: 108 { 109 /* Call to the base-class for "current state" item, compose ourselves otherwise: */ 106 110 return mIsCurrentState ? QTreeWidgetItem::data (aColumn, aRole) : QVariant (QString ("%1%2") 107 111 .arg (QTreeWidgetItem::data (aColumn, Qt::DisplayRole).toString()) 108 112 .arg (QTreeWidgetItem::data (aColumn, Qt::UserRole).toString())); 113 } 109 114 case Qt::SizeHintRole: 110 115 { … … 123 128 break; 124 129 } 130 131 /* Call to base-class: */ 125 132 return QTreeWidgetItem::data (aColumn, aRole); 126 133 } 127 134 135 /** Returns item text for corresponding @a iColumn. */ 128 136 QString text (int aColumn) const 129 137 { … … 131 139 } 132 140 141 /** Returns whether this is the "current state" item. */ 133 142 bool isCurrentStateItem() const 134 143 { … … 136 145 } 137 146 147 /** Calculates and returns the current item level. */ 138 148 int level() 139 149 { … … 148 158 } 149 159 160 /** Returns whether the font is bold. */ 150 161 bool bold() const { return font (0).bold(); } 162 /** Defines whether the font is @a fBold. */ 151 163 void setBold (bool aBold) 152 164 { 165 /* Update font: */ 153 166 QFont myFont = font (0); 154 167 myFont.setBold (aBold); 155 168 setFont (0, myFont); 169 170 /* Adjust text: */ 156 171 adjustText(); 157 172 } 158 173 174 /** Returns whether the font is italic. */ 159 175 bool italic() const { return font (0).italic(); } 176 /** Defines whether the font is @a fItalic. */ 160 177 void setItalic (bool aItalic) 161 178 { 179 /* Update font: */ 162 180 QFont myFont = font (0); 163 181 myFont.setItalic (aItalic); 164 182 setFont (0, myFont); 183 184 /* Adjust text: */ 165 185 adjustText(); 166 186 } 167 187 188 /** Returns item machine. */ 168 189 CMachine machine() const { return mMachine; } 190 /** Returns item snapshot. */ 169 191 CSnapshot snapshot() const { return mSnapshot; } 192 /** Returns item snapshot ID. */ 170 193 QString snapshotId() const { return mId; } 171 194 195 /** Recaches the item's contents. */ 172 196 void recache() 173 197 { 198 /* For "current state" item: */ 174 199 if (mIsCurrentState) 175 200 { … … 185 210 QString::null; 186 211 } 212 /* For others: */ 187 213 else 188 214 { … … 196 222 mCurStateModified = false; 197 223 } 224 225 /* Adjust text: */ 198 226 adjustText(); 227 /* Update tool-tip: */ 199 228 recacheToolTip(); 200 229 } 201 230 231 /** Returns current machine state. */ 202 232 KMachineState getCurrentState() 203 233 { 234 /* Make sure machine is valid: */ 204 235 if (mMachine.isNull()) 205 236 return KMachineState_Null; 206 237 238 /* Return cached state: */ 207 239 return mMachineState; 208 240 } 209 241 242 /** Recaches current machine state. */ 210 243 void updateCurrentState (KMachineState aState) 211 244 { 245 /* Make sure machine is valid: */ 212 246 if (mMachine.isNull()) 213 247 return; 214 248 249 /* Set corresponding icon: */ 215 250 setIcon(0, gpConverter->toIcon(aState)); 251 /* Cache new state: */ 216 252 mMachineState = aState; 253 /* Update timestamp: */ 217 254 mTimestamp.setTime_t (mMachine.GetLastStateChange() / 1000); 218 255 } 219 256 257 /** Updates item age. */ 220 258 SnapshotAgeFormat updateAge() 221 259 { 260 /* Prepare age: */ 222 261 QString age; 223 262 … … 254 293 } 255 294 256 /* Update data */295 /* Update data: */ 257 296 setData (0, Qt::UserRole, age); 258 297 298 /* Return age: */ 259 299 return ageFormat; 260 300 } … … 262 302 private: 263 303 304 /** Adjusts item text. */ 264 305 void adjustText() 265 306 { … … 272 313 treeWidget()->indentation() /* indent */ + 273 314 16 /* icon */; 315 316 /* Adjust size finally: */ 274 317 setSizeHint (0, QSize (wid0, hei0)); 275 318 } 276 319 320 /** Recaches item tool-tip. */ 277 321 void recacheToolTip() 278 322 { 323 /* Is the saved date today? */ 279 324 QString name = text (0); 280 325 326 /* Compose date time: */ 281 327 bool dateTimeToday = mTimestamp.date() == QDate::currentDate(); 282 328 QString dateTime = dateTimeToday ? … … 284 330 mTimestamp.toString (Qt::LocalDate); 285 331 332 /* Prepare details: */ 286 333 QString details; 287 334 335 /* For snapshot item: */ 288 336 if (!mSnapshot.isNull()) 289 337 { … … 293 341 else 294 342 details = " ("; 343 344 /* Add online/offline information: */ 295 345 details += mOnline ? UISnapshotPane::tr ("online)", "Snapshot details") 296 346 : UISnapshotPane::tr ("offline)", "Snapshot details"); 297 347 348 /* Add date/time information: */ 298 349 if (dateTimeToday) 299 350 dateTime = UISnapshotPane::tr ("Taken at %1", "Snapshot (time)").arg (dateTime); … … 301 352 dateTime = UISnapshotPane::tr ("Taken on %1", "Snapshot (date + time)").arg (dateTime); 302 353 } 354 /* For "current state" item: */ 303 355 else 304 356 { … … 307 359 } 308 360 361 /* Prepare tool-tip: */ 309 362 QString toolTip = QString ("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>") 310 363 .arg (name) .arg (details).arg (dateTime); 311 364 365 /* Append description if any: */ 312 366 if (!mDesc.isEmpty()) 313 367 toolTip += "<hr>" + mDesc; 314 368 369 /* Assign tool-tip finally: */ 315 370 setToolTip (0, toolTip); 316 371 } 317 372 318 /** Holds pointer to snapshot-widget 'this'item belongs to. */373 /** Holds the pointer to the snapshot-widget this item belongs to. */ 319 374 QPointer<UISnapshotPane> m_pSnapshotWidget; 320 375 376 /** Holds whether this is a "current state" item. */ 321 377 bool mIsCurrentState; 322 378 379 /** Holds the snapshot COM wrapper. */ 323 380 CSnapshot mSnapshot; 381 /** Holds the machine COM wrapper. */ 324 382 CMachine mMachine; 325 383 384 /** Holds the current snapshot ID. */ 326 385 QString mId; 386 /** Holds whether the current snapshot is online one. */ 327 387 bool mOnline; 388 389 /** Holds the item description. */ 328 390 QString mDesc; 391 /** Holds the item timestamp. */ 329 392 QDateTime mTimestamp; 330 393 394 /** Holds whether the current state is modified. */ 331 395 bool mCurStateModified; 396 /** Holds the cached machine state. */ 332 397 KMachineState mMachineState; 333 398 }; 334 399 335 /** 336 * Simple guard block to prevent cyclic call caused by: 337 * changing tree-widget item content (rename) leads to snapshot update & 338 * snapshot update leads to changing tree-widget item content. 339 */ 400 401 /** Simple guard block to prevent cyclic call caused by: 402 * changing tree-widget item content (rename) leads to snapshot 403 * update & snapshot update leads to changing tree-widget item content. */ 340 404 class SnapshotEditBlocker 341 405 { 342 406 public: 343 407 408 /** Constructs edit blocker. */ 344 409 SnapshotEditBlocker (bool &aProtector) 345 410 : mProtector (aProtector) … … 348 413 } 349 414 415 /** Destructs edit blocker. */ 350 416 ~SnapshotEditBlocker() 351 417 { … … 355 421 private: 356 422 423 /** Holds the protector flag reference. */ 357 424 bool &mProtector; 358 425 }; 426 359 427 360 428 UISnapshotPane::UISnapshotPane (QWidget *aParent) … … 371 439 , m_fShapshotOperationsAllowed(false) 372 440 { 373 /* Apply UI decorations */441 /* Apply UI decorations: */ 374 442 Ui::UISnapshotPane::setupUi (this); 375 443 444 /* No header: */ 376 445 mTreeWidget->header()->hide(); 377 446 378 447 #if QT_VERSION < 0x050000 379 /* The snapshots widget is not very useful if there are a lot 380 * of snapshots in a tree and the current Qt style decides not 381 * to draw lines (branches) between the snapshot nodes; it is 382 * then often unclear which snapshot is a child of another. 383 * So on platforms whose styles do not normally draw branches, 384 * we use QWindowsStyle which is present on every platform and 385 * draws required thing like we want. */ 448 // WORKAROUND: 449 // The snapshots widget is not very useful if there are a lot 450 // of snapshots in a tree and the current Qt style decides not 451 // to draw lines (branches) between the snapshot nodes; it is 452 // then often unclear which snapshot is a child of another. 453 // So on platforms whose styles do not normally draw branches, 454 // we use QWindowsStyle which is present on every platform and 455 // draws required thing like we want. */ 386 456 // #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) 387 457 QWindowsStyle *treeWidgetStyle = new QWindowsStyle; … … 399 469 const int iIconMetric = (int)(pStyle->pixelMetric(QStyle::PM_SmallIconSize) * 1.375); 400 470 401 /* ToolBar creation*/471 /* Create tool-bar: */ 402 472 UIToolBar *toolBar = new UIToolBar (this); 403 473 toolBar->setIconSize (QSize (iIconMetric, iIconMetric)); 404 474 toolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); 405 475 /* Add actions into tool-bar: */ 406 476 toolBar->addAction (mTakeSnapshotAction); 407 477 toolBar->addSeparator(); … … 411 481 toolBar->addSeparator(); 412 482 toolBar->addAction(mCloneSnapshotAction); 413 483 /* Add tool-bar into layout: */ 414 484 ((QVBoxLayout*)layout())->insertWidget (0, toolBar); 415 485 416 /* Setup action s*/486 /* Setup action icons: */ 417 487 mRestoreSnapshotAction->setIcon(UIIconPool::iconSetFull( 418 488 ":/snapshot_restore_22px.png", ":/snapshot_restore_16px.png", … … 430 500 ":/vm_clone_22px.png", ":/vm_clone_16px.png", 431 501 ":/vm_clone_disabled_22px.png", ":/vm_clone_disabled_16px.png")); 432 502 /* Setup action shortcuts: */ 433 503 mRestoreSnapshotAction->setShortcut (QString ("Ctrl+Shift+R")); 434 504 mDeleteSnapshotAction->setShortcut (QString ("Ctrl+Shift+D")); … … 437 507 mCloneSnapshotAction->setShortcut(QString ("Ctrl+Shift+C")); 438 508 509 /* Setup timer: */ 439 510 mAgeUpdateTimer.setSingleShot (true); 440 511 441 /* Setup connections*/512 /* Setup tree-widget connections: */ 442 513 connect (mTreeWidget, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)), 443 514 this, SLOT (onCurrentChanged (QTreeWidgetItem*))); … … 448 519 connect(mTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)), 449 520 this, SLOT (sltItemDoubleClicked(QTreeWidgetItem*))); 450 521 /* Setup snapshot operation connections: */ 451 522 connect (mTakeSnapshotAction, SIGNAL (triggered()), this, SLOT (sltTakeSnapshot())); 452 523 connect (mRestoreSnapshotAction, SIGNAL (triggered()), this, SLOT (sltRestoreSnapshot())); … … 454 525 connect (mShowSnapshotDetailsAction, SIGNAL (triggered()), this, SLOT (sltShowSnapshotDetails())); 455 526 connect (mCloneSnapshotAction, SIGNAL(triggered()), this, SLOT(sltCloneSnapshot())); 456 527 /* Setup Main event connections: */ 457 528 connect (gVBoxEvents, SIGNAL(sigMachineDataChange(QString)), 458 529 this, SLOT(machineDataChanged(QString))); … … 461 532 connect (gVBoxEvents, SIGNAL(sigSessionStateChange(QString, KSessionState)), 462 533 this, SLOT(sessionStateChanged(QString, KSessionState))); 463 534 /* Setup timer event connections: */ 464 535 connect (&mAgeUpdateTimer, SIGNAL (timeout()), this, SLOT (updateSnapshotsAge())); 465 536 537 /* Translate finally: */ 466 538 retranslateUi(); 467 539 } … … 469 541 void UISnapshotPane::setMachine (const CMachine &aMachine) 470 542 { 543 /* Cache passed machine: */ 471 544 mMachine = aMachine; 472 545 546 /* Cache machine details: */ 473 547 if (aMachine.isNull()) 474 548 { … … 484 558 } 485 559 560 /* Refresh everything: */ 486 561 refreshAll(); 487 562 } … … 492 567 Ui::UISnapshotPane::retranslateUi(this); 493 568 569 /* Translate actions names: */ 494 570 mRestoreSnapshotAction->setText(tr("&Restore Snapshot")); 495 571 mDeleteSnapshotAction->setText(tr("&Delete Snapshot")); … … 497 573 mTakeSnapshotAction->setText(tr("Take &Snapshot")); 498 574 mCloneSnapshotAction->setText(tr("&Clone...")); 499 575 /* Translate actions status-tips: */ 500 576 mRestoreSnapshotAction->setStatusTip(tr("Restore selected snapshot of the virtual machine")); 501 577 mDeleteSnapshotAction->setStatusTip(tr("Delete selected snapshot of the virtual machine")); … … 503 579 mTakeSnapshotAction->setStatusTip(tr("Take a snapshot of the current virtual machine state")); 504 580 mCloneSnapshotAction->setStatusTip(tr("Clone selected virtual machine")); 505 581 /* Translate actions tool-tips: */ 506 582 mRestoreSnapshotAction->setToolTip(mRestoreSnapshotAction->statusTip() + 507 583 QString(" (%1)").arg(mRestoreSnapshotAction->shortcut().toString())); … … 527 603 } 528 604 529 /* Whether another direct session is open or not */605 /* Whether another direct session is open or not: */ 530 606 bool busy = mSessionState != KSessionState_Unlocked; 531 607 532 /* Machine state of the current state item*/608 /* Acquire machine state of the "current state" item: */ 533 609 KMachineState s = KMachineState_Null; 534 610 if (curStateItem()) 535 611 s = curStateItem()->getCurrentState(); 536 612 537 /* Whether taking or deleting snapshots is possible right now */613 /* Whether taking or deleting snapshots is possible right now: */ 538 614 bool canTakeDeleteSnapshot = !busy 539 615 || s == KMachineState_PoweredOff … … 543 619 || s == KMachineState_Paused; 544 620 545 /* Enable/disable restoring snapshot*/621 /* Enable/disable snapshot operations: */ 546 622 mRestoreSnapshotAction->setEnabled (!busy && mCurSnapshotItem && item && !item->isCurrentStateItem()); 547 548 /* Enable/disable deleting snapshot */549 623 mDeleteSnapshotAction->setEnabled (m_fShapshotOperationsAllowed && 550 624 canTakeDeleteSnapshot && mCurSnapshotItem && item && !item->isCurrentStateItem()); 551 552 /* Enable/disable the details action regardless of the session state */553 625 mShowSnapshotDetailsAction->setEnabled (mCurSnapshotItem && item && !item->isCurrentStateItem()); 554 555 /* Enable/disable taking snapshots */556 626 mTakeSnapshotAction->setEnabled (m_fShapshotOperationsAllowed && 557 627 ((canTakeDeleteSnapshot && mCurSnapshotItem && item && item->isCurrentStateItem()) || 558 628 (item && !mCurSnapshotItem))); 559 560 /* Enable/disable cloning snapshots */561 629 mCloneSnapshotAction->setEnabled(!busy && item); 562 630 } … … 564 632 void UISnapshotPane::onContextMenuRequested (const QPoint &aPoint) 565 633 { 634 /* Search for corresponding snapshot item: */ 566 635 QTreeWidgetItem *item = mTreeWidget->itemAt (aPoint); 567 636 SnapshotWgtItem *snapshotItem = item ? static_cast <SnapshotWgtItem*> (item) : 0; … … 569 638 return; 570 639 640 /* Prepare menu: */ 571 641 QMenu menu; 572 642 /* For snapshot item: */ 573 643 if (mCurSnapshotItem && !snapshotItem->isCurrentStateItem()) 574 644 { … … 579 649 menu.addAction(mCloneSnapshotAction); 580 650 } 651 /* For "current state" item: */ 581 652 else 582 653 { … … 586 657 } 587 658 659 /* Show menu: */ 588 660 menu.exec (mTreeWidget->viewport()->mapToGlobal (aPoint)); 589 661 } … … 591 663 void UISnapshotPane::onItemChanged (QTreeWidgetItem *aItem) 592 664 { 665 /* Make sure nothing is being edited currently: */ 593 666 if (mEditProtector) 594 667 return; 595 668 669 /* Make sure snapshot item was changed: */ 596 670 SnapshotWgtItem *item = aItem ? static_cast <SnapshotWgtItem*> (aItem) : 0; 597 671 598 672 if (item) 599 673 { 674 /* Rename corresponding snapshot: */ 600 675 CSnapshot snap = item->snapshotId().isNull() ? CSnapshot() : mMachine.FindSnapshot(item->snapshotId()); 601 676 if (!snap.isNull() && snap.isOk() && snap.GetName() != item->text (0)) … … 606 681 void UISnapshotPane::sltItemDoubleClicked(QTreeWidgetItem *pItem) 607 682 { 608 /* Make sure *nothing*is being edited currently: */683 /* Make sure nothing is being edited currently: */ 609 684 if (mEditProtector) 610 685 return; 611 686 612 /* Make sure s ome *valid* item was *really*double-clicked: */687 /* Make sure snapshot item was double-clicked: */ 613 688 SnapshotWgtItem *pValidItem = pItem ? static_cast<SnapshotWgtItem*>(pItem) : 0; 614 689 if (!pValidItem) … … 618 693 if (QApplication::keyboardModifiers() == Qt::ControlModifier) 619 694 { 620 /* As call forsnapshot-restore procedure: */695 /* As snapshot-restore procedure: */ 621 696 sltRestoreSnapshot(true /* suppress non-critical warnings */); 622 697 } … … 633 708 SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0; 634 709 AssertReturn(pItem, (void)0); 710 635 711 /* Detemine snapshot id: */ 636 712 QString strSnapshotId = pItem->snapshotId(); … … 680 756 void UISnapshotPane::sltDeleteSnapshot() 681 757 { 758 /* Get currently chosen item: */ 682 759 SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 : 683 760 static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem()); 684 761 AssertReturn (item, (void) 0); 685 762 763 /* Detemine snapshot id: */ 686 764 QString snapId = item->snapshotId(); 687 765 AssertReturn (!snapId.isNull(), (void) 0); 766 /* Get currently desired snapshot: */ 688 767 CSnapshot snapshot = mMachine.FindSnapshot(snapId); 689 768 769 /* Confirm snapshot removal: */ 690 770 if (!msgCenter().confirmSnapshotRemoval(snapshot.GetName())) 691 771 return; … … 700 780 #endif 701 781 702 /* Open a direct session (this call will handle all errors)*/782 /* Open a session (this call will handle all errors): */ 703 783 bool busy = mSessionState != KSessionState_Unlocked; 704 784 CSession session; … … 715 795 if (machine.isOk()) 716 796 { 717 /* Show the progress dialog */718 797 msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_discard_90px.png"); 719 720 798 if (progress.GetResultCode() != 0) 721 799 msgCenter().cannotRemoveSnapshot(progress, snapshot.GetName(), mMachine.GetName()); … … 724 802 msgCenter().cannotRemoveSnapshot(machine, snapshot.GetName(), mMachine.GetName()); 725 803 804 /* Unlock machine finally: */ 726 805 session.UnlockMachine(); 727 806 } … … 729 808 void UISnapshotPane::sltShowSnapshotDetails() 730 809 { 810 /* Get currently chosen item: */ 731 811 SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 : 732 812 static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem()); 733 813 AssertReturn (item, (void) 0); 734 814 815 /* Get desired snapshot: */ 735 816 CSnapshot snap = item->snapshot(); 736 817 AssertReturn (!snap.isNull(), (void) 0); … … 738 819 CMachine snapMachine = snap.GetMachine(); 739 820 821 /* Show Snapshot Details dialog: */ 740 822 VBoxSnapshotDetailsDlg dlg (this); 741 823 dlg.getFromSnapshot (snap); … … 747 829 void UISnapshotPane::sltCloneSnapshot() 748 830 { 831 /* Get currently chosen item: */ 749 832 SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 : 750 833 static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem()); 751 834 AssertReturn (item, (void) 0); 752 835 836 /* Get desired machine/snapshot: */ 753 837 CMachine machine; 754 838 CSnapshot snapshot; … … 773 857 void UISnapshotPane::machineDataChanged(QString strId) 774 858 { 859 /* Prevent snapshot editing in the meantime: */ 775 860 SnapshotEditBlocker guardBlock (mEditProtector); 776 861 862 /* Make sure it's our VM: */ 777 863 if (strId != mMachineId) 778 864 return; 779 865 866 /* Recache state current item: */ 780 867 curStateItem()->recache(); 781 868 } … … 783 870 void UISnapshotPane::machineStateChanged(QString strId, KMachineState state) 784 871 { 872 /* Prevent snapshot editing in the meantime: */ 785 873 SnapshotEditBlocker guardBlock (mEditProtector); 786 874 875 /* Make sure it's our VM: */ 787 876 if (strId != mMachineId) 788 877 return; 789 878 879 /* Recache new machine state: */ 790 880 curStateItem()->recache(); 791 881 curStateItem()->updateCurrentState(state); … … 794 884 void UISnapshotPane::sessionStateChanged(QString strId, KSessionState state) 795 885 { 886 /* Prevent snapshot editing in the meantime: */ 796 887 SnapshotEditBlocker guardBlock (mEditProtector); 797 888 889 /* Make sure it's our VM: */ 798 890 if (strId != mMachineId) 799 891 return; 800 892 893 /* Recache new session state: */ 801 894 mSessionState = state; 802 895 onCurrentChanged (mTreeWidget->currentItem()); … … 805 898 void UISnapshotPane::updateSnapshotsAge() 806 899 { 900 /* Stop timer if active: */ 807 901 if (mAgeUpdateTimer.isActive()) 808 902 mAgeUpdateTimer.stop(); 809 903 904 /* Search for smallest snapshot age to optimize timer timeout: */ 810 905 SnapshotAgeFormat age = traverseSnapshotAge (mTreeWidget->invisibleRootItem()); 811 812 906 switch (age) 813 907 { … … 829 923 } 830 924 925 /* Restart timer if necessary: */ 831 926 if (mAgeUpdateTimer.interval() > 0) 832 927 mAgeUpdateTimer.start(); … … 842 937 AssertReturn(pItem, (bool)0); 843 938 844 /* Open a session to work with corresponding VM: */939 /* Open a session (this call will handle all errors): */ 845 940 CSession session; 846 941 if (mSessionState != KSessionState_Unlocked) … … 860 955 windowManager().registerNewParent(pDlg, pDlgParent); 861 956 862 / * Assign corresponding icon: */957 // TODO: Assign corresponding icon through sub-dialog API: */ 863 958 pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(mMachine.GetOSTypeId())); 864 959 … … 876 971 ++iterator; 877 972 } 973 // TODO: Assign corresponding snapshot name through sub-dialog API: */ 878 974 pDlg->mLeName->setText(snapShotName.arg(iMaxSnapShotIndex + 1)); 879 975 880 /* Exec thedialog: */976 /* Show Take Snapshot dialog: */ 881 977 bool fDialogAccepted = pDlg->exec() == QDialog::Accepted; 882 978 … … 884 980 if (pDlg) 885 981 { 886 /* Acquire variables: */982 /* Acquire snapshot name/description: */ 887 983 QString strSnapshotName = pDlg->mLeName->text().trimmed(); 888 984 QString strSnapshotDescription = pDlg->mTeDescription->toPlainText(); … … 894 990 if (fDialogAccepted) 895 991 { 992 /* Take snapshot: */ 896 993 QString strSnapshotId; 897 /* Prepare the take-snapshot progress: */898 994 CProgress progress = machine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotId); 899 995 if (machine.isOk()) 900 996 { 901 /* Show the take-snapshot progress: */902 997 msgCenter().showModalProgressDialog(progress, mMachine.GetName(), ":/progress_snapshot_create_90px.png"); 903 998 if (!progress.isOk() || progress.GetResultCode() != 0) … … 929 1024 void UISnapshotPane::refreshAll() 930 1025 { 1026 /* Prevent snapshot editing in the meantime: */ 931 1027 SnapshotEditBlocker guardBlock (mEditProtector); 932 1028 1029 /* If VM is null, just updated the current itm: */ 933 1030 if (mMachine.isNull()) 934 1031 { … … 937 1034 } 938 1035 1036 /* Remember the selected item and it's first child: */ 939 1037 QString selectedItem, firstChildOfSelectedItem; 940 1038 SnapshotWgtItem *cur = !mTreeWidget->currentItem() ? 0 : … … 947 1045 } 948 1046 1047 /* Clear the tree: */ 949 1048 mTreeWidget->clear(); 950 1049 951 /* Get the first snapshot*/1050 /* If machine has snapshots: */ 952 1051 if (mMachine.GetSnapshotCount() > 0) 953 1052 { 1053 /* Get the first snapshot: */ 954 1054 CSnapshot snapshot = mMachine.FindSnapshot(QString::null); 955 1055 1056 /* Populate snapshot tree: */ 956 1057 populateSnapshots (snapshot, 0); 1058 /* And make sure it has current snapshot item: */ 957 1059 Assert (mCurSnapshotItem); 958 1060 959 /* Add the "current state" item */1061 /* Add the "current state" item as a child to current snapshot item: */ 960 1062 SnapshotWgtItem *csi = new SnapshotWgtItem(this, mCurSnapshotItem, mMachine); 961 1063 csi->setBold (true); 962 1064 csi->recache(); 963 1065 1066 /* Search for a previously selected item: */ 964 1067 SnapshotWgtItem *cur = findItem (selectedItem); 965 1068 if (cur == 0) … … 968 1071 cur = curStateItem(); 969 1072 1073 /* Choose current item: */ 970 1074 mTreeWidget->scrollToItem (cur); 971 1075 mTreeWidget->setCurrentItem (cur); 972 1076 onCurrentChanged (cur); 973 1077 } 1078 /* If machine has no snapshots: */ 974 1079 else 975 1080 { 1081 /* There is no current snapshot item: */ 976 1082 mCurSnapshotItem = 0; 977 1083 978 /* Add the "current state" item */1084 /* Add the "current state" item as a child of tree-widget: */ 979 1085 SnapshotWgtItem *csi = new SnapshotWgtItem(this, mTreeWidget, mMachine); 980 1086 csi->setBold (true); 981 1087 csi->recache(); 982 1088 1089 /* Choose current item: */ 983 1090 mTreeWidget->setCurrentItem (csi); 984 1091 onCurrentChanged (csi); 985 1092 } 986 1093 987 /* Updat ing age*/1094 /* Update age: */ 988 1095 updateSnapshotsAge(); 989 1096 1097 /* Adjust tree-widget: */ 990 1098 mTreeWidget->resizeColumnToContents (0); 991 1099 } … … 993 1101 SnapshotWgtItem* UISnapshotPane::findItem (const QString &aSnapshotId) 994 1102 { 1103 /* Search for the first item with required ID: */ 995 1104 QTreeWidgetItemIterator it (mTreeWidget); 996 1105 while (*it) … … 1002 1111 } 1003 1112 1113 /* Null by default: */ 1004 1114 return 0; 1005 1115 } … … 1007 1117 SnapshotWgtItem *UISnapshotPane::curStateItem() 1008 1118 { 1119 /* Last child of the current snapshot item if any or first child of invisible root item otherwise: */ 1009 1120 QTreeWidgetItem *csi = mCurSnapshotItem ? 1010 1121 mCurSnapshotItem->child (mCurSnapshotItem->childCount() - 1) : … … 1015 1126 void UISnapshotPane::populateSnapshots (const CSnapshot &aSnapshot, QTreeWidgetItem *aItem) 1016 1127 { 1128 /* Create a child of passed item: */ 1017 1129 SnapshotWgtItem *item = aItem ? new SnapshotWgtItem(this, aItem, aSnapshot) : 1018 1130 new SnapshotWgtItem(this, mTreeWidget, aSnapshot); 1131 /* And recache it's content: */ 1019 1132 item->recache(); 1020 1133 1134 /* Mark current snapshot item bold and remember it: */ 1021 1135 CSnapshot curSnapshot = mMachine.GetCurrentSnapshot(); 1022 1136 if (!curSnapshot.isNull() && curSnapshot.GetId() == aSnapshot.GetId()) … … 1026 1140 } 1027 1141 1142 /* Walk through the children recursively: */ 1028 1143 CSnapshotVector snapshots = aSnapshot.GetChildren(); 1029 1144 foreach (const CSnapshot &snapshot, snapshots) 1030 1145 populateSnapshots (snapshot, item); 1031 1146 1147 /* Expand the newly created item: */ 1032 1148 item->setExpanded (true); 1149 /* And mark it as editable: */ 1033 1150 item->setFlags (item->flags() | Qt::ItemIsEditable); 1034 1151 } … … 1036 1153 SnapshotAgeFormat UISnapshotPane::traverseSnapshotAge (QTreeWidgetItem *aParentItem) 1037 1154 { 1155 /* Make sure passed root is of valid type: */ 1038 1156 SnapshotWgtItem *parentItem = aParentItem->type() == SnapshotWgtItem::ItemType ? 1039 1157 static_cast <SnapshotWgtItem*> (aParentItem) : 0; 1040 1158 1159 /* Fetch the snapshot age of the root if it's valid: */ 1041 1160 SnapshotAgeFormat age = parentItem ? parentItem->updateAge() : AgeMax; 1161 1162 /* Walk through the children recursively: */ 1042 1163 for (int i = 0; i < aParentItem->childCount(); ++ i) 1043 1164 { 1165 /* Fetch the smallest snapshot age of the children: */ 1044 1166 SnapshotAgeFormat newAge = traverseSnapshotAge (aParentItem->child (i)); 1167 /* Remember the smallest snapshot age among existing: */ 1045 1168 age = newAge < age ? newAge : age; 1046 1169 } 1047 1170 1171 /* Return result: */ 1048 1172 return age; 1049 1173 } -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h
r63804 r63818 16 16 */ 17 17 18 #ifndef __ UISnapshotPane_h__19 #define __ UISnapshotPane_h__18 #ifndef ___UISnapshotPane_h___ 19 #define ___UISnapshotPane_h___ 20 20 21 21 /* Qt includes: */ … … 31 31 #include "CMachine.h" 32 32 33 /* Local forwards*/33 /* Forward declarations: */ 34 34 class SnapshotWgtItem; 35 35 36 /* Snapshot age format */ 36 37 /** Snapshot age format. */ 37 38 enum SnapshotAgeFormat 38 39 { … … 44 45 }; 45 46 47 48 /** QWidget extension providing GUI with the pane to control snapshot related functionality. */ 46 49 class UISnapshotPane : public QIWithRetranslateUI <QWidget>, public Ui::UISnapshotPane 47 50 { … … 50 53 public: 51 54 55 /** Constructs snapshot pane passing @a aParent to the base-class. */ 52 56 UISnapshotPane(QWidget *aParent); 53 57 58 /** Defines the @a aMachine to be parsed. */ 54 59 void setMachine (const CMachine &aMachine); 55 60 … … 59 64 protected: 60 65 66 /** Handles translation event. */ 61 67 void retranslateUi(); 62 68 63 69 private slots: 64 70 65 /* Snapshot tree slots: */ 66 void onCurrentChanged (QTreeWidgetItem *aItem = 0); 67 void onContextMenuRequested (const QPoint &aPoint); 68 void onItemChanged (QTreeWidgetItem *aItem); 69 void sltItemDoubleClicked(QTreeWidgetItem *pItem); 71 /** @name Tree-view handlers 72 * @{ */ 73 /** Handles cursor change to @a aItem. */ 74 void onCurrentChanged (QTreeWidgetItem *aItem = 0); 75 /** Handles context menu request for @a aPoint. */ 76 void onContextMenuRequested (const QPoint &aPoint); 77 /** Handles modification for @a aItem. */ 78 void onItemChanged (QTreeWidgetItem *aItem); 79 /** Handles double-click for @a pItem. */ 80 void sltItemDoubleClicked(QTreeWidgetItem *pItem); 81 /** @} */ 70 82 71 /* Snapshot functionality slots: */ 72 void sltTakeSnapshot(); 73 void sltRestoreSnapshot(bool fSuppressNonCriticalWarnings = false); 74 void sltDeleteSnapshot(); 75 void sltShowSnapshotDetails(); 76 void sltCloneSnapshot(); 83 /** @name Snapshot operations 84 * @{ */ 85 /** Proposes to take a snapshot. */ 86 void sltTakeSnapshot(); 87 /** Proposes to restore the snapshot. */ 88 void sltRestoreSnapshot(bool fSuppressNonCriticalWarnings = false); 89 /** Proposes to delete the snapshot. */ 90 void sltDeleteSnapshot(); 91 /** Displays the snapshot details dialog. */ 92 void sltShowSnapshotDetails(); 93 /** Proposes to clone the snapshot. */ 94 void sltCloneSnapshot(); 95 /** @} */ 77 96 78 /* Main API event handlers: */ 79 void machineDataChanged(QString strId); 80 void machineStateChanged(QString strId, KMachineState state); 81 void sessionStateChanged(QString strId, KSessionState state); 97 /** @name Main event handlers 98 * @{ */ 99 /** Handles machine data change for machine with @a strId. */ 100 void machineDataChanged(QString strId); 101 /** Handles machine @a state change for machine with @a strId. */ 102 void machineStateChanged(QString strId, KMachineState state); 103 /** Handles session @a state change for machine with @a strId. */ 104 void sessionStateChanged(QString strId, KSessionState state); 105 /** @} */ 82 106 83 void updateSnapshotsAge(); 107 /** @name Timer event handlers 108 * @{ */ 109 /** Updates snapshots age. */ 110 void updateSnapshotsAge(); 111 /** @} */ 84 112 85 113 private: 86 114 87 /* Snapshot private functions: */ 88 bool takeSnapshot(); 89 //bool restoreSnapshot(); 90 //bool deleteSnapshot(); 91 //bool showSnapshotDetails(); 115 /** @name Snapshot operations 116 * @{ */ 117 /** Proposes to take a snapshot. */ 118 bool takeSnapshot(); 119 /** Proposes to restore the snapshot. */ 120 //bool restoreSnapshot(); 121 /** Proposes to delete the snapshot. */ 122 //bool deleteSnapshot(); 123 /** Displays the snapshot details dialog. */ 124 //bool showSnapshotDetails(); 125 /** Proposes to clone the snapshot. */ 126 //bool cloneSnapshot(); 127 /** @} */ 92 128 129 /** Refreshes everything. */ 93 130 void refreshAll(); 131 132 /** Searches for an item with corresponding @a aSnapshotId. */ 94 133 SnapshotWgtItem* findItem (const QString &aSnapshotId); 134 /** Returns the "current state" item. */ 95 135 SnapshotWgtItem* curStateItem(); 136 137 /** Populates snapshot items for corresponding @a aSnapshot using @a aItem as parent. */ 96 138 void populateSnapshots (const CSnapshot &aSnapshot, QTreeWidgetItem *aItem); 139 140 /** Searches for smallest snapshot age starting with @a aParentItem as parent. */ 97 141 SnapshotAgeFormat traverseSnapshotAge (QTreeWidgetItem *aParentItem); 98 142 143 /** Holds the machine COM wrapper. */ 99 144 CMachine mMachine; 145 /** Holds the machine ID. */ 100 146 QString mMachineId; 147 /** Holds the cached session state. */ 101 148 KSessionState mSessionState; 149 /** Holds the current snapshot item reference. */ 102 150 SnapshotWgtItem *mCurSnapshotItem; 151 /** Holds the snapshot item editing protector. */ 103 152 bool mEditProtector; 104 153 154 /** Holds the snapshot item action group instance. */ 105 155 QActionGroup *mSnapshotActionGroup; 156 /** Holds the current item action group instance. */ 106 157 QActionGroup *mCurStateActionGroup; 107 158 159 /** Holds the snapshot restore action instance. */ 108 160 QAction *mRestoreSnapshotAction; 161 /** Holds the snapshot delete action instance. */ 109 162 QAction *mDeleteSnapshotAction; 163 /** Holds the show snapshot details action instance. */ 110 164 QAction *mShowSnapshotDetailsAction; 165 /** Holds the snapshot take action instance. */ 111 166 QAction *mTakeSnapshotAction; 167 /** Holds the snapshot clone action instance. */ 112 168 QAction *mCloneSnapshotAction; 113 169 114 QTimer mAgeUpdateTimer; 170 /** Holds the snapshot age update timer. */ 171 QTimer mAgeUpdateTimer; 115 172 116 bool m_fShapshotOperationsAllowed; 173 /** Holds whether the snapshot operations are allowed. */ 174 bool m_fShapshotOperationsAllowed; 117 175 118 /** Pointer tocached snapshot-item pixmap for 'offline' state. */119 QIcon m_offlineSnapshotIcon;120 /** Pointer tocached snapshot-item pixmap for 'online' state. */121 QIcon m_onlineSnapshotIcon;176 /** Holds the cached snapshot-item pixmap for 'offline' state. */ 177 QIcon m_offlineSnapshotIcon; 178 /** Holds the cached snapshot-item pixmap for 'online' state. */ 179 QIcon m_onlineSnapshotIcon; 122 180 }; 123 181 124 #endif // __UISnapshotPane_h__ 182 #endif /* !___UISnapshotPane_h___ */ 183
Note:
See TracChangeset
for help on using the changeset viewer.