mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	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
 | ||||
|         QString fixed_message = QString(" %1 ").arg(message); | ||||
|         if (fixed_message.contains(QString(" @%1 ").arg(cur_nickname)) || | ||||
|         QString fixed_message = QStringLiteral(" %1 ").arg(message); | ||||
|         if (fixed_message.contains(QStringLiteral(" @%1 ").arg(cur_nickname)) || | ||||
|             (!cur_username.isEmpty() && | ||||
|              fixed_message.contains(QString(" @%1 ").arg(cur_username)))) { | ||||
|              fixed_message.contains(QStringLiteral(" @%1 ").arg(cur_username)))) { | ||||
| 
 | ||||
|             contains_ping = true; | ||||
|         } else { | ||||
|  | @ -66,20 +66,20 @@ public: | |||
|         if (username.isEmpty() || username == nickname) { | ||||
|             name = nickname; | ||||
|         } else { | ||||
|             name = QString("%1 (%2)").arg(nickname, username); | ||||
|             name = QStringLiteral("%1 (%2)").arg(nickname, username); | ||||
|         } | ||||
| 
 | ||||
|         QString style, text_color; | ||||
|         if (ContainsPing()) { | ||||
|             // 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
 | ||||
|             text_color = "color='#000000'"; | ||||
|             text_color = QStringLiteral("color='#000000'"); | ||||
|         } | ||||
| 
 | ||||
|         return QString("[%1] <font color='%2'><%3></font> <font style='%4' " | ||||
|                        "%5>%6</font>") | ||||
|             .arg(timestamp, color, name.toHtmlEscaped(), style, text_color, | ||||
|         return QStringLiteral("[%1] <font color='%2'><%3></font> <font style='%4' " | ||||
|                               "%5>%6</font>") | ||||
|             .arg(timestamp, QString::fromStdString(color), name.toHtmlEscaped(), style, text_color, | ||||
|                  message.toHtmlEscaped()); | ||||
|     } | ||||
| 
 | ||||
|  | @ -106,7 +106,8 @@ public: | |||
|     } | ||||
| 
 | ||||
