VirtualBox

Changeset 27374 in vbox for trunk/src


Ignore:
Timestamp:
Mar 15, 2010 4:42:37 PM (15 years ago)
Author:
vboxsync
Message:

FE/Qt4: new core: additions downloader works in the mm case now

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
1 added
12 edited
2 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r27335 r27374  
    357357        src/widgets/VBoxApplianceEditorWgt.h \
    358358        src/widgets/VBoxBootTable.h \
    359         src/widgets/VBoxDownloaderWgt.h \
     359        src/widgets/UIDownloader.h \
     360        src/widgets/UIDownloaderAdditions.h \
    360361        src/widgets/VBoxExportApplianceWgt.h \
    361362        src/widgets/VBoxFilePathSelectorWidget.h \
     
    485486        src/widgets/VBoxApplianceEditorWgt.cpp \
    486487        src/widgets/VBoxBootTable.cpp \
    487         src/widgets/VBoxDownloaderWgt.cpp \
     488        src/widgets/UIDownloader.cpp \
     489        src/widgets/UIDownloaderAdditions.cpp \
    488490        src/widgets/VBoxExportApplianceWgt.cpp \
    489491        src/widgets/VBoxFilePathSelectorWidget.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r27193 r27374  
    5252#include "VBoxConsoleView.h"
    5353#include "VBoxCloseVMDlg.h"
    54 #include "VBoxDownloaderWgt.h"
     54#include "UIDownloaderAdditions.h"
    5555#include "VBoxGlobal.h"
    5656#include "VBoxMediaManagerDlg.h"
     
    102102
    103103    QString mTip;
    104 };
    105 
    106 class VBoxAdditionsDownloader : public VBoxDownloaderWgt
    107 {
    108     Q_OBJECT;
    109 
    110 public:
    111 
    112     VBoxAdditionsDownloader (const QString &aSource, const QString &aTarget, QAction *aAction)
    113         : VBoxDownloaderWgt (aSource, aTarget)
    114         , mAction (aAction)
    115     {
    116         mAction->setEnabled (false);
    117         retranslateUi();
    118     }
    119 
    120     void start()
    121     {
    122         acknowledgeStart();
    123     }
    124 
    125 protected:
    126 
    127     void retranslateUi()
    128     {
    129         mCancelButton->setText (tr ("Cancel"));
    130         mProgressBar->setToolTip (tr ("Downloading the VirtualBox Guest Additions "
    131                                       "CD image from <nobr><b>%1</b>...</nobr>")
    132                                       .arg (mSource.toString()));
    133         mCancelButton->setToolTip (tr ("Cancel the VirtualBox Guest "
    134                                        "Additions CD image download"));
    135     }
    136 
    137 private slots:
    138 
    139     void downloadFinished (bool aError)
    140     {
    141         if (aError)
    142             VBoxDownloaderWgt::downloadFinished (aError);
    143         else
    144         {
    145             QByteArray receivedData (mHttp->readAll());
    146             /* Serialize the incoming buffer into the .iso image. */
    147             while (true)
    148             {
    149                 QFile file (mTarget);
    150                 if (file.open (QIODevice::WriteOnly))
    151                 {
    152                     file.write (receivedData);
    153                     file.close();
    154                     if (vboxProblem().confirmMountAdditions (mSource.toString(),
    155                         QDir::toNativeSeparators (mTarget)))
    156                         vboxGlobal().consoleWnd().installGuestAdditionsFrom (mTarget);
    157                     QTimer::singleShot (0, this, SLOT (suicide()));
    158                     break;
    159                 }
    160                 else
    161                 {
    162                     vboxProblem().message (window(), VBoxProblemReporter::Error,
    163                         tr ("<p>Failed to save the downloaded file as "
    164                             "<nobr><b>%1</b>.</nobr></p>")
    165                         .arg (QDir::toNativeSeparators (mTarget)));
    166                 }
    167 
    168                 QString target = QIFileDialog::getExistingDirectory (
    169                     QFileInfo (mTarget).absolutePath(), this,
    170                     tr ("Select folder to save Guest Additions image to"), true);
    171                 if (target.isNull())
    172                     QTimer::singleShot (0, this, SLOT (suicide()));
    173                 else
    174                     mTarget = QDir (target).absoluteFilePath (QFileInfo (mTarget).fileName());
    175             }
    176         }
    177     }
    178 
    179     void suicide()
    180     {
    181         QStatusBar *sb = qobject_cast <QStatusBar*> (parent());
    182         Assert (sb);
    183         sb->removeWidget (this);
    184         mAction->setEnabled (true);
    185         VBoxDownloaderWgt::suicide();
    186     }
    187 
    188 private:
    189 
    190     bool confirmDownload()
    191     {
    192         return vboxProblem().confirmDownloadAdditions (mSource.toString(),
    193             mHttp->lastResponse().contentLength());
    194     }
    195 
    196     void warnAboutError (const QString &aError)
    197     {
    198         return vboxProblem().cannotDownloadGuestAdditions (mSource.toString(), aError);
    199     }
    200 
    201     QAction *mAction;
    202104};
    203105
     
    11231025    mMainMenu->activateWindow();
    11241026#endif
    1125 }
    1126 
    1127 void VBoxConsoleWnd::installGuestAdditionsFrom (const QString &aSource)
    1128 {
    1129     CVirtualBox vbox = vboxGlobal().virtualBox();
    1130     QString uuid;
    1131 
    1132     CMedium image = vbox.FindDVDImage (aSource);
    1133     if (image.isNull())
    1134     {
    1135         image = vbox.OpenDVDImage (aSource, uuid);
    1136         if (vbox.isOk())
    1137             uuid = image.GetId();
    1138     }
    1139     else
    1140         uuid = image.GetId();
    1141 
    1142     if (!vbox.isOk())
    1143         return vboxProblem().cannotOpenMedium (this, vbox, VBoxDefs::MediumType_DVD, aSource);
    1144 
    1145     Assert (!uuid.isNull());
    1146     CMachine m = mSession.GetMachine();
    1147 
    1148     QString ctrName;
    1149     LONG ctrPort = -1, ctrDevice = -1;
    1150     /* Searching for the first suitable slot */
    1151     {
    1152         CStorageControllerVector controllers = m.GetStorageControllers();
    1153         int i = 0;
    1154         while (i < controllers.size() && ctrName.isNull())
    1155         {
    1156             CStorageController controller = controllers [i];
    1157             CMediumAttachmentVector attachments = m.GetMediumAttachmentsOfController (controller.GetName());
    1158             int j = 0;
    1159             while (j < attachments.size() && ctrName.isNull())
    1160             {
    1161                 CMediumAttachment attachment = attachments [j];
    1162                 if (attachment.GetType() == KDeviceType_DVD)
    1163                 {
    1164                     ctrName = controller.GetName();
    1165                     ctrPort = attachment.GetPort();
    1166                     ctrDevice = attachment.GetDevice();
    1167                 }
    1168                 ++ j;
    1169             }
    1170             ++ i;
    1171         }
    1172     }
    1173 
    1174     if (!ctrName.isNull())
    1175     {
    1176         bool isMounted = false;
    1177 
    1178         /* Mount medium to the predefined port/device */
    1179         m.MountMedium (ctrName, ctrPort, ctrDevice, uuid, false /* force */);
    1180         if (m.isOk())
    1181             isMounted = true;
    1182         else
    1183         {
    1184             /* Ask for force mounting */
    1185             if (vboxProblem().cannotRemountMedium (this, m, VBoxMedium (image, VBoxDefs::MediumType_DVD), true /* mount? */, true /* retry? */) == QIMessageBox::Ok)
    1186             {
    1187                 /* Force mount medium to the predefined port/device */
    1188                 m.MountMedium (ctrName, ctrPort, ctrDevice, uuid, true /* force */);
    1189                 if (m.isOk())
    1190                     isMounted = true;
    1191                 else
    1192                     vboxProblem().cannotRemountMedium (this, m, VBoxMedium (image, VBoxDefs::MediumType_DVD), true /* mount? */, false /* retry? */);
    1193             }
    1194         }
    1195 
    1196         /* Save medium mounted at runtime */
    1197         if (isMounted && mIsAutoSaveMedia)
    1198         {
    1199             m.SaveSettings();
    1200             if (!m.isOk())
    1201                 vboxProblem().cannotSaveMachineSettings (m);
    1202         }
    1203     }
    1204     else
    1205         vboxProblem().cannotMountGuestAdditions (m.GetName());
    12061027}
    12071028
     
    22612082                               .absoluteFilePath (name);
    22622083
    2263         VBoxAdditionsDownloader *dl =
    2264             new VBoxAdditionsDownloader (source, target, mDevicesInstallGuestToolsAction);
    2265         statusBar()->addWidget (dl, 0);
    2266         dl->start();
     2084        UIDownloaderAdditions *pDl = UIDownloaderAdditions::create();
     2085        /* Configure the additions downloader. */
     2086        pDl->setSource(source);
     2087        pDl->setTarget(target);
     2088        pDl->setAction(mDevicesInstallGuestToolsAction);
     2089        pDl->setParentWidget(this);
     2090        /* After the download is finished the user may like to install the
     2091         * additions.*/
     2092        connect(pDl, SIGNAL(downloadFinished(const QString&)),
     2093                this, SLOT(installGuestAdditionsFrom(const QString&)));
     2094        /* Add the progress bar widget to the statusbar. */
     2095        statusBar()->addWidget(pDl->processWidget(this), 0);
     2096        /* Start the download: */
     2097        pDl->startDownload();
    22672098    }
    22682099}
     
    29582789}
    29592790
     2791void VBoxConsoleWnd::installGuestAdditionsFrom (const QString &aSource)
     2792{
     2793    CVirtualBox vbox = vboxGlobal().virtualBox();
     2794    QString uuid;
     2795
     2796    CMedium image = vbox.FindDVDImage (aSource);
     2797    if (image.isNull())
     2798    {
     2799        image = vbox.OpenDVDImage (aSource, uuid);
     2800        if (vbox.isOk())
     2801            uuid = image.GetId();
     2802    }
     2803    else
     2804        uuid = image.GetId();
     2805
     2806    if (!vbox.isOk())
     2807        return vboxProblem().cannotOpenMedium (this, vbox, VBoxDefs::MediumType_DVD, aSource);
     2808
     2809    Assert (!uuid.isNull());
     2810    CMachine m = mSession.GetMachine();
     2811
     2812    QString ctrName;
     2813    LONG ctrPort = -1, ctrDevice = -1;
     2814    /* Searching for the first suitable slot */
     2815    {
     2816        CStorageControllerVector controllers = m.GetStorageControllers();
     2817        int i = 0;
     2818        while (i < controllers.size() && ctrName.isNull())
     2819        {
     2820            CStorageController controller = controllers [i];
     2821            CMediumAttachmentVector attachments = m.GetMediumAttachmentsOfController (controller.GetName());
     2822            int j = 0;
     2823            while (j < attachments.size() && ctrName.isNull())
     2824            {
     2825                CMediumAttachment attachment = attachments [j];
     2826                if (attachment.GetType() == KDeviceType_DVD)
     2827                {
     2828                    ctrName = controller.GetName();
     2829                    ctrPort = attachment.GetPort();
     2830                    ctrDevice = attachment.GetDevice();
     2831                }
     2832                ++ j;
     2833            }
     2834            ++ i;
     2835        }
     2836    }
     2837
     2838    if (!ctrName.isNull())
     2839    {
     2840        bool isMounted = false;
     2841
     2842        /* Mount medium to the predefined port/device */
     2843        m.MountMedium (ctrName, ctrPort, ctrDevice, uuid, false /* force */);
     2844        if (m.isOk())
     2845            isMounted = true;
     2846        else
     2847        {
     2848            /* Ask for force mounting */
     2849            if (vboxProblem().cannotRemountMedium (this, m, VBoxMedium (image, VBoxDefs::MediumType_DVD), true /* mount? */, true /* retry? */) == QIMessageBox::Ok)
     2850            {
     2851                /* Force mount medium to the predefined port/device */
     2852                m.MountMedium (ctrName, ctrPort, ctrDevice, uuid, true /* force */);
     2853                if (m.isOk())
     2854                    isMounted = true;
     2855                else
     2856                    vboxProblem().cannotRemountMedium (this, m, VBoxMedium (image, VBoxDefs::MediumType_DVD), true /* mount? */, false /* retry? */);
     2857            }
     2858        }
     2859
     2860        /* Save medium mounted at runtime */
     2861        if (isMounted && mIsAutoSaveMedia)
     2862        {
     2863            m.SaveSettings();
     2864            if (!m.isOk())
     2865                vboxProblem().cannotSaveMachineSettings (m);
     2866        }
     2867    }
     2868    else
     2869        vboxProblem().cannotMountGuestAdditions (m.GetName());
     2870}
     2871
    29602872/**
    29612873 *  This function checks the status of required features and
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.h

    r26729 r27374  
    107107    void popupMainMenu (bool aCenter);
    108108
    109     void installGuestAdditionsFrom (const QString &aSource);
    110 
    111109    void setMask (const QRegion &aRegion);
    112110    void clearMask();
     
    186184    void changePresentationMode (const VBoxChangePresentationModeEvent &aEvent);
    187185    void processGlobalSettingChange (const char *aPublicName, const char *aName);
     186
     187    void installGuestAdditionsFrom (const QString &aSource);
    188188
    189189#ifdef RT_OS_DARWIN /* Stupid moc doesn't recognize Q_WS_MAC */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r27311 r27374  
    3737#include "VBoxVMSettingsNetwork.h"
    3838#include "VBoxVMSettingsSF.h"
     39#include "UIDownloaderAdditions.h"
    3940#ifdef Q_WS_MAC
    4041# include "DockIconPreview.h"
    4142#endif /* Q_WS_MAC */
    42 
    43 //#include "VBoxDownloaderWgt.h"
    4443
    4544#include "QIFileDialog.h"
     
    14761475    /* Check the standard image locations */
    14771476    if (QFile::exists(strSrc1))
    1478         return installGuestAdditionsFrom(strSrc1);
     1477        return uisession()->sltInstallGuestAdditionsFrom(strSrc1);
    14791478    else if (QFile::exists(strSrc2))
    1480         return installGuestAdditionsFrom(strSrc2);
     1479        return uisession()->sltInstallGuestAdditionsFrom(strSrc2);
    14811480
    14821481    /* Check for the already registered image */
     
    14911490        QString fn = QFileInfo(path).fileName();
    14921491        if (RTPathCompare(name.toUtf8().constData(), fn.toUtf8().constData()) == 0)
    1493             return installGuestAdditionsFrom(path);
    1494     }
    1495 
    1496 #if 0 // TODO: Rework additions downloader logic...
     1492            return uisession()->sltInstallGuestAdditionsFrom(path);
     1493    }
     1494
    14971495    /* Download the required image */
    14981496    int result = vboxProblem().cannotFindGuestAdditions(QDir::toNativeSeparators(strSrc1), QDir::toNativeSeparators(strSrc2));
     
    15021500        QString target = QDir(vboxGlobal().virtualBox().GetHomeFolder()).absoluteFilePath(name);
    15031501
    1504         //UIAdditionsDownloader *pdl = new UIAdditionsDownloader(source, target, mDevicesInstallGuestToolsAction);
    1505         //machineWindowWrapper()->statusBar()->addWidget(pdl, 0);
    1506         //pdl->start();
    1507     }
    1508 #endif
     1502        UIDownloaderAdditions *pDl = UIDownloaderAdditions::create();
     1503        /* Configure the additions downloader. */
     1504        pDl->setSource(source);
     1505        pDl->setTarget(target);
     1506        pDl->setAction(actionsPool()->action(UIActionIndex_Simple_InstallGuestTools));
     1507        pDl->setParentWidget(mainMachineWindow()->machineWindow());
     1508        /* After the download is finished the user may like to install the
     1509         * additions.*/
     1510        connect(pDl, SIGNAL(downloadFinished(const QString&)),
     1511                uisession(), SLOT(sltInstallGuestAdditionsFrom(const QString&)));
     1512        /* Some of the modes may show additional info of the download progress. */
     1513        foreach (UIMachineWindow *pWindow, machineWindows())
     1514            pWindow->prepareAdditionsDownloader();
     1515        /* Start the download: */
     1516        pDl->startDownload();
     1517    }
    15091518}
    15101519
     
    15971606}
    15981607#endif /* Q_WS_MAC */
    1599 
    1600 void UIMachineLogic::installGuestAdditionsFrom(const QString &strSource)
    1601 {
    1602     CMachine machine = session().GetMachine();
    1603     CVirtualBox vbox = vboxGlobal().virtualBox();
    1604     QString strUuid;
    1605 
    1606     CMedium image = vbox.FindDVDImage(strSource);
    1607     if (image.isNull())
    1608     {
    1609         image = vbox.OpenDVDImage(strSource, strUuid);
    1610         if (vbox.isOk())
    1611             strUuid = image.GetId();
    1612     }
    1613     else
    1614         strUuid = image.GetId();
    1615 
    1616     if (!vbox.isOk())
    1617     {
    1618         vboxProblem().cannotOpenMedium(0, vbox, VBoxDefs::MediumType_DVD, strSource);
    1619         return;
    1620     }
    1621 
    1622     AssertMsg(!strUuid.isNull(), ("Guest Additions image UUID should be valid!\n"));
    1623 
    1624     QString strCntName;
    1625     LONG iCntPort = -1, iCntDevice = -1;
    1626     /* Searching for the first suitable slot */
    1627     {
    1628         CStorageControllerVector controllers = machine.GetStorageControllers();
    1629         int i = 0;
    1630         while (i < controllers.size() && strCntName.isNull())
    1631         {
    1632             CStorageController controller = controllers[i];
    1633             CMediumAttachmentVector attachments = machine.GetMediumAttachmentsOfController(controller.GetName());
    1634             int j = 0;
    1635             while (j < attachments.size() && strCntName.isNull())
    1636             {
    1637                 CMediumAttachment attachment = attachments[j];
    1638                 if (attachment.GetType() == KDeviceType_DVD)
    1639                 {
    1640                     strCntName = controller.GetName();
    1641                     iCntPort = attachment.GetPort();
    1642                     iCntDevice = attachment.GetDevice();
    1643                 }
    1644                 ++ j;
    1645             }
    1646             ++ i;
    1647         }
    1648     }
    1649 
    1650     if (!strCntName.isNull())
    1651     {
    1652         bool fIsMounted = false;
    1653 
    1654         /* Mount medium to the predefined port/device */
    1655         machine.MountMedium(strCntName, iCntPort, iCntDevice, strUuid, false /* force */);
    1656         if (machine.isOk())
    1657             fIsMounted = true;
    1658         else
    1659         {
    1660             /* Ask for force mounting */
    1661             if (vboxProblem().cannotRemountMedium(0, machine, VBoxMedium(image, VBoxDefs::MediumType_DVD),
    1662                                                   true /* mount? */, true /* retry? */) == QIMessageBox::Ok)
    1663             {
    1664                 /* Force mount medium to the predefined port/device */
    1665                 machine.MountMedium(strCntName, iCntPort, iCntDevice, strUuid, true /* force */);
    1666                 if (machine.isOk())
    1667                     fIsMounted = true;
    1668                 else
    1669                     vboxProblem().cannotRemountMedium(0, machine, VBoxMedium(image, VBoxDefs::MediumType_DVD),
    1670                                                       true /* mount? */, false /* retry? */);
    1671             }
    1672         }
    1673     }
    1674     else
    1675         vboxProblem().cannotMountGuestAdditions(machine.GetName());
    1676 }
    16771608
    16781609int UIMachineLogic::searchMaxSnapshotIndex(const CMachine &machine,
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r27335 r27374  
    177177
    178178    /* Utility functions: */
    179     void installGuestAdditionsFrom(const QString &strSource);
    180179    static int searchMaxSnapshotIndex(const CMachine &machine,
    181180                                      const CSnapshot &snapshot,
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp

    r27330 r27374  
    357357    /* Machine state-change updater: */
    358358    QObject::connect(uisession(), SIGNAL(sigMachineStateChange()), machineWindow(), SLOT(sltMachineStateChanged()));
     359}
     360
     361void UIMachineWindow::prepareAdditionsDownloader()
     362{
    359363}
    360364
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h

    r27335 r27374  
    7777    virtual void prepareWindowIcon();
    7878    virtual void prepareConsoleConnections();
     79    virtual void prepareAdditionsDownloader();
    7980    virtual void prepareMachineViewContainer();
    8081    //virtual void loadWindowSettings() {}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp

    r27335 r27374  
    728728}
    729729
     730void UISession::sltInstallGuestAdditionsFrom(const QString &strSource)
     731{
     732    CMachine machine = session().GetMachine();
     733    CVirtualBox vbox = vboxGlobal().virtualBox();
     734    QString strUuid;
     735
     736    CMedium image = vbox.FindDVDImage(strSource);
     737    if (image.isNull())
     738    {
     739        image = vbox.OpenDVDImage(strSource, strUuid);
     740        if (vbox.isOk())
     741            strUuid = image.GetId();
     742    }
     743    else
     744        strUuid = image.GetId();
     745
     746    if (!vbox.isOk())
     747    {
     748        vboxProblem().cannotOpenMedium(0, vbox, VBoxDefs::MediumType_DVD, strSource);
     749        return;
     750    }
     751
     752    AssertMsg(!strUuid.isNull(), ("Guest Additions image UUID should be valid!\n"));
     753
     754    QString strCntName;
     755    LONG iCntPort = -1, iCntDevice = -1;
     756    /* Searching for the first suitable slot */
     757    {
     758        CStorageControllerVector controllers = machine.GetStorageControllers();
     759        int i = 0;
     760        while (i < controllers.size() && strCntName.isNull())
     761        {
     762            CStorageController controller = controllers[i];
     763            CMediumAttachmentVector attachments = machine.GetMediumAttachmentsOfController(controller.GetName());
     764            int j = 0;
     765            while (j < attachments.size() && strCntName.isNull())
     766            {
     767                CMediumAttachment attachment = attachments[j];
     768                if (attachment.GetType() == KDeviceType_DVD)
     769                {
     770                    strCntName = controller.GetName();
     771                    iCntPort = attachment.GetPort();
     772                    iCntDevice = attachment.GetDevice();
     773                }
     774                ++ j;
     775            }
     776            ++ i;
     777        }
     778    }
     779
     780    if (!strCntName.isNull())
     781    {
     782        bool fIsMounted = false;
     783
     784        /* Mount medium to the predefined port/device */
     785        machine.MountMedium(strCntName, iCntPort, iCntDevice, strUuid, false /* force */);
     786        if (machine.isOk())
     787            fIsMounted = true;
     788        else
     789        {
     790            /* Ask for force mounting */
     791            if (vboxProblem().cannotRemountMedium(0, machine, VBoxMedium(image, VBoxDefs::MediumType_DVD),
     792                                                  true /* mount? */, true /* retry? */) == QIMessageBox::Ok)
     793            {
     794                /* Force mount medium to the predefined port/device */
     795                machine.MountMedium(strCntName, iCntPort, iCntDevice, strUuid, true /* force */);
     796                if (machine.isOk())
     797                    fIsMounted = true;
     798                else
     799                    vboxProblem().cannotRemountMedium(0, machine, VBoxMedium(image, VBoxDefs::MediumType_DVD),
     800                                                      true /* mount? */, false /* retry? */);
     801            }
     802        }
     803    }
     804    else
     805        vboxProblem().cannotMountGuestAdditions(machine.GetName());
     806}
     807
    730808void UISession::sltCloseVirtualSession()
    731809{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h

    r27335 r27374  
    3737
    3838/* Local forwards */
    39 class UIMachine;
    4039class UIActionsPool;
    4140class UIConsoleCallback;
     41class UIDownloaderAdditions;
     42class UIMachine;
    4243class UIMachineMenuBar;
    4344
     
    165166    void sigMouseCapturedStatusChanged();
    166167
     168public slots:
     169
     170    void sltInstallGuestAdditionsFrom(const QString &strSource);
     171
    167172private slots:
    168173
     
    233238    bool m_fIsHidingHostPointer : 1;
    234239
     240    UIDownloaderAdditions *m_pDownloaderAdditions;
     241
    235242    /* Friend classes: */
    236243    friend class UIConsoleCallback;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp

    r27311 r27374  
    3030#include "VBoxProblemReporter.h"
    3131
     32#include "UIActionsPool.h"
     33#include "UIDownloaderAdditions.h"
     34#include "UIMachineLogicNormal.h"
     35#include "UIMachineView.h"
     36#include "UIMachineWindow.h"
    3237#include "UISession.h"
    33 #include "UIActionsPool.h"
    34 #include "UIMachineLogicNormal.h"
    35 #include "UIMachineWindow.h"
    36 #include "UIMachineView.h"
    3738
    3839#include "VBoxUtils.h"
     
    6566    /* Prepare normal machine window: */
    6667    prepareMachineWindows();
     68
     69    /* If there is an Additions download running show the process bar. */
     70    if (UIDownloaderAdditions *pDl = UIDownloaderAdditions::current())
     71        pDl->setParentWidget(mainMachineWindow()->machineWindow());
    6772
    6873#ifdef Q_WS_MAC
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp

    r27335 r27374  
    3131#include "VBoxGlobal.h"
    3232
    33 #include "UISession.h"
    3433#include "UIActionsPool.h"
     34#include "UIDownloaderAdditions.h"
    3535#include "UIIndicatorsPool.h"
    3636#include "UIMachineLogic.h"
    3737#include "UIMachineView.h"
    3838#include "UIMachineWindowNormal.h"
     39#include "UISession.h"
    3940
    4041#include "QIStatusBar.h"
     
    416417    statusBar()->addPermanentWidget(pIndicatorBox, 0);
    417418
     419    /* Add the additions downloader progress bar to the status bar, if a
     420     * download is actually running. */
     421    prepareAdditionsDownloader();
     422
    418423    /* Create & start timer to update LEDs: */
    419424    m_pIdleTimer = new QTimer(this);
     
    425430    setUnifiedTitleAndToolBarOnMac(true);
    426431#endif
     432}
     433
     434void UIMachineWindowNormal::prepareAdditionsDownloader()
     435{
     436    /* If there is an Additions download running show the process bar. */
     437    if (UIDownloaderAdditions *pDl = UIDownloaderAdditions::current())
     438        statusBar()->addWidget(pDl->processWidget(this), 0);
    427439}
    428440
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.h

    r27098 r27374  
    9191    void prepareMenu();
    9292    void prepareStatusBar();
     93    void prepareAdditionsDownloader();
    9394    void prepareConnections();
    9495    void prepareMachineView();
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIDownloader.cpp

    r27353 r27374  
    33 *
    44 * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VBoxDownloaderWgt class implementation
     5 * UIDownloader class implementation
    66 */
    77
    88/*
    9  * Copyright (C) 2006-2007 Sun Microsystems, Inc.
     9 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2222 */
    2323
     24/* Local includes */
     25#include "UIDownloader.h"
    2426#include "QIHttp.h"
    25 #include "VBoxDownloaderWgt.h"
    2627#include "VBoxGlobal.h"
    27 
    28 /* Qt includes */
     28#include "VBoxProblemReporter.h"
     29
     30/* Global includes */
    2931#include <QFile>
    30 #include <QHBoxLayout>
    31 #include <QHttpResponseHeader>
    3232#include <QProgressBar>
    33 #include <QToolButton>
    34 
    35 VBoxDownloaderWgt::VBoxDownloaderWgt (const QString &aSource, const QString &aTarget)
    36     : mSource (aSource), mTarget (aTarget), mHttp (0)
    37     , mProgressBar (new QProgressBar (this))
    38     , mCancelButton (new QToolButton (this))
     33
     34UIMiniProcessWidget::UIMiniProcessWidget(QWidget *pParent /* = 0 */)
     35    : QWidget(pParent)
     36    , m_pProgressBar(new QProgressBar(this))
     37    , m_pCancelButton(new QToolButton(this))
    3938{
    4039    /* Progress Bar setup */
    41     mProgressBar->setFixedWidth (100);
    42     mProgressBar->setFormat ("%p%");
    43     mProgressBar->setValue (0);
     40    m_pProgressBar->setFixedWidth(100);
     41    m_pProgressBar->setFormat("%p%");
     42    m_pProgressBar->setValue(0);
    4443
    4544    /* Cancel Button setup */
    46     mCancelButton->setAutoRaise (true);
    47     mCancelButton->setFocusPolicy (Qt::TabFocus);
    48     connect (mCancelButton, SIGNAL (clicked()), this, SLOT (cancelDownloading()));
    49 
    50     /* Downloader setup */
    51     setFixedHeight (16);
    52     QHBoxLayout *mainLayout = new QHBoxLayout (this);
    53     mainLayout->setSpacing (0);
    54     VBoxGlobal::setLayoutMargin (mainLayout, 0);
    55     mainLayout->addWidget (mProgressBar);
    56     mainLayout->addWidget (mCancelButton);
    57     mainLayout->addStretch (1);
    58 }
    59 
    60 void VBoxDownloaderWgt::start()
     45    m_pCancelButton->setAutoRaise(true);
     46    m_pCancelButton->setFocusPolicy(Qt::TabFocus);
     47    connect(m_pCancelButton, SIGNAL(clicked()),
     48            this, SIGNAL(sigCancel()));
     49
     50    /* Layout setup */
     51    setFixedHeight(16);
     52    QHBoxLayout *pMainLayout = new QHBoxLayout(this);
     53    pMainLayout->setSpacing(0);
     54    VBoxGlobal::setLayoutMargin(pMainLayout, 0);
     55    pMainLayout->addWidget(m_pProgressBar);
     56    pMainLayout->addWidget(m_pCancelButton);
     57    pMainLayout->addStretch(1);
     58}
     59
     60void UIMiniProcessWidget::setCancelButtonText(const QString &strText)
     61{
     62    m_pCancelButton->setText(strText);
     63}
     64
     65QString UIMiniProcessWidget::cancelButtonText() const
     66{
     67    return m_pCancelButton->text();
     68}
     69
     70void UIMiniProcessWidget::setCancelButtonToolTip(const QString &strText)
     71{
     72    m_pCancelButton->setToolTip(strText);
     73}
     74
     75QString UIMiniProcessWidget::cancelButtonToolTip() const
     76{
     77    return m_pCancelButton->toolTip();
     78}
     79
     80void UIMiniProcessWidget::setProgressBarToolTip(const QString &strText)
     81{
     82    m_pProgressBar->setToolTip(strText);
     83}
     84
     85QString UIMiniProcessWidget::progressBarToolTip() const
     86{
     87    return m_pProgressBar->toolTip();
     88}
     89
     90void UIMiniProcessWidget::setSource(const QString &strSource)
     91{
     92    m_strSource = strSource;
     93}
     94
     95QString UIMiniProcessWidget::source() const
     96{
     97    return m_strSource;
     98}
     99
     100void UIMiniProcessWidget::sltProcess(int cDone, int cTotal)
     101{
     102    m_pProgressBar->setMaximum(cTotal);
     103    m_pProgressBar->setValue(cDone);
     104}
     105
     106UIDownloader::UIDownloader()
     107    : m_pHttp(0)
     108{
     109}
     110
     111void UIDownloader::setSource(const QString &strSource)
     112{
     113    m_source = strSource;
     114}
     115
     116QString UIDownloader::source() const
     117{
     118    return m_source.toString();
     119}
     120
     121void UIDownloader::setTarget(const QString &strTarget)
     122{
     123    m_strTarget = strTarget;
     124}
     125
     126QString UIDownloader::target() const
     127{
     128    return m_strTarget;
     129}
     130
     131void UIDownloader::startDownload()
    61132{
    62133    /* By default we are not using acknowledging step, so
     
    67138/* This function is used to start acknowledging mechanism:
    68139 * checking file presence & size */
    69 void VBoxDownloaderWgt::acknowledgeStart()
    70 {
    71     delete mHttp;
    72     mHttp = new QIHttp (this, mSource.host());
    73     connect (mHttp, SIGNAL (responseHeaderReceived (const QHttpResponseHeader &)),
    74              this, SLOT (acknowledgeProcess (const QHttpResponseHeader &)));
    75     connect (mHttp, SIGNAL (allIsDone (bool)), this, SLOT (acknowledgeFinished (bool)));
    76     mHttp->get (mSource.toEncoded());
     140void UIDownloader::acknowledgeStart()
     141{
     142    delete m_pHttp;
     143    m_pHttp = new QIHttp(this, m_source.host());
     144    connect(m_pHttp, SIGNAL(responseHeaderReceived(const QHttpResponseHeader &)),
     145            this, SLOT(acknowledgeProcess(const QHttpResponseHeader &)));
     146    connect(m_pHttp, SIGNAL(allIsDone(bool)),
     147            this, SLOT(acknowledgeFinished(bool)));
     148    m_pHttp->get(m_source.toEncoded());
    77149}
    78150
    79151/* This function is used to store content length */
    80 void VBoxDownloaderWgt::acknowledgeProcess (const QHttpResponseHeader & /* aResponse */)
     152void UIDownloader::acknowledgeProcess(const QHttpResponseHeader & /* response */)
    81153{
    82154    /* Abort connection as we already got all we need */
    83     mHttp->abort();
     155    m_pHttp->abort();
    84156}
    85157
     
    87159 * to download file of proposed size if no error present or
    88160 * abort download progress if error is present */
    89 void VBoxDownloaderWgt::acknowledgeFinished (bool aError)
    90 {
    91     NOREF(aError);
    92 
    93     AssertMsg (aError, ("Error must be 'true' due to aborting.\n"));
    94 
    95     mHttp->disconnect (this);
    96 
    97     switch (mHttp->errorCode())
     161void UIDownloader::acknowledgeFinished(bool fError)
     162{
     163    NOREF(fError);
     164
     165    AssertMsg(fError, ("Error must be 'true' due to aborting.\n"));
     166
     167    m_pHttp->disconnect(this);
     168
     169    switch (m_pHttp->errorCode())
    98170    {
    99171        case QIHttp::Aborted:
     
    101173            /* Ask the user if he wish to download it */
    102174            if (confirmDownload())
    103                 QTimer::singleShot (0, this, SLOT (downloadStart()));
     175                QTimer::singleShot(0, this, SLOT(downloadStart()));
    104176            else
    105                 QTimer::singleShot (0, this, SLOT (suicide()));
     177                QTimer::singleShot(0, this, SLOT(suicide()));
    106178            break;
    107179        }
     
    110182        {
    111183            /* Restart downloading at new location */
    112             mSource = mHttp->lastResponse().value ("location");
    113             QTimer::singleShot (0, this, SLOT (acknowledgeStart()));
     184            m_source = m_pHttp->lastResponse().value("location");
     185            QTimer::singleShot(0, this, SLOT(acknowledgeStart()));
    114186            break;
    115187        }
     
    117189        {
    118190            /* Show error happens during acknowledging */
    119             abortDownload (mHttp->errorString());
     191            abortDownload(m_pHttp->errorString());
    120192            break;
    121193        }
     
    125197/* This function is used to start downloading mechanism:
    126198 * downloading and saving the target */
    127 void VBoxDownloaderWgt::downloadStart()
    128 {
    129     delete mHttp;
    130     mHttp = new QIHttp (this, mSource.host());
    131     connect (mHttp, SIGNAL (dataReadProgress (int, int)),
    132              this, SLOT (downloadProcess (int, int)));
    133     connect (mHttp, SIGNAL (allIsDone (bool)), this, SLOT (downloadFinished (bool)));
    134     mHttp->get (mSource.toEncoded());
     199void UIDownloader::downloadStart()
     200{
     201    delete m_pHttp;
     202    m_pHttp = new QIHttp(this, m_source.host());
     203    connect(m_pHttp, SIGNAL(dataReadProgress (int, int)),
     204            this, SLOT (downloadProcess(int, int)));
     205    connect(m_pHttp, SIGNAL(allIsDone(bool)),
     206            this, SLOT(downloadFinished(bool)));
     207    m_pHttp->get(m_source.toEncoded());
    135208}
    136209
    137210/* this function is used to observe the downloading progress through
    138211 * changing the corresponding qprogressbar value */
    139 void VBoxDownloaderWgt::downloadProcess (int aDone, int aTotal)
    140 {
    141     mProgressBar->setMaximum (aTotal);
    142     mProgressBar->setValue (aDone);
     212void UIDownloader::downloadProcess(int cDone, int cTotal)
     213{
     214    emit sigDownloadProcess(cDone, cTotal);
    143215}
    144216
     
    146218 * through saving the downloaded into the file if there in no error or
    147219 * notifying the user about error happens */
    148 void VBoxDownloaderWgt::downloadFinished (bool aError)
    149 {
    150     mHttp->disconnect (this);
    151 
    152     if (aError)
     220void UIDownloader::downloadFinished(bool fError)
     221{
     222    m_pHttp->disconnect(this);
     223
     224    if (fError)
    153225    {
    154226        /* Show information about error happens */
    155         if (mHttp->errorCode() == QIHttp::Aborted)
    156             abortDownload (tr ("The download process has been cancelled by the user."));
     227        if (m_pHttp->errorCode() == QIHttp::Aborted)
     228            abortDownload(tr("The download process has been canceled by the user."));
    157229        else
    158             abortDownload (mHttp->errorString());
     230            abortDownload(m_pHttp->errorString());
    159231    }
    160232    else
     
    162234        /* Trying to serialize the incoming buffer into the target, this is the
    163235         * default behavior which have to be reimplemented in sub-class */
    164         QFile file (mTarget);
    165         if (file.open (QIODevice::WriteOnly))
    166         {
    167             file.write (mHttp->readAll());
     236        QFile file(m_strTarget);
     237        if (file.open(QIODevice::WriteOnly))
     238        {
     239            file.write(m_pHttp->readAll());
    168240            file.close();
    169241        }
    170         QTimer::singleShot (0, this, SLOT (suicide()));
     242        QTimer::singleShot(0, this, SLOT(suicide()));
    171243    }
    172244}
    173245
    174246/* This slot is used to process cancel-button clicking */
    175 void VBoxDownloaderWgt::cancelDownloading()
    176 {
    177     QTimer::singleShot (0, this, SLOT (suicide()));
     247void UIDownloader::cancelDownloading()
     248{
     249    QTimer::singleShot(0, this, SLOT(suicide()));
    178250}
    179251
    180252/* This function is used to abort download by showing aborting reason
    181253 * and calling the downloader's delete function */
    182 void VBoxDownloaderWgt::abortDownload (const QString &aError)
    183 {
    184     warnAboutError (aError);
    185     QTimer::singleShot (0, this, SLOT (suicide()));
     254void UIDownloader::abortDownload(const QString &strError)
     255{
     256    warnAboutError(strError);
     257    QTimer::singleShot(0, this, SLOT(suicide()));
    186258}
    187259
    188260/* This function is used to delete the downloader widget itself,
    189  * should be reimplemented to enhanse necessary functionality in sub-class */
    190 void VBoxDownloaderWgt::suicide()
     261 * should be reimplemented to enhance necessary functionality in sub-class */
     262void UIDownloader::suicide()
    191263{
    192264    delete this;
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIDownloader.h

    r27353 r27374  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VBoxDownloaderWgt class declaration
     4 * UIDownloader class declaration
    55 */
    66
     
    2121 */
    2222
    23 #ifndef __VBoxDownloaderWgt_h__
    24 #define __VBoxDownloaderWgt_h__
     23#ifndef __UIDownloader_h__
     24#define __UIDownloader_h__
    2525
    26 #include "QIWithRetranslateUI.h"
    27 
    28 /* Qt includes */
     26/* Global includes */
    2927#include <QUrl>
    3028#include <QWidget>
    3129
     30/* Global forward declarations */
    3231class QIHttp;
    3332class QHttpResponseHeader;
     
    3534class QToolButton;
    3635
     36class UIMiniProcessWidget : public QWidget
     37{
     38    Q_OBJECT;
     39
     40public:
     41
     42    UIMiniProcessWidget(QWidget *pParent = 0);
     43
     44    void setCancelButtonText(const QString &strText);
     45    QString cancelButtonText() const;
     46
     47    void setCancelButtonToolTip(const QString &strText);
     48    QString cancelButtonToolTip() const;
     49
     50    void setProgressBarToolTip(const QString &strText);
     51    QString progressBarToolTip() const;
     52
     53    void setSource(const QString &strSource);
     54    QString source() const;
     55
     56signals:
     57
     58    void sigCancel();
     59
     60public slots:
     61
     62    virtual void sltProcess(int cDone, int cTotal);
     63
     64private:
     65
     66    /* Private member vars */
     67    QProgressBar *m_pProgressBar;
     68    QToolButton *m_pCancelButton;
     69    QString m_strSource;
     70};
     71
    3772/**
    38  * The VBoxDownloaderWgt class is QWidget class re-implementation which embeds
     73 * The UIDownloader class is QWidget class re-implementation which embeds
    3974 * into the Dialog's status-bar and allows background http downloading.
    4075 * This class is not supposed to be used itself and made for sub-classing only.
     
    4681 * the result of those parts itself.
    4782 */
    48 class VBoxDownloaderWgt : public QIWithRetranslateUI <QWidget>
     83class UIDownloader : public QObject
    4984{
    5085    Q_OBJECT;
     
    5287public:
    5388
    54     VBoxDownloaderWgt (const QString &aSource, const QString &aTarget);
     89    UIDownloader();
    5590
    56     virtual void start();
     91    void setSource(const QString &strSource);
     92    QString source() const;
     93    void setTarget(const QString &strTarget);
     94    QString target() const;
     95
     96    virtual void startDownload() = 0;
     97
     98signals:
     99    void sigDownloadProcess(int cDone, int cTotal);
     100    void sigFinished();
    57101
    58102protected slots:
     
    60104    /* Acknowledging part */
    61105    virtual void acknowledgeStart();
    62     virtual void acknowledgeProcess (const QHttpResponseHeader &aResponse);
    63     virtual void acknowledgeFinished (bool aError);
     106    virtual void acknowledgeProcess(const QHttpResponseHeader &response);
     107    virtual void acknowledgeFinished(bool fError);
    64108
    65109    /* Downloading part */
    66110    virtual void downloadStart();
    67     virtual void downloadProcess (int aDone, int aTotal);
    68     virtual void downloadFinished (bool aError);
     111    virtual void downloadProcess(int cDone, int cTotal);
     112    virtual void downloadFinished(bool fError);
    69113
    70114    /* Common slots */
    71115    virtual void cancelDownloading();
    72     virtual void abortDownload (const QString &aError);
     116    virtual void abortDownload(const QString &strError);
    73117    virtual void suicide();
    74118
     
    81125    /* In sub-class this function will show the user which error happens
    82126     * in context of downloading file and executing his request. */
    83     virtual void warnAboutError (const QString &aError) = 0;
     127    virtual void warnAboutError(const QString &strError) = 0;
    84128
    85     QUrl mSource;
    86     QString mTarget;
    87     QIHttp *mHttp;
    88     QProgressBar *mProgressBar;
    89     QToolButton *mCancelButton;
     129    QUrl m_source;
     130    QString m_strTarget;
     131    QIHttp *m_pHttp;
    90132};
    91133
    92 #endif // __VBoxDownloaderWgt_h__
     134#endif // __UIDownloader_h__
    93135
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIDownloaderAdditions.cpp

    r27353 r27374  
    33 *
    44 * VBox frontends: Qt GUI ("VirtualBox"):
    5  * VBoxConsoleWnd class implementation
     5 * UIDownloaderAdditions class implementation
    66 */
    77
     
    2222 */
    2323
     24/* Local includes */
     25#include "UIDownloaderAdditions.h"
     26#include "QIFileDialog.h"
     27#include "QIHttp.h"
     28#include "VBoxProblemReporter.h"
     29
    2430/* Global includes */
    25 #ifdef VBOX_WITH_PRECOMPILED_HEADERS
    26 # include "precomp.h"
    27 #else /* !VBOX_WITH_PRECOMPILED_HEADERS */
    28 #include <QActionGroup>
    29 #include <QDesktopWidget>
     31#include <QAction>
    3032#include <QDir>
    31 #include <QFileInfo>
    32 #include <QMenuBar>
    33 #include <QProgressBar>
    34 #include <QTimer>
     33#include <QFile>
     34UIDownloaderAdditions *UIDownloaderAdditions::m_pInstance = 0;
    3535
    36 #ifdef Q_WS_X11
    37 # include <QX11Info>
    38 #endif
    39 #ifdef Q_WS_MAC
    40 # include <QPainter>
    41 #endif
     36UIDownloaderAdditions *UIDownloaderAdditions::create()
     37{
     38    if (!m_pInstance)
     39        m_pInstance = new UIDownloaderAdditions;
    4240
    43 /* Local includes */
    44 #include "QIFileDialog.h"
    45 #include "QIHotKeyEdit.h"
    46 #include "QIHttp.h"
    47 #include "QIStateIndicator.h"
    48 #include "QIStatusBar.h"
    49 #include "QIWidgetValidator.h"
    50 #include "QIHotKeyEdit.h"
    51 #include "VBoxConsoleWnd.h"
    52 #include "VBoxConsoleView.h"
    53 #include "VBoxCloseVMDlg.h"
    54 #include "VBoxDownloaderWgt.h"
    55 #include "VBoxGlobal.h"
    56 #include "VBoxMediaManagerDlg.h"
    57 #include "VBoxMiniToolBar.h"
    58 #include "VBoxProblemReporter.h"
    59 #include "VBoxTakeSnapshotDlg.h"
    60 #include "UIFirstRunWzd.h"
    61 #include "VBoxVMSettingsNetwork.h"
    62 #include "VBoxVMSettingsSF.h"
    63 #include "VBoxVMInformationDlg.h"
    64 
    65 #ifdef Q_WS_X11
    66 # include <X11/Xlib.h>
    67 # include <XKeyboard.h>
    68 #endif
    69 #ifdef Q_WS_MAC
    70 # include "VBoxUtils.h"
    71 # include "VBoxIChatTheaterWrapper.h"
    72 # include <ApplicationServices/ApplicationServices.h>
    73 #endif
    74 #ifdef VBOX_WITH_DEBUGGER_GUI
    75 # include <VBox/err.h>
    76 # include <iprt/ldr.h>
    77 #endif
    78 
    79 #include <VBox/VMMDev.h> /** @todo @bugref{4084} */
    80 #include <iprt/buildconfig.h>
    81 #include <iprt/param.h>
    82 #include <iprt/path.h>
    83 #endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    84 
    85 /* Global forwards */
    86 extern void qt_set_sequence_auto_mnemonic (bool on);
    87 
    88 /** class StatusTipEvent
    89  *
    90  *  The StatusTipEvent class is an auxiliary QEvent class
    91  *  for carrying statusTip text of non-QAction menu item's.
    92  *  This event is posted then the menu item is highlighted but
    93  *  processed later in VBoxConsoleWnd::event() handler to
    94  *  avoid statusBar messaging collisions.
    95  */
    96 class StatusTipEvent : public QEvent
    97 {
    98 public:
    99     enum { Type = QEvent::User + 10 };
    100     StatusTipEvent (const QString &aTip)
    101         : QEvent ((QEvent::Type) Type), mTip (aTip) {}
    102 
    103     QString mTip;
    104 };
    105 
    106 class VBoxAdditionsDownloader : public VBoxDownloaderWgt
    107 {
    108     Q_OBJECT;
    109 
    110 public:
    111 
    112     VBoxAdditionsDownloader (const QString &aSource, const QString &aTarget, QAction *aAction)
    113         : VBoxDownloaderWgt (aSource, aTarget)
    114         , mAction (aAction)
    115     {
    116         mAction->setEnabled (false);
    117         retranslateUi();
    118     }
    119 
    120     void start()
    121     {
    122         acknowledgeStart();
    123     }
    124 
    125 protected:
    126 
    127     void retranslateUi()
    128     {
    129         mCancelButton->setText (tr ("Cancel"));
    130         mProgressBar->setToolTip (tr ("Downloading the VirtualBox Guest Additions "
    131                                       "CD image from <nobr><b>%1</b>...</nobr>")
    132                                       .arg (mSource.toString()));
    133         mCancelButton->setToolTip (tr ("Cancel the VirtualBox Guest "
    134                                        "Additions CD image download"));
    135     }
    136 
    137 private slots:
    138 
    139     void downloadFinished (bool aError)
    140     {
    141         if (aError)
    142             VBoxDownloaderWgt::downloadFinished (aError);
    143         else
    144         {
    145             QByteArray receivedData (mHttp->readAll());
    146             /* Serialize the incoming buffer into the .iso image. */
    147             while (true)
    148             {
    149                 QFile file (mTarget);
    150                 if (file.open (QIODevice::WriteOnly))
    151                 {
    152                     file.write (receivedData);
    153                     file.close();
    154                     if (vboxProblem().confirmMountAdditions (mSource.toString(),
    155                         QDir::toNativeSeparators (mTarget)))
    156                         vboxGlobal().consoleWnd().installGuestAdditionsFrom (mTarget);
    157                     QTimer::singleShot (0, this, SLOT (suicide()));
    158                     break;
    159                 }
    160                 else
    161                 {
    162                     vboxProblem().message (window(), VBoxProblemReporter::Error,
    163                         tr ("<p>Failed to save the downloaded file as "
    164                             "<nobr><b>%1</b>.</nobr></p>")
    165                         .arg (QDir::toNativeSeparators (mTarget)));
    166                 }
    167 
    168                 QString target = QIFileDialog::getExistingDirectory (
    169                     QFileInfo (mTarget).absolutePath(), this,
    170                     tr ("Select folder to save Guest Additions image to"), true);
    171                 if (target.isNull())
    172                     QTimer::singleShot (0, this, SLOT (suicide()));
    173                 else
    174                     mTarget = QDir (target).absoluteFilePath (QFileInfo (mTarget).fileName());
    175             }
    176         }
    177     }
    178 
    179     void suicide()
    180     {
    181         QStatusBar *sb = qobject_cast <QStatusBar*> (parent());
    182         Assert (sb);
    183         sb->removeWidget (this);
    184         mAction->setEnabled (true);
    185         VBoxDownloaderWgt::suicide();
    186     }
    187 
    188 private:
    189 
    190     bool confirmDownload()
    191     {
    192         return vboxProblem().confirmDownloadAdditions (mSource.toString(),
    193             mHttp->lastResponse().contentLength());
    194     }
    195 
    196     void warnAboutError (const QString &aError)
    197     {
    198         return vboxProblem().cannotDownloadGuestAdditions (mSource.toString(), aError);
    199     }
    200 
    201     QAction *mAction;
    202 };
    203 
    204 struct MountTarget
    205 {
    206     MountTarget() : name (QString ("")), port (0), device (0), id (QString()), type (VBoxDefs::MediumType_Invalid) {}
    207     MountTarget (const QString &aName, LONG aPort, LONG aDevice)
    208         : name (aName), port (aPort), device (aDevice), id (QString()), type (VBoxDefs::MediumType_Invalid) {}
    209     MountTarget (const QString &aName, LONG aPort, LONG aDevice, const QString &aId)
    210         : name (aName), port (aPort), device (aDevice), id (aId), type (VBoxDefs::MediumType_Invalid) {}
    211     MountTarget (const QString &aName, LONG aPort, LONG aDevice, VBoxDefs::MediumType aType)
    212         : name (aName), port (aPort), device (aDevice), id (QString()), type (aType) {}
    213     QString name;
    214     LONG port;
    215     LONG device;
    216     QString id;
    217     VBoxDefs::MediumType type;
    218 };
    219 Q_DECLARE_METATYPE (MountTarget);
    220 
    221 int searchMaxSnapshotIndex (const CMachine &aMachine, const CSnapshot &aSnapshot, const QString &aNameTemplate)
    222 {
    223     int maxIndex = 0;
    224     QRegExp regExp (QString ("^") + aNameTemplate.arg ("([0-9]+)") + QString ("$"));
    225     if (!aSnapshot.isNull())
    226     {
    227         /* Check the current snapshot name */
    228         QString name = aSnapshot.GetName();
    229         int pos = regExp.indexIn (name);
    230         if (pos != -1)
    231             maxIndex = regExp.cap (1).toInt() > maxIndex ? regExp.cap (1).toInt() : maxIndex;
    232         /* Traversing all the snapshot children */
    233         foreach (const CSnapshot &child, aSnapshot.GetChildren())
    234         {
    235             int maxIndexOfChildren = searchMaxSnapshotIndex (aMachine, child, aNameTemplate);
    236             maxIndex = maxIndexOfChildren > maxIndex ? maxIndexOfChildren : maxIndex;
    237         }
    238     }
    239     return maxIndex;
     41    return m_pInstance;
    24042}
    24143
    242 /** \class VBoxConsoleWnd
    243  *
    244  *  The VBoxConsoleWnd class is a VM console window, one of two main VBox
    245  *  GUI windows.
    246  *
    247  *  This window appears when the user starts the virtual machine. It
    248  *  contains the VBoxConsoleView widget that acts as a console of the
    249  *  running virtual machine.
    250  */
     44UIDownloaderAdditions *UIDownloaderAdditions::current()
     45{
     46    return m_pInstance;
     47}
    25148
    252 /**
    253  *  Constructs the VM console window.
    254  *
    255  *  @param aSelf pointer to a variable where to store |this| right after
    256  *               this object's constructor is called (necessary to avoid
    257  *               recursion in VBoxGlobal::consoleWnd())
    258  */
    259 VBoxConsoleWnd::VBoxConsoleWnd (VBoxConsoleWnd **aSelf, QWidget* aParent, Qt::WindowFlags aFlags /* = Qt::Window */)
    260     : QIWithRetranslateUI2 <QMainWindow> (aParent, aFlags)
    261     /* Machine State */
    262     , mMachineState (KMachineState_Null)
    263     /* Window Variables */
    264     , mConsoleStyle (0)
    265     /* Menu Items */
    266     , mMainMenu (0)
    267     , mVMMenu (0)
    268     , mVMMenuMini (0)
    269     , mDevicesMenu (0)
    270     , mDevicesCDMenu (0)
    271     , mDevicesFDMenu (0)
    272     , mDevicesNetworkMenu (0)
    273     , mDevicesSFMenu (0)
    274     , mDevicesUSBMenu (0)
    275     , mVmDisMouseIntegrMenu (0)
    276 #if 0 /* TODO: Allow to setup status-bar! */
    277     , mDevicesVRDPMenu (0)
    278     , mVmAutoresizeMenu (0)
    279 #endif
    280 #ifdef VBOX_WITH_DEBUGGER_GUI
    281     , mDbgMenu (0)
    282 #endif
    283     , mHelpMenu (0)
    284     /* Action Groups */
    285     , mRunningActions (0)
    286     , mRunningOrPausedActions (0)
    287     /* Machine Menu Actions */
    288     , mVmFullscreenAction (0)
    289     , mVmSeamlessAction (0)
    290     , mVmAutoresizeGuestAction (0)
    291     , mVmAdjustWindowAction (0)
    292     , mVmDisableMouseIntegrAction (0)
    293     , mVmTypeCADAction (0)
    294 #ifdef Q_WS_X11
    295     , mVmTypeCABSAction (0)
    296 #endif
    297     , mVmTakeSnapshotAction (0)
    298     , mVmShowInformationDlgAction (0)
    299     , mVmResetAction (0)
    300     , mVmPauseAction (0)
    301     , mVmACPIShutdownAction (0)
    302     , mVmCloseAction (0)
    303     /* Device Menu Actions */
    304     , mDevicesNetworkDialogAction (0)
    305     , mDevicesSFDialogAction (0)
    306     , mDevicesSwitchVrdpSeparator (0)
    307     , mDevicesSwitchVrdpAction (0)
    308     , mDevicesInstallGuestToolsAction (0)
    309 #ifdef VBOX_WITH_DEBUGGER_GUI
    310     /* Debug Menu Actions */
    311     , mDbgStatisticsAction (0)
    312     , mDbgCommandLineAction (0)
    313     , mDbgLoggingAction (0)
    314 #endif
    315     /* Widgets */
    316     , mConsole (0)
    317     , mMiniToolBar (0)
    318 #ifdef VBOX_WITH_DEBUGGER_GUI
    319     , mDbgGui (0)
    320     , mDbgGuiVT (0)
    321 #endif
    322     /* LED Update Timer */
    323     , mIdleTimer (new QTimer (this))
    324     /* LEDs */
    325     , mHDLed (0)
    326     , mCDLed (0)
    327 #if 0 /* TODO: Allow to setup status-bar! */
    328     , mFDLed (0)
    329 #endif
    330     , mNetLed (0)
    331     , mUSBLed (0)
    332     , mSFLed (0)
    333     , mVirtLed (0)
    334     , mMouseLed (0)
    335     , mHostkeyLed (0)
    336     , mHostkeyLedContainer (0)
    337     , mHostkeyName (0)
    338 #if 0 /* TODO: Allow to setup status-bar! */
    339     , mVrdpLed (0)
    340     , mAutoresizeLed (0)
    341 #endif
    342     , mIsOpenViewFinished (false)
    343     , mIsFirstTimeStarted (false)
    344     , mIsAutoSaveMedia (true)
    345     , mNoAutoClose (false)
    346     , mIsFullscreen (false)
    347     , mIsSeamless (false)
    348     , mIsSeamlessSupported (false)
    349     , mIsGraphicsSupported (false)
    350     , mIsWaitingModeResize (false)
    351     , mWasMax (false)
     49void UIDownloaderAdditions::destroy()
    35250{
    353 #ifdef DEBUG_poetzsch
    354     printf("Old code path\n");
    355 #endif /* DEBUG_poetzsch */
    356     if (aSelf)
    357         *aSelf = this;
     51    if (m_pInstance)
     52        delete m_pInstance;
     53    m_pInstance = 0;
     54}
    35855
    359     vboxGlobal().setMainWindow (this);
     56void UIDownloaderAdditions::setAction(QAction *pAction)
     57{
     58    m_pAction = pAction;
     59    if (m_pAction)
     60        m_pAction->setEnabled(false);
     61}
    36062
    361     /* Cache IMedium data! */
    362     vboxGlobal().startEnumeratingMedia();
     63QAction *UIDownloaderAdditions::action() const
     64{
     65    return m_pAction;
     66}
    36367
    364 #if !(defined (Q_WS_WIN) || defined (Q_WS_MAC))
    365     /* The default application icon (will change to the VM-specific icon in
    366      * openView()). On Win32, it's built-in to the executable. On Mac OS X the
    367      * icon referenced in info.plist is used. */
    368     setWindowIcon (QIcon (":/VirtualBox_48px.png"));
    369 #endif
     68void UIDownloaderAdditions::setParentWidget(QWidget *pParent)
     69{
     70    m_pParent = pParent;
     71}
    37072
    371     /* Ensure status bar is created */
    372     setStatusBar (new QIStatusBar (this));
     73QWidget *UIDownloaderAdditions::parentWidget() const
     74{
     75    return m_pParent;
     76}
    37377
    374     /* A group for all actions that are enabled only when the VM is running.
    375      * Note that only actions whose enabled state depends exclusively on the
    376      * execution state of the VM are added to this group. */
    377     mRunningActions = new QActionGroup (this);
    378     mRunningActions->setExclusive (false);
     78UIMiniProcessWidgetAdditions* UIDownloaderAdditions::processWidget(QWidget *pParent /* = 0 */) const
     79{
     80    UIMiniProcessWidgetAdditions *pWidget = new UIMiniProcessWidgetAdditions(m_source.toString(), pParent);
    37981
    380     /* A group for all actions that are enabled when the VM is running or
    381      * paused. Note that only actions whose enabled state depends exclusively
    382      * on the execution state of the VM are added to this group. */
    383     mRunningOrPausedActions = new QActionGroup (this);
    384     mRunningOrPausedActions->setExclusive (false);
     82    /* Connect the cancel signal. */
     83    connect(pWidget, SIGNAL(sigCancel()),
     84            this, SLOT(cancelDownloading()));
     85    /* Connect the signal to notify about the download process. */
     86    connect(this, SIGNAL(sigDownloadProcess(int, int)),
     87            pWidget, SLOT(sltProcess(int, int)));
     88    /* Make sure the widget is destroyed when this class is deleted. */
     89    connect(this, SIGNAL(destroyed(QObject*)),
     90            pWidget, SLOT(close()));
    38591
    386     /* VM menu actions */
    387     mVmFullscreenAction = new QAction (this);
    388     mVmFullscreenAction->setIcon (VBoxGlobal::iconSetOnOff (
    389         ":/fullscreen_on_16px.png", ":/fullscreen_16px.png",
    390         ":/fullscreen_on_disabled_16px.png", ":/fullscreen_disabled_16px.png"));
    391     mVmFullscreenAction->setCheckable (true);
     92    return pWidget;
     93}
    39294
    393     mVmSeamlessAction = new QAction (this);
    394     mVmSeamlessAction->setIcon (VBoxGlobal::iconSetOnOff (
    395         ":/seamless_on_16px.png", ":/seamless_16px.png",
    396         ":/seamless_on_disabled_16px.png", ":/seamless_disabled_16px.png"));
    397     mVmSeamlessAction->setCheckable (true);
     95void UIDownloaderAdditions::startDownload()
     96{
     97    acknowledgeStart();
     98}
    39899
    399     mVmAutoresizeGuestAction = new QAction (mRunningActions);
    400     mVmAutoresizeGuestAction->setIcon (VBoxGlobal::iconSetOnOff (
    401         ":/auto_resize_on_on_16px.png", ":/auto_resize_on_16px.png",
    402         ":/auto_resize_on_on_disabled_16px.png", ":/auto_resize_on_disabled_16px.png"));
    403     mVmAutoresizeGuestAction->setCheckable (true);
    404     mVmAutoresizeGuestAction->setEnabled (false);
    405 
    406     mVmAdjustWindowAction = new QAction (this);
    407     mVmAdjustWindowAction->setIcon (VBoxGlobal::iconSet (
    408         ":/adjust_win_size_16px.png", ":/adjust_win_size_disabled_16px.png"));
    409 
    410     mVmDisableMouseIntegrAction = new QAction (this);
    411     mVmDisableMouseIntegrAction->setIcon (VBoxGlobal::iconSetOnOff (
    412         ":/mouse_can_seamless_on_16px.png", ":/mouse_can_seamless_16px.png",
    413         ":/mouse_can_seamless_on_disabled_16px.png", ":/mouse_can_seamless_disabled_16px.png"));
    414     mVmDisableMouseIntegrAction->setCheckable (true);
    415 
    416     mVmTypeCADAction = new QAction (mRunningActions);
    417     mVmTypeCADAction->setIcon (VBoxGlobal::iconSet (
    418         ":/hostkey_16px.png", ":/hostkey_disabled_16px.png"));
    419 
    420 #if defined(Q_WS_X11)
    421     mVmTypeCABSAction = new QAction (mRunningActions);
    422     mVmTypeCABSAction->setIcon (VBoxGlobal::iconSet (
    423         ":/hostkey_16px.png", ":/hostkey_disabled_16px.png"));
    424 #endif
    425 
    426     mVmTakeSnapshotAction = new QAction (mRunningOrPausedActions);
    427     mVmTakeSnapshotAction->setIcon (VBoxGlobal::iconSet (
    428         ":/take_snapshot_16px.png", ":/take_snapshot_dis_16px.png"));
    429 
    430     mVmShowInformationDlgAction = new QAction (this);
    431     mVmShowInformationDlgAction->setIcon (VBoxGlobal::iconSet (
    432         ":/session_info_16px.png", ":/session_info_disabled_16px.png"));
    433 
    434     mVmResetAction = new QAction (mRunningActions);
    435     mVmResetAction->setIcon (VBoxGlobal::iconSet (
    436         ":/reset_16px.png", ":/reset_disabled_16px.png"));
    437 
    438     mVmPauseAction = new QAction (this);
    439     mVmPauseAction->setIcon (VBoxGlobal::iconSet (
    440         ":/pause_16px.png", ":/pause_disabled_16px.png"));
    441     mVmPauseAction->setCheckable (true);
    442 
    443     mVmACPIShutdownAction = new QAction (mRunningActions);
    444     mVmACPIShutdownAction->setIcon (VBoxGlobal::iconSet (
    445         ":/acpi_16px.png", ":/acpi_disabled_16px.png"));
    446 
    447     mVmCloseAction = new QAction (this);
    448     mVmCloseAction->setMenuRole (QAction::QuitRole);
    449     mVmCloseAction->setIcon (VBoxGlobal::iconSet (":/exit_16px.png"));
    450 
    451     /* Devices menu actions */
    452     mDevicesNetworkDialogAction = new QAction (mRunningOrPausedActions);
    453     mDevicesNetworkDialogAction->setIcon (VBoxGlobal::iconSet (
    454         ":/nw_16px.png", ":/nw_disabled_16px.png"));
    455 
    456     mDevicesSFDialogAction = new QAction (mRunningOrPausedActions);
    457     mDevicesSFDialogAction->setIcon (VBoxGlobal::iconSet (
    458         ":/shared_folder_16px.png", ":/shared_folder_disabled_16px.png"));
    459 
    460     mDevicesSwitchVrdpAction = new QAction (mRunningOrPausedActions);
    461     mDevicesSwitchVrdpAction->setIcon (VBoxGlobal::iconSetOnOff (
    462         ":/vrdp_on_16px.png", ":/vrdp_16px.png",
    463         ":/vrdp_on_disabled_16px.png", ":/vrdp_disabled_16px.png"));
    464     mDevicesSwitchVrdpAction->setCheckable (true);
    465 
    466     mDevicesInstallGuestToolsAction = new QAction (mRunningActions);
    467     mDevicesInstallGuestToolsAction->setIcon (VBoxGlobal::iconSet (
    468         ":/guesttools_16px.png", ":/guesttools_disabled_16px.png"));
    469 
    470 #ifdef VBOX_WITH_DEBUGGER_GUI
    471     /* Debug menu actions */
    472     if (vboxGlobal().isDebuggerEnabled())
    473     {
    474         mDbgStatisticsAction = new QAction (this);
    475         mDbgCommandLineAction = new QAction (this);
    476         if (vboxGlobal().getDebuggerModule()== NIL_RTLDRMOD)
    477         {
    478             mDbgStatisticsAction->setEnabled (false);
    479             mDbgCommandLineAction->setEnabled (false);
    480         }
    481         mDbgLoggingAction = new QAction (this);
    482         mDbgLoggingAction->setCheckable (true);
    483     }
     100void UIDownloaderAdditions::downloadFinished(bool fError)
     101{
     102    if (fError)
     103        UIDownloader::downloadFinished(fError);
    484104    else
    485105    {
    486         mDbgStatisticsAction = 0;
    487         mDbgCommandLineAction = 0;
    488         mDbgLoggingAction = 0;
    489     }
    490 #endif
     106        QByteArray receivedData(m_pHttp->readAll());
     107        /* Serialize the incoming buffer into the .iso image. */
     108        while (true)
     109        {
     110            QFile file(m_strTarget);
     111            if (file.open(QIODevice::WriteOnly))
     112            {
     113                file.write(receivedData);
     114                file.close();
     115                if (vboxProblem().confirmMountAdditions(m_source.toString(),
     116                                                        QDir::toNativeSeparators(m_strTarget)))
     117                    emit downloadFinished(m_strTarget);
     118                QTimer::singleShot(0, this, SLOT(suicide()));
     119                break;
     120            }
     121            else
     122            {
     123                vboxProblem().message(m_pParent, VBoxProblemReporter::Error,
     124                                      tr("<p>Failed to save the downloaded file as "
     125                                         "<nobr><b>%1</b>.</nobr></p>")
     126                                      .arg(QDir::toNativeSeparators(m_strTarget)));
     127            }
    491128
    492     /* Help menu actions */
    493     mHelpActions.setup (this);
    494 
    495     /* Menu Items */
    496     mMainMenu = new QIMenu (this);
    497     mDevicesCDMenu = new QMenu (this);
    498     mDevicesFDMenu = new QMenu (this);
    499     mDevicesNetworkMenu = new QMenu (this);
    500     mDevicesSFMenu = new QMenu (this);
    501     mDevicesUSBMenu = new VBoxUSBMenu (this);
    502 
    503     /* Machine submenu */
    504     mVMMenu = menuBar()->addMenu (QString::null);
    505     mMainMenu->addMenu (mVMMenu);
    506     mVmDisMouseIntegrMenu = new VBoxSwitchMenu (mVMMenu, mVmDisableMouseIntegrAction, true);
    507 #if 0 /* TODO: Allow to setup status-bar! */
    508     mVmAutoresizeMenu = new VBoxSwitchMenu (mVMMenu, mVmAutoresizeGuestAction);
    509 #endif
    510 
    511     mVMMenu->addAction (mVmFullscreenAction);
    512     mVMMenu->addAction (mVmSeamlessAction);
    513     mVMMenu->addAction (mVmAutoresizeGuestAction);
    514     mVMMenu->addAction (mVmAdjustWindowAction);
    515     mVMMenu->addSeparator();
    516     mVMMenu->addAction (mVmDisableMouseIntegrAction);
    517     mVMMenu->addSeparator();
    518     mVMMenu->addAction (mVmTypeCADAction);
    519 #ifdef Q_WS_X11
    520     mVMMenu->addAction (mVmTypeCABSAction);
    521 #endif
    522     mVMMenu->addSeparator();
    523     mVMMenu->addAction (mVmTakeSnapshotAction);
    524     mVMMenu->addSeparator();
    525     mVMMenu->addAction (mVmShowInformationDlgAction);
    526     mVMMenu->addSeparator();
    527     mVMMenu->addAction (mVmResetAction);
    528     mVMMenu->addAction (mVmPauseAction);
    529     mVMMenu->addAction (mVmACPIShutdownAction);
    530 #ifndef Q_WS_MAC
    531     mVMMenu->addSeparator();
    532 #endif /* Q_WS_MAC */
    533     mVMMenu->addAction (mVmCloseAction);
    534 
    535     /* Devices submenu */
    536     mDevicesMenu = menuBar()->addMenu (QString::null);
    537     mMainMenu->addMenu (mDevicesMenu);
    538 
    539     mDevicesCDMenu->setIcon (VBoxGlobal::iconSet (":/cd_16px.png", ":/cd_disabled_16px.png"));
    540     mDevicesFDMenu->setIcon (VBoxGlobal::iconSet (":/fd_16px.png", ":/fd_disabled_16px.png"));
    541     mDevicesUSBMenu->setIcon (VBoxGlobal::iconSet (":/usb_16px.png", ":/usb_disabled_16px.png"));
    542 
    543     mDevicesMenu->addMenu (mDevicesCDMenu);
    544     mDevicesMenu->addMenu (mDevicesFDMenu);
    545     mDevicesMenu->addAction (mDevicesNetworkDialogAction);
    546     mDevicesMenu->addAction (mDevicesSFDialogAction);
    547     mDevicesMenu->addMenu (mDevicesUSBMenu);
    548 
    549 #if 0 /* TODO: Allow to setup status-bar! */
    550     mDevicesVRDPMenu = new VBoxSwitchMenu (mDevicesMenu, mDevicesSwitchVrdpAction);
    551 #endif
    552     mDevicesSwitchVrdpSeparator = mDevicesMenu->addSeparator();
    553     mDevicesMenu->addAction (mDevicesSwitchVrdpAction);
    554 
    555     mDevicesMenu->addSeparator();
    556     mDevicesMenu->addAction (mDevicesInstallGuestToolsAction);
    557 
    558 #ifdef VBOX_WITH_DEBUGGER_GUI
    559     /* Debug submenu */
    560     if (vboxGlobal().isDebuggerEnabled())
    561     {
    562         mDbgMenu = menuBar()->addMenu (QString::null);
    563         mMainMenu->addMenu (mDbgMenu);
    564         mDbgMenu->addAction (mDbgStatisticsAction);
    565         mDbgMenu->addAction (mDbgCommandLineAction);
    566         mDbgMenu->addAction (mDbgLoggingAction);
    567     }
    568     else
    569         mDbgMenu = 0;
    570 #endif
    571 
    572     /* Help submenu */
    573     mHelpMenu = menuBar()->addMenu (QString::null);
    574     mMainMenu->addMenu (mHelpMenu);
    575     mHelpActions.addTo (mHelpMenu);
    576 
    577     /* Machine submenu for mini-toolbar */
    578     mVMMenuMini = new QMenu (this);
    579     mVMMenuMini->addAction (mVmTypeCADAction);
    580 #ifdef Q_WS_X11
    581     mVMMenuMini->addAction (mVmTypeCABSAction);
    582 #endif
    583     mVMMenuMini->addSeparator();
    584     mVMMenuMini->addAction (mVmTakeSnapshotAction);
    585     mVMMenuMini->addSeparator();
    586     mVMMenuMini->addAction (mVmShowInformationDlgAction);
    587     mVMMenuMini->addSeparator();
    588     mVMMenuMini->addAction (mVmResetAction);
    589     mVMMenuMini->addAction (mVmPauseAction);
    590     mVMMenuMini->addAction (mVmACPIShutdownAction);
    591 
    592     /* Status bar */
    593     QWidget *indicatorBox = new QWidget;
    594     QHBoxLayout *indicatorBoxHLayout = new QHBoxLayout (indicatorBox);
    595     VBoxGlobal::setLayoutMargin (indicatorBoxHLayout, 0);
    596     indicatorBoxHLayout->setSpacing (5);
    597 
    598     /* i/o devices */
    599     mHDLed = new QIStateIndicator (KDeviceActivity_Idle);
    600     mHDLed->setStateIcon (KDeviceActivity_Idle, QPixmap (":/hd_16px.png"));
    601     mHDLed->setStateIcon (KDeviceActivity_Reading, QPixmap (":/hd_read_16px.png"));
    602     mHDLed->setStateIcon (KDeviceActivity_Writing, QPixmap (":/hd_write_16px.png"));
    603     mHDLed->setStateIcon (KDeviceActivity_Null, QPixmap (":/hd_disabled_16px.png"));
    604     indicatorBoxHLayout->addWidget (mHDLed);
    605     mCDLed = new QIStateIndicator (KDeviceActivity_Idle);
    606     mCDLed->setStateIcon (KDeviceActivity_Idle, QPixmap (":/cd_16px.png"));
    607     mCDLed->setStateIcon (KDeviceActivity_Reading, QPixmap (":/cd_read_16px.png"));
    608     mCDLed->setStateIcon (KDeviceActivity_Writing, QPixmap (":/cd_write_16px.png"));
    609     mCDLed->setStateIcon (KDeviceActivity_Null, QPixmap (":/cd_disabled_16px.png"));
    610     indicatorBoxHLayout->addWidget (mCDLed);
    611 #if 0 /* TODO: Allow to setup status-bar! */
    612     mFDLed = new QIStateIndicator (KDeviceActivity_Idle);
    613     mFDLed->setStateIcon (KDeviceActivity_Idle, QPixmap (":/fd_16px.png"));
    614     mFDLed->setStateIcon (KDeviceActivity_Reading, QPixmap (":/fd_read_16px.png"));
    615     mFDLed->setStateIcon (KDeviceActivity_Writing, QPixmap (":/fd_write_16px.png"));
    616     mFDLed->setStateIcon (KDeviceActivity_Null, QPixmap (":/fd_disabled_16px.png"));
    617     indicatorBoxHLayout->addWidget (mFDLed);
    618 #endif
    619     mNetLed = new QIStateIndicator (KDeviceActivity_Idle);
    620     mNetLed->setStateIcon (KDeviceActivity_Idle, QPixmap (":/nw_16px.png"));
    621     mNetLed->setStateIcon (KDeviceActivity_Reading, QPixmap (":/nw_read_16px.png"));
    622     mNetLed->setStateIcon (KDeviceActivity_Writing, QPixmap (":/nw_write_16px.png"));
    623     mNetLed->setStateIcon (KDeviceActivity_Null, QPixmap (":/nw_disabled_16px.png"));
    624     indicatorBoxHLayout->addWidget (mNetLed);
    625     mUSBLed = new QIStateIndicator (KDeviceActivity_Idle);
    626     mUSBLed->setStateIcon (KDeviceActivity_Idle, QPixmap (":/usb_16px.png"));
    627     mUSBLed->setStateIcon (KDeviceActivity_Reading, QPixmap (":/usb_read_16px.png"));
    628     mUSBLed->setStateIcon (KDeviceActivity_Writing, QPixmap (":/usb_write_16px.png"));
    629     mUSBLed->setStateIcon (KDeviceActivity_Null, QPixmap (":/usb_disabled_16px.png"));
    630     indicatorBoxHLayout->addWidget (mUSBLed);
    631     mSFLed = new QIStateIndicator (KDeviceActivity_Idle);
    632     mSFLed->setStateIcon (KDeviceActivity_Idle, QPixmap (":/shared_folder_16px.png"));
    633     mSFLed->setStateIcon (KDeviceActivity_Reading, QPixmap (":/shared_folder_read_16px.png"));
    634     mSFLed->setStateIcon (KDeviceActivity_Writing, QPixmap (":/shared_folder_write_16px.png"));
    635     mSFLed->setStateIcon (KDeviceActivity_Null, QPixmap (":/shared_folder_disabled_16px.png"));
    636     indicatorBoxHLayout->addWidget (mSFLed);
    637 
    638     /* virtualization */
    639     mVirtLed = new QIStateIndicator (0);
    640     mVirtLed->setStateIcon (0, QPixmap (":/vtx_amdv_disabled_16px.png"));
    641     mVirtLed->setStateIcon (1, QPixmap (":/vtx_amdv_16px.png"));
    642     indicatorBoxHLayout->addWidget (mVirtLed);
    643 
    644     QFrame *separator = new QFrame();
    645     separator->setFrameStyle (QFrame::VLine | QFrame::Sunken);
    646     indicatorBoxHLayout->addWidget (separator);
    647 
    648     /* mouse */
    649     mMouseLed = new QIStateIndicator (0);
    650     mMouseLed->setStateIcon (0, QPixmap (":/mouse_disabled_16px.png"));
    651     mMouseLed->setStateIcon (1, QPixmap (":/mouse_16px.png"));
    652     mMouseLed->setStateIcon (2, QPixmap (":/mouse_seamless_16px.png"));
    653     mMouseLed->setStateIcon (3, QPixmap (":/mouse_can_seamless_16px.png"));
    654     mMouseLed->setStateIcon (4, QPixmap (":/mouse_can_seamless_uncaptured_16px.png"));
    655     indicatorBoxHLayout->addWidget (mMouseLed);
    656 
    657     /* host key */
    658     mHostkeyLedContainer = new QWidget;
    659     QHBoxLayout *hostkeyLEDContainerLayout = new QHBoxLayout (mHostkeyLedContainer);
    660     VBoxGlobal::setLayoutMargin (hostkeyLEDContainerLayout, 0);
    661     hostkeyLEDContainerLayout->setSpacing (3);
    662     indicatorBoxHLayout->addWidget (mHostkeyLedContainer);
    663 
    664     mHostkeyLed = new QIStateIndicator (0);
    665     mHostkeyLed->setStateIcon (0, QPixmap (":/hostkey_16px.png"));
    666     mHostkeyLed->setStateIcon (1, QPixmap (":/hostkey_captured_16px.png"));
    667     mHostkeyLed->setStateIcon (2, QPixmap (":/hostkey_pressed_16px.png"));
    668     mHostkeyLed->setStateIcon (3, QPixmap (":/hostkey_captured_pressed_16px.png"));
    669     hostkeyLEDContainerLayout->addWidget (mHostkeyLed);
    670     mHostkeyName = new QLabel (QIHotKeyEdit::keyName (vboxGlobal().settings().hostKey()));
    671     hostkeyLEDContainerLayout->addWidget (mHostkeyName);
    672 
    673 #if 0 /* TODO: Allow to setup status-bar! */
    674     /* VRDP Led */
    675     mVrdpLed = new QIStateIndicator (0, indicatorBox, "mVrdpLed", Qt::WNoAutoErase);
    676     mVrdpLed->setStateIcon (0, QPixmap (":/vrdp_disabled_16px.png"));
    677     mVrdpLed->setStateIcon (1, QPixmap (":/vrdp_16px.png"));
    678     /* Auto-Resize LED */
    679     mAutoresizeLed = new QIStateIndicator (1, indicatorBox, "mAutoresizeLed", Qt::WNoAutoErase);
    680     mAutoresizeLed->setStateIcon (0, QPixmap (":/auto_resize_off_disabled_16px.png"));
    681     mAutoresizeLed->setStateIcon (1, QPixmap (":/auto_resize_off_16px.png"));
    682     mAutoresizeLed->setStateIcon (2, QPixmap (":/auto_resize_on_disabled_16px.png"));
    683     mAutoresizeLed->setStateIcon (3, QPixmap (":/auto_resize_on_16px.png"));
    684 #endif
    685 
    686 #ifdef Q_WS_MAC
    687     m_pDockMenu = new QMenu(this);
    688     /* Add all VM menu entries to the dock menu. Leave out close and stuff like
    689      * this. */
    690     QList<QAction*> actions = mVMMenu->actions();
    691     for (int i=0; i < actions.size(); ++i)
    692         if (actions.at(i)->menuRole() == QAction::TextHeuristicRole)
    693             m_pDockMenu->addAction(actions.at(i));
    694     m_pDockMenu->addSeparator();
    695 
    696     m_pDockSettingsMenu = new QMenu(this);
    697     QActionGroup *pDockPreviewModeGroup = new QActionGroup(this);
    698     m_pDockEnablePreviewMonitor = new QAction(pDockPreviewModeGroup);
    699     m_pDockEnablePreviewMonitor->setCheckable(true);
    700     m_pDockDisablePreview = new QAction(pDockPreviewModeGroup);
    701     m_pDockDisablePreview->setCheckable(true);
    702     m_pDockSettingsMenu->addActions(pDockPreviewModeGroup->actions());
    703 
    704     m_pDockMenu->addMenu(m_pDockSettingsMenu);
    705 
    706     /* Add it to the dock. */
    707     extern void qt_mac_set_dock_menu(QMenu *);
    708     qt_mac_set_dock_menu(m_pDockMenu);
    709 #endif /* Q_WS_MAC */
    710 
    711     /* add to statusbar */
    712     statusBar()->addPermanentWidget (indicatorBox, 0);
    713 
    714     /* Retranslate UI */
    715     retranslateUi();
    716 
    717     setWindowTitle (mCaptionPrefix);
    718 
    719     /* Connections */
    720     connect (mVmFullscreenAction, SIGNAL (toggled (bool)), this, SLOT (vmFullscreen (bool)));
    721     connect (mVmSeamlessAction, SIGNAL (toggled (bool)), this, SLOT (vmSeamless (bool)));
    722     connect (mVmAutoresizeGuestAction, SIGNAL (toggled (bool)), this, SLOT (vmAutoresizeGuest (bool)));
    723     connect (mVmAdjustWindowAction, SIGNAL (triggered()), this, SLOT (vmAdjustWindow()));
    724     connect (mVmDisableMouseIntegrAction, SIGNAL (toggled (bool)), this, SLOT (vmDisableMouseIntegration (bool)));
    725     connect (mVmTypeCADAction, SIGNAL (triggered()), this, SLOT (vmTypeCAD()));
    726 #ifdef Q_WS_X11
    727     connect (mVmTypeCABSAction, SIGNAL (triggered()), this, SLOT (vmTypeCABS()));
    728 #endif
    729     connect (mVmTakeSnapshotAction, SIGNAL (triggered()), this, SLOT (vmTakeSnapshot()));
    730     connect (mVmShowInformationDlgAction, SIGNAL (triggered()), this, SLOT (vmShowInfoDialog()));
    731     connect (mVmResetAction, SIGNAL (triggered()), this, SLOT (vmReset()));
    732     connect (mVmPauseAction, SIGNAL (toggled (bool)), this, SLOT (vmPause (bool)));
    733     connect (mVmACPIShutdownAction, SIGNAL (triggered()), this, SLOT (vmACPIShutdown()));
    734     connect (mVmCloseAction, SIGNAL (triggered()), this, SLOT (vmClose()));
    735 
    736     connect (mDevicesCDMenu, SIGNAL (aboutToShow()), this, SLOT (prepareStorageMenu()));
    737     connect (mDevicesFDMenu, SIGNAL (aboutToShow()), this, SLOT (prepareStorageMenu()));
    738     connect (mDevicesNetworkMenu, SIGNAL (aboutToShow()), this, SLOT (prepareNetworkMenu()));
    739     connect (mDevicesSFMenu, SIGNAL (aboutToShow()), this, SLOT (prepareSFMenu()));
    740     connect (mDevicesUSBMenu, SIGNAL(triggered (QAction *)), this, SLOT(switchUSB (QAction *)));
    741 
    742     connect (mDevicesNetworkDialogAction, SIGNAL (triggered()), this, SLOT (devicesOpenNetworkDialog()));
    743     connect (mDevicesSFDialogAction, SIGNAL (triggered()), this, SLOT (devicesOpenSFDialog()));
    744     connect (mDevicesSwitchVrdpAction, SIGNAL (toggled (bool)), this, SLOT (devicesSwitchVrdp (bool)));
    745     connect (mDevicesInstallGuestToolsAction, SIGNAL (triggered()), this, SLOT (devicesInstallGuestAdditions()));
    746 
    747     connect (mCDLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    748              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    749 #if 0 /* TODO: Allow to setup status-bar! */
    750     connect (mFDLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    751              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    752 #endif
    753     connect (mNetLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    754              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    755     connect (mUSBLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    756              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    757     connect (mSFLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    758              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    759     connect (mMouseLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    760              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    761 #if 0 /* TODO: Allow to setup status-bar! */
    762     connect (mVrdpLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    763              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    764     connect (mAutoresizeLed, SIGNAL (contextMenuRequested (QIStateIndicator *, QContextMenuEvent *)),
    765              this, SLOT (showIndicatorContextMenu (QIStateIndicator *, QContextMenuEvent *)));
    766 #endif
    767 
    768     /* Watch global settings changes */
    769     connect (&vboxGlobal().settings(), SIGNAL (propertyChanged (const char *, const char *)),
    770              this, SLOT (processGlobalSettingChange (const char *, const char *)));
    771 #ifdef Q_WS_MAC
    772     connect(pDockPreviewModeGroup, SIGNAL(triggered(QAction*)),
    773             this, SLOT(sltDockPreviewModeChanged(QAction*)));
    774     connect (&vboxGlobal(), SIGNAL (dockIconUpdateChanged (const VBoxChangeDockIconUpdateEvent &)),
    775              this, SLOT (changeDockIconUpdate (const VBoxChangeDockIconUpdateEvent &)));
    776     connect (&vboxGlobal(), SIGNAL (presentationModeChanged (const VBoxChangePresentationModeEvent &)),
    777              this, SLOT (changePresentationMode (const VBoxChangePresentationModeEvent &)));
    778 #endif
    779 
    780 #ifdef VBOX_WITH_DEBUGGER_GUI
    781     if (mDbgMenu)
    782         connect (mDbgMenu, SIGNAL (aboutToShow()), this, SLOT (dbgPrepareDebugMenu()));
    783     if (mDbgStatisticsAction)
    784         connect (mDbgStatisticsAction, SIGNAL (triggered()), this, SLOT (dbgShowStatistics()));
    785     if (mDbgCommandLineAction)
    786         connect (mDbgCommandLineAction, SIGNAL (triggered()), this, SLOT (dbgShowCommandLine()));
    787     if (mDbgLoggingAction)
    788         connect (mDbgLoggingAction, SIGNAL (toggled (bool)), this, SLOT (dbgLoggingToggled (bool)));
    789 #endif
    790 
    791 #ifdef Q_WS_MAC
    792     /* For the status bar on Cocoa */
    793     setUnifiedTitleAndToolBarOnMac (true);
    794 # ifdef VBOX_WITH_ICHAT_THEATER
    795     // int setAttr[] = { kHIWindowBitDoesNotShowBadgeInDock, 0 };
    796     // HIWindowChangeAttributes (window, setAttr, 0);
    797     initSharedAVManager();
    798 # endif
    799 #endif
    800 
    801     mMaskShift.scale (0, 0, Qt::IgnoreAspectRatio);
    802 }
    803 
    804 VBoxConsoleWnd::~VBoxConsoleWnd()
    805 {
    806     closeView();
    807 
    808 #ifdef VBOX_WITH_DEBUGGER_GUI
    809     dbgDestroy();
    810 #endif
    811 }
    812 
    813 #ifdef Q_WS_MAC
    814 void VBoxConsoleWnd::sltDockPreviewModeChanged(QAction *pAction)
    815 {
    816     if (mConsole)
    817     {
    818         CMachine machine = mSession.GetMachine();
    819         if (!machine.isNull())
    820         {
    821             if (pAction == m_pDockDisablePreview)
    822                 machine.SetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled, "false");
    823             else if (pAction == m_pDockEnablePreviewMonitor)
    824                 machine.SetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled, "true");
    825             mConsole->updateDockOverlay();
    826         }
    827     }
    828 }
    829 #endif /* Q_WS_MAC */
    830 
    831 /**
    832  *  Opens a new console view to interact with a given VM.
    833  *  Does nothing if the console view is already opened.
    834  *  Used by VBoxGlobal::startMachine(), should not be called directly.
    835  */
    836 bool VBoxConsoleWnd::openView (const CSession &aSession)
    837 {
    838     LogFlowFuncEnter();
    839 
    840     if (mConsole)
    841     {
    842         LogFlowFunc (("Already opened\n"));
    843         LogFlowFuncLeave();
    844         return false;
    845     }
    846 
    847 #ifdef Q_WS_MAC
    848     /* We have to make sure that we are getting the front most process. This is
    849      * necessary for Qt versions > 4.3.3 */
    850     ProcessSerialNumber psn = { 0, kCurrentProcess };
    851     ::SetFrontProcess (&psn);
    852 #endif /* Q_WS_MAC */
    853 
    854     mSession = aSession;
    855 
    856     if (!centralWidget())
    857     {
    858         setCentralWidget (new QWidget (this));
    859         QGridLayout *pMainLayout = new QGridLayout (centralWidget());
    860         VBoxGlobal::setLayoutMargin (pMainLayout, 0);
    861         pMainLayout->setSpacing (0);
    862 
    863         mShiftingSpacerLeft = new QSpacerItem (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
    864         mShiftingSpacerTop = new QSpacerItem (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
    865         mShiftingSpacerRight = new QSpacerItem (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
    866         mShiftingSpacerBottom = new QSpacerItem (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
    867         pMainLayout->addItem (mShiftingSpacerTop, 0, 0, 1, -1);
    868         pMainLayout->addItem (mShiftingSpacerLeft, 1, 0);
    869         pMainLayout->addItem (mShiftingSpacerRight, 1, 2);
    870         pMainLayout->addItem (mShiftingSpacerBottom, 2, 0, 1, -1);
    871     }
    872 
    873     mVmPauseAction->setChecked (false);
    874 
    875     CConsole console = mSession.GetConsole();
    876     AssertWrapperOk (mSession);
    877 
    878     CMachine machine = mSession.GetMachine();
    879 
    880 #ifdef VBOX_WITH_VIDEOHWACCEL
    881     /* Need to force the QGL framebuffer in case 2D Video Acceleration is supported & enabled */
    882     bool bAccelerate2DVideo = machine.GetAccelerate2DVideoEnabled()
    883             && VBoxGlobal::isAcceleration2DVideoAvailable()
    884     ;
    885 #endif
    886 
    887     mConsole = new VBoxConsoleView (this, console, vboxGlobal().vmRenderMode(),
    888 #ifdef VBOX_WITH_VIDEOHWACCEL
    889                                     bAccelerate2DVideo,
    890 #endif
    891                                     centralWidget());
    892     qobject_cast <QGridLayout*> (centralWidget()->layout())->addWidget (mConsole, 1, 1, Qt::AlignVCenter | Qt::AlignHCenter);
    893 
    894     /* Mini toolbar */
    895     bool isActive = !(machine.GetExtraData (VBoxDefs::GUI_ShowMiniToolBar) == "no");
    896     bool isAtTop = (machine.GetExtraData (VBoxDefs::GUI_MiniToolBarAlignment) == "top");
    897     bool isAutoHide = !(machine.GetExtraData (VBoxDefs::GUI_MiniToolBarAutoHide) == "off");
    898     QList <QMenu*> menus (QList <QMenu*>() << mVMMenuMini << mDevicesMenu);
    899     mMiniToolBar = new VBoxMiniToolBar (centralWidget(), isAtTop ? VBoxMiniToolBar::AlignTop : VBoxMiniToolBar::AlignBottom,
    900                                         isActive, isAutoHide);
    901     *mMiniToolBar << menus;
    902     connect (mMiniToolBar, SIGNAL (exitAction()), this, SLOT (mtExitMode()));
    903     connect (mMiniToolBar, SIGNAL (closeAction()), this, SLOT (mtCloseVM()));
    904     connect (mMiniToolBar, SIGNAL (geometryUpdated()), this, SLOT (mtMaskUpdate()));
    905     connect (this, SIGNAL (closing()), mMiniToolBar, SLOT (close()));
    906 
    907     activateUICustomizations();
    908 
    909     /* Set the VM-specific application icon */
    910     /* Not on Mac OS X. The dock icon is handled below. */
    911 #ifndef Q_WS_MAC
    912     setWindowIcon (vboxGlobal().vmGuestOSTypeIcon (machine.GetOSTypeId()));
    913 #endif
    914 
    915     /* Restore the position of the window and some options */
    916     {
    917         QString str = machine.GetExtraData (VBoxDefs::GUI_LastWindowPosition);
    918 
    919         bool ok = false, max = false;
    920         int x = 0, y = 0, w = 0, h = 0;
    921         x = str.section (',', 0, 0).toInt (&ok);
    922         if (ok)
    923             y = str.section (',', 1, 1).toInt (&ok);
    924         if (ok)
    925             w = str.section (',', 2, 2).toInt (&ok);
    926         if (ok)
    927             h = str.section (',', 3, 3).toInt (&ok);
    928         if (ok)
    929             max = str.section (',', 4, 4) == VBoxDefs::GUI_LastWindowPosition_Max;
    930 
    931         QRect ar = ok ? QApplication::desktop()->availableGeometry (QPoint (x, y)) :
    932                         QApplication::desktop()->availableGeometry (this);
    933 
    934         if (ok /* previous parameters were read correctly */)
    935         {
    936             mNormalGeo = QRect (x, y, w, h);
    937             setGeometry (mNormalGeo);
    938 
    939             /* Normalize to the optimal size */
    940             mConsole->normalizeGeometry (true /* adjustPosition */);
    941 
    942             if (max)
    943             {
    944                 /* Maximize if needed */
    945                 setWindowState (windowState() | Qt::WindowMaximized);
    946                 mWasMax = max;
    947             }
    948         }
    949         else
    950         {
    951             /* Normalize to the optimal size */
    952             mConsole->normalizeGeometry (true /* adjustPosition */);
    953 
    954             /* Move newly created window to the screen center. */
    955             mNormalGeo = geometry();
    956             mNormalGeo.moveCenter (ar.center());
    957             setGeometry (mNormalGeo);
    958         }
    959 
    960         show();
    961 
    962         /* Process show & possible maximize events */
    963         qApp->processEvents();
    964 
    965         mVmSeamlessAction->setEnabled (false);
    966         str = machine.GetExtraData (VBoxDefs::GUI_Seamless);
    967         if (str == "on")
    968             mVmSeamlessAction->setChecked (true);
    969 
    970         str = machine.GetExtraData (VBoxDefs::GUI_AutoresizeGuest);
    971         if (str != "off")
    972             mVmAutoresizeGuestAction->setChecked (true);
    973 
    974         str = machine.GetExtraData (VBoxDefs::GUI_FirstRun);
    975         if (str == "yes")
    976             mIsFirstTimeStarted = true;
    977         else if (!str.isEmpty())
    978             machine.SetExtraData (VBoxDefs::GUI_FirstRun, QString::null);
    979 
    980         str = machine.GetExtraData (VBoxDefs::GUI_SaveMountedAtRuntime);
    981         if (str == "no")
    982             mIsAutoSaveMedia = false;
    983 
    984         /* Check if one of extended modes to be activated on loading */
    985         QString fsMode = machine.GetExtraData (VBoxDefs::GUI_Fullscreen);
    986         QString slMode = machine.GetExtraData (VBoxDefs::GUI_Seamless);
    987         bool extendedMode = fsMode == "on" || slMode == "on";
    988 
    989         /* If one of extended modes to be loaded we have to ignore default
    990          * console resize event which will come from VGA Device on loading. */
    991         if (extendedMode)
    992             mConsole->requestToResize (QSize (w, h - menuBar()->height() - statusBar()->height()));
    993     }
    994 
    995     /* initialize storage stuff */
    996     int cdDevicesCount = 0;
    997     int fdDevicesCount = 0;
    998     const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
    999     foreach (const CMediumAttachment &attachment, attachments)
    1000     {
    1001         if (attachment.GetType() == KDeviceType_DVD)
    1002             ++ cdDevicesCount;
    1003         if (attachment.GetType() == KDeviceType_Floppy)
    1004             ++ fdDevicesCount;
    1005     }
    1006     mDevicesCDMenu->menuAction()->setData (cdDevicesCount);
    1007     mDevicesFDMenu->menuAction()->setData (fdDevicesCount);
    1008     mDevicesCDMenu->menuAction()->setVisible (cdDevicesCount);
    1009     mDevicesFDMenu->menuAction()->setVisible (fdDevicesCount);
    1010 
    1011     /* initialize usb stuff */
    1012     CUSBController usbctl = machine.GetUSBController();
    1013     if (   usbctl.isNull()
    1014         || !usbctl.GetEnabled()
    1015         || !usbctl.GetProxyAvailable())
    1016     {
    1017         /* hide usb_menu & usb_separator & usb_status_led */
    1018         mDevicesUSBMenu->menuAction()->setVisible (false);
    1019         mUSBLed->setHidden (true);
    1020     }
    1021     else
    1022     {
    1023         mDevicesUSBMenu->setEnabled (true);
    1024         mDevicesUSBMenu->setConsole (console);
    1025         mUSBLed->setState (true);
    1026     }
    1027 
    1028     /* initialize vrdp stuff */
    1029     CVRDPServer vrdpsrv = machine.GetVRDPServer();
    1030     if (vrdpsrv.isNull())
    1031     {
    1032         /* hide vrdp_menu_action & vrdp_separator & vrdp_status_icon */
    1033         mDevicesSwitchVrdpAction->setVisible (false);
    1034         mDevicesSwitchVrdpSeparator->setVisible (false);
    1035 #if 0 /* TODO: Allow to setup status-bar! */
    1036         mVrdpLed->setHidden (true);
    1037 #endif
    1038     }
    1039 
    1040     /* start an idle timer that will update device lighths */
    1041     connect (mIdleTimer, SIGNAL (timeout()), SLOT (updateDeviceLights()));
    1042     mIdleTimer->start (50);
    1043 
    1044     connect (mConsole, SIGNAL (mouseStateChanged (int)), this, SLOT (updateMouseState (int)));
    1045     connect (mConsole, SIGNAL (keyboardStateChanged (int)), mHostkeyLed, SLOT (setState (int)));
    1046     connect (mConsole, SIGNAL (machineStateChanged (KMachineState)), this, SLOT (updateMachineState (KMachineState)));
    1047     connect (mConsole, SIGNAL (additionsStateChanged (const QString&, bool, bool, bool)),
    1048              this, SLOT (updateAdditionsState (const QString &, bool, bool, bool)));
    1049     connect (mConsole, SIGNAL (mediaDriveChanged (VBoxDefs::MediumType)),
    1050              this, SLOT (updateMediaDriveState (VBoxDefs::MediumType)));
    1051     connect (mConsole, SIGNAL (usbStateChange()), this, SLOT (updateUsbState()));
    1052     connect (mConsole, SIGNAL (networkStateChange()), this, SLOT (updateNetworkAdaptersState()));
    1053     connect (mConsole, SIGNAL (sharedFoldersChanged()), this, SLOT (updateSharedFoldersState()));
    1054 
    1055 #ifdef Q_WS_MAC
    1056     QString strTest = machine.GetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled).toLower();
    1057     /* Default to true if it is an empty value */
    1058     bool f = (strTest.isEmpty() || strTest == "true");
    1059     if (f)
    1060         m_pDockEnablePreviewMonitor->setChecked(true);
    1061     else
    1062         m_pDockDisablePreview->setChecked(true);
    1063     mConsole->setDockIconEnabled (f);
    1064     mConsole->updateDockOverlay();
    1065 #endif
    1066 
    1067     /* set the correct initial mMachineState value */
    1068     mMachineState = console.GetState();
    1069 
    1070     mConsole->normalizeGeometry (false /* adjustPosition */);
    1071 
    1072     updateAppearanceOf (AllStuff);
    1073 
    1074     if (vboxGlobal().settings().autoCapture())
    1075         vboxProblem().remindAboutAutoCapture();
    1076 
    1077     /*
    1078      *  The further startup procedure should be done after we leave this method
    1079      *  and enter the main event loop in main(), because it may result into
    1080      *  showing various modal dialogs that will process events from within
    1081      *  this method that in turn can lead to various side effects like this
    1082      *  window is closed before this method returns, etc.
    1083      */
    1084 
    1085     QTimer::singleShot (0, this, SLOT (finalizeOpenView()));
    1086 
    1087     LogFlowFuncLeave();
    1088     return true;
    1089 }
    1090 
    1091 void VBoxConsoleWnd::setMouseIntegrationLocked (bool aDisabled)
    1092 {
    1093     mVmDisableMouseIntegrAction->setChecked (false);
    1094     mVmDisableMouseIntegrAction->setEnabled (aDisabled);
    1095 }
    1096 
    1097 /**
    1098  *  Shows up and activates the popup version of the main menu.
    1099  *
    1100  *  @param aCenter If @a true, center the popup menu on the screen, otherwise
    1101  *                 show it at the current mouse pointer location.
    1102  */
    1103 void VBoxConsoleWnd::popupMainMenu (bool aCenter)
    1104 {
    1105     QPoint pos = QCursor::pos();
    1106     if (aCenter)
    1107     {
    1108         QRect deskGeo = QApplication::desktop()->screenGeometry (this);
    1109         QRect popGeo = mMainMenu->frameGeometry();
    1110         popGeo.moveCenter (QPoint (deskGeo.width() / 2, deskGeo.height() / 2));
    1111         pos = popGeo.topLeft();
    1112     }
    1113     else
    1114     {
    1115         /* put the menu's bottom right corner to the pointer's hotspot point */
    1116         pos.setX (pos.x() - mMainMenu->frameGeometry().width());
    1117         pos.setY (pos.y() - mMainMenu->frameGeometry().height());
    1118     }
    1119 
    1120     mMainMenu->popup (pos);
    1121     mMainMenu->selectFirstAction();
    1122 #ifdef Q_WS_WIN
    1123     mMainMenu->activateWindow();
    1124 #endif
    1125 }
    1126 
    1127 void VBoxConsoleWnd::installGuestAdditionsFrom (const QString &aSource)
    1128 {
    1129     CVirtualBox vbox = vboxGlobal().virtualBox();
    1130     QString uuid;
    1131 
    1132     CMedium image = vbox.FindDVDImage (aSource);
    1133     if (image.isNull())
    1134     {
    1135         image = vbox.OpenDVDImage (aSource, uuid);
    1136         if (vbox.isOk())
    1137             uuid = image.GetId();
    1138     }
    1139     else
    1140         uuid = image.GetId();
    1141 
    1142     if (!vbox.isOk())
    1143         return vboxProblem().cannotOpenMedium (this, vbox, VBoxDefs::MediumType_DVD, aSource);
    1144 
    1145     Assert (!uuid.isNull());
    1146     CMachine m = mSession.GetMachine();
    1147 
    1148     QString ctrName;
    1149     LONG ctrPort = -1, ctrDevice = -1;
    1150     /* Searching for the first suitable slot */
    1151     {
    1152         CStorageControllerVector controllers = m.GetStorageControllers();
    1153         int i = 0;
    1154         while (i < controllers.size() && ctrName.isNull())
    1155         {
    1156             CStorageController controller = controllers [i];
    1157             CMediumAttachmentVector attachments = m.GetMediumAttachmentsOfController (controller.GetName());
    1158             int j = 0;
    1159             while (j < attachments.size() && ctrName.isNull())
    1160             {
    1161                 CMediumAttachment attachment = attachments [j];
    1162                 if (attachment.GetType() == KDeviceType_DVD)
    1163                 {
    1164                     ctrName = controller.GetName();
    1165                     ctrPort = attachment.GetPort();
    1166                     ctrDevice = attachment.GetDevice();
    1167                 }
    1168                 ++ j;
    1169             }
    1170             ++ i;
    1171         }
    1172     }
    1173 
    1174     if (!ctrName.isNull())
    1175     {
    1176         bool isMounted = false;
    1177 
    1178         /* Mount medium to the predefined port/device */
    1179         m.MountMedium (ctrName, ctrPort, ctrDevice, uuid, false /* force */);
    1180         if (m.isOk())
    1181             isMounted = true;
    1182         else
    1183         {
    1184             /* Ask for force mounting */
    1185             if (vboxProblem().cannotRemountMedium (this, m, VBoxMedium (image, VBoxDefs::MediumType_DVD), true /* mount? */, true /* retry? */) == QIMessageBox::Ok)
    1186             {
    1187                 /* Force mount medium to the predefined port/device */
    1188                 m.MountMedium (ctrName, ctrPort, ctrDevice, uuid, true /* force */);
    1189                 if (m.isOk())
    1190                     isMounted = true;
    1191                 else
    1192                     vboxProblem().cannotRemountMedium (this, m, VBoxMedium (image, VBoxDefs::MediumType_DVD), true /* mount? */, false /* retry? */);
    1193             }
    1194         }
    1195 
    1196         /* Save medium mounted at runtime */
    1197         if (isMounted && mIsAutoSaveMedia)
    1198         {
    1199             m.SaveSettings();
    1200             if (!m.isOk())
    1201                 vboxProblem().cannotSaveMachineSettings (m);
    1202         }
    1203     }
    1204     else
    1205         vboxProblem().cannotMountGuestAdditions (m.GetName());
    1206 }
    1207 
    1208 void VBoxConsoleWnd::setMask (const QRegion &aRegion)
    1209 {
    1210     QRegion region = aRegion;
    1211 
    1212     /* The global mask shift cause of toolbars and such things. */
    1213     region.translate (mMaskShift.width(), mMaskShift.height());
    1214 
    1215     /* Including mini toolbar area */
    1216     QRegion toolBarRegion (mMiniToolBar->mask());
    1217     toolBarRegion.translate (mMiniToolBar->mapToGlobal (toolBarRegion.boundingRect().topLeft()) - QPoint (1, 0));
    1218     region += toolBarRegion;
    1219 
    1220     /* Restrict the drawing to the available space on the screen.
    1221      * (The &operator is better than the previous used -operator,
    1222      * because this excludes space around the real screen also.
    1223      * This is necessary for the mac.) */
    1224     region &= mStrictedRegion;
    1225 
    1226 #ifdef Q_WS_WIN
    1227     QRegion difference = mPrevRegion.subtract (region);
    1228 
    1229     /* Region offset calculation */
    1230     int fleft = 0, ftop = 0;
    1231 
    1232     /* Visible region calculation */
    1233     HRGN newReg = CreateRectRgn (0, 0, 0, 0);
    1234     CombineRgn (newReg, region.handle(), 0, RGN_COPY);
    1235     OffsetRgn (newReg, fleft, ftop);
    1236 
    1237     /* Invisible region calculation */
    1238     HRGN diffReg = CreateRectRgn (0, 0, 0, 0);
    1239     CombineRgn (diffReg, difference.handle(), 0, RGN_COPY);
    1240     OffsetRgn (diffReg, fleft, ftop);
    1241 
    1242     /* Set the current visible region and clean the previous */
    1243     SetWindowRgn (winId(), newReg, FALSE);
    1244     RedrawWindow (0, 0, diffReg, RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN);
    1245     RedrawWindow (mConsole->viewport()->winId(), 0, 0, RDW_INVALIDATE);
    1246 
    1247     mPrevRegion = region;
    1248 #elif defined (Q_WS_MAC)
    1249 # if defined (VBOX_GUI_USE_QUARTZ2D)
    1250     if (vboxGlobal().vmRenderMode() == VBoxDefs::Quartz2DMode)
    1251     {
    1252         /* If we are using the Quartz2D backend we have to trigger
    1253          * an repaint only. All the magic clipping stuff is done
    1254          * in the paint engine. */
    1255         ::darwinWindowInvalidateShape (mConsole->viewport());
    1256     }
    1257     else
    1258 # endif
    1259     {
    1260         /* This is necessary to avoid the flicker by an mask update.
    1261          * See http://lists.apple.com/archives/Carbon-development/2001/Apr/msg01651.html
    1262          * for the hint.
    1263          * There *must* be a better solution. */
    1264         if (!region.isEmpty())
    1265             region |= QRect (0, 0, 1, 1);
    1266         // /* Save the current region for later processing in the darwin event handler. */
    1267         // mCurrRegion = region;
    1268         // /* We repaint the screen before the ReshapeCustomWindow command. Unfortunately
    1269         //  * this command flushes a copy of the backbuffer to the screen after the new
    1270         //  * mask is set. This leads into a missplaced drawing of the content. Currently
    1271         //  * no alternative to this and also this is not 100% perfect. */
    1272         // repaint();
    1273         // qApp->processEvents();
    1274         // /* Now force the reshaping of the window. This is definitly necessary. */
    1275         // ReshapeCustomWindow (reinterpret_cast <WindowPtr> (winId()));
    1276         QMainWindow::setMask (region);
    1277         // HIWindowInvalidateShadow (::darwinToWindowRef (mConsole->viewport()));
    1278     }
    1279 #else
    1280     QMainWindow::setMask (region);
    1281 #endif
    1282 }
    1283 
    1284 void VBoxConsoleWnd::clearMask()
    1285 {
    1286 #ifdef Q_WS_WIN
    1287     SetWindowRgn (winId(), 0, TRUE);
    1288 #else
    1289     QMainWindow::clearMask();
    1290 #endif
    1291 }
    1292 
    1293 void VBoxConsoleWnd::onDisplayResize (ulong aWidth, ulong aHeight)
    1294 {
    1295     if (mIsSeamless)
    1296     {
    1297         const QRect & geo = QApplication::desktop()->availableGeometry (this);
    1298         int dW = geo.width() - (int)aWidth;
    1299         int dH = geo.height() - (int)aHeight;
    1300         if (RT_ABS (dW) > 16 || RT_ABS (dH) > 16)
    1301         {
    1302             mVmSeamlessAction->setChecked (false);
    1303             /* should be cleared already, but just in case */
    1304             if (mIsSeamless)
    1305                 toggleFullscreenMode (false, true);
     129            QString target = QIFileDialog::getExistingDirectory(QFileInfo(m_strTarget).absolutePath(), m_pParent,
     130                                                                tr("Select folder to save Guest Additions image to"), true);
     131            if (target.isNull())
     132                QTimer::singleShot(0, this, SLOT(suicide()));
     133            else
     134                m_strTarget = QDir(target).absoluteFilePath(QFileInfo(m_strTarget).fileName());
    1306135        }
    1307136    }
    1308137}
    1309138
    1310 
    1311 bool VBoxConsoleWnd::event (QEvent *aEvent)
     139void UIDownloaderAdditions::suicide()
    1312140{
    1313     switch (aEvent->type())
    1314     {
    1315         /* By handling every Resize and Move we keep track of the normal
    1316          * (non-minimized and non-maximized) window geometry. Shame on Qt
    1317          * that it doesn't provide this geometry in its public APIs. */
    1318 
    1319         case QEvent::Resize:
    1320         {
    1321             QResizeEvent *re = (QResizeEvent *) aEvent;
    1322 
    1323             if (!mIsWaitingModeResize && !isWindowMaximized() &&
    1324                 !isTrueFullscreen() && !isTrueSeamless())
    1325             {
    1326                 mNormalGeo.setSize (re->size());
    1327 #ifdef VBOX_WITH_DEBUGGER_GUI
    1328                 dbgAdjustRelativePos();
    1329 #endif
    1330             }
    1331 
    1332             if (mIsWaitingModeResize)
    1333             {
    1334                 if (!mIsFullscreen && !mIsSeamless)
    1335                 {
    1336                     mIsWaitingModeResize = false;
    1337                     QTimer::singleShot (0, this, SLOT (onExitFullscreen()));
    1338                 }
    1339             }
    1340             break;
    1341         }
    1342         case QEvent::Move:
    1343         {
    1344             if (!isWindowMaximized() && !isTrueFullscreen() && !isTrueSeamless())
    1345             {
    1346                 mNormalGeo.moveTo (geometry().x(), geometry().y());
    1347 #ifdef VBOX_WITH_DEBUGGER_GUI
    1348                 dbgAdjustRelativePos();
    1349 #endif
    1350             }
    1351             break;
    1352         }
    1353 #ifdef Q_WS_MAC
    1354         case QEvent::Paint:
    1355         {
    1356             if (mIsSeamless)
    1357             {
    1358                 /* Clear the background */
    1359                 CGContextClearRect (::darwinToCGContextRef (this), ::darwinToCGRect (frameGeometry()));
    1360             }
    1361             break;
    1362         }
    1363 #endif
    1364         case StatusTipEvent::Type:
    1365         {
    1366             StatusTipEvent *ev = (StatusTipEvent*) aEvent;
    1367             statusBar()->showMessage (ev->mTip);
    1368             break;
    1369         }
    1370         default:
    1371             break;
    1372     }
    1373 
    1374     return QMainWindow::event (aEvent);
     141    if (m_pAction)
     142        m_pAction->setEnabled(true);
     143    UIDownloaderAdditions::destroy();
    1375144}
    1376145
    1377 void VBoxConsoleWnd::closeEvent (QCloseEvent *aEvent)
     146UIDownloaderAdditions::UIDownloaderAdditions()
     147    : UIDownloader()
     148    , m_pAction(0)
     149    , m_pParent(0)
    1378150{
    1379     LogFlowFuncEnter();
    1380 
    1381     static const char *kSave = "save";
    1382     static const char *kShutdown = "shutdown";
    1383     static const char *kPowerOff = "powerOff";
    1384     static const char *kDiscardCurState = "discardCurState";
    1385 
    1386     if (!mConsole)
    1387     {
    1388         aEvent->accept();
    1389         LogFlowFunc (("Console already destroyed!"));
    1390         LogFlowFuncLeave();
    1391         return;
    1392     }
    1393 
    1394     switch (mMachineState)
    1395     {
    1396         case KMachineState_PoweredOff:
    1397         case KMachineState_Saved:
    1398         case KMachineState_Teleported:
    1399         case KMachineState_Aborted:
    1400             /* The machine has been already powered off or saved or aborted -- close the window immediately. */
    1401             aEvent->accept();
    1402             break;
    1403 
    1404         default:
    1405             /* The machine is in some temporary state like Saving or Stopping.
    1406              * Ignore the close event. When it is Stopping, it will be soon closed anyway from updateMachineState().
    1407              * In all other cases, an appropriate progress dialog will be shown within a few seconds. */
    1408             aEvent->ignore();
    1409             break;
    1410 
    1411         case KMachineState_Teleporting:      /** @todo Live Migration: Test closing a VM that's being teleported or snapshotted. */
    1412         case KMachineState_LiveSnapshotting:
    1413         case KMachineState_Running:
    1414         case KMachineState_Paused:
    1415         case KMachineState_TeleportingPausedVM: /** @todo Live Migration: Check out this. */
    1416         case KMachineState_Stuck:
    1417             /* Start with ignoring the close event */
    1418             aEvent->ignore();
    1419 
    1420             bool isACPIEnabled = mSession.GetConsole().GetGuestEnteredACPIMode();
    1421 
    1422             bool success = true;
    1423 
    1424             bool wasPaused = mMachineState == KMachineState_Paused
    1425                           || mMachineState == KMachineState_Stuck
    1426                           || mMachineState == KMachineState_TeleportingPausedVM;
    1427             if (!wasPaused)
    1428             {
    1429                 /* Suspend the VM and ignore the close event if failed to do so.
    1430                  * pause() will show the error message to the user. */
    1431                 success = mConsole->pause (true);
    1432             }
    1433 
    1434             if (success)
    1435             {
    1436                 success = false;
    1437 
    1438                 CMachine machine = mSession.GetMachine();
    1439                 VBoxCloseVMDlg dlg (this);
    1440                 QString typeId = machine.GetOSTypeId();
    1441                 dlg.pmIcon->setPixmap (vboxGlobal().vmGuestOSTypeIcon (typeId));
    1442 
    1443                 /* Make the Discard checkbox invisible if there are no snapshots */
    1444                 dlg.mCbDiscardCurState->setVisible (machine.GetSnapshotCount() > 0);
    1445                 if (!machine.GetCurrentSnapshot().isNull())
    1446                     dlg.mCbDiscardCurState->setText (dlg.mCbDiscardCurState->text().arg (machine.GetCurrentSnapshot().GetName()));
    1447 
    1448                 if (mMachineState != KMachineState_Stuck)
    1449                 {
    1450                     /* Read the last user's choice for the given VM */
    1451                     QStringList lastAction = machine.GetExtraData (VBoxDefs::GUI_LastCloseAction).split (',');
    1452                     AssertWrapperOk (machine);
    1453                     if (lastAction [0] == kSave)
    1454                     {
    1455                         dlg.mRbShutdown->setEnabled (isACPIEnabled);
    1456                         dlg.mRbSave->setChecked (true);
    1457                         dlg.mRbSave->setFocus();
    1458                     }
    1459                     else if (lastAction [0] == kPowerOff || !isACPIEnabled)
    1460                     {
    1461                         dlg.mRbShutdown->setEnabled (isACPIEnabled);
    1462                         dlg.mRbPowerOff->setChecked (true);
    1463                         dlg.mRbPowerOff->setFocus();
    1464                     }
    1465                     else /* The default is ACPI Shutdown */
    1466                     {
    1467                         dlg.mRbShutdown->setChecked (true);
    1468                         dlg.mRbShutdown->setFocus();
    1469                     }
    1470                     dlg.mCbDiscardCurState->setChecked (lastAction.count() > 1 && lastAction [1] == kDiscardCurState);
    1471                 }
    1472                 else
    1473                 {
    1474                     /* The stuck VM can only be powered off; disable anything else and choose PowerOff */
    1475                     dlg.mRbSave->setEnabled (false);
    1476                     dlg.mRbShutdown->setEnabled (false);
    1477                     dlg.mRbPowerOff->setChecked (true);
    1478                 }
    1479 
    1480                 bool wasShutdown = false;
    1481 
    1482                 if (dlg.exec() == QDialog::Accepted)
    1483                 {
    1484                     /* Disable auto closure because we want to have a chance to show
    1485                      * the error dialog on save state / power off failure. */
    1486                     mNoAutoClose = true;
    1487 
    1488                     CConsole console = mConsole->console();
    1489 
    1490                     if (dlg.mRbSave->isChecked())
    1491                     {
    1492                         CProgress progress = console.SaveState();
    1493 
    1494                         if (console.isOk())
    1495                         {
    1496                             /* Show the "VM saving" progress dialog */
    1497                             vboxProblem().showModalProgressDialog (progress, machine.GetName(), this, 0);
    1498                             if (progress.GetResultCode() != 0)
    1499                                 vboxProblem().cannotSaveMachineState (progress);
    1500                             else
    1501                                 success = true;
    1502                         }
    1503                         else
    1504                             vboxProblem().cannotSaveMachineState (console);
    1505                     }
    1506                     else if (dlg.mRbShutdown->isChecked())
    1507                     {
    1508                         /* Unpause the VM to let it grab the ACPI shutdown event */
    1509                         mConsole->pause (false);
    1510                         /* Prevent the subsequent unpause request */
    1511                         wasPaused = true;
    1512                         /* Signal ACPI shutdown (if there is no ACPI device, the
    1513                          * operation will fail) */
    1514                         console.PowerButton();
    1515                         wasShutdown = console.isOk();
    1516                         if (!wasShutdown)
    1517                             vboxProblem().cannotACPIShutdownMachine (console);
    1518                         /* Success is always false because we never accept the close
    1519                          * window action when doing ACPI shutdown */
    1520                         success = false;
    1521                     }
    1522                     else if (dlg.mRbPowerOff->isChecked())
    1523                     {
    1524                         CProgress progress = console.PowerDown();
    1525 
    1526                         if (console.isOk())
    1527                         {
    1528                             /* Show the power down progress dialog */
    1529                             vboxProblem().showModalProgressDialog (progress, machine.GetName(), this);
    1530                             if (progress.GetResultCode() != 0)
    1531                                 vboxProblem().cannotStopMachine (progress);
    1532                             else
    1533                                 success = true;
    1534                         }
    1535                         else
    1536                             vboxProblem().cannotStopMachine (console);
    1537 
    1538                         if (success)
    1539                         {
    1540                             /* Note: leave success = true even if we fail to
    1541                              * discard the current state later -- the console window
    1542                              * will closed anyway */
    1543 
    1544                             /* Discard the current state if requested */
    1545                             if (dlg.mCbDiscardCurState->isChecked() && dlg.mCbDiscardCurState->isVisibleTo (&dlg))
    1546                             {
    1547                                 CSnapshot snapshot = machine.GetCurrentSnapshot();
    1548                                 CProgress progress = console.RestoreSnapshot (snapshot);
    1549                                 if (console.isOk())
    1550                                 {
    1551                                     /* Show the progress dialog */
    1552                                     vboxProblem().showModalProgressDialog (progress, machine.GetName(), this);
    1553                                     if (progress.GetResultCode() != 0)
    1554                                         vboxProblem().cannotRestoreSnapshot (progress, snapshot.GetName());
    1555                                 }
    1556                                 else
    1557                                     vboxProblem().cannotRestoreSnapshot (console, snapshot.GetName());
    1558                             }
    1559                         }
    1560                     }
    1561 
    1562                     if (success)
    1563                     {
    1564                         /* Accept the close action on success */
    1565                         aEvent->accept();
    1566                     }
    1567 
    1568                     if (success || wasShutdown)
    1569                     {
    1570                         /* Read the last user's choice for the given VM */
    1571                         QStringList prevAction = machine.GetExtraData (VBoxDefs::GUI_LastCloseAction).split (',');
    1572                         /* Memorize the last user's choice for the given VM */
    1573                         QString lastAction = kPowerOff;
    1574                         if (dlg.mRbSave->isChecked())
    1575                             lastAction = kSave;
    1576                         else if (dlg.mRbShutdown->isChecked() ||
    1577                                  (dlg.mRbPowerOff->isChecked() && prevAction [0] == kShutdown && !isACPIEnabled))
    1578                             lastAction = kShutdown;
    1579                         else if (dlg.mRbPowerOff->isChecked())
    1580                             lastAction = kPowerOff;
    1581                         else
    1582                             AssertFailed();
    1583                         if (dlg.mCbDiscardCurState->isChecked())
    1584                             (lastAction += ",") += kDiscardCurState;
    1585                         machine.SetExtraData (VBoxDefs::GUI_LastCloseAction, lastAction);
    1586                         AssertWrapperOk (machine);
    1587                     }
    1588                 }
    1589             }
    1590 
    1591             mNoAutoClose = false;
    1592 
    1593             if (   mMachineState == KMachineState_PoweredOff
    1594                 || mMachineState == KMachineState_Saved
    1595                 || mMachineState == KMachineState_Teleported
    1596                 || mMachineState == KMachineState_Aborted
    1597                )
    1598             {
    1599                 /* The machine has been stopped while showing the Close or the Pause
    1600                  * failure dialog -- accept the close event immediately. */
    1601                 aEvent->accept();
    1602             }
    1603             else
    1604             {
    1605                 if (!success)
    1606                 {
    1607                     /* Restore the running state if needed */
    1608                     if (!wasPaused && mMachineState == KMachineState_Paused)
    1609                         mConsole->pause (false);
    1610                 }
    1611             }
    1612             break;
    1613     }
    1614 
    1615     if (aEvent->isAccepted())
    1616     {
    1617 #ifndef VBOX_GUI_SEPARATE_VM_PROCESS
    1618         vboxGlobal().selectorWnd().show();
    1619 #endif
    1620 
    1621         /* Stop LED update timer */
    1622         mIdleTimer->stop();
    1623         mIdleTimer->disconnect (SIGNAL (timeout()), this, SLOT (updateDeviceLights()));
    1624 
    1625         /* Hide console window */
    1626         hide();
    1627 
    1628         /* Save the position of the window and some options */
    1629         CMachine machine = mSession.GetMachine();
    1630         QString winPos = QString ("%1,%2,%3,%4")
    1631             .arg (mNormalGeo.x()).arg (mNormalGeo.y())
    1632             .arg (mNormalGeo.width()).arg (mNormalGeo.height());
    1633         if (isWindowMaximized() || (mIsFullscreen && mWasMax) || (mIsSeamless && mWasMax))
    1634             winPos += QString (",%1").arg (VBoxDefs::GUI_LastWindowPosition_Max);
    1635 
    1636         machine.SetExtraData (VBoxDefs::GUI_LastWindowPosition, winPos);
    1637 
    1638         machine.SetExtraData (VBoxDefs::GUI_Fullscreen,
    1639                               mVmFullscreenAction->isChecked() ? "on" : "off");
    1640         machine.SetExtraData (VBoxDefs::GUI_Seamless,
    1641                               mVmSeamlessAction->isChecked() ? "on" : "off");
    1642         machine.SetExtraData (VBoxDefs::GUI_AutoresizeGuest,
    1643                               mVmAutoresizeGuestAction->isChecked() ? "on" : "off");
    1644         machine.SetExtraData (VBoxDefs::GUI_MiniToolBarAutoHide,
    1645                               mMiniToolBar->isAutoHide() ? "on" : "off");
    1646 
    1647 #ifdef VBOX_WITH_DEBUGGER_GUI
    1648         /* Close & destroy the debugger GUI */
    1649         dbgDestroy();
    1650 #endif
    1651 
    1652         /* Make sure all events are delievered */
    1653         qApp->processEvents();
    1654 
    1655         /* Notify all the top-level dialogs about closing */
    1656         emit closing();
    1657     }
    1658 
    1659     LogFlowFunc (("accepted=%d\n", aEvent->isAccepted()));
    1660     LogFlowFuncLeave();
    1661151}
    1662152
    1663 #ifdef Q_WS_X11
    1664 bool VBoxConsoleWnd::x11Event (XEvent *aEvent)
     153bool UIDownloaderAdditions::confirmDownload()
    1665154{
    1666     /* Qt bug: when the console view grabs the keyboard, FocusIn, FocusOut,
    1667      * WindowActivate and WindowDeactivate Qt events are not properly sent
    1668      * on top level window (i.e. this) deactivation. The fix is to substiute
    1669      * the mode in FocusOut X11 event structure to NotifyNormal to cause
    1670      * Qt to process it as desired. */
    1671     if (mConsole && aEvent->type == FocusOut)
    1672     {
    1673         if (aEvent->xfocus.mode == NotifyWhileGrabbed  &&
    1674             (aEvent->xfocus.detail == NotifyAncestor ||
    1675              aEvent->xfocus.detail == NotifyInferior ||
    1676              aEvent->xfocus.detail == NotifyNonlinear))
    1677         {
    1678              aEvent->xfocus.mode = NotifyNormal;
    1679         }
    1680     }
    1681     return false;
    1682 }
    1683 #endif
    1684 
    1685 /**
    1686  *  Sets the strings of the subwidgets using the current
    1687  *  language.
    1688  */
    1689 void VBoxConsoleWnd::retranslateUi()
    1690 {
    1691 #ifdef VBOX_OSE
    1692     mCaptionPrefix = tr ("VirtualBox OSE");
    1693 #else
    1694     mCaptionPrefix = tr ("Sun VirtualBox");
    1695 #endif
    1696 
    1697 #ifdef VBOX_BLEEDING_EDGE
    1698     mCaptionPrefix += tr (" EXPERIMENTAL build %1r%2 - %3").arg (RTBldCfgVersion()).arg (RTBldCfgRevisionStr()).arg (VBOX_BLEEDING_EDGE);
    1699 #endif
    1700     /*
    1701      *  Note: All action shortcuts should be added to the menu text in the
    1702      *  form of "\tHost+<Key>" where <Key> is the shortcut key according
    1703      *  to regular QKeySequence rules. No translation of the "Host" word is
    1704      *  allowed (VBoxConsoleView relies on its spelling). setAccel() must not
    1705      *  be used. Unfortunately on the Mac the "host" string is silently removed
    1706      *  & the key is created as an global shortcut. So every e.g. F key stroke
    1707      *  in the vm leads to a menu call of the F entry. Mysteriously the
    1708      *  associated action isn't started. As a workaround the Host+<key> is
    1709      *  written in braces after the menu text.
    1710      */
    1711 
    1712     /* VM actions */
    1713 #ifdef Q_WS_MAC
    1714     qt_set_sequence_auto_mnemonic (false);
    1715 #endif
    1716 
    1717     mVmDisMouseIntegrMenu->setToolTip (tr ("Mouse Integration", "enable/disable..."));
    1718 #if 0 /* TODO: Allow to setup status-bar! */
    1719     mVmAutoresizeMenu->setToolTip (tr ("Auto-resize Guest Display", "enable/disable..."));
    1720 #endif
    1721 
    1722     mVmFullscreenAction->setText (VBoxGlobal::insertKeyToActionText (tr ("&Fullscreen Mode"), "F"));
    1723     mVmFullscreenAction->setStatusTip (tr ("Switch to fullscreen mode" ));
    1724 
    1725     mVmSeamlessAction->setText (VBoxGlobal::insertKeyToActionText (tr ("Seam&less Mode"), "L"));
    1726     mVmSeamlessAction->setStatusTip (tr ("Switch to seamless desktop integration mode"));
    1727 
    1728     mVmAutoresizeGuestAction->setText (VBoxGlobal::insertKeyToActionText (tr ("Auto-resize &Guest Display"), "G"));
    1729     mVmAutoresizeGuestAction->setStatusTip (tr ("Automatically resize the guest display when the "
    1730                                                 "window is resized (requires Guest Additions)"));
    1731 
    1732     mVmAdjustWindowAction->setText (VBoxGlobal::insertKeyToActionText (tr ("&Adjust Window Size"), "A"));
    1733     mVmAdjustWindowAction->setStatusTip (tr ("Adjust window size and position to best fit the guest display"));
    1734 
    1735     /* mVmDisableMouseIntegrAction is set up in updateAppearanceOf() */
    1736 
    1737     mVmTypeCADAction->setText (VBoxGlobal::insertKeyToActionText (tr ("&Insert Ctrl-Alt-Del"), "Del"));
    1738     mVmTypeCADAction->setStatusTip (tr ("Send the Ctrl-Alt-Del sequence to the virtual machine"));
    1739 
    1740 #if defined(Q_WS_X11)
    1741     mVmTypeCABSAction->setText (VBoxGlobal::insertKeyToActionText (tr ("&Insert Ctrl-Alt-Backspace"), "Backspace"));
    1742     mVmTypeCABSAction->setStatusTip (tr ("Send the Ctrl-Alt-Backspace sequence to the virtual machine"));
    1743 #endif
    1744 
    1745     mVmTakeSnapshotAction->setText (VBoxGlobal::insertKeyToActionText (tr ("Take &Snapshot..."), "S"));
    1746     mVmTakeSnapshotAction->setStatusTip (tr ("Take a snapshot of the virtual machine"));
    1747 
    1748     mVmShowInformationDlgAction->setText (VBoxGlobal::insertKeyToActionText (tr ("Session I&nformation Dialog"), "N"));
    1749     mVmShowInformationDlgAction->setStatusTip (tr ("Show Session Information Dialog"));
    1750 
    1751     mVmResetAction->setText (VBoxGlobal::insertKeyToActionText (tr ("&Reset"), "R"));
    1752     mVmResetAction->setStatusTip (tr ("Reset the virtual machine"));
    1753 
    1754     /* mVmPauseAction is set up in updateAppearanceOf() */
    1755 
    1756 #ifdef Q_WS_MAC
    1757     /* Host+H is Hide on the mac */
    1758     mVmACPIShutdownAction->setText (VBoxGlobal::insertKeyToActionText (tr ("ACPI S&hutdown"), "U"));
    1759 #else /* Q_WS_MAC */
    1760     mVmACPIShutdownAction->setText (VBoxGlobal::insertKeyToActionText (tr ("ACPI S&hutdown"), "H"));
    1761 #endif /* !Q_WS_MAC */
    1762     mVmACPIShutdownAction->setStatusTip (tr ("Send the ACPI Power Button press event to the virtual machine"));
    1763 
    1764     mVmCloseAction->setText (VBoxGlobal::insertKeyToActionText (tr ("&Close..." ), "Q"));
    1765     mVmCloseAction->setStatusTip (tr ("Close the virtual machine"));
    1766     mVmCloseAction->setMenuRole (QAction::QuitRole);
    1767 
    1768     /* Devices actions */
    1769     mDevicesCDMenu->setTitle (tr ("&CD/DVD Devices"));
    1770     mDevicesFDMenu->setTitle (tr ("&Floppy Devices"));
    1771 
    1772     mDevicesNetworkDialogAction->setText (tr ("&Network Adapters..."));
    1773     mDevicesNetworkDialogAction->setStatusTip (tr ("Change the settings of network adapters"));
    1774 
    1775     mDevicesSFDialogAction->setText (tr ("&Shared Folders..."));
    1776     mDevicesSFDialogAction->setStatusTip (tr ("Create or modify shared folders"));
    1777 
    1778     mDevicesSwitchVrdpAction->setText (tr ("&Remote Display"));
    1779     mDevicesSwitchVrdpAction->setStatusTip (tr ("Enable or disable remote desktop (RDP) connections to this machine"));
    1780 #if 0 /* TODO: Allow to setup status-bar! */
    1781     mDevicesVRDPMenu->setToolTip (tr ("Remote Desktop (RDP) Server", "enable/disable..."));
    1782 #endif
    1783 
    1784     mDevicesInstallGuestToolsAction->setText (VBoxGlobal::insertKeyToActionText (tr ("&Install Guest Additions..."), "D"));
    1785     mDevicesInstallGuestToolsAction->setStatusTip (tr ("Mount the Guest Additions installation image"));
    1786 
    1787     mDevicesUSBMenu->setTitle (tr ("&USB Devices"));
    1788 
    1789 #ifdef VBOX_WITH_DEBUGGER_GUI
    1790     /* Debug actions */
    1791     if (mDbgStatisticsAction)
    1792         mDbgStatisticsAction->setText (tr ("&Statistics...", "debug action"));
    1793     if (mDbgCommandLineAction)
    1794         mDbgCommandLineAction->setText (tr ("&Command Line...", "debug action"));
    1795     if (mDbgLoggingAction)
    1796         mDbgLoggingAction->setText (tr ("&Logging...", "debug action"));
    1797 #endif
    1798 
    1799     /* Help actions */
    1800     mHelpActions.retranslateUi();
    1801 
    1802     /* Main menu & seamless popup menu */
    1803     mVMMenu->setTitle (tr ("&Machine"));
    1804     // mVMMenu->setIcon (VBoxGlobal::iconSet (":/machine_16px.png"));
    1805 
    1806     mVMMenuMini->setTitle (tr ("&Machine"));
    1807 
    1808     mDevicesMenu->setTitle (tr ("&Devices"));
    1809     // mDevicesMenu->setIcon (VBoxGlobal::iconSet (":/settings_16px.png"));
    1810 
    1811 #ifdef VBOX_WITH_DEBUGGER_GUI
    1812     if (vboxGlobal().isDebuggerEnabled())
    1813         mDbgMenu->setTitle (tr ("De&bug"));
    1814 #endif
    1815     mHelpMenu->setTitle (tr ("&Help"));
    1816     // mHelpMenu->setIcon (VBoxGlobal::iconSet (":/help_16px.png"));
    1817 
    1818 #ifdef Q_WS_MAC
    1819     m_pDockSettingsMenu->setTitle(tr("Dock Icon"));
    1820     m_pDockDisablePreview->setText(tr("Show Application Icon"));
    1821     m_pDockEnablePreviewMonitor->setText(tr("Show Monitor Preview"));
    1822 #endif /* Q_WS_MAC */
    1823 
    1824     /* Status bar widgets */
    1825     mMouseLed->setToolTip (
    1826         tr ("Indicates whether the host mouse pointer is captured by the guest OS:<br>"
    1827             "<nobr><img src=:/mouse_disabled_16px.png/>&nbsp;&nbsp;pointer is not captured</nobr><br>"
    1828             "<nobr><img src=:/mouse_16px.png/>&nbsp;&nbsp;pointer is captured</nobr><br>"
    1829             "<nobr><img src=:/mouse_seamless_16px.png/>&nbsp;&nbsp;mouse integration (MI) is On</nobr><br>"
    1830             "<nobr><img src=:/mouse_can_seamless_16px.png/>&nbsp;&nbsp;MI is Off, pointer is captured</nobr><br>"
    1831             "<nobr><img src=:/mouse_can_seamless_uncaptured_16px.png/>&nbsp;&nbsp;MI is Off, pointer is not captured</nobr><br>"
    1832             "Note that the mouse integration feature requires Guest Additions to be installed in the guest OS."));
    1833     mHostkeyLed->setToolTip (
    1834         tr ("Indicates whether the keyboard is captured by the guest OS "
    1835             "(<img src=:/hostkey_captured_16px.png/>) or not (<img src=:/hostkey_16px.png/>)."));
    1836     mHostkeyName->setToolTip (
    1837         tr ("Shows the currently assigned Host key.<br>"
    1838             "This key, when pressed alone, toggles the keyboard and mouse "
    1839             "capture state. It can also be used in combination with other keys "
    1840             "to quickly perform actions from the main menu."));
    1841     mHostkeyName->setText (QIHotKeyEdit::keyName (vboxGlobal().settings().hostKey()));
    1842 
    1843 #if 0 /* TODO: Allow to setup status-bar! */
    1844     mAutoresizeLed->setToolTip (
    1845         tr ("Indicates whether the guest display auto-resize function is On "
    1846             "(<img src=:/auto_resize_on_16px.png/>) or Off (<img src=:/auto_resize_off_16px.png/>). "
    1847             "Note that this function requires Guest Additions to be installed in the guest OS."));
    1848 #endif
    1849 
    1850     updateAppearanceOf (AllStuff);
     155    return vboxProblem().confirmDownloadAdditions(m_source.toString(),
     156                                                  m_pHttp->lastResponse().contentLength());
    1851157}
    1852158
    1853 void VBoxConsoleWnd::finalizeOpenView()
     159void UIDownloaderAdditions::warnAboutError(const QString &strError)
    1854160{
    1855     LogFlowFuncEnter();
    1856 
    1857     /* Notify the console scroll-view about the console-window is opened. */
    1858     mConsole->onViewOpened();
    1859 
    1860     bool saved = mMachineState == KMachineState_Saved;
    1861 
    1862     CMachine machine = mSession.GetMachine();
    1863     CConsole console = mConsole->console();
    1864 
    1865     if (mIsFirstTimeStarted)
    1866     {
    1867         UIFirstRunWzd wzd (this, machine);
    1868         wzd.exec();
    1869 
    1870         /* Remove GUI_FirstRun extra data key from the machine settings
    1871          * file after showing the wizard once. */
    1872         machine.SetExtraData (VBoxDefs::GUI_FirstRun, QString::null);
    1873     }
    1874 
    1875     /* Start the VM */
    1876     CProgress progress = vboxGlobal().isStartPausedEnabled() || vboxGlobal().isDebuggerAutoShowEnabled() ?
    1877                          console.PowerUpPaused() : console.PowerUp();
    1878 
    1879     /* Check for an immediate failure */
    1880     if (!console.isOk())
    1881     {
    1882         if (vboxGlobal().showStartVMErrors())
    1883             vboxProblem().cannotStartMachine (console);
    1884         /* close this window (this will call closeView()) */
    1885         close();
    1886 
    1887         LogFlowFunc (("Error starting VM\n"));
    1888         LogFlowFuncLeave();
    1889         return;
    1890     }
    1891 
    1892     mConsole->attach();
    1893 
    1894     /* Disable auto closure because we want to have a chance to show the
    1895      * error dialog on startup failure */
    1896     if (vboxGlobal().showStartVMErrors())
    1897         mNoAutoClose = true;
    1898 
    1899     /* show the "VM starting / restoring" progress dialog */
    1900 
    1901     if (saved)
    1902         vboxProblem().showModalProgressDialog (progress, machine.GetName(), this, 0);
    1903     else
    1904         vboxProblem().showModalProgressDialog (progress, machine.GetName(), this);
    1905 
    1906     if (progress.GetResultCode() != 0)
    1907     {
    1908         if (vboxGlobal().showStartVMErrors())
    1909             vboxProblem().cannotStartMachine (progress);
    1910         /* close this window (this will call closeView()) */
    1911         close();
    1912 
    1913         LogFlowFunc (("Error starting VM\n"));
    1914         LogFlowFuncLeave();
    1915         return;
    1916     }
    1917 
    1918     if (vboxGlobal().showStartVMErrors())
    1919         mNoAutoClose = false;
    1920 
    1921     /* Check if we missed a really quick termination after successful
    1922      * startup, and process it if we did. */
    1923     if (   mMachineState == KMachineState_PoweredOff
    1924         || mMachineState == KMachineState_Saved
    1925         || mMachineState == KMachineState_Teleported
    1926         || mMachineState == KMachineState_Aborted
    1927        )
    1928     {
    1929         close();
    1930         LogFlowFuncLeave();
    1931         return;
    1932     }
    1933 
    1934     /* Currently the machine is started and the guest API could be used...
    1935      * Checking if the fullscreen mode should be activated */
    1936     QString str = machine.GetExtraData (VBoxDefs::GUI_Fullscreen);
    1937     if (str == "on")
    1938         mVmFullscreenAction->setChecked (true);
    1939 
    1940     /* If seamless mode should be enabled then check if it is enabled
    1941      * currently and re-enable it if seamless is supported */
    1942     if (mVmSeamlessAction->isChecked() && mIsSeamlessSupported && mIsGraphicsSupported)
    1943         toggleFullscreenMode (true, true);
    1944 #ifdef VBOX_WITH_DEBUGGER_GUI
    1945     /* Open the debugger in "full screen" mode requested by the user. */
    1946     else if (vboxGlobal().isDebuggerAutoShowEnabled())
    1947     {
    1948         /* console in upper left corner of the desktop. */
    1949         QRect rct (0, 0, 0, 0);
    1950         QDesktopWidget *desktop = QApplication::desktop();
    1951         if (desktop)
    1952             rct = desktop->availableGeometry(pos());
    1953         move (QPoint (rct.x(), rct.y()));
    1954 
    1955         if (vboxGlobal().isDebuggerAutoShowStatisticsEnabled())
    1956             dbgShowStatistics();
    1957         if (vboxGlobal().isDebuggerAutoShowCommandLineEnabled())
    1958             dbgShowCommandLine();
    1959 
    1960         if (!vboxGlobal().isStartPausedEnabled())
    1961             mConsole->pause (false);
    1962     }
    1963 #endif
    1964 
    1965     mIsOpenViewFinished = true;
    1966     LogFlowFuncLeave();
    1967 
    1968 #ifdef VBOX_WITH_UPDATE_REQUEST
    1969     vboxGlobal().showUpdateDialog (false /* aForce */);
    1970 #endif
    1971 
    1972     /* Finally check the status of required features. */
    1973     checkRequiredFeatures();
    1974 
    1975     /* Re-request all the static values finally after
    1976      * view is really opened and attached. */
    1977     updateAppearanceOf (VirtualizationStuff);
     161    return vboxProblem().cannotDownloadGuestAdditions(m_source.toString(), strError);
    1978162}
    1979163
    1980 /**
    1981  *  Helper to safely close the main console window.
    1982  *
    1983  *  This method ensures that close() will not be called if there is some
    1984  *  modal widget currently being executed, as it can cause uninitialization
    1985  *  at the point of code where it is not expected at all (example:
    1986  *  VBoxConsoleView::mouseEvent() calling
    1987  *  VBoxProblemReporter::confirmInputCapture()). Instead, an attempt to
    1988  *  close the current modal widget is done and tryClose() is rescheduled for
    1989  *  later execution using a single-shot zero timer.
    1990  *
    1991  *  In particular, this method is used by updateMachineState() when the VM
    1992  *  goes offline, which can even happen if we are inside the modal event loop,
    1993  *  (for example, the VM has been externally powered off or the guest OS
    1994  *  has initiated a shutdown procedure).
    1995  */
    1996 void VBoxConsoleWnd::tryClose()
    1997 {
    1998     /* First close any open modal & popup widgets. Use a single shot with
    1999      * timeout 0 to allow the widgets to cleany close and test then again. If
    2000      * all open widgets are closed destroy ourself. */
    2001     QWidget *widget = QApplication::activeModalWidget() ?
    2002                       QApplication::activeModalWidget() :
    2003                       QApplication::activePopupWidget() ?
    2004                       QApplication::activePopupWidget() : 0;
    2005     if (widget)
    2006     {
    2007         widget->close();
    2008         QTimer::singleShot (0, this, SLOT (tryClose()));
    2009     }
    2010     else
    2011         close();
    2012 }
    2013 
    2014 void VBoxConsoleWnd::vmFullscreen (bool aOn)
    2015 {
    2016     bool ok = toggleFullscreenMode (aOn, false /* aSeamless */);
    2017     if (!ok)
    2018     {
    2019         /* On failure, restore the previous button state */
    2020         mVmFullscreenAction->blockSignals (true);
    2021         mVmFullscreenAction->setChecked (!aOn);
    2022         mVmFullscreenAction->blockSignals (false);
    2023     }
    2024 }
    2025 
    2026 void VBoxConsoleWnd::vmSeamless (bool aOn)
    2027 {
    2028     /* Check if it is possible to enter/leave seamless mode */
    2029     if ((mIsSeamlessSupported && mIsGraphicsSupported) || !aOn)
    2030     {
    2031         bool ok = toggleFullscreenMode (aOn, true /* aSeamless */);
    2032         if (!ok)
    2033         {
    2034             /* On failure, restore the previous button state */
    2035             mVmSeamlessAction->blockSignals (true);
    2036             mVmSeamlessAction->setChecked (!aOn);
    2037             mVmSeamlessAction->blockSignals (false);
    2038         }
    2039     }
    2040 }
    2041 
    2042 void VBoxConsoleWnd::vmAutoresizeGuest (bool on)
    2043 {
    2044     if (!mConsole)
    2045         return;
    2046 
    2047 #if 0 /* TODO: Allow to setup status-bar! */
    2048     mAutoresizeLed->setState (on ? 3 : 1);
    2049 #endif
    2050 
    2051     mConsole->setAutoresizeGuest (on, true);
    2052 }
    2053 
    2054 void VBoxConsoleWnd::vmAdjustWindow()
    2055 {
    2056     if (mConsole)
    2057     {
    2058         if (isWindowMaximized())
    2059             showNormal();
    2060         mConsole->normalizeGeometry (true /* adjustPosition */);
    2061     }
    2062 }
    2063 
    2064 void VBoxConsoleWnd::vmDisableMouseIntegration (bool aOff)
    2065 {
    2066     if (mConsole)
    2067     {
    2068         mConsole->setMouseIntegrationEnabled (!aOff);
    2069         updateAppearanceOf (DisableMouseIntegrAction);
    2070     }
    2071 }
    2072 
    2073 void VBoxConsoleWnd::vmTypeCAD()
    2074 {
    2075     if (mConsole)
    2076     {
    2077         CKeyboard keyboard  = mConsole->console().GetKeyboard();
    2078         Assert (!keyboard.isNull());
    2079         keyboard.PutCAD();
    2080         AssertWrapperOk (keyboard);
    2081     }
    2082 }
    2083 
    2084 #ifdef Q_WS_X11
    2085 void VBoxConsoleWnd::vmTypeCABS()
    2086 {
    2087     if (mConsole)
    2088     {
    2089         CKeyboard keyboard  = mConsole->console().GetKeyboard();
    2090         Assert (!keyboard.isNull());
    2091         static QVector <LONG> sSequence (6);
    2092         sSequence[0] = 0x1d; // Ctrl down
    2093         sSequence[1] = 0x38; // Alt down
    2094         sSequence[2] = 0x0E; // Backspace down
    2095         sSequence[3] = 0x8E; // Backspace up
    2096         sSequence[4] = 0xb8; // Alt up
    2097         sSequence[5] = 0x9d; // Ctrl up
    2098         keyboard.PutScancodes (sSequence);
    2099         AssertWrapperOk (keyboard);
    2100     }
    2101 }
    2102 #endif
    2103 
    2104 void VBoxConsoleWnd::vmTakeSnapshot()
    2105 {
    2106     AssertReturn (mConsole, (void) 0);
    2107 
    2108     /* remember the paused state */
    2109     bool wasPaused = mMachineState == KMachineState_Paused;
    2110     if (!wasPaused)
    2111     {
    2112         /* Suspend the VM and ignore the close event if failed to do so.
    2113          * pause() will show the error message to the user. */
    2114         if (!mConsole->pause (true))
    2115             return;
    2116     }
    2117 
    2118     CMachine machine = mSession.GetMachine();
    2119 
    2120     VBoxTakeSnapshotDlg dlg (this, machine);
    2121 
    2122     QString typeId = machine.GetOSTypeId();
    2123     dlg.mLbIcon->setPixmap (vboxGlobal().vmGuestOSTypeIcon (typeId));
    2124 
    2125     /* search for the max available filter index */
    2126     QString nameTemplate = tr ("Snapshot %1");
    2127     int maxSnapshotIndex = searchMaxSnapshotIndex (machine, machine.GetSnapshot (QString()), nameTemplate);
    2128     dlg.mLeName->setText (nameTemplate.arg (++ maxSnapshotIndex));
    2129 
    2130     if (dlg.exec() == QDialog::Accepted)
    2131     {
    2132         CConsole console = mSession.GetConsole();
    2133 
    2134         CProgress progress = console.TakeSnapshot (dlg.mLeName->text().trimmed(), dlg.mTeDescription->toPlainText());
    2135 
    2136         if (console.isOk())
    2137         {
    2138             /* Show the "Taking Snapshot" progress dialog */
    2139             vboxProblem().showModalProgressDialog (progress, machine.GetName(), this, 0);
    2140 
    2141             if (progress.GetResultCode() != 0)
    2142                 vboxProblem().cannotTakeSnapshot (progress);
    2143         }
    2144         else
    2145             vboxProblem().cannotTakeSnapshot (console);
    2146     }
    2147 
    2148     /* Restore the running state if needed */
    2149     if (!wasPaused)
    2150         mConsole->pause (false);
    2151 }
    2152 
    2153 void VBoxConsoleWnd::vmShowInfoDialog()
    2154 {
    2155     VBoxVMInformationDlg::createInformationDlg (mSession, mConsole);
    2156 }
    2157 
    2158 void VBoxConsoleWnd::vmReset()
    2159 {
    2160     if (mConsole)
    2161     {
    2162         if (vboxProblem().confirmVMReset (this))
    2163             mConsole->console().Reset();
    2164     }
    2165 }
    2166 
    2167 void VBoxConsoleWnd::vmPause (bool aOn)
    2168 {
    2169     if (mConsole)
    2170     {
    2171         mConsole->pause (aOn);
    2172         updateAppearanceOf (PauseAction);
    2173     }
    2174 }
    2175 
    2176 void VBoxConsoleWnd::vmACPIShutdown()
    2177 {
    2178     if (!mSession.GetConsole().GetGuestEnteredACPIMode())
    2179         return vboxProblem().cannotSendACPIToMachine();
    2180 
    2181     if (mConsole)
    2182     {
    2183         CConsole console = mConsole->console();
    2184         console.PowerButton();
    2185         if (!console.isOk())
    2186             vboxProblem().cannotACPIShutdownMachine (console);
    2187     }
    2188 }
    2189 
    2190 void VBoxConsoleWnd::vmClose()
    2191 {
    2192     if (mConsole)
    2193         close();
    2194 }
    2195 
    2196 void VBoxConsoleWnd::devicesSwitchVrdp (bool aOn)
    2197 {
    2198     if (!mConsole) return;
    2199 
    2200     CVRDPServer vrdpServer = mSession.GetMachine().GetVRDPServer();
    2201     /* This method should not be executed if vrdpServer is null */
    2202     Assert (!vrdpServer.isNull());
    2203 
    2204     vrdpServer.SetEnabled (aOn);
    2205     updateAppearanceOf (VRDPStuff);
    2206 }
    2207 
    2208 void VBoxConsoleWnd::devicesOpenNetworkDialog()
    2209 {
    2210     if (!mConsole) return;
    2211 
    2212     VBoxNetworkDialog dlg (mConsole, mSession);
    2213     dlg.exec();
    2214 }
    2215 
    2216 void VBoxConsoleWnd::devicesOpenSFDialog()
    2217 {
    2218     if (!mConsole) return;
    2219 
    2220     VBoxSFDialog dlg (mConsole, mSession);
    2221     dlg.exec();
    2222 }
    2223 
    2224 void VBoxConsoleWnd::devicesInstallGuestAdditions()
    2225 {
    2226     char szAppPrivPath [RTPATH_MAX];
    2227     int rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath));
    2228     AssertRC (rc);
    2229 
    2230     QString src1 = QString (szAppPrivPath) + "/VBoxGuestAdditions.iso";
    2231     QString src2 = qApp->applicationDirPath() + "/additions/VBoxGuestAdditions.iso";
    2232 
    2233     /* Check the standard image locations */
    2234     if (QFile::exists (src1))
    2235         return installGuestAdditionsFrom (src1);
    2236     else if (QFile::exists (src2))
    2237         return installGuestAdditionsFrom (src2);
    2238 
    2239     /* Check for the already registered image */
    2240     CVirtualBox vbox = vboxGlobal().virtualBox();
    2241     QString name = QString ("VBoxGuestAdditions_%1.iso").arg (vbox.GetVersion().remove ("_OSE"));
    2242 
    2243     CMediumVector vec = vbox.GetDVDImages();
    2244     for (CMediumVector::ConstIterator it = vec.begin(); it != vec.end(); ++ it)
    2245     {
    2246         QString path = it->GetLocation();
    2247         /* Compare the name part ignoring the file case */
    2248         QString fn = QFileInfo (path).fileName();
    2249         if (RTPathCompare (name.toUtf8().constData(), fn.toUtf8().constData()) == 0)
    2250             return installGuestAdditionsFrom (path);
    2251     }
    2252 
    2253     /* Download the required image */
    2254     int result = vboxProblem().cannotFindGuestAdditions (
    2255         QDir::toNativeSeparators (src1), QDir::toNativeSeparators (src2));
    2256     if (result == QIMessageBox::Yes)
    2257     {
    2258         QString source = QString ("http://download.virtualbox.org/virtualbox/%1/")
    2259                                   .arg (vbox.GetVersion().remove ("_OSE")) + name;
    2260         QString target = QDir (vboxGlobal().virtualBox().GetHomeFolder())
    2261                                .absoluteFilePath (name);
    2262 
    2263         VBoxAdditionsDownloader *dl =
    2264             new VBoxAdditionsDownloader (source, target, mDevicesInstallGuestToolsAction);
    2265         statusBar()->addWidget (dl, 0);
    2266         dl->start();
    2267     }
    2268 }
    2269 
    2270 void VBoxConsoleWnd::prepareStorageMenu()
    2271 {
    2272     QMenu *menu = qobject_cast <QMenu*> (sender());
    2273     Assert (menu);
    2274     menu->clear();
    2275 
    2276     KDeviceType deviceType = menu == mDevicesCDMenu ? KDeviceType_DVD :
    2277                              menu == mDevicesFDMenu ? KDeviceType_Floppy :
    2278                                                       KDeviceType_Null;
    2279     Assert (deviceType != KDeviceType_Null);
    2280 
    2281     VBoxDefs::MediumType mediumType = menu == mDevicesCDMenu ? VBoxDefs::MediumType_DVD :
    2282                                       menu == mDevicesFDMenu ? VBoxDefs::MediumType_Floppy :
    2283                                                                VBoxDefs::MediumType_Invalid;
    2284     Assert (mediumType != VBoxDefs::MediumType_Invalid);
    2285 
    2286     CMachine machine = mSession.GetMachine();
    2287     const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
    2288     foreach (const CMediumAttachment &attachment, attachments)
    2289     {
    2290         CStorageController controller = machine.GetStorageControllerByName (attachment.GetController());
    2291         if (   !controller.isNull()
    2292             && (attachment.GetType() == deviceType))
    2293         {
    2294             /* Attachment menu item */
    2295             QMenu *attachmentMenu = 0;
    2296             if (menu->menuAction()->data().toInt() > 1)
    2297             {
    2298                 attachmentMenu = new QMenu (menu);
    2299                 attachmentMenu->setTitle (QString ("%1 (%2)").arg (controller.GetName())
    2300                                           .arg (vboxGlobal().toString (StorageSlot (controller.GetBus(),
    2301                                                                                     attachment.GetPort(),
    2302                                                                                     attachment.GetDevice()))));
    2303                 switch (controller.GetBus())
    2304                 {
    2305                     case KStorageBus_IDE:
    2306                         attachmentMenu->setIcon (QIcon (":/ide_16px.png")); break;
    2307                     case KStorageBus_SATA:
    2308                         attachmentMenu->setIcon (QIcon (":/sata_16px.png")); break;
    2309                     case KStorageBus_SCSI:
    2310                         attachmentMenu->setIcon (QIcon (":/scsi_16px.png")); break;
    2311                     case KStorageBus_Floppy:
    2312                         attachmentMenu->setIcon (QIcon (":/floppy_16px.png")); break;
    2313                     default:
    2314                         break;
    2315                 }
    2316                 menu->addMenu (attachmentMenu);
    2317             }
    2318             else attachmentMenu = menu;
    2319 
    2320             /* Mount Medium actions */
    2321             CMediumVector mediums;
    2322             switch (mediumType)
    2323             {
    2324                 case VBoxDefs::MediumType_DVD:
    2325                     mediums += vboxGlobal().virtualBox().GetHost().GetDVDDrives();
    2326                     mediums += vboxGlobal().virtualBox().GetDVDImages();
    2327                     break;
    2328                 case VBoxDefs::MediumType_Floppy:
    2329                     mediums += vboxGlobal().virtualBox().GetHost().GetFloppyDrives();
    2330                     mediums += vboxGlobal().virtualBox().GetFloppyImages();
    2331                     break;
    2332                 default:
    2333                     break;
    2334             }
    2335 
    2336             int mediumsToBeShown = 0;
    2337             const int maxMediumsToBeShown = 5;
    2338             CMedium currentMedium = attachment.GetMedium();
    2339             QString currentId = currentMedium.isNull() ? QString::null : currentMedium.GetId();
    2340             bool currentUsed = false;
    2341             foreach (CMedium medium, mediums)
    2342             {
    2343                 bool isMediumUsed = false;
    2344                 foreach (const CMediumAttachment &otherAttachment, attachments)
    2345                 {
    2346                     if (otherAttachment != attachment)
    2347                     {
    2348                         CMedium otherMedium = otherAttachment.GetMedium();
    2349                         if (!otherMedium.isNull() && otherMedium.GetId() == medium.GetId())
    2350                         {
    2351                             isMediumUsed = true;
    2352                             break;
    2353                         }
    2354                     }
    2355                 }
    2356                 if (!isMediumUsed)
    2357                 {
    2358                     if (!currentUsed && !currentMedium.isNull() && mediumsToBeShown == maxMediumsToBeShown - 1)
    2359                         medium = currentMedium;
    2360 
    2361                     if (medium.GetId() == currentId)
    2362                         currentUsed = true;
    2363 
    2364                     QAction *mountMediumAction = new QAction (VBoxMedium (medium, mediumType).name(), attachmentMenu);
    2365                     mountMediumAction->setCheckable (true);
    2366                     mountMediumAction->setChecked (!currentMedium.isNull() && medium.GetId() == currentId);
    2367                     mountMediumAction->setData (QVariant::fromValue (MountTarget (controller.GetName(),
    2368                                                                                   attachment.GetPort(),
    2369                                                                                   attachment.GetDevice(),
    2370                                                                                   medium.GetId())));
    2371                     connect (mountMediumAction, SIGNAL (triggered (bool)), this, SLOT (mountMedium()));
    2372                     attachmentMenu->addAction (mountMediumAction);
    2373                     ++ mediumsToBeShown;
    2374                     if (mediumsToBeShown == maxMediumsToBeShown)
    2375                         break;
    2376                 }
    2377             }
    2378 
    2379             /* Virtual Media Manager action */
    2380             QAction *callVMMAction = new QAction (attachmentMenu);
    2381             callVMMAction->setIcon (QIcon (":/diskimage_16px.png"));
    2382             callVMMAction->setData (QVariant::fromValue (MountTarget (controller.GetName(),
    2383                                                                       attachment.GetPort(),
    2384                                                                       attachment.GetDevice(),
    2385                                                                       mediumType)));
    2386             connect (callVMMAction, SIGNAL (triggered (bool)), this, SLOT (mountMedium()));
    2387             attachmentMenu->addAction (callVMMAction);
    2388 
    2389             /* Separator */
    2390             attachmentMenu->addSeparator();
    2391 
    2392             /* Unmount Medium action */
    2393             QAction *unmountMediumAction = new QAction (attachmentMenu);
    2394             unmountMediumAction->setEnabled (!currentMedium.isNull());
    2395             unmountMediumAction->setData (QVariant::fromValue (MountTarget (controller.GetName(),
    2396                                                                             attachment.GetPort(),
    2397                                                                             attachment.GetDevice())));
    2398             connect (unmountMediumAction, SIGNAL (triggered (bool)), this, SLOT (mountMedium()));
    2399             attachmentMenu->addAction (unmountMediumAction);
    2400 
    2401             /* Switch CD/FD naming */
    2402             switch (mediumType)
    2403             {
    2404                 case VBoxDefs::MediumType_DVD:
    2405                     callVMMAction->setText (tr ("More CD/DVD Images..."));
    2406                     unmountMediumAction->setText (tr ("Unmount CD/DVD Device"));
    2407                     unmountMediumAction->setIcon (VBoxGlobal::iconSet (":/cd_unmount_16px.png",
    2408                                                                        ":/cd_unmount_dis_16px.png"));
    2409                     break;
    2410                 case VBoxDefs::MediumType_Floppy:
    2411                     callVMMAction->setText (tr ("More Floppy Images..."));
    2412                     unmountMediumAction->setText (tr ("Unmount Floppy Device"));
    2413                     unmountMediumAction->setIcon (VBoxGlobal::iconSet (":/fd_unmount_16px.png",
    2414                                                                        ":/fd_unmount_dis_16px.png"));
    2415                     break;
    2416                 default:
    2417                     break;
    2418             }
    2419         }
    2420     }
    2421 
    2422     if (menu->menuAction()->data().toInt() == 0)
    2423     {
    2424         /* Empty menu item */
    2425         Assert (menu->isEmpty());
    2426         QAction *emptyMenuAction = new QAction (menu);
    2427         emptyMenuAction->setEnabled (false);
    2428         switch (mediumType)
    2429         {
    2430             case VBoxDefs::MediumType_DVD:
    2431                 emptyMenuAction->setText (tr ("No CD/DVD Devices Attached"));
    2432                 break;
    2433             case VBoxDefs::MediumType_Floppy:
    2434                 emptyMenuAction->setText (tr ("No Floppy Devices Attached"));
    2435                 break;
    2436             default:
    2437                 break;
    2438         }
    2439         emptyMenuAction->setIcon (VBoxGlobal::iconSet (":/delete_16px.png", ":/delete_dis_16px.png"));
    2440         menu->addAction (emptyMenuAction);
    2441     }
    2442 }
    2443 
    2444 void VBoxConsoleWnd::prepareNetworkMenu()
    2445 {
    2446     mDevicesNetworkMenu->clear();
    2447     mDevicesNetworkMenu->addAction (mDevicesNetworkDialogAction);
    2448 }
    2449 
    2450 void VBoxConsoleWnd::prepareSFMenu()
    2451 {
    2452     mDevicesSFMenu->clear();
    2453     mDevicesSFMenu->addAction (mDevicesSFDialogAction);
    2454 }
    2455 
    2456 void VBoxConsoleWnd::mountMedium()
    2457 {
    2458     /* Get sender action */
    2459     QAction *action = qobject_cast <QAction*> (sender());
    2460     Assert (action);
    2461 
    2462     /* Get current machine */
    2463     CMachine machine = mSession.GetMachine();
    2464 
    2465     /* Get mount-target */
    2466     MountTarget target = action->data().value <MountTarget>();
    2467 
    2468     /* Current mount-target attributes */
    2469     CMediumAttachment currentAttachment = machine.GetMediumAttachment (target.name, target.port, target.device);
    2470     CMedium currentMedium = currentAttachment.GetMedium();
    2471     QString currentId = currentMedium.isNull() ? QString ("") : currentMedium.GetId();
    2472 
    2473     /* New mount-target attributes */
    2474     QString newId = QString ("");
    2475     bool selectWithMediaManager = target.type != VBoxDefs::MediumType_Invalid;
    2476 
    2477     /* Open Virtual Media Manager to select image id */
    2478     if (selectWithMediaManager)
    2479     {
    2480         /* Search for already used images */
    2481         QStringList usedImages;
    2482         foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments())
    2483         {
    2484             CMedium medium = attachment.GetMedium();
    2485             if (attachment != currentAttachment && !medium.isNull() && !medium.GetHostDrive())
    2486                 usedImages << medium.GetId();
    2487         }
    2488         /* Open VMM Dialog */
    2489         VBoxMediaManagerDlg dlg (this);
    2490         dlg.setup (target.type, true /* select? */, true /* refresh? */, machine, currentId, true, usedImages);
    2491         if (dlg.exec() == QDialog::Accepted)
    2492             newId = dlg.selectedId();
    2493         else return;
    2494     }
    2495     /* Use medium which was sent */
    2496     else if (!target.id.isNull() && target.id != currentId)
    2497         newId = target.id;
    2498 
    2499     bool mount = !newId.isEmpty();
    2500 
    2501     /* Remount medium to the predefined port/device */
    2502     bool wasMounted = false;
    2503     machine.MountMedium (target.name, target.port, target.device, newId, false /* force */);
    2504     if (machine.isOk())
    2505         wasMounted = true;
    2506     else
    2507     {
    2508         /* Ask for force remounting */
    2509         if (vboxProblem().cannotRemountMedium (this, machine, vboxGlobal().findMedium (mount ? newId : currentId), mount, true /* retry? */) == QIMessageBox::Ok)
    2510         {
    2511             /* Force remount medium to the predefined port/device. */
    2512             machine.MountMedium (target.name, target.port, target.device, newId, true /* force */);
    2513             if (machine.isOk())
    2514                 wasMounted = true;
    2515             else
    2516                 vboxProblem().cannotRemountMedium (this, machine, vboxGlobal().findMedium (mount ? newId : currentId), mount, false /* retry? */);
    2517         }
    2518     }
    2519 
    2520     /* Save medium mounted at runtime */
    2521     if (wasMounted && mIsAutoSaveMedia)
    2522     {
    2523         machine.SaveSettings();
    2524         if (!machine.isOk())
    2525             vboxProblem().cannotSaveMachineSettings (machine);
    2526     }
    2527 }
    2528 
    2529 /**
    2530  *  Attach/Detach selected USB Device.
    2531  */
    2532 void VBoxConsoleWnd::switchUSB (QAction *aAction)
    2533 {
    2534     if (!mConsole) return;
    2535 
    2536     CConsole console = mSession.GetConsole();
    2537     AssertWrapperOk (mSession);
    2538 
    2539     CUSBDevice usb = mDevicesUSBMenu->getUSB (aAction);
    2540     /* if null then some other item but a USB device is selected */
    2541     if (usb.isNull())
    2542         return;
    2543 
    2544     if (!aAction->isChecked())
    2545     {
    2546         console.DetachUSBDevice (usb.GetId());
    2547         if (!console.isOk())
    2548         {
    2549             /// @todo (r=dmik) the dialog should be either modeless
    2550             //  or we have to pause the VM
    2551             vboxProblem().cannotDetachUSBDevice (console, vboxGlobal().details (usb));
    2552         }
    2553     }
    2554     else
    2555     {
    2556         console.AttachUSBDevice (usb.GetId());
    2557         if (!console.isOk())
    2558         {
    2559             /// @todo (r=dmik) the dialog should be either modeless
    2560             //  or we have to pause the VM
    2561             vboxProblem().cannotAttachUSBDevice (console, vboxGlobal().details (usb));
    2562         }
    2563     }
    2564 }
    2565 
    2566 void VBoxConsoleWnd::showIndicatorContextMenu (QIStateIndicator *aInd, QContextMenuEvent *aEvent)
    2567 {
    2568     if (aInd == mCDLed)
    2569     {
    2570         mDevicesCDMenu->exec (aEvent->globalPos());
    2571     }
    2572 #if 0 /* TODO: Allow to setup status-bar! */
    2573     else if (aInd == mFDLed)
    2574     {
    2575         mDevicesFDMenu->exec (aEvent->globalPos());
    2576     }
    2577 #endif
    2578     else if (aInd == mNetLed)
    2579     {
    2580         if (mDevicesNetworkMenu->isEnabled())
    2581             mDevicesNetworkMenu->exec (aEvent->globalPos());
    2582     }
    2583     else if (aInd == mUSBLed)
    2584     {
    2585         if (mDevicesUSBMenu->isEnabled())
    2586             mDevicesUSBMenu->exec (aEvent->globalPos());
    2587     }
    2588     else if (aInd == mSFLed)
    2589     {
    2590         if (mDevicesSFMenu->isEnabled())
    2591             mDevicesSFMenu->exec (aEvent->globalPos());
    2592     }
    2593     else if (aInd == mMouseLed)
    2594     {
    2595         mVmDisMouseIntegrMenu->exec (aEvent->globalPos());
    2596     }
    2597 #if 0 /* TODO: Allow to setup status-bar! */
    2598     else if (aInd == mVrdpLed)
    2599     {
    2600         mDevicesVRDPMenu->exec (aEvent->globalPos());
    2601     }
    2602     else if (aInd == mAutoresizeLed)
    2603     {
    2604         mVmAutoresizeMenu->exec (aEvent->globalPos());
    2605     }
    2606 #endif
    2607 }
    2608 
    2609 void VBoxConsoleWnd::updateDeviceLights()
    2610 {
    2611     if (mConsole)
    2612     {
    2613         CConsole &console = mConsole->console();
    2614         int st;
    2615         if (mHDLed->state() != KDeviceActivity_Null)
    2616         {
    2617             st = console.GetDeviceActivity (KDeviceType_HardDisk);
    2618             if (mHDLed->state() != st)
    2619                 mHDLed->setState (st);
    2620         }
    2621         if (mCDLed->state() != KDeviceActivity_Null)
    2622         {
    2623             st = console.GetDeviceActivity (KDeviceType_DVD);
    2624             if (mCDLed->state() != st)
    2625                 mCDLed->setState (st);
    2626         }
    2627 #if 0 /* TODO: Allow to setup status-bar! */
    2628         if (mFDLed->state() != KDeviceActivity_Null)
    2629         {
    2630             st = console.GetDeviceActivity (KDeviceType_Floppy);
    2631             if (mFDLed->state() != st)
    2632                 mFDLed->setState (st);
    2633         }
    2634 #endif
    2635         if (mNetLed->state() != KDeviceActivity_Null)
    2636         {
    2637             st = console.GetDeviceActivity (KDeviceType_Network);
    2638             if (mNetLed->state() != st)
    2639                 mNetLed->setState (st);
    2640         }
    2641         if (mUSBLed->state() != KDeviceActivity_Null)
    2642         {
    2643             st = console.GetDeviceActivity (KDeviceType_USB);
    2644             if (mUSBLed->state() != st)
    2645                 mUSBLed->setState (st);
    2646         }
    2647         if (mSFLed->state() != KDeviceActivity_Null)
    2648         {
    2649             st = console.GetDeviceActivity (KDeviceType_SharedFolder);
    2650             if (mSFLed->state() != st)
    2651                 mSFLed->setState (st);
    2652         }
    2653     }
    2654 }
    2655 
    2656 void VBoxConsoleWnd::updateMachineState (KMachineState aState)
    2657 {
    2658     bool guruMeditation = false;
    2659 
    2660     if (mConsole && mMachineState != aState)
    2661     {
    2662         switch (aState)
    2663         {
    2664             case KMachineState_Stuck:
    2665             {
    2666                 guruMeditation = true;
    2667                 break;
    2668             }
    2669             case KMachineState_Paused:
    2670             {
    2671                 if (!mVmPauseAction->isChecked())
    2672                     mVmPauseAction->setChecked (true);
    2673                 break;
    2674             }
    2675             case KMachineState_Running:
    2676             case KMachineState_Teleporting:         /** @todo Live Migration: Check out this. */
    2677             case KMachineState_LiveSnapshotting:
    2678             {
    2679                 if (   (   mMachineState == KMachineState_Paused
    2680                         || mMachineState == KMachineState_TeleportingPausedVM)
    2681                     && mVmPauseAction->isChecked()
    2682                    )
    2683                     mVmPauseAction->setChecked (false);
    2684                 break;
    2685             }
    2686 #ifdef Q_WS_X11
    2687             case KMachineState_Starting:
    2688             case KMachineState_Restoring:
    2689             case KMachineState_TeleportingIn:
    2690             {
    2691                 /* The keyboard handler may wish to do some release logging
    2692                    on startup.  Tell it that the logger is now active. */
    2693                 doXKeyboardLogging (QX11Info::display());
    2694                 break;
    2695             }
    2696 #endif
    2697             default:
    2698                 break;
    2699         }
    2700 
    2701         bool isRunningOrPaused = aState == KMachineState_Running
    2702                               || aState == KMachineState_Teleporting
    2703                               || aState == KMachineState_LiveSnapshotting /** @todo Live Migration: Check out this. */
    2704                               || aState == KMachineState_Paused;
    2705 
    2706         /* Enable/Disable actions that are not managed by updateAppearanceOf() */
    2707 
    2708         mRunningActions->setEnabled (   aState == KMachineState_Running
    2709                                      || aState == KMachineState_Teleporting
    2710                                      || aState == KMachineState_LiveSnapshotting  /** @todo Live Migration: Check out this. */
    2711                                     );
    2712         mRunningOrPausedActions->setEnabled (isRunningOrPaused);
    2713 
    2714         mMachineState = aState;
    2715 
    2716         updateAppearanceOf (Caption |
    2717                             HardDiskStuff | DVDStuff | FloppyStuff |
    2718                             NetworkStuff | USBStuff | VRDPStuff |
    2719                             PauseAction | DisableMouseIntegrAction);
    2720 
    2721         if (   aState == KMachineState_PoweredOff
    2722             || aState == KMachineState_Saved
    2723             || aState == KMachineState_Teleported
    2724             || aState == KMachineState_Aborted
    2725            )
    2726         {
    2727             /* VM has been powered off or saved or aborted, no matter
    2728              * internally or externally -- we must *safely* close the console
    2729              * window unless auto closure is disabled. */
    2730             if (!mNoAutoClose)
    2731                 tryClose();
    2732         }
    2733     }
    2734 
    2735     if (guruMeditation)
    2736     {
    2737         mConsole->setIgnoreGuestResize (true);
    2738 
    2739         CConsole console = mConsole->console();
    2740         QString logFolder = console.GetMachine().GetLogFolder();
    2741 
    2742         /* Take the screenshot for debugging purposes and save it */
    2743         QString fname = logFolder + "/VBox.png";
    2744 
    2745         CDisplay dsp = console.GetDisplay();
    2746         QImage shot = QImage (dsp.GetWidth(), dsp.GetHeight(), QImage::Format_RGB32);
    2747         dsp.TakeScreenShot (shot.bits(), shot.width(), shot.height());
    2748         shot.save (QFile::encodeName (fname), "PNG");
    2749 
    2750         if (vboxProblem().remindAboutGuruMeditation (console, QDir::toNativeSeparators (logFolder)))
    2751         {
    2752             qApp->processEvents();
    2753             console.PowerDown();
    2754             if (!console.isOk())
    2755                 vboxProblem().cannotStopMachine (console);
    2756         }
    2757     }
    2758 
    2759 #ifdef Q_WS_MAC
    2760     if (mConsole)
    2761         mConsole->updateDockOverlay();
    2762 #endif
    2763 }
    2764 
    2765 void VBoxConsoleWnd::updateMouseState (int aState)
    2766 {
    2767     mVmDisableMouseIntegrAction->setEnabled (aState & VBoxConsoleView::MouseAbsolute);
    2768 
    2769     if ((aState & VBoxConsoleView::MouseAbsoluteDisabled) &&
    2770         (aState & VBoxConsoleView::MouseAbsolute) &&
    2771         !(aState & VBoxConsoleView::MouseCaptured))
    2772     {
    2773         mMouseLed->setState (4);
    2774     }
    2775     else
    2776     {
    2777         mMouseLed->setState (aState & (VBoxConsoleView::MouseAbsolute | VBoxConsoleView::MouseCaptured));
    2778     }
    2779 }
    2780 
    2781 void VBoxConsoleWnd::updateAdditionsState (const QString &aVersion,
    2782                                            bool aActive,
    2783                                            bool aSeamlessSupported,
    2784                                            bool aGraphicsSupported)
    2785 {
    2786     mVmAutoresizeGuestAction->setEnabled (aActive && aGraphicsSupported);
    2787     if ((mIsSeamlessSupported != aSeamlessSupported) ||
    2788         (mIsGraphicsSupported != aGraphicsSupported))
    2789     {
    2790         mVmSeamlessAction->setEnabled (aSeamlessSupported && aGraphicsSupported);
    2791         mIsSeamlessSupported = aSeamlessSupported;
    2792         mIsGraphicsSupported = aGraphicsSupported;
    2793         /* If seamless mode should be enabled then check if it is enabled
    2794          * currently and re-enable it if open-view procedure is finished */
    2795         if (mVmSeamlessAction->isChecked() && mIsOpenViewFinished && aSeamlessSupported && aGraphicsSupported)
    2796             toggleFullscreenMode (true, true);
    2797         /* Disable auto-resizing if advanced graphics are not available */
    2798         mConsole->setAutoresizeGuest (mIsGraphicsSupported && mVmAutoresizeGuestAction->isChecked(), false);
    2799         mVmAutoresizeGuestAction->setEnabled (mIsGraphicsSupported);
    2800     }
    2801 
    2802     /* Check the GA version only in case of additions are active */
    2803     if (!aActive)
    2804         return;
    2805 
    2806     /* Check the Guest Additions version and warn the user about possible
    2807      * compatibility issues in case if the installed version is outdated. */
    2808     uint version = aVersion.toUInt();
    2809     QString versionStr = QString ("%1.%2")
    2810         .arg (RT_HIWORD (version)).arg (RT_LOWORD (version));
    2811     QString expectedStr = QString ("%1.%2")
    2812         .arg (VMMDEV_VERSION_MAJOR).arg (VMMDEV_VERSION_MINOR); /** @todo r=bird: This isn't want we want! We want the VirtualBox version of the additions, all three numbers. See @bugref{4084}.*/
    2813 
    2814     if (RT_HIWORD (version) < VMMDEV_VERSION_MAJOR)
    2815     {
    2816         vboxProblem().warnAboutTooOldAdditions (this, versionStr, expectedStr);
    2817     }
    2818     else if (RT_HIWORD (version) == VMMDEV_VERSION_MAJOR &&
    2819              RT_LOWORD (version) <  VMMDEV_VERSION_MINOR)
    2820     {
    2821         vboxProblem().warnAboutOldAdditions (this, versionStr, expectedStr);
    2822     }
    2823     else if (version > VMMDEV_VERSION)
    2824     {
    2825         vboxProblem().warnAboutNewAdditions (this, versionStr, expectedStr);
    2826     }
    2827 }
    2828 
    2829 void VBoxConsoleWnd::updateNetworkAdaptersState()
    2830 {
    2831     updateAppearanceOf (NetworkStuff);
    2832 }
    2833 
    2834 void VBoxConsoleWnd::updateUsbState()
    2835 {
    2836     updateAppearanceOf (USBStuff);
    2837 }
    2838 
    2839 void VBoxConsoleWnd::updateMediaDriveState (VBoxDefs::MediumType aType)
    2840 {
    2841     Assert (aType == VBoxDefs::MediumType_DVD || aType == VBoxDefs::MediumType_Floppy);
    2842     updateAppearanceOf (aType == VBoxDefs::MediumType_DVD ? DVDStuff :
    2843                         aType == VBoxDefs::MediumType_Floppy ? FloppyStuff :
    2844                         AllStuff);
    2845 }
    2846 
    2847 void VBoxConsoleWnd::updateSharedFoldersState()
    2848 {
    2849     updateAppearanceOf (SharedFolderStuff);
    2850 }
    2851 
    2852 /**
    2853  *  This slot is called just after leaving the fullscreen/seamless mode,
    2854  *  when the console was resized to previous size.
    2855  */
    2856 void VBoxConsoleWnd::onExitFullscreen()
    2857 {
    2858     mConsole->setIgnoreMainwndResize (false);
    2859 }
    2860 
    2861 void VBoxConsoleWnd::unlockActionsSwitch()
    2862 {
    2863     if (mIsSeamless)
    2864         mVmSeamlessAction->setEnabled (true);
    2865     else if (mIsFullscreen)
    2866         mVmFullscreenAction->setEnabled (true);
    2867     else
    2868     {
    2869         mVmSeamlessAction->setEnabled (mIsSeamlessSupported && mIsGraphicsSupported);
    2870         mVmFullscreenAction->setEnabled (true);
    2871     }
    2872 
    2873 #ifdef Q_WS_MAC
    2874     if (!mIsSeamless)
    2875     {
    2876         /* Fade back to the normal gamma */
    2877         CGDisplayFade (mFadeToken, 0.5, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0.0, 0.0, 0.0, false);
    2878         CGReleaseDisplayFadeReservation (mFadeToken);
    2879     }
    2880     mConsole->setMouseCoalescingEnabled (true);
    2881 #endif
    2882 
    2883 #ifdef Q_WS_X11
    2884     if (vboxGlobal().isKWinManaged() && !mIsSeamless && !mIsFullscreen)
    2885     {
    2886         /* Workaround for a KWin bug to let console window to exit
    2887          * seamless mode correctly. */
    2888         setWindowFlags(Qt::Window);
    2889         setVisible(true);
    2890     }
    2891 #endif
    2892 }
    2893 
    2894 void VBoxConsoleWnd::mtExitMode()
    2895 {
    2896     if (mIsSeamless)
    2897         mVmSeamlessAction->toggle();
    2898     else
    2899         mVmFullscreenAction->toggle();
    2900 }
    2901 
    2902 void VBoxConsoleWnd::mtCloseVM()
    2903 {
    2904     mVmCloseAction->trigger();
    2905 }
    2906 
    2907 void VBoxConsoleWnd::mtMaskUpdate()
    2908 {
    2909     if (mIsSeamless)
    2910         setMask (mConsole->lastVisibleRegion());
    2911 }
    2912 
    2913 void VBoxConsoleWnd::changeDockIconUpdate (const VBoxChangeDockIconUpdateEvent &aEvent)
    2914 {
    2915 #ifdef Q_WS_MAC
    2916     if (mConsole)
    2917     {
    2918         mConsole->setDockIconEnabled (aEvent.mChanged);
    2919         mConsole->updateDockOverlay();
    2920     }
    2921 #else
    2922     Q_UNUSED (aEvent);
    2923 #endif
    2924 }
    2925 
    2926 void VBoxConsoleWnd::changePresentationMode (const VBoxChangePresentationModeEvent &aEvent)
    2927 {
    2928     Q_UNUSED (aEvent);
    2929 #ifdef Q_WS_MAC
    2930 # ifdef QT_MAC_USE_COCOA
    2931     if (mIsFullscreen)
    2932     {
    2933         /* First check if we are on the primary screen, only than the
    2934            presentation mode have to be changed. */
    2935         QDesktopWidget* pDesktop = QApplication::desktop();
    2936         if (pDesktop->screenNumber(this) == pDesktop->primaryScreen())
    2937         {
    2938             QString testStr = vboxGlobal().virtualBox().GetExtraData (VBoxDefs::GUI_PresentationModeEnabled).toLower();
    2939             /* Default to false if it is an empty value */
    2940             if (testStr.isEmpty() || testStr == "false")
    2941                 SetSystemUIMode (kUIModeAllHidden, 0);
    2942             else
    2943                 SetSystemUIMode (kUIModeAllSuppressed, 0);
    2944         }
    2945     }
    2946     else
    2947         SetSystemUIMode (kUIModeNormal, 0);
    2948 # endif /* QT_MAC_USE_COCOA */
    2949 #endif
    2950 }
    2951 
    2952 /**
    2953  *  Called (on non-UI thread!) when a global GUI setting changes.
    2954  */
    2955 void VBoxConsoleWnd::processGlobalSettingChange (const char * /* aPublicName */, const char * /* aName */)
    2956 {
    2957     mHostkeyName->setText (QIHotKeyEdit::keyName (vboxGlobal().settings().hostKey()));
    2958 }
    2959 
    2960 /**
    2961  *  This function checks the status of required features and
    2962  *  makes a warning and/or some action if something necessary
    2963  *  is not in good condition.
    2964  *  Does nothing if no console view was opened.
    2965  */
    2966 void VBoxConsoleWnd::checkRequiredFeatures()
    2967 {
    2968     if (!mConsole) return;
    2969 
    2970     CConsole console = mConsole->console();
    2971 
    2972     /* Check if the virtualization feature is required. */
    2973     bool is64BitsGuest    = vboxGlobal().virtualBox().GetGuestOSType (
    2974                             console.GetGuest().GetOSTypeId()).GetIs64Bit();
    2975     bool fRecommendVirtEx = vboxGlobal().virtualBox().GetGuestOSType (
    2976                             console.GetGuest().GetOSTypeId()).GetRecommendedVirtEx();
    2977     Assert(!is64BitsGuest || fRecommendVirtEx);
    2978     bool isVirtEnabled    = console.GetDebugger().GetHWVirtExEnabled();
    2979     if (fRecommendVirtEx && !isVirtEnabled)
    2980     {
    2981         bool ret;
    2982         bool fVTxAMDVSupported = vboxGlobal().virtualBox().GetHost()
    2983                                  .GetProcessorFeature (KProcessorFeature_HWVirtEx);
    2984 
    2985         vmPause (true);
    2986 
    2987         if (is64BitsGuest)
    2988             ret = vboxProblem().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
    2989         else
    2990             ret = vboxProblem().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
    2991 
    2992         if (ret == true)
    2993             close();
    2994         else
    2995             vmPause (false);
    2996     }
    2997 }
    2998 
    2999 void VBoxConsoleWnd::activateUICustomizations()
    3000 {
    3001     VBoxGlobalSettings settings = vboxGlobal().settings();
    3002     /* Process known keys */
    3003     menuBar()->setHidden (settings.isFeatureActive ("noMenuBar"));
    3004     statusBar()->setHidden (settings.isFeatureActive ("noStatusBar"));
    3005 }
    3006 
    3007 void VBoxConsoleWnd::updateAppearanceOf (int aElement)
    3008 {
    3009     if (!mConsole) return;
    3010 
    3011     CMachine machine = mSession.GetMachine();
    3012     CConsole console = mConsole->console();
    3013 
    3014     bool isStrictRunningOrPaused = mMachineState == KMachineState_Running
    3015                                 || mMachineState == KMachineState_Paused;
    3016     bool isRunningOrPaused = isStrictRunningOrPaused
    3017                           || mMachineState == KMachineState_Teleporting
    3018                           || mMachineState == KMachineState_LiveSnapshotting;
    3019 
    3020     if (aElement & Caption)
    3021     {
    3022         QString snapshotName;
    3023         if (machine.GetSnapshotCount() > 0)
    3024         {
    3025             CSnapshot snapshot = machine.GetCurrentSnapshot();
    3026             snapshotName = " (" + snapshot.GetName() + ")";
    3027         }
    3028         setWindowTitle (machine.GetName() + snapshotName +
    3029                         " [" + vboxGlobal().toString (mMachineState) + "] - " +
    3030                         mCaptionPrefix);
    3031         mMiniToolBar->setDisplayText (machine.GetName() + snapshotName);
    3032     }
    3033     if (aElement & HardDiskStuff)
    3034     {
    3035         QString tip = tr ("<p style='white-space:pre'><nobr>Indicates the activity "
    3036                           "of the virtual hard disks:</nobr>%1</p>", "HDD tooltip");
    3037         QString data;
    3038         bool attachmentsPresent = false;
    3039 
    3040         CStorageControllerVector controllers = machine.GetStorageControllers();
    3041         foreach (const CStorageController &controller, controllers)
    3042         {
    3043             QString attData;
    3044             CMediumAttachmentVector attachments = machine.GetMediumAttachmentsOfController (controller.GetName());
    3045             foreach (const CMediumAttachment &attachment, attachments)
    3046             {
    3047                 if (attachment.GetType() != KDeviceType_HardDisk)
    3048                     continue;
    3049                 attData += QString ("<br>&nbsp;<nobr>%1:&nbsp;%2</nobr>")
    3050                     .arg (vboxGlobal().toString (StorageSlot (controller.GetBus(), attachment.GetPort(), attachment.GetDevice())))
    3051                     .arg (VBoxMedium (attachment.GetMedium(), VBoxDefs::MediumType_HardDisk).location());
    3052                 attachmentsPresent = true;
    3053             }
    3054             if (!attData.isNull())
    3055                 data += QString ("<br><nobr><b>%1</b></nobr>").arg (controller.GetName()) + attData;
    3056         }
    3057 
    3058         if (!attachmentsPresent)
    3059             data += tr ("<br><nobr><b>No hard disks attached</b></nobr>", "HDD tooltip");
    3060 
    3061         mHDLed->setToolTip (tip.arg (data));
    3062         mHDLed->setState (attachmentsPresent ? KDeviceActivity_Idle : KDeviceActivity_Null);
    3063     }
    3064     if (aElement & DVDStuff)
    3065     {
    3066         QString tip = tr ("<p style='white-space:pre'><nobr>Indicates the activity "
    3067                           "of the CD/DVD devices:</nobr>%1</p>", "CD/DVD tooltip");
    3068         QString data;
    3069         bool attachmentsPresent = false;
    3070 
    3071         CStorageControllerVector controllers = machine.GetStorageControllers();
    3072         foreach (const CStorageController &controller, controllers)
    3073         {
    3074             QString attData;
    3075             CMediumAttachmentVector attachments = machine.GetMediumAttachmentsOfController (controller.GetName());
    3076             foreach (const CMediumAttachment &attachment, attachments)
    3077             {
    3078                 if (attachment.GetType() != KDeviceType_DVD)
    3079                     continue;
    3080                 VBoxMedium vboxMedium (attachment.GetMedium(), VBoxDefs::MediumType_DVD);
    3081                 attData += QString ("<br>&nbsp;<nobr>%1:&nbsp;%2</nobr>")
    3082                     .arg (vboxGlobal().toString (StorageSlot (controller.GetBus(), attachment.GetPort(), attachment.GetDevice())))
    3083                     .arg (vboxMedium.isNull() || vboxMedium.isHostDrive() ? vboxMedium.name() : vboxMedium.location());
    3084                 if (!vboxMedium.isNull())
    3085                     attachmentsPresent = true;
    3086             }
    3087             if (!attData.isNull())
    3088                 data += QString ("<br><nobr><b>%1</b></nobr>").arg (controller.GetName()) + attData;
    3089         }
    3090 
    3091         if (data.isNull())
    3092             data = tr ("<br><nobr><b>No CD/DVD devices attached</b></nobr>", "CD/DVD tooltip");
    3093 
    3094         mCDLed->setToolTip (tip.arg (data));
    3095         mCDLed->setState (attachmentsPresent ? KDeviceActivity_Idle : KDeviceActivity_Null);
    3096     }
    3097 #if 0 /* TODO: Allow to setup status-bar! */
    3098     if (aElement & FloppyStuff)
    3099     {
    3100         QString tip = tr ("<p style='white-space:pre'><nobr>Indicates the activity "
    3101                           "of the floppy devices:</nobr>%1</p>", "FD tooltip");
    3102         QString data;
    3103         bool attachmentsPresent = false;
    3104 
    3105         CStorageControllerVector controllers = machine.GetStorageControllers();
    3106         foreach (const CStorageController &controller, controllers)
    3107         {
    3108             QString attData;
    3109             CMediumAttachmentVector attachments = machine.GetMediumAttachmentsOfController (controller.GetName());
    3110             foreach (const CMediumAttachment &attachment, attachments)
    3111             {
    3112                 if (attachment.GetType() != KDeviceType_Floppy)
    3113                     continue;
    3114                 VBoxMedium vboxMedium (attachment.GetMedium(), VBoxDefs::MediumType_Floppy);
    3115                 attData += QString ("<br>&nbsp;<nobr>%1:&nbsp;%2</nobr>")
    3116                     .arg (vboxGlobal().toString (StorageSlot (controller.GetBus(), attachment.GetPort(), attachment.GetDevice())))
    3117                     .arg (vboxMedium.isNull() || vboxMedium.isHostDrive() ? vboxMedium.name() : vboxMedium.location());
    3118                 if (!vboxMedium.isNull())
    3119                     attachmentsPresent = true;
    3120             }
    3121             if (!attData.isNull())
    3122                 data += QString ("<br><nobr><b>%1</b></nobr>").arg (controller.GetName()) + attData;
    3123         }
    3124 
    3125         if (data.isNull())
    3126             data = tr ("<br><nobr><b>No floppy devices attached</b></nobr>", "FD tooltip");
    3127 
    3128         mFDLed->setToolTip (tip.arg (data));
    3129         mFDLed->setState (attachmentsPresent ? KDeviceActivity_Idle : KDeviceActivity_Null);
    3130     }
    3131 #endif
    3132     if (aElement & NetworkStuff)
    3133     {
    3134         ulong maxCount = vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount();
    3135         ulong count = 0;
    3136         for (ulong slot = 0; slot < maxCount; ++ slot)
    3137             if (machine.GetNetworkAdapter (slot).GetEnabled())
    3138                 ++ count;
    3139         mNetLed->setState (count > 0 ? KDeviceActivity_Idle : KDeviceActivity_Null);
    3140 
    3141         mDevicesNetworkDialogAction->setEnabled (isStrictRunningOrPaused && count > 0);
    3142         mDevicesNetworkMenu->setEnabled (isStrictRunningOrPaused && count > 0);
    3143 
    3144         QString tip = tr ("<p style='white-space:pre'><nobr>Indicates the activity of the "
    3145                            "network interfaces:</nobr>%1</p>", "Network adapters tooltip");
    3146         QString info;
    3147 
    3148         for (ulong slot = 0; slot < maxCount; ++ slot)
    3149         {
    3150             CNetworkAdapter adapter = machine.GetNetworkAdapter (slot);
    3151             if (adapter.GetEnabled())
    3152                 info += tr ("<br><nobr><b>Adapter %1 (%2)</b>: cable %3</nobr>", "Network adapters tooltip")
    3153                     .arg (slot + 1)
    3154                     .arg (vboxGlobal().toString (adapter.GetAttachmentType()))
    3155                     .arg (adapter.GetCableConnected() ?
    3156                           tr ("connected", "Network adapters tooltip") :
    3157                           tr ("disconnected", "Network adapters tooltip"));
    3158         }
    3159 
    3160         if (info.isNull())
    3161             info = tr ("<br><nobr><b>All network adapters are disabled</b></nobr>", "Network adapters tooltip");
    3162 
    3163         mNetLed->setToolTip (tip.arg (info));
    3164     }
    3165     if (aElement & USBStuff)
    3166     {
    3167         if (!mUSBLed->isHidden())
    3168         {
    3169             QString tip = tr ("<p style='white-space:pre'><nobr>Indicates the activity of "
    3170                               "the attached USB devices:</nobr>%1</p>", "USB device tooltip");
    3171             QString info;
    3172 
    3173             CUSBController usbctl = machine.GetUSBController();
    3174             if (!usbctl.isNull() && usbctl.GetEnabled())
    3175             {
    3176                 mDevicesUSBMenu->setEnabled (isStrictRunningOrPaused);
    3177 
    3178                 CUSBDeviceVector devsvec = console.GetUSBDevices();
    3179                 for (int i = 0; i < devsvec.size(); ++ i)
    3180                 {
    3181                     CUSBDevice usb = devsvec [i];
    3182                     info += QString ("<br><b><nobr>%1</nobr></b>").arg (vboxGlobal().details (usb));
    3183                 }
    3184                 if (info.isNull())
    3185                     info = tr ("<br><nobr><b>No USB devices attached</b></nobr>", "USB device tooltip");
    3186             }
    3187             else
    3188             {
    3189                 mDevicesUSBMenu->setEnabled (false);
    3190                 info = tr ("<br><nobr><b>USB Controller is disabled</b></nobr>", "USB device tooltip");
    3191             }
    3192 
    3193             mUSBLed->setToolTip (tip.arg (info));
    3194         }
    3195     }
    3196     if (aElement & VRDPStuff)
    3197     {
    3198         CVRDPServer vrdpsrv = mSession.GetMachine().GetVRDPServer();
    3199         if (!vrdpsrv.isNull())
    3200         {
    3201             /* update menu&status icon state */
    3202             bool isVRDPEnabled = vrdpsrv.GetEnabled();
    3203             mDevicesSwitchVrdpAction->setChecked (isVRDPEnabled);
    3204 #if 0 /* TODO: Allow to setup status-bar! */
    3205             mVrdpLed->setState (isVRDPEnabled ? 1 : 0);
    3206 
    3207             QString tip = tr ("Indicates whether the Remote Display (VRDP Server) "
    3208                               "is enabled (<img src=:/vrdp_16px.png/>) or not "
    3209                               "(<img src=:/vrdp_disabled_16px.png/>).");
    3210             if (vrdpsrv.GetEnabled())
    3211                 tip += tr ("<hr>The VRDP Server is listening on port %1").arg (vrdpsrv.GetPort());
    3212             mVrdpLed->setToolTip (tip);
    3213 #endif
    3214         }
    3215     }
    3216     if (aElement & SharedFolderStuff)
    3217     {
    3218         QString tip = tr ("<p style='white-space:pre'><nobr>Indicates the activity of "
    3219                           "the machine's shared folders:</nobr>%1</p>", "Shared folders tooltip");
    3220 
    3221         QString data;
    3222         QMap <QString, QString> sfs;
    3223 
    3224         mDevicesSFMenu->setEnabled (true);
    3225 
    3226         /* Permanent folders */
    3227         CSharedFolderVector psfvec = machine.GetSharedFolders();
    3228 
    3229         for (int i = 0; i < psfvec.size(); ++ i)
    3230         {
    3231             CSharedFolder sf = psfvec [i];
    3232             sfs.insert (sf.GetName(), sf.GetHostPath());
    3233         }
    3234 
    3235         /* Transient folders */
    3236         CSharedFolderVector tsfvec = console.GetSharedFolders();
    3237 
    3238         for (int i = 0; i < tsfvec.size(); ++ i)
    3239         {
    3240             CSharedFolder sf = tsfvec[i];
    3241             sfs.insert (sf.GetName(), sf.GetHostPath());
    3242         }
    3243 
    3244         for (QMap <QString, QString>::const_iterator it = sfs.constBegin(); it != sfs.constEnd(); ++ it)
    3245         {
    3246             /* Select slashes depending on the OS type */
    3247             if (VBoxGlobal::isDOSType (console.GetGuest().GetOSTypeId()))
    3248                 data += QString ("<br><nobr><b>\\\\vboxsvr\\%1&nbsp;</b></nobr><nobr>%2</nobr>")
    3249                                  .arg (it.key(), it.value());
    3250             else
    3251                 data += QString ("<br><nobr><b>%1&nbsp;</b></nobr><nobr>%2</nobr>")
    3252                                  .arg (it.key(), it.value());
    3253         }
    3254 
    3255         if (sfs.count() == 0)
    3256             data = tr ("<br><nobr><b>No shared folders</b></nobr>", "Shared folders tooltip");
    3257 
    3258         mSFLed->setToolTip (tip.arg (data));
    3259     }
    3260     if (aElement & VirtualizationStuff)
    3261     {
    3262         bool virtEnabled = console.GetDebugger().GetHWVirtExEnabled();
    3263         QString virtualization = virtEnabled ?
    3264             VBoxGlobal::tr ("Enabled", "details report (VT-x/AMD-V)") :
    3265             VBoxGlobal::tr ("Disabled", "details report (VT-x/AMD-V)");
    3266 
    3267         bool nestEnabled = console.GetDebugger().GetHWVirtExNestedPagingEnabled();
    3268         QString nestedPaging = nestEnabled ?
    3269             VBoxVMInformationDlg::tr ("Enabled", "nested paging") :
    3270             VBoxVMInformationDlg::tr ("Disabled", "nested paging");
    3271 
    3272         QString tip (tr ("Indicates the status of the hardware virtualization "
    3273                          "features used by this virtual machine:"
    3274                          "<br><nobr><b>%1:</b>&nbsp;%2</nobr>"
    3275                          "<br><nobr><b>%3:</b>&nbsp;%4</nobr>",
    3276                          "Virtualization Stuff LED")
    3277                          .arg (VBoxGlobal::tr ("VT-x/AMD-V", "details report"), virtualization)
    3278                          .arg (VBoxVMInformationDlg::tr ("Nested Paging"), nestedPaging));
    3279 
    3280         int cpuCount = console.GetMachine().GetCPUCount();
    3281         if (cpuCount > 1)
    3282             tip += tr ("<br><nobr><b>%1:</b>&nbsp;%2</nobr>", "Virtualization Stuff LED")
    3283                        .arg (VBoxGlobal::tr ("Processor(s)", "details report")).arg (cpuCount);
    3284 
    3285         mVirtLed->setToolTip (tip);
    3286         mVirtLed->setState (virtEnabled);
    3287     }
    3288     if (aElement & PauseAction)
    3289     {
    3290         if (!mVmPauseAction->isChecked())
    3291         {
    3292             mVmPauseAction->setText (VBoxGlobal::insertKeyToActionText (tr ("&Pause"), "P"));
    3293             mVmPauseAction->setStatusTip (tr ("Suspend the execution of the virtual machine"));
    3294         }
    3295         else
    3296         {
    3297             mVmPauseAction->setText (VBoxGlobal::insertKeyToActionText (tr ("R&esume"), "P"));
    3298             mVmPauseAction->setStatusTip (tr ("Resume the execution of the virtual machine" ) );
    3299         }
    3300         mVmPauseAction->setEnabled (isRunningOrPaused);
    3301     }
    3302     if (aElement & DisableMouseIntegrAction)
    3303     {
    3304         if (!mVmDisableMouseIntegrAction->isChecked())
    3305         {
    3306             mVmDisableMouseIntegrAction->setText (VBoxGlobal::insertKeyToActionText (tr ("Disable &Mouse Integration"), "I"));
    3307             mVmDisableMouseIntegrAction->setStatusTip (tr ("Temporarily disable host mouse pointer integration"));
    3308         }
    3309         else
    3310         {
    3311             mVmDisableMouseIntegrAction->setText (VBoxGlobal::insertKeyToActionText (tr ("Enable &Mouse Integration"), "I"));
    3312             mVmDisableMouseIntegrAction->setStatusTip (tr ("Enable temporarily disabled host mouse pointer integration"));
    3313         }
    3314         if (   mMachineState == KMachineState_Running
    3315             || mMachineState == KMachineState_Teleporting
    3316             || mMachineState == KMachineState_LiveSnapshotting
    3317            )
    3318             mVmDisableMouseIntegrAction->setEnabled (mConsole->mouseCanAbsolute() && mConsole->mouseCanRelative() && !mConsole->mouseNeedsHostCursor());
    3319         else
    3320             mVmDisableMouseIntegrAction->setEnabled (false);
    3321     }
    3322 }
    3323 
    3324 /**
    3325  * @return @c true if successfully performed the requested operation and false
    3326  * otherwise.
    3327  */
    3328 bool VBoxConsoleWnd::toggleFullscreenMode (bool aOn, bool aSeamless)
    3329 {
    3330     /* Please note: For some platforms like the Mac, the calling order of the
    3331      * functions in this methods is vital. So please be careful on changing
    3332      * this. */
    3333 
    3334     QSize initialSize = size();
    3335     if (aSeamless || mConsole->isAutoresizeGuestActive())
    3336     {
    3337         QRect screen = aSeamless ?
    3338             QApplication::desktop()->availableGeometry (this) :
    3339             QApplication::desktop()->screenGeometry (this);
    3340         ULONG64 availBits = mSession.GetMachine().GetVRAMSize() /* vram */
    3341                           * _1M /* mb to bytes */
    3342                           * 8; /* to bits */
    3343         ULONG guestBpp = mConsole->console().GetDisplay().GetBitsPerPixel();
    3344         ULONG64 usedBits = (screen.width() /* display width */
    3345                          * screen.height() /* display height */
    3346                          * guestBpp
    3347                          + _1M * 8) /* current cache per screen - may be changed in future */
    3348                          * mSession.GetMachine().GetMonitorCount() /**< @todo fix assumption that all screens have same resolution */
    3349                          + 4096 * 8; /* adapter info */
    3350         if (aOn && (availBits < usedBits))
    3351         {
    3352             if (aSeamless)
    3353             {
    3354                 vboxProblem().cannotEnterSeamlessMode (
    3355                     screen.width(), screen.height(), guestBpp,
    3356                     (((usedBits + 7) / 8 + _1M - 1) / _1M) * _1M);
    3357                 return false;
    3358             }
    3359             else
    3360             {
    3361                 int result = vboxProblem().cannotEnterFullscreenMode (
    3362                     screen.width(), screen.height(), guestBpp,
    3363                     (((usedBits + 7) / 8 + _1M - 1) / _1M) * _1M);
    3364                 if (result == QIMessageBox::Cancel)
    3365                     return false;
    3366             }
    3367         }
    3368     }
    3369 
    3370     AssertReturn (mConsole, false);
    3371     AssertReturn ((mHiddenChildren.empty() == aOn), false);
    3372     AssertReturn ((aSeamless && mIsSeamless != aOn) ||
    3373                   (!aSeamless && mIsFullscreen != aOn), false);
    3374     if (aOn)
    3375         AssertReturn ((aSeamless && !mIsFullscreen) ||
    3376                       (!aSeamless && !mIsSeamless), false);
    3377 
    3378     if (aOn)
    3379     {
    3380         /* Take the toggle hot key from the menu item. Since
    3381          * VBoxGlobal::extractKeyFromActionText gets exactly the
    3382          * linked key without the 'Host+' part we are adding it here. */
    3383         QString hotKey = QString ("Host+%1")
    3384             .arg (VBoxGlobal::extractKeyFromActionText (aSeamless ?
    3385                   mVmSeamlessAction->text() : mVmFullscreenAction->text()));
    3386 
    3387         Assert (!hotKey.isEmpty());
    3388 
    3389         /* Show the info message. */
    3390         bool ok = aSeamless ?
    3391             vboxProblem().confirmGoingSeamless (hotKey) :
    3392             vboxProblem().confirmGoingFullscreen (hotKey);
    3393         if (!ok)
    3394             return false;
    3395     }
    3396 
    3397 #ifdef Q_WS_MAC
    3398     if (!aSeamless)
    3399     {
    3400         /* Fade to black */
    3401         CGAcquireDisplayFadeReservation (kCGMaxDisplayReservationInterval, &mFadeToken);
    3402         CGDisplayFade (mFadeToken, 0.3, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, true);
    3403     }
    3404 #endif
    3405 
    3406     if (aSeamless)
    3407     {
    3408         /* Activate the auto-resize feature required for the seamless mode. */
    3409         if (!mVmAutoresizeGuestAction->isChecked())
    3410             mVmAutoresizeGuestAction->setChecked (true);
    3411 
    3412         /* Activate the mouse integration feature for the seamless mode. */
    3413         if (mVmDisableMouseIntegrAction->isChecked())
    3414             mVmDisableMouseIntegrAction->setChecked (false);
    3415 
    3416         mVmAdjustWindowAction->setEnabled (!aOn);
    3417         mVmFullscreenAction->setEnabled (!aOn);
    3418         mVmAutoresizeGuestAction->setEnabled (!aOn);
    3419         mVmDisableMouseIntegrAction->setEnabled (!aOn);
    3420 
    3421         mConsole->console().GetDisplay().SetSeamlessMode (aOn);
    3422         mIsSeamless = aOn;
    3423     }
    3424     else
    3425     {
    3426         mIsFullscreen = aOn;
    3427         mVmAdjustWindowAction->setEnabled (!aOn);
    3428         mVmSeamlessAction->setEnabled (!aOn && mIsSeamlessSupported && mIsGraphicsSupported);
    3429     }
    3430 
    3431     bool wasHidden = isHidden();
    3432 
    3433     /* Temporarily disable the mode-related action to make sure
    3434      * user can not leave the mode before he enter it and inside out. */
    3435     aSeamless ? mVmSeamlessAction->setEnabled (false) :
    3436                 mVmFullscreenAction->setEnabled (false);
    3437 
    3438     /* Calculate initial console size */
    3439     QSize consoleSize;
    3440 
    3441     if (aOn)
    3442     {
    3443         consoleSize = mConsole->frameSize();
    3444         consoleSize -= QSize (mConsole->frameWidth() * 2, mConsole->frameWidth() * 2);
    3445 
    3446         /* Toggle console to manual resize mode. */
    3447         mConsole->setIgnoreMainwndResize (true);
    3448 
    3449         /* Memorize the maximized state. */
    3450         QDesktopWidget *dtw = QApplication::desktop();
    3451         mWasMax = isWindowMaximized() &&
    3452                   dtw->availableGeometry().width()  == frameSize().width() &&
    3453                   dtw->availableGeometry().height() == frameSize().height();
    3454 
    3455         /* Save the previous scroll-view minimum size before entering
    3456          * fullscreen/seamless state to restore this minimum size before
    3457          * the exiting fullscreen. Required for correct scroll-view and
    3458          * guest display update in SDL mode. */
    3459         mPrevMinSize = mConsole->minimumSize();
    3460         mConsole->setMinimumSize (0, 0);
    3461 
    3462         /* let the widget take the whole available desktop space */
    3463         QRect scrGeo = aSeamless ?
    3464             dtw->availableGeometry (this) : dtw->screenGeometry (this);
    3465 
    3466         /* It isn't guaranteed that the guest os set the video mode that
    3467          * we requested. So after all the resizing stuff set the clipping
    3468          * mask and the spacing shifter to the corresponding values. */
    3469         if (aSeamless)
    3470             setViewInSeamlessMode (scrGeo);
    3471 
    3472 #ifdef Q_WS_WIN
    3473         mPrevRegion = dtw->screenGeometry (this);
    3474 #endif
    3475 
    3476         /* Hide all but the central widget containing the console view. */
    3477         QList <QWidget*> list (findChildren <QWidget*> ());
    3478         QList <QWidget*> excludes;
    3479         excludes << centralWidget() << centralWidget()->findChildren <QWidget*> ();
    3480         foreach (QWidget *w, list)
    3481         {
    3482             if (!excludes.contains (w))
    3483             {
    3484                 if (!w->isHidden())
    3485                 {
    3486                     w->hide();
    3487                     mHiddenChildren.append (w);
    3488                 }
    3489             }
    3490         }
    3491 
    3492         /* Adjust colors and appearance. */
    3493         mErasePalette = centralWidget()->palette();
    3494         QPalette palette(mErasePalette);
    3495         palette.setColor (centralWidget()->backgroundRole(), Qt::black);
    3496         centralWidget()->setPalette (palette);
    3497         centralWidget()->setAutoFillBackground (!aSeamless);
    3498         mConsoleStyle = mConsole->frameStyle();
    3499         mConsole->setFrameStyle (QFrame::NoFrame);
    3500         mConsole->setMaximumSize (scrGeo.size());
    3501         mConsole->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
    3502         mConsole->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
    3503     }
    3504     else
    3505     {
    3506         /* Reset the shifting spacers. */
    3507         mShiftingSpacerLeft->changeSize (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
    3508         mShiftingSpacerTop->changeSize (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
    3509         mShiftingSpacerRight->changeSize (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
    3510         mShiftingSpacerBottom->changeSize (0, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
    3511 
    3512         /* Restore the previous scroll-view minimum size before the exiting
    3513          * fullscreen. Required for correct scroll-view and guest display
    3514          * update in SDL mode. */
    3515         mConsole->setMinimumSize (mPrevMinSize);
    3516 
    3517 #ifdef Q_WS_MAC
    3518         if (aSeamless)
    3519         {
    3520             /* Please note: All the stuff below has to be done before the
    3521              * window switch back to normal size. Qt changes the winId on the
    3522              * fullscreen switch and make this stuff useless with the old
    3523              * winId. So please be careful on rearrangement of the method
    3524              * calls. */
    3525             /* Undo all mac specific installations */
    3526             ::darwinSetShowsWindowTransparent (this, false);
    3527         }
    3528 #endif
    3529 
    3530         /* Adjust colors and appearance. */
    3531         clearMask();
    3532         centralWidget()->setPalette (mErasePalette);
    3533         centralWidget()->setAutoFillBackground (false);
    3534         mConsole->setFrameStyle (mConsoleStyle);
    3535         mConsole->setMaximumSize (mConsole->sizeHint());
    3536         mConsole->setHorizontalScrollBarPolicy (Qt::ScrollBarAsNeeded);
    3537         mConsole->setVerticalScrollBarPolicy (Qt::ScrollBarAsNeeded);
    3538 
    3539         /* Show everything hidden when going fullscreen. */
    3540         foreach (QPointer <QWidget> child, mHiddenChildren)
    3541             if (child) child->show();
    3542         mHiddenChildren.clear();
    3543     }
    3544 
    3545     /* Set flag for waiting host resize if it awaited during mode entering */
    3546     if ((mIsFullscreen || mIsSeamless) && (consoleSize != initialSize))
    3547         mIsWaitingModeResize = true;
    3548 
    3549     if (!aOn)
    3550     {
    3551         /* Animation takes a bit long, the mini toolbar is still disappearing
    3552          * when switched to normal mode so hide it completely */
    3553         mMiniToolBar->hide();
    3554         mMiniToolBar->updateDisplay (false, true);
    3555     }
    3556 
    3557     /* Toggle qt full-screen mode */
    3558     switchToFullscreen (aOn, aSeamless);
    3559 
    3560     if (aOn)
    3561     {
    3562         mMiniToolBar->setSeamlessMode (aSeamless);
    3563         mMiniToolBar->updateDisplay (true, true);
    3564     }
    3565 
    3566 #ifdef Q_WS_MAC
    3567     if (aOn && aSeamless)
    3568     {
    3569         /* Please note: All the stuff below has to be done after the window has
    3570          * switched to fullscreen. Qt changes the winId on the fullscreen
    3571          * switch and make this stuff useless with the old winId. So please be
    3572          * careful on rearrangement of the method calls. */
    3573         ::darwinSetShowsWindowTransparent (this, true);
    3574     }
    3575 #endif
    3576 
    3577     /* Send guest size hint */
    3578     mConsole->toggleFSMode (consoleSize);
    3579 
    3580     /* Process all console attributes changes and sub-widget hidings */
    3581     qApp->processEvents();
    3582 
    3583     if (!mIsWaitingModeResize)
    3584         onExitFullscreen();
    3585 
    3586     /* Unlock FS actions locked during modes toggling */
    3587     QTimer::singleShot (300, this, SLOT (unlockActionsSwitch()));
    3588 
    3589 #ifdef Q_WS_MAC /* wasHidden is wrong on the mac it seems. */
    3590     /** @todo figure out what is really wrong here... */
    3591     if (!wasHidden)
    3592         show();
    3593 #else
    3594     if (wasHidden)
    3595         hide();
    3596 #endif
    3597 
    3598     return true;
    3599 }
    3600 
    3601 void VBoxConsoleWnd::switchToFullscreen (bool aOn, bool aSeamless)
    3602 {
    3603 #ifdef Q_WS_MAC
    3604 # ifndef QT_MAC_USE_COCOA
    3605     /* setWindowState removes the window group connection somehow. So save it
    3606      * temporary. */
    3607     WindowGroupRef g = GetWindowGroup (::darwinToNativeWindow (this));
    3608 # endif  /* !QT_MAC_USE_COCOA */
    3609     if (aSeamless)
    3610         if (aOn)
    3611         {
    3612             /* Save for later restoring */
    3613             mNormalGeometry = geometry();
    3614             mSavedFlags = windowFlags();
    3615             /* Remove the frame from the window */
    3616             const QRect fullscreen (qApp->desktop()->screenGeometry (qApp->desktop()->screenNumber (this)));
    3617             setParent (0, Qt::Window | Qt::FramelessWindowHint | (windowFlags() & 0xffff0000));
    3618             setGeometry (fullscreen);
    3619             /* Set it maximized */
    3620             setWindowState (windowState() ^ Qt::WindowMaximized);
    3621         }
    3622         else
    3623         {
    3624             /* Restore old values */
    3625             setParent (0, mSavedFlags);
    3626             setGeometry (mNormalGeometry);
    3627         }
    3628     else
    3629     {
    3630         /* Here we are going really fullscreen */
    3631         setWindowState (windowState() ^ Qt::WindowFullScreen);
    3632         changePresentationMode (VBoxChangePresentationModeEvent(aOn));
    3633     }
    3634 
    3635 # ifndef QT_MAC_USE_COCOA
    3636     /* Reassign the correct window group. */
    3637     SetWindowGroup (::darwinToNativeWindow (this), g);
    3638 # endif /* !QT_MAC_USE_COCOA */
    3639 #else
    3640     NOREF (aOn);
    3641     NOREF (aSeamless);
    3642     setWindowState (windowState() ^ Qt::WindowFullScreen);
    3643 #endif
    3644 }
    3645 
    3646 void VBoxConsoleWnd::setViewInSeamlessMode (const QRect &aTargetRect)
    3647 {
    3648 #ifndef Q_WS_MAC
    3649     /* It isn't guaranteed that the guest os set the video mode that
    3650      * we requested. So after all the resizing stuff set the clipping
    3651      * mask and the spacing shifter to the corresponding values. */
    3652     QDesktopWidget *dtw = QApplication::desktop();
    3653     QRect sRect = dtw->screenGeometry (this);
    3654     QRect aRect (aTargetRect);
    3655     mMaskShift.scale (aTargetRect.left(), aTargetRect.top(), Qt::IgnoreAspectRatio);
    3656     /* Set the clipping mask */
    3657     mStrictedRegion = aRect;
    3658     /* Set the shifting spacer */
    3659     mShiftingSpacerLeft->changeSize (RT_ABS (sRect.left() - aRect.left()), 0,
    3660                                      QSizePolicy::Fixed, QSizePolicy::Preferred);
    3661     mShiftingSpacerTop->changeSize (0, RT_ABS (sRect.top() - aRect.top()),
    3662                                     QSizePolicy::Preferred, QSizePolicy::Fixed);
    3663     mShiftingSpacerRight->changeSize (RT_ABS (sRect.right() - aRect.right()), 0,
    3664                                       QSizePolicy::Fixed, QSizePolicy::Preferred);
    3665     mShiftingSpacerBottom->changeSize (0, RT_ABS (sRect.bottom() - aRect.bottom()),
    3666                                            QSizePolicy::Preferred, QSizePolicy::Fixed);
    3667 #else // !Q_WS_MAC
    3668     NOREF (aTargetRect);
    3669 #endif // !Q_WS_MAC
    3670 }
    3671 
    3672 /**
    3673  *  Closes the console view opened by openView().
    3674  *  Does nothing if no console view was opened.
    3675  */
    3676 void VBoxConsoleWnd::closeView()
    3677 {
    3678     LogFlowFuncEnter();
    3679 
    3680     if (!mConsole)
    3681     {
    3682         LogFlow (("Already closed!\n"));
    3683         LogFlowFuncLeave();
    3684         return;
    3685     }
    3686 
    3687     mConsole->detach();
    3688     centralWidget()->layout()->removeWidget (mConsole);
    3689     delete mConsole;
    3690     mConsole = 0;
    3691     mSession.Close();
    3692     mSession.detach();
    3693 
    3694     LogFlowFuncLeave();
    3695 }
    3696 
    3697 #ifdef VBOX_WITH_DEBUGGER_GUI
    3698 
    3699 /**
    3700  * Prepare the Debug menu.
    3701  */
    3702 void VBoxConsoleWnd::dbgPrepareDebugMenu()
    3703 {
    3704     /* The "Logging" item. */
    3705     bool fEnabled = false;
    3706     bool fChecked = false;
    3707     CConsole console = mSession.GetConsole();
    3708     if (console.isOk())
    3709     {
    3710         CMachineDebugger cdebugger = console.GetDebugger();
    3711         if (console.isOk())
    3712         {
    3713             fEnabled = true;
    3714             fChecked = cdebugger.GetLogEnabled() != FALSE;
    3715         }
    3716     }
    3717     if (fEnabled != mDbgLoggingAction->isEnabled())
    3718         mDbgLoggingAction->setEnabled (fEnabled);
    3719     if (fChecked != mDbgLoggingAction->isChecked())
    3720         mDbgLoggingAction->setChecked (fChecked);
    3721 }
    3722 
    3723 /**
    3724  * Called when the Debug->Statistics... menu item is selected.
    3725  */
    3726 void VBoxConsoleWnd::dbgShowStatistics()
    3727 {
    3728     if (dbgCreated())
    3729         mDbgGuiVT->pfnShowStatistics (mDbgGui);
    3730 }
    3731 
    3732 /**
    3733  * Called when the Debug->Command Line... menu item is selected.
    3734  */
    3735 void VBoxConsoleWnd::dbgShowCommandLine()
    3736 {
    3737     if (dbgCreated())
    3738         mDbgGuiVT->pfnShowCommandLine (mDbgGui);
    3739 }
    3740 
    3741 /**
    3742  * Called when the Debug->Logging menu item is selected.
    3743  */
    3744 void VBoxConsoleWnd::dbgLoggingToggled (bool aState)
    3745 {
    3746     NOREF(aState);
    3747     CConsole console = mSession.GetConsole();
    3748     if (console.isOk())
    3749     {
    3750         CMachineDebugger cdebugger = console.GetDebugger();
    3751         if (console.isOk())
    3752             cdebugger.SetLogEnabled (aState);
    3753     }
    3754 }
    3755 
    3756 /**
    3757  * Ensures that the debugger GUI instance is ready.
    3758  *
    3759  * @returns true if instance is fine and dandy.
    3760  * @returns flase if it's not.
    3761  */
    3762 bool VBoxConsoleWnd::dbgCreated()
    3763 {
    3764     if (mDbgGui)
    3765         return true;
    3766 
    3767     RTLDRMOD hLdrMod = vboxGlobal().getDebuggerModule();
    3768     if (hLdrMod == NIL_RTLDRMOD)
    3769         return false;
    3770 
    3771     PFNDBGGUICREATE pfnGuiCreate;
    3772     int rc = RTLdrGetSymbol (hLdrMod, "DBGGuiCreate", (void**) &pfnGuiCreate);
    3773     if (RT_SUCCESS (rc))
    3774     {
    3775         ISession *pISession = mSession.raw();
    3776         rc = pfnGuiCreate (pISession, &mDbgGui, &mDbgGuiVT);
    3777         if (RT_SUCCESS (rc))
    3778         {
    3779             if (DBGGUIVT_ARE_VERSIONS_COMPATIBLE (mDbgGuiVT->u32Version, DBGGUIVT_VERSION) ||
    3780                 mDbgGuiVT->u32EndVersion == mDbgGuiVT->u32Version)
    3781             {
    3782                 mDbgGuiVT->pfnSetParent (mDbgGui, (QWidget*) this);
    3783                 mDbgGuiVT->pfnSetMenu (mDbgGui, (QMenu*) mDbgMenu);
    3784                 dbgAdjustRelativePos();
    3785                 return true;
    3786             }
    3787 
    3788             LogRel (("DBGGuiCreate failed, incompatible versions (loaded %#x/%#x, expected %#x)\n",
    3789                      mDbgGuiVT->u32Version, mDbgGuiVT->u32EndVersion, DBGGUIVT_VERSION));
    3790         }
    3791         else
    3792             LogRel (("DBGGuiCreate failed, rc=%Rrc\n", rc));
    3793     }
    3794     else
    3795         LogRel (("RTLdrGetSymbol(,\"DBGGuiCreate\",) -> %Rrc\n", rc));
    3796 
    3797     mDbgGui = 0;
    3798     mDbgGuiVT = 0;
    3799     return false;
    3800 }
    3801 
    3802 /**
    3803  * Destroys the debugger GUI instacne if it has been created.
    3804  */
    3805 void VBoxConsoleWnd::dbgDestroy()
    3806 {
    3807     if (mDbgGui)
    3808     {
    3809         mDbgGuiVT->pfnDestroy (mDbgGui);
    3810         mDbgGui = 0;
    3811         mDbgGuiVT = 0;
    3812     }
    3813 }
    3814 
    3815 /**
    3816  * Tells the debugger GUI that the console window has moved or been resized.
    3817  */
    3818 void VBoxConsoleWnd::dbgAdjustRelativePos()
    3819 {
    3820     if (mDbgGui)
    3821     {
    3822         QRect rct = frameGeometry();
    3823         mDbgGuiVT->pfnAdjustRelativePos (mDbgGui, rct.x(), rct.y(), rct.width(), rct.height());
    3824     }
    3825 }
    3826 
    3827 #endif /* VBOX_WITH_DEBUGGER_GUI */
    3828 
    3829 VBoxNetworkDialog::VBoxNetworkDialog (QWidget *aParent, CSession &aSession)
    3830     : QIWithRetranslateUI <QDialog> (aParent)
    3831     , mSettings (0)
    3832     , mSession (aSession)
    3833 {
    3834     setModal (true);
    3835     /* Setup Dialog's options */
    3836     setWindowIcon (QIcon (":/nw_16px.png"));
    3837     setSizeGripEnabled (true);
    3838 
    3839     /* Setup main dialog's layout */
    3840     QVBoxLayout *mainLayout = new QVBoxLayout (this);
    3841     VBoxGlobal::setLayoutMargin (mainLayout, 10);
    3842     mainLayout->setSpacing (10);
    3843 
    3844     /* Setup settings layout */
    3845     mSettings = new VBoxVMSettingsNetworkPage (true);
    3846     mSettings->setOrderAfter (this);
    3847     VBoxGlobal::setLayoutMargin (mSettings->layout(), 0);
    3848     mSettings->getFrom (aSession.GetMachine());
    3849     mainLayout->addWidget (mSettings);
    3850 
    3851     /* Setup button's layout */
    3852     QIDialogButtonBox *buttonBox = new QIDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
    3853 
    3854     connect (buttonBox, SIGNAL (helpRequested()), &vboxProblem(), SLOT (showHelpHelpDialog()));
    3855     connect (buttonBox, SIGNAL (accepted()), this, SLOT (accept()));
    3856     connect (buttonBox, SIGNAL (rejected()), this, SLOT (reject()));
    3857     mainLayout->addWidget (buttonBox);
    3858 
    3859     retranslateUi();
    3860 }
    3861 
    3862 void VBoxNetworkDialog::retranslateUi()
    3863 {
    3864     setWindowTitle (tr ("Network Adapters"));
    3865 }
    3866 
    3867 void VBoxNetworkDialog::accept()
    3868 {
    3869     mSettings->putBackTo();
    3870     CMachine machine = mSession.GetMachine();
    3871     machine.SaveSettings();
    3872     if (!machine.isOk())
    3873         vboxProblem().cannotSaveMachineSettings (machine);
    3874     QDialog::accept();
    3875 }
    3876 
    3877 void VBoxNetworkDialog::showEvent (QShowEvent *aEvent)
    3878 {
    3879     resize (450, 300);
    3880     VBoxGlobal::centerWidget (this, parentWidget());
    3881     setMinimumWidth (400);
    3882     QDialog::showEvent (aEvent);
    3883 }
    3884 
    3885 VBoxSFDialog::VBoxSFDialog (QWidget *aParent, CSession &aSession)
    3886     : QIWithRetranslateUI <QDialog> (aParent)
    3887     , mSettings (0)
    3888     , mSession (aSession)
    3889 {
    3890     setModal (true);
    3891     /* Setup Dialog's options */
    3892     setWindowIcon (QIcon (":/select_file_16px.png"));
    3893     setSizeGripEnabled (true);
    3894 
    3895     /* Setup main dialog's layout */
    3896     QVBoxLayout *mainLayout = new QVBoxLayout (this);
    3897     VBoxGlobal::setLayoutMargin (mainLayout, 10);
    3898     mainLayout->setSpacing (10);
    3899 
    3900     /* Setup settings layout */
    3901     mSettings = new VBoxVMSettingsSF (MachineType | ConsoleType, this);
    3902     VBoxGlobal::setLayoutMargin (mSettings->layout(), 0);
    3903     mSettings->getFromConsole (aSession.GetConsole());
    3904     mSettings->getFromMachine (aSession.GetMachine());
    3905     mainLayout->addWidget (mSettings);
    3906 
    3907     /* Setup button's layout */
    3908     QIDialogButtonBox *buttonBox = new QIDialogButtonBox (QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help);
    3909 
    3910     connect (buttonBox, SIGNAL (helpRequested()), &vboxProblem(), SLOT (showHelpHelpDialog()));
    3911     connect (buttonBox, SIGNAL (accepted()), this, SLOT (accept()));
    3912     connect (buttonBox, SIGNAL (rejected()), this, SLOT (reject()));
    3913     mainLayout->addWidget (buttonBox);
    3914 
    3915     retranslateUi();
    3916 }
    3917 
    3918 void VBoxSFDialog::retranslateUi()
    3919 {
    3920     setWindowTitle (tr ("Shared Folders"));
    3921 }
    3922 
    3923 void VBoxSFDialog::accept()
    3924 {
    3925     mSettings->putBackToConsole();
    3926     mSettings->putBackToMachine();
    3927     CMachine machine = mSession.GetMachine();
    3928     machine.SaveSettings();
    3929     if (!machine.isOk())
    3930         vboxProblem().cannotSaveMachineSettings (machine);
    3931     QDialog::accept();
    3932 }
    3933 
    3934 void VBoxSFDialog::showEvent (QShowEvent *aEvent)
    3935 {
    3936     resize (450, 300);
    3937     VBoxGlobal::centerWidget (this, parentWidget());
    3938     setMinimumWidth (400);
    3939     QDialog::showEvent (aEvent);
    3940 }
    3941 
    3942 #include "VBoxConsoleWnd.moc"
    3943 
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIDownloaderAdditions.h

    r27353 r27374  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VBoxConsoleWnd class declaration
     4 * UIDownloaderAdditions class declaration
    55 */
    66
    77/*
    8  * Copyright (C) 2006-2009 Sun Microsystems, Inc.
     8 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2121 */
    2222
    23 #ifndef __VBoxConsoleWnd_h__
    24 #define __VBoxConsoleWnd_h__
     23#ifndef __UIDownloaderAdditions_h__
     24#define __UIDownloaderAdditions_h__
     25
     26/* Local includes */
     27#include "QIWithRetranslateUI.h"
     28#include "UIDownloader.h"
    2529
    2630/* Global includes */
    27 #include <QColor>
    28 #include <QDialog>
    29 #include <QMainWindow>
    30 #include <QMap>
    31 #include <QMenu>
    3231#include <QPointer>
    3332
    34 /* Local includes */
    35 #include "COMDefs.h"
    36 #include "QIWithRetranslateUI.h"
    37 #include "VBoxProblemReporter.h"
    38 #include "VBoxHelpActions.h"
    39 
    40 #ifdef VBOX_WITH_DEBUGGER_GUI
    41 # include <VBox/dbggui.h>
    42 #endif
    43 #ifdef Q_WS_MAC
    44 # include <ApplicationServices/ApplicationServices.h>
    45 # ifndef QT_MAC_USE_COCOA
    46 #  include <Carbon/Carbon.h>
    47 # endif /* !QT_MAC_USE_COCOA */
    48 #endif
    49 
    50 /* Global forwards */
    51 class QAction;
    52 class QActionGroup;
    53 class QLabel;
    54 class QSpacerItem;
    55 class QIWidgetValidator;
    56 
    57 /* Local forwards */
    58 class QIMenu;
    59 class QIStateIndicator;
    60 class VBoxChangeDockIconUpdateEvent;
    61 class VBoxChangePresentationModeEvent;
    62 class VBoxConsoleView;
    63 class VBoxMiniToolBar;
    64 class VBoxSwitchMenu;
    65 class VBoxUSBMenu;
    66 
    67 class VBoxConsoleWnd : public QIWithRetranslateUI2 <QMainWindow>
     33class UIMiniProcessWidgetAdditions : public QIWithRetranslateUI<UIMiniProcessWidget>
    6834{
    6935    Q_OBJECT;
     
    7137public:
    7238
    73     VBoxConsoleWnd (VBoxConsoleWnd **aSelf, QWidget* aParent = 0, Qt::WindowFlags aFlags = Qt::Window);
    74     virtual ~VBoxConsoleWnd();
    75 
    76     bool isWindowMaximized() const
     39    UIMiniProcessWidgetAdditions(const QString &strSource, QWidget *pParent = 0)
     40      : QIWithRetranslateUI<UIMiniProcessWidget>(pParent)
    7741    {
    78 #ifdef Q_WS_MAC
    79         /* On Mac OS X we didn't really jump to the fullscreen mode but
    80          * maximize the window. This situation has to be considered when
    81          * checking for maximized or fullscreen mode. */
    82         return !isTrueSeamless() && QMainWindow::isMaximized();
    83 #else /* Q_WS_MAC */
    84         return QMainWindow::isMaximized();
    85 #endif /* Q_WS_MAC */
     42        setSource(strSource);
     43        retranslateUi();
    8644    }
    87     bool isWindowFullScreen() const
    88     {
    89 #ifdef Q_WS_MAC
    90         /* On Mac OS X we didn't really jump to the fullscreen mode but
    91          * maximize the window. This situation has to be considered when
    92          * checking for maximized or fullscreen mode. */
    93         return isTrueFullscreen() || isTrueSeamless();
    94 #else /* Q_WS_MAC */
    95         return QMainWindow::isFullScreen();
    96 #endif /* Q_WS_MAC */
    97     }
    98     bool isTrueFullscreen() const { return mIsFullscreen; }
    99     bool isTrueSeamless() const { return mIsSeamless; }
    100 
    101     KMachineState machineState() const { return mMachineState; }
    102 
    103     bool openView (const CSession &aSession);
    104 
    105     void setMouseIntegrationLocked (bool aDisabled);
    106 
    107     void popupMainMenu (bool aCenter);
    108 
    109     void installGuestAdditionsFrom (const QString &aSource);
    110 
    111     void setMask (const QRegion &aRegion);
    112     void clearMask();
    113 
    114     /* informs that the guest display is resized */
    115     void onDisplayResize (ulong aWidth, ulong aHeight);
    116 
    117     /* used for obtaining the extradata settings */
    118     CSession &session() { return mSession; }
    119 signals:
    120 
    121     void closing();
    12245
    12346protected:
    12447
    125     bool event (QEvent *aEvent);
    126     void closeEvent (QCloseEvent *aEvent);
    127 #ifdef Q_WS_X11
    128     bool x11Event (XEvent *aEvent);
    129 #endif
    130 
    131     void retranslateUi();
    132 
    133 private slots:
    134 
    135     void finalizeOpenView();
    136     void tryClose();
    137 
    138     void vmFullscreen (bool aOn);
    139     void vmSeamless (bool aOn);
    140     void vmAutoresizeGuest (bool aOn);
    141     void vmAdjustWindow();
    142     void vmDisableMouseIntegration (bool aOff);
    143     void vmTypeCAD();
    144 #ifdef Q_WS_X11
    145     void vmTypeCABS();
    146 #endif
    147     void vmTakeSnapshot();
    148     void vmShowInfoDialog();
    149     void vmReset();
    150     void vmPause (bool aOn);
    151     void vmACPIShutdown();
    152     void vmClose();
    153 
    154     void devicesSwitchVrdp (bool aOn);
    155     void devicesOpenNetworkDialog();
    156     void devicesOpenSFDialog();
    157     void devicesInstallGuestAdditions();
    158 
    159     void prepareStorageMenu();
    160     void prepareNetworkMenu();
    161     void prepareSFMenu();
    162 
    163     void mountMedium();
    164     void switchUSB (QAction *aAction);
    165 
    166     void showIndicatorContextMenu (QIStateIndicator *aInd, QContextMenuEvent *aEvent);
    167 
    168     void updateDeviceLights();
    169     void updateMachineState (KMachineState aState);
    170     void updateMouseState (int aState);
    171     void updateAdditionsState (const QString &aVersion, bool aActive,
    172                                bool aSeamlessSupported, bool aGraphicsSupported);
    173     void updateNetworkAdaptersState();
    174     void updateUsbState();
    175     void updateMediaDriveState (VBoxDefs::MediumType aType);
    176     void updateSharedFoldersState();
    177 
    178     void onExitFullscreen();
    179     void unlockActionsSwitch();
    180 
    181     void mtExitMode();
    182     void mtCloseVM();
    183     void mtMaskUpdate();
    184 
    185     void changeDockIconUpdate (const VBoxChangeDockIconUpdateEvent &aEvent);
    186     void changePresentationMode (const VBoxChangePresentationModeEvent &aEvent);
    187     void processGlobalSettingChange (const char *aPublicName, const char *aName);
    188 
    189 #ifdef RT_OS_DARWIN /* Stupid moc doesn't recognize Q_WS_MAC */
    190     void sltDockPreviewModeChanged(QAction *pAction);
    191 #endif /* RT_OS_DARWIN */
    192 
    193 #ifdef VBOX_WITH_DEBUGGER_GUI
    194     void dbgPrepareDebugMenu();
    195     void dbgShowStatistics();
    196     void dbgShowCommandLine();
    197     void dbgLoggingToggled (bool aBool);
    198 #endif
    199 
    200 private:
    201 
    202     enum /* Stuff */
     48    void retranslateUi()
    20349    {
    204         HardDiskStuff               = 0x01,
    205         DVDStuff                    = 0x02,
    206         FloppyStuff                 = 0x04,
    207         PauseAction                 = 0x08,
    208         NetworkStuff                = 0x10,
    209         DisableMouseIntegrAction    = 0x20,
    210         Caption                     = 0x40,
    211         USBStuff                    = 0x80,
    212         VRDPStuff                   = 0x100,
    213         SharedFolderStuff           = 0x200,
    214         VirtualizationStuff         = 0x400,
    215         AllStuff                    = 0xFFFF,
    216     };
    217 
    218     void checkRequiredFeatures();
    219     void activateUICustomizations();
    220 
    221     void updateAppearanceOf (int aElement);
    222 
    223     bool toggleFullscreenMode (bool aOn, bool aSeamless);
    224     void switchToFullscreen (bool aOn, bool aSeamless);
    225     void setViewInSeamlessMode (const QRect &aTargetRect);
    226 
    227     void closeView();
    228 
    229 #ifdef VBOX_WITH_DEBUGGER_GUI
    230     bool dbgCreated();
    231     void dbgDestroy();
    232     void dbgAdjustRelativePos();
    233 #endif
    234 
    235     /* COM Variables */
    236     CSession mSession;
    237 
    238     /* Machine State */
    239     KMachineState mMachineState;
    240 
    241     /* Window Variables */
    242     QString mCaptionPrefix;
    243     int mConsoleStyle;
    244 
    245     /* Menu items */
    246     QIMenu *mMainMenu;
    247     QMenu *mVMMenu;
    248     QMenu *mVMMenuMini;
    249     QMenu *mDevicesMenu;
    250     QMenu *mDevicesCDMenu;
    251     QMenu *mDevicesFDMenu;
    252     QMenu *mDevicesNetworkMenu;
    253     QMenu *mDevicesSFMenu;
    254     VBoxUSBMenu *mDevicesUSBMenu;
    255     VBoxSwitchMenu *mVmDisMouseIntegrMenu;
    256 #if 0 /* todo: allow to setup */
    257     VBoxSwitchMenu *mDevicesVRDPMenu;
    258     VBoxSwitchMenu *mVmAutoresizeMenu;
    259 #endif
    260 #ifdef VBOX_WITH_DEBUGGER_GUI
    261     QMenu *mDbgMenu;
    262 #endif
    263     QMenu *mHelpMenu;
    264 
    265     QActionGroup *mRunningActions;
    266     QActionGroup *mRunningOrPausedActions;
    267 
    268     /* Machine actions */
    269     QAction *mVmFullscreenAction;
    270     QAction *mVmSeamlessAction;
    271     QAction *mVmAutoresizeGuestAction;
    272     QAction *mVmAdjustWindowAction;
    273     QAction *mVmDisableMouseIntegrAction;
    274     QAction *mVmTypeCADAction;
    275 #ifdef Q_WS_X11
    276     QAction *mVmTypeCABSAction;
    277 #endif
    278     QAction *mVmTakeSnapshotAction;
    279     QAction *mVmShowInformationDlgAction;
    280     QAction *mVmResetAction;
    281     QAction *mVmPauseAction;
    282     QAction *mVmACPIShutdownAction;
    283     QAction *mVmCloseAction;
    284 
    285     /* Devices actions */
    286     QAction *mDevicesNetworkDialogAction;
    287     QAction *mDevicesSFDialogAction;
    288     QAction *mDevicesSwitchVrdpSeparator;
    289     QAction *mDevicesSwitchVrdpAction;
    290     QAction *mDevicesInstallGuestToolsAction;
    291 
    292 #ifdef VBOX_WITH_DEBUGGER_GUI
    293     /* Debugger actions */
    294     QAction *mDbgStatisticsAction;
    295     QAction *mDbgCommandLineAction;
    296     QAction *mDbgLoggingAction;
    297 #endif
    298 
    299     /* Help actions */
    300     VBoxHelpActions mHelpActions;
    301 
    302     /* Widgets */
    303     VBoxConsoleView *mConsole;
    304     VBoxMiniToolBar *mMiniToolBar;
    305 #ifdef VBOX_WITH_DEBUGGER_GUI
    306     /** The handle to the debugger gui. */
    307     PDBGGUI mDbgGui;
    308     /** The virtual method table for the debugger GUI. */
    309     PCDBGGUIVT mDbgGuiVT;
    310 #endif
    311 
    312 #ifdef Q_WS_MAC
    313     QMenu *m_pDockMenu;
    314     QMenu *m_pDockSettingsMenu;
    315     QAction *m_pDockDisablePreview;
    316     QAction *m_pDockEnablePreviewMonitor;
    317 #endif /* Q_WS_MAC */
    318 
    319     /* Timer to update LEDs */
    320     QTimer *mIdleTimer;
    321 
    322     /* LEDs */
    323     QIStateIndicator *mHDLed;
    324     QIStateIndicator *mCDLed;
    325 #if 0 /* todo: allow to setup */
    326     QIStateIndicator *mFDLed;
    327 #endif
    328     QIStateIndicator *mNetLed;
    329     QIStateIndicator *mUSBLed;
    330     QIStateIndicator *mSFLed;
    331     QIStateIndicator *mVirtLed;
    332     QIStateIndicator *mMouseLed;
    333     QIStateIndicator *mHostkeyLed;
    334     QWidget *mHostkeyLedContainer;
    335     QLabel *mHostkeyName;
    336 #if 0 /* todo: allow to setup */
    337     QIStateIndicator *mVrdpLed;
    338     QIStateIndicator *mAutoresizeLed;
    339 #endif
    340 
    341     /* Normal Mode */
    342     QRect mNormalGeo;
    343 
    344     /* Fullscreen/Seamless Mode */
    345     QList < QPointer <QWidget> > mHiddenChildren;
    346     QSpacerItem *mShiftingSpacerLeft;
    347     QSpacerItem *mShiftingSpacerTop;
    348     QSpacerItem *mShiftingSpacerRight;
    349     QSpacerItem *mShiftingSpacerBottom;
    350     QPalette mErasePalette;
    351     QSize mPrevMinSize;
    352     QSize mMaskShift;
    353     QRegion mStrictedRegion;
    354 #ifdef Q_WS_WIN
    355     QRegion mPrevRegion;
    356 #endif
    357 #ifdef Q_WS_MAC
    358     //QRegion mCurrRegion;
    359 # ifndef QT_MAC_USE_COCOA
    360     //EventHandlerRef mDarwinRegionEventHandlerRef;
    361 # endif
    362     /* For seamless maximizing */
    363     QRect mNormalGeometry;
    364     Qt::WindowFlags mSavedFlags;
    365     /* For the fade effect if the the window goes fullscreen */
    366     CGDisplayFadeReservationToken mFadeToken;
    367 #endif
    368 
    369     /* Different bool flags */
    370     bool mIsOpenViewFinished : 1;
    371     bool mIsFirstTimeStarted : 1;
    372     bool mIsAutoSaveMedia : 1;
    373     bool mNoAutoClose : 1;
    374     bool mIsFullscreen : 1;
    375     bool mIsSeamless : 1;
    376     bool mIsSeamlessSupported : 1;
    377     bool mIsGraphicsSupported : 1;
    378     bool mIsWaitingModeResize : 1;
    379     bool mWasMax : 1;
     50        setCancelButtonText(tr("Cancel"));
     51        setCancelButtonToolTip(tr("Cancel the VirtualBox Guest "
     52                                  "Additions CD image download"));
     53        setProgressBarToolTip((tr("Downloading the VirtualBox Guest Additions "
     54                                  "CD image from <nobr><b>%1</b>...</nobr>")
     55                               .arg(source())));
     56    }
    38057};
    38158
    382 /* We want to make the first action highlighted but not
    383  * selected, but Qt makes the both or neither one of this,
    384  * so, just move the focus to the next eligible object,
    385  * which will be the first menu action. This little
    386  * subclass made only for that purpose. */
    387 class QIMenu : public QMenu
     59class UIDownloaderAdditions : public UIDownloader
    38860{
    38961    Q_OBJECT;
    39062
    39163public:
     64    static UIDownloaderAdditions* create();
     65    static UIDownloaderAdditions* current();
     66    static void destroy();
    39267
    393     QIMenu (QWidget *aParent) : QMenu (aParent) {}
     68    void setAction(QAction *pAction);
     69    QAction *action() const;
    39470
    395     void selectFirstAction() { QMenu::focusNextChild(); }
    396 };
     71    void setParentWidget(QWidget *pParent);
     72    QWidget *parentWidget() const;
    39773
    398 class VBoxSettingsPage;
    399 class VBoxNetworkDialog : public QIWithRetranslateUI <QDialog>
    400 {
    401     Q_OBJECT;
     74    UIMiniProcessWidgetAdditions* processWidget(QWidget *pParent = 0) const;
     75    void startDownload();
    40276
    403 public:
     77signals:
     78    void downloadFinished(const QString &strFile);
    40479
    405     VBoxNetworkDialog (QWidget *aParent, CSession &aSession);
     80private slots:
    40681
    407 protected:
    408 
    409     void retranslateUi();
    410 
    411 protected slots:
    412 
    413     virtual void accept();
    414 
    415 protected:
    416 
    417     void showEvent (QShowEvent *aEvent);
     82    void downloadFinished(bool fError);
     83    void suicide();
    41884
    41985private:
    42086
    421     VBoxSettingsPage *mSettings;
    422     CSession &mSession;
     87    UIDownloaderAdditions();
     88
     89    bool confirmDownload();
     90    void warnAboutError(const QString &strError);
     91
     92    /* Private member vars */
     93    static UIDownloaderAdditions *m_pInstance;
     94
     95    /* We use QPointer here, cause these items could be deleted in the life of
     96     * this object. QPointer guarantees that the ptr itself is zero in that
     97     * case. */
     98    QPointer<QAction> m_pAction;
     99    QPointer<QWidget> m_pParent;
    423100};
    424101
    425 class VBoxVMSettingsSF;
    426 class VBoxSFDialog : public QIWithRetranslateUI <QDialog>
    427 {
    428     Q_OBJECT;
     102#endif // __UIDownloaderAdditions_h__
    429103
    430 public:
    431 
    432     VBoxSFDialog (QWidget *aParent, CSession &aSession);
    433 
    434 protected:
    435 
    436     void retranslateUi();
    437 
    438 protected slots:
    439 
    440     virtual void accept();
    441 
    442 protected:
    443 
    444     void showEvent (QShowEvent *aEvent);
    445 
    446 private:
    447 
    448     VBoxVMSettingsSF *mSettings;
    449     CSession &mSession;
    450 };
    451 
    452 #endif // __VBoxConsoleWnd_h__
    453 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette