Mercurial: Handle HTTP authentication

Make it possible to pull and push onto online repositories with http
authorization.

Task-number: QTCREATORBUG-5104

Change-Id: Id5f5a865d301e644002e4fa8b7056d08fd9b7467
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Nikita Baryshnikov
2013-06-05 12:28:13 +03:00
committed by hjk
parent b3dd4db044
commit be5c2ea372
3 changed files with 58 additions and 2 deletions

View File

@@ -29,8 +29,13 @@
#include "srcdestdialog.h" #include "srcdestdialog.h"
#include "ui_srcdestdialog.h" #include "ui_srcdestdialog.h"
#include "mercurialplugin.h"
#include <QInputDialog>
#include <QSettings>
#include <QUrl>
using namespace VcsBase;
using namespace Mercurial::Internal; using namespace Mercurial::Internal;
SrcDestDialog::SrcDestDialog(QWidget *parent) : SrcDestDialog::SrcDestDialog(QWidget *parent) :
@@ -39,6 +44,13 @@ SrcDestDialog::SrcDestDialog(QWidget *parent) :
{ {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->localPathChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory); m_ui->localPathChooser->setExpectedKind(Utils::PathChooser::ExistingDirectory);
QUrl repoUrl(getRepoUrl());
if (repoUrl.isEmpty())
return;
if (!repoUrl.password().isEmpty())
repoUrl.setPassword(QLatin1String("***"));
m_ui->defaultPath->setText(repoUrl.toString());
m_ui->promptForCredentials->setChecked(!repoUrl.scheme().isEmpty() && repoUrl.scheme() != QLatin1String("file"));
} }
SrcDestDialog::~SrcDestDialog() SrcDestDialog::~SrcDestDialog()
@@ -53,9 +65,32 @@ void SrcDestDialog::setPathChooserKind(Utils::PathChooser::Kind kind)
QString SrcDestDialog::getRepositoryString() const QString SrcDestDialog::getRepositoryString() const
{ {
if (m_ui->defaultButton->isChecked()) if (m_ui->defaultButton->isChecked()) {
return QString(); QUrl repoUrl(getRepoUrl());
if (m_ui->promptForCredentials && (repoUrl.userName().isEmpty() || repoUrl.password().isEmpty())) {
if (repoUrl.userName().isEmpty()) {
QString user = QInputDialog::getText(0, tr("Enter user name"), tr("User name:"));
if (user.isEmpty())
return repoUrl.toString();
repoUrl.setUserName(user);
}
if (repoUrl.password().isEmpty()) {
QString password = QInputDialog::getText(0, tr("Enter password"), tr("Password:"), QLineEdit::Password);
if (!password.isEmpty())
repoUrl.setPassword(password);
}
}
return repoUrl.toString();
}
if (m_ui->localButton->isChecked()) if (m_ui->localButton->isChecked())
return m_ui->localPathChooser->path(); return m_ui->localPathChooser->path();
return m_ui->urlLineEdit->text(); return m_ui->urlLineEdit->text();
} }
QUrl SrcDestDialog::getRepoUrl() const
{
MercurialPlugin *plugin = MercurialPlugin::instance();
const VcsBasePluginState state = plugin->currentState();
QSettings settings(QString(QLatin1String("%1/.hg/hgrc")).arg(state.currentProjectPath()), QSettings::IniFormat);
return settings.value(QLatin1String("paths/default")).toUrl();
}

View File

@@ -49,6 +49,9 @@ public:
void setPathChooserKind(Utils::PathChooser::Kind kind); void setPathChooserKind(Utils::PathChooser::Kind kind);
QString getRepositoryString() const; QString getRepositoryString() const;
private:
QUrl getRepoUrl() const;
private: private:
Ui::SrcDestDialog *m_ui; Ui::SrcDestDialog *m_ui;
}; };

View File

@@ -60,6 +60,24 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="defaultPath">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="promptForCredentials">
<property name="text">
<string>Prompt for credentials</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</item> </item>
<item> <item>