~ubuntu-branches/ubuntu/wily/virtualbox/wily

« back to all changes in this revision

Viewing changes to src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

  • Committer: Package Import Robot
  • Author(s): Felix Geyer, Felix Geyer, Gianfranco Costamagna
  • Date: 2013-07-21 23:25:44 UTC
  • mfrom: (3.3.1 sid)
  • Revision ID: package-import@ubuntu.com-20130721232544-lwx39bot5tshhd3o
Tags: 4.2.16-dfsg-1
[ Felix Geyer ]
* New upstream release.
  - Fixes CVE-2013-3792: virtio-net host DoS vulnerability. (Closes: #715327)
* Drop 36-python-multiarch.patch and 37-wheezy-kernel-drm.patch,
  fixed upstream.
* Explicity load the vboxguest and vboxsf kernel modules in the
  virtualbox-guest-utils init script.
  This makes sure that shared folders can be mounted. (Closes: #712438)

[ Gianfranco Costamagna ]
* Patch refresh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
/* Qt includes: */
21
21
#include <QApplication>
 
22
#include <QDesktopWidget>
22
23
#include <QWidget>
23
24
#include <QTimer>
24
25
 
65
66
#include "CHostNetworkInterface.h"
66
67
#include "CVRDEServer.h"
67
68
#include "CUSBController.h"
 
69
#include "CSnapshot.h"
68
70
 
69
71
UISession::UISession(UIMachine *pMachine, CSession &sessionReference)
70
72
    : QObject(pMachine)
83
85
    , m_fIsGuestResizeIgnored(false)
84
86
    , m_fIsSeamlessModeRequested(false)
85
87
    , m_fIsAutoCaptureDisabled(false)
 
88
    , m_fReconfigurable(false)
86
89
    /* Guest additions flags: */
87
90
    , m_ulGuestAdditionsRunLevel(0)
88
91
    , m_fIsGuestSupportsGraphics(false)
102
105
    , m_fIsValidPointerShapePresent(false)
103
106
    , m_fIsHidingHostPointer(true)
104
107
{
 
108
    /* Prepare connections: */
 
109
    prepareConnections();
 
110
 
105
111
    /* Prepare console event-handlers: */
106
112
    prepareConsoleEventHandlers();
107
113
 
284
290
    emit sigMachineStarted();
285
291
}
286
292
 
 
293
bool UISession::save()
 
294
{
 
295
    /* Prepare the save-state progress: */
 
296
    CMachine machine = m_session.GetMachine();
 
297
    CConsole console = m_session.GetConsole();
 
298
    CProgress progress = console.SaveState();
 
299
    if (console.isOk())
 
300
    {
 
301
        /* Show the save-state progress: */
 
302
        msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_state_save_90px.png", mainMachineWindow(), true);
 
303
        if (!progress.isOk() || progress.GetResultCode() != 0)
 
304
        {
 
305
            /* Failed in progress: */
 
306
            msgCenter().cannotSaveMachineState(progress);
 
307
            return false;
 
308
        }
 
309
    }
 
310
    else
 
311
    {
 
312
        /* Failed in console: */
 
313
        msgCenter().cannotSaveMachineState(console);
 
314
        return false;
 
315
    }
 
316
    /* Passed: */
 
317
    return true;
 
318
}
 
319
 
 
320
bool UISession::shutdown()
 
321
{
 
322
    /* Send ACPI shutdown signal if possible: */
 
323
    CConsole console = m_session.GetConsole();
 
324
    console.PowerButton();
 
325
    if (!console.isOk())
 
326
    {
 
327
        /* Failed in console: */
 
328
        msgCenter().cannotACPIShutdownMachine(console);
 
329
        return false;
 
330
    }
 
331
    /* Passed: */
 
332
    return true;
 
333
}
 
334
 
 
335
bool UISession::powerOff(bool fDiscardState, bool &fServerCrashed)
 
336
{
 
337
    /* Prepare the power-off progress: */
 
338
    CMachine machine = m_session.GetMachine();
 
339
    CConsole console = m_session.GetConsole();
 
340
    CProgress progress = console.PowerDown();
 
341
    if (console.isOk())
 
342
    {
 
343
        /* Show the power-off progress: */
 
344
        msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_poweroff_90px.png", mainMachineWindow(), true);
 
345
        if (progress.isOk() && progress.GetResultCode() == 0)
 
346
        {
 
347
            /* Discard the current state if requested: */
 
348
            if (fDiscardState)
 
349
            {
 
350
                /* Prepare the discard-state progress: */
 
351
                CSnapshot snapshot = machine.GetCurrentSnapshot();
 
352
                CProgress progress = console.RestoreSnapshot(snapshot);
 
353
                if (console.isOk())
 
354
                {
 
355
                    /* Show the discard-state progress: */
 
356
                    msgCenter().showModalProgressDialog(progress, machine.GetName(), ":/progress_snapshot_discard_90px.png", mainMachineWindow(), true);
 
357
                    if (!progress.isOk() || progress.GetResultCode() != 0)
 
358
                    {
 
359
                        /* Failed in progress: */
 
360
                        msgCenter().cannotRestoreSnapshot(progress, snapshot.GetName());
 
361
                        return false;
 
362
                    }
 
363
                }
 
364
                else
 
365
                {
 
366
                    /* Failed in console: */
 
367
                    msgCenter().cannotRestoreSnapshot(console, snapshot.GetName());
 
368
                    return false;
 
369
                }
 
370
            }
 
371
        }
 
372
        else
 
373
        {
 
374
            /* Failed in progress: */
 
375
            msgCenter().cannotStopMachine(progress);
 
376
            return false;
 
377
        }
 
378
    }
 
379
    else
 
380
    {
 
381
        /* Failed in console: */
 
382
        COMResult res(console);
 
383
        /* This can happen if VBoxSVC is not running: */
 
384
        if (FAILED_DEAD_INTERFACE(res.rc()))
 
385
            fServerCrashed = true;
 
386
        else
 
387
            msgCenter().cannotStopMachine(console);
 
388
        return false;
 
389
    }
 
390
    /* Passed: */
 
391
    return true;
 
392
}
 
393
 
287
394
UIMachineLogic* UISession::machineLogic() const
288
395
{
289
396
    return uimachine()->machineLogic();
294
401
    return machineLogic()->mainMachineWindow();
295
402
}
296
403
 
297
 
QMenu* UISession::newMenu(UIMainMenuType fOptions /* = UIMainMenuType_ALL */)
 
404
QMenu* UISession::newMenu(RuntimeMenuType fOptions /* = RuntimeMenuType_ALL */)
298
405
{
299
406
    /* Create new menu: */
300
407
    QMenu *pMenu = m_pMenuPool->createMenu(fOptions);
306
413
    return pMenu;
307
414
}
308
415
 
309
 
QMenuBar* UISession::newMenuBar(UIMainMenuType fOptions /* = UIMainMenuType_ALL */)
 
416
QMenuBar* UISession::newMenuBar(RuntimeMenuType fOptions /* = RuntimeMenuType_ALL */)
310
417
{
311
418
    /* Create new menubar: */
312
419
    QMenuBar *pMenuBar = m_pMenuPool->createMenuBar(fOptions);
570
677
        /* Store new data: */
571
678
        m_machineState = state;
572
679
 
 
680
        /* Update session settings: */
 
681
        updateSessionSettings();
 
682
 
573
683
        /* Notify listeners about machine state changed: */
574
684
        emit sigMachineStateChange();
575
685
    }
591
701
    emit sigVRDEChange();
592
702
}
593
703
 
 
704
void UISession::sltGuestMonitorChange(KGuestMonitorChangedEventType changeType, ulong uScreenId, QRect screenGeo)
 
705
{
 
706
    /* Ignore KGuestMonitorChangedEventType_NewOrigin change event: */
 
707
    if (changeType == KGuestMonitorChangedEventType_NewOrigin)
 
708
        return;
 
709
    /* Ignore KGuestMonitorChangedEventType_Disabled event if there is only one window visible: */
 
710
    AssertMsg(countOfVisibleWindows() > 0, ("All machine windows are hidden!"));
 
711
    if (   changeType == KGuestMonitorChangedEventType_Disabled
 
712
        && countOfVisibleWindows() == 1
 
713
        && isScreenVisible(uScreenId))
 
714
        return;
 
715
 
 
716
    /* Process KGuestMonitorChangedEventType_Enabled change event: */
 
717
    if (   !isScreenVisible(uScreenId)
 
718
        && changeType == KGuestMonitorChangedEventType_Enabled)
 
719
        setScreenVisible(uScreenId, true);
 
720
    /* Process KGuestMonitorChangedEventType_Disabled change event: */
 
721
    else if (   isScreenVisible(uScreenId)
 
722
             && changeType == KGuestMonitorChangedEventType_Disabled)
 
723
        setScreenVisible(uScreenId, false);
 
724
 
 
725
    /* Notify listeners about the change: */
 
726
    emit sigGuestMonitorChange(changeType, uScreenId, screenGeo);
 
727
}
 
728
 
594
729
void UISession::sltAdditionsChange()
595
730
{
596
731
    /* Get our guest: */
669
804
            this, SIGNAL(sigCPUExecutionCapChange()));
670
805
 
671
806
    connect(gConsoleEvents, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)),
