Commit 2eb2a382 authored by Kavindra Devi Palaraja's avatar Kavindra Devi Palaraja
Browse files

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

parents f1a81dec 6782dc55
The QtCreator 1.1.1 release is a pure bug fix release for the Windows platform.
Platform Specific
Windows
* Fixed performance problem on Windows machines that are part of a
windows domain
......@@ -59,11 +59,11 @@ public:
inline int size() const { return m_size; }
inline const char *data() const { return m_data; }
void append(QChar *&out) const
void appendTo(QChar *&out) const
{
const char *s = m_data;
for (int i = m_size; --i >= 0;)
*out++ = *s++;
*out++ = QLatin1Char(*s++);
}
operator QString() const
......@@ -75,7 +75,7 @@ public:
s.resize(m_size);
#endif
QChar *d = s.data();
append(d);
appendTo(d);
return s;
}
......@@ -100,7 +100,7 @@ public:
s.resize(this->size());
#endif
QChar *d = s.data();
this->append(d);
this->appendTo(d);
return s;
}
......@@ -114,7 +114,7 @@ public:
inline int size() const { return a->size(); }
inline void append(QChar *&out) const
inline void appendTo(QChar *&out) const
{
const int n = a->size();
memcpy(out, (char*)a->constData(), sizeof(QChar) * n);
......@@ -133,12 +133,23 @@ int qStringBuilderSize(const A a) { return a.size(); }
inline int qStringBuilderSize(const char) { return 1; }
inline int qStringBuilderSize(const QLatin1Char) { return 1; }
inline int qStringBuilderSize(const QLatin1String a) { return qstrlen(a.latin1()); }
template <typename A>
inline void qStringBuilderAppend(const A a, QChar *&out) { a.append(out); }
inline void qStringBuilderAppend(const A a, QChar *&out) { a.appendTo(out); }
inline void qStringBuilderAppend(char c, QChar *&out) { *out++ = QLatin1Char(c); }
inline void qStringBuilderAppend(QLatin1Char c, QChar *&out) { *out++ = c; }
inline void qStringBuilderAppend(QLatin1String a, QChar *&out)
{
for (const char *s = a.latin1(); *s; )
*out++ = QLatin1Char(*s++);
}
template <typename A, typename B>
class QStringBuilderPair
......@@ -151,7 +162,7 @@ public:
return qStringBuilderSize(a) + qStringBuilderSize(b);
}
inline void append(QChar *&out) const
inline void appendTo(QChar *&out) const
{
qStringBuilderAppend(a, out);
qStringBuilderAppend(b, out);
......
......@@ -278,6 +278,8 @@ public:
QToolBar *toolBar() { return m_toolBar; }
bool temporaryEditor() const { return false; }
signals:
void changed();
......
......@@ -185,7 +185,7 @@ void CMakeRunner::run(QFutureInterface<void> &fi)
m_mutex.lock();
m_supportsQtCreator = response.contains(QLatin1String("QtCreator"));
m_version = versionRegexp.cap(1);
if (!versionRegexp.capturedTexts().size()>3)
if (!(versionRegexp.capturedTexts().size() > 3))
m_version += QLatin1Char('.') + versionRegexp.cap(3);
m_cacheUpToDate = true;
m_mutex.unlock();
......
......@@ -129,6 +129,11 @@ QSettings *CoreImpl::settings() const
return m_mainwindow->settings();
}
SettingsDatabase *CoreImpl::settingsDatabase() const
{
return m_mainwindow->settingsDatabase();
}
QPrinter *CoreImpl::printer() const
{
return m_mainwindow->printer();
......
......@@ -64,6 +64,7 @@ public:
MimeDatabase *mimeDatabase() const;
QSettings *settings() const;
SettingsDatabase *settingsDatabase() const;
QPrinter *printer() const;
QString resourcePath() const;
......
......@@ -4,7 +4,8 @@ DEFINES += CORE_LIBRARY
QT += xml \
network \
script \
svg
svg \
sql
include(../../qtcreatorplugin.pri)
include(../../libs/utils/utils.pri)
include(../../shared/scriptwrapper/scriptwrapper.pri)
......@@ -77,7 +78,8 @@ SOURCES += mainwindow.cpp \
icore.cpp \
editormanager/ieditor.cpp \
dialogs/ioptionspage.cpp \
dialogs/iwizard.cpp
dialogs/iwizard.cpp \
settingsdatabase.cpp
HEADERS += mainwindow.h \
welcomemode.h \
welcomemode_p.h \
......@@ -156,7 +158,8 @@ HEADERS += mainwindow.h \
rightpane.h \
sidebar.h \
fileiconprovider.h \
mimedatabase.h
mimedatabase.h \
settingsdatabase.h
FORMS += dialogs/newdialog.ui \
dialogs/settingsdialog.ui \
dialogs/shortcutsettings.ui \
......
......@@ -47,6 +47,7 @@
#include <coreplugin/editormanager/iexternaleditor.h>
#include <coreplugin/baseview.h>
#include <coreplugin/imode.h>
#include <coreplugin/settingsdatabase.h>
#include <extensionsystem/pluginmanager.h>
......@@ -694,7 +695,7 @@ bool EditorManager::closeEditors(const QList<IEditor*> editorsToClose, bool askA
//ask whether to save modified files
if (askAboutModifiedEditors) {
bool cancelled = false;
QList<IFile*> list = ICore::instance()->fileManager()->
QList<IFile*> list = m_d->m_core->fileManager()->
saveModifiedFiles(filesForEditors(acceptedEditors), &cancelled);
if (cancelled)
return false;
......@@ -958,7 +959,8 @@ template <class EditorFactoryLike>
inline EditorFactoryLike *findByKind(ExtensionSystem::PluginManager *pm,
const QString &kind)
{
foreach(EditorFactoryLike *efl, pm->getObjects<EditorFactoryLike>())
const QList<EditorFactoryLike *> factories = pm->template getObjects<EditorFactoryLike>();
foreach(EditorFactoryLike *efl, factories)
if (kind == efl->kind())
return efl;
return 0;
......@@ -1010,7 +1012,9 @@ void EditorManager::addEditor(IEditor *editor, bool isDuplicate)
m_d->m_editorModel->addEditor(editor, isDuplicate);
if (!isDuplicate) {
m_d->m_core->fileManager()->addFile(editor->file());
m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName());
if (!editor->temporaryEditor()) {
m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName());
}
}
m_d->m_editorHistory.removeAll(editor);
......@@ -1275,7 +1279,7 @@ bool EditorManager::saveFile(IEditor *editor)
m_d->m_core->fileManager()->unblockFileChange(file);
}
if (success)
if (success && !editor->temporaryEditor())
m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName());
return success;
......@@ -1370,7 +1374,7 @@ bool EditorManager::saveFileAs(IEditor *editor)
m_d->m_core->fileManager()->unblockFileChange(editor->file());
editor->file()->checkPermissions();
if (success)
if (success && !editor->temporaryEditor())
m_d->m_core->fileManager()->addToRecentFiles(editor->file()->fileName());
updateActions();
......@@ -1684,21 +1688,36 @@ bool EditorManager::restoreState(const QByteArray &state)
return true;
}
void EditorManager::saveSettings(QSettings *settings)
static const char * const documentStatesKey = "EditorManager/DocumentStates";
static const char * const externalEditorKey = "EditorManager/ExternalEditorCommand";
void EditorManager::saveSettings()
{
settings->setValue(QLatin1String("EditorManager/DocumentStates"),
m_d->m_editorStates);
settings->setValue(QLatin1String("EditorManager/ExternalEditorCommand"),
m_d->m_externalEditor);
SettingsDatabase *settings = m_d->m_core->settingsDatabase();
settings->setValue(QLatin1String(documentStatesKey), m_d->m_editorStates);
settings->setValue(QLatin1String(externalEditorKey), m_d->m_externalEditor);
}
void EditorManager::readSettings(QSettings *settings)
void EditorManager::readSettings()
{
if (settings->contains(QLatin1String("EditorManager/DocumentStates")))
m_d->m_editorStates = settings->value(QLatin1String("EditorManager/DocumentStates"))
// Backward compatibility to old locations for these settings
QSettings *qs = m_d->m_core->settings();
if (qs->contains(QLatin1String(documentStatesKey))) {
m_d->m_editorStates = qs->value(QLatin1String(documentStatesKey))
.value<QMap<QString, QVariant> >();
qs->remove(QLatin1String(documentStatesKey));
}
if (qs->contains(QLatin1String(externalEditorKey))) {
m_d->m_externalEditor = qs->value(QLatin1String(externalEditorKey)).toString();
qs->remove(QLatin1String(externalEditorKey));
}
SettingsDatabase *settings = m_d->m_core->settingsDatabase();
if (settings->contains(QLatin1String(documentStatesKey)))
m_d->m_editorStates = settings->value(QLatin1String(documentStatesKey))
.value<QMap<QString, QVariant> >();
if (settings->contains(QLatin1String("EditorManager/ExternalEditorCommand")))
m_d->m_externalEditor = settings->value(QLatin1String("EditorManager/ExternalEditorCommand")).toString();
if (settings->contains(QLatin1String(externalEditorKey)))
m_d->m_externalEditor = settings->value(QLatin1String(externalEditorKey)).toString();
}
......@@ -1800,7 +1819,7 @@ void EditorManager::openInExternalEditor()
return;
if (editor->file()->isModified()) {
bool cancelled = false;
QList<IFile*> list = ICore::instance()->fileManager()->
QList<IFile*> list = m_d->m_core->fileManager()->
saveModifiedFiles(QList<IFile*>() << editor->file(), &cancelled);
if (cancelled)
return;
......
......@@ -149,8 +149,8 @@ public:
IEditor *restoreEditor(QString fileName, QString editorKind, EditorGroup *group);
void saveSettings(QSettings *settings);
void readSettings(QSettings *settings);
void saveSettings();
void readSettings();
Internal::OpenEditorsWindow *windowPopup() const;
void showWindowPopup() const;
......
......@@ -63,6 +63,8 @@ public:
virtual int currentLine() const { return 0; }
virtual int currentColumn() const { return 0; }
virtual bool temporaryEditor() const = 0;
virtual QToolBar *toolBar() = 0;
signals:
......
......@@ -179,6 +179,19 @@
You can use it to retrieve or set application wide settings
(in contrast to session or project specific settings).
\see settingsDatabase()
*/
/*!
\fn SettingsDatabase *ICore::settingsDatabase() const
\brief Returns the application's settings database.
The settings database is meant as an alternative to the regular settings
object. It is more suitable for storing large amounts of data. The settings
are application wide.
\see SettingsDatabase
*/
/*!
......@@ -186,7 +199,7 @@
\brief Returns the application's printer object.
Always use this printer object for printing, so the different parts of the
application re-use it's settings.
application re-use its settings.
*/
/*!
......@@ -251,7 +264,7 @@
\brief Registers an additional \a context object.
After registration this context object gets automatically the
current context object whenever it's widget gets focus.
current context object whenever its widget gets focus.
\sa ICore::removeContextObject()
\sa ICore::addAdditionalContext()
......@@ -324,11 +337,11 @@
/*!
\fn void ICore::contextAboutToChange(Core::IContext *context)
\brief Sent just before a new \a context becomes the current context
(meaning that it's widget got focus).
(meaning that its widget got focus).
*/
/*!
\fn void ICore::contextChanged(Core::IContext *context)
\brief Sent just after a new \a context became the current context
(meaning that it's widget got focus).
(meaning that its widget got focus).
*/
......@@ -52,6 +52,7 @@ class MimeDatabase;
class ModeManager;
class ProgressManager;
class ScriptManager;
class SettingsDatabase;
class UniqueIDManager;
class VariableManager;
class VCSManager;
......@@ -87,6 +88,7 @@ public:
virtual MimeDatabase *mimeDatabase() const = 0;
virtual QSettings *settings() const = 0;
virtual SettingsDatabase *settingsDatabase() const = 0;
virtual QPrinter *printer() const = 0;
virtual QString resourcePath() const = 0;
......
......@@ -66,6 +66,7 @@
#include "ioutputpane.h"
#include <coreplugin/findplaceholder.h>
#include <coreplugin/settingsdatabase.h>
#include <utils/pathchooser.h>
#include <extensionsystem/pluginmanager.h>
......@@ -111,7 +112,11 @@ MainWindow::MainWindow() :
m_uniqueIDManager(new UniqueIDManager()),
m_globalContext(QList<int>() << Constants::C_GLOBAL_ID),
m_additionalContexts(m_globalContext),
m_settings(new QSettings(QSettings::IniFormat, QSettings::UserScope, QLatin1String("Nokia"), QLatin1String("QtCreator"), this)),
m_settings(new QSettings(QSettings::IniFormat, QSettings::UserScope,
QLatin1String("Nokia"), QLatin1String("QtCreator"), this)),
m_settingsDatabase(new SettingsDatabase(QFileInfo(m_settings->fileName()).path(),
QLatin1String("QtCreator"),
this)),
m_printer(0),
m_actionManager(new ActionManagerPrivate(this)),
m_editorManager(0),
......@@ -760,7 +765,7 @@ void MainWindow::registerDefaultActions()
void MainWindow::newFile()
{
showNewItemDialog(tr("New", "Title of dialog"), IWizard::allWizards());
showNewItemDialog(tr("New...", "Title of dialog"), IWizard::allWizards());
}
void MainWindow::openFile()
......@@ -1099,7 +1104,7 @@ void MainWindow::readSettings()
m_settings->endGroup();
m_editorManager->readSettings(m_settings);
m_editorManager->readSettings();
m_navigationWidget->restoreSettings(m_settings);
m_rightPaneWidget->readSettings(m_settings);
}
......@@ -1124,7 +1129,7 @@ void MainWindow::writeSettings()
m_fileManager->saveRecentFiles();
m_viewManager->saveSettings(m_settings);
m_actionManager->saveSettings(m_settings);
m_editorManager->saveSettings(m_settings);
m_editorManager->saveSettings();
m_navigationWidget->saveSettings(m_settings);
}
......
......@@ -60,6 +60,7 @@ class ModeManager;
class ProgressManager;
class RightPaneWidget;
class ScriptManager;
class SettingsDatabase;
class UniqueIDManager;
class VariableManager;
class VCSManager;
......@@ -109,6 +110,7 @@ public:
VCSManager *vcsManager() const;
inline QSettings *settings() const { return m_settings; }
inline SettingsDatabase *settingsDatabase() const { return m_settingsDatabase; }
virtual QPrinter *printer() const;
IContext * currentContextObject() const;
QStatusBar *statusBar() const;
......@@ -169,6 +171,7 @@ private:
QList<int> m_globalContext;
QList<int> m_additionalContexts;
QSettings *m_settings;
SettingsDatabase *m_settingsDatabase;
mutable QPrinter *m_printer;
ActionManagerPrivate *m_actionManager;
EditorManager *m_editorManager;
......
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
**
**************************************************************************/
#include "settingsdatabase.h"
#include <QtCore/QMap>
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QDebug>
/*!
\class Core::SettingsDatabase
\brief An alternative to the application-wide QSettings that is more
suitable for storing large amounts of data.
The settings database is SQLite based, and lazily retrieves data when it
is asked for. It also does incremental updates of the database rather than
rewriting the whole file each time one of the settings change.
The SettingsDatabase API mimics that of QSettings.
*/
using namespace Core;
using namespace Core::Internal;
enum { debug_settings = 0 };
namespace Core {
namespace Internal {
typedef QMap<QString, QVariant> SettingsMap;
class SettingsDatabasePrivate
{
public:
QString effectiveGroup() const
{
return m_groups.join(QLatin1String("/"));
}
QString effectiveKey(const QString &key) const
{
QString g = effectiveGroup();
if (!g.isEmpty() && !key.isEmpty())
g += QLatin1Char('/');
g += key;
return g;
}
SettingsMap m_settings;
QStringList m_groups;
QStringList m_dirtyKeys;
QSqlDatabase m_db;
};
} // namespace Internal
} // namespace Core
SettingsDatabase::SettingsDatabase(const QString &path,
const QString &application,
QObject *parent)
: QObject(parent)
, d(new SettingsDatabasePrivate)
{
const QLatin1Char slash('/');
// TODO: Don't rely on a path, but determine automatically
QString fileName = path;
if (!fileName.endsWith(slash))
fileName += slash;
fileName += application;
fileName += QLatin1String(".db");
d->m_db = QSqlDatabase::addDatabase("QSQLITE", QLatin1String("settings"));
d->m_db.setDatabaseName(fileName);
if (!d->m_db.open())
qWarning() << "Warning: Failed to open settings database!";
// Create the settings table if it doesn't exist yet
QSqlQuery query(d->m_db);
query.prepare(QLatin1String("CREATE TABLE IF NOT EXISTS settings ("
"key PRIMARY KEY ON CONFLICT REPLACE, "
"value)"));
if (d->m_db.isOpen() && !query.exec())
qWarning() << "Warning: Failed to prepare settings database!";
// Retrieve all available keys (values are retrieved lazily)
if (query.exec(QLatin1String("SELECT key FROM settings"))) {
while (query.next()) {
d->m_settings.insert(query.value(0).toString(), QVariant());
}
}
}
SettingsDatabase::~SettingsDatabase()
{
sync();
delete d;
QSqlDatabase::removeDatabase(QLatin1String("settings"));
}
void SettingsDatabase::setValue(const QString &key, const QVariant &value)
{
const QString effectiveKey = d->effectiveKey(key);
// Add to cache
d->m_settings.insert(effectiveKey, value);
// Instant apply (TODO: Delay writing out settings)
QSqlQuery query(d->m_db);
query.prepare(QLatin1String("INSERT INTO settings VALUES (?, ?)"));
query.addBindValue(effectiveKey);
query.addBindValue(value);
query.exec();
if (debug_settings)
qDebug() << "Stored:" << effectiveKey << "=" << value;
}
QVariant SettingsDatabase::value(const QString &key, const QVariant &defaultValue) const
{
const QString effectiveKey = d->effectiveKey(key);
QVariant value = defaultValue;
SettingsMap::const_iterator i = d->m_settings.constFind(effectiveKey);
if (i != d->m_settings.constEnd() && i.value().isValid()) {
value = i.value();
} else {
// Try to read the value from the database
QSqlQuery query(d->m_db);
query.prepare(QLatin1String("SELECT value FROM settings WHERE key = ?"));
query.addBindValue(effectiveKey);
query.exec();
if (query.next()) {
value = query.value(0);
if (debug_settings)
qDebug() << "Retrieved:" << effectiveKey << "=" << value;
}
// Cache the result
d->m_settings.insert(effectiveKey, value);
}
return value;
}
bool SettingsDatabase::contains(const QString &key) const
{
return d->m_settings.contains(d->effectiveKey(key));
}