Commit 5a3a940a authored by Eike Ziller's avatar Eike Ziller
Browse files

Use new mime database



Change-Id: I4305872b6b11ef3e8a364280ffa5209a5a793600
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 365c1ddb
......@@ -4,7 +4,7 @@
<alias type="text/x-qml"/>
<sub-class-of type="text/plain"/>
<comment>QML file</comment>
<glob weight="50" pattern="*.qml"/>
<glob pattern="*.qml"/>
</mime-type>
<mime-type type="application/x-qt.qbs+qml">
<alias type="text/x-qt.qbs+qml"/>
......@@ -16,7 +16,7 @@
<alias type="text/x-qt.ui+qml"/>
<sub-class-of type="application/x-qml"/>
<comment>QtQuick Designer ui file</comment>
<glob weight="100" pattern="*.ui.qml"/>
<glob pattern="*.ui.qml"/>
</mime-type>
<mime-type type="application/x-qmlproject">
<alias type="text/x-qmlproject"/>
......@@ -30,16 +30,6 @@
<comment>QML file</comment>
<glob pattern="*.qmltypes"/>
</mime-type>
<mime-type type="application/javascript">
<alias type="application/x-javascript"/>
<alias type="text/javascript"/>
<alias type="text/x-javascript"/>
<sub-class-of type="text/plain"/>
<comment>Qt Script file</comment>
<glob pattern="*.js"/>
<glob pattern="*.qs"/>
<glob pattern="*.qtt"/>
</mime-type>
<mime-type type="application/json">
<sub-class-of type="text/plain"/>
<comment>JSON file</comment>
......
......@@ -52,6 +52,7 @@
#include <qtsupport/qtsupportconstants.h>
#include <texteditor/textdocument.h>
#include <utils/hostosinfo.h>
#include <utils/mimetypes/mimedatabase.h>
#include <QDir>
#include <QFile>
......@@ -76,22 +77,18 @@ ModelManagerInterface::ProjectInfo QmlJSTools::Internal::ModelManager::defaultPr
ModelManagerInterface::ProjectInfo projectInfo(project);
ProjectExplorer::Target *activeTarget = 0;
if (project) {
QList<MimeGlobPattern> globs;
foreach (const MimeType &mimeType, MimeDatabase::mimeTypes())
if (mimeType.type() == QLatin1String(Constants::QML_MIMETYPE)
|| mimeType.subClassesOf().contains(QLatin1String(Constants::QML_MIMETYPE)))
globs << mimeType.globPatterns();
if (globs.isEmpty()) {
globs.append(MimeGlobPattern(QLatin1String("*.qbs")));
globs.append(MimeGlobPattern(QLatin1String("*.qml")));
globs.append(MimeGlobPattern(QLatin1String("*.qmltypes")));
globs.append(MimeGlobPattern(QLatin1String("*.qmlproject")));
Utils::MimeDatabase mdb;
QList<Utils::MimeType> qmlTypes;
foreach (const Utils::MimeType &mimeType, mdb.allMimeTypes()) {
if (mimeType.matchesName(QLatin1String(Constants::QML_MIMETYPE))
|| mimeType.allAncestors().contains(QLatin1String(Constants::QML_MIMETYPE)))
qmlTypes.append(mimeType);
}
foreach (const QString &filePath,
project->files(ProjectExplorer::Project::ExcludeGeneratedFiles))
foreach (const MimeGlobPattern &glob, globs)
if (glob.matches(filePath))
projectInfo.sourceFiles << filePath;
project->files(ProjectExplorer::Project::ExcludeGeneratedFiles)) {
if (mdb.bestMatch(filePath, qmlTypes).isValid())
projectInfo.sourceFiles << filePath;
}
activeTarget = project->activeTarget();
}
ProjectExplorer::Kit *activeKit = activeTarget ? activeTarget->kit() :
......@@ -179,22 +176,23 @@ QHash<QString,QmlJS::Dialect> ModelManager::languageForSuffix() const
QHash<QString,QmlJS::Dialect> res = ModelManagerInterface::languageForSuffix();
if (ICore::instance()) {
MimeType jsSourceTy = MimeDatabase::findByType(QLatin1String(Constants::JS_MIMETYPE));
Utils::MimeDatabase mdb;
Utils::MimeType jsSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::JS_MIMETYPE));
foreach (const QString &suffix, jsSourceTy.suffixes())
res[suffix] = Dialect::JavaScript;
MimeType qmlSourceTy = MimeDatabase::findByType(QLatin1String(Constants::QML_MIMETYPE));
Utils::MimeType qmlSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QML_MIMETYPE));
foreach (const QString &suffix, qmlSourceTy.suffixes())
res[suffix] = Dialect::Qml;
MimeType qbsSourceTy = MimeDatabase::findByType(QLatin1String(Constants::QBS_MIMETYPE));
Utils::MimeType qbsSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QBS_MIMETYPE));
foreach (const QString &suffix, qbsSourceTy.suffixes())
res[suffix] = Dialect::QmlQbs;
MimeType qmlProjectSourceTy = MimeDatabase::findByType(QLatin1String(Constants::QMLPROJECT_MIMETYPE));
Utils::MimeType qmlProjectSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QMLPROJECT_MIMETYPE));
foreach (const QString &suffix, qmlProjectSourceTy.suffixes())
res[suffix] = Dialect::QmlProject;
MimeType qmlUiSourceTy = MimeDatabase::findByType(QLatin1String(Constants::QMLUI_MIMETYPE));
Utils::MimeType qmlUiSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::QMLUI_MIMETYPE));
foreach (const QString &suffix, qmlUiSourceTy.suffixes())
res[suffix] = Dialect::QmlQtQuick2Ui;
MimeType jsonSourceTy = MimeDatabase::findByType(QLatin1String(Constants::JSON_MIMETYPE));
Utils::MimeType jsonSourceTy = mdb.mimeTypeForName(QLatin1String(Constants::JSON_MIMETYPE));
foreach (const QString &suffix, jsonSourceTy.suffixes())
res[suffix] = Dialect::Json;
}
......@@ -269,23 +267,6 @@ void ModelManager::updateDefaultProjectInfo()
}
// Check whether fileMimeType is the same or extends knownMimeType
bool ModelManager::matchesMimeType(const MimeType &fileMimeType, const MimeType &knownMimeType)
{
const QStringList knownTypeNames = QStringList(knownMimeType.type()) + knownMimeType.aliases();
foreach (const QString &knownTypeName, knownTypeNames)
if (fileMimeType.matchesType(knownTypeName))
return true;
// recursion to parent types of fileMimeType
foreach (const QString &parentMimeType, fileMimeType.subClassesOf())
if (matchesMimeType(MimeDatabase::findByType(parentMimeType), knownMimeType))
return true;
return false;
}
void ModelManager::addTaskInternal(QFuture<void> result, const QString &msg, const char *taskId) const
{
ProgressManager::addTask(result, msg, taskId);
......
......@@ -46,7 +46,7 @@
QT_FORWARD_DECLARE_CLASS(QTimer)
QT_FORWARD_DECLARE_CLASS(QLocale)
namespace Core { class MimeType; }
namespace Utils { class MimeType; }
namespace QmlJSTools {
namespace Internal {
......@@ -70,7 +70,6 @@ private slots:
void updateDefaultProjectInfo();
private:
void loadDefaultQmlTypeDescriptions();
static bool matchesMimeType(const Core::MimeType &fileMimeType, const Core::MimeType &knownMimeType);
};
} // namespace Internal
......
......@@ -42,8 +42,8 @@
#include <coreplugin/coreconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/progressmanager/progressmanager.h>
#include <utils/mimetypes/mimedatabase.h>
#include <QtPlugin>
#include <QMenu>
......@@ -72,9 +72,9 @@ QmlJSToolsPlugin::~QmlJSToolsPlugin()
bool QmlJSToolsPlugin::initialize(const QStringList &arguments, QString *error)
{
Q_UNUSED(arguments)
Q_UNUSED(error)
if (!MimeDatabase::addMimeTypes(QLatin1String(":/qmljstools/QmlJSTools.mimetypes.xml"), error))
return false;
Utils::MimeDatabase::addMimeTypes(QLatin1String(":/qmljstools/QmlJSTools.mimetypes.xml"));
m_settings = new QmlJSToolsSettings(this); // force registration of qmljstools settings
......
......@@ -37,10 +37,11 @@
#include <coreplugin/fileiconprovider.h>
#include <coreplugin/icore.h>
#include <coreplugin/mimedatabase.h>
#include <qtsupport/qtsupportconstants.h>
#include <utils/mimetypes/mimedatabase.h>
#include <QtPlugin>
#include <QApplication>
......@@ -58,18 +59,14 @@ QmlProjectPlugin::~QmlProjectPlugin()
bool QmlProjectPlugin::initialize(const QStringList &, QString *errorMessage)
{
using namespace Core;
const QLatin1String mimetypesXml(":/qmlproject/QmlProjectManager.mimetypes.xml");
if (!MimeDatabase::addMimeTypes(mimetypesXml, errorMessage))
return false;
Q_UNUSED(errorMessage)
Utils::MimeDatabase::addMimeTypes(QLatin1String(":/qmlproject/QmlProjectManager.mimetypes.xml"));
addAutoReleasedObject(new Internal::Manager);
addAutoReleasedObject(new Internal::QmlProjectRunConfigurationFactory);
addAutoReleasedObject(new Internal::QmlApplicationWizard);
FileIconProvider::registerIconOverlayForSuffix(":/qmlproject/images/qmlproject.png", "qmlproject");
Core::FileIconProvider::registerIconOverlayForSuffix(":/qmlproject/images/qmlproject.png", "qmlproject");
return true;
}
......
......@@ -33,7 +33,6 @@
#include "qmlprojectmanagerconstants.h"
#include "qmlprojectrunconfigurationwidget.h"
#include "qmlprojectenvironmentaspect.h"
#include <coreplugin/mimedatabase.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/icore.h>
......@@ -43,6 +42,7 @@
#include <qtsupport/qtsupportconstants.h>
#include <utils/fileutils.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcprocess.h>
#include <utils/winutils.h>
......@@ -264,22 +264,23 @@ void QmlProjectRunConfiguration::changeCurrentFile(IEditor *editor)
void QmlProjectRunConfiguration::updateEnabled()
{
bool qmlFileFound = false;
Utils::MimeDatabase mdb;
if (mainScriptSource() == FileInEditor) {
IDocument *document = EditorManager::currentDocument();
if (document) {
m_currentFileFilename = document->filePath().toString();
if (MimeDatabase::findByFile(mainScript()).type() == QLatin1String("application/x-qml"))
if (mdb.mimeTypeForFile(mainScript()).matchesName(QLatin1String("application/x-qml")))
qmlFileFound = true;
}
if (!document
|| MimeDatabase::findByFile(mainScript()).type() == QLatin1String("application/x-qmlproject")) {
|| mdb.mimeTypeForFile(mainScript()).matchesName(QLatin1String("application/x-qmlproject"))) {
// find a qml file with lowercase filename. This is slow, but only done
// in initialization/other border cases.
foreach (const QString &filename, target()->project()->files(Project::AllFiles)) {
const QFileInfo fi(filename);
if (!filename.isEmpty() && fi.baseName()[0].isLower()
&& MimeDatabase::findByFile(fi).type() == QLatin1String("application/x-qml"))
&& mdb.mimeTypeForFile(fi).matchesName(QLatin1String("application/x-qml")))
{
m_currentFileFilename = filename;
qmlFileFound = true;
......
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/vnd.rim.qnx.bar_descriptor">
<comment>BAR descriptor file (BlackBerry)</comment>
<sub-class-of type="application/xml"/>
<glob pattern="*.xml"/>
<magic>
<match value="&lt;qnx&gt;" type="string" offset="0:1000"/>
</magic>
</mime-type>
</mime-info>
This diff is collapsed.
This diff is collapsed.
......@@ -50,7 +50,6 @@ SOURCES += qnxplugin.cpp \
blackberryabstractdeploystep.cpp \
blackberryndksettingswidget.cpp \
blackberryndksettingspage.cpp \
bardescriptormagicmatcher.cpp \
bardescriptoreditorfactory.cpp \
bardescriptoreditor.cpp \
bardescriptoreditorwidget.cpp \
......@@ -161,7 +160,6 @@ HEADERS += qnxplugin.h\
blackberryabstractdeploystep.h \
blackberryndksettingswidget.h \
blackberryndksettingspage.h \
bardescriptormagicmatcher.h \
bardescriptoreditorfactory.h \
bardescriptoreditor.h \
bardescriptoreditorwidget.h \
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment