Add a deprecation notice to the launcher for XML files

This commit is contained in:
Alexander Bock
2022-01-25 14:48:48 +01:00
parent 322e29e53c
commit a6bd29e679

View File

@@ -382,6 +382,23 @@ void LauncherWindow::populateProfilesList(std::string preset) {
}
}
// Returns 'true' if the file was a configuration file, 'false' otherwise
bool handleConfigurationFile(QComboBox& box, const std::filesystem::directory_entry& p) {
const bool isXml = p.path().extension() == ".xml";
const bool isJson = p.path().extension() == ".json";
if (!isXml && !isJson) {
return false;
}
box.addItem(QString::fromStdString(p.path().filename().string()));
// For now, mark the XML configuration files to show that they are deprecated
if (isXml) {
box.setItemData(box.count() - 1, QBrush(Qt::darkYellow), Qt::ForegroundRole);
}
return true;
}
void LauncherWindow::populateWindowConfigsList(std::string preset) {
namespace fs = std::filesystem;
@@ -389,16 +406,22 @@ void LauncherWindow::populateWindowConfigsList(std::string preset) {
_userConfigCount = 0;
_windowConfigBox->addItem(QString::fromStdString("--- User Configurations ---"));
const QStandardItemModel* model = qobject_cast<const QStandardItemModel*>(_windowConfigBox->model());
const QStandardItemModel* model =
qobject_cast<const QStandardItemModel*>(_windowConfigBox->model());
model->item(_userConfigCount)->setEnabled(false);
++_userConfigCount;
bool hasXmlConfig = false;
// Add all the files with the .xml or .json extension to the dropdown
for (const fs::directory_entry& p : fs::directory_iterator(_userConfigPath)) {
if (p.path().extension() != ".xml" && p.path().extension() != ".json") {
continue;
bool isConfigFile = handleConfigurationFile(*_windowConfigBox, p);
if (isConfigFile) {
++_userConfigCount;
}
_windowConfigBox->addItem(QString::fromStdString(p.path().filename().string()));
++_userConfigCount;
hasXmlConfig |= p.path().extension() == ".xml";
}
_windowConfigBox->addItem(QString::fromStdString("--- OpenSpace Configurations ---"));
model = qobject_cast<const QStandardItemModel*>(_windowConfigBox->model());
@@ -407,12 +430,8 @@ void LauncherWindow::populateWindowConfigsList(std::string preset) {
if (std::filesystem::exists(_configPath)) {
// Add all the files with the .xml or .json extension to the dropdown
for (const fs::directory_entry& p : fs::directory_iterator(_configPath)) {
if (p.path().extension() != ".xml" && p.path().extension() != ".json") {
continue;
}
_windowConfigBox->addItem(
QString::fromStdString(p.path().filename().string())
);
handleConfigurationFile(*_windowConfigBox, p);
hasXmlConfig |= p.path().extension() == ".xml";
}
}
else {
@@ -422,6 +441,17 @@ void LauncherWindow::populateWindowConfigsList(std::string preset) {
);
}
if (hasXmlConfig) {
// At least one XML configuration file is present, so we should show the tooltip
// informing the user that files will be deprecated
_windowConfigBox->setToolTip(
"Support for XML-based configuration files will be removed in the next "
"version of OpenSpace. Please convert the files to the new JSON format or "
"run the Node tool at "
"https://github.com/sgct/sgct/tree/master/support/config-converter"
);
}
// Try to find the requested configuration file and set it as the current one. As we
// have support for function-generated configuration files that will not be in the
// list we need to add a preset that doesn't exist a file for