citra/src/citra_qt/multiplayer/client_room.cpp
zhupengfei 8b8b39ec0e
citra_qt/multiplayer: Add user ping support
The user would be notified if the message contains "@" followed by the user's nickname or forum username. An alert would be shown, and the icon and message in the status bar would be changed. All notification is only shown if the chat window currently does not have focus.

Also added a connected_notification icon for showing in the status bar.
2018-12-15 11:03:35 +08:00

109 lines
3.8 KiB
C++

// Copyright 2017 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <future>
#include <QColor>
#include <QImage>
#include <QList>
#include <QLocale>
#include <QMetaType>
#include <QTime>
#include <QtConcurrent/QtConcurrentRun>
#include "citra_qt/game_list_p.h"
#include "citra_qt/multiplayer/client_room.h"
#include "citra_qt/multiplayer/message.h"
#include "citra_qt/multiplayer/moderation_dialog.h"
#include "citra_qt/multiplayer/state.h"
#include "common/logging/log.h"
#include "core/announce_multiplayer_session.h"
#include "ui_client_room.h"
ClientRoomWindow::ClientRoomWindow(QWidget* parent)
: QDialog(parent, Qt::WindowTitleHint | Qt::WindowCloseButtonHint | Qt::WindowSystemMenuHint),
ui(std::make_unique<Ui::ClientRoom>()) {
ui->setupUi(this);
// setup the callbacks for network updates
if (auto member = Network::GetRoomMember().lock()) {
member->BindOnRoomInformationChanged(
[this](const Network::RoomInformation& info) { emit RoomInformationChanged(info); });
member->BindOnStateChanged(
[this](const Network::RoomMember::State& state) { emit StateChanged(state); });
connect(this, &ClientRoomWindow::RoomInformationChanged, this,
&ClientRoomWindow::OnRoomUpdate);
connect(this, &ClientRoomWindow::StateChanged, this, &::ClientRoomWindow::OnStateChange);
// Update the state
OnStateChange(member->GetState());
} else {
// TODO (jroweboy) network was not initialized?
}
connect(ui->disconnect, &QPushButton::pressed, [this] { Disconnect(); });
ui->disconnect->setDefault(false);
ui->disconnect->setAutoDefault(false);
connect(ui->moderation, &QPushButton::clicked, [this] {
ModerationDialog dialog(this);
dialog.exec();
});
ui->moderation->setDefault(false);
ui->moderation->setAutoDefault(false);
connect(ui->chat, &ChatRoom::UserPinged, this, &ClientRoomWindow::ShowNotification);
UpdateView();
}
ClientRoomWindow::~ClientRoomWindow() = default;
void ClientRoomWindow::SetModPerms(bool is_mod) {
ui->chat->SetModPerms(is_mod);
ui->moderation->setVisible(is_mod);
ui->moderation->setDefault(false);
ui->moderation->setAutoDefault(false);
}
void ClientRoomWindow::RetranslateUi() {
ui->retranslateUi(this);
ui->chat->RetranslateUi();
}
void ClientRoomWindow::OnRoomUpdate(const Network::RoomInformation& info) {
UpdateView();
}
void ClientRoomWindow::OnStateChange(const Network::RoomMember::State& state) {
if (state == Network::RoomMember::State::Joined) {
ui->chat->Clear();
ui->chat->AppendStatusMessage(tr("Connected"));
}
UpdateView();
}
void ClientRoomWindow::Disconnect() {
auto parent = static_cast<MultiplayerState*>(parentWidget());
if (parent->OnCloseRoom()) {
ui->chat->AppendStatusMessage(tr("Disconnected"));
close();
}
}
void ClientRoomWindow::UpdateView() {
if (auto member = Network::GetRoomMember().lock()) {
if (member->IsConnected()) {
ui->chat->Enable();
ui->disconnect->setEnabled(true);
auto memberlist = member->GetMemberInformation();
ui->chat->SetPlayerList(memberlist);
const auto information = member->GetRoomInformation();
setWindowTitle(QString(tr("%1 (%2/%3 members) - connected"))
.arg(QString::fromStdString(information.name))
.arg(memberlist.size())
.arg(information.member_slots));
ui->description->setText(QString::fromStdString(information.description));
return;
}
}
// TODO(B3N30): can't get RoomMember*, show error and close window
close();
}