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:
Zach H 2024-12-28 19:37:49 -05:00 committed by GitHub
parent 7679546e30
commit bf63dc4ab7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 26 deletions

View file

@ -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 <QCheckBox>
@ -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<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()
{
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());
}

View file

@ -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<QString, std::pair<QString, UserConnection_Information>> savedHostList;
HandlePublicServers *hps;
const QString placeHolderText = tr("Downloading...");