MCPcopy Create free account
hub / github.com/PCSX2/pcsx2 / BindWidgetToFolderSetting

Function BindWidgetToFolderSetting

pcsx2-qt/SettingWidgetBinder.h:1163–1263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1161 }
1162
1163 static inline void BindWidgetToFolderSetting(SettingsInterface* sif, QLineEdit* widget, QAbstractButton* browse_button,
1164 QAbstractButton* open_button, QAbstractButton* reset_button, std::string section, std::string key, std::string default_value,
1165 bool use_relative = true)
1166 {
1167 using Accessor = SettingAccessor<QLineEdit>;
1168
1169 std::string current_path(Host::GetBaseStringSettingValue(section.c_str(), key.c_str(), default_value.c_str()));
1170 if (current_path.empty())
1171 current_path = default_value;
1172 else if (use_relative && !Path::IsAbsolute(current_path))
1173 current_path = Path::Canonicalize(Path::Combine(EmuFolders::DataRoot, current_path));
1174
1175 const QString value(QString::fromStdString(current_path));
1176 Accessor::setStringValue(widget, value);
1177
1178 // if we're doing per-game settings, disable the widget, we only allow folder changes in the base config
1179 if (sif)
1180 {
1181 widget->setEnabled(false);
1182 if (browse_button)
1183 browse_button->setEnabled(false);
1184 if (reset_button)
1185 reset_button->setEnabled(false);
1186 return;
1187 }
1188
1189
1190 auto value_changed = [widget, section = std::move(section), key = std::move(key), default_value, use_relative]() {
1191 const std::string new_value(widget->text().toStdString());
1192 if (!new_value.empty())
1193 {
1194 if (FileSystem::DirectoryExists(new_value.c_str()) ||
1195 QMessageBox::question(QtUtils::GetRootWidget(widget), qApp->translate("SettingWidgetBinder", "Confirm Folder"),
1196 qApp->translate("SettingWidgetBinder",
1197 "The chosen directory does not currently exist:\n\n%1\n\nDo you want to create this directory?")
1198 .arg(QString::fromStdString(new_value)),
1199 QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes)
1200 {
1201 if (use_relative)
1202 {
1203 const std::string relative_path(Path::MakeRelative(new_value, EmuFolders::DataRoot));
1204 Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), relative_path.c_str());
1205 }
1206 else
1207 {
1208 Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), new_value.c_str());
1209 }
1210
1211 Host::CommitBaseSettingChanges();
1212 g_emu_thread->updateEmuFolders();
1213 return;
1214 }
1215 }
1216 else
1217 {
1218 QMessageBox::critical(QtUtils::GetRootWidget(widget), qApp->translate("SettingWidgetBinder", "Error"),
1219 qApp->translate("SettingWidgetBinder", "Folder path cannot be empty."));
1220 }

Callers 6

setupBIOSPageMethod · 0.85
FolderSettingsWidgetMethod · 0.85
BIOSSettingsWidgetMethod · 0.85
DebugSettingsWidgetMethod · 0.85

Calls 8

CombineFunction · 0.85
GetRootWidgetFunction · 0.85
OpenURLFunction · 0.85
argMethod · 0.80
updateEmuFoldersMethod · 0.80
c_strMethod · 0.45
emptyMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected