|
23 | 23 | #include <QtWidgets/QSpinBox> |
24 | 24 |
|
25 | 25 | #include "common/FileSystem.h" |
| 26 | +#include "common/HostSys.h" |
26 | 27 | #include "common/Path.h" |
27 | 28 |
|
28 | 29 | #include "pcsx2/Config.h" |
@@ -1261,8 +1262,8 @@ namespace SettingWidgetBinder |
1261 | 1262 | widget->connect(widget, &QLineEdit::editingFinished, widget, std::move(value_changed)); |
1262 | 1263 | } |
1263 | 1264 |
|
1264 | | - static inline void BindWidgetToFileSetting(SettingsInterface* sif, QLineEdit* widget, QAbstractButton* browse_button, |
1265 | | - QAbstractButton* open_button, QAbstractButton* reset_button, std::string section, std::string key, std::string default_value, |
| 1265 | + static inline void BindWidgetToAudioFileSetting(SettingsInterface* sif, QLineEdit* widget, QAbstractButton* browse_button, |
| 1266 | + QAbstractButton* preview_button, QAbstractButton* reset_button, std::string section, std::string key, std::string default_value, |
1266 | 1267 | const QString& filter, bool allow_pergame = false, bool use_relative = true) |
1267 | 1268 | { |
1268 | 1269 | using Accessor = SettingAccessor<QLineEdit>; |
@@ -1296,60 +1297,48 @@ namespace SettingWidgetBinder |
1296 | 1297 | Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), relative_path.c_str()); |
1297 | 1298 | } |
1298 | 1299 | else |
1299 | | - { |
1300 | 1300 | Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.c_str()); |
1301 | | - } |
1302 | 1301 |
|
1303 | 1302 | if (!FileSystem::FileExists(new_value.c_str())) |
1304 | | - { |
1305 | 1303 | QMessageBox::critical(QtUtils::GetRootWidget(widget), qApp->translate("SettingWidgetBinder", "Error"), |
1306 | 1304 | qApp->translate("SettingWidgetBinder", "File cannot be found.")); |
1307 | | - } |
1308 | 1305 |
|
1309 | 1306 | Host::CommitBaseSettingChanges(); |
1310 | 1307 | return; |
1311 | 1308 | } |
1312 | 1309 | else |
1313 | | - { |
1314 | | - QMessageBox::critical(QtUtils::GetRootWidget(widget), qApp->translate("SettingWidgetBinder", "Error"), |
1315 | | - qApp->translate("SettingWidgetBinder", "File path cannot be empty.")); |
1316 | | - } |
| 1310 | + Host::RemoveBaseSettingValue(section.c_str(), key.c_str()); |
1317 | 1311 |
|
1318 | | - // reset to old value |
1319 | | - std::string current_path(Host::GetBaseStringSettingValue(section.c_str(), key.c_str(), default_value.c_str())); |
1320 | | - if (current_path.empty()) |
1321 | | - current_path = default_value; |
1322 | | - else if (use_relative && !Path::IsAbsolute(current_path)) |
1323 | | - current_path = Path::Canonicalize(Path::Combine(EmuFolders::DataRoot, current_path)); |
1324 | | - |
1325 | | - widget->setText(QString::fromStdString(current_path)); |
1326 | 1312 | }; |
1327 | 1313 |
|
1328 | 1314 | if (browse_button) |
1329 | 1315 | { |
1330 | 1316 | QObject::connect(browse_button, &QAbstractButton::clicked, browse_button, [widget, key, value_changed, filter]() { |
1331 | 1317 | const QString path(QDir::toNativeSeparators(QFileDialog::getOpenFileName(QtUtils::GetRootWidget(widget), |
1332 | | - qApp->translate("SettingWidgetBinder", "Select File"), QString(), filter))); |
| 1318 | + qApp->translate("SettingWidgetBinder", "Select Audio File"), QString(), filter))); |
1333 | 1319 | if (path.isEmpty()) |
1334 | 1320 | return; |
1335 | 1321 |
|
1336 | 1322 | widget->setText(path); |
1337 | 1323 | value_changed(); |
1338 | 1324 | }); |
1339 | 1325 | } |
1340 | | - if (open_button) |
| 1326 | + if (preview_button) |
1341 | 1327 | { |
1342 | | - QObject::connect(open_button, &QAbstractButton::clicked, open_button, [widget]() { |
1343 | | - QString path(Accessor::getStringValue(widget)); |
1344 | | - if (!path.isEmpty()) |
1345 | | - QtUtils::OpenURL(QtUtils::GetRootWidget(widget), QUrl::fromLocalFile(path)); |
| 1328 | + QObject::connect(preview_button, &QAbstractButton::clicked, preview_button, [widget, default_value = std::move(default_value)]() { |
| 1329 | + const QByteArray path = widget->text().toUtf8(); |
| 1330 | + Common::PlaySoundAsync( |
| 1331 | + (path.isEmpty() |
| 1332 | + ? default_value |
| 1333 | + : path.constData()).c_str() |
| 1334 | + ); |
1346 | 1335 | }); |
1347 | 1336 | } |
1348 | 1337 | if (reset_button) |
1349 | 1338 | { |
1350 | 1339 | QObject::connect( |
1351 | | - reset_button, &QAbstractButton::clicked, reset_button, [widget, default_value = std::move(default_value), value_changed]() { |
1352 | | - widget->setText(QString::fromStdString(default_value)); |
| 1340 | + reset_button, &QAbstractButton::clicked, reset_button, [widget, value_changed]() { |
| 1341 | + widget->clear(); |
1353 | 1342 | value_changed(); |
1354 | 1343 | }); |
1355 | 1344 | } |
|
0 commit comments