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, Lobby::Lobby(QWidget* parent, QStandardItemModel* list,
std::shared_ptr<Core::AnnounceMultiplayerSession> session) std::shared_ptr<Core::AnnounceMultiplayerSession> session)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint), : 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); ui->setupUi(this);
// setup the watcher for background connections // setup the watcher for background connections
watcher = new QFutureWatcher<void>; watcher = new QFutureWatcher<void>;
model = new QStandardItemModel(ui->room_list); 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 = new LobbyFilterProxyModel(this, game_list);
proxy->setSourceModel(model); proxy->setSourceModel(model);
proxy->setDynamicSortFilter(true); proxy->setDynamicSortFilter(true);
@ -114,20 +125,21 @@ void Lobby::OnJoinRoom(const QModelIndex& source) {
return; 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); QModelIndex connection_index = proxy->index(index.row(), Column::HOST);
const std::string nickname = ui->nickname->text().toStdString(); const std::string nickname = ui->nickname->text().toStdString();
const std::string ip = const std::string ip =
proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString(); proxy->data(connection_index, LobbyItemHost::HostIPRole).toString().toStdString();
int port = proxy->data(connection_index, LobbyItemHost::HostPortRole).toInt(); 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); room_member->Join(nickname, ip.c_str(), port, 0, Network::NoPreferredMac, password);
} }
}); });
watcher->setFuture(f); 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 // Save settings
UISettings::values.nickname = ui->nickname->text(); UISettings::values.nickname = ui->nickname->text();

View file

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