- Timestamp:
- Aug 13, 2008 4:46:39 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 34690
- Location:
- trunk/src/VBox/Frontends/VirtualBox4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxNetworkFramework.h
r8155 r11401 29 29 #include <QThread> 30 30 #include <QDataStream> 31 #include <QStringList> 31 32 32 33 typedef happyhttp::Connection HConnect; … … 52 53 } 53 54 54 void postRequest (const QString &aHost, const QString &aUrl); 55 void postRequest (const QString &aHost, const QString &aUrl, const QString &aBody, 56 const QStringList &aHeaders = QStringList()); 55 57 56 58 signals: -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxRegistrationDlg.h
r9729 r11401 70 70 private: 71 71 72 void postRequest (const QString &aHost, const QString &a Path);72 void postRequest (const QString &aHost, const QString &aUrl, const QString &aBody); 73 73 void abortRegisterRequest (const QString &aReason); 74 QString getPlatform();75 74 void finish(); 76 75 -
trunk/src/VBox/Frontends/VirtualBox4/include/VBoxUpdateDlg.h
r10611 r11401 127 127 128 128 /* Private functions */ 129 void searchAbort (const QString &aReason);130 void searchComplete (const QString &aFullList);129 void networkAbort (const QString &aReason); 130 void processResponse (const QString &aResponse); 131 131 132 132 /* Private variables */ -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxNetworkFramework.cpp
r8155 r11401 132 132 133 133 void VBoxNetworkFramework::postRequest (const QString &aHost, 134 const QString &aUrl) 134 const QString &aUrl, 135 const QString &aBody, 136 const QStringList &aHeaders) 135 137 { 136 138 /* Network requests thread class */ … … 139 141 public: 140 142 141 Thread (QObject *aProc, const QString &aHost, const QString &aUrl) 142 : mProc (aProc), mHost (aHost), mUrl (aUrl) {} 143 Thread (QObject *aHandler, const QString &aHost, const QString &aUrl, 144 const QString &aBody, const QStringList &aHeaders) 145 : mHandler (aHandler), mHost (aHost), mUrl (aUrl) 146 , mBody (aBody), mHeaders (aHeaders) {} 143 147 144 148 virtual void run() … … 146 150 try 147 151 { 152 /* Create & setup connection */ 148 153 HConnect conn (mHost.toAscii().constData(), 80); 149 conn.setcallbacks (onBegin, onData, onFinish, mProc); 150 const char *headers[] = 151 { 152 "Connection", "close", 153 "Content-type", "application/x-www-form-urlencoded", 154 "Accept", "text/plain", 155 0 156 }; 157 158 conn.request ("POST", mUrl.toAscii().constData(), headers, 0, 0); 154 conn.setcallbacks (onBegin, onData, onFinish, mHandler); 155 156 /* Format POST request */ 157 conn.putrequest ("POST", mUrl.toAscii().constData()); 158 159 /* Append standard headers */ 160 conn.putheader ("Connection", "close"); 161 conn.putheader ("Content-Length", mBody.size()); 162 conn.putheader ("Content-type", "application/x-www-form-urlencoded"); 163 conn.putheader ("Accept", "text/plain"); 164 165 /* Append additional headers */ 166 for (int i = 0; i < mHeaders.size(); i = i + 2) 167 conn.putheader (mHeaders [i].toAscii().constData(), 168 mHeaders [i + 1].toAscii().constData()); 169 170 /* Finishing header */ 171 conn.endheaders(); 172 173 /* Append & send body */ 174 conn.send ((const unsigned char*) mBody.toAscii().constData(), 175 mBody.toAscii().size()); 176 177 /* Pull the connection for response */ 159 178 while (conn.outstanding()) 160 179 conn.pump(); … … 162 181 catch (happyhttp::Wobbly &ex) 163 182 { 164 QApplication::postEvent (m Proc, new PostErrorEvent (ex.what()));183 QApplication::postEvent (mHandler, new PostErrorEvent (ex.what())); 165 184 } 166 185 } … … 168 187 private: 169 188 170 QObject *mProc; 171 QString mHost; 172 QString mUrl; 189 QObject *mHandler; 190 QString mHost; 191 QString mUrl; 192 QString mBody; 193 QStringList mHeaders; 173 194 }; 174 195 … … 176 197 mNetworkThread->wait (1000); 177 198 delete mNetworkThread; 178 mNetworkThread = new Thread (this, aHost, aUrl );199 mNetworkThread = new Thread (this, aHost, aUrl, aBody, aHeaders); 179 200 mNetworkThread->start(); 180 201 } -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxRegistrationDlg.cpp
r11388 r11401 332 332 333 333 /* Handshake */ 334 QString argument = QString ("?version=%1").arg (version);335 postRequest (mUrl.host(), mUrl.path() + argument);334 QString body = QString ("version=%1").arg (version); 335 postRequest (mUrl.host(), mUrl.path(), body); 336 336 } 337 337 … … 341 341 mHandshake = false; 342 342 QString version = vboxGlobal().virtualBox().GetVersion(); 343 QString platform = getPlatform();343 QString platform = vboxGlobal().platformInfo(); 344 344 QString name = mLeName->text(); 345 345 QString email = mLeEmail->text(); … … 351 351 352 352 /* Registration */ 353 QString argument;354 argument += QString ("?version=%1").arg (version);355 argument+= QString ("&key=%1").arg (mKey);356 argument+= QString ("&platform=%1").arg (platform);357 argument+= QString ("&name=%1").arg (name);358 argument+= QString ("&email=%1").arg (email);359 argument+= QString ("&private=%1").arg (prvt);360 361 postRequest (mUrl.host(), mUrl.path() + argument);353 QString body; 354 body += QString ("version=%1").arg (version); 355 body += QString ("&key=%1").arg (mKey); 356 body += QString ("&platform=%1").arg (platform); 357 body += QString ("&name=%1").arg (name); 358 body += QString ("&email=%1").arg (email); 359 body += QString ("&private=%1").arg (prvt); 360 361 postRequest (mUrl.host(), mUrl.path(), body); 362 362 } 363 363 … … 442 442 443 443 void VBoxRegistrationDlg::postRequest (const QString &aHost, 444 const QString &aPath) 444 const QString &aUrl, 445 const QString &aBody) 445 446 { 446 447 delete mNetfw; … … 455 456 SLOT (onNetError (const QString&))); 456 457 mTimeout->start (MaxWaitTime); 457 mNetfw->postRequest (aHost, a Path);458 mNetfw->postRequest (aHost, aUrl, aBody); 458 459 } 459 460 … … 475 476 } 476 477 477 QString VBoxRegistrationDlg::getPlatform()478 {479 QString platform;480 481 #if defined (Q_OS_WIN)482 platform = "win";483 #elif defined (Q_OS_LINUX)484 platform = "linux";485 #elif defined (Q_OS_MACX)486 platform = "macosx";487 #elif defined (Q_OS_OS2)488 platform = "os2";489 #elif defined (Q_OS_FREEBSD)490 platform = "freebsd";491 #elif defined (Q_OS_SOLARIS)492 platform = "solaris";493 #else494 platform = "unknown";495 #endif496 497 /* the format is <system>.<bitness> */498 platform += QString (".%1").arg (ARCH_BITS);499 500 /* add more system information */501 #if defined (Q_OS_WIN)502 OSVERSIONINFO versionInfo;503 ZeroMemory (&versionInfo, sizeof (OSVERSIONINFO));504 versionInfo.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);505 GetVersionEx (&versionInfo);506 int major = versionInfo.dwMajorVersion;507 int minor = versionInfo.dwMinorVersion;508 int build = versionInfo.dwBuildNumber;509 QString sp = QString::fromUtf16 ((ushort*)versionInfo.szCSDVersion);510 511 QString distrib;512 if (major == 6)513 distrib = QString ("Windows Vista %1");514 else if (major == 5)515 {516 if (minor == 2)517 distrib = QString ("Windows Server 2003 %1");518 else if (minor == 1)519 distrib = QString ("Windows XP %1");520 else if (minor == 0)521 distrib = QString ("Windows 2000 %1");522 else523 distrib = QString ("Unknown %1");524 }525 else if (major == 4)526 {527 if (minor == 90)528 distrib = QString ("Windows Me %1");529 else if (minor == 10)530 distrib = QString ("Windows 98 %1");531 else if (minor == 0)532 distrib = QString ("Windows 95 %1");533 else534 distrib = QString ("Unknown %1");535 }536 else537 distrib = QString ("Unknown %1");538 distrib = distrib.arg (sp);539 QString version = QString ("%1.%2").arg (major).arg (minor);540 QString kernel = QString ("%1").arg (build);541 platform += QString (" [Distribution: %1 | Version: %2 | Build: %3]")542 .arg (distrib).arg (version).arg (kernel);543 #elif defined (Q_OS_OS2)544 // TODO: add sys info for os2 if any...545 #elif defined (Q_OS_LINUX) || defined (Q_OS_MACX) || defined (Q_OS_FREEBSD) || defined (Q_OS_SOLARIS)546 /* Get script path */547 char szAppPrivPath [RTPATH_MAX];548 int rc = RTPathAppPrivateNoArch (szAppPrivPath, sizeof (szAppPrivPath));549 Assert (RT_SUCCESS (rc));550 /* Run script */551 QByteArray result =552 Process::singleShot (QString (szAppPrivPath) + "/VBoxSysInfo.sh");553 if (!result.isNull())554 platform += QString (" [%1]").arg (QString (result).trimmed());555 #endif556 return platform;557 }558 559 478 void VBoxRegistrationDlg::finish() 560 479 { -
trunk/src/VBox/Frontends/VirtualBox4/src/VBoxUpdateDlg.cpp
r11186 r11401 221 221 , mNetfw (0) 222 222 , mTimeout (new QTimer (this)) 223 , mUrl ("http:// www.virtualbox.org/download/latest_version")223 , mUrl ("http://innotek.de/query.php") 224 224 , mForceRun (aForceRun) 225 225 , mSuicide (false) … … 284 284 void VBoxUpdateDlg::search() 285 285 { 286 /* Show progress bar */ 287 mPbCheck->show(); 288 289 /* Start downloading latest releases file */ 286 /* Create & setup network framework */ 290 287 mNetfw = new VBoxNetworkFramework(); 291 288 connect (mNetfw, SIGNAL (netBegin (int)), … … 297 294 connect (mNetfw, SIGNAL (netError (const QString&)), 298 295 SLOT (onNetError (const QString&))); 296 297 QString body = QString ("platform=%1") 298 .arg (vboxGlobal().virtualBox().GetPackageType()); 299 QStringList header ("User-Agent"); 300 header << QString ("VirtualBox %1 <%2>") 301 .arg (vboxGlobal().virtualBox().GetVersion()) 302 .arg (vboxGlobal().platformInfo()); 303 304 /* Show progress bar & send composed information */ 305 mPbCheck->show(); 299 306 mTimeout->start (MaxWaitTime); 300 mNetfw->postRequest (mUrl.host(), mUrl.path() );307 mNetfw->postRequest (mUrl.host(), mUrl.path(), body, header); 301 308 } 302 309 … … 309 316 void VBoxUpdateDlg::processTimeout() 310 317 { 311 searchAbort (tr ("Connection timed out."));318 networkAbort (tr ("Connection timed out.")); 312 319 } 313 320 … … 318 325 319 326 if (aStatus == 404) 320 searchAbort (tr ("Could not locate the latest version "327 networkAbort (tr ("Could not locate the latest version " 321 328 "list on the server (response: %1).").arg (aStatus)); 322 329 else … … 338 345 339 346 mTimeout->stop(); 340 searchComplete (aTotalData);347 processResponse (aTotalData); 341 348 } 342 349 … … 344 351 void VBoxUpdateDlg::onNetError (const QString &aError) 345 352 { 346 searchAbort (aError);353 networkAbort (aError); 347 354 } 348 355 … … 355 362 } 356 363 357 void VBoxUpdateDlg:: searchAbort (const QString &aReason)364 void VBoxUpdateDlg::networkAbort (const QString &aReason) 358 365 { 359 366 /* Protect against double kill request. */ … … 380 387 } 381 388 382 void VBoxUpdateDlg:: searchComplete (const QString &aFullList)389 void VBoxUpdateDlg::processResponse (const QString &aResponse) 383 390 { 384 391 /* Hide progress bar */ 385 392 mPbCheck->hide(); 386 393 387 QStringList list = aFullList.split ("\n", QString::SkipEmptyParts); 388 389 QString latestVersion (list [0]); 390 latestVersion.remove (QRegExp ("Version: ")); 391 QString currentVersion (vboxGlobal().virtualBox().GetVersion()); 392 VBoxVersion cv (currentVersion); 393 VBoxVersion lv (latestVersion); 394 395 if (cv < lv) 396 { 397 /* Search for the current platform link */ 398 QString packageType = vboxGlobal().virtualBox().GetPackageType(); 399 for (int i = 1; i < list.size(); ++ i) 400 { 401 QStringList platformInfo = list [i].split (": "); 402 if (packageType == platformInfo [0]) 403 { 404 /* If newer version of necessary package found */ 405 if (isHidden()) 406 { 407 /* For background update */ 408 vboxProblem().showUpdateSuccess (vboxGlobal().mainWindow(), 409 lv.toString(), platformInfo [1]); 410 QTimer::singleShot (0, this, SLOT (accept())); 411 } 412 else 413 { 414 /* For wizard update */ 415 mTextSuccessInfo->setText (mTextSuccessInfo->text() 416 .arg (lv.toString(), platformInfo [1], platformInfo [1])); 417 mTextSuccessInfo->show(); 418 mPageStack->setCurrentIndex (1); 419 } 420 return; 421 } 422 } 423 } 424 425 /* If no newer version of necessary package found */ 426 if (isHidden()) 427 { 428 /* For background update */ 429 if (mForceRun) 430 vboxProblem().showUpdateNotFound (vboxGlobal().mainWindow()); 431 QTimer::singleShot (0, this, SLOT (accept())); 432 } 433 else 434 { 435 /* For wizard update */ 436 mTextNotFoundInfo->show(); 437 mPageStack->setCurrentIndex (1); 438 } 439 } 440 394 if (aResponse.indexOf (QRegExp ("^\\d+\\.\\d+\\.\\d+ \\S+$")) == 0) 395 { 396 /* Newer version of necessary package found */ 397 QStringList response = aResponse.split (" ", QString::SkipEmptyParts); 398 399 if (isHidden()) 400 { 401 /* For background update */ 402 vboxProblem().showUpdateSuccess (vboxGlobal().mainWindow(), 403 response [0], response [1]); 404 QTimer::singleShot (0, this, SLOT (accept())); 405 } 406 else 407 { 408 /* For wizard update */ 409 mTextSuccessInfo->setText (mTextSuccessInfo->text() 410 .arg (response [0], response [1], response [1])); 411 mTextSuccessInfo->show(); 412 mPageStack->setCurrentIndex (1); 413 } 414 } 415 else /* if (aResponse == "UPTODATE") */ 416 { 417 /* No newer version of necessary package found */ 418 if (isHidden()) 419 { 420 /* For background update */ 421 if (mForceRun) 422 vboxProblem().showUpdateNotFound (vboxGlobal().mainWindow()); 423 QTimer::singleShot (0, this, SLOT (accept())); 424 } 425 else 426 { 427 /* For wizard update */ 428 mTextNotFoundInfo->show(); 429 mPageStack->setCurrentIndex (1); 430 } 431 } 432 } 433
Note:
See TracChangeset
for help on using the changeset viewer.