From 0249980607986b1b786886f61dc7d68dfb5b2420 Mon Sep 17 00:00:00 2001 From: kh1 Date: Thu, 28 Feb 2013 17:30:06 +0100 Subject: Use Q_GLOBAL_STATIC{_WITH_ARGS} following Qt coding conventions. Move the regexp into its own compilation unit, so we get it only once and use a accessor to fetch the value. I guess we should do the same with the constants file, as all strings get compiled in the file including it. At least Ossi wasn't satisfied currently. Change-Id: Ic495a82f4b3cfe7810523b12cd3ef255eb15f149 Reviewed-by: Tim Jenssen Reviewed-by: Karsten Heimrich --- src/libs/installer/component.cpp | 13 +++---- src/libs/installer/globals.cpp | 47 +++++++++++++++++++++++++ src/libs/installer/globals.h | 54 +++++++++++++++++++++++++++++ src/libs/installer/installer.pro | 6 ++-- src/libs/installer/packagemanagercore.cpp | 20 ++++++----- src/libs/installer/packagemanagercore_p.cpp | 5 +-- src/libs/installer/qinstallerglobal.h | 2 -- src/libs/kdtools/kdupdaterapplication.h | 2 -- src/libs/kdtools/kdupdaterpackagesinfo.cpp | 8 +++-- src/libs/kdtools/kdupdaterupdatefinder.cpp | 4 ++- 10 files changed, 134 insertions(+), 27 deletions(-) create mode 100644 src/libs/installer/globals.cpp create mode 100644 src/libs/installer/globals.h (limited to 'src/libs') diff --git a/src/libs/installer/component.cpp b/src/libs/installer/component.cpp index fb554155f..7b457d71b 100644 --- a/src/libs/installer/component.cpp +++ b/src/libs/installer/component.cpp @@ -43,6 +43,7 @@ #include "errors.h" #include "fileutils.h" #include "fsengineclient.h" +#include "globals.h" #include "lib7z_facade.h" #include "packagemanagercore.h" #include "messageboxhandler.h" @@ -181,13 +182,13 @@ void Component::loadDataFromPackage(const Package &package) } setLocalTempPath(QInstaller::pathFromUrl(package.sourceInfo().url)); - const QStringList uis = package.data(QLatin1String("UserInterfaces")).toString().split(scCommaRegExp, - QString::SkipEmptyParts); + const QStringList uis = package.data(QLatin1String("UserInterfaces")).toString() + .split(QInstaller::commaRegExp(), QString::SkipEmptyParts); if (!uis.isEmpty()) loadUserInterfaces(QDir(QString::fromLatin1("%1/%2").arg(localTempPath(), name())), uis); - const QStringList qms = package.data(QLatin1String("Translations")).toString().split(scCommaRegExp, - QString::SkipEmptyParts); + const QStringList qms = package.data(QLatin1String("Translations")).toString() + .split(QInstaller::commaRegExp(), QString::SkipEmptyParts); if (!qms.isEmpty()) loadTranslations(QDir(QString::fromLatin1("%1/%2").arg(localTempPath(), name())), qms); @@ -994,13 +995,13 @@ void Component::addDependency(const QString &newDependency) */ QStringList Component::dependencies() const { - return d->m_vars.value(scDependencies).split(scCommaRegExp, QString::SkipEmptyParts); + return d->m_vars.value(scDependencies).split(QInstaller::commaRegExp(), QString::SkipEmptyParts); } QStringList Component::autoDependencies() const { QStringList autoDependencyStringList = - d->m_vars.value(scAutoDependOn).split(scCommaRegExp, QString::SkipEmptyParts); + d->m_vars.value(scAutoDependOn).split(QInstaller::commaRegExp(), QString::SkipEmptyParts); autoDependencyStringList.removeAll(QLatin1String("script")); return autoDependencyStringList; } diff --git a/src/libs/installer/globals.cpp b/src/libs/installer/globals.cpp new file mode 100644 index 000000000..f0910372d --- /dev/null +++ b/src/libs/installer/globals.cpp @@ -0,0 +1,47 @@ +/************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ +#include "globals.h" + +Q_GLOBAL_STATIC_WITH_ARGS(QRegExp, staticCommaRegExp, (QLatin1String("\\b(,|, )\\b"))); +QRegExp QInstaller::commaRegExp() +{ + return *staticCommaRegExp(); +} diff --git a/src/libs/installer/globals.h b/src/libs/installer/globals.h new file mode 100644 index 000000000..858c856d5 --- /dev/null +++ b/src/libs/installer/globals.h @@ -0,0 +1,54 @@ +/************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Installer Framework. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +**************************************************************************/ +#ifndef GLOBALS_H +#define GLOBALS_H + +#include "installer_global.h" + +#include + +namespace QInstaller { + +QRegExp INSTALLER_EXPORT commaRegExp(); + +} // QInstaller + +#endif // GLOBALS_H diff --git a/src/libs/installer/installer.pro b/src/libs/installer/installer.pro index e696bf994..79500b2d5 100644 --- a/src/libs/installer/installer.pro +++ b/src/libs/installer/installer.pro @@ -104,7 +104,8 @@ HEADERS += packagemanagercore.h \ createlinkoperation.h \ packagemanagercoredata.h \ registerqtincreatorqnxoperation.h \ - applyproductkeyoperation.h + applyproductkeyoperation.h \ + globals.h SOURCES += packagemanagercore.cpp \ packagemanagercore_p.cpp \ @@ -173,7 +174,8 @@ HEADERS += packagemanagercore.h \ createlinkoperation.cpp \ packagemanagercoredata.cpp \ registerqtincreatorqnxoperation.cpp \ - applyproductkeyoperation.cpp + applyproductkeyoperation.cpp \ + globals.cpp RESOURCES += resources/patch_file_lists.qrc \ resources/installer.qrc diff --git a/src/libs/installer/packagemanagercore.cpp b/src/libs/installer/packagemanagercore.cpp index 376b178c3..7d59dddec 100644 --- a/src/libs/installer/packagemanagercore.cpp +++ b/src/libs/installer/packagemanagercore.cpp @@ -48,6 +48,7 @@ #include "downloadarchivesjob.h" #include "errors.h" #include "fsengineclient.h" +#include "globals.h" #include "getrepositoriesmetainfojob.h" #include "messageboxhandler.h" #include "packagemanagerproxyfactory.h" @@ -86,9 +87,9 @@ using namespace QInstaller; -static QMutex sModelMutex; +Q_GLOBAL_STATIC(QMutex, globalModelMutex); static QFont *sVirtualComponentsFont = 0; -static QMutex sVirtualComponentsFontMutex; +Q_GLOBAL_STATIC(QMutex, globalVirtualComponentsFontMutex); static bool sNoForceInstallation = false; static bool sVirtualComponentsVisible = false; @@ -554,7 +555,7 @@ PackageManagerCore::~PackageManagerCore() /* static */ QFont PackageManagerCore::virtualComponentsFont() { - QMutexLocker _(&sVirtualComponentsFontMutex); + QMutexLocker _(globalVirtualComponentsFontMutex()); if (!sVirtualComponentsFont) sVirtualComponentsFont = new QFont; return *sVirtualComponentsFont; @@ -563,7 +564,7 @@ QFont PackageManagerCore::virtualComponentsFont() /* static */ void PackageManagerCore::setVirtualComponentsFont(const QFont &font) { - QMutexLocker _(&sVirtualComponentsFontMutex); + QMutexLocker _(globalVirtualComponentsFontMutex()); if (sVirtualComponentsFont) delete sVirtualComponentsFont; sVirtualComponentsFont = new QFont(font); @@ -1086,7 +1087,7 @@ QList PackageManagerCore::dependencies(const Component *component, Q ComponentModel *PackageManagerCore::defaultComponentModel() const { - QMutexLocker _(&sModelMutex); + QMutexLocker _(globalModelMutex()); if (!d->m_defaultModel) { d->m_defaultModel = componentModel(const_cast (this), QLatin1String("AllComponentsModel")); @@ -1096,7 +1097,7 @@ ComponentModel *PackageManagerCore::defaultComponentModel() const ComponentModel *PackageManagerCore::updaterComponentModel() const { - QMutexLocker _(&sModelMutex); + QMutexLocker _(globalModelMutex()); if (!d->m_updaterModel) { d->m_updaterModel = componentModel(const_cast (this), QLatin1String("UpdaterComponentsModel")); @@ -1642,7 +1643,7 @@ bool PackageManagerCore::updateComponentData(struct Data &data, Component *compo // add downloadable archive from xml const QStringList downloadableArchives = data.package->data(scDownloadableArchives).toString() - .split(scCommaRegExp, QString::SkipEmptyParts); + .split(QInstaller::commaRegExp(), QString::SkipEmptyParts); if (component->isFromOnlineRepository()) { foreach (const QString downloadableArchive, downloadableArchives) @@ -1650,7 +1651,7 @@ bool PackageManagerCore::updateComponentData(struct Data &data, Component *compo } const QStringList componentsToReplace = data.package->data(scReplaces).toString() - .split(scCommaRegExp, QString::SkipEmptyParts); + .split(QInstaller::commaRegExp(), QString::SkipEmptyParts); if (!componentsToReplace.isEmpty()) { // Store the component (this is a component that replaces others) and all components that @@ -1798,7 +1799,8 @@ bool PackageManagerCore::fetchUpdaterPackages(const PackagesList &remotes, const bool isValidUpdate = locals.contains(name); if (!isValidUpdate && !replaces.isEmpty()) { - const QStringList possibleNames = replaces.split(scCommaRegExp, QString::SkipEmptyParts); + const QStringList possibleNames = replaces.split(QInstaller::commaRegExp(), + QString::SkipEmptyParts); foreach (const QString &possibleName, possibleNames) { if (locals.contains(possibleName)) { isValidUpdate = true; diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index 9b25728d6..cd413c5b0 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -47,6 +47,7 @@ #include "errors.h" #include "fileutils.h" #include "fsengineclient.h" +#include "globals.h" #include "messageboxhandler.h" #include "packagemanagercore.h" #include "progresscoordinator.h" @@ -2283,8 +2284,8 @@ bool PackageManagerCorePrivate::appendComponentsToUninstall(const QListvalue(scReplaces); - QStringList possibleNames = replaces.split(scCommaRegExp, QString::SkipEmptyParts); - possibleNames.append(c->name()); + const QStringList possibleNames = replaces.split(QInstaller::commaRegExp(), + QString::SkipEmptyParts) << c->name(); foreach (const QString &possibleName, possibleNames) autoDependencies.removeAll(possibleName); } diff --git a/src/libs/installer/qinstallerglobal.h b/src/libs/installer/qinstallerglobal.h index 81635830b..7f0fbbbc0 100644 --- a/src/libs/installer/qinstallerglobal.h +++ b/src/libs/installer/qinstallerglobal.h @@ -57,8 +57,6 @@ QT_END_NAMESPACE namespace QInstaller { -static QRegExp scCommaRegExp(QLatin1String("\\b(,|, )\\b")); - enum INSTALLER_EXPORT JobError { InvalidUrl = 0x24B04, diff --git a/src/libs/kdtools/kdupdaterapplication.h b/src/libs/kdtools/kdupdaterapplication.h index b2079fe7c..f1ca9d612 100644 --- a/src/libs/kdtools/kdupdaterapplication.h +++ b/src/libs/kdtools/kdupdaterapplication.h @@ -25,7 +25,6 @@ #include "kdupdater.h" #include -#include QT_BEGIN_NAMESPACE class QUrl; @@ -36,7 +35,6 @@ namespace KDUpdater { class PackagesInfo; class UpdateSourcesInfo; -static QRegExp scCommaRegExp(QLatin1String("\\b(,|, )\\b")); class ConfigurationInterface { public: diff --git a/src/libs/kdtools/kdupdaterpackagesinfo.cpp b/src/libs/kdtools/kdupdaterpackagesinfo.cpp index 9ac2b8eac..142cf67b0 100644 --- a/src/libs/kdtools/kdupdaterpackagesinfo.cpp +++ b/src/libs/kdtools/kdupdaterpackagesinfo.cpp @@ -21,6 +21,7 @@ **********************************************************************/ #include "kdupdaterpackagesinfo.h" #include "kdupdaterapplication.h" +#include "globals.h" #include #include @@ -511,9 +512,10 @@ void PackagesInfo::PackagesInfoData::addPackageFrom(const QDomElement &packageE) info.virtualComp = childNodeE.text().toLower() == QLatin1String("true") ? true : false; else if (childNodeE.tagName() == QLatin1String("Size")) info.uncompressedSize = childNodeE.text().toULongLong(); - else if (childNodeE.tagName() == QLatin1String("Dependencies")) - info.dependencies = childNodeE.text().split(scCommaRegExp, QString::SkipEmptyParts); - else if (childNodeE.tagName() == QLatin1String("ForcedInstallation")) + else if (childNodeE.tagName() == QLatin1String("Dependencies")) { + info.dependencies = childNodeE.text().split(QInstaller::commaRegExp(), + QString::SkipEmptyParts); + } else if (childNodeE.tagName() == QLatin1String("ForcedInstallation")) info.forcedInstallation = childNodeE.text().toLower() == QLatin1String( "true" ) ? true : false; else if (childNodeE.tagName() == QLatin1String("LastUpdateDate")) info.lastUpdateDate = QDate::fromString(childNodeE.text(), Qt::ISODate); diff --git a/src/libs/kdtools/kdupdaterupdatefinder.cpp b/src/libs/kdtools/kdupdaterupdatefinder.cpp index caa66982e..0262dfc50 100644 --- a/src/libs/kdtools/kdupdaterupdatefinder.cpp +++ b/src/libs/kdtools/kdupdaterupdatefinder.cpp @@ -29,6 +29,8 @@ #include "kdupdaterfiledownloaderfactory.h" #include "kdupdaterupdatesinfo_p.h" +#include "globals.h" + #include #include @@ -471,7 +473,7 @@ QList UpdateFinder::Private::applicableUpdates(UpdatesInfo *updatesI appName = appName.replace(QLatin1String( " ," ), QLatin1String( "," )); // Catch hold of app names contained updatesInfo->applicationName() - QStringList apps = appName.split(scCommaRegExp, QString::SkipEmptyParts); + QStringList apps = appName.split(QInstaller::commaRegExp(), QString::SkipEmptyParts); appNameIndex = apps.indexOf(this->application->applicationName()); // If the application appName isn't one of the app names, then -- cgit v1.2.3