Commit b3270758 authored by Volker Krause's avatar Volker Krause
Browse files

Allow to select different servers from history in the connect dialog

parent bba28d17
......@@ -20,6 +20,7 @@
#include <rest/serverinfo.h>
#include <QDebug>
#include <QIcon>
#include <QUrl>
......@@ -30,6 +31,7 @@ ConnectDialog::ConnectDialog(QWidget *parent) :
ui(new Ui::ConnectDialog)
{
ui->setupUi(this);
connect(ui->serverUrl, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ConnectDialog::serverSelected);
setWindowIcon(QIcon::fromTheme(QStringLiteral("network-connect")));
}
......@@ -41,7 +43,7 @@ ConnectDialog::~ConnectDialog()
ServerInfo ConnectDialog::serverInfo() const
{
ServerInfo info;
info.setUrl(QUrl(ui->serverUrl->text()));
info.setUrl(QUrl(ui->serverUrl->currentText()));
info.setUserName(ui->userName->text());
info.setPassword(ui->password->text());
return info;
......@@ -49,7 +51,19 @@ ServerInfo ConnectDialog::serverInfo() const
void ConnectDialog::setServerInfo(const ServerInfo& serverInfo)
{
ui->serverUrl->setText(serverInfo.url().toString());
ui->serverUrl->setCurrentText(serverInfo.url().toString());
ui->userName->setText(serverInfo.userName());
ui->password->setText(serverInfo.password());
}
void ConnectDialog::addRecentServerInfos(const QStringList& serverInfoNames)
{
ui->serverUrl->addItems(serverInfoNames);
}
void ConnectDialog::serverSelected()
{
auto info = ServerInfo::load(ui->serverUrl->currentText());
if (!info.url().isEmpty())
setServerInfo(info);
}
......@@ -42,7 +42,11 @@ public:
ServerInfo serverInfo() const;
void setServerInfo(const ServerInfo &serverInfo);
void addRecentServerInfos(const QStringList &serverInfoNames);
private:
void serverSelected();
std::unique_ptr<Ui::ConnectDialog> ui;
};
......
......@@ -26,10 +26,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="serverUrl"/>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&amp;User name:</string>
......@@ -39,10 +36,10 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QLineEdit" name="userName"/>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>P&amp;assword:</string>
......@@ -52,13 +49,29 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="serverUrl">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::InsertAlphabetically</enum>
</property>
</widget>
</item>
</layout>
</item>
<item>
......
......@@ -83,11 +83,17 @@ MainWindow::MainWindow() :
QSettings settings;
auto info = ServerInfo::load(settings.value(QStringLiteral("LastServerInfo")).toString());
ConnectDialog dlg(this);
auto recents = settings.value(QStringLiteral("RecentServerInfos")).toStringList();
dlg.addRecentServerInfos(recents);
dlg.setServerInfo(info);
if (dlg.exec()) {
info = dlg.serverInfo();
info.save();
settings.setValue(QStringLiteral("LastServerInfo"), info.url().toString());
if (!recents.contains(info.url().toString())) {
recents.push_back(info.url().toString());
settings.setValue(QStringLiteral("RecentServerInfos"), recents);
}
connectToServer(info);
}
});
......
Supports Markdown
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