Introduce QT_NO_MIMETYPE

The mime type stuff generates one of the biggest translation units in QtCore
due to the compressed 1.7MB freedesktop.org.xml resource.

With QT_NO_MIMETYPE, libQt5Core.so is almost 400Kb smaller
(4.8MB->4.4MB gcc 4.9 stripped release build)

Change-Id: I5339090994034355724ff4deddb64720e81baeaf
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Sérgio Martins 2015-02-15 16:39:13 +00:00
parent 3c1d9911c4
commit fbeeaf23fe
28 changed files with 116 additions and 14 deletions

View File

@ -297,6 +297,9 @@
#ifndef QT_NO_DESKTOPSERVICES
# define QT_NO_DESKTOPSERVICES
#endif
#ifndef QT_NO_MIMETYPE
# define QT_NO_MIMETYPE
#endif
#ifndef QT_NO_SYSTEMTRAYICON
# define QT_NO_SYSTEMTRAYICON
#endif

View File

@ -187,6 +187,9 @@
#ifndef QT_NO_DESKTOPSERVICES
# define QT_NO_DESKTOPSERVICES
#endif
#ifndef QT_NO_MIMETYPE
# define QT_NO_MIMETYPE
#endif
#ifndef QT_NO_SYSTEMTRAYICON
# define QT_NO_SYSTEMTRAYICON
#endif

View File

@ -879,6 +879,12 @@ Section: Utilities
Requires:
Name: QDesktopServices
Feature: MIMETYPE
Description: Describes types of file or data, represented by a MIME type string.
Section: Utilities
Requires:
Name: QMimeType
Feature: SYSTEMTRAYICON
Description: Provides an icon for an application in the system tray.
Section: Utilities

View File

@ -20,6 +20,6 @@ SOURCES += \
mimetypes/qmimeglobpattern.cpp \
mimetypes/qmimeprovider.cpp
RESOURCES += \
mimetypes/mimetypes.qrc
!contains(DEFINES, QT_NO_MIMETYPE) {
RESOURCES += mimetypes/mimetypes.qrc
}

View File

@ -33,8 +33,9 @@
#include <qplatformdefs.h> // always first
#include "qmimedatabase.h"
#ifndef QT_NO_MIMETYPE
#include "qmimedatabase.h"
#include "qmimedatabase_p.h"
#include "qmimeprovider_p.h"
@ -597,3 +598,5 @@ QList<QMimeType> QMimeDatabase::allMimeTypes() const
*/
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -35,6 +35,9 @@
#define QMIMEDATABASE_H
#include <QtCore/qmimetype.h>
#ifndef QT_NO_MIMETYPE
#include <QtCore/qstringlist.h>
QT_BEGIN_NAMESPACE
@ -81,4 +84,6 @@ private:
};
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEDATABASE_H

View File

@ -45,13 +45,16 @@
// We mean it.
//
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
#include "qmimetype.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetype_p.h"
#include "qmimeglobpattern_p.h"
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
QT_BEGIN_NAMESPACE
class QIODevice;
@ -90,4 +93,5 @@ public:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEDATABASE_P_H

View File

@ -33,6 +33,8 @@
#include "qmimeglobpattern_p.h"
#ifndef QT_NO_MIMETYPE
#include <QRegExp>
#include <QStringList>
#include <QDebug>
@ -234,3 +236,5 @@ void QMimeAllGlobPatterns::clear()
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -45,6 +45,10 @@
// We mean it.
//
#include <QtCore/qglobal.h>
#ifndef QT_NO_MIMETYPE
#include <QtCore/qstringlist.h>
#include <QtCore/qhash.h>
@ -146,4 +150,5 @@ public:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEGLOBPATTERN_P_H

View File

@ -36,6 +36,8 @@
#include "qmimemagicrule_p.h"
#ifndef QT_NO_MIMETYPE
#include <QtCore/QList>
#include <QtCore/QDebug>
#include <qendian.h>
@ -377,3 +379,5 @@ bool QMimeMagicRule::matches(const QByteArray &data) const
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -45,6 +45,10 @@
// We mean it.
//
#include <QtCore/qglobal.h>
#ifndef QT_NO_MIMETYPE
#include <QtCore/qbytearray.h>
#include <QtCore/qscopedpointer.h>
#include <QtCore/qlist.h>
@ -89,4 +93,5 @@ Q_DECLARE_TYPEINFO(QMimeMagicRule, Q_MOVABLE_TYPE);
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEMAGICRULE_H

