Commit 970131a8 authored by Hugues Delorme's avatar Hugues Delorme

Svn: refactor class SubversionSettings

SubversionSettings now inherits VcsBase::VcsBaseClientSettings allowing
significant code factorization.

Change-Id: I6be1bde16ce9b3d1294dd859fe8b2c60cf68b9d0
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 11eba859
......@@ -82,17 +82,19 @@ QSharedPointer<VcsBase::AbstractCheckoutJob> CheckoutWizard::createJob(const QLi
const CheckoutWizardPage *cwp = qobject_cast<const CheckoutWizardPage *>(parameterPages.front());
QTC_ASSERT(cwp, return QSharedPointer<VcsBase::AbstractCheckoutJob>());
const SubversionSettings settings = SubversionPlugin::instance()->settings();
const QString binary = settings.svnBinaryPath;
const QString binary = settings.binaryPath();
const QString directory = cwp->directory();
QStringList args;
args << QLatin1String("checkout") << cwp->repository() << directory;
const QString workingDirectory = cwp->path();
*checkoutPath = workingDirectory + QLatin1Char('/') + directory;
const QStringList completeArgs = settings.hasAuthentication() ?
SubversionPlugin::addAuthenticationOptions(args, settings.user, settings.password) :
args;
if (settings.hasAuthentication()) {
const QString user = settings.stringValue(SubversionSettings::userKey);
const QString pwd = settings.stringValue(SubversionSettings::passwordKey);
args = SubversionPlugin::addAuthenticationOptions(args, user, pwd);
}
VcsBase::ProcessCheckoutJob *job = new VcsBase::ProcessCheckoutJob;
job->addStep(binary, completeArgs, workingDirectory);
job->addStep(binary, args, workingDirectory);
return QSharedPointer<VcsBase::AbstractCheckoutJob>(job);
}
......
......@@ -54,30 +54,31 @@ SettingsPageWidget::SettingsPageWidget(QWidget *parent) :
SubversionSettings SettingsPageWidget::settings() const
{
SubversionSettings rc;
rc.svnCommand = m_ui.pathChooser->rawPath();
rc.svnBinaryPath = m_ui.pathChooser->path();
rc.useAuthentication = m_ui.userGroupBox->isChecked();
rc.user = m_ui.usernameLineEdit->text();
rc.password = m_ui.passwordLineEdit->text();
rc.timeOutS = m_ui.timeOutSpinBox->value();
if (rc.user.isEmpty())
rc.useAuthentication = false;
rc.promptToSubmit = m_ui.promptToSubmitCheckBox->isChecked();
rc.spaceIgnorantAnnotation = m_ui.spaceIgnorantAnnotationCheckBox->isChecked();
rc.logCount = m_ui.logCountSpinBox->value();
rc.setValue(SubversionSettings::binaryPathKey, m_ui.pathChooser->rawPath());
rc.setValue(SubversionSettings::useAuthenticationKey, m_ui.userGroupBox->isChecked());
rc.setValue(SubversionSettings::userKey, m_ui.usernameLineEdit->text());
rc.setValue(SubversionSettings::passwordKey, m_ui.passwordLineEdit->text());
rc.setValue(SubversionSettings::timeoutKey, m_ui.timeOutSpinBox->value());
if (rc.stringValue(SubversionSettings::userKey).isEmpty())
rc.setValue(SubversionSettings::useAuthenticationKey, false);
rc.setValue(SubversionSettings::promptOnSubmitKey, m_ui.promptToSubmitCheckBox->isChecked());
rc.setValue(SubversionSettings::spaceIgnorantAnnotationKey,
m_ui.spaceIgnorantAnnotationCheckBox->isChecked());
rc.setValue(SubversionSettings::logCountKey, m_ui.logCountSpinBox->value());
return rc;
}
void SettingsPageWidget::setSettings(const SubversionSettings &s)
{
m_ui.pathChooser->setPath(s.svnCommand);
m_ui.usernameLineEdit->setText(s.user);
m_ui.passwordLineEdit->setText(s.password);
m_ui.userGroupBox->setChecked(s.useAuthentication);
m_ui.timeOutSpinBox->setValue(s.timeOutS);
m_ui.promptToSubmitCheckBox->setChecked(s.promptToSubmit);
m_ui.spaceIgnorantAnnotationCheckBox->setChecked(s.spaceIgnorantAnnotation);
m_ui.logCountSpinBox->setValue(s.logCount);
m_ui.pathChooser->setPath(s.binaryPath());
m_ui.usernameLineEdit->setText(s.stringValue(SubversionSettings::userKey));
m_ui.passwordLineEdit->setText(s.stringValue(SubversionSettings::passwordKey));
m_ui.userGroupBox->setChecked(s.boolValue(SubversionSettings::useAuthenticationKey));
m_ui.timeOutSpinBox->setValue(s.intValue(SubversionSettings::timeoutKey));
m_ui.promptToSubmitCheckBox->setChecked(s.boolValue(SubversionSettings::promptOnSubmitKey));
m_ui.spaceIgnorantAnnotationCheckBox->setChecked(
s.boolValue(SubversionSettings::spaceIgnorantAnnotationKey));
m_ui.logCountSpinBox->setValue(s.intValue(SubversionSettings::logCountKey));
}
QString SettingsPageWidget::searchKeywords() const
......
......@@ -55,7 +55,7 @@ Core::Id SubversionControl::id() const
bool SubversionControl::isConfigured() const
{
const QString binary = m_plugin->settings().svnBinaryPath;
const QString binary = m_plugin->settings().binaryPath();
if (binary.isEmpty())
return false;
QFileInfo fi(binary);
......
......@@ -260,7 +260,7 @@ bool SubversionPlugin::initialize(const QStringList & /*arguments */, QString *e
if (!Core::ICore::mimeDatabase()->addMimeTypes(QLatin1String(":/trolltech.subversion/Subversion.mimetypes.xml"), errorMessage))
return false;
m_settings.fromSettings(Core::ICore::settings());
m_settings.readSettings(Core::ICore::settings());
addAutoReleasedObject(new SettingsPage);
......@@ -479,7 +479,8 @@ bool SubversionPlugin::submitEditorAboutToClose(VcsBase::VcsBaseSubmitEditor *su
editor->promptSubmit(tr("Closing Subversion Editor"),
tr("Do you want to commit the change?"),
tr("The commit message check failed. Do you want to commit the change?"),
&newSettings.promptToSubmit, !m_submitActionTriggered);
newSettings.boolPointer(SubversionSettings::promptOnSubmitKey),
!m_submitActionTriggered);
m_submitActionTriggered = false;
switch (answer) {
case VcsBase::VcsBaseSubmitEditor::SubmitCanceled:
......@@ -584,7 +585,7 @@ void SubversionPlugin::svnDiff(const Subversion::Internal::SubversionDiffParamet
args << p.files;
const SubversionResponse response =
runSvn(p.workingDir, args, m_settings.timeOutMS(), 0, codec);
runSvn(p.workingDir, args, m_settings.timeOutMs(), 0, codec);
if (response.error)
return;
......@@ -683,7 +684,7 @@ void SubversionPlugin::revertAll()
QStringList args;
args << QLatin1String("revert") << QLatin1String("--recursive") << state.topLevel();
const SubversionResponse revertResponse =
runSvn(state.topLevel(), args, m_settings.timeOutMS(),
runSvn(state.topLevel(), args, m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow);
if (revertResponse.error)
QMessageBox::warning(0, title, tr("Revert failed: %1").arg(revertResponse.message), QMessageBox::Ok);
......@@ -700,7 +701,7 @@ void SubversionPlugin::revertCurrentFile()
args.push_back(state.relativeCurrentFile());
const SubversionResponse diffResponse =
runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(), 0);
runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMs(), 0);
if (diffResponse.error)
return;
......@@ -718,7 +719,7 @@ void SubversionPlugin::revertCurrentFile()
args << QLatin1String("revert") << state.relativeCurrentFile();
const SubversionResponse revertResponse =
runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMS(),
runSvn(state.currentFileTopLevel(), args, m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow);
if (!revertResponse.error)
......@@ -776,7 +777,7 @@ void SubversionPlugin::startCommit(const QString &workingDir, const QStringList
args += files;
const SubversionResponse response =
runSvn(workingDir, args, m_settings.timeOutMS(), 0);
runSvn(workingDir, args, m_settings.timeOutMs(), 0);
if (response.error)
return;
......@@ -816,7 +817,7 @@ bool SubversionPlugin::commit(const QString &messageFile,
args << QLatin1String(nonInteractiveOptionC) << QLatin1String("--file") << messageFile;
args.append(subVersionFileList);
const SubversionResponse response =
runSvn(m_commitRepository, args, m_settings.longTimeOutMS(),
runSvn(m_commitRepository, args, 10 * m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow);
return !response.error ;
}
......@@ -872,7 +873,7 @@ void SubversionPlugin::svnStatus(const QString &workingDir, const QStringList &r
args.append(relativePaths);
VcsBase::VcsBaseOutputWindow *outwin = VcsBase::VcsBaseOutputWindow::instance();
outwin->setRepository(workingDir);
runSvn(workingDir, args, m_settings.timeOutMS(),
runSvn(workingDir, args, m_settings.timeOutMs(),
ShowStdOutInLogWindow|ShowSuccessMessage);
outwin->clearRepository();
}
......@@ -883,15 +884,17 @@ void SubversionPlugin::filelog(const QString &workingDir,
{
// no need for temp file
QStringList args(QLatin1String("log"));
if (m_settings.logCount > 0)
args << QLatin1String("-l") << QString::number(m_settings.logCount);
if (m_settings.intValue(SubversionSettings::logCountKey) > 0) {
args << QLatin1String("-l")
<< QString::number(m_settings.intValue(SubversionSettings::logCountKey));
}
foreach (const QString &file, files)
args.append(QDir::toNativeSeparators(file));
// subversion stores log in UTF-8 and returns it back in user system locale.
// So we do not need to encode it.
const SubversionResponse response =
runSvn(workingDir, args, m_settings.timeOutMS(),
runSvn(workingDir, args, m_settings.timeOutMs(),
SshPasswordPrompt, 0/*codec*/);
if (response.error)
return;
......@@ -928,7 +931,7 @@ void SubversionPlugin::svnUpdate(const QString &workingDir, const QStringList &r
if (!relativePaths.isEmpty())
args.append(relativePaths);
const SubversionResponse response =
runSvn(workingDir, args, m_settings.longTimeOutMS(),
runSvn(workingDir, args, 10 * m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow);
if (!response.error)
subVersionControl()->emitRepositoryChanged(workingDir);
......@@ -957,7 +960,7 @@ void SubversionPlugin::vcsAnnotate(const QString &workingDir, const QString &fil
QTextCodec *codec = VcsBase::VcsBaseEditorWidget::getCodec(source);
QStringList args(QLatin1String("annotate"));
if (m_settings.spaceIgnorantAnnotation)
if (m_settings.boolValue(SubversionSettings::spaceIgnorantAnnotationKey))
args << QLatin1String("-x") << QLatin1String("-uw");
if (!revision.isEmpty())
args << QLatin1String("-r") << revision;
......@@ -965,7 +968,7 @@ void SubversionPlugin::vcsAnnotate(const QString &workingDir, const QString &fil
args.append(QDir::toNativeSeparators(file));
const SubversionResponse response =
runSvn(workingDir, args, m_settings.timeOutMS(),
runSvn(workingDir, args, m_settings.timeOutMs(),
SshPasswordPrompt|ForceCLocale, codec);
if (response.error)
return;
......@@ -1019,7 +1022,7 @@ void SubversionPlugin::describe(const QString &source, const QString &changeNr)
args.push_back(QLatin1String("-r"));
args.push_back(changeNr);
const SubversionResponse logResponse =
runSvn(topLevel, args, m_settings.timeOutMS(), SshPasswordPrompt);
runSvn(topLevel, args, m_settings.timeOutMs(), SshPasswordPrompt);
if (logResponse.error)
return;
description = logResponse.stdOut;
......@@ -1034,7 +1037,7 @@ void SubversionPlugin::describe(const QString &source, const QString &changeNr)
QTextCodec *codec = VcsBase::VcsBaseEditorWidget::getCodec(source);
const SubversionResponse response =
runSvn(topLevel, args, m_settings.timeOutMS(),
runSvn(topLevel, args, m_settings.timeOutMs(),
SshPasswordPrompt, codec);
if (response.error)
return;
......@@ -1086,12 +1089,11 @@ SubversionResponse
unsigned flags,
QTextCodec *outputCodec)
{
return m_settings.hasAuthentication() ?
runSvn(workingDir, m_settings.user, m_settings.password,
arguments, timeOut, flags, outputCodec) :
runSvn(workingDir, QString(), QString(),
arguments, timeOut, flags, outputCodec);
const bool hasAuth = m_settings.hasAuthentication();
return runSvn(workingDir,
hasAuth ? m_settings.stringValue(SubversionSettings::userKey) : QString(),
hasAuth ? m_settings.stringValue(SubversionSettings::passwordKey) : QString(),
arguments, timeOut, flags, outputCodec);
}
// Add authorization options to the command line arguments.
......@@ -1120,7 +1122,7 @@ SubversionResponse SubversionPlugin::runSvn(const QString &workingDir,
const QStringList &arguments, int timeOut,
unsigned flags, QTextCodec *outputCodec)
{
const QString executable = m_settings.svnBinaryPath;
const QString executable = m_settings.binaryPath();
SubversionResponse response;
if (executable.isEmpty()) {
response.error = true;
......@@ -1179,7 +1181,7 @@ void SubversionPlugin::setSettings(const SubversionSettings &s)
{
if (s != m_settings) {
m_settings = s;
m_settings.toSettings(Core::ICore::settings());
m_settings.writeSettings(Core::ICore::settings());
subVersionControl()->emitConfigurationChanged();
}
}
......@@ -1204,7 +1206,7 @@ bool SubversionPlugin::vcsAdd15(const QString &workingDir, const QString &rawFil
QStringList args;
args << QLatin1String("add") << QLatin1String("--parents") << file;
const SubversionResponse response =
runSvn(workingDir, args, m_settings.timeOutMS(),
runSvn(workingDir, args, m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow);
return !response.error;
}
......@@ -1227,7 +1229,7 @@ bool SubversionPlugin::vcsAdd14(const QString &workingDir, const QString &rawFil
QStringList addDirArgs;
addDirArgs << QLatin1String("add") << QLatin1String("--non-recursive") << QDir::toNativeSeparators(path);
const SubversionResponse addDirResponse =
runSvn(workingDir, addDirArgs, m_settings.timeOutMS(),
runSvn(workingDir, addDirArgs, m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow);
if (addDirResponse.error)
return false;
......@@ -1238,7 +1240,7 @@ bool SubversionPlugin::vcsAdd14(const QString &workingDir, const QString &rawFil
QStringList args;
args << QLatin1String("add") << QDir::toNativeSeparators(rawFileName);
const SubversionResponse response =
runSvn(workingDir, args, m_settings.timeOutMS(),
runSvn(workingDir, args, m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow);
return !response.error;
}
......@@ -1251,7 +1253,7 @@ bool SubversionPlugin::vcsDelete(const QString &workingDir, const QString &rawFi
args.push_back(file);
const SubversionResponse response =
runSvn(workingDir, args, m_settings.timeOutMS(),
runSvn(workingDir, args, m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow);
return !response.error;
}
......@@ -1261,7 +1263,7 @@ bool SubversionPlugin::vcsMove(const QString &workingDir, const QString &from, c
QStringList args(QLatin1String("move"));
args << QDir::toNativeSeparators(from) << QDir::toNativeSeparators(to);
const SubversionResponse response =
runSvn(workingDir, args, m_settings.timeOutMS(),
runSvn(workingDir, args, m_settings.timeOutMs(),
SshPasswordPrompt|ShowStdOutInLogWindow|FullySynchronously);
return !response.error;
}
......@@ -1283,12 +1285,12 @@ bool SubversionPlugin::vcsCheckout(const QString &directory, const QByteArray &u
tempUrl.setUserInfo(QString());
args << QLatin1String(tempUrl.toEncoded()) << directory;
const SubversionResponse response = runSvn(directory, username, password, args,
m_settings.longTimeOutMS(),
10 * m_settings.timeOutMs(),
VcsBase::VcsBasePlugin::SshPasswordPrompt);
return !response.error;
} else {
args << QLatin1String(url) << directory;
const SubversionResponse response = runSvn(directory, args, m_settings.longTimeOutMS(),
const SubversionResponse response = runSvn(directory, args, 10 * m_settings.timeOutMs(),
VcsBase::VcsBasePlugin::SshPasswordPrompt);
return !response.error;
}
......@@ -1300,7 +1302,7 @@ QString SubversionPlugin::vcsGetRepositoryURL(const QString &directory)
QStringList args = QStringList(QLatin1String("info"));
args << QLatin1String("--xml");
const SubversionResponse response = runSvn(directory, args, m_settings.longTimeOutMS(), SuppressCommandLogging);
const SubversionResponse response = runSvn(directory, args, 10 * m_settings.timeOutMs(), SuppressCommandLogging);
xml.addData(response.stdOut);
bool repo = false;
......
......@@ -34,73 +34,48 @@
#include <QSettings>
static const char groupC[] = "Subversion";
static const char commandKeyC[] = "Command";
static const char userKeyC[] = "User";
static const char passwordKeyC[] = "Password";
static const char authenticationKeyC[] = "Authentication";
namespace Subversion {
namespace Internal {
static const char promptToSubmitKeyC[] = "PromptForSubmit";
static const char timeOutKeyC[] = "TimeOut";
static const char spaceIgnorantAnnotationKeyC[] = "SpaceIgnorantAnnotation";
static const char logCountKeyC[] = "LogCount";
const QLatin1String SubversionSettings::useAuthenticationKey("Authentication");
const QLatin1String SubversionSettings::userKey("User");
const QLatin1String SubversionSettings::passwordKey("Password");
const QLatin1String SubversionSettings::spaceIgnorantAnnotationKey("SpaceIgnorantAnnotation");
enum { defaultTimeOutS = 30, defaultLogCount = 1000 };
static QString defaultCommand()
SubversionSettings::SubversionSettings()
{
return QLatin1String("svn" QTC_HOST_EXE_SUFFIX);
setSettingsGroup(QLatin1String("Subversion"));
declareKey(binaryPathKey, QLatin1String("svn" QTC_HOST_EXE_SUFFIX));
declareKey(logCountKey, 1000);
declareKey(useAuthenticationKey, false);
declareKey(userKey, QLatin1String(""));
declareKey(passwordKey, QLatin1String(""));
declareKey(spaceIgnorantAnnotationKey, true);
}
using namespace Subversion::Internal;
SubversionSettings::SubversionSettings() :
svnCommand(defaultCommand()),
useAuthentication(false),
logCount(defaultLogCount),
timeOutS(defaultTimeOutS),
promptToSubmit(true),
spaceIgnorantAnnotation(true)
bool SubversionSettings::hasAuthentication() const
{
return boolValue(useAuthenticationKey) && !stringValue(userKey).isEmpty();
}
void SubversionSettings::fromSettings(QSettings *settings)
int SubversionSettings::timeOutMs() const
{
settings->beginGroup(QLatin1String(groupC));
svnCommand = settings->value(QLatin1String(commandKeyC), defaultCommand()).toString();
svnBinaryPath = Utils::Environment::systemEnvironment().searchInPath(svnCommand);
useAuthentication = settings->value(QLatin1String(authenticationKeyC), QVariant(false)).toBool();
user = settings->value(QLatin1String(userKeyC), QString()).toString();
password = settings->value(QLatin1String(passwordKeyC), QString()).toString();
timeOutS = settings->value(QLatin1String(timeOutKeyC), defaultTimeOutS).toInt();
promptToSubmit = settings->value(QLatin1String(promptToSubmitKeyC), true).toBool();
spaceIgnorantAnnotation = settings->value(QLatin1String(spaceIgnorantAnnotationKeyC), true).toBool();
logCount = settings->value(QLatin1String(logCountKeyC), int(defaultLogCount)).toInt();
settings->endGroup();
return 1000 * intValue(timeoutKey);
}
void SubversionSettings::toSettings(QSettings *settings) const
void SubversionSettings::readLegacySettings(const QSettings *settings)
{
settings->beginGroup(QLatin1String(groupC));
settings->setValue(QLatin1String(commandKeyC), svnCommand);
settings->setValue(QLatin1String(authenticationKeyC), QVariant(useAuthentication));
settings->setValue(QLatin1String(userKeyC), user);
settings->setValue(QLatin1String(passwordKeyC), password);
settings->setValue(QLatin1String(promptToSubmitKeyC), promptToSubmit);
settings->setValue(QLatin1String(timeOutKeyC), timeOutS);
settings->setValue(QLatin1String(spaceIgnorantAnnotationKeyC), spaceIgnorantAnnotation);
settings->setValue(QLatin1String(logCountKeyC), logCount);
settings->endGroup();
const QString keyRoot = settingsGroup() + QLatin1Char('/');
const QString oldBinaryPathKey = keyRoot + QLatin1String("Command");
const QString oldPromptOnSubmitKey = keyRoot + QLatin1String("PromptForSubmit");
const QString oldTimeoutKey = keyRoot + QLatin1String("TimeOut");
if (settings->contains(oldBinaryPathKey))
this->setValue(binaryPathKey, settings->value(oldBinaryPathKey).toString());
if (settings->contains(oldPromptOnSubmitKey))
this->setValue(promptOnSubmitKey, settings->value(oldPromptOnSubmitKey).toBool());
if (settings->contains(oldTimeoutKey))
this->setValue(timeoutKey, settings->value(oldTimeoutKey).toInt());
}
bool SubversionSettings::equals(const SubversionSettings &s) const
{
return svnCommand == s.svnCommand
&& useAuthentication == s.useAuthentication
&& user == s.user
&& password == s.password
&& logCount == s.logCount
&& timeOutS == s.timeOutS
&& promptToSubmit == s.promptToSubmit
&& spaceIgnorantAnnotation == s.spaceIgnorantAnnotation;
}
} // namespace Internal
} // namespace Subversion
......@@ -30,45 +30,28 @@
#ifndef SUBVERSIONSETTINGS_H
#define SUBVERSIONSETTINGS_H
#include <QStringList>
QT_BEGIN_NAMESPACE
class QSettings;
QT_END_NAMESPACE
#include <vcsbase/vcsbaseclientsettings.h>
namespace Subversion {
namespace Internal {
struct SubversionSettings
class SubversionSettings : public VcsBase::VcsBaseClientSettings
{
SubversionSettings();
void fromSettings(QSettings *);
void toSettings(QSettings *) const;
public:
static const QLatin1String useAuthenticationKey;
static const QLatin1String userKey;
static const QLatin1String passwordKey;
static const QLatin1String spaceIgnorantAnnotationKey;
inline int timeOutMS() const { return timeOutS * 1000; }
inline int longTimeOutMS() const { return timeOutS * 10000; }
inline bool hasAuthentication() const { return useAuthentication && !user.isEmpty(); }
SubversionSettings();
bool hasAuthentication() const;
bool equals(const SubversionSettings &s) const;
int timeOutMs() const;
QString svnCommand;
QString svnBinaryPath;
bool useAuthentication;
QString user;
QString password;
int logCount;
int timeOutS;
bool promptToSubmit;
bool spaceIgnorantAnnotation;
protected:
void readLegacySettings(const QSettings *settings);
};
inline bool operator==(const SubversionSettings &p1, const SubversionSettings &p2)
{ return p1.equals(p2); }
inline bool operator!=(const SubversionSettings &p1, const SubversionSettings &p2)
{ return !p1.equals(p2); }
} // namespace Internal
} // namespace Subversion
......
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