|     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: | ||||
|  | @ -146,9 +147,9 @@ public: | |||
|         if (username.isEmpty() || username == nickname) { | ||||
|             name = nickname; | ||||
|         } 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) { | ||||
|         name = QString::fromStdString(status_message.nickname); | ||||
|     } else { | ||||
|         name = QString("%1 (%2)").arg(QString::fromStdString(status_message.nickname), | ||||
|                                       QString::fromStdString(status_message.username)); | ||||
|         name = QStringLiteral("%1 (%2)").arg(QString::fromStdString(status_message.nickname), | ||||
|                                              QString::fromStdString(status_message.username)); | ||||
|     } | ||||
|     QString message; | ||||
|     switch (status_message.type) { | ||||
|  | @ -353,7 +354,8 @@ void ChatRoom::UpdateIconDisplay() { | |||
|         if (icon_cache.count(avatar_url)) { | ||||
|             item->setData(icon_cache.at(avatar_url), Qt::DecorationRole); | ||||
|         } 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)); | ||||
|             QFuture<std::string> future = QtConcurrent::run([url] { | ||||
|                 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); | ||||
|                 if (result.returned_data.empty()) { | ||||
|                     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")); | ||||
|         connect(view_profile_action, &QAction::triggered, [username] { | ||||
|             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() { | ||||
|     bool ok; | ||||
|     const QString text = QInputDialog::getText(this, tr("Password Required to Join"), | ||||
|                                                tr("Password:"), QLineEdit::Password, "", &ok); | ||||
|     const QString text = | ||||
|         QInputDialog::getText(this, tr("Password Required to Join"), tr("Password:"), | ||||
|                               QLineEdit::Password, QString(), &ok); | ||||
|     return ok ? text : QString(); | ||||
| } | ||||
| 
 | ||||
|  | @ -181,7 +182,7 @@ void Lobby::OnJoinRoom(const QModelIndex& source) { | |||
| void Lobby::ResetModel() { | ||||
|     model->clear(); | ||||
|     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::GAME_NAME, Qt::Horizontal, tr("Preferred Game"), Qt::DisplayRole); | ||||
|     model->setHeaderData(Column::HOST, Qt::Horizontal, tr("Host"), Qt::DisplayRole); | ||||
|  |  | |||
|  | @ -42,7 +42,7 @@ public: | |||
|     QVariant data(int role) const override { | ||||
|         if (role == Qt::DecorationRole) { | ||||
|             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) { | ||||
|             return LobbyItem::data(role); | ||||
|  | @ -69,7 +69,7 @@ public: | |||
|             return LobbyItem::data(role); | ||||
|         } | ||||
|         auto description = data(DescriptionRole).toString(); | ||||
|         description.prepend("Description: "); | ||||
|         description.prepend(QStringLiteral("Description: ")); | ||||
|         return description; | ||||
|     } | ||||
| 
 | ||||
|  | @ -157,7 +157,7 @@ public: | |||
|         if (username.isEmpty() || username == nickname) { | ||||
|             return nickname; | ||||
|         } else { | ||||
|             return QString("%1 (%2)").arg(nickname, username); | ||||
|             return QStringLiteral("%1 (%2)").arg(nickname, username); | ||||
|         } | ||||
|     } | ||||
|     u64 GetTitleId() const { | ||||
|  | @ -192,8 +192,8 @@ public: | |||
|             return LobbyItem::data(role); | ||||
|         } | ||||
|         auto members = data(MemberListRole).toList(); | ||||
|         return QString("%1 / %2").arg(QString::number(members.size()), | ||||
|                                       data(MaxPlayerRole).toString()); | ||||
|         return QStringLiteral("%1 / %2").arg(QString::number(members.size()), | ||||
|                                              data(MaxPlayerRole).toString()); | ||||
|     } | ||||
| 
 | ||||
|     bool operator<(const QStandardItem& other) const override { | ||||
|  | @ -225,7 +225,7 @@ public: | |||
|         bool first = true; | ||||
|         for (const auto& member : members) { | ||||
|             if (!first) | ||||
|                 out += '\n'; | ||||
|                 out.append(QStringLiteral("\n")); | ||||
|             const auto& m = member.value<LobbyMember>(); | ||||
|             if (m.GetGameName().isEmpty()) { | ||||
|                 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_text->setToolTip(tr("Current connection status")); | ||||
|     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_icon, &ClickableLabel::clicked, this, &MultiplayerState::OnOpenNetworkRoom); | ||||
|  | @ -113,12 +113,12 @@ void MultiplayerState::OnNetworkStateChanged(const Network::RoomMember::State& s | |||
|         state == Network::RoomMember::State::Moderator) { | ||||
| 
 | ||||
|         OnOpenNetworkRoom(); | ||||
|         status_icon->setPixmap(QIcon::fromTheme("connected").pixmap(16)); | ||||
|         status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected")).pixmap(16)); | ||||
|         status_text->setText(tr("Connected")); | ||||
|         leave_room->setEnabled(true); | ||||
|         show_room->setEnabled(true); | ||||
|     } else { | ||||
|         status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16)); | ||||
|         status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("disconnected")).pixmap(16)); | ||||
|         status_text->setText(tr("Not Connected")); | ||||
|         leave_room->setEnabled(false); | ||||
|         show_room->setEnabled(false); | ||||
|  | @ -183,13 +183,14 @@ void MultiplayerState::OnAnnounceFailed(const Common::WebResult& result) { | |||
| 
 | ||||
| void MultiplayerState::UpdateThemedIcons() { | ||||
|     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 || | ||||
|                current_state == Network::RoomMember::State::Moderator) { | ||||
| 
 | ||||
|         status_icon->setPixmap(QIcon::fromTheme("connected").pixmap(16)); | ||||
|         status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("connected")).pixmap(16)); | ||||
|     } else { | ||||
|         status_icon->setPixmap(QIcon::fromTheme("disconnected").pixmap(16)); | ||||
|         status_icon->setPixmap(QIcon::fromTheme(QStringLiteral("disconnected")).pixmap(16)); | ||||
|     } | ||||
|     if (client_room) | ||||
|         client_room->UpdateIconDisplay(); | ||||
|  | @ -245,13 +246,13 @@ void MultiplayerState::ShowNotification() { | |||
|         return; // Do not show notification if the chat window currently has focus
 | ||||
|     show_notification = true; | ||||
|     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")); | ||||
| } | ||||
| 
 | ||||
| void MultiplayerState::HideNotification() { | ||||
|     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")); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,6 +5,7 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <QRegExp> | ||||
| #include <QString> | ||||
| #include <QValidator> | ||||
| 
 | ||||
| class Validation { | ||||
|  | @ -29,18 +30,18 @@ public: | |||
| 
 | ||||
| private: | ||||
|     /// 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; | ||||
| 
 | ||||
|     /// 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; | ||||
| 
 | ||||
|     /// ipv4 address only
 | ||||
|     // 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}|" | ||||
|         "2[0-4][0-9]|25[0-5])"); | ||||
|         "2[0-4][0-9]|25[0-5])")); | ||||
|     QRegExpValidator ip; | ||||
| 
 | ||||
|     /// port must be between 0 and 65535
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue