Changeset 63821 in vbox
- Timestamp:
- Sep 13, 2016 6:35:33 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/selector
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.cpp
r63818 r63821 61 61 62 62 /** Constructs normal snapshot item (child of tree-widget). */ 63 SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidget *aTreeWidget, const CSnapshot &aSnapshot)64 : QTreeWidgetItem (aTreeWidget, ItemType)63 SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidget *pTreeWidget, const CSnapshot &comSnapshot) 64 : QTreeWidgetItem(pTreeWidget, ItemType) 65 65 , m_pSnapshotWidget(pSnapshotWidget) 66 , m IsCurrentState(false)67 , m Snapshot (aSnapshot)66 , m_fCurrentState(false) 67 , m_comSnapshot(comSnapshot) 68 68 { 69 69 } 70 70 71 71 /** Constructs normal snapshot item (child of tree-widget-item). */ 72 SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *aRootItem, const CSnapshot &aSnapshot)73 : QTreeWidgetItem (aRootItem, ItemType)72 SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *pRootItem, const CSnapshot &comSnapshot) 73 : QTreeWidgetItem(pRootItem, ItemType) 74 74 , m_pSnapshotWidget(pSnapshotWidget) 75 , m IsCurrentState(false)76 , m Snapshot (aSnapshot)75 , m_fCurrentState(false) 76 , m_comSnapshot(comSnapshot) 77 77 { 78 78 } 79 79 80 80 /** Constructs "current state" item (child of tree-widget). */ 81 SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidget *aTreeWidget, const CMachine &aMachine)82 : QTreeWidgetItem (aTreeWidget, ItemType)81 SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidget *pTreeWidget, const CMachine &comMachine) 82 : QTreeWidgetItem(pTreeWidget, ItemType) 83 83 , m_pSnapshotWidget(pSnapshotWidget) 84 , m IsCurrentState(true)85 , m Machine (aMachine)84 , m_fCurrentState(true) 85 , m_comMachine(comMachine) 86 86 { 87 87 /* Fetch current machine state: */ 88 updateCurrentState (mMachine.GetState());88 updateCurrentState(m_comMachine.GetState()); 89 89 } 90 90 91 91 /** Constructs "current state" item (child of tree-widget-item). */ 92 SnapshotWgtItem (UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *aRootItem, const CMachine &aMachine)93 : QTreeWidgetItem (aRootItem, ItemType)92 SnapshotWgtItem(UISnapshotPane *pSnapshotWidget, QTreeWidgetItem *pRootItem, const CMachine &comMachine) 93 : QTreeWidgetItem(pRootItem, ItemType) 94 94 , m_pSnapshotWidget(pSnapshotWidget) 95 , m IsCurrentState(true)96 , m Machine (aMachine)95 , m_fCurrentState(true) 96 , m_comMachine(comMachine) 97 97 { 98 98 /* Fetch current machine state: */ 99 updateCurrentState (mMachine.GetState());99 updateCurrentState(m_comMachine.GetState()); 100 100 } 101 101 102 102 /** Returns item data for corresponding @a iColumn and @a iRole. */ 103 QVariant data (int aColumn, int aRole) const104 { 105 switch ( aRole)103 QVariant data(int iColumn, int iRole) const 104 { 105 switch (iRole) 106 106 { 107 107 case Qt::DisplayRole: 108 108 { 109 109 /* Call to the base-class for "current state" item, compose ourselves otherwise: */ 110 return m IsCurrentState ? QTreeWidgetItem::data (aColumn, aRole) : QVariant (QString("%1%2")111 .arg (QTreeWidgetItem::data (aColumn, Qt::DisplayRole).toString())112 .arg (QTreeWidgetItem::data (aColumn, Qt::UserRole).toString()));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())); 113 113 } 114 114 case Qt::SizeHintRole: … … 118 118 const int iIconMetric = pStyle->pixelMetric(QStyle::PM_SmallIconSize); 119 119 /* Determine the minimum size-hint for this tree-widget-item: */ 120 const QSize baseSizeHint = QTreeWidgetItem::data( aColumn, aRole).toSize();120 const QSize baseSizeHint = QTreeWidgetItem::data(iColumn, iRole).toSize(); 121 121 /* Determine the effective height-hint for this tree-widget-item: */ 122 122 const int iEffectiveHeightHint = qMax(baseSizeHint.height(), … … 130 130 131 131 /* Call to base-class: */ 132 return QTreeWidgetItem::data (aColumn, aRole);132 return QTreeWidgetItem::data(iColumn, iRole); 133 133 } 134 134 135 135 /** Returns item text for corresponding @a iColumn. */ 136 QString text (int aColumn) const137 { 138 return QTreeWidgetItem::data (aColumn, Qt::DisplayRole).toString();136 QString text(int iColumn) const 137 { 138 return QTreeWidgetItem::data(iColumn, Qt::DisplayRole).toString(); 139 139 } 140 140 … … 142 142 bool isCurrentStateItem() const 143 143 { 144 return m Snapshot.isNull();144 return m_comSnapshot.isNull(); 145 145 } 146 146 147 147 /** Calculates and returns the current item level. */ 148 int level() 149 { 150 QTreeWidgetItem *item = this;151 int result = 0;152 while ( item->parent())153 { 154 ++ result;155 item = item->parent();156 } 157 return result;148 int level() const 149 { 150 const QTreeWidgetItem *pItem = this; 151 int iResult = 0; 152 while (pItem->parent()) 153 { 154 ++iResult; 155 pItem = pItem->parent(); 156 } 157 return iResult; 158 158 } 159 159 … … 161 161 bool bold() const { return font (0).bold(); } 162 162 /** Defines whether the font is @a fBold. */ 163 void setBold (bool aBold)163 void setBold(bool fBold) 164 164 { 165 165 /* Update font: */ 166 QFont myFont = font 167 myFont.setBold (aBold);168 setFont 166 QFont myFont = font(0); 167 myFont.setBold(fBold); 168 setFont(0, myFont); 169 169 170 170 /* Adjust text: */ … … 175 175 bool italic() const { return font (0).italic(); } 176 176 /** Defines whether the font is @a fItalic. */ 177 void setItalic (bool aItalic)177 void setItalic(bool fItalic) 178 178 { 179 179 /* Update font: */ 180 QFont myFont = font 181 myFont.setItalic (aItalic);182 setFont 180 QFont myFont = font(0); 181 myFont.setItalic(fItalic); 182 setFont(0, myFont); 183 183 184 184 /* Adjust text: */ … … 187 187 188 188 /** Returns item machine. */ 189 CMachine machine() const { return m Machine; }189 CMachine machine() const { return m_comMachine; } 190 190 /** Returns item snapshot. */ 191 CSnapshot snapshot() const { return m Snapshot; }191 CSnapshot snapshot() const { return m_comSnapshot; } 192 192 /** Returns item snapshot ID. */ 193 QString snapshotI d() const { return mId; }193 QString snapshotID() const { return m_strSnapshotID; } 194 194 195 195 /** Recaches the item's contents. */ … … 197 197 { 198 198 /* For "current state" item: */ 199 if (m IsCurrentState)200 { 201 Assert (!mMachine.isNull());202 m CurStateModified =mMachine.GetCurrentStateModified();203 setText (0, mCurStateModified ?204 UISnapshotPane::tr("Current State (changed)", "Current State (Modified)") :205 UISnapshotPane::tr("Current State", "Current State (Unmodified)"));206 m Desc = mCurStateModified ?207 UISnapshotPane::tr("The current state differs from the state stored in the current snapshot") :208 parent() != 0 ?209 UISnapshotPane::tr("The current state is identical to the state stored in the current snapshot") :210 QString::null;199 if (m_fCurrentState) 200 { 201 AssertReturnVoid(!m_comMachine.isNull()); 202 m_fCurrentStateModified = m_comMachine.GetCurrentStateModified(); 203 setText(0, m_fCurrentStateModified ? 204 UISnapshotPane::tr("Current State (changed)", "Current State (Modified)") : 205 UISnapshotPane::tr("Current State", "Current State (Unmodified)")); 206 m_strDesc = m_fCurrentStateModified ? 207 UISnapshotPane::tr("The current state differs from the state stored in the current snapshot") : 208 parent() != 0 ? 209 UISnapshotPane::tr("The current state is identical to the state stored in the current snapshot") : 210 QString(); 211 211 } 212 212 /* For others: */ 213 213 else 214 214 { 215 Assert (!mSnapshot.isNull());216 m Id =mSnapshot.GetId();217 setText (0,mSnapshot.GetName());218 m Online =mSnapshot.GetOnline();219 setIcon(0, m_pSnapshotWidget->snapshotItemIcon(m Online));220 m Desc =mSnapshot.GetDescription();221 m Timestamp.setTime_t (mSnapshot.GetTimeStamp() / 1000);222 m CurStateModified = false;215 AssertReturnVoid(!m_comSnapshot.isNull()); 216 m_strSnapshotID = m_comSnapshot.GetId(); 217 setText(0, m_comSnapshot.GetName()); 218 m_fOnline = m_comSnapshot.GetOnline(); 219 setIcon(0, m_pSnapshotWidget->snapshotItemIcon(m_fOnline)); 220 m_strDesc = m_comSnapshot.GetDescription(); 221 m_timestamp.setTime_t(m_comSnapshot.GetTimeStamp() / 1000); 222 m_fCurrentStateModified = false; 223 223 } 224 224 … … 230 230 231 231 /** Returns current machine state. */ 232 KMachineState getCurrentState() 232 KMachineState getCurrentState() const 233 233 { 234 234 /* Make sure machine is valid: */ 235 if (m Machine.isNull())235 if (m_comMachine.isNull()) 236 236 return KMachineState_Null; 237 237 238 238 /* Return cached state: */ 239 return m MachineState;239 return m_enmMachineState; 240 240 } 241 241 242 242 /** Recaches current machine state. */ 243 void updateCurrentState (KMachineState aState)243 void updateCurrentState(KMachineState enmState) 244 244 { 245 245 /* Make sure machine is valid: */ 246 if (m Machine.isNull())246 if (m_comMachine.isNull()) 247 247 return; 248 248 249 249 /* Set corresponding icon: */ 250 setIcon(0, gpConverter->toIcon( aState));250 setIcon(0, gpConverter->toIcon(enmState)); 251 251 /* Cache new state: */ 252 m MachineState = aState;252 m_enmMachineState = enmState; 253 253 /* Update timestamp: */ 254 m Timestamp.setTime_t (mMachine.GetLastStateChange() / 1000);254 m_timestamp.setTime_t(m_comMachine.GetLastStateChange() / 1000); 255 255 } 256 256 … … 259 259 { 260 260 /* Prepare age: */ 261 QString age;261 QString strAge; 262 262 263 263 /* Age: [date time|%1d ago|%1h ago|%1min ago|%1sec ago] */ 264 SnapshotAgeFormat ageFormat;265 QDateTime now = QDateTime::currentDateTime();266 QDateTime then = m Timestamp;264 SnapshotAgeFormat enmAgeFormat; 265 const QDateTime now = QDateTime::currentDateTime(); 266 QDateTime then = m_timestamp; 267 267 if (then > now) 268 268 then = now; /* can happen if the host time is wrong */ 269 if (then.daysTo 270 { 271 age = UISnapshotPane::tr (" (%1)").arg (then.toString(Qt::LocalDate));272 ageFormat = AgeMax;273 } 274 else if (then.secsTo 275 { 276 age = UISnapshotPane::tr (" (%1 ago)").arg(VBoxGlobal::daysToString(then.secsTo(now) / 60 / 60 / 24));277 ageFormat = AgeInDays;278 } 279 else if (then.secsTo 280 { 281 age = UISnapshotPane::tr (" (%1 ago)").arg(VBoxGlobal::hoursToString(then.secsTo(now) / 60 / 60));282 ageFormat = AgeInHours;283 } 284 else if (then.secsTo 285 { 286 age = UISnapshotPane::tr (" (%1 ago)").arg(VBoxGlobal::minutesToString(then.secsTo(now) / 60));287 ageFormat = AgeInMinutes;269 if (then.daysTo(now) > 30) 270 { 271 strAge = UISnapshotPane::tr(" (%1)").arg(then.toString(Qt::LocalDate)); 272 enmAgeFormat = SnapshotAgeFormat_Max; 273 } 274 else if (then.secsTo(now) > 60 * 60 * 24) 275 { 276 strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::daysToString(then.secsTo(now) / 60 / 60 / 24)); 277 enmAgeFormat = SnapshotAgeFormat_InDays; 278 } 279 else if (then.secsTo(now) > 60 * 60) 280 { 281 strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::hoursToString(then.secsTo(now) / 60 / 60)); 282 enmAgeFormat = SnapshotAgeFormat_InHours; 283 } 284 else if (then.secsTo(now) > 60) 285 { 286 strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::minutesToString(then.secsTo(now) / 60)); 287 enmAgeFormat = SnapshotAgeFormat_InMinutes; 288 288 } 289 289 else 290 290 { 291 age = UISnapshotPane::tr (" (%1 ago)").arg(VBoxGlobal::secondsToString(then.secsTo(now)));292 ageFormat = AgeInSeconds;291 strAge = UISnapshotPane::tr(" (%1 ago)").arg(VBoxGlobal::secondsToString(then.secsTo(now))); 292 enmAgeFormat = SnapshotAgeFormat_InSeconds; 293 293 } 294 294 295 295 /* Update data: */ 296 setData (0, Qt::UserRole, age);296 setData(0, Qt::UserRole, strAge); 297 297 298 298 /* Return age: */ 299 return ageFormat;300 } 301 302 pr ivate:299 return enmAgeFormat; 300 } 301 302 protected: 303 303 304 304 /** Adjusts item text. */ … … 306 306 { 307 307 if (!treeWidget()) return; /* only for initialised items */ 308 QFontMetrics metrics (font(0));309 int hei0 = (metrics.height() > 16 ?310 metrics.height() /* text */ : 16 /* icon */) +311 2 * 2 /* 2 pixel per margin */;312 int wid0 = metrics.width (text(0)) /* text */ +313 treeWidget()->indentation() /* indent */ +314 16 /* icon */;308 QFontMetrics metrics(font(0)); 309 int iHei0 = (metrics.height() > 16 ? 310 metrics.height() /* text */ : 16 /* icon */) + 311 2 * 2 /* 2 pixel per margin */; 312 int iWid0 = metrics.width(text(0)) /* text */ + 313 treeWidget()->indentation() /* indent */ + 314 16 /* icon */; 315 315 316 316 /* Adjust size finally: */ 317 setSizeHint (0, QSize (wid0, hei0));317 setSizeHint(0, QSize(iWid0, iHei0)); 318 318 } 319 319 … … 322 322 { 323 323 /* Is the saved date today? */ 324 QString name = text(0);324 const QString strName = text(0); 325 325 326 326 /* Compose date time: */ 327 bool dateTimeToday = mTimestamp.date() == QDate::currentDate();328 QString dateTime = dateTimeToday ?329 mTimestamp.time().toString(Qt::LocalDate) :330 mTimestamp.toString(Qt::LocalDate);327 const bool fDateTimeToday = m_timestamp.date() == QDate::currentDate(); 328 QString strDateTime = fDateTimeToday ? 329 m_timestamp.time().toString(Qt::LocalDate) : 330 m_timestamp.toString(Qt::LocalDate); 331 331 332 332 /* Prepare details: */ 333 QString details;333 QString strDetails; 334 334 335 335 /* For snapshot item: */ 336 if (!m Snapshot.isNull())337 { 338 /* The current snapshot is always bold */336 if (!m_comSnapshot.isNull()) 337 { 338 /* The current snapshot is always bold: */ 339 339 if (bold()) 340 details = UISnapshotPane::tr(" (current, ", "Snapshot details");340 strDetails = UISnapshotPane::tr(" (current, ", "Snapshot details"); 341 341 else 342 details = " (";342 strDetails = " ("; 343 343 344 344 /* Add online/offline information: */ 345 details += mOnline ? UISnapshotPane::tr("online)", "Snapshot details")346 : UISnapshotPane::tr("offline)", "Snapshot details");345 strDetails += m_fOnline ? UISnapshotPane::tr("online)", "Snapshot details") 346 : UISnapshotPane::tr("offline)", "Snapshot details"); 347 347 348 348 /* Add date/time information: */ 349 if ( dateTimeToday)350 dateTime = UISnapshotPane::tr ("Taken at %1", "Snapshot (time)").arg (dateTime);349 if (fDateTimeToday) 350 strDateTime = UISnapshotPane::tr("Taken at %1", "Snapshot (time)").arg(strDateTime); 351 351 else 352 dateTime = UISnapshotPane::tr ("Taken on %1", "Snapshot (date + time)").arg (dateTime);352 strDateTime = UISnapshotPane::tr("Taken on %1", "Snapshot (date + time)").arg(strDateTime); 353 353 } 354 354 /* For "current state" item: */ 355 355 else 356 356 { 357 dateTime = UISnapshotPane::tr("%1 since %2", "Current State (time or date + time)")358 .arg (gpConverter->toString (mMachineState)).arg (dateTime);357 strDateTime = UISnapshotPane::tr("%1 since %2", "Current State (time or date + time)") 358 .arg(gpConverter->toString(m_enmMachineState)).arg(strDateTime); 359 359 } 360 360 361 361 /* Prepare tool-tip: */ 362 QString toolTip = QString("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>")363 .arg (name) .arg (details).arg (dateTime);362 QString strToolTip = QString("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>") 363 .arg(strName).arg(strDetails).arg(strDateTime); 364 364 365 365 /* Append description if any: */ 366 if (!m Desc.isEmpty())367 toolTip += "<hr>" + mDesc;366 if (!m_strDesc.isEmpty()) 367 strToolTip += "<hr>" + m_strDesc; 368 368 369 369 /* Assign tool-tip finally: */ 370 setToolTip (0, toolTip); 371 } 370 setToolTip(0, strToolTip); 371 } 372 373 private: 372 374 373 375 /** Holds the pointer to the snapshot-widget this item belongs to. */ … … 375 377 376 378 /** Holds whether this is a "current state" item. */ 377 bool mIsCurrentState;379 bool m_fCurrentState; 378 380 379 381 /** Holds the snapshot COM wrapper. */ 380 CSnapshot mSnapshot;382 CSnapshot m_comSnapshot; 381 383 /** Holds the machine COM wrapper. */ 382 CMachine mMachine;384 CMachine m_comMachine; 383 385 384 386 /** Holds the current snapshot ID. */ 385 QString mId;387 QString m_strSnapshotID; 386 388 /** Holds whether the current snapshot is online one. */ 387 bool mOnline;389 bool m_fOnline; 388 390 389 391 /** Holds the item description. */ 390 QString mDesc;392 QString m_strDesc; 391 393 /** Holds the item timestamp. */ 392 QDateTime mTimestamp;394 QDateTime m_timestamp; 393 395 394 396 /** Holds whether the current state is modified. */ 395 bool mCurStateModified;397 bool m_fCurrentStateModified; 396 398 /** Holds the cached machine state. */ 397 KMachineState mMachineState;399 KMachineState m_enmMachineState; 398 400 }; 399 401 … … 407 409 408 410 /** Constructs edit blocker. */ 409 SnapshotEditBlocker (bool &aProtector)410 : m Protector (aProtector)411 { 412 m Protector = true;411 SnapshotEditBlocker(bool &fProtector) 412 : m_fProtector(fProtector) 413 { 414 m_fProtector = true; 413 415 } 414 416 415 417 /** Destructs edit blocker. */ 416 ~SnapshotEditBlocker()417 { 418 m Protector = false;418 virtual ~SnapshotEditBlocker() 419 { 420 m_fProtector = false; 419 421 } 420 422 … … 422 424 423 425 /** Holds the protector flag reference. */ 424 bool &m Protector;426 bool &m_fProtector; 425 427 }; 426 428 427 429 428 UISnapshotPane::UISnapshotPane (QWidget *aParent)429 : QIWithRetranslateUI <QWidget> (aParent)430 , m CurSnapshotItem(0)431 , m EditProtector(false)432 , m SnapshotActionGroup (new QActionGroup(this))433 , m CurStateActionGroup (new QActionGroup(this))434 , m RestoreSnapshotAction (new QAction (mSnapshotActionGroup))435 , m DeleteSnapshotAction (new QAction (mSnapshotActionGroup))436 , m ShowSnapshotDetailsAction (new QAction (mSnapshotActionGroup))437 , m TakeSnapshotAction (new QAction (mCurStateActionGroup))438 , m CloneSnapshotAction(new QAction(mCurStateActionGroup))430 UISnapshotPane::UISnapshotPane(QWidget *pParent) 431 : QIWithRetranslateUI<QWidget>(pParent) 432 , m_pCurrentSnapshotItem(0) 433 , m_fEditProtector(false) 434 , m_pSnapshotItemActionGroup(new QActionGroup(this)) 435 , m_pCurrentStateItemActionGroup(new QActionGroup(this)) 436 , m_pActionRestoreSnapshot(new QAction(m_pSnapshotItemActionGroup)) 437 , m_pActionDeleteSnapshot(new QAction(m_pSnapshotItemActionGroup)) 438 , m_pActionShowSnapshotDetails(new QAction(m_pSnapshotItemActionGroup)) 439 , m_pActionTakeSnapshot(new QAction(m_pCurrentStateItemActionGroup)) 440 , m_pActionCloneSnapshot(new QAction(m_pCurrentStateItemActionGroup)) 439 441 , m_fShapshotOperationsAllowed(false) 440 442 { 441 443 /* Apply UI decorations: */ 442 Ui::UISnapshotPane::setupUi 444 Ui::UISnapshotPane::setupUi(this); 443 445 444 446 /* No header: */ 445 m TreeWidget->header()->hide();447 m_pTreeWidget->header()->hide(); 446 448 447 449 #if QT_VERSION < 0x050000 … … 455 457 // draws required thing like we want. */ 456 458 // #if defined(RT_OS_DARWIN) || defined(RT_OS_LINUX) || defined(RT_OS_SOLARIS) 457 QWindowsStyle * treeWidgetStyle = new QWindowsStyle;458 m TreeWidget->setStyle (treeWidgetStyle);459 connect (mTreeWidget, SIGNAL (destroyed (QObject *)), treeWidgetStyle, SLOT(deleteLater()));459 QWindowsStyle *pTreeWidgetStyle = new QWindowsStyle; 460 m_pTreeWidget->setStyle(pTreeWidgetStyle); 461 connect(m_pTreeWidget, SIGNAL(destroyed(QObject *)), pTreeWidgetStyle, SLOT(deleteLater())); 460 462 // #endif 461 463 #endif /* QT_VERSION < 0x050000 */ 462 464 463 465 /* Cache pixmaps: */ 464 m_ offlineSnapshotIcon= UIIconPool::iconSet(":/snapshot_offline_16px.png");465 m_ onlineSnapshotIcon= UIIconPool::iconSet(":/snapshot_online_16px.png");466 m_snapshotIconOffline = UIIconPool::iconSet(":/snapshot_offline_16px.png"); 467 m_snapshotIconOnline = UIIconPool::iconSet(":/snapshot_online_16px.png"); 466 468 467 469 /* Determine icon metric: */ … … 470 472 471 473 /* Create tool-bar: */ 472 UIToolBar * toolBar = new UIToolBar(this);473 toolBar->setIconSize (QSize(iIconMetric, iIconMetric));474 toolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);474 UIToolBar *pToolBar = new UIToolBar(this); 475 pToolBar->setIconSize(QSize(iIconMetric, iIconMetric)); 476 pToolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed); 475 477 /* Add actions into tool-bar: */ 476 toolBar->addAction (mTakeSnapshotAction);477 toolBar->addSeparator();478 toolBar->addAction (mRestoreSnapshotAction);479 toolBar->addAction (mDeleteSnapshotAction);480 toolBar->addAction (mShowSnapshotDetailsAction);481 toolBar->addSeparator();482 toolBar->addAction(mCloneSnapshotAction);478 pToolBar->addAction(m_pActionTakeSnapshot); 479 pToolBar->addSeparator(); 480 pToolBar->addAction(m_pActionRestoreSnapshot); 481 pToolBar->addAction(m_pActionDeleteSnapshot); 482 pToolBar->addAction(m_pActionShowSnapshotDetails); 483 pToolBar->addSeparator(); 484 pToolBar->addAction(m_pActionCloneSnapshot); 483 485 /* Add tool-bar into layout: */ 484 ((QVBoxLayout*)layout())->insertWidget (0, toolBar);486 ((QVBoxLayout*)layout())->insertWidget(0, pToolBar); 485 487 486 488 /* Setup action icons: */ 487 m RestoreSnapshotAction->setIcon(UIIconPool::iconSetFull(489 m_pActionRestoreSnapshot->setIcon(UIIconPool::iconSetFull( 488 490 ":/snapshot_restore_22px.png", ":/snapshot_restore_16px.png", 489 491 ":/snapshot_restore_disabled_22px.png", ":/snapshot_restore_disabled_16px.png")); 490 m DeleteSnapshotAction->setIcon(UIIconPool::iconSetFull(492 m_pActionDeleteSnapshot->setIcon(UIIconPool::iconSetFull( 491 493 ":/snapshot_delete_22px.png", ":/snapshot_delete_16px.png", 492 494 ":/snapshot_delete_disabled_22px.png", ":/snapshot_delete_disabled_16px.png")); 493 m ShowSnapshotDetailsAction->setIcon(UIIconPool::iconSetFull(495 m_pActionShowSnapshotDetails->setIcon(UIIconPool::iconSetFull( 494 496 ":/snapshot_show_details_22px.png", ":/snapshot_show_details_16px.png", 495 497 ":/snapshot_show_details_disabled_22px.png", ":/snapshot_details_show_disabled_16px.png")); 496 m TakeSnapshotAction->setIcon(UIIconPool::iconSetFull(498 m_pActionTakeSnapshot->setIcon(UIIconPool::iconSetFull( 497 499 ":/snapshot_take_22px.png", ":/snapshot_take_16px.png", 498 500 ":/snapshot_take_disabled_22px.png", ":/snapshot_take_disabled_16px.png")); 499 m CloneSnapshotAction->setIcon(UIIconPool::iconSetFull(501 m_pActionCloneSnapshot->setIcon(UIIconPool::iconSetFull( 500 502 ":/vm_clone_22px.png", ":/vm_clone_16px.png", 501 503 ":/vm_clone_disabled_22px.png", ":/vm_clone_disabled_16px.png")); 502 504 /* Setup action shortcuts: */ 503 m RestoreSnapshotAction->setShortcut (QString("Ctrl+Shift+R"));504 m DeleteSnapshotAction->setShortcut (QString("Ctrl+Shift+D"));505 m ShowSnapshotDetailsAction->setShortcut (QString("Ctrl+Space"));506 m TakeSnapshotAction->setShortcut (QString("Ctrl+Shift+S"));507 m CloneSnapshotAction->setShortcut(QString("Ctrl+Shift+C"));505 m_pActionRestoreSnapshot->setShortcut(QString("Ctrl+Shift+R")); 506 m_pActionDeleteSnapshot->setShortcut(QString("Ctrl+Shift+D")); 507 m_pActionShowSnapshotDetails->setShortcut(QString("Ctrl+Space")); 508 m_pActionTakeSnapshot->setShortcut(QString("Ctrl+Shift+S")); 509 m_pActionCloneSnapshot->setShortcut(QString("Ctrl+Shift+C")); 508 510 509 511 /* Setup timer: */ 510 m AgeUpdateTimer.setSingleShot(true);512 m_ageUpdateTimer.setSingleShot(true); 511 513 512 514 /* Setup tree-widget connections: */ 513 connect (mTreeWidget, SIGNAL (currentItemChanged (QTreeWidgetItem*, QTreeWidgetItem*)),514 this, SLOT (onCurrentChanged (QTreeWidgetItem*)));515 connect (mTreeWidget, SIGNAL (customContextMenuRequested (const QPoint&)),516 this, SLOT (onContextMenuRequested (const QPoint&)));517 connect (mTreeWidget, SIGNAL (itemChanged (QTreeWidgetItem*, int)),518 this, SLOT (onItemChanged (QTreeWidgetItem*)));519 connect(m TreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*, int)),520 this, SLOT (sltItemDoubleClicked(QTreeWidgetItem*)));515 connect(m_pTreeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), 516 this, SLOT(sltCurrentItemChanged(QTreeWidgetItem *))); 517 connect(m_pTreeWidget, SIGNAL(customContextMenuRequested(const QPoint &)), 518 this, SLOT(sltContextMenuRequested(const QPoint &))); 519 connect(m_pTreeWidget, SIGNAL(itemChanged(QTreeWidgetItem *, int)), 520 this, SLOT(sltItemChanged(QTreeWidgetItem *))); 521 connect(m_pTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)), 522 this, SLOT(sltItemDoubleClicked(QTreeWidgetItem *))); 521 523 /* Setup snapshot operation connections: */ 522 connect (mTakeSnapshotAction, SIGNAL (triggered()), this, SLOT(sltTakeSnapshot()));523 connect (mRestoreSnapshotAction, SIGNAL (triggered()), this, SLOT(sltRestoreSnapshot()));524 connect (mDeleteSnapshotAction, SIGNAL (triggered()), this, SLOT(sltDeleteSnapshot()));525 connect (mShowSnapshotDetailsAction, SIGNAL (triggered()), this, SLOT(sltShowSnapshotDetails()));526 connect (mCloneSnapshotAction, SIGNAL(triggered()), this, SLOT(sltCloneSnapshot()));524 connect(m_pActionTakeSnapshot, SIGNAL(triggered()), this, SLOT(sltTakeSnapshot())); 525 connect(m_pActionRestoreSnapshot, SIGNAL(triggered()), this, SLOT(sltRestoreSnapshot())); 526 connect(m_pActionDeleteSnapshot, SIGNAL(triggered()), this, SLOT(sltDeleteSnapshot())); 527 connect(m_pActionShowSnapshotDetails, SIGNAL(triggered()), this, SLOT(sltShowSnapshotDetails())); 528 connect(m_pActionCloneSnapshot, SIGNAL(triggered()), this, SLOT(sltCloneSnapshot())); 527 529 /* Setup Main event connections: */ 528 connect 529 this, SLOT(machineDataChanged(QString)));530 connect 531 this, SLOT(machineStateChanged(QString, KMachineState)));532 connect 533 this, SLOT(sessionStateChanged(QString, KSessionState)));530 connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)), 531 this, SLOT(sltMachineDataChange(QString))); 532 connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QString, KMachineState)), 533 this, SLOT(sltMachineStateChange(QString, KMachineState))); 534 connect(gVBoxEvents, SIGNAL(sigSessionStateChange(QString, KSessionState)), 535 this, SLOT(sltSessionStateChange(QString, KSessionState))); 534 536 /* Setup timer event connections: */ 535 connect (&mAgeUpdateTimer, SIGNAL (timeout()), this, SLOT (updateSnapshotsAge()));537 connect(&m_ageUpdateTimer, SIGNAL(timeout()), this, SLOT(sltUpdateSnapshotsAge())); 536 538 537 539 /* Translate finally: */ … … 539 541 } 540 542 541 void UISnapshotPane::setMachine (const CMachine &aMachine)543 void UISnapshotPane::setMachine(const CMachine &comMachine) 542 544 { 543 545 /* Cache passed machine: */ 544 m Machine = aMachine;546 m_comMachine = comMachine; 545 547 546 548 /* Cache machine details: */ 547 if ( aMachine.isNull())548 { 549 m MachineId = QString::null;550 m SessionState = KSessionState_Null;549 if (m_comMachine.isNull()) 550 { 551 m_strMachineID = QString(); 552 m_enmSessionState = KSessionState_Null; 551 553 m_fShapshotOperationsAllowed = false; 552 554 } 553 555 else 554 556 { 555 m MachineId = aMachine.GetId();556 m SessionState = aMachine.GetSessionState();557 m_fShapshotOperationsAllowed = gEDataManager->machineSnapshotOperationsEnabled(m MachineId);557 m_strMachineID = comMachine.GetId(); 558 m_enmSessionState = comMachine.GetSessionState(); 559 m_fShapshotOperationsAllowed = gEDataManager->machineSnapshotOperationsEnabled(m_strMachineID); 558 560 } 559 561 … … 568 570 569 571 /* Translate actions names: */ 570 m RestoreSnapshotAction->setText(tr("&Restore Snapshot"));571 m DeleteSnapshotAction->setText(tr("&Delete Snapshot"));572 m ShowSnapshotDetailsAction->setText(tr("S&how Details"));573 m TakeSnapshotAction->setText(tr("Take &Snapshot"));574 m CloneSnapshotAction->setText(tr("&Clone..."));572 m_pActionRestoreSnapshot->setText(tr("&Restore Snapshot")); 573 m_pActionDeleteSnapshot->setText(tr("&Delete Snapshot")); 574 m_pActionShowSnapshotDetails->setText(tr("S&how Details")); 575 m_pActionTakeSnapshot->setText(tr("Take &Snapshot")); 576 m_pActionCloneSnapshot->setText(tr("&Clone...")); 575 577 /* Translate actions status-tips: */ 576 m RestoreSnapshotAction->setStatusTip(tr("Restore selected snapshot of the virtual machine"));577 m DeleteSnapshotAction->setStatusTip(tr("Delete selected snapshot of the virtual machine"));578 m ShowSnapshotDetailsAction->setStatusTip(tr("Display a window with selected snapshot details"));579 m TakeSnapshotAction->setStatusTip(tr("Take a snapshot of the current virtual machine state"));580 m CloneSnapshotAction->setStatusTip(tr("Clone selected virtual machine"));578 m_pActionRestoreSnapshot->setStatusTip(tr("Restore selected snapshot of the virtual machine")); 579 m_pActionDeleteSnapshot->setStatusTip(tr("Delete selected snapshot of the virtual machine")); 580 m_pActionShowSnapshotDetails->setStatusTip(tr("Display a window with selected snapshot details")); 581 m_pActionTakeSnapshot->setStatusTip(tr("Take a snapshot of the current virtual machine state")); 582 m_pActionCloneSnapshot->setStatusTip(tr("Clone selected virtual machine")); 581 583 /* Translate actions tool-tips: */ 582 m RestoreSnapshotAction->setToolTip(mRestoreSnapshotAction->statusTip() +583 QString(" (%1)").arg(m RestoreSnapshotAction->shortcut().toString()));584 m DeleteSnapshotAction->setToolTip(mDeleteSnapshotAction->statusTip() +585 QString(" (%1)").arg(m DeleteSnapshotAction->shortcut().toString()));586 m ShowSnapshotDetailsAction->setToolTip(mShowSnapshotDetailsAction->statusTip() +587 QString(" (%1)").arg(m ShowSnapshotDetailsAction->shortcut().toString()));588 m TakeSnapshotAction->setToolTip(mTakeSnapshotAction->statusTip() +589 QString(" (%1)").arg(m TakeSnapshotAction->shortcut().toString()));590 m CloneSnapshotAction->setToolTip(mCloneSnapshotAction->statusTip() +591 QString(" (%1)").arg(m CloneSnapshotAction->shortcut().toString()));592 } 593 594 void UISnapshotPane:: onCurrentChanged (QTreeWidgetItem *aItem)595 { 596 /* Make the selected item visible */597 SnapshotWgtItem *item = aItem ? static_cast <SnapshotWgtItem*> (aItem) : 0;598 if ( item)599 { 600 m TreeWidget->horizontalScrollBar()->setValue(0);601 m TreeWidget->scrollToItem (item);602 m TreeWidget->horizontalScrollBar()->setValue (mTreeWidget->indentation() * item->level());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 } 595 596 void UISnapshotPane::sltCurrentItemChanged(QTreeWidgetItem *pItem) 597 { 598 /* Make the selected item visible: */ 599 const SnapshotWgtItem *pSnapshotItem = pItem ? static_cast<const SnapshotWgtItem*>(pItem) : 0; 600 if (pSnapshotItem) 601 { 602 m_pTreeWidget->horizontalScrollBar()->setValue(0); 603 m_pTreeWidget->scrollToItem(pSnapshotItem); 604 m_pTreeWidget->horizontalScrollBar()->setValue(m_pTreeWidget->indentation() * pSnapshotItem->level()); 603 605 } 604 606 605 607 /* Whether another direct session is open or not: */ 606 bool busy =mSessionState != KSessionState_Unlocked;608 const bool fBusy = m_enmSessionState != KSessionState_Unlocked; 607 609 608 610 /* Acquire machine state of the "current state" item: */ 609 KMachineState s= KMachineState_Null;610 if (cur StateItem())611 s = curStateItem()->getCurrentState();611 KMachineState enmState = KMachineState_Null; 612 if (currentStateItem()) 613 enmState = currentStateItem()->getCurrentState(); 612 614 613 615 /* Whether taking or deleting snapshots is possible right now: */ 614 bool canTakeDeleteSnapshot = !busy615 || s== KMachineState_PoweredOff616 || s== KMachineState_Saved617 || s== KMachineState_Aborted618 || s== KMachineState_Running619 || s== KMachineState_Paused;616 const bool canTakeDeleteSnapshot = !fBusy 617 || enmState == KMachineState_PoweredOff 618 || enmState == KMachineState_Saved 619 || enmState == KMachineState_Aborted 620 || enmState == KMachineState_Running 621 || enmState == KMachineState_Paused; 620 622 621 623 /* Enable/disable snapshot operations: */ 622 m RestoreSnapshotAction->setEnabled (!busy && mCurSnapshotItem && item && !item->isCurrentStateItem());623 m DeleteSnapshotAction->setEnabled(m_fShapshotOperationsAllowed &&624 canTakeDeleteSnapshot && mCurSnapshotItem && item && !item->isCurrentStateItem());625 m ShowSnapshotDetailsAction->setEnabled (mCurSnapshotItem && item && !item->isCurrentStateItem());626 m TakeSnapshotAction->setEnabled(m_fShapshotOperationsAllowed &&627 ((canTakeDeleteSnapshot && mCurSnapshotItem && item && item->isCurrentStateItem()) ||628 ( item && !mCurSnapshotItem)));629 m CloneSnapshotAction->setEnabled(!busy && item);630 } 631 632 void UISnapshotPane:: onContextMenuRequested (const QPoint &aPoint)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); 632 } 633 634 void UISnapshotPane::sltContextMenuRequested(const QPoint &point) 633 635 { 634 636 /* Search for corresponding snapshot item: */ 635 QTreeWidgetItem *item = mTreeWidget->itemAt (aPoint);636 SnapshotWgtItem *snapshotItem = item ? static_cast <SnapshotWgtItem*> (item) : 0;637 if (! snapshotItem)637 const QTreeWidgetItem *pItem = m_pTreeWidget->itemAt(point); 638 const SnapshotWgtItem *pSnapshotItem = pItem ? static_cast<const SnapshotWgtItem*>(pItem) : 0; 639 if (!pSnapshotItem) 638 640 return; 639 641 … … 641 643 QMenu menu; 642 644 /* For snapshot item: */ 643 if (m CurSnapshotItem && !snapshotItem->isCurrentStateItem())644 { 645 menu.addAction (mRestoreSnapshotAction);646 menu.addAction (mDeleteSnapshotAction);647 menu.addAction (mShowSnapshotDetailsAction);645 if (m_pCurrentSnapshotItem && !pSnapshotItem->isCurrentStateItem()) 646 { 647 menu.addAction(m_pActionRestoreSnapshot); 648 menu.addAction(m_pActionDeleteSnapshot); 649 menu.addAction(m_pActionShowSnapshotDetails); 648 650 menu.addSeparator(); 649 menu.addAction(m CloneSnapshotAction);651 menu.addAction(m_pActionCloneSnapshot); 650 652 } 651 653 /* For "current state" item: */ 652 654 else 653 655 { 654 menu.addAction (mTakeSnapshotAction);656 menu.addAction(m_pActionTakeSnapshot); 655 657 menu.addSeparator(); 656 menu.addAction(m CloneSnapshotAction);658 menu.addAction(m_pActionCloneSnapshot); 657 659 } 658 660 659 661 /* Show menu: */ 660 menu.exec (mTreeWidget->viewport()->mapToGlobal (aPoint));661 } 662 663 void UISnapshotPane:: onItemChanged (QTreeWidgetItem *aItem)662 menu.exec(m_pTreeWidget->viewport()->mapToGlobal(point)); 663 } 664 665 void UISnapshotPane::sltItemChanged(QTreeWidgetItem *pItem) 664 666 { 665 667 /* Make sure nothing is being edited currently: */ 666 if (m EditProtector)668 if (m_fEditProtector) 667 669 return; 668 670 669 671 /* Make sure snapshot item was changed: */ 670 SnapshotWgtItem *item = aItem ? static_cast <SnapshotWgtItem*> (aItem) : 0;671 672 if ( item)672 const SnapshotWgtItem *pSnapshotItem = pItem ? static_cast<const SnapshotWgtItem*>(pItem) : 0; 673 674 if (pSnapshotItem) 673 675 { 674 676 /* Rename corresponding snapshot: */ 675 CSnapshot snap = item->snapshotId().isNull() ? CSnapshot() : mMachine.FindSnapshot(item->snapshotId());676 if (! snap.isNull() && snap.isOk() && snap.GetName() != item->text(0))677 snap.SetName (item->text(0));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)); 678 680 } 679 681 } … … 682 684 { 683 685 /* Make sure nothing is being edited currently: */ 684 if (m EditProtector)686 if (m_fEditProtector) 685 687 return; 686 688 687 689 /* Make sure snapshot item was double-clicked: */ 688 SnapshotWgtItem *pValidItem = pItem ? static_cast<SnapshotWgtItem*>(pItem) : 0;689 if (!p ValidItem)690 const SnapshotWgtItem *pSnapshotItem = pItem ? static_cast<const SnapshotWgtItem*>(pItem) : 0; 691 if (!pSnapshotItem) 690 692 return; 691 693 … … 703 705 } 704 706 705 void UISnapshotPane::sltRestoreSnapshot(bool fSuppressNonCriticalWarnings /* = false */)707 void UISnapshotPane::sltRestoreSnapshot(bool fSuppressNonCriticalWarnings /* = false */) 706 708 { 707 709 /* Get currently chosen item: */ 708 SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0;709 AssertReturn (pItem, (void)0);710 const SnapshotWgtItem *pSnapshotItem = m_pTreeWidget->currentItem() ? static_cast<const SnapshotWgtItem*>(m_pTreeWidget->currentItem()) : 0; 711 AssertReturnVoid(pSnapshotItem); 710 712 711 713 /* Detemine snapshot id: */ 712 QString strSnapshotId = pItem->snapshotId();713 AssertReturn (!strSnapshotId.isNull(), (void)0);714 const QString strSnapshotID = pSnapshotItem->snapshotID(); 715 AssertReturnVoid(!strSnapshotID.isNull()); 714 716 /* Get currently desired snapshot: */ 715 CSnapshot snapshot = mMachine.FindSnapshot(strSnapshotId);717 const CSnapshot comSnapshot = m_comMachine.FindSnapshot(strSnapshotID); 716 718 717 719 /* Ask the user if he really wants to restore the snapshot: */ 718 720 int iResultCode = AlertButton_Ok; 719 if (!fSuppressNonCriticalWarnings || m Machine.GetCurrentStateModified())720 { 721 iResultCode = msgCenter().confirmSnapshotRestoring( snapshot.GetName(),mMachine.GetCurrentStateModified());721 if (!fSuppressNonCriticalWarnings || m_comMachine.GetCurrentStateModified()) 722 { 723 iResultCode = msgCenter().confirmSnapshotRestoring(comSnapshot.GetName(), m_comMachine.GetCurrentStateModified()); 722 724 if (iResultCode & AlertButton_Cancel) 723 725 return; … … 728 730 { 729 731 /* Take snapshot of changed current state: */ 730 m TreeWidget->setCurrentItem(curStateItem());732 m_pTreeWidget->setCurrentItem(currentStateItem()); 731 733 if (!takeSnapshot()) 732 734 return; … … 734 736 735 737 /* Open a direct session (this call will handle all errors): */ 736 CSession session = vboxGlobal().openSession(mMachineId);737 if ( session.isNull())738 CSession comSession = vboxGlobal().openSession(m_strMachineID); 739 if (comSession.isNull()) 738 740 return; 739 741 740 742 /* Restore chosen snapshot: */ 741 CMachine machine = session.GetMachine();742 CProgress progress = machine.RestoreSnapshot(snapshot);743 if ( machine.isOk())744 { 745 msgCenter().showModalProgressDialog( progress,mMachine.GetName(), ":/progress_snapshot_restore_90px.png");746 if ( progress.GetResultCode() != 0)747 msgCenter().cannotRestoreSnapshot( progress, snapshot.GetName(),mMachine.GetName());743 CMachine comMachine = comSession.GetMachine(); 744 CProgress comProgress = comMachine.RestoreSnapshot(comSnapshot); 745 if (comMachine.isOk()) 746 { 747 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_restore_90px.png"); 748 if (comProgress.GetResultCode() != 0) 749 msgCenter().cannotRestoreSnapshot(comProgress, comSnapshot.GetName(), m_comMachine.GetName()); 748 750 } 749 751 else 750 msgCenter().cannotRestoreSnapshot( machine, snapshot.GetName(),mMachine.GetName());752 msgCenter().cannotRestoreSnapshot(comMachine, comSnapshot.GetName(), m_comMachine.GetName()); 751 753 752 754 /* Unlock machine finally: */ 753 session.UnlockMachine();755 comSession.UnlockMachine(); 754 756 } 755 757 … … 757 759 { 758 760 /* Get currently chosen item: */ 759 SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :760 static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());761 AssertReturn (item, (void) 0);761 const SnapshotWgtItem *pSnapshotItem = !m_pTreeWidget->currentItem() ? 0 : 762 static_cast<const SnapshotWgtItem*>(m_pTreeWidget->currentItem()); 763 AssertReturnVoid(pSnapshotItem); 762 764 763 765 /* Detemine snapshot id: */ 764 QString snapId = item->snapshotId();765 AssertReturn (!snapId.isNull(), (void) 0);766 const QString strSnapshotID = pSnapshotItem->snapshotID(); 767 AssertReturnVoid(!strSnapshotID.isNull()); 766 768 /* Get currently desired snapshot: */ 767 CSnapshot snapshot = mMachine.FindSnapshot(snapId);769 const CSnapshot comSnapshot = m_comMachine.FindSnapshot(strSnapshotID); 768 770 769 771 /* Confirm snapshot removal: */ 770 if (!msgCenter().confirmSnapshotRemoval( snapshot.GetName()))772 if (!msgCenter().confirmSnapshotRemoval(comSnapshot.GetName())) 771 773 return; 772 774 773 775 /** @todo check available space on the target filesystem etc etc. */ 774 776 #if 0 775 if (!msgCenter().warnAboutSnapshotRemovalFreeSpace( snapshot.GetName(),777 if (!msgCenter().warnAboutSnapshotRemovalFreeSpace(comSnapshot.GetName(), 776 778 "/home/juser/.VirtualBox/Machines/SampleVM/Snapshots/{01020304-0102-0102-0102-010203040506}.vdi", 777 779 "59 GiB", … … 781 783 782 784 /* Open a session (this call will handle all errors): */ 783 bool busy =mSessionState != KSessionState_Unlocked;784 CSession session;785 if ( busy)786 session = vboxGlobal().openExistingSession(mMachineId);785 bool fBusy = m_enmSessionState != KSessionState_Unlocked; 786 CSession comSession; 787 if (fBusy) 788 comSession = vboxGlobal().openExistingSession(m_strMachineID); 787 789 else 788 session = vboxGlobal().openSession(mMachineId);789 if ( session.isNull())790 comSession = vboxGlobal().openSession(m_strMachineID); 791 if (comSession.isNull()) 790 792 return; 791 793 792 794 /* Remove chosen snapshot: */ 793 CMachine machine = session.GetMachine();794 CProgress progress = machine.DeleteSnapshot(snapId);795 if ( machine.isOk())796 { 797 msgCenter().showModalProgressDialog( progress,mMachine.GetName(), ":/progress_snapshot_discard_90px.png");798 if ( progress.GetResultCode() != 0)799 msgCenter().cannotRemoveSnapshot( progress, snapshot.GetName(),mMachine.GetName());795 CMachine comMachine = comSession.GetMachine(); 796 CProgress comProgress = comMachine.DeleteSnapshot(strSnapshotID); 797 if (comMachine.isOk()) 798 { 799 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_discard_90px.png"); 800 if (comProgress.GetResultCode() != 0) 801 msgCenter().cannotRemoveSnapshot(comProgress, comSnapshot.GetName(), m_comMachine.GetName()); 800 802 } 801 803 else 802 msgCenter().cannotRemoveSnapshot( machine, snapshot.GetName(),mMachine.GetName());804 msgCenter().cannotRemoveSnapshot(comMachine, comSnapshot.GetName(), m_comMachine.GetName()); 803 805 804 806 /* Unlock machine finally: */ 805 session.UnlockMachine();807 comSession.UnlockMachine(); 806 808 } 807 809 … … 809 811 { 810 812 /* Get currently chosen item: */ 811 SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :812 static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());813 AssertReturn (item, (void) 0);813 const SnapshotWgtItem *pSnapshotItem = !m_pTreeWidget->currentItem() ? 0 : 814 static_cast<const SnapshotWgtItem*>(m_pTreeWidget->currentItem()); 815 AssertReturnVoid(pSnapshotItem); 814 816 815 817 /* Get desired snapshot: */ 816 CSnapshot snap = item->snapshot(); 817 AssertReturn (!snap.isNull(), (void) 0); 818 819 CMachine snapMachine = snap.GetMachine(); 818 const CSnapshot comSnapshot = pSnapshotItem->snapshot(); 819 AssertReturnVoid(!comSnapshot.isNull()); 820 821 // WTF? 822 CMachine comMachine = comSnapshot.GetMachine(); 820 823 821 824 /* Show Snapshot Details dialog: */ 822 VBoxSnapshotDetailsDlg dlg(this);823 dlg.getFromSnapshot (snap);824 825 if ( dlg.exec() == QDialog::Accepted)826 dlg.putBackToSnapshot();825 VBoxSnapshotDetailsDlg pDlg(this); 826 pDlg.getFromSnapshot(comSnapshot); 827 828 if (pDlg.exec() == QDialog::Accepted) 829 pDlg.putBackToSnapshot(); 827 830 } 828 831 … … 830 833 { 831 834 /* Get currently chosen item: */ 832 SnapshotWgtItem *item = !mTreeWidget->currentItem() ? 0 :833 static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());834 AssertReturn (item, (void) 0);835 const SnapshotWgtItem *pSnapshotItem = !m_pTreeWidget->currentItem() ? 0 : 836 static_cast<const SnapshotWgtItem*>(m_pTreeWidget->currentItem()); 837 AssertReturnVoid(pSnapshotItem); 835 838 836 839 /* Get desired machine/snapshot: */ 837 CMachine machine;838 CSnapshot snapshot;839 if ( item->isCurrentStateItem())840 machine = item->machine();840 CMachine comMachine; 841 CSnapshot comSnapshot; 842 if (pSnapshotItem->isCurrentStateItem()) 843 comMachine = pSnapshotItem->machine(); 841 844 else 842 845 { 843 snapshot = item->snapshot();844 AssertReturn (!snapshot.isNull(), (void)0);845 machine = snapshot.GetMachine();846 } 847 AssertReturn (!machine.isNull(), (void)0);846 comSnapshot = pSnapshotItem->snapshot(); 847 AssertReturnVoid(!comSnapshot.isNull()); 848 comMachine = comSnapshot.GetMachine(); 849 } 850 AssertReturnVoid(!comMachine.isNull()); 848 851 849 852 /* Show Clone VM wizard: */ 850 UISafePointerWizard pWizard = new UIWizardCloneVM(this, machine, snapshot);853 UISafePointerWizard pWizard = new UIWizardCloneVM(this, comMachine, comSnapshot); 851 854 pWizard->prepare(); 852 855 pWizard->exec(); … … 855 858 } 856 859 857 void UISnapshotPane:: machineDataChanged(QString strId)860 void UISnapshotPane::sltMachineDataChange(QString strMachineID) 858 861 { 859 862 /* Prevent snapshot editing in the meantime: */ 860 SnapshotEditBlocker guardBlock (mEditProtector);863 SnapshotEditBlocker guardBlock(m_fEditProtector); 861 864 862 865 /* Make sure it's our VM: */ 863 if (str Id != mMachineId)866 if (strMachineID != m_strMachineID) 864 867 return; 865 868 866 869 /* Recache state current item: */ 867 cur StateItem()->recache();868 } 869 870 void UISnapshotPane:: machineStateChanged(QString strId, KMachineState state)870 currentStateItem()->recache(); 871 } 872 873 void UISnapshotPane::sltMachineStateChange(QString strMachineID, KMachineState enmState) 871 874 { 872 875 /* Prevent snapshot editing in the meantime: */ 873 SnapshotEditBlocker guardBlock (mEditProtector);876 SnapshotEditBlocker guardBlock(m_fEditProtector); 874 877 875 878 /* Make sure it's our VM: */ 876 if (str Id != mMachineId)879 if (strMachineID != m_strMachineID) 877 880 return; 878 881 879 882 /* Recache new machine state: */ 880 cur StateItem()->recache();881 cur StateItem()->updateCurrentState(state);882 } 883 884 void UISnapshotPane::s essionStateChanged(QString strId, KSessionState state)883 currentStateItem()->recache(); 884 currentStateItem()->updateCurrentState(enmState); 885 } 886 887 void UISnapshotPane::sltSessionStateChange(QString strMachineID, KSessionState enmState) 885 888 { 886 889 /* Prevent snapshot editing in the meantime: */ 887 SnapshotEditBlocker guardBlock (mEditProtector);890 SnapshotEditBlocker guardBlock(m_fEditProtector); 888 891 889 892 /* Make sure it's our VM: */ 890 if (str Id != mMachineId)893 if (strMachineID != m_strMachineID) 891 894 return; 892 895 893 896 /* Recache new session state: */ 894 m SessionState = state;895 onCurrentChanged (mTreeWidget->currentItem());896 } 897 898 void UISnapshotPane:: updateSnapshotsAge()897 m_enmSessionState = enmState; 898 sltCurrentItemChanged(m_pTreeWidget->currentItem()); 899 } 900 901 void UISnapshotPane::sltUpdateSnapshotsAge() 899 902 { 900 903 /* Stop timer if active: */ 901 if (m AgeUpdateTimer.isActive())902 m AgeUpdateTimer.stop();904 if (m_ageUpdateTimer.isActive()) 905 m_ageUpdateTimer.stop(); 903 906 904 907 /* Search for smallest snapshot age to optimize timer timeout: */ 905 SnapshotAgeFormat age = traverseSnapshotAge (mTreeWidget->invisibleRootItem());908 const SnapshotAgeFormat age = traverseSnapshotAge(m_pTreeWidget->invisibleRootItem()); 906 909 switch (age) 907 910 { 908 case AgeInSeconds:909 m AgeUpdateTimer.setInterval(5 * 1000);911 case SnapshotAgeFormat_InSeconds: 912 m_ageUpdateTimer.setInterval(5 * 1000); 910 913 break; 911 case AgeInMinutes:912 m AgeUpdateTimer.setInterval(60 * 1000);914 case SnapshotAgeFormat_InMinutes: 915 m_ageUpdateTimer.setInterval(60 * 1000); 913 916 break; 914 case AgeInHours:915 m AgeUpdateTimer.setInterval(60 * 60 * 1000);917 case SnapshotAgeFormat_InHours: 918 m_ageUpdateTimer.setInterval(60 * 60 * 1000); 916 919 break; 917 case AgeInDays:918 m AgeUpdateTimer.setInterval(24 * 60 * 60 * 1000);920 case SnapshotAgeFormat_InDays: 921 m_ageUpdateTimer.setInterval(24 * 60 * 60 * 1000); 919 922 break; 920 923 default: 921 m AgeUpdateTimer.setInterval(0);924 m_ageUpdateTimer.setInterval(0); 922 925 break; 923 926 } 924 927 925 928 /* Restart timer if necessary: */ 926 if (m AgeUpdateTimer.interval() > 0)927 m AgeUpdateTimer.start();929 if (m_ageUpdateTimer.interval() > 0) 930 m_ageUpdateTimer.start(); 928 931 } 929 932 … … 933 936 bool fIsValid = true; 934 937 935 / * Get currently chosen item: */936 SnapshotWgtItem *pItem = mTreeWidget->currentItem() ? static_cast<SnapshotWgtItem*>(mTreeWidget->currentItem()) : 0;937 AssertReturn(p Item, (bool)0);938 // WTF? 939 const SnapshotWgtItem *pSnapshotItem = m_pTreeWidget->currentItem() ? static_cast<const SnapshotWgtItem*>(m_pTreeWidget->currentItem()) : 0; 940 AssertReturn(pSnapshotItem, (bool)0); 938 941 939 942 /* Open a session (this call will handle all errors): */ 940 CSession session;941 if (m SessionState != KSessionState_Unlocked)942 session = vboxGlobal().openExistingSession(mMachineId);943 CSession comSession; 944 if (m_enmSessionState != KSessionState_Unlocked) 945 comSession = vboxGlobal().openExistingSession(m_strMachineID); 943 946 else 944 session = vboxGlobal().openSession(mMachineId);945 fIsValid = ! session.isNull();947 comSession = vboxGlobal().openSession(m_strMachineID); 948 fIsValid = !comSession.isNull(); 946 949 947 950 if (fIsValid) 948 951 { 949 952 /* Get corresponding machine object also: */ 950 CMachine machine = session.GetMachine();953 CMachine comMachine = comSession.GetMachine(); 951 954 952 955 /* Create take-snapshot dialog: */ 953 956 QWidget *pDlgParent = windowManager().realParentWindow(this); 954 QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(pDlgParent, m Machine);957 QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(pDlgParent, m_comMachine); 955 958 windowManager().registerNewParent(pDlg, pDlgParent); 956 959 957 960 // TODO: Assign corresponding icon through sub-dialog API: */ 958 pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m Machine.GetOSTypeId()));961 pDlg->mLbIcon->setPixmap(vboxGlobal().vmGuestOSTypeIcon(m_comMachine.GetOSTypeId())); 959 962 960 963 /* Search for the max available snapshot index: */ 961 964 int iMaxSnapShotIndex = 0; 962 QString s napShotName = tr("Snapshot %1");963 QRegExp regExp(QString("^") + s napShotName.arg("([0-9]+)") + QString("$"));964 QTreeWidgetItemIterator iterator(m TreeWidget);965 QString strSnapshotName = tr("Snapshot %1"); 966 QRegExp regExp(QString("^") + strSnapshotName.arg("([0-9]+)") + QString("$")); 967 QTreeWidgetItemIterator iterator(m_pTreeWidget); 965 968 while (*iterator) 966 969 { 967 QString s napShot = static_cast<SnapshotWgtItem*>(*iterator)->text(0);968 int pos = regExp.indexIn(snapShot);969 if ( pos != -1)970 QString strSnapshot = static_cast<SnapshotWgtItem*>(*iterator)->text(0); 971 int iPos = regExp.indexIn(strSnapshot); 972 if (iPos != -1) 970 973 iMaxSnapShotIndex = regExp.cap(1).toInt() > iMaxSnapShotIndex ? regExp.cap(1).toInt() : iMaxSnapShotIndex; 971 974 ++iterator; 972 975 } 973 976 // TODO: Assign corresponding snapshot name through sub-dialog API: */ 974 pDlg->mLeName->setText(s napShotName.arg(iMaxSnapShotIndex + 1));977 pDlg->mLeName->setText(strSnapshotName.arg(iMaxSnapShotIndex + 1)); 975 978 976 979 /* Show Take Snapshot dialog: */ … … 981 984 { 982 985 /* Acquire snapshot name/description: */ 983 QString strSnapshotName = pDlg->mLeName->text().trimmed();984 QString strSnapshotDescription = pDlg->mTeDescription->toPlainText();986 const QString strSnapshotName = pDlg->mLeName->text().trimmed(); 987 const QString strSnapshotDescription = pDlg->mTeDescription->toPlainText(); 985 988 986 989 /* Destroy dialog early: */ … … 991 994 { 992 995 /* Take snapshot: */ 993 QString strSnapshotI d;994 CProgress progress = machine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotId);995 if ( machine.isOk())996 QString strSnapshotID; 997 CProgress comProgress = comMachine.TakeSnapshot(strSnapshotName, strSnapshotDescription, true, strSnapshotID); 998 if (comMachine.isOk()) 996 999 { 997 msgCenter().showModalProgressDialog( progress,mMachine.GetName(), ":/progress_snapshot_create_90px.png");998 if (! progress.isOk() || progress.GetResultCode() != 0)1000 msgCenter().showModalProgressDialog(comProgress, m_comMachine.GetName(), ":/progress_snapshot_create_90px.png"); 1001 if (!comProgress.isOk() || comProgress.GetResultCode() != 0) 999 1002 { 1000 msgCenter().cannotTakeSnapshot( progress,mMachine.GetName());1003 msgCenter().cannotTakeSnapshot(comProgress, m_comMachine.GetName()); 1001 1004 fIsValid = false; 1002 1005 } … … 1004 1007 else 1005 1008 { 1006 msgCenter().cannotTakeSnapshot( machine,mMachine.GetName());1009 msgCenter().cannotTakeSnapshot(comMachine, m_comMachine.GetName()); 1007 1010 fIsValid = false; 1008 1011 } … … 1015 1018 1016 1019 /* Unlock machine finally: */ 1017 session.UnlockMachine();1020 comSession.UnlockMachine(); 1018 1021 } 1019 1022 … … 1025 1028 { 1026 1029 /* Prevent snapshot editing in the meantime: */ 1027 SnapshotEditBlocker guardBlock (mEditProtector);1030 SnapshotEditBlocker guardBlock(m_fEditProtector); 1028 1031 1029 1032 /* If VM is null, just updated the current itm: */ 1030 if (m Machine.isNull())1031 { 1032 onCurrentChanged();1033 if (m_comMachine.isNull()) 1034 { 1035 sltCurrentItemChanged(); 1033 1036 return; 1034 1037 } 1035 1038 1036 1039 /* Remember the selected item and it's first child: */ 1037 QString s electedItem, firstChildOfSelectedItem;1038 SnapshotWgtItem *cur = !mTreeWidget->currentItem() ? 0 :1039 static_cast <SnapshotWgtItem*> (mTreeWidget->currentItem());1040 if ( cur)1041 { 1042 s electedItem = cur->snapshotId();1043 if ( cur->child(0))1044 firstChildOfSelectedItem = static_cast <SnapshotWgtItem*> (cur->child (0))->snapshotId();1040 QString strSelectedItem, strFirstChildOfSelectedItem; 1041 const SnapshotWgtItem *pSnapshotItem = !m_pTreeWidget->currentItem() ? 0 : 1042 static_cast<const SnapshotWgtItem*>(m_pTreeWidget->currentItem()); 1043 if (pSnapshotItem) 1044 { 1045 strSelectedItem = pSnapshotItem->snapshotID(); 1046 if (pSnapshotItem->child(0)) 1047 strFirstChildOfSelectedItem = static_cast<const SnapshotWgtItem*>(pSnapshotItem->child(0))->snapshotID(); 1045 1048 } 1046 1049 1047 1050 /* Clear the tree: */ 1048 m TreeWidget->clear();1051 m_pTreeWidget->clear(); 1049 1052 1050 1053 /* If machine has snapshots: */ 1051 if (m Machine.GetSnapshotCount() > 0)1054 if (m_comMachine.GetSnapshotCount() > 0) 1052 1055 { 1053 1056 /* Get the first snapshot: */ 1054 CSnapshot snapshot = mMachine.FindSnapshot(QString::null);1057 const CSnapshot comSnapshot = m_comMachine.FindSnapshot(QString()); 1055 1058 1056 1059 /* Populate snapshot tree: */ 1057 populateSnapshots (snapshot, 0);1060 populateSnapshots(comSnapshot, 0); 1058 1061 /* And make sure it has current snapshot item: */ 1059 Assert (mCurSnapshotItem);1062 Assert(m_pCurrentSnapshotItem); 1060 1063 1061 1064 /* Add the "current state" item as a child to current snapshot item: */ 1062 SnapshotWgtItem * csi = new SnapshotWgtItem(this, mCurSnapshotItem,mMachine);1063 csi->setBold(true);1064 csi->recache();1065 SnapshotWgtItem *pCsi = new SnapshotWgtItem(this, m_pCurrentSnapshotItem, m_comMachine); 1066 pCsi->setBold(true); 1067 pCsi->recache(); 1065 1068 1066 1069 /* Search for a previously selected item: */ 1067 SnapshotWgtItem * cur = findItem (selectedItem);1068 if ( cur== 0)1069 cur = findItem (firstChildOfSelectedItem);1070 if ( cur== 0)1071 cur = curStateItem();1070 SnapshotWgtItem *pCurrentItem = findItem(strSelectedItem); 1071 if (pCurrentItem == 0) 1072 pCurrentItem = findItem(strFirstChildOfSelectedItem); 1073 if (pCurrentItem == 0) 1074 pCurrentItem = currentStateItem(); 1072 1075 1073 1076 /* Choose current item: */ 1074 m TreeWidget->scrollToItem (cur);1075 m TreeWidget->setCurrentItem (cur);1076 onCurrentChanged (cur);1077 m_pTreeWidget->scrollToItem(pCurrentItem); 1078 m_pTreeWidget->setCurrentItem(pCurrentItem); 1079 sltCurrentItemChanged(pCurrentItem); 1077 1080 } 1078 1081 /* If machine has no snapshots: */ … … 1080 1083 { 1081 1084 /* There is no current snapshot item: */ 1082 m CurSnapshotItem = 0;1085 m_pCurrentSnapshotItem = 0; 1083 1086 1084 1087 /* Add the "current state" item as a child of tree-widget: */ 1085 SnapshotWgtItem * csi = new SnapshotWgtItem(this, mTreeWidget,mMachine);1086 csi->setBold(true);1087 csi->recache();1088 SnapshotWgtItem *pCsi = new SnapshotWgtItem(this, m_pTreeWidget, m_comMachine); 1089 pCsi->setBold(true); 1090 pCsi->recache(); 1088 1091 1089 1092 /* Choose current item: */ 1090 m TreeWidget->setCurrentItem (csi);1091 onCurrentChanged (csi);1093 m_pTreeWidget->setCurrentItem(pCsi); 1094 sltCurrentItemChanged(pCsi); 1092 1095 } 1093 1096 1094 1097 /* Update age: */ 1095 updateSnapshotsAge();1098 sltUpdateSnapshotsAge(); 1096 1099 1097 1100 /* Adjust tree-widget: */ 1098 m TreeWidget->resizeColumnToContents(0);1099 } 1100 1101 SnapshotWgtItem * UISnapshotPane::findItem (const QString &aSnapshotId)1101 m_pTreeWidget->resizeColumnToContents(0); 1102 } 1103 1104 SnapshotWgtItem *UISnapshotPane::findItem(const QString &strSnapshotID) const 1102 1105 { 1103 1106 /* Search for the first item with required ID: */ 1104 QTreeWidgetItemIterator it (mTreeWidget);1107 QTreeWidgetItemIterator it(m_pTreeWidget); 1105 1108 while (*it) 1106 1109 { 1107 SnapshotWgtItem * lvi = static_cast <SnapshotWgtItem*>(*it);1108 if ( lvi->snapshotId() == aSnapshotId)1109 return lvi;1110 ++ 1110 SnapshotWgtItem *pSnapshotItem = static_cast<SnapshotWgtItem*>(*it); 1111 if (pSnapshotItem->snapshotID() == strSnapshotID) 1112 return pSnapshotItem; 1113 ++it; 1111 1114 } 1112 1115 … … 1115 1118 } 1116 1119 1117 SnapshotWgtItem *UISnapshotPane::cur StateItem()1120 SnapshotWgtItem *UISnapshotPane::currentStateItem() const 1118 1121 { 1119 1122 /* Last child of the current snapshot item if any or first child of invisible root item otherwise: */ 1120 QTreeWidgetItem * csi = mCurSnapshotItem ?1121 mCurSnapshotItem->child (mCurSnapshotItem->childCount() - 1) :1122 mTreeWidget->invisibleRootItem()->child(0);1123 return static_cast <SnapshotWgtItem*> (csi);1124 } 1125 1126 void UISnapshotPane::populateSnapshots (const CSnapshot &aSnapshot, QTreeWidgetItem *aItem)1123 QTreeWidgetItem *pCsi = m_pCurrentSnapshotItem ? 1124 m_pCurrentSnapshotItem->child(m_pCurrentSnapshotItem->childCount() - 1) : 1125 m_pTreeWidget->invisibleRootItem()->child(0); 1126 return static_cast<SnapshotWgtItem*>(pCsi); 1127 } 1128 1129 void UISnapshotPane::populateSnapshots(const CSnapshot &comSnapshot, QTreeWidgetItem *pItem) 1127 1130 { 1128 1131 /* Create a child of passed item: */ 1129 SnapshotWgtItem * item = aItem ? new SnapshotWgtItem(this, aItem, aSnapshot) :1130 new SnapshotWgtItem(this, mTreeWidget, aSnapshot);1132 SnapshotWgtItem *pSnapshotItem = pItem ? new SnapshotWgtItem(this, pItem, comSnapshot) : 1133 new SnapshotWgtItem(this, m_pTreeWidget, comSnapshot); 1131 1134 /* And recache it's content: */ 1132 item->recache();1135 pSnapshotItem->recache(); 1133 1136 1134 1137 /* Mark current snapshot item bold and remember it: */ 1135 CSnapshot c urSnapshot =mMachine.GetCurrentSnapshot();1136 if (!c urSnapshot.isNull() && curSnapshot.GetId() == aSnapshot.GetId())1137 { 1138 item->setBold(true);1139 m CurSnapshotItem = item;1138 CSnapshot comCurrentSnapshot = m_comMachine.GetCurrentSnapshot(); 1139 if (!comCurrentSnapshot.isNull() && comCurrentSnapshot.GetId() == comSnapshot.GetId()) 1140 { 1141 pSnapshotItem->setBold(true); 1142 m_pCurrentSnapshotItem = pSnapshotItem; 1140 1143 } 1141 1144 1142 1145 /* Walk through the children recursively: */ 1143 CSnapshotVector snapshots = aSnapshot.GetChildren();1144 foreach (const CSnapshot & snapshot, snapshots)1145 populateSnapshots (snapshot, item);1146 const CSnapshotVector snapshots = comSnapshot.GetChildren(); 1147 foreach (const CSnapshot &comIteratedSnapshot, snapshots) 1148 populateSnapshots(comIteratedSnapshot, pSnapshotItem); 1146 1149 1147 1150 /* Expand the newly created item: */ 1148 item->setExpanded(true);1151 pSnapshotItem->setExpanded(true); 1149 1152 /* And mark it as editable: */ 1150 item->setFlags (item->flags() | Qt::ItemIsEditable);1151 } 1152 1153 SnapshotAgeFormat UISnapshotPane::traverseSnapshotAge (QTreeWidgetItem *aParentItem)1153 pSnapshotItem->setFlags(pSnapshotItem->flags() | Qt::ItemIsEditable); 1154 } 1155 1156 SnapshotAgeFormat UISnapshotPane::traverseSnapshotAge(QTreeWidgetItem *pItem) const 1154 1157 { 1155 1158 /* Make sure passed root is of valid type: */ 1156 SnapshotWgtItem *p arentItem = aParentItem->type() == SnapshotWgtItem::ItemType ?1157 static_cast <SnapshotWgtItem*> (aParentItem) : 0;1159 SnapshotWgtItem *pSnapshotItem = pItem->type() == SnapshotWgtItem::ItemType ? 1160 static_cast<SnapshotWgtItem*>(pItem) : 0; 1158 1161 1159 1162 /* Fetch the snapshot age of the root if it's valid: */ 1160 SnapshotAgeFormat age = p arentItem ? parentItem->updateAge() : AgeMax;1163 SnapshotAgeFormat age = pSnapshotItem ? pSnapshotItem->updateAge() : SnapshotAgeFormat_Max; 1161 1164 1162 1165 /* Walk through the children recursively: */ 1163 for (int i = 0; i < aParentItem->childCount(); ++i)1166 for (int i = 0; i < pItem->childCount(); ++i) 1164 1167 { 1165 1168 /* Fetch the smallest snapshot age of the children: */ 1166 SnapshotAgeFormat newAge = traverseSnapshotAge (aParentItem->child(i));1169 const SnapshotAgeFormat newAge = traverseSnapshotAge(pItem->child(i)); 1167 1170 /* Remember the smallest snapshot age among existing: */ 1168 1171 age = newAge < age ? newAge : age; -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.h
r63818 r63821 38 38 enum SnapshotAgeFormat 39 39 { 40 AgeInSeconds,41 AgeInMinutes,42 AgeInHours,43 AgeInDays,44 AgeMax40 SnapshotAgeFormat_InSeconds, 41 SnapshotAgeFormat_InMinutes, 42 SnapshotAgeFormat_InHours, 43 SnapshotAgeFormat_InDays, 44 SnapshotAgeFormat_Max 45 45 }; 46 46 … … 53 53 public: 54 54 55 /** Constructs snapshot pane passing @a aParent to the base-class. */56 UISnapshotPane(QWidget * aParent);55 /** Constructs snapshot pane passing @a pParent to the base-class. */ 56 UISnapshotPane(QWidget *pParent); 57 57 58 /** Defines the @a aMachine to be parsed. */59 void setMachine (const CMachine &aMachine);58 /** Defines the @a comMachine to be parsed. */ 59 void setMachine(const CMachine &comMachine); 60 60 61 61 /** Returns cached snapshot-item icon depending on @a fOnline flag. */ 62 const QIcon & snapshotItemIcon(bool fOnline) { return !fOnline ? m_offlineSnapshotIcon : m_onlineSnapshotIcon; }62 const QIcon &snapshotItemIcon(bool fOnline) const { return !fOnline ? m_snapshotIconOffline : m_snapshotIconOnline; } 63 63 64 64 protected: 65 65 66 66 /** Handles translation event. */ 67 v oid retranslateUi();67 virtual void retranslateUi() /* override */; 68 68 69 69 private slots: … … 71 71 /** @name Tree-view handlers 72 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);73 /** Handles cursor change to @a pItem. */ 74 void sltCurrentItemChanged(QTreeWidgetItem *pItem = 0); 75 /** Handles context menu request for @a point. */ 76 void sltContextMenuRequested(const QPoint &point); 77 /** Handles modification for @a pItem. */ 78 void sltItemChanged(QTreeWidgetItem *pItem); 79 79 /** Handles double-click for @a pItem. */ 80 80 void sltItemDoubleClicked(QTreeWidgetItem *pItem); … … 97 97 /** @name Main event handlers 98 98 * @{ */ 99 /** Handles machine data change for machine with @a str Id. */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 s essionStateChanged(QString strId, KSessionState state);99 /** Handles machine data change for machine with @a strMachineID. */ 100 void sltMachineDataChange(QString strMachineID); 101 /** Handles machine @a enmState change for machine with @a strMachineID. */ 102 void sltMachineStateChange(QString strMachineID, KMachineState enmState); 103 /** Handles session @a enmState change for machine with @a strMachineID. */ 104 void sltSessionStateChange(QString strMachineID, KSessionState enmState); 105 105 /** @} */ 106 106 … … 108 108 * @{ */ 109 109 /** Updates snapshots age. */ 110 void updateSnapshotsAge();110 void sltUpdateSnapshotsAge(); 111 111 /** @} */ 112 112 … … 130 130 void refreshAll(); 131 131 132 /** Searches for an item with corresponding @a aSnapshotId. */133 SnapshotWgtItem * findItem (const QString &aSnapshotId);132 /** Searches for an item with corresponding @a strSnapshotID. */ 133 SnapshotWgtItem *findItem(const QString &strSnapshotID) const; 134 134 /** Returns the "current state" item. */ 135 SnapshotWgtItem * curStateItem();135 SnapshotWgtItem *currentStateItem() const; 136 136 137 /** Populates snapshot items for corresponding @a aSnapshot using @a aItem as parent. */138 void populateSnapshots (const CSnapshot &aSnapshot, QTreeWidgetItem *aItem);137 /** Populates snapshot items for corresponding @a comSnapshot using @a pItem as parent. */ 138 void populateSnapshots(const CSnapshot &comSnapshot, QTreeWidgetItem *pItem); 139 139 140 /** Searches for smallest snapshot age starting with @a aParentItem as parent. */141 SnapshotAgeFormat traverseSnapshotAge (QTreeWidgetItem *aParentItem);140 /** Searches for smallest snapshot age starting with @a pItem as parent. */ 141 SnapshotAgeFormat traverseSnapshotAge(QTreeWidgetItem *pItem) const; 142 142 143 143 /** Holds the machine COM wrapper. */ 144 CMachine m Machine;144 CMachine m_comMachine; 145 145 /** Holds the machine ID. */ 146 QString m MachineId;146 QString m_strMachineID; 147 147 /** Holds the cached session state. */ 148 KSessionState m SessionState;148 KSessionState m_enmSessionState; 149 149 /** Holds the current snapshot item reference. */ 150 SnapshotWgtItem *m CurSnapshotItem;150 SnapshotWgtItem *m_pCurrentSnapshotItem; 151 151 /** Holds the snapshot item editing protector. */ 152 bool m EditProtector;152 bool m_fEditProtector; 153 153 154 154 /** Holds the snapshot item action group instance. */ 155 QActionGroup *m SnapshotActionGroup;155 QActionGroup *m_pSnapshotItemActionGroup; 156 156 /** Holds the current item action group instance. */ 157 QActionGroup *m CurStateActionGroup;157 QActionGroup *m_pCurrentStateItemActionGroup; 158 158 159 159 /** Holds the snapshot restore action instance. */ 160 QAction *m RestoreSnapshotAction;160 QAction *m_pActionRestoreSnapshot; 161 161 /** Holds the snapshot delete action instance. */ 162 QAction *m DeleteSnapshotAction;162 QAction *m_pActionDeleteSnapshot; 163 163 /** Holds the show snapshot details action instance. */ 164 QAction *m ShowSnapshotDetailsAction;164 QAction *m_pActionShowSnapshotDetails; 165 165 /** Holds the snapshot take action instance. */ 166 QAction *m TakeSnapshotAction;166 QAction *m_pActionTakeSnapshot; 167 167 /** Holds the snapshot clone action instance. */ 168 QAction *m CloneSnapshotAction;168 QAction *m_pActionCloneSnapshot; 169 169 170 170 /** Holds the snapshot age update timer. */ 171 QTimer m AgeUpdateTimer;171 QTimer m_ageUpdateTimer; 172 172 173 173 /** Holds whether the snapshot operations are allowed. */ … … 175 175 176 176 /** Holds the cached snapshot-item pixmap for 'offline' state. */ 177 QIcon m_ offlineSnapshotIcon;177 QIcon m_snapshotIconOffline; 178 178 /** Holds the cached snapshot-item pixmap for 'online' state. */ 179 QIcon m_ onlineSnapshotIcon;179 QIcon m_snapshotIconOnline; 180 180 }; 181 181 -
trunk/src/VBox/Frontends/VirtualBox/src/selector/UISnapshotPane.ui
r63804 r63821 40 40 </property> 41 41 <item> 42 <widget class="QTreeWidget" name="m TreeWidget" >42 <widget class="QTreeWidget" name="m_pTreeWidget" > 43 43 <property name="contextMenuPolicy" > 44 44 <enum>Qt::CustomContextMenu</enum>
Note:
See TracChangeset
for help on using the changeset viewer.