View File

@ -35,6 +35,8 @@
#include "qmimemagicrulematcher_p.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetype_p.h"
QT_BEGIN_NAMESPACE
@ -98,3 +100,4 @@ unsigned QMimeMagicRuleMatcher::priority() const
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -45,12 +45,14 @@
// We mean it.
//
#include "qmimemagicrule_p.h"
#ifndef QT_NO_MIMETYPE
#include <QtCore/qbytearray.h>
#include <QtCore/qlist.h>
#include <QtCore/qstring.h>
#include "qmimemagicrule_p.h"
QT_BEGIN_NAMESPACE
class QMimeMagicRuleMatcher
@ -78,4 +80,5 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEMAGICRULEMATCHER_P_H

View File

@ -33,6 +33,8 @@
#include "qmimeprovider_p.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetypeparser_p.h"
#include <qstandardpaths.h>
#include "qmimemagicrulematcher_p.h"
@ -866,3 +868,5 @@ void QMimeXMLProvider::addMagicMatcher(const QMimeMagicRuleMatcher &matcher)
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -45,8 +45,11 @@
// We mean it.
//
#include <QtCore/qdatetime.h>
#include "qmimedatabase_p.h"
#ifndef QT_NO_MIMETYPE
#include <QtCore/qdatetime.h>
#include <QtCore/qset.h>
QT_BEGIN_NAMESPACE
@ -168,4 +171,5 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMEPROVIDER_P_H

View File

@ -33,6 +33,8 @@
#include "qmimetype.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetype_p.h"
#include "qmimedatabase_p.h"
#include "qmimeprovider_p.h"
@ -449,3 +451,5 @@ QDebug operator<<(QDebug debug, const QMimeType &mime)
#endif
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -34,6 +34,10 @@
#ifndef QMIMETYPE_H
#define QMIMETYPE_H
#include <QtCore/qglobal.h>
#ifndef QT_NO_MIMETYPE
#include <QtCore/qshareddata.h>
#include <QtCore/qstring.h>
@ -108,4 +112,6 @@ Q_CORE_EXPORT QDebug operator<<(QDebug debug, const QMimeType &mime);
#endif
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // QMIMETYPE_H

View File

@ -47,6 +47,8 @@
#include "qmimetype.h"
#ifndef QT_NO_MIMETYPE
#include <QtCore/qhash.h>
#include <QtCore/qstringlist.h>
@ -112,4 +114,5 @@ QT_END_NAMESPACE
QT_END_NAMESPACE
#endif
#endif // QT_NO_MIMETYPE
#endif // QMIMETYPE_P_H

View File

@ -35,6 +35,8 @@
#include "qmimetypeparser_p.h"
#ifndef QT_NO_MIMETYPE
#include "qmimetype_p.h"
#include "qmimemagicrulematcher_p.h"
@ -341,3 +343,5 @@ bool QMimeTypeParserBase::parse(QIODevice *dev, const QString &fileName, QString
}
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE

View File

@ -47,6 +47,9 @@
//
#include "qmimedatabase_p.h"
#ifndef QT_NO_MIMETYPE
#include "qmimeprovider_p.h"
QT_BEGIN_NAMESPACE
@ -118,4 +121,5 @@ private:
QT_END_NAMESPACE
#endif // QT_NO_MIMETYPE
#endif // MIMETYPEPARSER_P_H

View File

