summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Baryshnikov <nib952051@gmail.com>2013-06-10 00:57:54 +0300
committerTobias Hunger <tobias.hunger@digia.com>2013-06-11 18:40:13 +0200
commitbc29c67183db6d2ad87861aca4966c4ae2e1b83d (patch)
tree3a68cbfa2825fd34aad95ba65b6944689342643e
parent8ba09eabca5054fb67b8da50d052e595c9ae8bfa (diff)
downloadqt-creator-bc29c67183db6d2ad87861aca4966c4ae2e1b83d.tar.gz
Mercurial: Handle HTTP authentication, auth dialog
Make it possible to pull and push into online repositories with http authorization. Changes: * Separated dialogs for entering username and password are merge together * Do not show dialog for local repos * Prohibit passwords for ssh scheme Task-number: QTCREATORBUG-5104 Change-Id: I22fe3d778bb43d25ccd3ee423f98b22dd2019c24 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
-rw-r--r--src/plugins/mercurial/authenticationdialog.cpp62
-rw-r--r--src/plugins/mercurial/authenticationdialog.h58
-rw-r--r--src/plugins/mercurial/authenticationdialog.ui92
-rw-r--r--src/plugins/mercurial/mercurial.pro9
-rw-r--r--src/plugins/mercurial/mercurial.qbs3
-rw-r--r--src/plugins/mercurial/srcdestdialog.cpp29
6 files changed, 237 insertions, 16 deletions
diff --git a/src/plugins/mercurial/authenticationdialog.cpp b/src/plugins/mercurial/authenticationdialog.cpp
new file mode 100644
index 0000000000..2dc6cbf6dc
--- /dev/null
+++ b/src/plugins/mercurial/authenticationdialog.cpp
@@ -0,0 +1,62 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#include "authenticationdialog.h"
+#include "ui_authenticationdialog.h"
+
+using namespace Mercurial::Internal;
+
+AuthenticationDialog::AuthenticationDialog(const QString &username, const QString &password, QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::AuthenticationDialog)
+{
+ ui->setupUi(this);
+ ui->username->setText(username);
+ ui->password->setText(password);
+}
+
+AuthenticationDialog::~AuthenticationDialog()
+{
+ delete ui;
+}
+
+void AuthenticationDialog::setPasswordEnabled(bool enabled)
+{
+ ui->password->setEnabled(enabled);
+}
+
+QString AuthenticationDialog::getUserName()
+{
+ return ui->username->text();
+}
+
+QString AuthenticationDialog::getPassword()
+{
+ return ui->password->text();
+}
diff --git a/src/plugins/mercurial/authenticationdialog.h b/src/plugins/mercurial/authenticationdialog.h
new file mode 100644
index 0000000000..31e54a8ffb
--- /dev/null
+++ b/src/plugins/mercurial/authenticationdialog.h
@@ -0,0 +1,58 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of Qt Creator.
+**
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+****************************************************************************/
+
+#ifndef AUTHENTICATIONDIALOG_H
+#define AUTHENTICATIONDIALOG_H
+
+#include <QDialog>
+
+namespace Mercurial {
+namespace Internal {
+
+namespace Ui { class AuthenticationDialog; }
+
+class AuthenticationDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit AuthenticationDialog(const QString &username, const QString &password, QWidget *parent = 0);
+ ~AuthenticationDialog();
+ void setPasswordEnabled(bool enabled);
+ QString getUserName();
+ QString getPassword();
+
+private:
+ Ui::AuthenticationDialog *ui;
+};
+
+} // namespace Internal
+} // namespace Mercurial
+
+#endif // AUTHENTICATIONDIALOG_H
diff --git a/src/plugins/mercurial/authenticationdialog.ui b/src/plugins/mercurial/authenticationdialog.ui
new file mode 100644
index 0000000000..c2c9bdaa17
--- /dev/null
+++ b/src/plugins/mercurial/authenticationdialog.ui
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Mercurial::Internal::AuthenticationDialog</class>
+ <widget class="QDialog" name="Mercurial::Internal::AuthenticationDialog">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>312</width>
+ <height>116</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QFormLayout" name="formLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="usernameLabel">
+ <property name="text">
+ <string>User name:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QLineEdit" name="username"/>
+ </item>
+ <item row="1" column="0">
+ <widget class="QLabel" name="passwordLabel">
+ <property name="text">
+ <string>Password:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <widget class="QLineEdit" name="password">
+ <property name="echoMode">
+ <enum>QLineEdit::Password</enum>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QDialogButtonBox" name="buttonBox">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="standardButtons">
+ <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>accepted()</signal>
+ <receiver>Mercurial::Internal::AuthenticationDialog</receiver>
+ <slot>accept()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>248</x>
+ <y>254</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>157</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ <connection>
+ <sender>buttonBox</sender>
+ <signal>rejected()</signal>
+ <receiver>Mercurial::Internal::AuthenticationDialog</receiver>
+ <slot>reject()</slot>
+ <hints>
+ <hint type="sourcelabel">
+ <x>316</x>
+ <y>260</y>
+ </hint>
+ <hint type="destinationlabel">
+ <x>286</x>
+ <y>274</y>
+ </hint>
+ </hints>
+ </connection>
+ </connections>
+</ui>
diff --git a/src/plugins/mercurial/mercurial.pro b/src/plugins/mercurial/mercurial.pro
index f103139049..a10510d5a1 100644
--- a/src/plugins/mercurial/mercurial.pro
+++ b/src/plugins/mercurial/mercurial.pro
@@ -11,7 +11,8 @@ SOURCES += mercurialplugin.cpp \
commiteditor.cpp \
clonewizardpage.cpp \
clonewizard.cpp \
- mercurialsettings.cpp
+ mercurialsettings.cpp \
+ authenticationdialog.cpp
HEADERS += mercurialplugin.h \
constants.h \
optionspage.h \
@@ -25,9 +26,11 @@ HEADERS += mercurialplugin.h \
commiteditor.h \
clonewizardpage.h \
clonewizard.h \
- mercurialsettings.h
+ mercurialsettings.h \
+ authenticationdialog.h
FORMS += optionspage.ui \
revertdialog.ui \
srcdestdialog.ui \
- mercurialcommitpanel.ui
+ mercurialcommitpanel.ui \
+ authenticationdialog.ui
RESOURCES += mercurial.qrc
diff --git a/src/plugins/mercurial/mercurial.qbs b/src/plugins/mercurial/mercurial.qbs
index fcf9752e5f..734ba4b0b8 100644
--- a/src/plugins/mercurial/mercurial.qbs
+++ b/src/plugins/mercurial/mercurial.qbs
@@ -15,6 +15,9 @@ QtcPlugin {
files: [
"annotationhighlighter.cpp",
"annotationhighlighter.h",
+ "authenticationdialog.cpp",
+ "authenticationdialog.h",
+ "authenticationdialog.ui",
"clonewizard.cpp",
"clonewizard.h",
"clonewizardpage.cpp",
diff --git a/src/plugins/mercurial/srcdestdialog.cpp b/src/plugins/mercurial/srcdestdialog.cpp
index 2a55fdd9fa..a5559754aa 100644
--- a/src/plugins/mercurial/srcdestdialog.cpp
+++ b/src/plugins/mercurial/srcdestdialog.cpp
@@ -27,11 +27,11 @@
**
****************************************************************************/
+#include "authenticationdialog.h"
+#include "mercurialplugin.h"
#include "srcdestdialog.h"
#include "ui_srcdestdialog.h"
-#include "mercurialplugin.h"
-#include <QInputDialog>
#include <QSettings>
#include <QUrl>
@@ -67,18 +67,21 @@ QString SrcDestDialog::getRepositoryString() const
{
if (m_ui->defaultButton->isChecked()) {
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();
+ if (m_ui->promptForCredentials->isChecked() && !repoUrl.scheme().isEmpty() && repoUrl.scheme() != QLatin1String("file")) {
+ QScopedPointer<AuthenticationDialog> authDialog(new AuthenticationDialog(repoUrl.userName(), repoUrl.password()));
+ authDialog->setPasswordEnabled(repoUrl.scheme() != QLatin1String("ssh"));
+ if (authDialog->exec()== 0)
+ return repoUrl.toString();
+
+ QString user = authDialog->getUserName();
+ if (user.isEmpty())
+ return repoUrl.toString();
+ if (user != repoUrl.userName())
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);
- }
+
+ QString pass = authDialog->getPassword();
+ if (!pass.isEmpty() && pass != repoUrl.password())
+ repoUrl.setPassword(pass);
}
return repoUrl.toString();
}