| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <QFile> |
| 4 | #include <QString> |
| 5 | #include <QTextStream> |
| 6 | |
| 7 | #include "Configuration.h" |
| 8 | #include "Util.h" |
| 9 | |
| 10 | QMap<QString, QString> Configuration::fromFile(const QString &curr_path) |
| 11 | { |
| 12 | QFile curr_file(curr_path); |
| 13 | |
| 14 | if ( !curr_file.open(QFile::ReadOnly) |
| 15 | || !curr_file.isReadable() |
| 16 | || curr_file.atEnd()) { |
| 17 | return {}; |
| 18 | } |
| 19 | |
| 20 | auto result = Util::parseParameters(curr_file); |
| 21 | |
| 22 | curr_file.close(); |
| 23 | return result; |
| 24 | } |
| 25 | |
| 26 | |
| 27 | bool Configuration::toFile(const QString &curr_path, const Parameters ¶ms) |
| 28 | { |
| 29 | QFile output(curr_path); |
| 30 | |
| 31 | if(!output.open(QFile::WriteOnly|QFile::Truncate)){ |
| 32 | return false; |
| 33 | } |
| 34 | QTextStream outStream(&output); |
| 35 | for(auto it = params.begin(); it != params.end(); ++it){ |
| 36 | outStream << it.key() << " = " << it.value() << "\n"; |
| 37 | } |
| 38 | |
| 39 | output.close(); |
| 40 | return true; |
| 41 | } |