@ -438,6 +438,7 @@ QPrint::ColorMode QPpdPrintDevice::defaultColorMode() const
return QPrint::GrayScale;
}
#ifndef QT_NO_MIMETYPE
void QPpdPrintDevice::loadMimeTypes() const
{
// TODO No CUPS api? Need to manually load CUPS mime.types file?
@ -453,6 +454,7 @@ void QPpdPrintDevice::loadMimeTypes() const
m_mimeTypes.append(db.mimeTypeForName(QStringLiteral("text/plain")));
m_haveMimeTypes = true;
}
#endif
void QPpdPrintDevice::loadPrinter()
{

View File

@ -95,7 +95,9 @@ protected:
void loadOutputBins() const Q_DECL_OVERRIDE;
void loadDuplexModes() const Q_DECL_OVERRIDE;
void loadColorModes() const Q_DECL_OVERRIDE;
#ifndef QT_NO_MIMETYPE
void loadMimeTypes() const Q_DECL_OVERRIDE;
#endif
private:
void loadPrinter();

View File

@ -359,6 +359,7 @@ QList<QPrint::ColorMode> QPlatformPrintDevice::supportedColorModes() const
return m_colorModes.toList();
}
#ifndef QT_NO_MIMETYPE
void QPlatformPrintDevice::loadMimeTypes() const
{
}
@ -369,6 +370,7 @@ QList<QMimeType> QPlatformPrintDevice::supportedMimeTypes() const
loadMimeTypes();
return m_mimeTypes.toList();
}
#endif // QT_NO_MIMETYPE
QPageSize QPlatformPrintDevice::createPageSize(const QString &key, const QSize &size, const QString &localizedName)
{

View File

@ -114,7 +114,9 @@ public:
virtual QPrint::ColorMode defaultColorMode() const;
virtual QList<QPrint::ColorMode> supportedColorModes() const;
#ifndef QT_NO_MIMETYPE
virtual QList<QMimeType> supportedMimeTypes() const;
#endif
static QPageSize createPageSize(const QString &key, const QSize &size, const QString &localizedName);
static QPageSize createPageSize(int windowsId, const QSize &size, const QString &localizedName);
@ -126,7 +128,9 @@ protected:
virtual void loadOutputBins() const;
virtual void loadDuplexModes() const;
virtual void loadColorModes() const;
#ifndef QT_NO_MIMETYPE
virtual void loadMimeTypes() const;
#endif
QPageSize supportedPageSizeMatch(const QPageSize &pageSize) const;
@ -163,8 +167,10 @@ protected:
mutable bool m_haveColorModes;
mutable QVector<QPrint::ColorMode> m_colorModes;
#ifndef QT_NO_MIMETYPE
mutable bool m_haveMimeTypes;
mutable QVector<QMimeType> m_mimeTypes;
#endif
};
QT_END_NAMESPACE

View File

@ -237,10 +237,12 @@ QList<QPrint::ColorMode> QPrintDevice::supportedColorModes() const
return isValid() ? d->supportedColorModes() : QList<QPrint::ColorMode>();
}
#ifndef QT_NO_MIMETYPE
QList<QMimeType> QPrintDevice::supportedMimeTypes() const
{
return isValid() ? d->supportedMimeTypes() : QList<QMimeType>();
}
#endif // QT_NO_MIMETYPE
#endif // QT_NO_PRINTER

View File

@ -123,7 +123,9 @@ public:
QPrint::ColorMode defaultColorMode() const;
QList<QPrint::ColorMode> supportedColorModes() const;
#ifndef QT_NO_MIMETYPE
QList<QMimeType> supportedMimeTypes() const;
#endif
private:
friend class QPlatformPrinterSupport;

View File

@ -1516,6 +1516,8 @@ void QFileDialog::setFilter(QDir::Filters filters)
d->showHiddenAction->setChecked((filters & QDir::Hidden));
}
#ifndef QT_NO_MIMETYPE
static QString nameFilterForMime(const QString &mimeType)
{
QMimeDatabase db;
@ -1585,6 +1587,8 @@ void QFileDialog::selectMimeTypeFilter(const QString &filter)
selectNameFilter(text);
}
#endif // QT_NO_MIMETYPE
/*!
\property QFileDialog::viewMode
\brief the way files and directories are displayed in the dialog
@ -2843,9 +2847,12 @@ void QFileDialogPrivate::createWidgets()
if (!options->sidebarUrls().isEmpty())
q->setSidebarUrls(options->sidebarUrls());
q->setDirectoryUrl(options->initialDirectory());
#ifndef QT_NO_MIMETYPE
if (!options->mimeTypeFilters().isEmpty())
q->setMimeTypeFilters(options->mimeTypeFilters());
else if (!options->nameFilters().isEmpty())
else
#endif
if (!options->nameFilters().isEmpty())
q->setNameFilters(options->nameFilters());
q->selectNameFilter(options->initiallySelectedNameFilter());
q->setDefaultSuffix(options->defaultSuffix());

View File

@ -119,9 +119,11 @@ public:
void selectNameFilter(const QString &filter);
QString selectedNameFilter() const;
#ifndef QT_NO_MIMETYPE
void setMimeTypeFilters(const QStringList &filters);
QStringList mimeTypeFilters() const;
void selectMimeTypeFilter(const QString &filter);
#endif
QDir::Filters filter() const;
void setFilter(QDir::Filters filters);