diff --git a/src/plugins/mercurial/authenticationdialog.cpp b/src/plugins/mercurial/authenticationdialog.cpp new file mode 100644 index 00000000000..2dc6cbf6dc8 --- /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 00000000000..31e54a8ffb9 --- /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 + +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 00000000000..c2c9bdaa175 --- /dev/null +++ b/src/plugins/mercurial/authenticationdialog.ui @@ -0,0 +1,92 @@ + + + Mercurial::Internal::AuthenticationDialog + + + + 0 + 0 + 312 + 116 + + + + Dialog + + + + + + + + User name: + + + + + + + + + + Password: + + + + + + + QLineEdit::Password + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Mercurial::Internal::AuthenticationDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Mercurial::Internal::AuthenticationDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/mercurial/mercurial.pro b/src/plugins/mercurial/mercurial.pro index f103139049a..a10510d5a1b 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 fcf9752e5fd..734ba4b0b89 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 2a55fdd9fad..a5559754aa3 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 #include #include @@ -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 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(); }