Commit a37589d4 authored by hjk's avatar hjk Committed by Tobias Hunger

Apply 'static' pattern to MimeDatabase

Also adjust and streamline using and surrounding code.

Change-Id: I6a8b05126bdcbb74ff611b21c7cb3c5902a2d5ca
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 1226400a
......@@ -89,7 +89,7 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
androidManifestMimeType.setGlobPatterns(QList<Core::MimeGlobPattern>() << androidManifestGlobPattern);
androidManifestMimeType.setSubClassesOf(QStringList() << QLatin1String("application/xml"));
if (!Core::ICore::mimeDatabase()->addMimeType(androidManifestMimeType)) {
if (!Core::MimeDatabase::addMimeType(androidManifestMimeType)) {
*errorMessage = tr("Could not add mime-type for AndroidManifest.xml editor.");
return false;
}
......
......@@ -38,7 +38,6 @@
#include "configurestep.h"
#include "autotoolsprojectconstants.h"
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <QStringList>
......@@ -59,7 +58,7 @@ bool AutotoolsProjectPlugin::initialize(const QStringList &arguments,
{
Q_UNUSED(arguments);
if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":autotoolsproject/AutotoolsProjectManager.mimetypes.xml"), errorString))
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":autotoolsproject/AutotoolsProjectManager.mimetypes.xml"), errorString))
return false;
addAutoReleasedObject(new AutotoolsBuildConfigurationFactory);
......
......@@ -374,7 +374,7 @@ bool ClearCasePlugin::initialize(const QStringList & /*arguments */, QString *er
connect(ProgressManager::instance(), SIGNAL(allTasksFinished(QString)),
this, SLOT(tasksFinished(QString)));
if (!ICore::mimeDatabase()->addMimeTypes(QLatin1String(":/clearcase/ClearCase.mimetypes.xml"), errorMessage))
if (!MimeDatabase::addMimeTypes(QLatin1String(":/clearcase/ClearCase.mimetypes.xml"), errorMessage))
return false;
m_settings.fromSettings(ICore::settings());
......
......@@ -39,7 +39,6 @@
#include "cmakehighlighterfactory.h"
#include <coreplugin/featureprovider.h>
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <texteditor/texteditoractionhandler.h>
......@@ -69,7 +68,7 @@ CMakeProjectPlugin::~CMakeProjectPlugin()
bool CMakeProjectPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
{
if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":cmakeproject/CMakeProjectManager.mimetypes.xml"), errorMessage))
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":cmakeproject/CMakeProjectManager.mimetypes.xml"), errorMessage))
return false;
CMakeSettingsPage *cmp = new CMakeSettingsPage();
addAutoReleasedObject(cmp);
......
......@@ -77,8 +77,8 @@ public:
QString id;
QString category;
QString displayCategory;
Core::FeatureSet requiredFeatures;
Core::IWizard::WizardFlags flags;
FeatureSet requiredFeatures;
IWizard::WizardFlags flags;
QString descriptionImage;
};
......@@ -210,12 +210,12 @@ QString BaseFileWizardParameters::displayCategory() const
return m_d->displayCategory;
}
Core::FeatureSet BaseFileWizardParameters::requiredFeatures() const
FeatureSet BaseFileWizardParameters::requiredFeatures() const
{
return m_d->requiredFeatures;
}
void BaseFileWizardParameters::setRequiredFeatures(Core::FeatureSet features)
void BaseFileWizardParameters::setRequiredFeatures(FeatureSet features)
{
m_d->requiredFeatures = features;
......@@ -226,12 +226,12 @@ void BaseFileWizardParameters::setDisplayCategory(const QString &v)
m_d->displayCategory = v;
}
Core::IWizard::WizardFlags BaseFileWizardParameters::flags() const
IWizard::WizardFlags BaseFileWizardParameters::flags() const
{
return m_d->flags;
}
void BaseFileWizardParameters::setFlags(Core::IWizard::WizardFlags flags)
void BaseFileWizardParameters::setFlags(IWizard::WizardFlags flags)
{
m_d->flags = flags;
}
......@@ -537,8 +537,8 @@ void BaseFileWizard::runWizard(const QString &path, QWidget *parent, const QStri
if (removeOpenProjectAttribute) {
for (int i = 0; i < files.count(); i++) {
if (files[i].attributes() & Core::GeneratedFile::OpenProjectAttribute)
files[i].setAttributes(Core::GeneratedFile::OpenEditorAttribute);
if (files[i].attributes() & GeneratedFile::OpenProjectAttribute)
files[i].setAttributes(GeneratedFile::OpenEditorAttribute);
}
}
......@@ -549,12 +549,12 @@ void BaseFileWizard::runWizard(const QString &path, QWidget *parent, const QStri
}
Core::FeatureSet BaseFileWizard::requiredFeatures() const
FeatureSet BaseFileWizard::requiredFeatures() const
{
return d->m_parameters.requiredFeatures();
}
Core::IWizard::WizardFlags BaseFileWizard::flags() const
IWizard::WizardFlags BaseFileWizard::flags() const
{
return d->m_parameters.flags();
}
......@@ -649,9 +649,9 @@ bool BaseFileWizard::postGenerateFiles(const QWizard *, const GeneratedFiles &l,
bool BaseFileWizard::postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage)
{
foreach (const Core::GeneratedFile &file, l) {
if (file.attributes() & Core::GeneratedFile::OpenEditorAttribute) {
if (!Core::EditorManager::openEditor(file.path(), file.editorId())) {
foreach (const GeneratedFile &file, l) {
if (file.attributes() & GeneratedFile::OpenEditorAttribute) {
if (!EditorManager::openEditor(file.path(), file.editorId())) {
if (errorMessage)
*errorMessage = tr("Failed to open an editor for '%1'.").arg(QDir::toNativeSeparators(file.path()));
return false;
......@@ -773,7 +773,7 @@ QString BaseFileWizard::buildFileName(const QString &path,
QString BaseFileWizard::preferredSuffix(const QString &mimeType)
{
const QString rc = Core::ICore::mimeDatabase()->preferredSuffixByType(mimeType);
const QString rc = MimeDatabase::preferredSuffixByType(mimeType);
if (rc.isEmpty())
qWarning("%s: WARNING: Unable to find a preferred suffix for %s.",
Q_FUNC_INFO, mimeType.toUtf8().constData());
......
......@@ -759,7 +759,7 @@ QString DocumentManager::getSaveAsFileName(const IDocument *document, const QStr
QString filterString;
if (filter.isEmpty()) {
if (const MimeType &mt = Core::ICore::mimeDatabase()->findByFile(fi))
if (const MimeType &mt = MimeDatabase::findByFile(fi))
filterString = mt.filterString();
selectedFilter = &filterString;
} else {
......@@ -1298,7 +1298,7 @@ void DocumentManager::populateOpenWithMenu(QMenu *menu, const QString &fileName)
bool anyMatches = false;
if (const MimeType mt = ICore::mimeDatabase()->findByFile(QFileInfo(fileName))) {
if (const MimeType mt = MimeDatabase::findByFile(QFileInfo(fileName))) {
const EditorFactoryList factories = EditorManager::editorFactories(mt, false);
const ExternalEditorList externalEditors = EditorManager::externalEditors(mt, false);
anyMatches = !factories.empty() || !externalEditors.empty();
......
......@@ -1280,8 +1280,7 @@ Core::IEditor *EditorManager::activateEditorForDocument(Core::Internal::EditorVi
* or IExternalEditor), find the one best matching the mimetype passed in.
* Recurse over the parent classes of the mimetype to find them. */
template <class EditorFactoryLike>
static void mimeTypeFactoryRecursion(const MimeDatabase *db,
const MimeType &mimeType,
static void mimeTypeFactoryRecursion(const MimeType &mimeType,
const QList<EditorFactoryLike*> &allFactories,
bool firstMatchOnly,
QList<EditorFactoryLike*> *list)
......@@ -1305,8 +1304,8 @@ static void mimeTypeFactoryRecursion(const MimeDatabase *db,
return;
const QStringList::const_iterator pcend = parentTypes .constEnd();
for (QStringList::const_iterator pit = parentTypes .constBegin(); pit != pcend; ++pit) {
if (const MimeType parent = db->findByType(*pit))
mimeTypeFactoryRecursion(db, parent, allFactories, firstMatchOnly, list);
if (const MimeType parent = MimeDatabase::findByType(*pit))
mimeTypeFactoryRecursion(parent, allFactories, firstMatchOnly, list);
}
}
......@@ -1315,7 +1314,7 @@ EditorManager::EditorFactoryList
{
EditorFactoryList rc;
const EditorFactoryList allFactories = ExtensionSystem::PluginManager::getObjects<IEditorFactory>();
mimeTypeFactoryRecursion(ICore::mimeDatabase(), mimeType, allFactories, bestMatchOnly, &rc);
mimeTypeFactoryRecursion(mimeType, allFactories, bestMatchOnly, &rc);
if (debugEditorManager)
qDebug() << Q_FUNC_INFO << mimeType.type() << " returns " << rc;
return rc;
......@@ -1326,7 +1325,7 @@ EditorManager::ExternalEditorList
{
ExternalEditorList rc;
const ExternalEditorList allEditors = ExtensionSystem::PluginManager::getObjects<IExternalEditor>();
mimeTypeFactoryRecursion(ICore::mimeDatabase(), mimeType, allEditors, bestMatchOnly, &rc);
mimeTypeFactoryRecursion(mimeType, allEditors, bestMatchOnly, &rc);
if (debugEditorManager)
qDebug() << Q_FUNC_INFO << mimeType.type() << " returns " << rc;
return rc;
......@@ -1353,15 +1352,15 @@ IEditor *EditorManager::createEditor(const Id &editorId, const QString &fileName
if (!editorId.isValid()) {
const QFileInfo fileInfo(fileName);
// Find by mime type
MimeType mimeType = ICore::mimeDatabase()->findByFile(fileInfo);
MimeType mimeType = MimeDatabase::findByFile(fileInfo);
if (!mimeType) {
qWarning("%s unable to determine mime type of %s/%s. Falling back to text/plain",
Q_FUNC_INFO, fileName.toUtf8().constData(), editorId.name().constData());
mimeType = ICore::mimeDatabase()->findByType(QLatin1String("text/plain"));
mimeType = MimeDatabase::findByType(QLatin1String("text/plain"));
}
// open text files > 48 MB in binary editor
if (fileInfo.size() > maxTextFileSize() && mimeType.type().startsWith(QLatin1String("text")))
mimeType = ICore::mimeDatabase()->findByType(QLatin1String("application/octet-stream"));
mimeType = MimeDatabase::findByType(QLatin1String("application/octet-stream"));
factories = editorFactories(mimeType, true);
} else {
// Find by editor id
......@@ -1406,10 +1405,10 @@ Core::Id EditorManager::getOpenWithEditorId(const QString &fileName,
bool *isExternalEditor)
{
// Collect editors that can open the file
MimeType mt = ICore::mimeDatabase()->findByFile(fileName);
MimeType mt = MimeDatabase::findByFile(fileName);
//Unable to determine mime type of fileName. Falling back to text/plain",
if (!mt)
mt = ICore::mimeDatabase()->findByType(QLatin1String("text/plain"));
mt = MimeDatabase::findByType(QLatin1String("text/plain"));
QList<Id> allEditorIds;
QStringList allEditorDisplayNames;
QList<Id> externalEditorIds;
......@@ -1606,7 +1605,7 @@ bool EditorManager::openExternalEditor(const QString &fileName, const Core::Id &
QStringList EditorManager::getOpenFileNames()
{
QString selectedFilter;
const QString &fileFilters = ICore::mimeDatabase()->allFiltersString(&selectedFilter);
const QString &fileFilters = MimeDatabase::allFiltersString(&selectedFilter);
return DocumentManager::getOpenFileNames(fileFilters, QString(), &selectedFilter);
}
......@@ -1769,9 +1768,9 @@ bool EditorManager::saveDocumentAs(IDocument *documentParam)
if (!document)
return false;
const QString &filter = ICore::mimeDatabase()->allFiltersString();
const QString filter = MimeDatabase::allFiltersString();
QString selectedFilter =
ICore::mimeDatabase()->findByFile(QFileInfo(document->filePath())).filterString();
MimeDatabase::findByFile(QFileInfo(document->filePath())).filterString();
const QString &absoluteFilePath =
DocumentManager::getSaveAsFileName(document, filter, &selectedFilter);
......
......@@ -114,13 +114,6 @@
the plugin manager's object pool.
*/
/*!
\fn MimeDatabase *ICore::mimeDatabase()
\brief Returns the application's mime database.
Use the mime database to manage mime types.
*/
/*!
\fn QSettings *ICore::settings(QSettings::Scope scope = QSettings::UserScope)
\brief Returns the application's main settings object.
......@@ -361,11 +354,6 @@ VcsManager *ICore::vcsManager()
return m_mainwindow->vcsManager();
}
MimeDatabase *ICore::mimeDatabase()
{
return m_mainwindow->mimeDatabase();
}
QSettings *ICore::settings(QSettings::Scope scope)
{
return m_mainwindow->settings(scope);
......
......@@ -47,7 +47,6 @@ namespace Core {
class IWizard;
class Context;
class IContext;
class MimeDatabase;
class ProgressManager;
class SettingsDatabase;
class VcsManager;
......@@ -82,7 +81,6 @@ public:
QWidget *parent = 0);
static VcsManager *vcsManager();
static MimeDatabase *mimeDatabase();
static QSettings *settings(QSettings::Scope scope = QSettings::UserScope);
static SettingsDatabase *settingsDatabase();
......
......@@ -1276,7 +1276,6 @@ public:
void debug(QTextStream &str) const;
private:
typedef QHash<QString, MimeMapEntry> TypeMimeTypeMap;
typedef QHash<QString, QString> AliasMap;
typedef QMultiHash<QString, QString> ParentChildrenMap;
......@@ -1297,6 +1296,7 @@ private:
AliasMap m_aliasMap;
ParentChildrenMap m_parentChildrenMap;
int m_maxLevel;
QMutex m_mutex;
};
const QChar MimeDatabasePrivate::kSemiColon(QLatin1Char(';'));
......@@ -1825,9 +1825,11 @@ void MimeDatabasePrivate::debug(QTextStream &str) const
str << "<MimeDatabase\n";
}
MimeDatabase::MimeDatabase() :
d(new MimeDatabasePrivate)
static MimeDatabasePrivate *d;
MimeDatabase::MimeDatabase()
{
d = new MimeDatabasePrivate;
}
MimeDatabase::~MimeDatabase()
......@@ -1835,75 +1837,75 @@ MimeDatabase::~MimeDatabase()
delete d;
}
MimeType MimeDatabase::findByType(const QString &typeOrAlias) const
MimeType MimeDatabase::findByType(const QString &typeOrAlias)
{
m_mutex.lock();
d->m_mutex.lock();
const MimeType rc = d->findByType(typeOrAlias);
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
MimeType MimeDatabase::findByFileUnlocked(const QFileInfo &f) const
MimeType MimeDatabase::findByFileUnlocked(const QFileInfo &f)
{
return d->findByFile(f);
}
MimeType MimeDatabase::findByFile(const QFileInfo &f) const
MimeType MimeDatabase::findByFile(const QFileInfo &f)
{
m_mutex.lock();
d->m_mutex.lock();
const MimeType rc = findByFileUnlocked(f);
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
MimeType MimeDatabase::findByData(const QByteArray &data) const
MimeType MimeDatabase::findByData(const QByteArray &data)
{
m_mutex.lock();
d->m_mutex.lock();
const MimeType rc = d->findByData(data);
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
bool MimeDatabase::addMimeType(const MimeType &mt)
{
m_mutex.lock();
d->m_mutex.lock();
const bool rc = d->addMimeType(mt);
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
bool MimeDatabase::addMimeTypes(const QString &fileName, QString *errorMessage)
{
m_mutex.lock();
d->m_mutex.lock();
const bool rc = d->addMimeTypes(fileName, errorMessage);
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
bool MimeDatabase::addMimeTypes(QIODevice *device, QString *errorMessage)
{
m_mutex.lock();
d->m_mutex.lock();
const bool rc = d->addMimeTypes(device, errorMessage);
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
QStringList MimeDatabase::suffixes() const
QStringList MimeDatabase::suffixes()
{
m_mutex.lock();
d->m_mutex.lock();
const QStringList rc = d->suffixes();
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
QStringList MimeDatabase::filterStrings() const
QStringList MimeDatabase::filterStrings()
{
m_mutex.lock();
d->m_mutex.lock();
const QStringList rc = d->filterStrings();
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
QString MimeDatabase::allFiltersString(QString *allFilesFilter) const
QString MimeDatabase::allFiltersString(QString *allFilesFilter)
{
if (allFilesFilter)
allFilesFilter->clear();
......@@ -1927,58 +1929,58 @@ QString MimeDatabase::allFiltersString(QString *allFilesFilter) const
return filters.join(QLatin1String(";;"));
}
QList<MimeGlobPattern> MimeDatabase::globPatterns() const
QList<MimeGlobPattern> MimeDatabase::globPatterns()
{
m_mutex.lock();
d->m_mutex.lock();
const QList<MimeGlobPattern> rc = d->globPatterns();
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
void MimeDatabase::setGlobPatterns(const QString &typeOrAlias,
const QList<MimeGlobPattern> &globPatterns)
{
m_mutex.lock();
d->m_mutex.lock();
d->setGlobPatterns(typeOrAlias, globPatterns);
m_mutex.unlock();
d->m_mutex.unlock();
}
MimeDatabase::IMagicMatcherList MimeDatabase::magicMatchers() const
MimeDatabase::IMagicMatcherList MimeDatabase::magicMatchers()
{
m_mutex.lock();
d->m_mutex.lock();
const IMagicMatcherList rc = d->magicMatchers();
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
void MimeDatabase::setMagicMatchers(const QString &typeOrAlias,
const IMagicMatcherList &matchers)
{
m_mutex.lock();
d->m_mutex.lock();
d->setMagicMatchers(typeOrAlias, matchers);
m_mutex.unlock();
d->m_mutex.unlock();
}
QList<MimeType> MimeDatabase::mimeTypes() const
QList<MimeType> MimeDatabase::mimeTypes()
{
m_mutex.lock();
d->m_mutex.lock();
const QList<MimeType> &mimeTypes = d->mimeTypes();
m_mutex.unlock();
d->m_mutex.unlock();
return mimeTypes;
}
void MimeDatabase::syncUserModifiedMimeTypes()
{
m_mutex.lock();
d->m_mutex.lock();
d->syncUserModifiedMimeTypes();
m_mutex.unlock();
d->m_mutex.unlock();
}
void MimeDatabase::clearUserModifiedMimeTypes()
{
m_mutex.lock();
d->m_mutex.lock();
d->clearUserModifiedMimeTypes();
m_mutex.unlock();
d->m_mutex.unlock();
}
QList<MimeType> MimeDatabase::readUserModifiedMimeTypes()
......@@ -1991,14 +1993,14 @@ void MimeDatabase::writeUserModifiedMimeTypes(const QList<MimeType> &mimeTypes)
MimeDatabasePrivate::writeUserModifiedMimeTypes(mimeTypes);
}
QString MimeDatabase::preferredSuffixByType(const QString &type) const
QString MimeDatabase::preferredSuffixByType(const QString &type)
{
if (const MimeType mt = findByType(type))
return mt.preferredSuffix(); // already does Mutex locking
return QString();
}
QString MimeDatabase::preferredSuffixByFile(const QFileInfo &f) const
QString MimeDatabase::preferredSuffixByFile(const QFileInfo &f)
{
if (const MimeType mt = findByFile(f))
return mt.preferredSuffix(); // already does Mutex locking
......@@ -2007,9 +2009,9 @@ QString MimeDatabase::preferredSuffixByFile(const QFileInfo &f) const
bool MimeDatabase::setPreferredSuffix(const QString &typeOrAlias, const QString &suffix)
{
m_mutex.lock();
d->m_mutex.lock();
const bool rc = d->setPreferredSuffix(typeOrAlias, suffix);
m_mutex.unlock();
d->m_mutex.unlock();
return rc;
}
......@@ -2023,15 +2025,15 @@ QStringList MimeDatabase::fromGlobPatterns(const QList<MimeGlobPattern> &globPat
return MimeDatabasePrivate::fromGlobPatterns(globPatterns);
}
QDebug operator<<(QDebug d, const MimeDatabase &mt)
{
QString s;
{
QTextStream str(&s);
mt.d->debug(str);
}
d << s;
return d;
}
//QDebug operator<<(QDebug d, const MimeDatabase &mt)
//{
// QString s;
// {
// QTextStream str(&s);
// d->debug(str);
// }
// db << s;
// return db;
//}
} // namespace Core
......@@ -261,80 +261,57 @@ public:
typedef IMagicMatcher::IMagicMatcherList IMagicMatcherList;
typedef IMagicMatcher::IMagicMatcherSharedPointer IMagicMatcherSharedPointer;
bool addMimeTypes(const QString &fileName, QString *errorMessage);
bool addMimeTypes(QIODevice *device, QString *errorMessage);
bool addMimeType(const MimeType &mt);
static bool addMimeTypes(const QString &fileName, QString *errorMessage);
static bool addMimeTypes(QIODevice *device, QString *errorMessage);
static bool addMimeType(const MimeType &mt);
// Returns a mime type or Null one if none found
MimeType findByType(const QString &type) const;
static MimeType findByType(const QString &type);
// Returns a mime type or Null one if none found
MimeType findByFile(const QFileInfo &f) const;
static MimeType findByFile(const QFileInfo &f);
// Returns a mime type or Null one if none found
MimeType findByData(const QByteArray &data) const;
// Convenience that mutex-locks the DB and calls a function
// of the signature 'void f(const MimeType &, const QFileInfo &, const QString &)'
// for each filename of a sequence. This avoids locking the DB for each
// single file.
template <class Iterator, typename Function>
inline void findByFile(Iterator i1, const Iterator &i2, Function f) const;
static MimeType findByData(const QByteArray &data);
// Return all known suffixes
QStringList suffixes() const;
bool setPreferredSuffix(const QString &typeOrAlias, const QString &suffix);
QString preferredSuffixByType(const QString &type) const;
QString preferredSuffixByFile(const QFileInfo &f) const;
static QStringList suffixes();
static bool setPreferredSuffix(const QString &typeOrAlias, const QString &suffix);
static QString preferredSuffixByType(const QString &type);
static QString preferredSuffixByFile(const QFileInfo &f);
QStringList filterStrings() const;
static QStringList filterStrings();
// Return a string with all the possible file filters, for use with file dialogs
QString allFiltersString(QString *allFilesFilter = 0) const;
static QString allFiltersString(QString *allFilesFilter = 0);
QList<MimeGlobPattern> globPatterns() const;
void setGlobPatterns(const QString &typeOrAlias, const QList<MimeGlobPattern> &globPatterns);
static QList<MimeGlobPattern> globPatterns();
static void setGlobPatterns(const QString &typeOrAlias, const QList<MimeGlobPattern> &globPatterns);
IMagicMatcherList magicMatchers() const;
void setMagicMatchers(const QString &typeOrAlias, const IMagicMatcherList &matchers);
static IMagicMatcherList magicMatchers();
static void setMagicMatchers(const QString &typeOrAlias, const IMagicMatcherList &matchers);
QList<MimeType> mimeTypes() const;
static QList<MimeType> mimeTypes();
// The mime types from the functions bellow are considered only in regard to
// their glob patterns and rule-based magic matchers.
void syncUserModifiedMimeTypes();
static void syncUserModifiedMimeTypes();
static QList<MimeType> readUserModifiedMimeTypes();
static void writeUserModifiedMimeTypes(const QList<MimeType> &mimeTypes);
void clearUserModifiedMimeTypes();
static void clearUserModifiedMimeTypes();
static QList<MimeGlobPattern> toGlobPatterns(const QStringList &patterns,
int weight = MimeGlobPattern::MaxWeight);
static QStringList fromGlobPatterns(const QList<MimeGlobPattern> &globPatterns);
friend QDebug operator<<(QDebug d, const MimeDatabase &mt);
private:
MimeDatabase();
~MimeDatabase();
MimeType findByFileUnlocked(const QFileInfo &f) const;
MimeDatabasePrivate *d;
mutable QMutex m_mutex;
static MimeType findByFileUnlocked(const QFileInfo &f);
friend class Core::Internal::MainWindow;
};
template <class Iterator, typename Function>
void MimeDatabase::findByFile(Iterator i1, const Iterator &i2, Function f) const
{
m_mutex.lock();
for ( ; i1 != i2; ++i1) {
const QFileInfo fi(*i1);
f(findByFileUnlocked(fi), fi, *i1);
}
m_mutex.unlock();
}
} // namespace Core
#endif // MIMEDATABASE_H
......@@ -126,10 +126,10 @@ QVariant MimeTypeSettingsModel::data(const QModelIndex &modelIndex, int role) co
void MimeTypeSettingsModel::load()
{
m_mimeTypes = ICore::mimeDatabase()->mimeTypes();
m_mimeTypes = MimeDatabase::mimeTypes();
qSort(m_mimeTypes.begin(), m_mimeTypes.end(), MimeTypeComp());
m_knownPatterns = QSet<QString>::fromList(
MimeDatabase::fromGlobPatterns(ICore::mimeDatabase()->globPatterns()));
MimeDatabase::fromGlobPatterns(MimeDatabase::globPatterns()));