Changeset 4043 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Aug 6, 2007 1:13:10 PM (17 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
r3946 r4043 82 82 include/VBoxConsoleWnd.h \ 83 83 include/VBoxConsoleView.h \ 84 include/VBoxProblemReporter.h 84 include/VBoxProblemReporter.h \ 85 include/VBoxDownloaderWgt.h 85 86 86 87 # Sources containing local definitions of classes that use the Q_OBJECT macro 87 VirtualBox_QT_MOCSRCS = src/VBoxSelectorWnd.cpp \ 88 src/VBoxConsoleWnd.cpp 88 VirtualBox_QT_MOCSRCS = src/VBoxSelectorWnd.cpp 89 89 ifdef VBOX_WITH_XPCOM 90 90 VirtualBox_QT_MOCSRCS += src/COMDefs.cpp … … 141 141 src/VBoxConsoleView.cpp \ 142 142 src/VBoxConsoleWnd.cpp \ 143 src/VBoxDownloaderWgt.cpp \ 143 144 src/VBoxVMListBox.cpp \ 144 145 src/VBoxFrameBuffer.cpp -
trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp
r4033 r4043 21 21 */ 22 22 23 #include "VBoxGlobal.h"24 25 23 #include "VBoxConsoleWnd.h" 26 27 #include "VBoxDefs.h"28 24 #include "VBoxConsoleView.h" 29 #include "VBoxProblemReporter.h"30 25 #include "VBoxCloseVMDlg.h" 31 26 #include "VBoxTakeSnapshotDlg.h" … … 33 28 #include "VBoxVMFirstRunWzd.h" 34 29 #include "VBoxSharedFoldersSettings.h" 35 #include "VBoxUtils.h" 36 #include "VBoxMediaComboBox.h" 30 #include "VBoxDownloaderWgt.h" 37 31 #include "QIStateIndicator.h" 38 32 #include "QIStatusBar.h" 39 33 #include "QIHotKeyEdit.h" 40 34 41 #include <qlabel.h>42 35 #include <qaction.h> 43 36 #include <qmenubar.h> 44 #include <qpopupmenu.h>45 37 #include <qbuttongroup.h> 46 38 #include <qradiobutton.h> 47 #include <qtooltip.h>48 #include <qlineedit.h>49 #include <qtextedit.h>50 #include <qtooltip.h>51 39 #include <qdir.h> 52 40 #include <qpushbutton.h> 53 #include <qtoolbutton.h>54 41 #include <qcursor.h> 55 #include <qhttp.h> 56 #include <qprogressbar.h> 57 42 #include <qtimer.h> 58 43 #include <qeventloop.h> 59 60 #include <qlayout.h>61 #include <qhbox.h>62 63 #include <qtimer.h>64 44 65 45 #include <VBox/VBoxGuest.h> … … 203 183 class QHttpResponseHeader; 204 184 #endif 205 206 /** class VBoxGADownloader207 *208 * The VBoxGADownloader class is an QWidget class for Guest Additions209 * http backgroung downloading. This class is also used to display the210 * Guest Additions download state through the progress dialog integrated211 * into the VM console status bar.212 */213 class VBoxGADownloader : public QWidget214 {215 Q_OBJECT216 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-downloading295 * procedure. It also checks the downloading status for the file296 * 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 #endif307 if (mStatus == 404)308 abortDownload (tr ("Could not locate the file on "309 "the server (response: %1).")310 .arg (mStatus));311 else312 processFile (aTotal);313 }314 else315 mProgressBar->setProgress (aRead, aTotal);316 }317 else318 abortDownload (tr ("Could not determine the file size."));319 }320 321 /* This slot is used to handle the finish signal of every operation's322 * response. It is used to display the errors occurred during the download323 * 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 else352 abortDownload (tr ("Could not save the downloaded file as "353 "<nobr><b>%1</b></nobr>.")354 .arg (QDir::convertSeparators (path)));355 }356 #else357 NOREF (aError);358 #endif /* !RT_OS_DARWIN */359 }360 361 /* This slot is used to handle the header responses about the362 * 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 #else368 NOREF(aHeader);369 #endif370 }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 #endif381 }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 #endif392 }393 394 /* This slot is used to terminate the downloader, activate the395 * Install Guest Additions action and removing the downloader's396 * 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 #endif413 QTimer::singleShot (5000, this, SLOT (processTimeout()));414 }415 416 /* This function is used to ask the user about he wants to download the417 * founded Guest Additions image or not. It also shows the progress-bar418 * 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 else430 abortDownload();431 }432 433 /* This wrapper displays an error message box (unless @aReason is434 * QString::null) with the cause of the download procedure435 * termination. After the message box is dismissed, the downloader signals436 * 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 };465 185 466 186 /** \class VBoxConsoleWnd … … 2567 2287 QString src2 = qApp->applicationDirPath() + "/../../release/bin/additions/VBoxGuestAdditions.iso"; 2568 2288 #else 2569 char szAppPrivPath [RTPATH_MAX];2289 char szAppPrivPath [RTPATH_MAX]; 2570 2290 int rc; 2571 2291 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"; 2576 2296 QString src2 = qApp->applicationDirPath() + "/additions/VBoxGuestAdditions.iso"; 2577 2297 #endif … … 2583 2303 else 2584 2304 { 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: */ 2585 2317 int rc = vboxProblem().cannotFindGuestAdditions ( 2586 2318 QDir::convertSeparators (src1), QDir::convertSeparators (src2)); 2587 2319 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 } 2589 2329 } 2590 2330 } … … 2593 2333 { 2594 2334 CVirtualBox vbox = vboxGlobal().virtualBox(); 2595 2596 QString src (aSource);2597 2335 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); 2607 2341 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 2610 2349 if (!vbox.isOk()) 2611 2350 { 2612 vboxProblem().cannotRegisterMedia (this, vbox, VBoxDefs::CD, src);2351 vboxProblem().cannotRegisterMedia (this, vbox, VBoxDefs::CD, aSource); 2613 2352 return; 2614 2353 } 2354 2355 Assert (!uuid.isNull()); 2615 2356 CDVDDrive drv = csession.GetMachine().GetDVDDrive(); 2616 2357 drv.MountImage (uuid); … … 3262 3003 QDialog::showEvent (aEvent); 3263 3004 } 3264 3265 #include "VBoxConsoleWnd.moc"
Note:
See TracChangeset
for help on using the changeset viewer.