mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-02 03:23:56 -07:00
Add option to remove saved sever (#5368)
* Add option to remove saved sever - Fix #4099 - Removes old method that didn't work
This commit is contained in:
parent
7679546e30
commit
bf63dc4ab7
2 changed files with 26 additions and 26 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
#include "dlg_connect.h"
|
#include "dlg_connect.h"
|
||||||
|
|
||||||
#include "../server/user/user_info_connection.h"
|
|
||||||
#include "../settings/cache_settings.h"
|
#include "../settings/cache_settings.h"
|
||||||
#include "../utility/macros.h"
|
|
||||||
#include "trice_limits.h"
|
#include "trice_limits.h"
|
||||||
|
|
||||||
#include <QCheckBox>
|
#include <QCheckBox>
|
||||||
|
|
@ -22,7 +20,13 @@ DlgConnect::DlgConnect(QWidget *parent) : QDialog(parent)
|
||||||
{
|
{
|
||||||
previousHostButton = new QRadioButton(tr("Known Hosts"), this);
|
previousHostButton = new QRadioButton(tr("Known Hosts"), this);
|
||||||
previousHosts = new QComboBox(this);
|
previousHosts = new QComboBox(this);
|
||||||
previousHosts->installEventFilter(new DeleteHighlightedItemWhenShiftDelPressedEventFilter);
|
|
||||||
|
btnDeleteServer = new QPushButton(this);
|
||||||
|
btnDeleteServer->setIcon(QPixmap("theme:icons/remove_row"));
|
||||||
|
btnDeleteServer->setToolTip(tr("Delete the currently selected saved server"));
|
||||||
|
btnDeleteServer->setFixedWidth(30);
|
||||||
|
|
||||||
|
connect(btnDeleteServer, &QPushButton::clicked, this, &DlgConnect::actRemoveSavedServer);
|
||||||
|
|
||||||
hps = new HandlePublicServers(this);
|
hps = new HandlePublicServers(this);
|
||||||
btnRefreshServers = new QPushButton(this);
|
btnRefreshServers = new QPushButton(this);
|
||||||
|
|
@ -111,6 +115,7 @@ DlgConnect::DlgConnect(QWidget *parent) : QDialog(parent)
|
||||||
|
|
||||||
newHolderLayout = new QHBoxLayout;
|
newHolderLayout = new QHBoxLayout;
|
||||||
newHolderLayout->addWidget(previousHosts);
|
newHolderLayout->addWidget(previousHosts);
|
||||||
|
newHolderLayout->addWidget(btnDeleteServer);
|
||||||
newHolderLayout->addWidget(btnRefreshServers);
|
newHolderLayout->addWidget(btnRefreshServers);
|
||||||
|
|
||||||
connectionLayout = new QGridLayout;
|
connectionLayout = new QGridLayout;
|
||||||
|
|
@ -255,6 +260,16 @@ void DlgConnect::updateDisplayInfo(const QString &saveName)
|
||||||
UserConnection_Information uci;
|
UserConnection_Information uci;
|
||||||
QStringList _data = uci.getServerInfo(saveName);
|
QStringList _data = uci.getServerInfo(saveName);
|
||||||
|
|
||||||
|
if (_data.isEmpty()) {
|
||||||
|
_data << ""
|
||||||
|
<< ""
|
||||||
|
<< ""
|
||||||
|
<< ""
|
||||||
|
<< ""
|
||||||
|
<< ""
|
||||||
|
<< "";
|
||||||
|
}
|
||||||
|
|
||||||
bool savePasswordStatus = (_data.at(5) == "1");
|
bool savePasswordStatus = (_data.at(5) == "1");
|
||||||
|
|
||||||
saveEdit->setText(_data.at(0));
|
saveEdit->setText(_data.at(0));
|
||||||
|
|
@ -345,21 +360,6 @@ QString DlgConnect::getHost() const
|
||||||
return hostEdit->text().trimmed();
|
return hostEdit->text().trimmed();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeleteHighlightedItemWhenShiftDelPressedEventFilter::eventFilter(QObject *obj, QEvent *event)
|
|
||||||
{
|
|
||||||
if (event->type() == QEvent::KeyPress) {
|
|
||||||
auto *keyEvent = dynamic_cast<QKeyEvent *>(event);
|
|
||||||
|
|
||||||
if (keyEvent->key() == Qt::Key_Delete) {
|
|
||||||
auto *combobox = reinterpret_cast<QComboBox *>(obj);
|
|
||||||
combobox->removeItem(combobox->currentIndex());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QObject::eventFilter(obj, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DlgConnect::actForgotPassword()
|
void DlgConnect::actForgotPassword()
|
||||||
{
|
{
|
||||||
ServersSettings &servers = SettingsCache::instance().servers();
|
ServersSettings &servers = SettingsCache::instance().servers();
|
||||||
|
|
@ -370,3 +370,9 @@ void DlgConnect::actForgotPassword()
|
||||||
emit sigStartForgotPasswordRequest();
|
emit sigStartForgotPasswordRequest();
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgConnect::actRemoveSavedServer()
|
||||||
|
{
|
||||||
|
SettingsCache::instance().servers().removeServer(hostEdit->text());
|
||||||
|
previousHosts->removeItem(previousHosts->currentIndex());
|
||||||
|
}
|
||||||
|
|
@ -18,13 +18,6 @@ class QPushButton;
|
||||||
class QRadioButton;
|
class QRadioButton;
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
|
|
||||||
class DeleteHighlightedItemWhenShiftDelPressedEventFilter : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
protected:
|
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
|
||||||
};
|
|
||||||
|
|
||||||
class DlgConnect : public QDialog
|
class DlgConnect : public QDialog
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
@ -59,6 +52,7 @@ private slots:
|
||||||
void previousHostSelected(bool state);
|
void previousHostSelected(bool state);
|
||||||
void newHostSelected(bool state);
|
void newHostSelected(bool state);
|
||||||
void actForgotPassword();
|
void actForgotPassword();
|
||||||
|
void actRemoveSavedServer();
|
||||||
void updateDisplayInfo(const QString &saveName);
|
void updateDisplayInfo(const QString &saveName);
|
||||||
void preRebuildComboBoxList();
|
void preRebuildComboBoxList();
|
||||||
void rebuildComboBoxList(int failure = -1);
|
void rebuildComboBoxList(int failure = -1);
|
||||||
|
|
@ -74,7 +68,7 @@ private:
|
||||||
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
|
QCheckBox *savePasswordCheckBox, *autoConnectCheckBox;
|
||||||
QComboBox *previousHosts;
|
QComboBox *previousHosts;
|
||||||
QRadioButton *newHostButton, *previousHostButton;
|
QRadioButton *newHostButton, *previousHostButton;
|
||||||
QPushButton *btnConnect, *btnForgotPassword, *btnRefreshServers;
|
QPushButton *btnConnect, *btnForgotPassword, *btnRefreshServers, *btnDeleteServer;
|
||||||
QMap<QString, std::pair<QString, UserConnection_Information>> savedHostList;
|
QMap<QString, std::pair<QString, UserConnection_Information>> savedHostList;
|
||||||
HandlePublicServers *hps;
|
HandlePublicServers *hps;
|
||||||
const QString placeHolderText = tr("Downloading...");
|
const QString placeHolderText = tr("Downloading...");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue