1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-28 10:38:45 +00:00
transmission/qt/SessionDialog.cc
Charles Kerr d70c8387b3
fixup! refactor: use qt5's connect api (#1491) (#2024)
* fixup! refactor: use qt5's connect api (#1491)

fix broken signal connection in session dialog
2021-10-23 22:28:16 -05:00

79 lines
2.4 KiB
C++

/*
* This file Copyright (C) 2009-2015 Mnemosyne LLC
*
* It may be used under the GNU GPL versions 2 or 3
* or any future license endorsed by Mnemosyne LLC.
*
*/
#include "Prefs.h"
#include "Session.h"
#include "SessionDialog.h"
/***
****
***/
void SessionDialog::accept()
{
prefs_.set(Prefs::SESSION_IS_REMOTE, ui_.remoteSessionRadio->isChecked());
prefs_.set(Prefs::SESSION_REMOTE_HOST, ui_.hostEdit->text());
prefs_.set(Prefs::SESSION_REMOTE_PORT, ui_.portSpin->value());
prefs_.set(Prefs::SESSION_REMOTE_AUTH, ui_.authCheck->isChecked());
prefs_.set(Prefs::SESSION_REMOTE_USERNAME, ui_.usernameEdit->text());
prefs_.set(Prefs::SESSION_REMOTE_PASSWORD, ui_.passwordEdit->text());
session_.restart();
BaseDialog::accept();
}
void SessionDialog::resensitize() const
{
bool const is_remote = ui_.remoteSessionRadio->isChecked();
bool const use_auth = ui_.authCheck->isChecked();
for (QWidget* const w : remote_widgets_)
{
w->setEnabled(is_remote);
}
for (QWidget* const w : auth_widgets_)
{
w->setEnabled(is_remote && use_auth);
}
}
/***
****
***/
SessionDialog::SessionDialog(Session& session, Prefs& prefs, QWidget* parent)
: BaseDialog(parent)
, session_(session)
, prefs_(prefs)
{
ui_.setupUi(this);
ui_.localSessionRadio->setChecked(!prefs.get<bool>(Prefs::SESSION_IS_REMOTE));
connect(ui_.localSessionRadio, &QAbstractButton::toggled, this, &SessionDialog::resensitize);
ui_.remoteSessionRadio->setChecked(prefs.get<bool>(Prefs::SESSION_IS_REMOTE));
connect(ui_.remoteSessionRadio, &QAbstractButton::toggled, this, &SessionDialog::resensitize);
ui_.hostEdit->setText(prefs.get<QString>(Prefs::SESSION_REMOTE_HOST));
remote_widgets_ << ui_.hostLabel << ui_.hostEdit;
ui_.portSpin->setValue(prefs.get<int>(Prefs::SESSION_REMOTE_PORT));
remote_widgets_ << ui_.portLabel << ui_.portSpin;
ui_.authCheck->setChecked(prefs.get<bool>(Prefs::SESSION_REMOTE_AUTH));
connect(ui_.authCheck, &QAbstractButton::toggled, this, &SessionDialog::resensitize);
remote_widgets_ << ui_.authCheck;
ui_.usernameEdit->setText(prefs.get<QString>(Prefs::SESSION_REMOTE_USERNAME));
auth_widgets_ << ui_.usernameLabel << ui_.usernameEdit;
ui_.passwordEdit->setText(prefs.get<QString>(Prefs::SESSION_REMOTE_PASSWORD));
auth_widgets_ << ui_.passwordLabel << ui_.passwordEdit;
resensitize();
}