672
 
            this, SIGNAL(sigGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)));
 
807
            this, SLOT(sltGuestMonitorChange(KGuestMonitorChangedEventType, ulong, QRect)));
 
808
}
 
809
 
 
810
void UISession::prepareConnections()
 
811
{
 
812
    connect(QApplication::desktop(), SIGNAL(screenCountChanged(int)),
 
813
            this, SIGNAL(sigHostScreenCountChanged(int)));
673
814
}
674
815
 
675
816
void UISession::prepareScreens()
707
848
 
708
849
void UISession::prepareMenuPool()
709
850
{
710
 
    m_pMenuPool = new UIMachineMenuBar;
 
851
    m_pMenuPool = new UIMachineMenuBar(session().GetMachine());
711
852
}
712
853
 
713
854
void UISession::loadSessionSettings()
735
876
        QAction *pGuestAutoresizeSwitch = gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize);
736
877
        pGuestAutoresizeSwitch->setChecked(strSettings != "off");
737
878
 
 
879
        /* Should we allow reconfiguration? */
 
880
        m_fReconfigurable = VBoxGlobal::shouldWeAllowMachineReconfiguration(machine);
 
881
        updateSessionSettings();
 
882
 
738
883
#if 0 /* Disabled for now! */
739
884
# ifdef Q_WS_WIN
740
885
        /* Disable host screen-saver if requested: */
801
946
    UIConsoleEventHandler::destroy();
802
947
}
803
948
 
 
949
void UISession::updateSessionSettings()
 
950
{
 
951
    bool fAllowReconfiguration = m_machineState != KMachineState_Stuck && m_fReconfigurable;
 
952
    gActionPool->action(UIActionIndexRuntime_Simple_SettingsDialog)->setEnabled(fAllowReconfiguration);
 
953
    gActionPool->action(UIActionIndexRuntime_Simple_SharedFoldersDialog)->setEnabled(fAllowReconfiguration);
 
954
    gActionPool->action(UIActionIndexRuntime_Simple_NetworkAdaptersDialog)->setEnabled(fAllowReconfiguration);
 
955
}
 
956
 
804
957
WId UISession::winId() const
805
958
{
806
959
    return mainMachineWindow()->winId();