diff --git a/entryprovider.cpp b/entryprovider.cpp index 3165d93..41e00e5 100644 --- a/entryprovider.cpp +++ b/entryprovider.cpp @@ -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 void assignIfDestDefault(T &dest, const T &source) diff --git a/window.cpp b/window.cpp index c861d47..04e96ce 100644 --- a/window.cpp +++ b/window.cpp @@ -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; } }