From bf63dc4ab7e0f9fce66650f953853b748b5ab113 Mon Sep 17 00:00:00 2001 From: Zach H Date: Sat, 28 Dec 2024 19:37:49 -0500 Subject: [PATCH] Add option to remove saved sever (#5368) * Add option to remove saved sever - Fix #4099 - Removes old method that didn't work --- cockatrice/src/dialogs/dlg_connect.cpp | 42 +++++++++++++++----------- cockatrice/src/dialogs/dlg_connect.h | 10 ++---- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/cockatrice/src/dialogs/dlg_connect.cpp b/cockatrice/src/dialogs/dlg_connect.cpp index 8c85d365c..2fa2478df 100644 --- a/cockatrice/src/dialogs/dlg_connect.cpp +++ b/cockatrice/src/dialogs/dlg_connect.cpp @@ -1,8 +1,6 @@ #include "dlg_connect.h" -#include "../server/user/user_info_connection.h" #include "../settings/cache_settings.h" -#include "../utility/macros.h" #include "trice_limits.h" #include @@ -22,7 +20,13 @@ DlgConnect::DlgConnect(QWidget *parent) : QDialog(parent) { previousHostButton = new QRadioButton(tr("Known Hosts"), 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); btnRefreshServers = new QPushButton(this); @@ -111,6 +115,7 @@ DlgConnect::DlgConnect(QWidget *parent) : QDialog(parent) newHolderLayout = new QHBoxLayout; newHolderLayout->addWidget(previousHosts); + newHolderLayout->addWidget(btnDeleteServer); newHolderLayout->addWidget(btnRefreshServers); connectionLayout = new QGridLayout; @@ -255,6 +260,16 @@ void DlgConnect::updateDisplayInfo(const QString &saveName) UserConnection_Information uci; QStringList _data = uci.getServerInfo(saveName); + if (_data.isEmpty()) { + _data << "" + << "" + << "" + << "" + << "" + << "" + << ""; + } + bool savePasswordStatus = (_data.at(5) == "1"); saveEdit->setText(_data.at(0)); @@ -345,21 +360,6 @@ QString DlgConnect::getHost() const return hostEdit->text().trimmed(); } -bool DeleteHighlightedItemWhenShiftDelPressedEventFilter::eventFilter(QObject *obj, QEvent *event) -{ - if (event->type() == QEvent::KeyPress) { - auto *keyEvent = dynamic_cast(event); - - if (keyEvent->key() == Qt::Key_Delete) { - auto *combobox = reinterpret_cast(obj); - combobox->removeItem(combobox->currentIndex()); - return true; - } - } - - return QObject::eventFilter(obj, event); -} - void DlgConnect::actForgotPassword() { ServersSettings &servers = SettingsCache::instance().servers(); @@ -369,4 +369,10 @@ void DlgConnect::actForgotPassword() emit sigStartForgotPasswordRequest(); reject(); +} + +void DlgConnect::actRemoveSavedServer() +{ + SettingsCache::instance().servers().removeServer(hostEdit->text()); + previousHosts->removeItem(previousHosts->currentIndex()); } \ No newline at end of file diff --git a/cockatrice/src/dialogs/dlg_connect.h b/cockatrice/src/dialogs/dlg_connect.h index fe64bc82f..119e3b816 100644 --- a/cockatrice/src/dialogs/dlg_connect.h +++ b/cockatrice/src/dialogs/dlg_connect.h @@ -18,13 +18,6 @@ class QPushButton; class QRadioButton; class QVBoxLayout; -class DeleteHighlightedItemWhenShiftDelPressedEventFilter : public QObject -{ - Q_OBJECT -protected: - bool eventFilter(QObject *obj, QEvent *event) override; -}; - class DlgConnect : public QDialog { Q_OBJECT @@ -59,6 +52,7 @@ private slots: void previousHostSelected(bool state); void newHostSelected(bool state); void actForgotPassword(); + void actRemoveSavedServer(); void updateDisplayInfo(const QString &saveName); void preRebuildComboBoxList(); void rebuildComboBoxList(int failure = -1); @@ -74,7 +68,7 @@ private: QCheckBox *savePasswordCheckBox, *autoConnectCheckBox; QComboBox *previousHosts; QRadioButton *newHostButton, *previousHostButton; - QPushButton *btnConnect, *btnForgotPassword, *btnRefreshServers; + QPushButton *btnConnect, *btnForgotPassword, *btnRefreshServers, *btnDeleteServer; QMap> savedHostList; HandlePublicServers *hps; const QString placeHolderText = tr("Downloading...");