- Timestamp:
- Nov 18, 2009 10:17:40 PM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/include/VBoxSnapshotsWgt.h
r23924 r24774 24 24 #define __VBoxSnapshotsWgt_h__ 25 25 26 /* Global includes */ 27 #include <QTimer> 28 26 29 /* Local includes */ 27 30 #include "VBoxSnapshotsWgt.gen.h" … … 31 34 /* Local forwards */ 32 35 class SnapshotWgtItem; 36 37 /* Snapshot age format */ 38 enum SnapshotAgeFormat 39 { 40 AgeInSeconds, 41 AgeInMinutes, 42 AgeInHours, 43 AgeInDays, 44 AgeMax 45 }; 33 46 34 47 class VBoxSnapshotsWgt : public QIWithRetranslateUI <QWidget>, public Ui::VBoxSnapshotsWgt … … 61 74 void sessionStateChanged (const VBoxSessionStateChangeEvent &aEvent); 62 75 76 void updateSnapshotsAge(); 77 63 78 private: 64 79 … … 67 82 SnapshotWgtItem* curStateItem(); 68 83 void populateSnapshots (const CSnapshot &aSnapshot, QTreeWidgetItem *aItem); 84 SnapshotAgeFormat traverseSnapshotAge (QTreeWidgetItem *aParentItem); 69 85 70 86 CMachine mMachine; … … 81 97 QAction *mShowSnapshotDetailsAction; 82 98 QAction *mTakeSnapshotAction; 99 100 QTimer mAgeUpdateTimer; 83 101 }; 84 102 -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxSnapshotsWgt.cpp
r24734 r24774 41 41 public: 42 42 43 enum { ItemType = QTreeWidgetItem::UserType + 1 }; 44 43 45 /* Normal snapshot item (child of tree-widget) */ 44 46 SnapshotWgtItem (QTreeWidget *aTreeWidget, const CSnapshot &aSnapshot) 45 : QTreeWidgetItem (aTreeWidget )47 : QTreeWidgetItem (aTreeWidget, ItemType) 46 48 , mSnapshot (aSnapshot) 47 49 { … … 50 52 /* Normal snapshot item (child of tree-widget-item) */ 51 53 SnapshotWgtItem (QTreeWidgetItem *aRootItem, const CSnapshot &aSnapshot) 52 : QTreeWidgetItem (aRootItem )54 : QTreeWidgetItem (aRootItem, ItemType) 53 55 , mSnapshot (aSnapshot) 54 56 { … … 57 59 /* Current state item (child of tree-widget) */ 58 60 SnapshotWgtItem (QTreeWidget *aTreeWidget, const CMachine &aMachine) 59 : QTreeWidgetItem (aTreeWidget )61 : QTreeWidgetItem (aTreeWidget, ItemType) 60 62 , mMachine (aMachine) 61 63 { … … 65 67 /* Current state item (child of tree-widget-item) */ 66 68 SnapshotWgtItem (QTreeWidgetItem *aRootItem, const CMachine &aMachine) 67 : QTreeWidgetItem (aRootItem )69 : QTreeWidgetItem (aRootItem, ItemType) 68 70 , mMachine (aMachine) 69 71 { 70 72 updateCurrentState (mMachine.GetState()); 73 } 74 75 QVariant data (int aColumn, int aRole) const 76 { 77 switch (aRole) 78 { 79 case Qt::DisplayRole: 80 return QVariant (QString ("%1%2").arg (QTreeWidgetItem::data (aColumn, aRole).toString()).arg (mAge)); 81 default: 82 break; 83 } 84 return QTreeWidgetItem::data (aColumn, aRole); 85 } 86 87 QString text (int aColumn) const 88 { 89 return QTreeWidgetItem::data (aColumn, Qt::DisplayRole).toString(); 71 90 } 72 91 … … 148 167 } 149 168 169 SnapshotAgeFormat updateAge() 170 { 171 QString oldAge (mAge); 172 173 /* Age: [date time|%1d ago|%1h ago|%1min ago|%1sec ago] */ 174 SnapshotAgeFormat ageFormat; 175 if (mTimestamp.daysTo (QDateTime::currentDateTime()) > 30) 176 { 177 mAge = VBoxSnapshotsWgt::tr (" [%1]").arg (mTimestamp.toString (Qt::LocalDate)); 178 ageFormat = AgeMax; 179 } 180 else if (mTimestamp.secsTo (QDateTime::currentDateTime()) > 60 * 60 * 24) 181 { 182 mAge = VBoxSnapshotsWgt::tr (" [%1d ago]").arg (mTimestamp.secsTo (QDateTime::currentDateTime()) / 60 / 60 / 24); 183 ageFormat = AgeInDays; 184 } 185 else if (mTimestamp.secsTo (QDateTime::currentDateTime()) > 60 * 60) 186 { 187 mAge = VBoxSnapshotsWgt::tr (" [%1h ago]").arg (mTimestamp.secsTo (QDateTime::currentDateTime()) / 60 / 60); 188 ageFormat = AgeInHours; 189 } 190 else if (mTimestamp.secsTo (QDateTime::currentDateTime()) > 60) 191 { 192 mAge = VBoxSnapshotsWgt::tr (" [%1min ago]").arg (mTimestamp.secsTo (QDateTime::currentDateTime()) / 60); 193 ageFormat = AgeInMinutes; 194 } 195 else 196 { 197 mAge = VBoxSnapshotsWgt::tr (" [%1sec ago]").arg (mTimestamp.secsTo (QDateTime::currentDateTime())); 198 ageFormat = AgeInSeconds; 199 } 200 201 if (mAge != oldAge) 202 emitDataChanged(); 203 204 return ageFormat; 205 } 206 150 207 private: 151 208 … … 211 268 QString mDesc; 212 269 QDateTime mTimestamp; 270 QString mAge; 213 271 214 272 bool mCurStateModified; … … 308 366 mTakeSnapshotAction->setShortcut (QString ("Ctrl+Shift+S")); 309 367 368 mAgeUpdateTimer.setSingleShot (true); 369 310 370 /* Setup connections */ 311 371 connect (mTreeWidget, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)), … … 328 388 this, SLOT (sessionStateChanged (const VBoxSessionStateChangeEvent&))); 329 389 390 connect (&mAgeUpdateTimer, SIGNAL (timeout()), this, SLOT (updateSnapshotsAge())); 391 330 392 retranslateUi(); 331 393 } … … 406 468 if (item) 407 469 { 408 CSnapshot snap = mMachine.GetSnapshot (item->snapshotId());470 CSnapshot snap = item->snapshotId().isNull() ? CSnapshot() : mMachine.GetSnapshot (item->snapshotId()); 409 471 if (!snap.isNull() && snap.isOk() && snap.GetName() != item->text (0)) 410 472 snap.SetName (item->text (0)); … … 518 580 while (*iterator) 519 581 { 520 QString snapShot = (*iterator)->text (0);582 QString snapShot = static_cast <SnapshotWgtItem*> (*iterator)->text (0); 521 583 int pos = regExp.indexIn (snapShot); 522 584 if (pos != -1) … … 584 646 mSessionState = aEvent.state; 585 647 onCurrentChanged (mTreeWidget->currentItem()); 648 } 649 650 void VBoxSnapshotsWgt::updateSnapshotsAge() 651 { 652 if (mAgeUpdateTimer.isActive()) 653 mAgeUpdateTimer.stop(); 654 655 SnapshotAgeFormat age = traverseSnapshotAge (mTreeWidget->invisibleRootItem()); 656 657 switch (age) 658 { 659 case AgeInSeconds: 660 mAgeUpdateTimer.setInterval (5 * 1000); 661 break; 662 case AgeInMinutes: 663 mAgeUpdateTimer.setInterval (60 * 1000); 664 break; 665 case AgeInHours: 666 mAgeUpdateTimer.setInterval (60 * 60 * 1000); 667 break; 668 case AgeInDays: 669 mAgeUpdateTimer.setInterval (24 * 60 * 60 * 1000); 670 break; 671 default: 672 mAgeUpdateTimer.setInterval (0); 673 break; 674 } 675 676 if (mAgeUpdateTimer.interval() > 0) 677 mAgeUpdateTimer.start(); 586 678 } 587 679 … … 669 761 } 670 762 763 /* Updating age */ 764 updateSnapshotsAge(); 765 671 766 mTreeWidget->resizeColumnToContents (0); 672 767 } … … 715 810 } 716 811 812 SnapshotAgeFormat VBoxSnapshotsWgt::traverseSnapshotAge (QTreeWidgetItem *aParentItem) 813 { 814 SnapshotWgtItem *parentItem = aParentItem->type() == SnapshotWgtItem::ItemType ? 815 static_cast <SnapshotWgtItem*> (aParentItem) : 0; 816 817 SnapshotAgeFormat age = parentItem ? parentItem->updateAge() : AgeMax; 818 for (int i = 0; i < aParentItem->childCount(); ++ i) 819 { 820 SnapshotAgeFormat newAge = traverseSnapshotAge (aParentItem->child (i)); 821 age = newAge < age ? newAge : age; 822 } 823 824 return age; 825 } 826
Note:
See TracChangeset
for help on using the changeset viewer.