Merge pull request #4183 from zhaowenlan1779/multiplayer-ui

citra_qt/multiplayer: three minor fixes
This commit is contained in:
Pengfei Zhu 2018-09-24 13:20:32 +08:00 committed by GitHub
commit d6a9b01624
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 13 deletions

View File

@ -21,13 +21,24 @@
Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
std::shared_ptr<Core::AnnounceMultiplayerSession> session)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
ui(std::make_unique<Ui::Lobby>()), announce_multiplayer_session(session), game_list(list) {
ui(std::make_unique<Ui::Lobby>()), announce_multiplayer_session(session) {
ui->setupUi(this);
// setup the watcher for background connections
watcher = new QFutureWatcher<void>;
model = new QStandardItemModel(ui->room_list);
// Create a proxy to the game list to get the list of games owned
game_list = new QStandardItemModel;
for (int i = 0; i < list->rowCount(); i++) {
auto parent = list->item(i, 0);
for (int j = 0; j < parent->rowCount(); j++) {
game_list->appendRow(parent->child(j)->clone());
}
}
proxy = new LobbyFilterProxyModel(this, game_list);
proxy->setSourceModel(model);
proxy->setDynamicSortFilter(true);
@ -114,20 +125,21 @@ void Lobby::OnJoinRoom(const QModelIndex& source) {
return;
}
// attempt to connect in a different thread
QFuture<void> f = QtConcurrent::run([&, password] {
if (auto room_member = Network::GetRoomMember().lock()) {
QModelIndex connection_index = proxy->index(index.row(), Column::HOST);
const std::string nickname = ui->nickname->text().toStdString();
const std::string ip =
proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString();
int port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toInt();
// attempt to connect in a different thread
QFuture<void> f = QtConcurrent::run([nickname, ip, port, password] {
if (auto room_member = Network::GetRoomMember().lock()) {
room_member->Join(nickname, ip.c_str(), port, 0, Network::NoPreferredMac, password);
}
});
watcher->setFuture(f);
// and disable widgets and display a connecting while we wait
QModelIndex connection_index = proxy->index(index.row(), Column::HOST);
// TODO(jroweboy): disable widgets and display a connecting while we wait
// Save settings
UISettings::values.nickname = ui->nickname->text();

View File

@ -28,12 +28,12 @@ public:
}
private:
/// room name can be alphanumeric and " " "_" "." and "-"
QRegExp room_name_regex = QRegExp("^[a-zA-Z0-9._- ]+$");
/// room name can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
QRegExp room_name_regex = QRegExp("^[a-zA-Z0-9._- ]{4,20}$");
QRegExpValidator room_name;
/// nickname can be alphanumeric and " " "_" "." and "-"
QRegExp nickname_regex = QRegExp("^[a-zA-Z0-9._- ]+$");
/// nickname can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
QRegExp nickname_regex = QRegExp("^[a-zA-Z0-9._- ]{4,20}$");
QRegExpValidator nickname;
/// ipv4 address only