Commit b46072c7 authored by cerf's avatar cerf Committed by Tobias Hunger
Browse files

vcsbase: auto save settings when requested by Core::ICore



Bazaar and Mercurial plugins are impacted

Change-Id: Ia781dae79983350d773f454de32f812e876bfbfb
Merge-request: 350
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
Reviewed-on: http://codereview.qt.nokia.com/645

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
parent f0c32d79
......@@ -136,7 +136,6 @@ BazaarPlugin::BazaarPlugin() :
BazaarPlugin::~BazaarPlugin()
{
m_bazaarSettings.writeSettings(m_core->settings(), Constants::BAZAAR);
if (m_client) {
delete m_client;
m_client = 0;
......@@ -162,7 +161,7 @@ bool BazaarPlugin::initialize(const QStringList &arguments, QString *errorMessag
m_optionsPage = new OptionsPage();
addAutoReleasedObject(m_optionsPage);
m_bazaarSettings.readSettings(m_core->settings(), Constants::BAZAAR);
m_bazaarSettings.readSettings(m_core->settings());
connect(m_optionsPage, SIGNAL(settingsChanged()), m_client, SLOT(settingsChanged()));
connect(m_client, SIGNAL(changed(QVariant)), versionControl(), SLOT(changed(QVariant)));
......
......@@ -45,6 +45,7 @@ BazaarSettings::BazaarSettings() :
diffIgnoreWhiteSpace(false),
diffIgnoreBlankLines(false)
{
setSettingsGroup(QLatin1String(Constants::BAZAAR));
setBinary(QLatin1String(Constants::BAZAARDEFAULT));
}
......@@ -63,19 +64,19 @@ bool BazaarSettings::sameUserId(const BazaarSettings& other) const
return userName() == other.userName() && email() == other.email();
}
void BazaarSettings::writeSettings(QSettings *settings, const QString &group) const
void BazaarSettings::writeSettings(QSettings *settings) const
{
VCSBaseClientSettings::writeSettings(settings, group);
settings->beginGroup(group);
VCSBaseClientSettings::writeSettings(settings);
settings->beginGroup(settingsGroup());
settings->setValue(diffIgnoreWhiteSpaceKey, diffIgnoreWhiteSpace);
settings->setValue(diffIgnoreBlankLinesKey, diffIgnoreBlankLines);
settings->endGroup();
}
void BazaarSettings::readSettings(const QSettings *settings, const QString &group)
void BazaarSettings::readSettings(const QSettings *settings)
{
VCSBaseClientSettings::readSettings(settings, group);
const QString keyRoot = group + QLatin1Char('/');
VCSBaseClientSettings::readSettings(settings);
const QString keyRoot = settingsGroup() + QLatin1Char('/');
diffIgnoreWhiteSpace = settings->value(keyRoot + diffIgnoreWhiteSpaceKey, false).toBool();
diffIgnoreBlankLines = settings->value(keyRoot + diffIgnoreBlankLinesKey, false).toBool();
}
......
......@@ -45,8 +45,8 @@ public:
BazaarSettings& operator=(const BazaarSettings& other);
bool sameUserId(const BazaarSettings& other) const;
virtual void writeSettings(QSettings *settings, const QString &group) const;
virtual void readSettings(const QSettings *settings, const QString &group);
virtual void writeSettings(QSettings *settings) const;
virtual void readSettings(const QSettings *settings);
virtual bool equals(const VCSBaseClientSettings &rhs) const;
bool diffIgnoreWhiteSpace;
......
......@@ -126,8 +126,7 @@ void OptionsPage::apply()
if (newSettings != plugin->settings()) {
//assume success and emit signal that settings are changed;
plugin->setSettings(newSettings);
newSettings.writeSettings(Core::ICore::instance()->settings(),
Constants::BAZAAR);
newSettings.writeSettings(Core::ICore::instance()->settings());
emit settingsChanged();
}
}
......
......@@ -164,7 +164,7 @@ bool MercurialPlugin::initialize(const QStringList & /* arguments */, QString *
optionsPage = new OptionsPage();
addAutoReleasedObject(optionsPage);
mercurialSettings.readSettings(core->settings(), QLatin1String("Mercurial"));
mercurialSettings.readSettings(core->settings());
connect(optionsPage, SIGNAL(settingsChanged()), m_client, SLOT(settingsChanged()));
......
......@@ -45,6 +45,7 @@ namespace Internal {
diffIgnoreWhiteSpace(false),
diffIgnoreBlankLines(false)
{
setSettingsGroup(QLatin1String("Mercurial"));
setBinary(QLatin1String(Constants::MERCURIALDEFAULT));
}
......@@ -58,19 +59,19 @@ namespace Internal {
return *this;
}
void MercurialSettings::writeSettings(QSettings *settings, const QString &group) const
void MercurialSettings::writeSettings(QSettings *settings) const
{
VCSBaseClientSettings::writeSettings(settings, group);
settings->beginGroup(group);
VCSBaseClientSettings::writeSettings(settings);
settings->beginGroup(this->settingsGroup());
settings->setValue(diffIgnoreWhiteSpaceKey, diffIgnoreWhiteSpace);
settings->setValue(diffIgnoreBlankLinesKey, diffIgnoreBlankLines);
settings->endGroup();
}
void MercurialSettings::readSettings(const QSettings *settings, const QString &group)
void MercurialSettings::readSettings(const QSettings *settings)
{
VCSBaseClientSettings::readSettings(settings, group);
const QString keyRoot = group + QLatin1Char('/');
VCSBaseClientSettings::readSettings(settings);
const QString keyRoot = this->settingsGroup() + QLatin1Char('/');
diffIgnoreWhiteSpace = settings->value(keyRoot + diffIgnoreWhiteSpaceKey, false).toBool();
diffIgnoreBlankLines = settings->value(keyRoot + diffIgnoreBlankLinesKey, false).toBool();
}
......
......@@ -44,8 +44,8 @@ public:
MercurialSettings();
MercurialSettings& operator=(const MercurialSettings& other);
virtual void writeSettings(QSettings *settings, const QString &group) const;
virtual void readSettings(const QSettings *settings, const QString &group);
virtual void writeSettings(QSettings *settings) const;
virtual void readSettings(const QSettings *settings);
virtual bool equals(const VCSBaseClientSettings &rhs) const;
bool diffIgnoreWhiteSpace;
......
......@@ -125,8 +125,7 @@ void OptionsPage::apply()
if (newSettings != plugin->settings()) {
//assume success and emit signal that settings are changed;
plugin->setSettings(newSettings);
newSettings.writeSettings(Core::ICore::instance()->settings(),
QLatin1String("Mercurial"));
newSettings.writeSettings(Core::ICore::instance()->settings());
emit settingsChanged();
}
}
......
......@@ -97,6 +97,7 @@ VCSBaseClient::VCSBaseClient(VCSBaseClientSettings *settings) :
d(new VCSBaseClientPrivate(settings))
{
qRegisterMetaType<QVariant>();
connect(d->m_core, SIGNAL(saveSettingsRequested()), this, SLOT(saveSettings()));
}
VCSBaseClient::~VCSBaseClient()
......@@ -252,6 +253,11 @@ void VCSBaseClient::slotAnnotateRevisionRequested(const QString &source,
annotate(fi.absolutePath(), fi.fileName(), change, lineNumber);
}
void VCSBaseClient::saveSettings()
{
d->m_clientSettings->writeSettings(d->m_core->settings());
}
void VCSBaseClient::annotate(const QString &workingDir, const QString &file,
const QString revision /* = QString() */,
int lineNumber /* = -1 */)
......
......@@ -185,6 +185,7 @@ protected:
private slots:
void statusParser(const QByteArray &data);
void slotAnnotateRevisionRequested(const QString &source, QString change, int lineNumber);
void saveSettings();
private:
QScopedPointer<VCSBaseClientPrivate> d;
......
......@@ -129,9 +129,19 @@ void VCSBaseClientSettings::setTimeoutSeconds(int s)
m_timeoutSeconds = s;
}
void VCSBaseClientSettings::writeSettings(QSettings *settings, const QString &group) const
QString VCSBaseClientSettings::settingsGroup() const
{
settings->beginGroup(group);
return m_settingsGroup;
}
void VCSBaseClientSettings::setSettingsGroup(const QString &group)
{
m_settingsGroup = group;
}
void VCSBaseClientSettings::writeSettings(QSettings *settings) const
{
settings->beginGroup(settingsGroup());
settings->setValue(QLatin1String("VCS_Path"), m_binary);
settings->setValue(QLatin1String("VCS_Username"), m_user);
settings->setValue(QLatin1String("VCS_Email"), m_mail);
......@@ -141,9 +151,9 @@ void VCSBaseClientSettings::writeSettings(QSettings *settings, const QString &gr
settings->endGroup();
}
void VCSBaseClientSettings::readSettings(const QSettings *settings, const QString &group)
void VCSBaseClientSettings::readSettings(const QSettings *settings)
{
const QString keyRoot = group + QLatin1Char('/');
const QString keyRoot = settingsGroup() + QLatin1Char('/');
m_binary = settings->value(keyRoot + QLatin1String("VCS_Path"), QString()).toString();
m_user = settings->value(keyRoot + QLatin1String("VCS_Username"), QString()).toString();
m_mail = settings->value(keyRoot + QLatin1String("VCS_Email"), QString()).toString();
......
......@@ -71,8 +71,11 @@ public:
int timeoutSeconds() const;
void setTimeoutSeconds(int s);
virtual void writeSettings(QSettings *settings, const QString &group) const;
virtual void readSettings(const QSettings *settings, const QString &group);
QString settingsGroup() const;
void setSettingsGroup(const QString &group);
virtual void writeSettings(QSettings *settings) const;
virtual void readSettings(const QSettings *settings);
virtual bool equals(const VCSBaseClientSettings &rhs) const;
......@@ -84,6 +87,7 @@ private:
int m_logCount;
bool m_prompt;
int m_timeoutSeconds;
QString m_settingsGroup;
};
inline bool operator==(const VCSBaseClientSettings &s1, const VCSBaseClientSettings &s2)
......
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