Save rearranged EntryConfig of buttons with new EntryProvider::saveUserEntry

这个提交包含在:
Albert S. 2020-09-13 21:08:17 +02:00
父节点 f06e9a4f7b
当前提交 653089c475
共有 2 个文件被更改,包括 46 次插入0 次删除

查看文件

@ -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)

查看文件

@ -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;
}
}