Skip to content

Commit

Permalink
RMG: add refresh button to NetplaySessionBrowserDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosalie241 committed Dec 22, 2024
1 parent 82687d5 commit b6cbc52
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ NetplaySessionBrowserDialog::NetplaySessionBrowserDialog(QWidget *parent, QWebSo
joinButton->setText("Join");
joinButton->setEnabled(false);

// change restore defaults button name
QPushButton* refreshButton = this->buttonBox->button(QDialogButtonBox::RestoreDefaults);
refreshButton->setText("Refresh");
refreshButton->setIcon(QIcon());
refreshButton->setEnabled(false);

// set validator for nickname
QRegularExpression re(NETPLAYCOMMON_NICKNAME_REGEX);
this->nickNameLineEdit->setValidator(new QRegularExpressionValidator(re, this));
Expand Down Expand Up @@ -231,6 +237,15 @@ void NetplaySessionBrowserDialog::addSessionData(QString name, QString game, QSt

void NetplaySessionBrowserDialog::on_webSocket_connected(void)
{
if (!this->webSocket->isValid())
{
return;
}

// clear sessions from the table
this->tableWidget->model()->removeRows(0, this->tableWidget->rowCount());

// request session list from server
QJsonObject json;
json.insert("type", "request_get_rooms");
NetplayCommon::AddCommonJson(json);
Expand Down Expand Up @@ -317,13 +332,16 @@ void NetplaySessionBrowserDialog::on_networkAccessManager_Finished(QNetworkReply

void NetplaySessionBrowserDialog::on_serverComboBox_currentIndexChanged(int index)
{
QPushButton* refreshButton = this->buttonBox->button(QDialogButtonBox::RestoreDefaults);
refreshButton->setEnabled(index != -1);

if (index == -1)
{
return;
}

// clear sessions from the table
this->tableWidget->setRowCount(0);
this->tableWidget->model()->removeRows(0, this->tableWidget->rowCount());

QString address = this->serverComboBox->itemData(index).toString();
this->webSocket->open(QUrl(address));
Expand All @@ -339,6 +357,15 @@ void NetplaySessionBrowserDialog::on_nickNameLineEdit_textChanged()
this->validateJoinButton();
}

void NetplaySessionBrowserDialog::on_buttonBox_clicked(QAbstractButton* button)
{
// refresh session list when refresh button has been pressed
if (button == this->buttonBox->button(QDialogButtonBox::RestoreDefaults))
{
this->on_webSocket_connected();
}
}

void NetplaySessionBrowserDialog::accept()
{
if (!this->webSocket->isValid())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class NetplaySessionBrowserDialog : public QDialog, private Ui::NetplaySessionBr

void on_nickNameLineEdit_textChanged(void);

void on_buttonBox_clicked(QAbstractButton* button);

void accept(void) Q_DECL_OVERRIDE;

};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok|QDialogButtonBox::StandardButton::RestoreDefaults</set>
</property>
</widget>
</item>
Expand Down

0 comments on commit b6cbc52

Please sign in to comment.