"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "gmic-qt/src/FilterSelector/FavesModelReader.cpp" between
gmic_2.8.1.tar.gz and gmic_2.8.2.tar.gz

About: G’MIC (GREY’s Magic for Image Computing) is a framework for image processing. It provides several different user interfaces to convert/manipulate/filter/ visualize generic image datasets (usable standalone or as plug-in for GIMP and Krita).

FavesModelReader.cpp  (gmic_2.8.1):FavesModelReader.cpp  (gmic_2.8.2)
skipping to change at line 39 skipping to change at line 39
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonValue> #include <QJsonValue>
#include <QList> #include <QList>
#include <QLocale> #include <QLocale>
#include <QRegularExpression> #include <QRegularExpression>
#include <QSettings> #include <QSettings>
#include <QString> #include <QString>
#include "Common.h" #include "Common.h"
#include "FilterSelector/FavesModel.h" #include "FilterSelector/FavesModel.h"
#include "Logger.h"
#include "Utils.h" #include "Utils.h"
#include "gmic.h" #include "gmic.h"
FavesModelReader::FavesModelReader(FavesModel & model) : _model(model) {} FavesModelReader::FavesModelReader(FavesModel & model) : _model(model) {}
bool FavesModelReader::gmicGTKFaveFileAvailable() bool FavesModelReader::gmicGTKFaveFileAvailable()
{ {
QFileInfo info(gmicGTKFavesFilename()); QFileInfo info(gmicGTKFavesFilename());
return info.isReadable(); return info.isReadable();
} }
skipping to change at line 102 skipping to change at line 103
fave.setCommand(list[2].replace(QRegularExpression("^gimp_"), "fx_")); fave.setCommand(list[2].replace(QRegularExpression("^gimp_"), "fx_"));
fave.setPreviewCommand(list[3].replace(QRegularExpression("^gimp_"), "fx _")); fave.setPreviewCommand(list[3].replace(QRegularExpression("^gimp_"), "fx _"));
list.pop_front(); list.pop_front();
list.pop_front(); list.pop_front();
list.pop_front(); list.pop_front();
list.pop_front(); list.pop_front();
fave.setDefaultValues(list); fave.setDefaultValues(list);
fave.build(); fave.build();
_model.addFave(fave); _model.addFave(fave);
} else { } else {
std::cerr << "[gmic-qt] Error: Import failed for fave at gimp_faves:" << lineNumber << "\n"; Logger::error(QString("Import failed for fave at %1:%2").arg(file.fileNa me()).arg(lineNumber));
} }
++lineNumber; ++lineNumber;
} }
} else { } else {
qWarning() << "[gmic-qt] Error: Import failed. Cannot open" << filename; Logger::error("Import failed. Cannot open " + filename);
} }
} }
void FavesModelReader::loadFaves() void FavesModelReader::loadFaves()
{ {
// Read JSON faves if file exists // Read JSON faves if file exists
QString jsonFilename(QString("%1%2").arg(GmicQt::path_rc(false)).arg("gmic_qt_ faves.json")); QString jsonFilename(QString("%1%2").arg(GmicQt::path_rc(false)).arg("gmic_qt_ faves.json"));
QFile jsonFile(jsonFilename); QFile jsonFile(jsonFilename);
if (jsonFile.exists()) { if (jsonFile.exists()) {
if (jsonFile.open(QIODevice::ReadOnly)) { if (jsonFile.open(QIODevice::ReadOnly)) {
QJsonDocument document; QJsonDocument document;
QJsonParseError parseError; QJsonParseError parseError;
document = QJsonDocument::fromJson(jsonFile.readAll(), &parseError); document = QJsonDocument::fromJson(jsonFile.readAll(), &parseError);
if (parseError.error == QJsonParseError::NoError) { if (parseError.error == QJsonParseError::NoError) {
QJsonArray array = document.array(); QJsonArray array = document.array();
for (const QJsonValueRef & value : array) { for (const QJsonValueRef & value : array) {
_model.addFave(jsonObjectToFave(value.toObject())); _model.addFave(jsonObjectToFave(value.toObject()));
} }
} else { } else {
qWarning() << "[gmic-qt] Error loading faves (parse error) : " << jsonFi Logger::error("Cannot load faves (parse error) : " + jsonFilename);
lename; Logger::error(parseError.errorString());
qWarning() << "[gmic-qt]" << parseError.errorString();
} }
} else { } else {
qWarning() << "[gmic-qt] Error: Faves loading failed: Cannot open" << json Filename; Logger::log("Faves loading failed: Cannot open " + jsonFilename);
} }
return; return;
} }
// Read old 2.0.0 prerelease file format if no JSON was found // Read old 2.0.0 prerelease file format if no JSON was found
QString filename(QString("%1%2").arg(GmicQt::path_rc(false)).arg("gmic_qt_fave s")); QString filename(QString("%1%2").arg(GmicQt::path_rc(false)).arg("gmic_qt_fave s"));
QFile file(filename); QFile file(filename);
if (file.exists()) { if (file.exists()) {
if (file.open(QIODevice::ReadOnly)) { if (file.open(QIODevice::ReadOnly)) {
QString line; QString line;
int lineNumber = 1; int lineNumber = 1;
while (!(line = file.readLine()).isEmpty()) { while (!(line = file.readLine()).isEmpty()) {
line = line.trimmed(); line = line.trimmed();
if (line.startsWith("{")) { if (line.startsWith("{")) {
line.replace(QRegExp("^."), "").replace(QRegExp(".$"), ""); line.replace(QRegExp("^."), "").replace(QRegExp(".$"), "");
QList<QString> list = line.split("}{"); QList<QString> list = line.split("}{");
for (QString & str : list) { for (QString & str : list) {
str.replace(QChar(gmic_lbrace), QString("{")); str.replace(QChar(gmic_lbrace), QString("{"));
str.replace(QChar(gmic_rbrace), QString("}")); str.replace(QChar(gmic_rbrace), QString("}"));
// (29 == gmic_newline) until gmic version 2.7.1 // (29 == gmic_newline) until gmic version 2.7.1
str.replace(QChar(29), QString("\n")); str.replace(QChar(29), QString("\n"));
} }
if (list.size() >= 4) { if (list.size() >= 4) {
FavesModel::Fave fave; FavesModel::Fave fave;
fave.setName(list.front()); fave.setName(list.front());
fave.setOriginalName(list[1]); fave.setOriginalName(list[1]);
fave.setCommand(list[2]); fave.setCommand(list[2]);
fave.setPreviewCommand(list[3]); fave.setPreviewCommand(list[3]);
list.pop_front(); list.pop_front();
list.pop_front(); list.pop_front();
list.pop_front(); list.pop_front();
list.pop_front(); list.pop_front();
fave.setDefaultValues(list); fave.setDefaultValues(list);
fave.build(); fave.build();
_model.addFave(fave); _model.addFave(fave);
} else { } else {
std::cerr << "[gmic-qt] Error: Loading failed for fave at gmic_qt_fa ves:" << lineNumber << "\n"; Logger::log(QString("Loading failed for fave at %1:%2").arg(file.fil eName()).arg(lineNumber));
} }
} }
++lineNumber; ++lineNumber;
} }
} else { } else {
qWarning() << "[gmic-qt] Error: Loading failed. Cannot open" << filename; Logger::error("Fave loading failed. Cannot open " + filename);
} }
} }
} }
QString FavesModelReader::gmicGTKFavesFilename() QString FavesModelReader::gmicGTKFavesFilename()
{ {
return QString("%1%2").arg(GmicQt::path_rc(false)).arg("gimp_faves"); return QString("%1%2").arg(GmicQt::path_rc(false)).arg("gimp_faves");
} }
 End of changes. 8 change blocks. 
9 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)