Save rearranged EntryConfig of buttons with new EntryProvider::saveUserEntry

This commit is contained in:
Albert S. 2020-09-13 21:08:17 +02:00
parent f06e9a4f7b
commit 653089c475
2 changed files with 46 additions and 0 deletions

View File

@ -258,6 +258,41 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
{
throw std::runtime_error("Only user entries can be saved");
}
QString transitPath = config.entryPath + ".transit";
QFile file{transitPath};
if(!file.open(QIODevice::WriteOnly))
{
throw std::runtime_error("Error: Can not open file for writing");
}
QTextStream outStream(&file);
if(!config.inherit.isEmpty())
{
outStream << "inherit" << " " << config.inherit << endl;
}
if(!config.name.isEmpty())
{
outStream << "name" << " " << config.name << endl;
}
if(!config.command.isEmpty())
{
outStream << "command" << " " << config.command << endl;
}
if(!config.icon.isNull())
{
outStream << "icon" << " " << config.icon.name() << endl;
}
outStream << "row" << " " << config.row << endl;
outStream << "col" << " " << config.col << endl;
outStream.flush();
file.close();
// Qts don't work if file already exists and c++17... don't want to pull in the fs lib yet
int ret = rename(transitPath.toStdString().c_str(), config.entryPath.toStdString().c_str());
if(ret != 0)
{
qDebug() << strerror(errno);
throw std::runtime_error("Failed to save entry file: Error during rename");
}
}
template <class T> void assignIfDestDefault(T &dest, const T &source)

View File

@ -436,6 +436,17 @@ void Window::dropEvent(QDropEvent *event)
grid->addWidget(buttonAtDrop, tmp_row, tmp_col);
buttonAtDrop->setRow(tmp_row);
buttonAtDrop->setCol(tmp_col);
try
{
this->entryProvider->saveUserEntry(buttonAtDrop->getEntryConfig());
this->entryProvider->saveUserEntry(buttonAtSource->getEntryConfig());
}
catch(std::exception &e)
{
QMessageBox::critical(this, "Failed to rearrange items", e.what());
}
break;
}
}