- Timestamp:
- Apr 1, 2013 10:40:35 AM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/globals
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
r45268 r45269 284 284 } 285 285 286 bool UIMessageCenter::askForOverridingFile(const QString& strPath, QWidget *pParent /* = NULL */)287 {288 return messageYesNo(pParent, MessageType_Question, tr("A file named <b>%1</b> already exists. Are you sure you want to replace it?<br /><br />Replacing it will overwrite its contents.").arg(strPath));289 }290 291 bool UIMessageCenter::askForOverridingFiles(const QVector<QString>& strPaths, QWidget *pParent /* = NULL */)292 {293 if (strPaths.size() == 1)294 /* If it is only one file use the single question versions above */295 return askForOverridingFile(strPaths.at(0), pParent);296 else if (strPaths.size() > 1)297 return messageYesNo(pParent, MessageType_Question, tr("The following files already exist:<br /><br />%1<br /><br />Are you sure you want to replace them? Replacing them will overwrite their contents.").arg(QStringList(strPaths.toList()).join("<br />")));298 else299 return true;300 }301 302 bool UIMessageCenter::askForOverridingFileIfExists(const QString& strPath, QWidget *pParent /* = NULL */)303 {304 QFileInfo fi(strPath);305 if (fi.exists())306 return askForOverridingFile(strPath, pParent);307 else308 return true;309 }310 311 bool UIMessageCenter::askForOverridingFilesIfExists(const QVector<QString>& strPaths, QWidget *pParent /* = NULL */)312 {313 QVector<QString> existingFiles;314 foreach(const QString &file, strPaths)315 {316 QFileInfo fi(file);317 if (fi.exists())318 existingFiles << fi.absoluteFilePath();319 }320 if (existingFiles.size() == 1)321 /* If it is only one file use the single question versions above */322 return askForOverridingFileIfExists(existingFiles.at(0), pParent);323 else if (existingFiles.size() > 1)324 return askForOverridingFiles(existingFiles, pParent);325 else326 return true;327 }328 329 286 #ifdef RT_OS_LINUX 330 287 void UIMessageCenter::warnAboutWrongUSBMounted() … … 340 297 void UIMessageCenter::cannotStartSelector() 341 298 { 342 message( mainWindowShown(), MessageType_Critical,299 message(0, MessageType_Critical, 343 300 tr("<p>Cannot start VirtualBox Manager due to local restrictions.</p>" 344 301 "<p>The application will now terminate.</p>")); … … 347 304 void UIMessageCenter::showBETAWarning() 348 305 { 349 message 350 (0, MessageType_Warning, 351 tr("You are running a prerelease version of VirtualBox. " 352 "This version is not suitable for production use.")); 306 message(0, MessageType_Warning, 307 tr("You are running a prerelease version of VirtualBox. " 308 "This version is not suitable for production use.")); 353 309 } 354 310 355 311 void UIMessageCenter::showBEBWarning() 356 312 { 357 message 358 (0, MessageType_Warning, 359 tr("You are running an EXPERIMENTAL build of VirtualBox. " 360 "This version is not suitable for production use.")); 313 message(0, MessageType_Warning, 314 tr("You are running an EXPERIMENTAL build of VirtualBox. " 315 "This version is not suitable for production use.")); 316 } 317 318 void UIMessageCenter::cannotInitUserHome(const QString &strUserHome) 319 { 320 message(0, MessageType_Critical, 321 tr("<p>Failed to initialize COM because the VirtualBox global " 322 "configuration directory <b><nobr>%1</nobr></b> is not accessible. " 323 "Please check the permissions of this directory and of its parent directory.</p>" 324 "<p>The application will now terminate.</p>").arg(strUserHome), 325 formatErrorInfo(COMErrorInfo())); 361 326 } 362 327 … … 364 329 { 365 330 message(0, MessageType_Critical, 366 tr("<p>Failed to initialize COM or to find the VirtualBox COM server. " 367 "Most likely, the VirtualBox server is not running " 368 "or failed to start.</p>" 369 "<p>The application will now terminate.</p>"), 370 formatErrorInfo(COMErrorInfo(), rc)); 371 } 372 373 void UIMessageCenter::cannotInitUserHome(const QString &strUserHome) 331 tr("<p>Failed to initialize COM or to find the VirtualBox COM server. " 332 "Most likely, the VirtualBox server is not running or failed to start.</p>" 333 "<p>The application will now terminate.</p>"), 334 formatErrorInfo(COMErrorInfo(), rc)); 335 } 336 337 void UIMessageCenter::cannotCreateVirtualBox(const CVirtualBox &vbox) 374 338 { 375 339 message(0, MessageType_Critical, 376 tr("<p>Failed to initialize COM because the VirtualBox global " 377 "configuration directory <b><nobr>%1</nobr></b> is not accessible. " 378 "Please check the permissions of this directory and of its parent " 379 "directory.</p>" 380 "<p>The application will now terminate.</p>").arg(strUserHome), 381 formatErrorInfo(COMErrorInfo())); 382 } 383 384 void UIMessageCenter::cannotCreateVirtualBox(const CVirtualBox &vbox) 385 { 386 message(0, MessageType_Critical, 387 tr("<p>Failed to create the VirtualBox COM object.</p>" 388 "<p>The application will now terminate.</p>"), 389 formatErrorInfo(vbox)); 390 } 391 392 #ifdef Q_WS_X11 393 void UIMessageCenter::cannotFindLicenseFiles(const QString &strPath) 394 { 395 message 396 (0, MessageType_Error, 397 tr("Failed to find license files in " 398 "<nobr><b>%1</b></nobr>.") 399 .arg(strPath)); 400 } 401 #endif /* Q_WS_X11 */ 402 403 void UIMessageCenter::cannotOpenLicenseFile(QWidget *pParent, const QString &strPath) 404 { 405 message 406 (pParent, MessageType_Error, 407 tr("Failed to open the license file <nobr><b>%1</b></nobr>. " 408 "Check file permissions.") 409 .arg(strPath)); 340 tr("<p>Failed to create the VirtualBox COM object.</p>" 341 "<p>The application will now terminate.</p>"), 342 formatErrorInfo(vbox)); 410 343 } 411 344 … … 2472 2405 } 2473 2406 2407 void UIMessageCenter::cannotOpenLicenseFile(QWidget *pParent, const QString &strPath) 2408 { 2409 message(pParent, MessageType_Error, 2410 tr("Failed to open the license file <nobr><b>%1</b></nobr>. " 2411 "Check file permissions.").arg(strPath)); 2412 } 2413 2414 bool UIMessageCenter::askForOverridingFile(const QString &strPath, QWidget *pParent /* = 0 */) 2415 { 2416 return messageYesNo(pParent, MessageType_Question, 2417 tr("A file named <b>%1</b> already exists. " 2418 "Are you sure you want to replace it?<br /><br />" 2419 "Replacing it will overwrite its contents.").arg(strPath)); 2420 } 2421 2422 bool UIMessageCenter::askForOverridingFiles(const QVector<QString> &strPaths, QWidget *pParent /* = 0 */) 2423 { 2424 /* If it is only one file use the single question versions above: */ 2425 if (strPaths.size() == 1) 2426 return askForOverridingFile(strPaths.at(0), pParent); 2427 else if (strPaths.size() > 1) 2428 return messageYesNo(pParent, MessageType_Question, 2429 tr("The following files already exist:<br /><br />%1<br /><br />" 2430 "Are you sure you want to replace them? " 2431 "Replacing them will overwrite their contents.") 2432 .arg(QStringList(strPaths.toList()).join("<br />"))); 2433 else 2434 return true; 2435 } 2436 2437 bool UIMessageCenter::askForOverridingFileIfExists(const QString &strPath, QWidget *pParent /* = 0 */) 2438 { 2439 QFileInfo fi(strPath); 2440 if (fi.exists()) 2441 return askForOverridingFile(strPath, pParent); 2442 else 2443 return true; 2444 } 2445 2446 bool UIMessageCenter::askForOverridingFilesIfExists(const QVector<QString> &strPaths, QWidget *pParent /* = 0 */) 2447 { 2448 QVector<QString> existingFiles; 2449 foreach(const QString &file, strPaths) 2450 { 2451 QFileInfo fi(file); 2452 if (fi.exists()) 2453 existingFiles << fi.absoluteFilePath(); 2454 } 2455 /* If it is only one file use the single question versions above: */ 2456 if (existingFiles.size() == 1) 2457 return askForOverridingFileIfExists(existingFiles.at(0), pParent); 2458 else if (existingFiles.size() > 1) 2459 return askForOverridingFiles(existingFiles, pParent); 2460 else 2461 return true; 2462 } 2463 2474 2464 /* static */ 2475 2465 QString UIMessageCenter::mediumToAccusative(UIMediumType type, bool fIsHostDrive /* = false */) -
trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.h
r45268 r45269 184 184 QWidget* networkManagerOrMainMachineWindowShown() const; 185 185 186 /* API: File read/write overriding stuff: */187 bool askForOverridingFile(const QString& strPath, QWidget *pParent = NULL);188 bool askForOverridingFiles(const QVector<QString>& strPaths, QWidget *pParent = NULL);189 bool askForOverridingFileIfExists(const QString& strPath, QWidget *pParent = NULL);190 bool askForOverridingFilesIfExists(const QVector<QString>& strPaths, QWidget *pParent = NULL);191 192 186 /* API: Main (startup) warnings: */ 193 187 #ifdef RT_OS_LINUX … … 199 193 200 194 /* API: COM startup warnings: */ 195 void cannotInitUserHome(const QString &strUserHome); 201 196 void cannotInitCOM(HRESULT rc); 202 void cannotInitUserHome(const QString &strUserHome);203 197 void cannotCreateVirtualBox(const CVirtualBox &vbox); 204 205 /* API: Lincensing warnings: */206 #ifdef Q_WS_X11207 void cannotFindLicenseFiles(const QString &strPath);208 #endif /* Q_WS_X11 */209 void cannotOpenLicenseFile(QWidget *pParent, const QString &strPath);210 198 211 199 /* API: Global warnings: */ … … 377 365 void notifyAboutExtPackInstalled(const QString &strPackName, QWidget *pParent); 378 366 367 /* API: License-viewer warnings: */ 368 void cannotOpenLicenseFile(QWidget *pParent, const QString &strPath); 369 370 /* API: File-dialog warnings: */ 371 bool askForOverridingFile(const QString &strPath, QWidget *pParent = 0); 372 bool askForOverridingFiles(const QVector<QString> &strPaths, QWidget *pParent = 0); 373 bool askForOverridingFileIfExists(const QString &strPath, QWidget *pParent = 0); 374 bool askForOverridingFilesIfExists(const QVector<QString> &strPaths, QWidget *pParent = 0); 375 379 376 /* Helpers: */ 380 377 static QString mediumToAccusative(UIMediumType type, bool fIsHostDrive = false); -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
r45267 r45269 1724 1724 return QString (sTableTpl). arg (report); 1725 1725 } 1726 1727 #if defined(Q_WS_X11) && !defined(VBOX_OSE)1728 double VBoxGlobal::findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const1729 {1730 double maxVersionNumber = 0;1731 aLicenseFile = "";1732 for (int index = 0; index < aFilesList.count(); ++ index)1733 {1734 aPattern.indexIn (aFilesList [index]);1735 QString version = aPattern.cap (1);1736 if (maxVersionNumber < version.toDouble())1737 {1738 maxVersionNumber = version.toDouble();1739 aLicenseFile = aFilesList [index];1740 }1741 }1742 return maxVersionNumber;1743 }1744 1745 bool VBoxGlobal::showVirtualBoxLicense()1746 {1747 /* get the apps doc path */1748 int size = 256;1749 char *buffer = (char*) RTMemTmpAlloc (size);1750 RTPathAppDocs (buffer, size);1751 QString path (buffer);1752 RTMemTmpFree (buffer);1753 QDir docDir (path);1754 docDir.setFilter (QDir::Files);1755 docDir.setNameFilters (QStringList ("License-*.html"));1756 1757 /* Make sure that the language is in two letter code.1758 * Note: if languageId() returns an empty string lang.name() will1759 * return "C" which is an valid language code. */1760 QLocale lang (VBoxGlobal::languageId());1761 1762 QStringList filesList = docDir.entryList();1763 QString licenseFile;1764 /* First try to find a localized version of the license file. */1765 double versionNumber = findLicenseFile (filesList, QRegExp (QString ("License-([\\d\\.]+)-%1.html").arg (lang.name())), licenseFile);1766 /* If there wasn't a localized version of the currently selected language,1767 * search for the generic one. */1768 if (versionNumber == 0)1769 versionNumber = findLicenseFile (filesList, QRegExp ("License-([\\d\\.]+).html"), licenseFile);1770 /* Check the version again. */1771 if (!versionNumber)1772 {1773 msgCenter().cannotFindLicenseFiles (path);1774 return false;1775 }1776 1777 /* compose the latest license file full path */1778 QString latestVersion = QString::number (versionNumber);1779 QString latestFilePath = docDir.absoluteFilePath (licenseFile);1780 1781 /* check for the agreed license version */1782 QStringList strList = virtualBox().GetExtraData (GUI_LicenseKey).split(",");1783 for (int i=0; i < strList.size(); ++i)1784 if (strList.at(i) == latestVersion)1785 return true;1786 1787 VBoxLicenseViewer licenseDialog;1788 bool result = licenseDialog.showLicenseFromFile(latestFilePath) == QDialog::Accepted;1789 if (result)1790 virtualBox().SetExtraData (GUI_LicenseKey, (strList << latestVersion).join(","));1791 return result;1792 }1793 #endif /* defined(Q_WS_X11) && !defined(VBOX_OSE) */1794 1726 1795 1727 /** -
trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
r45267 r45269 237 237 238 238 /* VirtualBox helpers */ 239 240 #if defined(Q_WS_X11) && !defined(VBOX_OSE)241 double findLicenseFile (const QStringList &aFilesList, QRegExp aPattern, QString &aLicenseFile) const;242 bool showVirtualBoxLicense();243 #endif244 239 245 240 CSession openSession(const QString &aId, KLockType aLockType = KLockType_Write);
Note:
See TracChangeset
for help on using the changeset viewer.