Commit ce3ab6f7 authored by con's avatar con
Browse files

Merge branch 'master' of scm.dev.nokia.troll.no:creator/mainline

parents 2ca77dfe b15e93cf
......@@ -31,6 +31,9 @@
**
**************************************************************************/
// WARNING: This code is shared with the qmlplugindump tool code in Qt.
// Modifications to this file need to be applied there.
#include <QtDeclarative/QtDeclarative>
#include <QtDeclarative/private/qdeclarativemetatype_p.h>
#include <QtDeclarative/private/qdeclarativeopenmetaobject_p.h>
......
......@@ -31,6 +31,9 @@
**
**************************************************************************/
// WARNING: This code is shared with the qmlplugindump tool code in Qt.
// Modifications to this file need to be applied there.
#include "qmlstreamwriter.h"
#include <QtCore/QBuffer>
......
......@@ -31,6 +31,9 @@
**
**************************************************************************/
// WARNING: This code is shared with the qmlplugindump tool code in Qt.
// Modifications to this file need to be applied there.
#ifndef QMLSTREAMWRITER_H
#define QMLSTREAMWRITER_H
......
......@@ -56,11 +56,11 @@ leave room for the Qt 4 target page.
<!-- Create a 2nd wizard page with parameters -->
<fieldpagetitle>Custom QML Extension Plugin Parameters</fieldpagetitle>
<fields>
<field mandatory="false" name="ObjectName">
<field mandatory="true" name="ObjectName">
<fieldcontrol class="QLineEdit" validator='^[A-Za-z0-9_]+$' defaulttext="MyItem"/>
<fielddescription>Object Class-name:</fielddescription>
</field>
<field mandatory="false" name="Uri">
<field mandatory="true" name="Uri">
<fieldcontrol class="QLineEdit" validator='^[A-Za-z0-9]+([A-Za-z0-9-]*[A-Za-z0-9]+)?(\.[A-Za-z0-9]+([-A-Za-z0-9]*[A-Za-z0-9]+)?)*$' defaulttext="com.mycompany.qmlcomponents"/>
<fielddescription>URI:</fielddescription>
</field>
......
......@@ -253,7 +253,9 @@ const char * const SETTINGS_CATEGORY_CORE = "A.Core";
const char * const SETTINGS_CATEGORY_CORE_ICON = ":/core/images/category_core.png";
const char * const SETTINGS_TR_CATEGORY_CORE = QT_TRANSLATE_NOOP("Core", "Environment");
const char * const SETTINGS_ID_ENVIRONMENT = "A.General";
const char * const SETTINGS_ID_TOOLS = "G.ExternalTools";
const char * const SETTINGS_ID_SHORTCUTS = "B.Keyboard";
const char * const SETTINGS_ID_TOOLS = "C.ExternalTools";
const char * const SETTINGS_ID_MIMETYPES = "D.MimeTypes";
const char * const SETTINGS_DEFAULTTEXTENCODING = "General/DefaultFileEncoding";
......
......@@ -38,6 +38,7 @@
#include "modemanager.h"
#include "fileiconprovider.h"
#include "designmode.h"
#include "mimedatabase.h"
#include <extensionsystem/pluginmanager.h>
......@@ -99,6 +100,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
void CorePlugin::extensionsInitialized()
{
m_mainWindow->mimeDatabase()->syncUserModifiedMimeTypes();
m_mainWindow->extensionsInitialized();
}
......
......@@ -91,7 +91,9 @@ SOURCES += mainwindow.cpp \
externaltool.cpp \
dialogs/externaltoolconfig.cpp \
toolsettings.cpp \
variablechooser.cpp
variablechooser.cpp \
mimetypemagicdialog.cpp \
mimetypesettings.cpp
HEADERS += mainwindow.h \
editmode.h \
......@@ -180,7 +182,9 @@ HEADERS += mainwindow.h \
externaltool.h \
dialogs/externaltoolconfig.h \
toolsettings.h \
variablechooser.h
variablechooser.h \
mimetypemagicdialog.h \
mimetypesettings.h
FORMS += dialogs/newdialog.ui \
actionmanager/commandmappings.ui \
......@@ -189,7 +193,10 @@ FORMS += dialogs/newdialog.ui \
editormanager/openeditorsview.ui \
generalsettings.ui \
dialogs/externaltoolconfig.ui \
variablechooser.ui
variablechooser.ui \
mimetypesettingspage.ui \
mimetypemagicdialog.ui
RESOURCES += core.qrc \
fancyactionbar.qrc
......
......@@ -75,7 +75,7 @@ ShortcutSettings::~ShortcutSettings()
QString ShortcutSettings::id() const
{
return QLatin1String("D.Keyboard");
return QLatin1String(Core::Constants::SETTINGS_ID_SHORTCUTS);
}
QString ShortcutSettings::displayName() const
......
......@@ -40,6 +40,7 @@
#include "editormanager.h"
#include "externaltool.h"
#include "toolsettings.h"
#include "mimetypesettings.h"
#include "fancytabwidget.h"
#include "filemanager.h"
#include "generalsettings.h"
......@@ -152,6 +153,7 @@ MainWindow::MainWindow() :
m_generalSettings(new GeneralSettings),
m_shortcutSettings(new ShortcutSettings),
m_toolSettings(new ToolSettings),
m_mimeTypeSettings(new MimeTypeSettings),
m_systemEditor(new SystemEditor),
m_focusToEditor(0),
m_newAction(0),
......@@ -256,6 +258,7 @@ MainWindow::~MainWindow()
pm->removeObject(m_shortcutSettings);
pm->removeObject(m_generalSettings);
pm->removeObject(m_toolSettings);
pm->removeObject(m_mimeTypeSettings);
pm->removeObject(m_systemEditor);
delete m_externalToolManager;
m_externalToolManager = 0;
......@@ -267,6 +270,8 @@ MainWindow::~MainWindow()
m_generalSettings = 0;
delete m_toolSettings;
m_toolSettings = 0;
delete m_mimeTypeSettings;
m_mimeTypeSettings = 0;
delete m_systemEditor;
m_systemEditor = 0;
delete m_settings;
......@@ -325,9 +330,9 @@ bool MainWindow::init(QString *errorMessage)
pm->addObject(m_generalSettings);
pm->addObject(m_shortcutSettings);
pm->addObject(m_toolSettings);
pm->addObject(m_mimeTypeSettings);
pm->addObject(m_systemEditor);
// Add widget to the bottom, we create the view here instead of inside the
// OutputPaneManager, since the StatusBarManager needs to be initialized before
m_outputView = new Core::StatusBarWidget;
......@@ -352,8 +357,6 @@ void MainWindow::extensionsInitialized()
readSettings();
updateContext();
registerUserMimeTypes();
emit m_coreImpl->coreAboutToOpen();
show();
emit m_coreImpl->coreOpened();
......@@ -1397,15 +1400,3 @@ bool MainWindow::showWarningWithOptions(const QString &title,
}
return false;
}
void MainWindow::registerUserMimeTypes() const
{
// This is to temporarily allow user specific MIME types (without recompilation).
// Be careful with the file contents. Otherwise unpredictable behavior might arise.
const QString &fileName = m_coreImpl->userResourcePath() + QLatin1String("/mimetypes.xml");
if (QFile::exists(fileName)) {
QString error;
if (!m_coreImpl->mimeDatabase()->addMimeTypes(fileName, &error))
qWarning() << error;
}
}
......@@ -78,6 +78,7 @@ class GeneralSettings;
class ProgressManagerPrivate;
class ShortcutSettings;
class ToolSettings;
class MimeTypeSettings;
class StatusBarManager;
class VersionDialog;
class SystemEditor;
......@@ -179,8 +180,6 @@ private:
void readSettings();
void writeSettings();
void registerUserMimeTypes() const;
CoreImpl *m_coreImpl;
UniqueIDManager *m_uniqueIDManager;
Context m_additionalContexts;
......@@ -214,6 +213,7 @@ private:
GeneralSettings *m_generalSettings;
ShortcutSettings *m_shortcutSettings;
ToolSettings *m_toolSettings;
MimeTypeSettings *m_mimeTypeSettings;
SystemEditor *m_systemEditor;
// actions
......
This diff is collapsed.
......@@ -41,6 +41,7 @@
#include <QtCore/QByteArray>
#include <QtCore/QMutex>
#include <QtCore/QFileInfo>
#include <QtCore/QPair>
QT_BEGIN_NAMESPACE
class QIODevice;
......@@ -66,6 +67,9 @@ class CORE_EXPORT IMagicMatcher
protected:
IMagicMatcher() {}
public:
typedef QSharedPointer<IMagicMatcher> IMagicMatcherSharedPointer;
typedef QList<IMagicMatcherSharedPointer> IMagicMatcherList;
// Check for a match on contents of a file
virtual bool matches(const QByteArray &data) const = 0;
// Return a priority value from 1..100
......@@ -83,13 +87,19 @@ public:
MagicRule(int startPos, int endPos);
virtual ~MagicRule();
virtual QString matchType() const = 0;
virtual QString matchValue() const = 0;
virtual bool matches(const QByteArray &data) const = 0;
protected:
int startPos() const;
int endPos() const;
static QString toOffset(const QPair<int, int> &startEnd);
static QPair<int, int> fromOffset(const QString &offset);
private:
static const QChar kColon;
const int m_startPos;
const int m_endPos;
};
......@@ -100,8 +110,12 @@ public:
MagicStringRule(const QString &s, int startPos, int endPos);
virtual ~MagicStringRule();
virtual QString matchType() const;
virtual QString matchValue() const;
virtual bool matches(const QByteArray &data) const;
static const QString kMatchType;
private:
const QByteArray m_pattern;
};
......@@ -112,11 +126,17 @@ public:
MagicByteRule(const QString &s, int startPos, int endPos);
virtual ~MagicByteRule();
virtual QString matchType() const;
virtual QString matchValue() const;
virtual bool matches(const QByteArray &data) const;
static bool validateByteSequence(const QString &sequence, QList<int> *bytes = 0);
static const QString kMatchType;
private:
QList<int> m_bytes;
int m_bytesSize;
QList<int> m_bytes;
};
/* Utility class: A Magic matcher that checks a number of rules based on
......@@ -125,17 +145,24 @@ class CORE_EXPORT MagicRuleMatcher : public IMagicMatcher
{
Q_DISABLE_COPY(MagicRuleMatcher)
public:
typedef QSharedPointer<MagicRule> MagicRuleSharedPointer;
typedef QSharedPointer<MagicRule> MagicRuleSharedPointer;
typedef QList<MagicRuleSharedPointer> MagicRuleList;
MagicRuleMatcher();
void add(const MagicRuleSharedPointer &rule);
void add(const MagicRuleList &ruleList);
MagicRuleList magicRules() const;
virtual bool matches(const QByteArray &data) const;
virtual int priority() const;
void setPriority(int p);
// Create a list of MagicRuleMatchers from a hash of rules indexed by priorities.
static IMagicMatcher::IMagicMatcherList createMatchers(const QHash<int, MagicRuleList> &);
private:
typedef QList<MagicRuleSharedPointer> MagicRuleList;
MagicRuleList m_list;
int m_priority;
};
......@@ -169,6 +196,9 @@ private:
class CORE_EXPORT MimeType
{
public:
typedef IMagicMatcher::IMagicMatcherList IMagicMatcherList;
typedef IMagicMatcher::IMagicMatcherSharedPointer IMagicMatcherSharedPointer;
MimeType();
MimeType(const MimeType&);
MimeType &operator=(const MimeType&);
......@@ -200,9 +230,6 @@ public:
// Extension over standard mime data
QStringList suffixes() const;
void setSuffixes(const QStringList &);
// Extension over standard mime data
QString preferredSuffix() const;
bool setPreferredSuffix(const QString&);
......@@ -216,12 +243,19 @@ public:
// Return a filter string usable for a file dialog
QString filterString() const;
// Add magic matcher
void addMagicMatcher(const QSharedPointer<IMagicMatcher> &matcher);
void addMagicMatcher(const IMagicMatcherSharedPointer &matcher);
const IMagicMatcherList &magicMatchers() const;
void setMagicMatchers(const IMagicMatcherList &matchers);
// Convenience for rule-base matchers.
IMagicMatcherList magicRuleMatchers() const;
void setMagicRuleMatchers(const IMagicMatcherList &matchers);
friend QDebug operator<<(QDebug d, const MimeType &mt);
static QString formatFilterString(const QString &description, const QList<MimeGlobPattern> &globs);
static QString formatFilterString(const QString &description,
const QList<MimeGlobPattern> &globs);
private:
explicit MimeType(const MimeTypeData &d);
......@@ -243,8 +277,10 @@ class CORE_EXPORT MimeDatabase
{
Q_DISABLE_COPY(MimeDatabase)
public:
MimeDatabase();
typedef IMagicMatcher::IMagicMatcherList IMagicMatcherList;
typedef IMagicMatcher::IMagicMatcherSharedPointer IMagicMatcherSharedPointer;
MimeDatabase();
~MimeDatabase();
bool addMimeTypes(const QString &fileName, QString *errorMessage);
......@@ -256,27 +292,45 @@ public:
// Returns a mime type or Null one if none found
MimeType findByFile(const QFileInfo &f) 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;
// Convenience
QString preferredSuffixByType(const QString &type) const;
QString preferredSuffixByFile(const QFileInfo &f) const;
inline void findByFile(Iterator i1, const Iterator &i2, Function f) const;
// 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;
QStringList filterStrings() const;
// Return a string with all the possible file filters, for use with file dialogs
QString allFiltersString(QString *allFilesFilter = 0) const;
QList<MimeGlobPattern> globPatterns() const;
void setGlobPatterns(const QString &typeOrAlias, const QList<MimeGlobPattern> &globPatterns);
IMagicMatcherList magicMatchers() const;
void setMagicMatchers(const QString &typeOrAlias, const IMagicMatcherList &matchers);
QList<MimeType> mimeTypes() const;
// The mime types from the functions bellow are considered only in regard to
// their glob patterns and rule-based magic matchers.
void syncUserModifiedMimeTypes();
static QList<MimeType> readUserModifiedMimeTypes();
static void writeUserModifiedMimeTypes(const QList<MimeType> &mimeTypes);
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);
// returns a string with all the possible file filters, for use with file dialogs
QString allFiltersString(QString *allFilesFilter = 0) const;
private:
MimeType findByFileUnlocked(const QFileInfo &f) const;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#include "mimetypemagicdialog.h"
#include "mimedatabase.h"
#include <QtCore/QLatin1String>
#include <QtGui/QMessageBox>
using namespace Core;
using namespace Internal;
MimeTypeMagicDialog::MimeTypeMagicDialog(QWidget *parent) :
QDialog(parent)
{
ui.setupUi(this);
setWindowTitle(tr("Magic Header"));
connect(ui.useRecommendedGroupBox, SIGNAL(clicked(bool)),
this, SLOT(applyRecommended(bool)));
connect(ui.buttonBox, SIGNAL(accepted()), this, SLOT(validateAccept()));
}
void MimeTypeMagicDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui.retranslateUi(this);
break;
default:
break;
}
}
void MimeTypeMagicDialog::applyRecommended(bool checked)
{
if (checked) {
ui.startRangeSpinBox->setValue(0);
ui.endRangeSpinBox->setValue(0);
ui.prioritySpinBox->setValue(50);
}
}
void MimeTypeMagicDialog::validateAccept()
{
if (ui.valueLineEdit->text().isEmpty()
|| (ui.byteRadioButton->isChecked()
&& !Core::MagicByteRule::validateByteSequence(ui.valueLineEdit->text()))) {
QMessageBox::critical(0, tr("Error"), tr("Not a valid byte pattern."));
return;
}
accept();
}
void MimeTypeMagicDialog::setMagicData(const MagicData &data)
{
ui.valueLineEdit->setText(data.m_value);
if (data.m_type == Core::MagicStringRule::kMatchType)
ui.stringRadioButton->setChecked(true);
else
ui.byteRadioButton->setChecked(true);
ui.startRangeSpinBox->setValue(data.m_start);
ui.endRangeSpinBox->setValue(data.m_end);
ui.prioritySpinBox->setValue(data.m_priority);
}
MagicData MimeTypeMagicDialog::magicData() const
{
MagicData data;
data.m_value = ui.valueLineEdit->text();
if (ui.stringRadioButton->isChecked())
data.m_type = Core::MagicStringRule::kMatchType;
else
data.m_type = Core::MagicByteRule::kMatchType;
data.m_start = ui.startRangeSpinBox->value();
data.m_end = ui.endRangeSpinBox->value();
data.m_priority = ui.prioritySpinBox->value();
return data;
}
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** No Commercial Usage
**
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** 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, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**************************************************************************/
#ifndef MIMETYPEMAGICDIALOG_H
#define MIMETYPEMAGICDIALOG_H
#include "ui_mimetypemagicdialog.h"
namespace Core {
namespace Internal {
struct MagicData
{
MagicData() {}
MagicData(const QString &value, const QString &type, int start, int end, int p)
: m_value(value)
, m_type(type)
, m_start(start)
, m_end(end)
, m_priority(p) {}
QString m_value;
QString m_type;
int m_start;
int m_end;
int m_priority;
};
class MimeTypeMagicDialog : public QDialog
{
Q_OBJECT
public:
explicit MimeTypeMagicDialog(QWidget *parent = 0);
void setMagicData(const MagicData &data);
MagicData magicData() const;
protected:
void changeEvent(QEvent *e);
private slots:
void applyRecommended(bool checked);
void validateAccept();
private:
Ui::MimeTypeMagicDialog ui;
};
} // Internal
} // Core