citra_qt/multiplayer: Specify string conversions explicitly
This commit is contained in:
parent
ff931590b0
commit
8f29ab3ceb
5 changed files with 43 additions and 38 deletions
|
@ -44,10 +44,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle pings at the beginning and end of message
|
// Handle pings at the beginning and end of message
|
||||||
QString fixed_message = QString(" %1 ").arg(message);
|
QString fixed_message = QStringLiteral(" %1 ").arg(message);
|
||||||
if (fixed_message.contains(QString(" @%1 ").arg(cur_nickname)) ||
|
if (fixed_message.contains(QStringLiteral(" @%1 ").arg(cur_nickname)) ||
|
||||||
(!cur_username.isEmpty() &&
|
(!cur_username.isEmpty() &&
|
||||||
fixed_message.contains(QString(" @%1 ").arg(cur_username)))) {
|
fixed_message.contains(QStringLiteral(" @%1 ").arg(cur_username)))) {
|
||||||
|
|
||||||
contains_ping = true;
|
contains_ping = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -66,20 +66,20 @@ public:
|
||||||
if (username.isEmpty() || username == nickname) {
|
if (username.isEmpty() || username == nickname) {
|
||||||
name = nickname;
|
name = nickname;
|
||||||
} else {
|
} else {
|
||||||
name = QString("%1 (%2)").arg(nickname, username);
|
name = QStringLiteral("%1 (%2)").arg(nickname, username);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString style, text_color;
|
QString style, text_color;
|
||||||
if (ContainsPing()) {
|
if (ContainsPing()) {
|
||||||
// Add a background color to these messages
|
// Add a background color to these messages
|
||||||
style = QString("background-color: %1").arg(ping_color);
|
style = QStringLiteral("background-color: %1").arg(QString::fromStdString(ping_color));
|
||||||
// Add a font color
|
// Add a font color
|
||||||
text_color = "color='#000000'";
|
text_color = QStringLiteral("color='#000000'");
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString("[%1] <font color='%2'><%3></font> <font style='%4' "
|
return QStringLiteral("[%1] <font color='%2'><%3></font> <font style='%4' "
|
||||||
"%5>%6</font>")
|
"%5>%6</font>")
|
||||||
.arg(timestamp, color, name.toHtmlEscaped(), style, text_color,
|
.arg(timestamp, QString::fromStdString(color), name.toHtmlEscaped(), style, text_color,
|
||||||
message.toHtmlEscaped());
|
message.toHtmlEscaped());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GetSystemChatMessage() const {
|
QString GetSystemChatMessage() const {
|
||||||
return QString("[%1] <font color='%2'>* %3</font>").arg(timestamp, system_color, message);
|
return QStringLiteral("[%1] <font color='%2'>* %3</font>")
|
||||||
|
.arg(timestamp, QString::fromStdString(system_color), message);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -146,9 +147,9 @@ public:
|
||||||
if (username.isEmpty() || username == nickname) {
|
if (username.isEmpty() || username == nickname) {
|
||||||
name = nickname;
|
name = nickname;
|
||||||
} else {
|
} else {
|
||||||
name = QString("%1 (%2)").arg(nickname, username);
|
name = QStringLiteral("%1 (%2)").arg(nickname, username);
|
||||||
}
|
}
|
||||||
return QString("%1\n %2").arg(name, data(GameNameRole).toString());
|
return QStringLiteral("%1\n %2").arg(name, data(GameNameRole).toString());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -288,8 +289,8 @@ void ChatRoom::OnStatusMessageReceive(const Network::StatusMessageEntry& status_
|
||||||
if (status_message.username.empty() || status_message.username == status_message.nickname) {
|
if (status_message.username.empty() || status_message.username == status_message.nickname) {
|
||||||
name = QString::fromStdString(status_message.nickname);
|
name = QString::fromStdString(status_message.nickname);
|
||||||
} else {
|
} else {
|
||||||
name = QString("%1 (%2)").arg(QString::fromStdString(status_message.nickname),
|
name = QStringLiteral("%1 (%2)").arg(QString::fromStdString(status_message.nickname),
|
||||||
QString::fromStdString(status_message.username));
|
QString::fromStdString(status_message.username));
|
||||||
}
|
}
|
||||||
QString message;
|
QString message;
|
||||||
switch (status_message.type) {
|
switch (status_message.type) {
|
||||||
|
@ -353,7 +354,8 @@ void ChatRoom::UpdateIconDisplay() {
|
||||||
if (icon_cache.count(avatar_url)) {
|
if (icon_cache.count(avatar_url)) {
|
||||||
item->setData(icon_cache.at(avatar_url), Qt::DecorationRole);
|
item->setData(icon_cache.at(avatar_url), Qt::DecorationRole);
|
||||||
} else {
|
} else {
|
||||||
item->setData(QIcon::fromTheme("no_avatar").pixmap(48), Qt::DecorationRole);
|
item->setData(QIcon::fromTheme(QStringLiteral("no_avatar")).pixmap(48),
|
||||||
|
Qt::DecorationRole);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,7 +375,7 @@ void ChatRoom::SetPlayerList(const Network::RoomMember::MemberList& member_list)
|
||||||
const QUrl url(QString::fromStdString(member.avatar_url));
|
const QUrl url(QString::fromStdString(member.avatar_url));
|
||||||
QFuture<std::string> future = QtConcurrent::run([url] {
|
QFuture<std::string> future = QtConcurrent::run([url] {
|
||||||
WebService::Client client(
|
WebService::Client client(
|
||||||
QString("%1://%2").arg(url.scheme(), url.host()).toStdString(), "", "");
|
QStringLiteral("%1://%2").arg(url.scheme(), url.host()).toStdString(), "", "");
|
||||||
auto result = client.GetImage(url.path().toStdString(), true);
|
auto result = client.GetImage(url.path().toStdString(), true);
|
||||||
if (result.returned_data.empty()) {
|
if (result.returned_data.empty()) {
|
||||||
LOG_ERROR(WebService, "Failed to get avatar");
|
LOG_ERROR(WebService, "Failed to get avatar");
|
||||||
|
@ -426,7 +428,7 @@ void ChatRoom::PopupContextMenu(const QPoint& menu_location) {
|
||||||
QAction* view_profile_action = context_menu.addAction(tr("View Profile"));
|
QAction* view_profile_action = context_menu.addAction(tr("View Profile"));
|
||||||
connect(view_profile_action, &QAction::triggered, [username] {
|
connect(view_profile_action, &QAction::triggered, [username] {
|
||||||
QDesktopServices::openUrl(
|
QDesktopServices::openUrl(
|
||||||
QUrl(QString("https://community.citra-emu.org/u/%1").arg(username)));
|
QUrl(QStringLiteral("https://community.citra-emu.org/u/%1").arg(username)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,8 +99,9 @@ void Lobby::RetranslateUi() {
|
||||||
|
|
||||||
QString Lobby::PasswordPrompt() {
|
QString Lobby::PasswordPrompt() {
|
||||||
bool ok;
|
bool ok;
|
||||||
const QString text = QInputDialog::getText(this, tr("Password Required to Join"),
|
const QString text =
|
||||||
tr("Password:"), QLineEdit::Password, "", &ok);
|
QInputDialog::getText(this, tr("Password Required to Join"), tr("Password:"),
|
||||||
|
QLineEdit::Password, QString(), &ok);
|
||||||
return ok ? text : QString();
|
return ok ? text : QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +182,7 @@ void Lobby::OnJoinRoom(const QModelIndex& source) {
|
||||||
void Lobby::ResetModel() {
|
void Lobby::ResetModel() {
|
||||||
model->clear();
|
model->clear();
|
||||||
model->insertColumns(0, Column::TOTAL);
|
model->insertColumns(0, Column::TOTAL);
|
||||||
model->setHeaderData(Column::EXPAND, Qt::Horizontal, "", Qt::DisplayRole);
|
model->setHeaderData(Column::EXPAND, Qt::Horizontal, QString(), Qt::DisplayRole);
|
||||||
model->setHeaderData(Column::ROOM_NAME, Qt::Horizontal, tr("Room Name"), Qt::DisplayRole);
|
model->setHeaderData(Column::ROOM_NAME, Qt::Horizontal, tr("Room Name"), Qt::DisplayRole);
|
||||||
model->setHeaderData(Column::GAME_NAME, Qt::Horizontal, tr("Preferred Game"), Qt::DisplayRole);
|
model->setHeaderData(Column::GAME_NAME, Qt::Horizontal, tr("Preferred Game"), Qt::DisplayRole);
|
||||||
model->setHeaderData(Column::HOST, Qt::Horizontal, tr("Host"), Qt::DisplayRole);
|
model->setHeaderData(Column::HOST, Qt::Horizontal, tr("Host"), Qt::DisplayRole);
|
||||||
|
|
|
@ -42,7 +42,7 @@ public:
|
||||||
QVariant data(int role) const override {
|
QVariant data(int role) const override {
|
||||||
if (role == Qt::DecorationRole) {
|
if (role == Qt::DecorationRole) {
|
||||||
bool has_password = data(PasswordRole).toBool();
|
bool has_password = data(PasswordRole).toBool();
|
||||||
return has_password ? QIcon::fromTheme("lock").pixmap(16) : QIcon();
|
return has_password ? QIcon::fromTheme(QStringLiteral("lock")).pixmap(16) : QIcon();
|
||||||
}
|
}
|
||||||
if (role != Qt::DisplayRole) {
|
if (role != Qt::DisplayRole) {
|
||||||
return LobbyItem::data(role);
|
return LobbyItem::data(role);
|
||||||
|
@ -69,7 +69,7 @@ public:
|
||||||
return LobbyItem::data(role);
|
return LobbyItem::data(role);
|
||||||
}
|
}
|
||||||
auto description = data(DescriptionRole).toString();
|
auto description = data(DescriptionRole).toString();
|
||||||
description.prepend("Description: ");
|
description.prepend(QStringLiteral("Description: "));
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ public:
|
||||||
if (username.isEmpty() || username == nickname) {
|
if (username.isEmpty() || username == nickname) {
|
||||||
return nickname;
|
return nickname;
|
||||||
} else {
|
} else {
|
||||||
return QString("%1 (%2)").arg(nickname, username);
|
return QStringLiteral("%1 (%2)").arg(nickname, username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
u64 GetTitleId() const {
|
u64 GetTitleId() const {
|
||||||
|
@ -192,8 +192,8 @@ public:
|
||||||
return LobbyItem::data(role);
|
return LobbyItem::data(role);
|
||||||
}
|
}
|
||||||
auto members = data(MemberListRole).toList();
|
auto members = data(MemberListRole).toList();
|
||||||
return QString("%1 / %2").arg(QString::number(members.size()),
|
return QStringLiteral("%1 / %2").arg(QString::number(members.size()),
|
||||||
data(MaxPlayerRole).toString());
|
data(MaxPlayerRole).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator<(const QStandardItem& other) const override {
|
bool operator<(const QStandardItem& other) const override {
|
||||||
|
@ -225,7 +225,7 @@ public:
|
||||||
bool first = true;
|
bool first = true;
|
||||||
for (const auto& member : members) {
|
for (const auto& member : members) {
|
||||||
if (!first)
|
if (!first)
|
||||||
out += '\n';
|
out.append(QStringLiteral("\n"));
|
||||||
const auto& m = member.value<LobbyMember>();
|
const auto& m = member.value<LobbyMember>();
|
||||||
if (m.GetGameName().isEmpty()) {
|
if (m.GetGameName().isEmpty()) {
|
||||||
out += QString(QObject::tr("%1 is not playing a game")).arg(m.GetName());
|
out += QString(QObject::tr("%1 is not playing a game")).arg(m.GetName());
|
||||||
|
|
|
@ -46,7 +46,7 @@ MultiplayerState::MultiplayerState(QWidget* parent, QStandardItemModel* game_lis
|
||||||
status_icon = new ClickableLabel(this);
|
status_icon = new ClickableLabel(this);
|
||||||
status_text->setToolTip(tr("Current connection status"));
|
status_text->setToolTip(tr("Current connection status"));
|
||||||
status_text->setText(tr("Not Connected. Click here to find a room!"));
|
status_text->setText(tr("Not Connected. Click here to find a room!"));
|
||||||
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("disconnected")).pixmap(16));
|
||||||
|
|
||||||
connect(status_text, &ClickableLabel::clicked, this, &MultiplayerState::OnOpenNetworkRoom);
|
connect(status_text, &ClickableLabel::clicked, this, &MultiplayerState::OnOpenNetworkRoom);
|
||||||
connect(status_icon, &ClickableLabel::clicked, this, &MultiplayerState::OnOpenNetworkRoom);
|
connect(status_icon, &ClickableLabel::clicked, this, &MultiplayerState::OnOpenNetworkRoom);
|
||||||
|
@ -113,12 +113,12 @@ void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& s
|
||||||
state == Network::RoomMember::State::Moderator) {
|
state == Network::RoomMember::State::Moderator) {
|
||||||
|
|
||||||
OnOpenNetworkRoom();
|
OnOpenNetworkRoom();
|
||||||
status_icon->setPixmap(QIcon::fromTheme("connected").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected")).pixmap(16));
|
||||||
status_text->setText(tr("Connected"));
|
status_text->setText(tr("Connected"));
|
||||||
leave_room->setEnabled(true);
|
leave_room->setEnabled(true);
|
||||||
show_room->setEnabled(true);
|
show_room->setEnabled(true);
|
||||||
} else {
|
} else {
|
||||||
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("disconnected")).pixmap(16));
|
||||||
status_text->setText(tr("Not Connected"));
|
status_text->setText(tr("Not Connected"));
|
||||||
leave_room->setEnabled(false);
|
leave_room->setEnabled(false);
|
||||||
show_room->setEnabled(false);
|
show_room->setEnabled(false);
|
||||||
|
@ -183,13 +183,14 @@ void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) {
|
||||||
|
|
||||||
void MultiplayerState::UpdateThemedIcons() {
|
void MultiplayerState::UpdateThemedIcons() {
|
||||||
if (show_notification) {
|
if (show_notification) {
|
||||||
status_icon->setPixmap(QIcon::fromTheme("connected_notification").pixmap(16));
|
status_icon->setPixmap(
|
||||||
|
QIcon::fromTheme(QStringLiteral("connected_notification")).pixmap(16));
|
||||||
} else if (current_state == Network::RoomMember::State::Joined ||
|
} else if (current_state == Network::RoomMember::State::Joined ||
|
||||||
current_state == Network::RoomMember::State::Moderator) {
|
current_state == Network::RoomMember::State::Moderator) {
|
||||||
|
|
||||||
status_icon->setPixmap(QIcon::fromTheme("connected").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected")).pixmap(16));
|
||||||
} else {
|
} else {
|
||||||
status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("disconnected")).pixmap(16));
|
||||||
}
|
}
|
||||||
if (client_room)
|
if (client_room)
|
||||||
client_room->UpdateIconDisplay();
|
client_room->UpdateIconDisplay();
|
||||||
|
@ -245,13 +246,13 @@ void MultiplayerState::ShowNotification() {
|
||||||
return; // Do not show notification if the chat window currently has focus
|
return; // Do not show notification if the chat window currently has focus
|
||||||
show_notification = true;
|
show_notification = true;
|
||||||
QApplication::alert(nullptr);
|
QApplication::alert(nullptr);
|
||||||
status_icon->setPixmap(QIcon::fromTheme("connected_notification").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected_notification")).pixmap(16));
|
||||||
status_text->setText(tr("New Messages Received"));
|
status_text->setText(tr("New Messages Received"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiplayerState::HideNotification() {
|
void MultiplayerState::HideNotification() {
|
||||||
show_notification = false;
|
show_notification = false;
|
||||||
status_icon->setPixmap(QIcon::fromTheme("connected").pixmap(16));
|
status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected")).pixmap(16));
|
||||||
status_text->setText(tr("Connected"));
|
status_text->setText(tr("Connected"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
#include <QString>
|
||||||
#include <QValidator>
|
#include <QValidator>
|
||||||
|
|
||||||
class Validation {
|
class Validation {
|
||||||
|
@ -29,18 +30,18 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// room name can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
|
/// 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}$");
|
QRegExp room_name_regex = QRegExp(QStringLiteral("^[a-zA-Z0-9._- ]{4,20}$"));
|
||||||
QRegExpValidator room_name;
|
QRegExpValidator room_name;
|
||||||
|
|
||||||
/// nickname can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
|
/// nickname can be alphanumeric and " " "_" "." and "-" and must have a size of 4-20
|
||||||
QRegExp nickname_regex = QRegExp("^[a-zA-Z0-9._- ]{4,20}$");
|
QRegExp nickname_regex = QRegExp(QStringLiteral("^[a-zA-Z0-9._- ]{4,20}$"));
|
||||||
QRegExpValidator nickname;
|
QRegExpValidator nickname;
|
||||||
|
|
||||||
/// ipv4 address only
|
/// ipv4 address only
|
||||||
// TODO remove this when we support hostnames in direct connect
|
// TODO remove this when we support hostnames in direct connect
|
||||||
QRegExp ip_regex = QRegExp(
|
QRegExp ip_regex = QRegExp(QStringLiteral(
|
||||||
"(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|"
|
"(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|"
|
||||||
"2[0-4][0-9]|25[0-5])");
|
"2[0-4][0-9]|25[0-5])"));
|
||||||
QRegExpValidator ip;
|
QRegExpValidator ip;
|
||||||
|
|
||||||
/// port must be between 0 and 65535
|
/// port must be between 0 and 65535
|
||||||
|
|
Loading…
Reference in a new issue