From 40b40e6274e4db14531461c455c88378d12d85f2 Mon Sep 17 00:00:00 2001 From: kh1 Date: Thu, 6 Dec 2012 15:47:26 +0100 Subject: Finally IFW compiles with Qt5 (use private headers) Change-Id: I2604c77418e4a930bd0f76092db581fef1e45817 Reviewed-by: Tim Jenssen --- src/libs/installer/binaryformatenginehandler.h | 7 ++- src/libs/installer/component.cpp | 5 ++ src/libs/installer/component_p.cpp | 76 ++++++++++++++++++-------- src/libs/installer/component_p.h | 3 + src/libs/installer/fsengineclient.h | 8 ++- src/libs/installer/fsengineserver.cpp | 7 ++- src/libs/installer/init.cpp | 45 ++++++++++++--- src/libs/installer/messageboxhandler.cpp | 13 ++++- src/libs/installer/packagemanagercore.cpp | 31 ++++++++++- src/libs/installer/settings.h | 4 +- src/libs/installer/utils.cpp | 3 - src/sdk/settingsdialog.cpp | 6 ++ 12 files changed, 163 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/libs/installer/binaryformatenginehandler.h b/src/libs/installer/binaryformatenginehandler.h index 82269eda9..4dc4b196b 100644 --- a/src/libs/installer/binaryformatenginehandler.h +++ b/src/libs/installer/binaryformatenginehandler.h @@ -35,8 +35,11 @@ #include "installer_global.h" -#include - +#if QT_VERSION < 0x050000 +# include +#else +# include +#endif namespace QInstallerCreator { diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index 2f75e4675..e13fa6602 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -454,8 +454,13 @@ void Component::loadTranslations(const QDir &directory, const QStringList &qms) */ void Component::loadUserInterfaces(const QDir &directory, const QStringList &uis) { +#if QT_VERSION < 0x050000 if (QApplication::type() == QApplication::Tty) return; +#else + if (qobject_cast (qApp) == 0) + return; +#endif QDirIterator it(directory.path(), uis, QDir::Files); while (it.hasNext()) { diff --git a/src/libs/installer/component_p.cpp b/src/libs/installer/component_p.cpp index ba6800247..3879d72b6 100644 --- a/src/libs/installer/component_p.cpp +++ b/src/libs/installer/component_p.cpp @@ -37,11 +37,16 @@ #include "packagemanagercore.h" #include -#include +#if QT_VERSION < 0x050000 +# include +#else +# include +#endif namespace QInstaller { + // -- ComponentPrivate ComponentPrivate::ComponentPrivate(PackageManagerCore *core, Component *qq) @@ -88,26 +93,6 @@ QScriptEngine *ComponentPrivate::scriptEngine() // register QMessageBox::StandardButton enum in the script connection registerMessageBox(m_scriptEngine); - // register QDesktopServices in the script connection - QScriptValue desktopServices = m_scriptEngine->newArray(); - setProperty(desktopServices, QLatin1String("DesktopLocation"), QDesktopServices::DesktopLocation); - setProperty(desktopServices, QLatin1String("DocumentsLocation"), QDesktopServices::DocumentsLocation); - setProperty(desktopServices, QLatin1String("FontsLocation"), QDesktopServices::FontsLocation); - setProperty(desktopServices, QLatin1String("ApplicationsLocation"), QDesktopServices::ApplicationsLocation); - setProperty(desktopServices, QLatin1String("MusicLocation"), QDesktopServices::MusicLocation); - setProperty(desktopServices, QLatin1String("MoviesLocation"), QDesktopServices::MoviesLocation); - setProperty(desktopServices, QLatin1String("PicturesLocation"), QDesktopServices::PicturesLocation); - setProperty(desktopServices, QLatin1String("TempLocation"), QDesktopServices::TempLocation); - setProperty(desktopServices, QLatin1String("HomeLocation"), QDesktopServices::HomeLocation); - setProperty(desktopServices, QLatin1String("DataLocation"), QDesktopServices::DataLocation); - setProperty(desktopServices, QLatin1String("CacheLocation"), QDesktopServices::CacheLocation); - - desktopServices.setProperty(QLatin1String("openUrl"), m_scriptEngine->newFunction(qDesktopServicesOpenUrl)); - desktopServices.setProperty(QLatin1String("displayName"), - m_scriptEngine->newFunction(qDesktopServicesDisplayName)); - desktopServices.setProperty(QLatin1String("storageLocation"), - m_scriptEngine->newFunction(qDesktopServicesStorageLocation)); - // register ::WizardPage enum in the script connection QScriptValue qinstaller = m_scriptEngine->newArray(); setProperty(qinstaller, QLatin1String("Introduction"), PackageManagerCore::Introduction); @@ -138,11 +123,14 @@ QScriptEngine *ComponentPrivate::scriptEngine() m_scriptEngine->globalObject().setProperty(QLatin1String("QInstaller"), qinstaller); m_scriptEngine->globalObject().setProperty(QLatin1String("installer"), installerObject); - m_scriptEngine->globalObject().setProperty(QLatin1String("QDesktopServices"), desktopServices); + + // register QDesktopServices in the script connection + m_scriptEngine->globalObject().setProperty(QLatin1String("QDesktopServices"), getDesktopServices()); m_scriptEngine->globalObject().setProperty(QLatin1String("component"), m_scriptEngine->newQObject(q)); QScriptValue fileDialog = m_scriptEngine->newArray(); - fileDialog.setProperty(QLatin1String("getExistingDirectory"), m_scriptEngine->newFunction(qFileDialogGetExistingDirectory)); + fileDialog.setProperty(QLatin1String("getExistingDirectory"), + m_scriptEngine->newFunction(qFileDialogGetExistingDirectory)); m_scriptEngine->globalObject().setProperty(QLatin1String("QFileDialog"), fileDialog); return m_scriptEngine; @@ -153,6 +141,48 @@ void ComponentPrivate::setProperty(QScriptValue &scriptValue, const QString &pro scriptValue.setProperty(propertyName, m_scriptEngine->newVariant(value)); } +// -- private + +QScriptValue ComponentPrivate::getDesktopServices() +{ + QScriptValue desktopServices = m_scriptEngine->newArray(); +#if QT_VERSION < 0x050000 + setProperty(desktopServices, QLatin1String("DesktopLocation"), QDesktopServices::DesktopLocation); + setProperty(desktopServices, QLatin1String("DesktopLocation"), QDesktopServices::DesktopLocation); + setProperty(desktopServices, QLatin1String("DocumentsLocation"), QDesktopServices::DocumentsLocation); + setProperty(desktopServices, QLatin1String("FontsLocation"), QDesktopServices::FontsLocation); + setProperty(desktopServices, QLatin1String("ApplicationsLocation"), QDesktopServices::ApplicationsLocation); + setProperty(desktopServices, QLatin1String("MusicLocation"), QDesktopServices::MusicLocation); + setProperty(desktopServices, QLatin1String("MoviesLocation"), QDesktopServices::MoviesLocation); + setProperty(desktopServices, QLatin1String("PicturesLocation"), QDesktopServices::PicturesLocation); + setProperty(desktopServices, QLatin1String("TempLocation"), QDesktopServices::TempLocation); + setProperty(desktopServices, QLatin1String("HomeLocation"), QDesktopServices::HomeLocation); + setProperty(desktopServices, QLatin1String("DataLocation"), QDesktopServices::DataLocation); + setProperty(desktopServices, QLatin1String("CacheLocation"), QDesktopServices::CacheLocation); +#else + setProperty(desktopServices, QLatin1String("DesktopLocation"), QStandardPaths::DesktopLocation); + setProperty(desktopServices, QLatin1String("DesktopLocation"), QStandardPaths::DesktopLocation); + setProperty(desktopServices, QLatin1String("DocumentsLocation"), QStandardPaths::DocumentsLocation); + setProperty(desktopServices, QLatin1String("FontsLocation"), QStandardPaths::FontsLocation); + setProperty(desktopServices, QLatin1String("ApplicationsLocation"), QStandardPaths::ApplicationsLocation); + setProperty(desktopServices, QLatin1String("MusicLocation"), QStandardPaths::MusicLocation); + setProperty(desktopServices, QLatin1String("MoviesLocation"), QStandardPaths::MoviesLocation); + setProperty(desktopServices, QLatin1String("PicturesLocation"), QStandardPaths::PicturesLocation); + setProperty(desktopServices, QLatin1String("TempLocation"), QStandardPaths::TempLocation); + setProperty(desktopServices, QLatin1String("HomeLocation"), QStandardPaths::HomeLocation); + setProperty(desktopServices, QLatin1String("DataLocation"), QStandardPaths::DataLocation); + setProperty(desktopServices, QLatin1String("CacheLocation"), QStandardPaths::CacheLocation); +#endif + + desktopServices.setProperty(QLatin1String("openUrl"), + m_scriptEngine->newFunction(qDesktopServicesOpenUrl)); + desktopServices.setProperty(QLatin1String("displayName"), + m_scriptEngine->newFunction(qDesktopServicesDisplayName)); + desktopServices.setProperty(QLatin1String("storageLocation"), + m_scriptEngine->newFunction(qDesktopServicesStorageLocation)); + return desktopServices; +} + // -- ComponentModelHelper diff --git a/src/libs/installer/component_p.h b/src/libs/installer/component_p.h index 18d1ea21d..47e6a85ef 100644 --- a/src/libs/installer/component_p.h +++ b/src/libs/installer/component_p.h @@ -87,6 +87,9 @@ public: QHash > m_licenses; QList > m_pathesForUninstallation; +private: + QScriptValue getDesktopServices(); + private: QScriptEngine* m_scriptEngine; }; diff --git a/src/libs/installer/fsengineclient.h b/src/libs/installer/fsengineclient.h index b974234ec..1bb94887c 100644 --- a/src/libs/installer/fsengineclient.h +++ b/src/libs/installer/fsengineclient.h @@ -35,10 +35,14 @@ #include "installer_global.h" -#include - #include +#if QT_VERSION < 0x050000 +# include +#else +# include +#endif + QT_BEGIN_NAMESPACE class QTcpSocket; QT_END_NAMESPACE diff --git a/src/libs/installer/fsengineserver.cpp b/src/libs/installer/fsengineserver.cpp index 0c5592bbb..bc1342a1d 100644 --- a/src/libs/installer/fsengineserver.cpp +++ b/src/libs/installer/fsengineserver.cpp @@ -34,7 +34,6 @@ #include "utils.h" #include -#include #include #include #include @@ -42,6 +41,12 @@ #include +#if QT_VERSION < 0x050000 +# include +#else +# include +#endif + typedef int descriptor_t; #ifdef Q_OS_WIN diff --git a/src/libs/installer/init.cpp b/src/libs/installer/init.cpp index 0ea48d3c6..b728dde58 100644 --- a/src/libs/installer/init.cpp +++ b/src/libs/installer/init.cpp @@ -146,7 +146,7 @@ static void initResources() Q_INIT_RESOURCE(patch_file_lists); } -static void messageHandler(QtMsgType type, const char *msg) +static QByteArray trimAndPrepend(QtMsgType type, const QByteArray &msg) { QByteArray ba(msg); // last character is a space from qDebug @@ -155,31 +155,56 @@ static void messageHandler(QtMsgType type, const char *msg) // remove quotes if the whole message is surrounded with them if (ba.startsWith('"') && ba.endsWith('"')) - ba = ba.mid(1, ba.length()-2); + ba = ba.mid(1, ba.length() - 2); // prepend the message type, skip QtDebugMsg switch (type) { - case QtWarningMsg: { + case QtMsgType::QtWarningMsg: ba.prepend("Warning: "); - } break; - case QtCriticalMsg: { + break; + + case QtMsgType::QtCriticalMsg: ba.prepend("Critical: "); - } break; - case QtFatalMsg: { + break; + + case QtMsgType::QtFatalMsg: ba.prepend("Fatal: "); - } break; + break; + default: break; } + return ba; +} + +#if QT_VERSION < 0x050000 +static void messageHandler(QtMsgType type, const char *msg) +{ + const QByteArray ba = trimAndPrepend(type, msg); +#else +void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + QByteArray ba = trimAndPrepend(type, msg.toLocal8Bit()); + if (type != QtMsgType::QtDebugMsg) { + ba += QByteArray(" (") + context.file + QByteArray(":").append(context.line) + QByteArray(", ") + + context.function + QByteArray(")"); + } +#endif verbose() << ba.constData() << std::endl; if (!isVerbose() && type != QtDebugMsg) std::cout << ba.constData() << std::endl << std::endl; if (type == QtFatalMsg) { +#if QT_VERSION < 0x050000 QtMsgHandler oldMsgHandler = qInstallMsgHandler(0); qt_message_output(type, msg); qInstallMsgHandler(oldMsgHandler); +#else + QtMessageHandler oldMsgHandler = qInstallMessageHandler(0); + qt_message_output(type, context, msg); + qInstallMessageHandler(oldMsgHandler); +#endif } } @@ -231,5 +256,9 @@ void QInstaller::init() ::initArchives(); // qDebug -> verbose() +#if QT_VERSION < 0x050000 qInstallMsgHandler(messageHandler); +#else + qInstallMessageHandler(messageHandler); +#endif } diff --git a/src/libs/installer/messageboxhandler.cpp b/src/libs/installer/messageboxhandler.cpp index 3c3a70ee9..dd55a9c7f 100644 --- a/src/libs/installer/messageboxhandler.cpp +++ b/src/libs/installer/messageboxhandler.cpp @@ -128,9 +128,13 @@ MessageBoxHandler *MessageBoxHandler::instance() QWidget *MessageBoxHandler::currentBestSuitParent() { - if (QApplication::type() == QApplication::Tty) { +#if QT_VERSION < 0x050000 + if (QApplication::type() == QApplication::Tty) return 0; - } +#else + if (qobject_cast (qApp) == 0) + return 0; +#endif if (qApp->activeModalWidget()) return qApp->activeModalWidget(); @@ -283,8 +287,13 @@ QMessageBox::StandardButton MessageBoxHandler::showMessageBox(MessageType messag qDebug() << QString::fromLatin1("created %1 message box %2: '%3', %4").arg(messageTypeHash .value(messageType),identifier, title, text); +#if QT_VERSION < 0x050000 if (QApplication::type() == QApplication::Tty) return defaultButton; +#else + if (qobject_cast (qApp) == 0) + return defaultButton; +#endif if (m_automaticAnswers.contains(identifier)) return m_automaticAnswers.value(identifier); diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index 6f1eda6e1..254240b5d 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -70,10 +70,15 @@ # include "qt_windows.h" #endif +#if QT_VERSION >= 0x050000 +# include +#endif + using namespace QInstaller; static QMutex sModelMutex; -static QFont sVirtualComponentsFont; +static QFont *sVirtualComponentsFont = 0; +static QMutex sVirtualComponentsFontMutex; static bool sNoForceInstallation = false; static bool sVirtualComponentsVisible = false; @@ -174,9 +179,16 @@ QScriptValue QInstaller::qDesktopServicesDisplayName(QScriptContext *context, QS const QScriptValue check = checkArguments(context, 1, 1); if (check.isError()) return check; + +#if QT_VERSION < 0x050000 const QDesktopServices::StandardLocation location = static_cast< QDesktopServices::StandardLocation >(context->argument(0).toInt32()); return QDesktopServices::displayName(location); +#else + const QStandardPaths::StandardLocation location = + static_cast< QStandardPaths::StandardLocation >(context->argument(0).toInt32()); + return QStandardPaths::displayName(location); +#endif } QScriptValue QInstaller::qDesktopServicesStorageLocation(QScriptContext *context, QScriptEngine *engine) @@ -185,9 +197,16 @@ QScriptValue QInstaller::qDesktopServicesStorageLocation(QScriptContext *context const QScriptValue check = checkArguments(context, 1, 1); if (check.isError()) return check; + +#if QT_VERSION < 0x050000 const QDesktopServices::StandardLocation location = static_cast< QDesktopServices::StandardLocation >(context->argument(0).toInt32()); return QDesktopServices::storageLocation(location); +#else + const QStandardPaths::StandardLocation location = + static_cast< QStandardPaths::StandardLocation >(context->argument(0).toInt32()); + return QStandardPaths::writableLocation(location); +#endif } QScriptValue QInstaller::qFileDialogGetExistingDirectory( QScriptContext *context, QScriptEngine *engine ) @@ -525,13 +544,19 @@ PackageManagerCore::~PackageManagerCore() /* static */ QFont PackageManagerCore::virtualComponentsFont() { - return sVirtualComponentsFont; + QMutexLocker _(&sVirtualComponentsFontMutex); + if (!sVirtualComponentsFont) + sVirtualComponentsFont = new QFont; + return *sVirtualComponentsFont; } /* static */ void PackageManagerCore::setVirtualComponentsFont(const QFont &font) { - sVirtualComponentsFont = font; + QMutexLocker _(&sVirtualComponentsFontMutex); + if (sVirtualComponentsFont) + delete sVirtualComponentsFont; + sVirtualComponentsFont = new QFont(font); } /* static */ diff --git a/src/libs/installer/settings.h b/src/libs/installer/settings.h index f5a614fed..5eb5c4932 100644 --- a/src/libs/installer/settings.h +++ b/src/libs/installer/settings.h @@ -42,7 +42,9 @@ #include -Q_DECLARE_METATYPE(QNetworkProxy) +#if QT_VERSION < 0x050000 + Q_DECLARE_METATYPE(QNetworkProxy) +#endif namespace QInstaller { class Repository; diff --git a/src/libs/installer/utils.cpp b/src/libs/installer/utils.cpp index 65d64f1c2..53b1d6294 100644 --- a/src/libs/installer/utils.cpp +++ b/src/libs/installer/utils.cpp @@ -58,8 +58,6 @@ bool QInstaller::isVerbose() } #ifdef Q_OS_WIN -void qWinMsgHandler(QtMsgType t, const char *str); - class debugstream : public std::ostream { class buf : public std::stringbuf @@ -72,7 +70,6 @@ class debugstream : public std::ostream std::string s = str(); if (s[s.length() - 1] == '\n' ) s[s.length() - 1] = '\0'; // remove \n - qWinMsgHandler(QtDebugMsg, s.c_str()); std::cout << s << std::endl; str(std::string()); return 0; diff --git a/src/sdk/settingsdialog.cpp b/src/sdk/settingsdialog.cpp index 58b7e4d23..d609aac80 100644 --- a/src/sdk/settingsdialog.cpp +++ b/src/sdk/settingsdialog.cpp @@ -537,8 +537,14 @@ void SettingsDialog::setupRepositoriesTreeWidget() for (int i = 0; i < treeWidget->model()->columnCount(); ++i) treeWidget->resizeColumnToContents(i); +#if QT_VERSION < 0x050000 treeWidget->header()->setResizeMode(0, QHeaderView::Fixed); treeWidget->header()->setResizeMode(1, QHeaderView::Fixed); +#else + treeWidget->header()->setSectionResizeMode(0, QHeaderView::Fixed); + treeWidget->header()->setSectionResizeMode(1, QHeaderView::Fixed); +#endif + treeWidget->header()->setMinimumSectionSize(treeWidget->columnWidth(1)); treeWidget->setItemDelegateForColumn(0, new PasswordDelegate(treeWidget)); treeWidget->setItemDelegateForColumn(1, new PasswordDelegate(treeWidget)); -- cgit v1.2.3