summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-08-02 17:59:16 +0200
committerhjk <hjk@qt.io>2022-08-03 09:44:08 +0000
commitdac9dff4595505773bf86795cb7817f1954264da (patch)
tree2d384577c385c429217d5b150877fcc10c59369a
parentde08f08a2101e96857fa194f84ad7c24c5392667 (diff)
downloadqt-creator-dac9dff4595505773bf86795cb7817f1954264da.tar.gz
Gerrit: inline authenticationdialog.ui
Also, replace /#/settings/http-password by /#/settings/#HTTPCredentials There should probably be some stretch between the form and the buttonbox, but it wasn't there in the .ui so I left it out for now. Change-Id: Ie07a3283261a1070a489e454f9fb86c0c6dc2ca8 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r--src/plugins/git/CMakeLists.txt2
-rw-r--r--src/plugins/git/gerrit/authenticationdialog.cpp96
-rw-r--r--src/plugins/git/gerrit/authenticationdialog.h9
-rw-r--r--src/plugins/git/gerrit/authenticationdialog.ui127
-rw-r--r--src/plugins/git/git.qbs1
5 files changed, 76 insertions, 159 deletions
diff --git a/src/plugins/git/CMakeLists.txt b/src/plugins/git/CMakeLists.txt
index 5bcf468529..3aaee139c2 100644
--- a/src/plugins/git/CMakeLists.txt
+++ b/src/plugins/git/CMakeLists.txt
@@ -8,7 +8,7 @@ add_qtc_plugin(Git
branchview.cpp branchview.h
changeselectiondialog.cpp changeselectiondialog.h changeselectiondialog.ui
commitdata.cpp commitdata.h
- gerrit/authenticationdialog.cpp gerrit/authenticationdialog.h gerrit/authenticationdialog.ui
+ gerrit/authenticationdialog.cpp gerrit/authenticationdialog.h
gerrit/branchcombobox.cpp gerrit/branchcombobox.h
gerrit/gerritdialog.cpp gerrit/gerritdialog.h gerrit/gerritdialog.ui
gerrit/gerritmodel.cpp gerrit/gerritmodel.h
diff --git a/src/plugins/git/gerrit/authenticationdialog.cpp b/src/plugins/git/gerrit/authenticationdialog.cpp
index a78b569fee..dfecd3e9e2 100644
--- a/src/plugins/git/gerrit/authenticationdialog.cpp
+++ b/src/plugins/git/gerrit/authenticationdialog.cpp
@@ -24,21 +24,27 @@
****************************************************************************/
#include "authenticationdialog.h"
-#include "ui_authenticationdialog.h"
+
#include "gerritserver.h"
#include <utils/fileutils.h>
#include <utils/hostosinfo.h>
+#include <utils/layoutbuilder.h>
#include <QClipboard>
+#include <QDialogButtonBox>
#include <QDir>
#include <QFile>
#include <QGuiApplication>
+#include <QLabel>
+#include <QLineEdit>
#include <QPushButton>
#include <QRegularExpression>
#include <QTextStream>
#include <QTimer>
+using namespace Utils;
+
namespace Gerrit {
namespace Internal {
@@ -65,49 +71,85 @@ static bool replaceEntry(QString &line, const QString &type, const QString &valu
return true;
}
-AuthenticationDialog::AuthenticationDialog(GerritServer *server) :
- ui(new Ui::AuthenticationDialog),
- m_server(server)
+AuthenticationDialog::AuthenticationDialog(GerritServer *server)
+ : m_server(server)
{
- ui->setupUi(this);
- ui->descriptionLabel->setText(ui->descriptionLabel->text().replace(
- "LINK_PLACEHOLDER", server->url() + "/#/settings/http-password"));
- ui->descriptionLabel->setOpenExternalLinks(true);
- ui->serverLineEdit->setText(server->host);
- ui->userLineEdit->setText(server->user.userName);
+ setWindowTitle(tr("Authentication"));
+ resize(400, 334);
+
+ // FIXME: Take html out of this translatable string.
+ const QString desc = tr(
+ "<html><head/><body><p>Gerrit server with HTTP was detected, but you need "
+ "to set up credentials for it.</p><p>To get your password, "
+ "<a href=\"LINK_PLACEHOLDER\"><span style=\" text-decoration: "
+ "underline; color:#007af4;\">click here</span></a> (sign in if needed). "
+ "Click Generate Password if the password is blank, and copy the user name "
+ "and password to this form.</p><p>Choose Anonymous if you do not want "
+ "authentication for this server. In this case, changes that require "
+ "authentication (like draft changes or private projects) will not be displayed."
+ "</p></body></html>")
+ .replace("LINK_PLACEHOLDER", server->url() + "/#/settings/#HTTPCredentials");
+
+ auto descriptionLabel = new QLabel(desc);
+ descriptionLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
+ descriptionLabel->setTextFormat(Qt::RichText);
+ descriptionLabel->setWordWrap(true);
+ descriptionLabel->setOpenExternalLinks(true);
+
+ m_userLineEdit = new QLineEdit(server->user.userName);
+
+ m_passwordLineEdit = new QLineEdit;
+
+ auto serverLineEdit = new QLineEdit(server->host);
+ serverLineEdit->setEnabled(false);
+
+ m_buttonBox = new QDialogButtonBox(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
+
m_netrcFileName = QDir::homePath() + '/' +
QLatin1String(Utils::HostOsInfo::isWindowsHost() ? "_netrc" : ".netrc");
+
+ using namespace Layouting;
+ Column {
+ descriptionLabel,
+ Form {
+ tr("Server:"), serverLineEdit, br,
+ tr("&User:"), m_userLineEdit, br,
+ tr("&Password:"), m_passwordLineEdit, br,
+ },
+ m_buttonBox,
+ }.attachTo(this);
+
readExistingConf();
- QPushButton *anonymous = ui->buttonBox->addButton(tr("Anonymous"), QDialogButtonBox::AcceptRole);
- connect(ui->buttonBox, &QDialogButtonBox::clicked,
+ QPushButton *anonymous = m_buttonBox->addButton(tr("Anonymous"), QDialogButtonBox::AcceptRole);
+ connect(m_buttonBox, &QDialogButtonBox::clicked,
this, [this, anonymous](QAbstractButton *button) {
if (button == anonymous)
m_authenticated = false;
});
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
- connect(ui->passwordLineEdit, &QLineEdit::editingFinished,
+ m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+ connect(m_passwordLineEdit, &QLineEdit::editingFinished,
this, &AuthenticationDialog::checkCredentials);
m_checkTimer = new QTimer(this);
m_checkTimer->setSingleShot(true);
connect(m_checkTimer, &QTimer::timeout, this, &AuthenticationDialog::checkCredentials);
- connect(ui->passwordLineEdit, &QLineEdit::textChanged, [this]() {
- if (QGuiApplication::clipboard()->text() == ui->passwordLineEdit->text()) {
+ connect(m_passwordLineEdit, &QLineEdit::textChanged, [this]() {
+ if (QGuiApplication::clipboard()->text() == m_passwordLineEdit->text()) {
checkCredentials();
return;
}
m_checkTimer->start(2000);
});
- if (!ui->userLineEdit->text().isEmpty())
- ui->passwordLineEdit->setFocus();
-}
+ if (!m_userLineEdit->text().isEmpty())
+ m_passwordLineEdit->setFocus();
-AuthenticationDialog::~AuthenticationDialog()
-{
- delete ui;
+ connect(m_buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(m_buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
}
+AuthenticationDialog::~AuthenticationDialog() = default;
+
void AuthenticationDialog::readExistingConf()
{
QFile netrcFile(m_netrcFileName);
@@ -123,9 +165,9 @@ void AuthenticationDialog::readExistingConf()
const QString login = findEntry(line, "login");
const QString password = findEntry(line, "password");
if (!login.isEmpty())
- ui->userLineEdit->setText(login);
+ m_userLineEdit->setText(login);
if (!password.isEmpty())
- ui->passwordLineEdit->setText(password);
+ m_passwordLineEdit->setText(password);
}
}
netrcFile.close();
@@ -136,8 +178,8 @@ bool AuthenticationDialog::setupCredentials()
QString netrcContents;
QTextStream out(&netrcContents);
bool found = false;
- const QString user = ui->userLineEdit->text().trimmed();
- const QString password = ui->passwordLineEdit->text().trimmed();
+ const QString user = m_userLineEdit->text().trimmed();
+ const QString password = m_passwordLineEdit->text().trimmed();
if (user.isEmpty() || password.isEmpty())
return false;
@@ -165,7 +207,7 @@ void AuthenticationDialog::checkCredentials()
int result = 400;
if (setupCredentials())
result = m_server->testConnection();
- ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(result == 200);
+ m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(result == 200);
}
} // Internal
diff --git a/src/plugins/git/gerrit/authenticationdialog.h b/src/plugins/git/gerrit/authenticationdialog.h
index 7556c5bd0b..32584d2258 100644
--- a/src/plugins/git/gerrit/authenticationdialog.h
+++ b/src/plugins/git/gerrit/authenticationdialog.h
@@ -29,6 +29,8 @@
#include <QDialog>
QT_BEGIN_NAMESPACE
+class QDialogButtonBox;
+class QLineEdit;
class QTimer;
QT_END_NAMESPACE
@@ -37,8 +39,6 @@ namespace Internal {
class GerritServer;
-namespace Ui { class AuthenticationDialog; }
-
class AuthenticationDialog : public QDialog
{
Q_DECLARE_TR_FUNCTIONS(Gerrit::Internal::AuthenticationDialog)
@@ -52,12 +52,15 @@ private:
void readExistingConf();
bool setupCredentials();
void checkCredentials();
- Ui::AuthenticationDialog *ui = nullptr;
+
GerritServer *m_server = nullptr;
QString m_netrcFileName;
QStringList m_allMachines;
bool m_authenticated = true;
QTimer *m_checkTimer = nullptr;
+ QLineEdit *m_userLineEdit;
+ QLineEdit *m_passwordLineEdit;
+ QDialogButtonBox *m_buttonBox;
};
} // Internal
diff --git a/src/plugins/git/gerrit/authenticationdialog.ui b/src/plugins/git/gerrit/authenticationdialog.ui
deleted file mode 100644
index 5fd21bd758..0000000000
--- a/src/plugins/git/gerrit/authenticationdialog.ui
+++ /dev/null
@@ -1,127 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>Gerrit::Internal::AuthenticationDialog</class>
- <widget class="QDialog" name="Gerrit::Internal::AuthenticationDialog">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>400</width>
- <height>334</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Authentication</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="QLabel" name="descriptionLabel">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Gerrit server with HTTP was detected, but you need to set up credentials for it.&lt;/p&gt;&lt;p&gt;To get your password, &lt;a href=&quot;LINK_PLACEHOLDER&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;click here&lt;/span&gt;&lt;/a&gt; (sign in if needed). Click Generate Password if the password is blank, and copy the user name and password to this form.&lt;/p&gt;&lt;p&gt;Choose Anonymous if you do not want authentication for this server. In this case, changes that require authentication (like draft changes or private projects) will not be displayed.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
- </property>
- <property name="textFormat">
- <enum>Qt::RichText</enum>
- </property>
- <property name="wordWrap">
- <bool>true</bool>
- </property>
- </widget>
- </item>
- <item>
- <layout class="QFormLayout" name="formLayout">
- <item row="1" column="0">
- <widget class="QLabel" name="userLabel">
- <property name="text">
- <string>&amp;User:</string>
- </property>
- <property name="buddy">
- <cstring>userLineEdit</cstring>
- </property>
- </widget>
- </item>
- <item row="1" column="1">
- <widget class="QLineEdit" name="userLineEdit"/>
- </item>
- <item row="2" column="0">
- <widget class="QLabel" name="passwordLabel">
- <property name="text">
- <string>&amp;Password:</string>
- </property>
- <property name="buddy">
- <cstring>passwordLineEdit</cstring>
- </property>
- </widget>
- </item>
- <item row="2" column="1">
- <widget class="QLineEdit" name="passwordLineEdit"/>
- </item>
- <item row="0" column="0">
- <widget class="QLabel" name="serverLabel">
- <property name="text">
- <string>Server:</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QLineEdit" name="serverLineEdit">
- <property name="enabled">
- <bool>false</bool>
- </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>Gerrit::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>Gerrit::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/git/git.qbs b/src/plugins/git/git.qbs
index ad22026f28..971ee7ad2f 100644
--- a/src/plugins/git/git.qbs
+++ b/src/plugins/git/git.qbs
@@ -74,7 +74,6 @@ QtcPlugin {
files: [
"authenticationdialog.cpp",
"authenticationdialog.h",
- "authenticationdialog.ui",
"branchcombobox.cpp",
"branchcombobox.h",
"gerritdialog.cpp",