VirtualBox

Changeset 4043 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Aug 6, 2007 1:13:10 PM (17 years ago)
Author:
vboxsync
Message:

2142: GUI should download Additions:

  1. VBoxGADownloader class renamed to VBoxDownloaderWgt and parametrized with aURL (source) and aTarget (destination).
  2. VBoxGADownloader moved into VBoxDownloaderWgt.cpp/h files.
  3. Guest Additions file named "VBoxGuestAdditions.iso" is searched in RTPathAppPrivateNoArch()/ and qApp->applicationDirPath()/additions/ directories. After that, Guest Additions image named "VBoxGuestAdditions_<version>.iso" is searched in VBox's registered images. If the image was not found in above paths, the user will be queried to download this file.
Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 edited

Legend:

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

    r3946 r4043  
    8282        include/VBoxConsoleWnd.h \
    8383        include/VBoxConsoleView.h \
    84         include/VBoxProblemReporter.h
     84        include/VBoxProblemReporter.h \
     85        include/VBoxDownloaderWgt.h
    8586
    8687# Sources containing local definitions of classes that use the Q_OBJECT macro
    87 VirtualBox_QT_MOCSRCS = src/VBoxSelectorWnd.cpp \
    88                                                 src/VBoxConsoleWnd.cpp
     88VirtualBox_QT_MOCSRCS = src/VBoxSelectorWnd.cpp
    8989ifdef VBOX_WITH_XPCOM
    9090VirtualBox_QT_MOCSRCS += src/COMDefs.cpp
     
    141141        src/VBoxConsoleView.cpp \
    142142        src/VBoxConsoleWnd.cpp \
     143        src/VBoxDownloaderWgt.cpp \
    143144        src/VBoxVMListBox.cpp \
    144145        src/VBoxFrameBuffer.cpp
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r4033 r4043  
    2121 */
    2222
    23 #include "VBoxGlobal.h"
    24 
    2523#include "VBoxConsoleWnd.h"
    26 
    27 #include "VBoxDefs.h"
    2824#include "VBoxConsoleView.h"
    29 #include "VBoxProblemReporter.h"
    3025#include "VBoxCloseVMDlg.h"
    3126#include "VBoxTakeSnapshotDlg.h"
     
    3328#include "VBoxVMFirstRunWzd.h"
    3429#include "VBoxSharedFoldersSettings.h"
    35 #include "VBoxUtils.h"
    36 #include "VBoxMediaComboBox.h"
     30#include "VBoxDownloaderWgt.h"
    3731#include "QIStateIndicator.h"
    3832#include "QIStatusBar.h"
    3933#include "QIHotKeyEdit.h"
    4034
    41 #include <qlabel.h>
    4235#include <qaction.h>
    4336#include <qmenubar.h>
    44 #include <qpopupmenu.h>
    4537#include <qbuttongroup.h>
    4638#include <qradiobutton.h>
    47 #include <qtooltip.h>
    48 #include <qlineedit.h>
    49 #include <qtextedit.h>
    50 #include <qtooltip.h>
    5139#include <qdir.h>
    5240#include <qpushbutton.h>
    53 #include <qtoolbutton.h>
    5441#include <qcursor.h>
    55 #include <qhttp.h>
    56 #include <qprogressbar.h>
    57 
     42#include <qtimer.h>
    5843#include <qeventloop.h>
    59 
    60 #include <qlayout.h>
    61 #include <qhbox.h>
    62 
    63 #include <qtimer.h>
    6444
    6545#include <VBox/VBoxGuest.h>
     
    203183class QHttpResponseHeader;
    204184#endif
    205 
    206 /** class VBoxGADownloader
    207  *
    208  *  The VBoxGADownloader class is an QWidget class for Guest Additions
    209  *  http backgroung downloading. This class is also used to display the
    210  *  Guest Additions download state through the progress dialog integrated
    211  *  into the VM console status bar.
    212  */
    213 class VBoxGADownloader : public QWidget
    214 {
    215     Q_OBJECT
    216 
    217 public:
    218 
    219     VBoxGADownloader (QStatusBar *aStatusBar, QAction *aAction)
    220         : QWidget (0, "VBoxGADownloader")
    221         , mStatusBar (aStatusBar)
    222         , mProtocol ("http://")
    223         , mHost (QString::null), mPath (QString::null), mFile (QString::null)
    224         , mHttp (0), mIsChecking (true)
    225         , mProgressBar (0), mCancelButton (0)
    226         , mAction (aAction), mStatus (0)
    227         , mConnectDone (false), mSuicide (false)
    228     {
    229         /* Disable Install Guest Additions action */
    230         mAction->setEnabled (false);
    231 
    232         /* Drawing itself */
    233         setFixedHeight (16);
    234 
    235         mProgressBar = new QProgressBar (this);
    236         mProgressBar->setFixedWidth (100);
    237         mProgressBar->setPercentageVisible (true);
    238         mProgressBar->setProgress (0);
    239 
    240         mCancelButton = new QToolButton (this);
    241         mCancelButton->setAutoRaise (true);
    242         mCancelButton->setFocusPolicy (TabFocus);
    243         QSpacerItem *spacer = new QSpacerItem (0, 0, QSizePolicy::Expanding,
    244                                                      QSizePolicy::Fixed);
    245 
    246         QHBoxLayout *mainLayout = new QHBoxLayout (this);
    247         mainLayout->addWidget (mProgressBar);
    248         mainLayout->addWidget (mCancelButton);
    249         mainLayout->addItem (spacer);
    250 
    251         /* Select the product version */
    252         QString version = vboxGlobal().virtualBox().GetVersion();
    253 
    254         /* Select the Guest Additions image file */
    255         mHost = "www.virtualbox.org";
    256         mPath = QString ("/download/%1/").arg (version);
    257         mFile = QString ("VBoxGuestAdditions_%1.iso").arg (version);
    258 
    259 #ifndef RT_OS_DARWIN /// @todo fix the qt build on darwin.   
    260         /* Initialize url operator */
    261         mHttp = new QHttp (this, "mHttp");
    262         mHttp->setHost (mHost);
    263 
    264         /* Setup connections */
    265         connect (mHttp, SIGNAL (dataReadProgress (int, int)),
    266                  this, SLOT (processProgress (int, int)));
    267         connect (mHttp, SIGNAL (requestFinished (int, bool)),
    268                  this, SLOT (processFinished (int, bool)));
    269         connect (mHttp, SIGNAL (responseHeaderReceived (const QHttpResponseHeader&)),
    270                  this, SLOT (processResponse (const QHttpResponseHeader&)));
    271 #endif /* !RT_OS_DARWIN */ /// @todo fix the qt build on darwin.   
    272         connect (mCancelButton, SIGNAL (clicked()),
    273                  this, SLOT (processAbort()));
    274 
    275         languageChange();
    276         mStatusBar->addWidget (this);
    277 
    278         /* Try to get the required file for the information */
    279         getFile();
    280     }
    281 
    282     void languageChange()
    283     {
    284         mCancelButton->setText (tr ("Cancel"));
    285         QToolTip::add (mProgressBar, tr ("Downloading the VirtualBox Guest Additions "
    286                                          "CD image from <nobr><b>%1</b>...</nobr>")
    287                                      .arg (mProtocol + mHost + mPath + mFile));
    288         QToolTip::add (mCancelButton, tr ("Cancel the VirtualBox Guest "
    289                                           "Additions CD image download"));
    290     }
    291 
    292 private slots:
    293 
    294     /* This slot is used to handle the progress of the file-downloading
    295      * procedure. It also checks the downloading status for the file
    296      * presence verifying purposes. */
    297     void processProgress (int aRead, int aTotal)
    298     {
    299         mConnectDone = true;
    300         if (aTotal != -1)
    301         {
    302             if (mIsChecking)
    303             {
    304 #ifndef RT_OS_DARWIN /// @todo fix the qt build on darwin.   
    305                 mHttp->abort();
    306 #endif               
    307                 if (mStatus == 404)
    308                     abortDownload (tr ("Could not locate the file on "
    309                                        "the server (response: %1).")
    310                                    .arg (mStatus));
    311                 else
    312                     processFile (aTotal);
    313             }
    314             else
    315                 mProgressBar->setProgress (aRead, aTotal);
    316         }
    317         else
    318             abortDownload (tr ("Could not determine the file size."));
    319     }
    320 
    321     /* This slot is used to handle the finish signal of every operation's
    322      * response. It is used to display the errors occurred during the download
    323      * operation and for the received-buffer serialization procedure. */
    324     void processFinished (int, bool aError)
    325     {
    326 #ifndef RT_OS_DARWIN /// @todo fix the qt build on darwin.   
    327         if (aError && mHttp->error() != QHttp::Aborted)
    328         {
    329             mConnectDone = true;
    330             QString reason = mIsChecking ?
    331                 tr ("Could not connect to the server (%1).") :
    332                 tr ("Could not download the file (%1).");
    333             abortDownload (reason.arg (mHttp->errorString()));
    334         }
    335         else if (!aError && !mIsChecking)
    336         {
    337             mHttp->abort();
    338             /* Serialize the incoming buffer into the .iso image. */
    339             QString path = QDir (QDir::home()).absFilePath (mFile);
    340             QFile file (path);
    341             if (file.open (IO_WriteOnly))
    342             {
    343                 file.writeBlock (mHttp->readAll());
    344                 file.close();
    345                 int rc = vboxProblem().confirmMountAdditions (mProtocol + mHost +
    346                                   mPath + mFile, QDir::convertSeparators (path));
    347                 if (rc == QIMessageBox::Yes)
    348                     vboxGlobal().consoleWnd().installGuestAdditionsFrom (path);
    349                 QTimer::singleShot (0, this, SLOT (suicide()));
    350             }
    351             else
    352                 abortDownload (tr ("Could not save the downloaded file as "
    353                                    "<nobr><b>%1</b></nobr>.")
    354                                .arg (QDir::convertSeparators (path)));
    355         }
    356 #else
    357         NOREF (aError);
    358 #endif /* !RT_OS_DARWIN */       
    359     }
    360 
    361     /* This slot is used to handle the header responses about the
    362      * requested operations. Watches for the header's status-code. */
    363     void processResponse (const QHttpResponseHeader &aHeader)
    364     {
    365 #ifndef RT_OS_DARWIN /// @todo fix the qt build on darwin.   
    366         mStatus = aHeader.statusCode();
    367 #else
    368         NOREF(aHeader);
    369 #endif
    370     }
    371 
    372     /* This slot is used to control the connection timeout. */
    373     void processTimeout()
    374     {
    375         if (mConnectDone)
    376             return;
    377 #ifndef RT_OS_DARWIN /// @todo fix the qt build on darwin.   
    378         mHttp->abort();
    379         abortDownload (tr ("Connection timed out."));
    380 #endif       
    381     }
    382 
    383     /* This slot is used to process cancel-button clicking signal. */
    384     void processAbort()
    385     {
    386 #ifndef RT_OS_DARWIN /// @todo fix the qt build on darwin.   
    387         mConnectDone = true;
    388         mHttp->abort();
    389         abortDownload (tr ("The download process has been cancelled "
    390                            "by the user."));
    391 #endif       
    392     }
    393 
    394     /* This slot is used to terminate the downloader, activate the
    395      * Install Guest Additions action and removing the downloader's
    396      * sub-widgets from the VM Console status-bar. */
    397     void suicide()
    398     {
    399         mAction->setEnabled (true);
    400         mStatusBar->removeWidget (this);
    401         delete this;
    402     }
    403 
    404 private:
    405 
    406     /* This function is used to make a request to get a file */
    407     void getFile()
    408     {
    409         mConnectDone = false;
    410 #ifndef RT_OS_DARWIN /// @todo fix the qt build on darwin.   
    411         mHttp->get (mPath + mFile);
    412 #endif       
    413         QTimer::singleShot (5000, this, SLOT (processTimeout()));
    414     }
    415 
    416     /* This function is used to ask the user about he wants to download the
    417      * founded Guest Additions image or not. It also shows the progress-bar
    418      * and Cancel-button widgets. */
    419     void processFile (int aSize)
    420     {
    421         /* Ask user about GA image downloading */
    422         int rc = vboxProblem().
    423             confirmDownloadAdditions (mProtocol + mHost + mPath + mFile, aSize);
    424         if (rc == QIMessageBox::Yes)
    425         {
    426             mIsChecking = false;
    427             getFile();
    428         }
    429         else
    430             abortDownload();
    431     }
    432 
    433     /* This wrapper displays an error message box (unless @aReason is
    434      * QString::null) with the cause of the download procedure
    435      * termination. After the message box is dismissed, the downloader signals
    436      * to close itself on the next event loop iteration. */
    437     void abortDownload (const QString &aReason = QString::null)
    438     {
    439         /* Protect against double kill request. */
    440         if (mSuicide)
    441             return;
    442         mSuicide = true;
    443 
    444         if (!aReason.isNull())
    445             vboxProblem().cannotDownloadGuestAdditions (mProtocol + mHost +
    446                                                         mPath + mFile, aReason);
    447         /* Allows all the queued signals to be processed before quit. */
    448         QTimer::singleShot (0, this, SLOT (suicide()));
    449     }
    450 
    451     QStatusBar *mStatusBar;
    452     QString mProtocol;
    453     QString mHost;
    454     QString mPath;
    455     QString mFile;
    456     QHttp *mHttp;
    457     bool mIsChecking;
    458     QProgressBar *mProgressBar;
    459     QToolButton *mCancelButton;
    460     QAction *mAction;
    461     int mStatus;
    462     bool mConnectDone;
    463     bool mSuicide;
    464 };
    465185
    466186/** \class VBoxConsoleWnd
     
    25672287    QString src2 = qApp->applicationDirPath() + "/../../release/bin/additions/VBoxGuestAdditions.iso";
    25682288#else
    2569     char szAppPrivPath[RTPATH_MAX];
     2289    char szAppPrivPath [RTPATH_MAX];
    25702290    int rc;
    25712291
    2572     rc = RTPathAppPrivateNoArch(szAppPrivPath, sizeof(szAppPrivPath));
    2573     Assert(RT_SUCCESS(rc));
    2574 
    2575     QString src1 = QString(szAppPrivPath) + "/VBoxGuestAdditions.iso";
     2292    rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath));
     2293    Assert (RT_SUCCESS (rc));
     2294
     2295    QString src1 = QString (szAppPrivPath) + "/VBoxGuestAdditions.iso";
    25762296    QString src2 = qApp->applicationDirPath() + "/additions/VBoxGuestAdditions.iso";
    25772297#endif
     
    25832303    else
    25842304    {
     2305        /* Check for the already registered required image: */
     2306        CVirtualBox vbox = vboxGlobal().virtualBox();
     2307        QString iName = QString ("VBoxGuestAdditions_%1.iso")
     2308                                 .arg (vbox.GetVersion());
     2309        CDVDImageEnumerator en = vbox.GetDVDImages().Enumerate();
     2310        while (en.HasMore())
     2311        {
     2312            QString path = en.GetNext().GetFilePath();
     2313            if (path.find (iName) != -1 && QFile::exists (path))
     2314                return installGuestAdditionsFrom (path);
     2315        }
     2316        /* Download required image: */
    25852317        int rc = vboxProblem().cannotFindGuestAdditions (
    25862318            QDir::convertSeparators (src1), QDir::convertSeparators (src2));
    25872319        if (rc == QIMessageBox::Yes)
    2588             new VBoxGADownloader (statusBar(), devicesInstallGuestToolsAction);
     2320        {
     2321            QString url = QString ("http://www.virtualbox.org/download/%1/")
     2322                                   .arg (vbox.GetVersion()) + iName;
     2323            QString target = QDir (vboxGlobal().virtualBox().GetHomeFolder())
     2324                                   .absFilePath (iName);
     2325
     2326            new VBoxDownloaderWgt (statusBar(), devicesInstallGuestToolsAction,
     2327                                   url, target);
     2328        }
    25892329    }
    25902330}
     
    25932333{
    25942334    CVirtualBox vbox = vboxGlobal().virtualBox();
    2595 
    2596     QString src (aSource);
    25972335    QUuid uuid;
    2598     CDVDImage newImage = vbox.OpenDVDImage (src, uuid);
    2599     if (vbox.isOk())
    2600     {
    2601         src = newImage.GetFilePath();
    2602         CDVDImage oldImage = vbox.FindDVDImage(src);
    2603         if (oldImage.isNull())
    2604             vbox.RegisterDVDImage (newImage);
    2605         else
    2606             newImage = oldImage;
     2336
     2337    CDVDImage image = vbox.FindDVDImage (aSource);
     2338    if (image.isNull())
     2339    {
     2340        image = vbox.OpenDVDImage (aSource, uuid);
    26072341        if (vbox.isOk())
    2608             uuid = newImage.GetId();
    2609     }
     2342            vbox.RegisterDVDImage (image);
     2343        if (vbox.isOk())
     2344            uuid = image.GetId();
     2345    }
     2346    else
     2347        uuid = image.GetId();
     2348
    26102349    if (!vbox.isOk())
    26112350    {
    2612         vboxProblem().cannotRegisterMedia (this, vbox, VBoxDefs::CD, src);
     2351        vboxProblem().cannotRegisterMedia (this, vbox, VBoxDefs::CD, aSource);
    26132352        return;
    26142353    }
     2354
     2355    Assert (!uuid.isNull());
    26152356    CDVDDrive drv = csession.GetMachine().GetDVDDrive();
    26162357    drv.MountImage (uuid);
     
    32623003    QDialog::showEvent (aEvent);
    32633004}
    3264 
    3265 #include "VBoxConsoleWnd.moc"
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