1 | /**
|
---|
2 | *
|
---|
3 | * VBox frontends: Qt GUI ("VirtualBox"):
|
---|
4 | * Snapshot details dialog (Qt Designer)
|
---|
5 | */
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
13 | * General Public License (GPL) as published by the Free Software
|
---|
14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
17 | *
|
---|
18 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
19 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
20 | * additional information or have any questions.
|
---|
21 | */
|
---|
22 |
|
---|
23 | /****************************************************************************
|
---|
24 | ** ui.h extension file, included from the uic-generated form implementation.
|
---|
25 | **
|
---|
26 | ** If you want to add, delete, or rename functions or slots, use
|
---|
27 | ** Qt Designer to update this file, preserving your code.
|
---|
28 | **
|
---|
29 | ** You should not define a constructor or destructor in this file.
|
---|
30 | ** Instead, write your code in functions called init() and destroy().
|
---|
31 | ** These will automatically be called by the form's constructor and
|
---|
32 | ** destructor.
|
---|
33 | *****************************************************************************/
|
---|
34 |
|
---|
35 | /** QListViewItem subclass for snapshots */
|
---|
36 | class VBoxSnapshotsWgt::ListViewItem : public QListViewItem
|
---|
37 | {
|
---|
38 | public:
|
---|
39 |
|
---|
40 | /** Normal snapshot item */
|
---|
41 | ListViewItem (QListView *lv, const CSnapshot &aSnapshot)
|
---|
42 | : QListViewItem (lv)
|
---|
43 | , mBld (false), mItal (false)
|
---|
44 | , mSnapshot (aSnapshot)
|
---|
45 | {
|
---|
46 | recache();
|
---|
47 | }
|
---|
48 |
|
---|
49 | /** Normal snapshot item */
|
---|
50 | ListViewItem (QListViewItem *lvi, const CSnapshot &aSnapshot)
|
---|
51 | : QListViewItem (lvi)
|
---|
52 | , mBld (false), mItal (false)
|
---|
53 | , mSnapshot (aSnapshot)
|
---|
54 | {
|
---|
55 | recache();
|
---|
56 | }
|
---|
57 |
|
---|
58 | /** Current state item */
|
---|
59 | ListViewItem (QListView *lv, const CMachine &aMachine)
|
---|
60 | : QListViewItem (lv)
|
---|
61 | , mBld (false), mItal (true)
|
---|
62 | , mMachine (aMachine)
|
---|
63 | {
|
---|
64 | recache();
|
---|
65 | updateCurrentState (mMachine.GetState());
|
---|
66 | }
|
---|
67 |
|
---|
68 | /** Current state item */
|
---|
69 | ListViewItem (QListViewItem *lvi, const CMachine &aMachine)
|
---|
70 | : QListViewItem (lvi)
|
---|
71 | , mBld (false), mItal (true)
|
---|
72 | , mMachine (aMachine)
|
---|
73 | {
|
---|
74 | recache();
|
---|
75 | updateCurrentState (mMachine.GetState());
|
---|
76 | }
|
---|
77 |
|
---|
78 | bool bold() const { return mBld; }
|
---|
79 | void setBold (bool bold)
|
---|
80 | {
|
---|
81 | mBld = bold;
|
---|
82 | repaint();
|
---|
83 | }
|
---|
84 |
|
---|
85 | bool italic() const { return mItal; }
|
---|
86 | void setItalic (bool italic)
|
---|
87 | {
|
---|
88 | mItal = italic;
|
---|
89 | repaint();
|
---|
90 | }
|
---|
91 |
|
---|
92 | void paintCell (QPainter *p, const QColorGroup &cg, int column, int width, int align)
|
---|
93 | {
|
---|
94 | QFont font = p->font();
|
---|
95 | if (font.bold() != mBld)
|
---|
96 | font.setBold (mBld);
|
---|
97 | if (font.italic() != mItal)
|
---|
98 | font.setItalic (mItal);
|
---|
99 | if (font != p->font())
|
---|
100 | p->setFont (font);
|
---|
101 | QListViewItem::paintCell (p, cg, column, width, align);
|
---|
102 | }
|
---|
103 |
|
---|
104 | int width (const QFontMetrics &fm, const QListView *lv, int c) const
|
---|
105 | {
|
---|
106 | QFont font = lv->font();
|
---|
107 | if (font.bold() != mBld)
|
---|
108 | font.setBold (mBld);
|
---|
109 | if (font.italic() != mItal)
|
---|
110 | font.setItalic (mItal);
|
---|
111 | if (font != lv->font())
|
---|
112 | return QListViewItem::width (QFontMetrics (font), lv, c);
|
---|
113 | return QListViewItem::width (fm, lv, c);
|
---|
114 | }
|
---|
115 |
|
---|
116 | CSnapshot snapshot() const { return mSnapshot; }
|
---|
117 | QUuid snapshotId() const { return mId; }
|
---|
118 |
|
---|
119 | KMachineState machineState() const { return mMachineState; }
|
---|
120 |
|
---|
121 | void recache()
|
---|
122 | {
|
---|
123 | if (!mSnapshot.isNull())
|
---|
124 | {
|
---|
125 | mId = mSnapshot.GetId();
|
---|
126 | setText (0, mSnapshot.GetName());
|
---|
127 | mOnline = mSnapshot.GetOnline();
|
---|
128 | setPixmap (0, vboxGlobal().snapshotIcon (mOnline));
|
---|
129 | mDesc = mSnapshot.GetDescription();
|
---|
130 | mTimestamp.setTime_t (mSnapshot.GetTimeStamp() / 1000);
|
---|
131 | mCurStateModified = false;
|
---|
132 | }
|
---|
133 | else
|
---|
134 | {
|
---|
135 | Assert (!mMachine.isNull());
|
---|
136 | mCurStateModified = mMachine.GetCurrentStateModified();
|
---|
137 | setText (0, mCurStateModified ?
|
---|
138 | VBoxSnapshotsWgt::tr ("Current State (changed)",
|
---|
139 | "Current State (Modified)") :
|
---|
140 | VBoxSnapshotsWgt::tr ("Current State",
|
---|
141 | "Current State (Unmodified)"));
|
---|
142 | mDesc = mCurStateModified ?
|
---|
143 | VBoxSnapshotsWgt::tr ("The current state differs from the state "
|
---|
144 | "stored in the current snapshot") :
|
---|
145 | parent() != 0 ? /* we're not the only item in the view */
|
---|
146 | VBoxSnapshotsWgt::tr ("The current state is identical to the state "
|
---|
147 | "stored in the current snapshot") :
|
---|
148 | QString::null;
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 | void updateCurrentState (KMachineState aState)
|
---|
153 | {
|
---|
154 | AssertReturn (!mMachine.isNull(), (void) 0);
|
---|
155 | setPixmap (0, vboxGlobal().toIcon (aState));
|
---|
156 | mMachineState = aState;
|
---|
157 | mTimestamp.setTime_t (mMachine.GetLastStateChange() / 1000);
|
---|
158 | }
|
---|
159 |
|
---|
160 | QString toolTipText() const
|
---|
161 | {
|
---|
162 | QString name = !mSnapshot.isNull() ?
|
---|
163 | text (0) : text (0);
|
---|
164 |
|
---|
165 | bool dateTimeToday = mTimestamp.date() == QDate::currentDate();
|
---|
166 | QString dateTime = dateTimeToday ?
|
---|
167 | mTimestamp.time().toString (Qt::LocalDate) :
|
---|
168 | mTimestamp.toString (Qt::LocalDate);
|
---|
169 |
|
---|
170 | QString details;
|
---|
171 | if (!mSnapshot.isNull())
|
---|
172 | {
|
---|
173 | /* the current snapshot is always bold */
|
---|
174 | if (mBld)
|
---|
175 | details = VBoxSnapshotsWgt::tr (" (current, ", "Snapshot details");
|
---|
176 | else
|
---|
177 | details = " (";
|
---|
178 | details += mOnline ? VBoxSnapshotsWgt::tr ("online)", "Snapshot details")
|
---|
179 | : VBoxSnapshotsWgt::tr ("offline)", "Snapshot details");
|
---|
180 |
|
---|
181 | if (dateTimeToday)
|
---|
182 | dateTime = VBoxSnapshotsWgt::tr ("Taken at %1", "Snapshot (time)")
|
---|
183 | .arg (dateTime);
|
---|
184 | else
|
---|
185 | dateTime = VBoxSnapshotsWgt::tr ("Taken on %1", "Snapshot (date + time)")
|
---|
186 | .arg (dateTime);
|
---|
187 | }
|
---|
188 | else
|
---|
189 | {
|
---|
190 | dateTime = VBoxSnapshotsWgt::tr ("%1 since %2", "Current State (time or date + time)")
|
---|
191 | .arg (vboxGlobal().toString (mMachineState))
|
---|
192 | .arg (dateTime);
|
---|
193 | }
|
---|
194 |
|
---|
195 | QString toolTip = QString ("<nobr><b>%1</b>%2</nobr><br><nobr>%3</nobr>")
|
---|
196 | .arg (name) .arg (details)
|
---|
197 | .arg (dateTime);
|
---|
198 |
|
---|
199 | if (!mDesc.isEmpty())
|
---|
200 | toolTip += "<br><hr>" + mDesc;
|
---|
201 |
|
---|
202 | return toolTip;
|
---|
203 | }
|
---|
204 |
|
---|
205 | void okRename (int aCol)
|
---|
206 | {
|
---|
207 | QListViewItem::okRename (aCol);
|
---|
208 | AssertReturn (aCol == 0 && !mSnapshot.isNull(), (void) 0);
|
---|
209 | mSnapshot.SetName (text (0));
|
---|
210 | }
|
---|
211 |
|
---|
212 | private:
|
---|
213 |
|
---|
214 | bool mBld : 1;
|
---|
215 | bool mItal : 1;
|
---|
216 |
|
---|
217 | CSnapshot mSnapshot;
|
---|
218 | CMachine mMachine;
|
---|
219 |
|
---|
220 | QUuid mId;
|
---|
221 | bool mOnline;
|
---|
222 | QString mDesc;
|
---|
223 | QDateTime mTimestamp;
|
---|
224 |
|
---|
225 | bool mCurStateModified;
|
---|
226 | KMachineState mMachineState;
|
---|
227 | };
|
---|
228 |
|
---|
229 | ////////////////////////////////////////////////////////////////////////////////
|
---|
230 |
|
---|
231 | /** Tooltips for snapshots */
|
---|
232 | class VBoxSnapshotsWgt::ToolTip : public QToolTip
|
---|
233 | {
|
---|
234 | public:
|
---|
235 |
|
---|
236 | ToolTip (QListView *aLV, QWidget *aParent, QToolTipGroup *aTG = 0)
|
---|
237 | : QToolTip (aParent, aTG), mLV (aLV)
|
---|
238 | {}
|
---|
239 |
|
---|
240 | virtual ~ToolTip()
|
---|
241 | {
|
---|
242 | remove (parentWidget());
|
---|
243 | }
|
---|
244 |
|
---|
245 | void maybeTip (const QPoint &aPnt);
|
---|
246 |
|
---|
247 | private:
|
---|
248 |
|
---|
249 | QListView *mLV;
|
---|
250 | };
|
---|
251 |
|
---|
252 | void VBoxSnapshotsWgt::ToolTip::maybeTip (const QPoint &aPnt)
|
---|
253 | {
|
---|
254 | ListViewItem *lvi = static_cast <ListViewItem *> (mLV->itemAt (aPnt));
|
---|
255 | if (!lvi)
|
---|
256 | return;
|
---|
257 |
|
---|
258 | if (parentWidget()->topLevelWidget()->inherits ("QMainWindow"))
|
---|
259 | {
|
---|
260 | /*
|
---|
261 | * Ensure the main window doesn't show the text from the previous
|
---|
262 | * tooltip in the status bar.
|
---|
263 | */
|
---|
264 | QToolTipGroup *toolTipGroup =
|
---|
265 | (::qt_cast <QMainWindow *> (parentWidget()->topLevelWidget()))->
|
---|
266 | toolTipGroup();
|
---|
267 | if (toolTipGroup)
|
---|
268 | {
|
---|
269 | int index = toolTipGroup->metaObject()->findSignal("removeTip()", false);
|
---|
270 | toolTipGroup->qt_emit (index, 0);
|
---|
271 | }
|
---|
272 | }
|
---|
273 |
|
---|
274 | tip (mLV->itemRect (lvi), lvi->toolTipText());
|
---|
275 | }
|
---|
276 |
|
---|
277 | ////////////////////////////////////////////////////////////////////////////////
|
---|
278 |
|
---|
279 | void VBoxSnapshotsWgt::init()
|
---|
280 | {
|
---|
281 | mCurSnapshotItem = 0;
|
---|
282 |
|
---|
283 | listView->setItemMargin (2);
|
---|
284 | listView->header()->hide();
|
---|
285 | listView->setRootIsDecorated (true);
|
---|
286 | /* we have our own tooltips */
|
---|
287 | listView->setShowToolTips (false);
|
---|
288 | /* disable sorting */
|
---|
289 | listView->setSorting (-1);
|
---|
290 | /* disable unselecting items by clicking in the unused area of the list */
|
---|
291 | new QIListViewSelectionPreserver (this, listView);
|
---|
292 |
|
---|
293 | /* toolbar */
|
---|
294 | VBoxToolBar *toolBar = new VBoxToolBar (0, this, "snapshotToolBar");
|
---|
295 |
|
---|
296 | curStateActionGroup->addTo (toolBar);
|
---|
297 | toolBar->addSeparator();
|
---|
298 | snapshotActionGroup->addTo (toolBar);
|
---|
299 | toolBar->addSeparator();
|
---|
300 | showSnapshotDetailsAction->addTo (toolBar);
|
---|
301 |
|
---|
302 | toolBar->setUsesTextLabel (false);
|
---|
303 | toolBar->setUsesBigPixmaps (true);
|
---|
304 | toolBar->setSizePolicy (QSizePolicy::Fixed, QSizePolicy::Fixed);
|
---|
305 | VBoxSnapshotsWgtLayout->insertWidget (0, toolBar);
|
---|
306 | #ifdef Q_WS_MAC
|
---|
307 | toolBar->setMacStyle();
|
---|
308 | #endif
|
---|
309 |
|
---|
310 | /* context menu */
|
---|
311 | mContextMenu = new QPopupMenu (this);
|
---|
312 | mContextMenuDirty = true;
|
---|
313 |
|
---|
314 | /* icons */
|
---|
315 | discardSnapshotAction->setIconSet (VBoxGlobal::iconSetEx (
|
---|
316 | "discard_snapshot_22px.png", "discard_snapshot_16px.png",
|
---|
317 | "discard_snapshot_dis_22px.png", "discard_snapshot_dis_16px.png"));
|
---|
318 | takeSnapshotAction->setIconSet (VBoxGlobal::iconSetEx (
|
---|
319 | "take_snapshot_22px.png", "take_snapshot_16px.png",
|
---|
320 | "take_snapshot_dis_22px.png", "take_snapshot_dis_16px.png"));
|
---|
321 | revertToCurSnapAction->setIconSet (VBoxGlobal::iconSetEx (
|
---|
322 | "discard_cur_state_22px.png", "discard_cur_state_16px.png",
|
---|
323 | "discard_cur_state_dis_22px.png", "discard_cur_state_dis_16px.png"));
|
---|
324 | discardCurSnapAndStateAction->setIconSet (VBoxGlobal::iconSetEx (
|
---|
325 | "discard_cur_state_snapshot_22px.png", "discard_cur_state_snapshot_16px.png",
|
---|
326 | "discard_cur_state_snapshot_dis_22px.png", "discard_cur_state_snapshot_dis_16px.png"));
|
---|
327 | showSnapshotDetailsAction->setIconSet (VBoxGlobal::iconSetEx (
|
---|
328 | "show_snapshot_details_22px.png", "show_snapshot_details_16px.png",
|
---|
329 | "show_snapshot_details_dis_22px.png", "show_snapshot_details_dis_16px.png"));
|
---|
330 |
|
---|
331 | /* tooltip */
|
---|
332 | mToolTip = new ToolTip (listView, listView->viewport());
|
---|
333 | }
|
---|
334 |
|
---|
335 | void VBoxSnapshotsWgt::destroy()
|
---|
336 | {
|
---|
337 | delete mToolTip;
|
---|
338 | }
|
---|
339 |
|
---|
340 | void VBoxSnapshotsWgt::setMachine (const CMachine &aMachine)
|
---|
341 | {
|
---|
342 | mMachine = aMachine;
|
---|
343 |
|
---|
344 | if (aMachine.isNull())
|
---|
345 | {
|
---|
346 | mMachineId = QUuid();
|
---|
347 | mSessionState = KSessionState_Null;
|
---|
348 | }
|
---|
349 | else
|
---|
350 | {
|
---|
351 | mMachineId = aMachine.GetId();
|
---|
352 | mSessionState = aMachine.GetSessionState();
|
---|
353 | }
|
---|
354 |
|
---|
355 | refreshAll();
|
---|
356 | }
|
---|
357 |
|
---|
358 | VBoxSnapshotsWgt::ListViewItem *VBoxSnapshotsWgt::findItem (const QUuid &aSnapshotId)
|
---|
359 | {
|
---|
360 | QListViewItemIterator it (listView);
|
---|
361 | while (it.current())
|
---|
362 | {
|
---|
363 | ListViewItem *lvi = static_cast <ListViewItem *> (it.current());
|
---|
364 | if (lvi->snapshotId() == aSnapshotId)
|
---|
365 | return lvi;
|
---|
366 | ++ it;
|
---|
367 | }
|
---|
368 |
|
---|
369 | return 0;
|
---|
370 | }
|
---|
371 |
|
---|
372 | void VBoxSnapshotsWgt::refreshAll (bool aKeepSelected /* = false */)
|
---|
373 | {
|
---|
374 | QUuid selected, selectedFirstChild;
|
---|
375 | if (aKeepSelected)
|
---|
376 | {
|
---|
377 | ListViewItem *cur = static_cast <ListViewItem *> (listView->selectedItem());
|
---|
378 | Assert (cur);
|
---|
379 | if (cur)
|
---|
380 | {
|
---|
381 | selected = cur->snapshotId();
|
---|
382 | if (cur->firstChild())
|
---|
383 | selectedFirstChild =
|
---|
384 | static_cast <ListViewItem *> (cur->firstChild())->snapshotId();
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | listView->clear();
|
---|
389 |
|
---|
390 | if (mMachine.isNull())
|
---|
391 | {
|
---|
392 | listView_currentChanged (NULL);
|
---|
393 | return;
|
---|
394 | }
|
---|
395 |
|
---|
396 | /* get the first snapshot */
|
---|
397 | if (mMachine.GetSnapshotCount() > 0)
|
---|
398 | {
|
---|
399 | CSnapshot snapshot = mMachine.GetSnapshot (QUuid());
|
---|
400 |
|
---|
401 | populateSnapshots (snapshot, 0);
|
---|
402 | Assert (mCurSnapshotItem);
|
---|
403 |
|
---|
404 | /* add the "current state" item */
|
---|
405 | new ListViewItem (mCurSnapshotItem, mMachine);
|
---|
406 |
|
---|
407 | ListViewItem *cur = 0;
|
---|
408 | if (aKeepSelected)
|
---|
409 | {
|
---|
410 | cur = findItem (selected);
|
---|
411 | if (cur == 0)
|
---|
412 | cur = findItem (selectedFirstChild);
|
---|
413 | }
|
---|
414 | if (cur == 0)
|
---|
415 | cur = curStateItem();
|
---|
416 | listView->setSelected (cur, true);
|
---|
417 | listView->ensureItemVisible (cur);
|
---|
418 | }
|
---|
419 | else
|
---|
420 | {
|
---|
421 | mCurSnapshotItem = NULL;
|
---|
422 |
|
---|
423 | /* add the "current state" item */
|
---|
424 | ListViewItem *csi = new ListViewItem (listView, mMachine);
|
---|
425 |
|
---|
426 | listView->setSelected (csi, true);
|
---|
427 | /*
|
---|
428 | * stupid Qt doesn't issue this signal when only one item is added
|
---|
429 | * to the empty list -- do it manually
|
---|
430 | */
|
---|
431 | listView_currentChanged (csi);
|
---|
432 | }
|
---|
433 |
|
---|
434 | listView->adjustColumn (0);
|
---|
435 | }
|
---|
436 |
|
---|
437 | VBoxSnapshotsWgt::ListViewItem *VBoxSnapshotsWgt::curStateItem()
|
---|
438 | {
|
---|
439 | QListViewItem *csi = mCurSnapshotItem ? mCurSnapshotItem->firstChild()
|
---|
440 | : listView->firstChild();
|
---|
441 | Assert (csi);
|
---|
442 | return static_cast <ListViewItem *> (csi);
|
---|
443 | }
|
---|
444 |
|
---|
445 | void VBoxSnapshotsWgt::populateSnapshots (const CSnapshot &snapshot, QListViewItem *item)
|
---|
446 | {
|
---|
447 | ListViewItem *si = 0;
|
---|
448 | if (item)
|
---|
449 | si = new ListViewItem (item, snapshot);
|
---|
450 | else
|
---|
451 | si = new ListViewItem (listView, snapshot);
|
---|
452 |
|
---|
453 | if (mMachine.GetCurrentSnapshot().GetId() == snapshot.GetId())
|
---|
454 | {
|
---|
455 | si->setBold (true);
|
---|
456 | mCurSnapshotItem = si;
|
---|
457 | }
|
---|
458 |
|
---|
459 | CSnapshotEnumerator en = snapshot.GetChildren().Enumerate();
|
---|
460 | while (en.HasMore())
|
---|
461 | {
|
---|
462 | CSnapshot sn = en.GetNext();
|
---|
463 | populateSnapshots (sn, si);
|
---|
464 | }
|
---|
465 |
|
---|
466 | si->setOpen (true);
|
---|
467 | si->setRenameEnabled (0, true);
|
---|
468 | }
|
---|
469 |
|
---|
470 | void VBoxSnapshotsWgt::listView_currentChanged (QListViewItem *item)
|
---|
471 | {
|
---|
472 | /* Make the selected item visible */
|
---|
473 | if (item)
|
---|
474 | {
|
---|
475 | QPoint oldPos (listView->contentsX(), listView->contentsY());
|
---|
476 | listView->ensureItemVisible (item);
|
---|
477 | listView->setContentsPos (listView->treeStepSize() * item->depth(),
|
---|
478 | listView->contentsY());
|
---|
479 | /* Sometimes (here, when both X and Y are changed), affected items
|
---|
480 | * are not properly updated after moving the contents. Fix it. */
|
---|
481 | if (oldPos != QPoint (listView->contentsX(), listView->contentsY()))
|
---|
482 | listView->triggerUpdate();
|
---|
483 | }
|
---|
484 |
|
---|
485 | /* whether another direct session is open or not */
|
---|
486 | bool busy = mSessionState != KSessionState_Closed;
|
---|
487 |
|
---|
488 | /* enable/disable snapshot actions */
|
---|
489 | snapshotActionGroup->setEnabled (!busy &&
|
---|
490 | item && mCurSnapshotItem && item != mCurSnapshotItem->firstChild());
|
---|
491 |
|
---|
492 | /* enable/disable the details action regardles of the session state */
|
---|
493 | showSnapshotDetailsAction->setEnabled (
|
---|
494 | item && mCurSnapshotItem && item != mCurSnapshotItem->firstChild());
|
---|
495 |
|
---|
496 | /* enable/disable current state actions */
|
---|
497 | curStateActionGroup->setEnabled (!busy &&
|
---|
498 | item && mCurSnapshotItem && item == mCurSnapshotItem->firstChild());
|
---|
499 |
|
---|
500 | /* the Take Snapshot action is always enabled for the current state */
|
---|
501 | takeSnapshotAction->setEnabled ((!busy && curStateActionGroup->isEnabled()) ||
|
---|
502 | (item && !mCurSnapshotItem));
|
---|
503 |
|
---|
504 | mContextMenuDirty = true;
|
---|
505 | }
|
---|
506 |
|
---|
507 | void VBoxSnapshotsWgt::
|
---|
508 | listView_contextMenuRequested (QListViewItem *item, const QPoint &pnt,
|
---|
509 | int /* col */)
|
---|
510 | {
|
---|
511 | if (!item)
|
---|
512 | return;
|
---|
513 |
|
---|
514 | if (mContextMenuDirty)
|
---|
515 | {
|
---|
516 | mContextMenu->clear();
|
---|
517 |
|
---|
518 | if (!mCurSnapshotItem)
|
---|
519 | {
|
---|
520 | /* we have only one item -- current state */
|
---|
521 | curStateActionGroup->addTo (mContextMenu);
|
---|
522 | }
|
---|
523 | else
|
---|
524 | {
|
---|
525 | if (item == mCurSnapshotItem->firstChild())
|
---|
526 | {
|
---|
527 | /* current state is selected */
|
---|
528 | curStateActionGroup->addTo (mContextMenu);
|
---|
529 | }
|
---|
530 | else
|
---|
531 | {
|
---|
532 | /* snapshot is selected */
|
---|
533 | snapshotActionGroup->addTo (mContextMenu);
|
---|
534 | mContextMenu->insertSeparator();
|
---|
535 | showSnapshotDetailsAction->addTo (mContextMenu);
|
---|
536 | }
|
---|
537 | }
|
---|
538 |
|
---|
539 | mContextMenuDirty = false;
|
---|
540 | }
|
---|
541 |
|
---|
542 | mContextMenu->exec (pnt);
|
---|
543 | }
|
---|
544 |
|
---|
545 | void VBoxSnapshotsWgt::discardSnapshot()
|
---|
546 | {
|
---|
547 | ListViewItem *item = static_cast <ListViewItem *> (listView->currentItem());
|
---|
548 | AssertReturn (item, (void) 0);
|
---|
549 |
|
---|
550 | QUuid snapId = item->snapshotId();
|
---|
551 | AssertReturn (!snapId.isNull(), (void) 0);
|
---|
552 |
|
---|
553 | /* open a direct session (this call will handle all errors) */
|
---|
554 | CSession session = vboxGlobal().openSession (mMachineId);
|
---|
555 | if (session.isNull())
|
---|
556 | return;
|
---|
557 |
|
---|
558 | QString snapName = mMachine.GetSnapshot (snapId).GetName();
|
---|
559 |
|
---|
560 | CConsole console = session.GetConsole();
|
---|
561 | CProgress progress = console.DiscardSnapshot (snapId);
|
---|
562 | if (console.isOk())
|
---|
563 | {
|
---|
564 | /* show the progress dialog */
|
---|
565 | vboxProblem().showModalProgressDialog (progress, mMachine.GetName(),
|
---|
566 | vboxProblem().mainWindowShown());
|
---|
567 |
|
---|
568 | if (progress.GetResultCode() != 0)
|
---|
569 | vboxProblem().cannotDiscardSnapshot (progress, snapName);
|
---|
570 | }
|
---|
571 | else
|
---|
572 | vboxProblem().cannotDiscardSnapshot (console, snapName);
|
---|
573 |
|
---|
574 | session.Close();
|
---|
575 | }
|
---|
576 |
|
---|
577 | void VBoxSnapshotsWgt::takeSnapshot()
|
---|
578 | {
|
---|
579 | ListViewItem *item = static_cast <ListViewItem *> (listView->currentItem());
|
---|
580 | AssertReturn (item, (void) 0);
|
---|
581 |
|
---|
582 | VBoxTakeSnapshotDlg dlg (this, "VBoxTakeSnapshotDlg");
|
---|
583 |
|
---|
584 | QString typeId = mMachine.GetOSTypeId();
|
---|
585 | dlg.pmIcon->setPixmap (vboxGlobal().vmGuestOSTypeIcon (typeId));
|
---|
586 |
|
---|
587 | /* search for the max available filter index */
|
---|
588 | int maxSnapShotIndex = 0;
|
---|
589 | QString snapShotName = tr ("Snapshot %1");
|
---|
590 | QRegExp regExp (QString ("^") + snapShotName.arg ("([0-9]+)") + QString ("$"));
|
---|
591 | QListViewItemIterator iterator (listView);
|
---|
592 | while (*iterator)
|
---|
593 | {
|
---|
594 | QString snapShot = (*iterator)->text (0);
|
---|
595 | int pos = regExp.search (snapShot);
|
---|
596 | if (pos != -1)
|
---|
597 | maxSnapShotIndex = regExp.cap (1).toInt() > maxSnapShotIndex ?
|
---|
598 | regExp.cap (1).toInt() : maxSnapShotIndex;
|
---|
599 | ++ iterator;
|
---|
600 | }
|
---|
601 | dlg.leName->setText (snapShotName.arg (maxSnapShotIndex + 1));
|
---|
602 |
|
---|
603 | if (dlg.exec() == QDialog::Accepted)
|
---|
604 | {
|
---|
605 | /* open a direct session (this call will handle all errors) */
|
---|
606 | CSession session = vboxGlobal().openSession (mMachineId);
|
---|
607 | if (session.isNull())
|
---|
608 | return;
|
---|
609 |
|
---|
610 | CConsole console = session.GetConsole();
|
---|
611 | CProgress progress =
|
---|
612 | console.TakeSnapshot (dlg.leName->text().stripWhiteSpace(),
|
---|
613 | dlg.txeDescription->text());
|
---|
614 | if (console.isOk())
|
---|
615 | {
|
---|
616 | /* show the progress dialog */
|
---|
617 | vboxProblem().showModalProgressDialog (progress, mMachine.GetName(),
|
---|
618 | vboxProblem().mainWindowShown());
|
---|
619 |
|
---|
620 | if (progress.GetResultCode() != 0)
|
---|
621 | vboxProblem().cannotTakeSnapshot (progress);
|
---|
622 | }
|
---|
623 | else
|
---|
624 | vboxProblem().cannotTakeSnapshot (console);
|
---|
625 |
|
---|
626 | session.Close();
|
---|
627 | }
|
---|
628 | }
|
---|
629 |
|
---|
630 | void VBoxSnapshotsWgt::discardCurState()
|
---|
631 | {
|
---|
632 | ListViewItem *item = static_cast <ListViewItem *> (listView->currentItem());
|
---|
633 | AssertReturn (item, (void) 0);
|
---|
634 |
|
---|
635 | /* open a direct session (this call will handle all errors) */
|
---|
636 | CSession session = vboxGlobal().openSession (mMachineId);
|
---|
637 | if (session.isNull())
|
---|
638 | return;
|
---|
639 |
|
---|
640 | CConsole console = session.GetConsole();
|
---|
641 | CProgress progress = console.DiscardCurrentState();
|
---|
642 | if (console.isOk())
|
---|
643 | {
|
---|
644 | /* show the progress dialog */
|
---|
645 | vboxProblem().showModalProgressDialog (progress, mMachine.GetName(),
|
---|
646 | vboxProblem().mainWindowShown());
|
---|
647 |
|
---|
648 | if (progress.GetResultCode() != 0)
|
---|
649 | vboxProblem().cannotDiscardCurrentState (progress);
|
---|
650 | }
|
---|
651 | else
|
---|
652 | vboxProblem().cannotDiscardCurrentState (console);
|
---|
653 |
|
---|
654 | session.Close();
|
---|
655 | }
|
---|
656 |
|
---|
657 | void VBoxSnapshotsWgt::discardCurSnapAndState()
|
---|
658 | {
|
---|
659 | ListViewItem *item = static_cast <ListViewItem *> (listView->currentItem());
|
---|
660 | AssertReturn (item, (void) 0);
|
---|
661 |
|
---|
662 | /* open a direct session (this call will handle all errors) */
|
---|
663 | CSession session = vboxGlobal().openSession (mMachineId);
|
---|
664 | if (session.isNull())
|
---|
665 | return;
|
---|
666 |
|
---|
667 | CConsole console = session.GetConsole();
|
---|
668 | CProgress progress = console.DiscardCurrentSnapshotAndState();
|
---|
669 | if (console.isOk())
|
---|
670 | {
|
---|
671 | /* show the progress dialog */
|
---|
672 | vboxProblem().showModalProgressDialog (progress, mMachine.GetName(),
|
---|
673 | vboxProblem().mainWindowShown());
|
---|
674 |
|
---|
675 | if (progress.GetResultCode() != 0)
|
---|
676 | vboxProblem().cannotDiscardCurrentSnapshotAndState (progress);
|
---|
677 | }
|
---|
678 | else
|
---|
679 | vboxProblem().cannotDiscardCurrentSnapshotAndState (console);
|
---|
680 |
|
---|
681 | session.Close();
|
---|
682 | }
|
---|
683 |
|
---|
684 | void VBoxSnapshotsWgt::showSnapshotDetails()
|
---|
685 | {
|
---|
686 | ListViewItem *item = static_cast <ListViewItem *> (listView->currentItem());
|
---|
687 | AssertReturn (item, (void) 0);
|
---|
688 |
|
---|
689 | CSnapshot snap = item->snapshot();
|
---|
690 | AssertReturn (!snap.isNull(), (void) 0);
|
---|
691 |
|
---|
692 | CMachine snapMachine = snap.GetMachine();
|
---|
693 |
|
---|
694 | VBoxSnapshotDetailsDlg dlg (this);
|
---|
695 | dlg.getFromSnapshot (snap);
|
---|
696 |
|
---|
697 | if (dlg.exec() == QDialog::Accepted)
|
---|
698 | {
|
---|
699 | dlg.putBackToSnapshot();
|
---|
700 | }
|
---|
701 | }
|
---|
702 |
|
---|
703 | void VBoxSnapshotsWgt::machineDataChanged (const VBoxMachineDataChangeEvent &aE)
|
---|
704 | {
|
---|
705 | if (aE.id != mMachineId)
|
---|
706 | return; /* not interested in other machines */
|
---|
707 |
|
---|
708 | curStateItem()->recache();
|
---|
709 | }
|
---|
710 |
|
---|
711 | void VBoxSnapshotsWgt::machineStateChanged (const VBoxMachineStateChangeEvent &aE)
|
---|
712 | {
|
---|
713 | if (aE.id != mMachineId)
|
---|
714 | return; /* not interested in other machines */
|
---|
715 |
|
---|
716 | curStateItem()->recache();
|
---|
717 | curStateItem()->updateCurrentState (aE.state);
|
---|
718 | }
|
---|
719 |
|
---|
720 | void VBoxSnapshotsWgt::sessionStateChanged (const VBoxSessionStateChangeEvent &aE)
|
---|
721 | {
|
---|
722 | if (aE.id != mMachineId)
|
---|
723 | return; /* not interested in other machines */
|
---|
724 |
|
---|
725 | mSessionState = aE.state;
|
---|
726 | listView_currentChanged (listView->currentItem());
|
---|
727 | }
|
---|
728 |
|
---|
729 | void VBoxSnapshotsWgt::snapshotChanged (const VBoxSnapshotEvent &aE)
|
---|
730 | {
|
---|
731 | if (aE.machineId != mMachineId)
|
---|
732 | return; /* not interested in other machines */
|
---|
733 |
|
---|
734 | switch (aE.what)
|
---|
735 | {
|
---|
736 | case VBoxSnapshotEvent::Taken:
|
---|
737 | case VBoxSnapshotEvent::Discarded:
|
---|
738 | {
|
---|
739 | refreshAll (true);
|
---|
740 | break;
|
---|
741 | }
|
---|
742 | case VBoxSnapshotEvent::Changed:
|
---|
743 | {
|
---|
744 | ListViewItem *lvi = findItem (aE.snapshotId);
|
---|
745 | if (!lvi)
|
---|
746 | refreshAll();
|
---|
747 | else
|
---|
748 | {
|
---|
749 | lvi->recache();
|
---|
750 | lvi->repaint();
|
---|
751 | }
|
---|
752 | break;
|
---|
753 | }
|
---|
754 | }
|
---|
755 | }
|
---|
756 |
|
---|