Save rearranged EntryConfig of buttons with new EntryProvider::saveUserEntry
This commit is contained in:
parent
f06e9a4f7b
commit
653089c475
@ -258,6 +258,41 @@ void EntryProvider::saveUserEntry(const EntryConfig &config)
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Only user entries can be saved");
|
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)
|
template <class T> void assignIfDestDefault(T &dest, const T &source)
|
||||||
|
11
window.cpp
11
window.cpp
@ -436,6 +436,17 @@ void Window::dropEvent(QDropEvent *event)
|
|||||||
grid->addWidget(buttonAtDrop, tmp_row, tmp_col);
|
grid->addWidget(buttonAtDrop, tmp_row, tmp_col);
|
||||||
buttonAtDrop->setRow(tmp_row);
|
buttonAtDrop->setRow(tmp_row);
|
||||||
buttonAtDrop->setCol(tmp_col);
|
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;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user