Debian Codegraph @

Source/Core/DolphinQt/Config/InfoWidget.cpp

raw symbols SCIP
1 // Copyright 2016 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #include "DolphinQt/Config/InfoWidget.h"
5
6 #include <QComboBox>
7 #include <QCryptographicHash>
8 #include <QDir>
9 #include <QFormLayout>
10 #include <QGroupBox>
11 #include <QLabel>
12 #include <QLineEdit>
13 #include <QPushButton>
14 #include <QTextEdit>
15
16 #include "Core/ConfigManager.h"
17
18 #include "DiscIO/Enums.h"
19 #include "DiscIO/Volume.h"
20 #include "DiscIO/WiiSaveBanner.h"
21
22 #include "DolphinQt/QtUtils/DolphinFileDialog.h"
23 #include "DolphinQt/QtUtils/ImageConverter.h"
24
25 #include "UICommon/UICommon.h"
26
27 InfoWidget::InfoWidget(const UICommon::GameFile& game) : m_game(game)
28 {
29 m_volume = DiscIO::CreateVolume(m_game.GetFilePath());
30
31 QVBoxLayout* layout = new QVBoxLayout();
32
33 layout->addWidget(CreateFileDetails());
34 layout->addWidget(CreateGameDetails());
35
36 if (!game.GetLanguages().empty())
37 layout->addWidget(CreateBannerDetails());
38
39 layout->addStretch(1);
40
41 setLayout(layout);
42 }
43
44 InfoWidget::~InfoWidget() = default;
45
46 QGroupBox* InfoWidget::CreateFileDetails()
47 {
48 QGroupBox* group = new QGroupBox(tr("File Details"));
49 QFormLayout* layout = new QFormLayout;
50
51 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
52
53 QString path = QDir::toNativeSeparators(QString::fromStdString(m_game.GetFilePath()));
54 layout->addRow(tr("Path:"), CreateValueDisplay(path));
55
56 const std::string file_size = UICommon::FormatSize(m_game.GetFileSize());
57
58 if (!m_game.ShouldShowFileFormatDetails())
59 {
60 layout->addRow(tr("File Size:"), CreateValueDisplay(file_size));
61 }
62 else
63 {
64 const QString file_format = QStringLiteral("%1 (%2)")
65 .arg(QString::fromStdString(m_game.GetFileFormatName()))
66 .arg(QString::fromStdString(file_size));
67 layout->addRow(tr("File Format:"), CreateValueDisplay(file_format));
68
69 QString compression = QString::fromStdString(m_game.GetCompressionMethod());
70 if (compression.isEmpty())
71 compression = tr("No Compression");
72 layout->addRow(tr("Compression:"), CreateValueDisplay(compression));
73
74 if (m_game.GetBlockSize() > 0)
75 {
76 const std::string block_size = UICommon::FormatSize(m_game.GetBlockSize(), 0);
77 layout->addRow(tr("Block Size:"), CreateValueDisplay(block_size));
78 }
79 }
80
81 group->setLayout(layout);
82 return group;
83 }
84
85 QGroupBox* InfoWidget::CreateGameDetails()
86 {
87 const QString UNKNOWN_NAME = tr("Unknown");
88
89 QGroupBox* group = new QGroupBox(tr("Game Details"));
90 QFormLayout* layout = new QFormLayout;
91
92 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
93
94 const QString game_name = QString::fromStdString(m_game.GetInternalName());
95
96 bool is_disc_based = m_game.GetPlatform() == DiscIO::Platform::GameCubeDisc ||
97 m_game.GetPlatform() == DiscIO::Platform::Triforce ||
98 m_game.GetPlatform() == DiscIO::Platform::WiiDisc;
99
100 QLineEdit* internal_name =
101 CreateValueDisplay(is_disc_based ? tr("%1 (Disc %2, Revision %3)")
102 .arg(game_name.isEmpty() ? UNKNOWN_NAME : game_name)
103 .arg(m_game.GetDiscNumber() + 1)
104 .arg(m_game.GetRevision()) :
105 tr("%1 (Revision %3)")
106 .arg(game_name.isEmpty() ? UNKNOWN_NAME : game_name)
107 .arg(m_game.GetRevision()));
108
109 QString game_id_string = QString::fromStdString(m_game.GetGameID());
110
111 if (const u64 title_id = m_game.GetTitleID())
112 game_id_string += QStringLiteral(" (%1)").arg(title_id, 16, 16, QLatin1Char('0'));
113
114 QLineEdit* game_id = CreateValueDisplay(game_id_string);
115
116 QLineEdit* country = CreateValueDisplay(DiscIO::GetName(m_game.GetCountry(), true));
117
118 const std::string game_maker = m_game.GetMaker(UICommon::GameFile::Variant::LongAndNotCustom);
119
120 QLineEdit* maker =
121 CreateValueDisplay((game_maker.empty() ? UNKNOWN_NAME.toStdString() : game_maker) + " (" +
122 m_game.GetMakerID() + ")");
123
124 layout->addRow(tr("Name:"), internal_name);
125 layout->addRow(tr("Game ID:"), game_id);
126 layout->addRow(tr("Country:"), country);
127 layout->addRow(tr("Maker:"), maker);
128
129 if (!m_game.GetApploaderDate().empty())
130 layout->addRow(tr("Apploader Date:"), CreateValueDisplay(m_game.GetApploaderDate()));
131
132 if (m_volume)
133 {
134 const DiscIO::Partition partition = m_volume->GetGamePartition();
135 const IOS::ES::TMDReader& tmd = m_volume->GetTMD(partition);
136 if (tmd.IsValid())
137 {
138 const auto ios = fmt::format("IOS{}", static_cast<u32>(tmd.GetIOSId()));
139 layout->addRow(tr("IOS Version:"), CreateValueDisplay(ios));
140 }
141 }
142
143 group->setLayout(layout);
144 return group;
145 }
146
147 QGroupBox* InfoWidget::CreateBannerDetails()
148 {
149 QGroupBox* group = new QGroupBox(tr("Banner Details"));
150 QFormLayout* layout = new QFormLayout;
151
152 layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);
153
154 CreateLanguageSelector();
155 layout->addRow(tr("Show Language:"), m_language_selector);
156
157 if (m_game.GetPlatform() == DiscIO::Platform::GameCubeDisc)
158 {
159 layout->addRow(tr("Name:"), m_name = CreateValueDisplay());
160 layout->addRow(tr("Maker:"), m_maker = CreateValueDisplay());
161 layout->addRow(tr("Description:"), m_description = new QTextEdit());
162 m_description->setReadOnly(true);
163 }
164 else if (DiscIO::IsWii(m_game.GetPlatform()))
165 {
166 layout->addRow(tr("Name:"), m_name = CreateValueDisplay());
167 }
168
169 ChangeLanguage();
170
171 QPixmap banner = ToQPixmap(m_game.GetBannerImage());
172 if (!banner.isNull())
173 layout->addRow(tr("Banner:"), CreateBannerGraphic(banner));
174
175 group->setLayout(layout);
176 return group;
177 }
178
179 QWidget* InfoWidget::CreateBannerGraphic(const QPixmap& image)
180 {
181 QWidget* widget = new QWidget();
182 QHBoxLayout* layout = new QHBoxLayout();
183
184 QLabel* banner = new QLabel();
185 banner->setPixmap(image.scaled(image.size().boundedTo(
186 QSize{DiscIO::WiiSaveBanner::BANNER_WIDTH, DiscIO::WiiSaveBanner::BANNER_HEIGHT})));
187
188 QPushButton* save = new QPushButton(tr("Save as..."));
189 connect(save, &QPushButton::clicked, this, &InfoWidget::SaveBanner);
190
191 layout->addWidget(banner);
192 layout->addWidget(save);
193 widget->setLayout(layout);
194 return widget;
195 }
196
197 void InfoWidget::SaveBanner()
198 {
199 QString path = DolphinFileDialog::getSaveFileName(this, tr("Select a File"), QDir::currentPath(),
200 tr("PNG image file (*.png);; All Files (*)"));
201 ToQPixmap(m_game.GetBannerImage()).save(path, "PNG");
202 }
203
204 QLineEdit* InfoWidget::CreateValueDisplay(const QString& value)
205 {
206 QLineEdit* value_display = new QLineEdit(value, this);
207 value_display->setReadOnly(true);
208 value_display->setCursorPosition(0);
209 return value_display;
210 }
211
212 QLineEdit* InfoWidget::CreateValueDisplay(const std::string& value)
213 {
214 return CreateValueDisplay(QString::fromStdString(value));
215 }
216
217 void InfoWidget::CreateLanguageSelector()
218 {
219 const bool is_wii = DiscIO::IsWii(m_game.GetPlatform());
220 const DiscIO::Language preferred_language = SConfig::GetInstance().GetCurrentLanguage(is_wii);
221
222 m_language_selector = new QComboBox();
223 for (DiscIO::Language language : m_game.GetLanguages())
224 {
225 m_language_selector->addItem(QString::fromStdString(DiscIO::GetName(language, true)),
226 static_cast<int>(language));
227 if (language == preferred_language)
228 m_language_selector->setCurrentIndex(m_language_selector->count() - 1);
229 }
230 if (m_language_selector->count() == 1)
231 m_language_selector->setDisabled(true);
232
233 connect(m_language_selector, &QComboBox::currentIndexChanged, this, &InfoWidget::ChangeLanguage);
234 }
235
236 void InfoWidget::ChangeLanguage()
237 {
238 DiscIO::Language language =
239 static_cast<DiscIO::Language>(m_language_selector->currentData().toInt());
240
241 if (m_name)
242 m_name->setText(QString::fromStdString(m_game.GetLongName(language)));
243
244 if (m_maker)
245 m_maker->setText(QString::fromStdString(m_game.GetLongMaker(language)));
246
247 if (m_description)
248 m_description->setText(QString::fromStdString(m_game.GetDescription(language)));
249 }