Save temporal changes.
This commit is contained in:
parent
e9d39454dc
commit
76b4c12584
@ -278,7 +278,6 @@ file( GLOB APP_SOURCES_GL
|
|||||||
"src/qtsingleapplication/qtsinglecoreapplication.cpp"
|
"src/qtsingleapplication/qtsinglecoreapplication.cpp"
|
||||||
"src/qtsingleapplication/qtlocalpeer.cpp"
|
"src/qtsingleapplication/qtlocalpeer.cpp"
|
||||||
|
|
||||||
"src/qt-json/*.cpp"
|
|
||||||
"src/gui/dialogs/*.cpp"
|
"src/gui/dialogs/*.cpp"
|
||||||
"src/gui/notifications/*.cpp"
|
"src/gui/notifications/*.cpp"
|
||||||
"src/gui/*.cpp"
|
"src/gui/*.cpp"
|
||||||
|
@ -155,6 +155,8 @@ NetworkResult NetworkFactory::uploadData(const QString &url, int timeout, const
|
|||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
NetworkResult result;
|
NetworkResult result;
|
||||||
|
|
||||||
|
QString str(input_data);
|
||||||
|
|
||||||
downloader.appendRawHeader("Content-Type", input_content_type.toLocal8Bit());
|
downloader.appendRawHeader("Content-Type", input_content_type.toLocal8Bit());
|
||||||
|
|
||||||
if (set_basic_header) {
|
if (set_basic_header) {
|
||||||
|
@ -1,603 +0,0 @@
|
|||||||
/**
|
|
||||||
* QtJson - A simple class for parsing JSON data into a QVariant hierarchies and vice-versa.
|
|
||||||
* Copyright (C) 2011 Eeli Reilin
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \file json.cpp
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <QDateTime>
|
|
||||||
#include <QStringList>
|
|
||||||
#include "json.h"
|
|
||||||
|
|
||||||
namespace QtJson {
|
|
||||||
static QString dateFormat, dateTimeFormat;
|
|
||||||
|
|
||||||
static QString sanitizeString(QString str);
|
|
||||||
static QByteArray join(const QList<QByteArray> &list, const QByteArray &sep);
|
|
||||||
static QVariant parseValue(const QString &json, int &index, bool &success);
|
|
||||||
static QVariant parseObject(const QString &json, int &index, bool &success);
|
|
||||||
static QVariant parseArray(const QString &json, int &index, bool &success);
|
|
||||||
static QVariant parseString(const QString &json, int &index, bool &success);
|
|
||||||
static QVariant parseNumber(const QString &json, int &index);
|
|
||||||
static int lastIndexOfNumber(const QString &json, int index);
|
|
||||||
static void eatWhitespace(const QString &json, int &index);
|
|
||||||
static int lookAhead(const QString &json, int index);
|
|
||||||
static int nextToken(const QString &json, int &index);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
QByteArray serializeMap(const T &map, bool &success) {
|
|
||||||
QByteArray str = "{";
|
|
||||||
QList<QByteArray> pairs;
|
|
||||||
for (typename T::const_iterator it = map.begin(), itend = map.end(); it != itend; ++it) {
|
|
||||||
QByteArray serializedValue = serialize(it.value());
|
|
||||||
if (serializedValue.isNull()) {
|
|
||||||
success = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pairs << sanitizeString(it.key()).toUtf8() + ":" + serializedValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
str += join(pairs, ",");
|
|
||||||
str += "}";
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
void insert(QVariant &v, const QString &key, const QVariant &value);
|
|
||||||
void append(QVariant &v, const QVariant &value);
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void cloneMap(QVariant &json, const T &map) {
|
|
||||||
for (typename T::const_iterator it = map.begin(), itend = map.end(); it != itend; ++it) {
|
|
||||||
insert(json, it.key(), (*it));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
void cloneList(QVariant &json, const T &list) {
|
|
||||||
for (typename T::const_iterator it = list.begin(), itend = list.end(); it != itend; ++it) {
|
|
||||||
append(json, (*it));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* parse
|
|
||||||
*/
|
|
||||||
QVariant parse(const QString &json) {
|
|
||||||
bool success = true;
|
|
||||||
return parse(json, success);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* parse
|
|
||||||
*/
|
|
||||||
QVariant parse(const QString &json, bool &success) {
|
|
||||||
success = true;
|
|
||||||
|
|
||||||
// Return an empty QVariant if the JSON data is either null or empty
|
|
||||||
if (!json.isNull() || !json.isEmpty()) {
|
|
||||||
QString data = json;
|
|
||||||
// We'll start from index 0
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
// Parse the first value
|
|
||||||
QVariant value = parseValue(data, index, success);
|
|
||||||
|
|
||||||
// Return the parsed value
|
|
||||||
return value;
|
|
||||||
} else {
|
|
||||||
// Return the empty QVariant
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* clone
|
|
||||||
*/
|
|
||||||
QVariant clone(const QVariant &data) {
|
|
||||||
QVariant v;
|
|
||||||
|
|
||||||
if (data.type() == QVariant::Map) {
|
|
||||||
cloneMap(v, data.toMap());
|
|
||||||
} else if (data.type() == QVariant::Hash) {
|
|
||||||
cloneMap(v, data.toHash());
|
|
||||||
} else if (data.type() == QVariant::List) {
|
|
||||||
cloneList(v, data.toList());
|
|
||||||
} else if (data.type() == QVariant::StringList) {
|
|
||||||
cloneList(v, data.toStringList());
|
|
||||||
} else {
|
|
||||||
v = QVariant(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
return v;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* insert value (map case)
|
|
||||||
*/
|
|
||||||
void insert(QVariant &v, const QString &key, const QVariant &value) {
|
|
||||||
if (!v.canConvert<QVariantMap>()) v = QVariantMap();
|
|
||||||
QVariantMap *p = (QVariantMap *)v.data();
|
|
||||||
p->insert(key, clone(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* append value (list case)
|
|
||||||
*/
|
|
||||||
void append(QVariant &v, const QVariant &value) {
|
|
||||||
if (!v.canConvert<QVariantList>()) v = QVariantList();
|
|
||||||
QVariantList *p = (QVariantList *)v.data();
|
|
||||||
p->append(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray serialize(const QVariant &data) {
|
|
||||||
bool success = true;
|
|
||||||
return serialize(data, success);
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray serialize(const QVariant &data, bool &success) {
|
|
||||||
QByteArray str;
|
|
||||||
success = true;
|
|
||||||
|
|
||||||
if (!data.isValid()) { // invalid or null?
|
|
||||||
str = "null";
|
|
||||||
} else if ((data.type() == QVariant::List) ||
|
|
||||||
(data.type() == QVariant::StringList)) { // variant is a list?
|
|
||||||
QList<QByteArray> values;
|
|
||||||
const QVariantList list = data.toList();
|
|
||||||
Q_FOREACH(const QVariant& v, list) {
|
|
||||||
QByteArray serializedValue = serialize(v);
|
|
||||||
if (serializedValue.isNull()) {
|
|
||||||
success = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
values << serializedValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
str = "[" + join( values, "," ) + "]";
|
|
||||||
} else if (data.type() == QVariant::Hash) { // variant is a hash?
|
|
||||||
str = serializeMap<>(data.toHash(), success);
|
|
||||||
} else if (data.type() == QVariant::Map) { // variant is a map?
|
|
||||||
str = serializeMap<>(data.toMap(), success);
|
|
||||||
} else if ((data.type() == QVariant::String) ||
|
|
||||||
(data.type() == QVariant::ByteArray)) {// a string or a byte array?
|
|
||||||
str = sanitizeString(data.toString()).toUtf8();
|
|
||||||
} else if (data.type() == QVariant::Double) { // double?
|
|
||||||
double value = data.toDouble(&success);
|
|
||||||
if (success) {
|
|
||||||
str = QByteArray::number(value, 'g');
|
|
||||||
if (!str.contains(".") && ! str.contains("e")) {
|
|
||||||
str += ".0";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (data.type() == QVariant::Bool) { // boolean value?
|
|
||||||
str = data.toBool() ? "true" : "false";
|
|
||||||
} else if (data.type() == QVariant::ULongLong) { // large unsigned number?
|
|
||||||
str = QByteArray::number(data.value<qulonglong>());
|
|
||||||
} else if (data.canConvert<qlonglong>()) { // any signed number?
|
|
||||||
str = QByteArray::number(data.value<qlonglong>());
|
|
||||||
} else if (data.canConvert<long>()) { //TODO: this code is never executed because all smaller types can be converted to qlonglong
|
|
||||||
str = QString::number(data.value<long>()).toUtf8();
|
|
||||||
} else if (data.type() == QVariant::DateTime) { // datetime value?
|
|
||||||
str = sanitizeString(dateTimeFormat.isEmpty()
|
|
||||||
? data.toDateTime().toString()
|
|
||||||
: data.toDateTime().toString(dateTimeFormat)).toUtf8();
|
|
||||||
} else if (data.type() == QVariant::Date) { // date value?
|
|
||||||
str = sanitizeString(dateTimeFormat.isEmpty()
|
|
||||||
? data.toDate().toString()
|
|
||||||
: data.toDate().toString(dateFormat)).toUtf8();
|
|
||||||
} else if (data.canConvert<QString>()) { // can value be converted to string?
|
|
||||||
// this will catch QUrl, ... (all other types which can be converted to string)
|
|
||||||
str = sanitizeString(data.toString()).toUtf8();
|
|
||||||
} else {
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success) {
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
return QByteArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString serializeStr(const QVariant &data) {
|
|
||||||
return QString::fromUtf8(serialize(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString serializeStr(const QVariant &data, bool &success) {
|
|
||||||
return QString::fromUtf8(serialize(data, success));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \enum JsonToken
|
|
||||||
*/
|
|
||||||
enum JsonToken {
|
|
||||||
JsonTokenNone = 0,
|
|
||||||
JsonTokenCurlyOpen = 1,
|
|
||||||
JsonTokenCurlyClose = 2,
|
|
||||||
JsonTokenSquaredOpen = 3,
|
|
||||||
JsonTokenSquaredClose = 4,
|
|
||||||
JsonTokenColon = 5,
|
|
||||||
JsonTokenComma = 6,
|
|
||||||
JsonTokenString = 7,
|
|
||||||
JsonTokenNumber = 8,
|
|
||||||
JsonTokenTrue = 9,
|
|
||||||
JsonTokenFalse = 10,
|
|
||||||
JsonTokenNull = 11
|
|
||||||
};
|
|
||||||
|
|
||||||
static QString sanitizeString(QString str) {
|
|
||||||
str.replace(QLatin1String("\\"), QLatin1String("\\\\"));
|
|
||||||
str.replace(QLatin1String("\""), QLatin1String("\\\""));
|
|
||||||
str.replace(QLatin1String("\b"), QLatin1String("\\b"));
|
|
||||||
str.replace(QLatin1String("\f"), QLatin1String("\\f"));
|
|
||||||
str.replace(QLatin1String("\n"), QLatin1String("\\n"));
|
|
||||||
str.replace(QLatin1String("\r"), QLatin1String("\\r"));
|
|
||||||
str.replace(QLatin1String("\t"), QLatin1String("\\t"));
|
|
||||||
return QString(QLatin1String("\"%1\"")).arg(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
static QByteArray join(const QList<QByteArray> &list, const QByteArray &sep) {
|
|
||||||
QByteArray res;
|
|
||||||
Q_FOREACH(const QByteArray &i, list) {
|
|
||||||
if (!res.isEmpty()) {
|
|
||||||
res += sep;
|
|
||||||
}
|
|
||||||
res += i;
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* parseValue
|
|
||||||
*/
|
|
||||||
static QVariant parseValue(const QString &json, int &index, bool &success) {
|
|
||||||
// Determine what kind of data we should parse by
|
|
||||||
// checking out the upcoming token
|
|
||||||
switch(lookAhead(json, index)) {
|
|
||||||
case JsonTokenString:
|
|
||||||
return parseString(json, index, success);
|
|
||||||
case JsonTokenNumber:
|
|
||||||
return parseNumber(json, index);
|
|
||||||
case JsonTokenCurlyOpen:
|
|
||||||
return parseObject(json, index, success);
|
|
||||||
case JsonTokenSquaredOpen:
|
|
||||||
return parseArray(json, index, success);
|
|
||||||
case JsonTokenTrue:
|
|
||||||
nextToken(json, index);
|
|
||||||
return QVariant(true);
|
|
||||||
case JsonTokenFalse:
|
|
||||||
nextToken(json, index);
|
|
||||||
return QVariant(false);
|
|
||||||
case JsonTokenNull:
|
|
||||||
nextToken(json, index);
|
|
||||||
return QVariant();
|
|
||||||
case JsonTokenNone:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there were no tokens, flag the failure and return an empty QVariant
|
|
||||||
success = false;
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* parseObject
|
|
||||||
*/
|
|
||||||
static QVariant parseObject(const QString &json, int &index, bool &success) {
|
|
||||||
QVariantMap map;
|
|
||||||
int token;
|
|
||||||
|
|
||||||
// Get rid of the whitespace and increment index
|
|
||||||
nextToken(json, index);
|
|
||||||
|
|
||||||
// Loop through all of the key/value pairs of the object
|
|
||||||
bool done = false;
|
|
||||||
while (!done) {
|
|
||||||
// Get the upcoming token
|
|
||||||
token = lookAhead(json, index);
|
|
||||||
|
|
||||||
if (token == JsonTokenNone) {
|
|
||||||
success = false;
|
|
||||||
return QVariantMap();
|
|
||||||
} else if (token == JsonTokenComma) {
|
|
||||||
nextToken(json, index);
|
|
||||||
} else if (token == JsonTokenCurlyClose) {
|
|
||||||
nextToken(json, index);
|
|
||||||
return map;
|
|
||||||
} else {
|
|
||||||
// Parse the key/value pair's name
|
|
||||||
QString name = parseString(json, index, success).toString();
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
return QVariantMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the next token
|
|
||||||
token = nextToken(json, index);
|
|
||||||
|
|
||||||
// If the next token is not a colon, flag the failure
|
|
||||||
// return an empty QVariant
|
|
||||||
if (token != JsonTokenColon) {
|
|
||||||
success = false;
|
|
||||||
return QVariant(QVariantMap());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the key/value pair's value
|
|
||||||
QVariant value = parseValue(json, index, success);
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
return QVariantMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assign the value to the key in the map
|
|
||||||
map[name] = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the map successfully
|
|
||||||
return QVariant(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* parseArray
|
|
||||||
*/
|
|
||||||
static QVariant parseArray(const QString &json, int &index, bool &success) {
|
|
||||||
QVariantList list;
|
|
||||||
|
|
||||||
nextToken(json, index);
|
|
||||||
|
|
||||||
bool done = false;
|
|
||||||
while(!done) {
|
|
||||||
int token = lookAhead(json, index);
|
|
||||||
|
|
||||||
if (token == JsonTokenNone) {
|
|
||||||
success = false;
|
|
||||||
return QVariantList();
|
|
||||||
} else if (token == JsonTokenComma) {
|
|
||||||
nextToken(json, index);
|
|
||||||
} else if (token == JsonTokenSquaredClose) {
|
|
||||||
nextToken(json, index);
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
QVariant value = parseValue(json, index, success);
|
|
||||||
if (!success) {
|
|
||||||
return QVariantList();
|
|
||||||
}
|
|
||||||
list.push_back(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariant(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* parseString
|
|
||||||
*/
|
|
||||||
static QVariant parseString(const QString &json, int &index, bool &success) {
|
|
||||||
QString s;
|
|
||||||
QChar c;
|
|
||||||
|
|
||||||
eatWhitespace(json, index);
|
|
||||||
|
|
||||||
c = json[index++];
|
|
||||||
|
|
||||||
bool complete = false;
|
|
||||||
while(!complete) {
|
|
||||||
if (index == json.size()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = json[index++];
|
|
||||||
|
|
||||||
if (c == '\"') {
|
|
||||||
complete = true;
|
|
||||||
break;
|
|
||||||
} else if (c == '\\') {
|
|
||||||
if (index == json.size()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
c = json[index++];
|
|
||||||
|
|
||||||
if (c == '\"') {
|
|
||||||
s.append('\"');
|
|
||||||
} else if (c == '\\') {
|
|
||||||
s.append('\\');
|
|
||||||
} else if (c == '/') {
|
|
||||||
s.append('/');
|
|
||||||
} else if (c == 'b') {
|
|
||||||
s.append('\b');
|
|
||||||
} else if (c == 'f') {
|
|
||||||
s.append('\f');
|
|
||||||
} else if (c == 'n') {
|
|
||||||
s.append('\n');
|
|
||||||
} else if (c == 'r') {
|
|
||||||
s.append('\r');
|
|
||||||
} else if (c == 't') {
|
|
||||||
s.append('\t');
|
|
||||||
} else if (c == 'u') {
|
|
||||||
int remainingLength = json.size() - index;
|
|
||||||
if (remainingLength >= 4) {
|
|
||||||
QString unicodeStr = json.mid(index, 4);
|
|
||||||
|
|
||||||
int symbol = unicodeStr.toInt(0, 16);
|
|
||||||
|
|
||||||
s.append(QChar(symbol));
|
|
||||||
|
|
||||||
index += 4;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
s.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!complete) {
|
|
||||||
success = false;
|
|
||||||
return QVariant();
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariant(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* parseNumber
|
|
||||||
*/
|
|
||||||
static QVariant parseNumber(const QString &json, int &index) {
|
|
||||||
eatWhitespace(json, index);
|
|
||||||
|
|
||||||
int lastIndex = lastIndexOfNumber(json, index);
|
|
||||||
int charLength = (lastIndex - index) + 1;
|
|
||||||
QString numberStr;
|
|
||||||
|
|
||||||
numberStr = json.mid(index, charLength);
|
|
||||||
|
|
||||||
index = lastIndex + 1;
|
|
||||||
bool ok;
|
|
||||||
|
|
||||||
if (numberStr.contains('.')) {
|
|
||||||
return QVariant(numberStr.toDouble(NULL));
|
|
||||||
} else if (numberStr.startsWith('-')) {
|
|
||||||
int i = numberStr.toInt(&ok);
|
|
||||||
if (!ok) {
|
|
||||||
qlonglong ll = numberStr.toLongLong(&ok);
|
|
||||||
return ok ? ll : QVariant(numberStr);
|
|
||||||
}
|
|
||||||
return i;
|
|
||||||
} else {
|
|
||||||
uint u = numberStr.toUInt(&ok);
|
|
||||||
if (!ok) {
|
|
||||||
qulonglong ull = numberStr.toULongLong(&ok);
|
|
||||||
return ok ? ull : QVariant(numberStr);
|
|
||||||
}
|
|
||||||
return u;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* lastIndexOfNumber
|
|
||||||
*/
|
|
||||||
static int lastIndexOfNumber(const QString &json, int index) {
|
|
||||||
int lastIndex;
|
|
||||||
|
|
||||||
for(lastIndex = index; lastIndex < json.size(); lastIndex++) {
|
|
||||||
if (QString("0123456789+-.eE").indexOf(json[lastIndex]) == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return lastIndex -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* eatWhitespace
|
|
||||||
*/
|
|
||||||
static void eatWhitespace(const QString &json, int &index) {
|
|
||||||
for(; index < json.size(); index++) {
|
|
||||||
if (QString(" \t\n\r").indexOf(json[index]) == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* lookAhead
|
|
||||||
*/
|
|
||||||
static int lookAhead(const QString &json, int index) {
|
|
||||||
int saveIndex = index;
|
|
||||||
return nextToken(json, saveIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* nextToken
|
|
||||||
*/
|
|
||||||
static int nextToken(const QString &json, int &index) {
|
|
||||||
eatWhitespace(json, index);
|
|
||||||
|
|
||||||
if (index == json.size()) {
|
|
||||||
return JsonTokenNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
QChar c = json[index];
|
|
||||||
index++;
|
|
||||||
switch(c.toLatin1()) {
|
|
||||||
case '{': return JsonTokenCurlyOpen;
|
|
||||||
case '}': return JsonTokenCurlyClose;
|
|
||||||
case '[': return JsonTokenSquaredOpen;
|
|
||||||
case ']': return JsonTokenSquaredClose;
|
|
||||||
case ',': return JsonTokenComma;
|
|
||||||
case '"': return JsonTokenString;
|
|
||||||
case '0': case '1': case '2': case '3': case '4':
|
|
||||||
case '5': case '6': case '7': case '8': case '9':
|
|
||||||
case '-': return JsonTokenNumber;
|
|
||||||
case ':': return JsonTokenColon;
|
|
||||||
}
|
|
||||||
index--; // ^ WTF?
|
|
||||||
|
|
||||||
int remainingLength = json.size() - index;
|
|
||||||
|
|
||||||
// True
|
|
||||||
if (remainingLength >= 4) {
|
|
||||||
if (json[index] == 't' && json[index + 1] == 'r' &&
|
|
||||||
json[index + 2] == 'u' && json[index + 3] == 'e') {
|
|
||||||
index += 4;
|
|
||||||
return JsonTokenTrue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// False
|
|
||||||
if (remainingLength >= 5) {
|
|
||||||
if (json[index] == 'f' && json[index + 1] == 'a' &&
|
|
||||||
json[index + 2] == 'l' && json[index + 3] == 's' &&
|
|
||||||
json[index + 4] == 'e') {
|
|
||||||
index += 5;
|
|
||||||
return JsonTokenFalse;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Null
|
|
||||||
if (remainingLength >= 4) {
|
|
||||||
if (json[index] == 'n' && json[index + 1] == 'u' &&
|
|
||||||
json[index + 2] == 'l' && json[index + 3] == 'l') {
|
|
||||||
index += 4;
|
|
||||||
return JsonTokenNull;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return JsonTokenNone;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDateTimeFormat(const QString &format) {
|
|
||||||
dateTimeFormat = format;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setDateFormat(const QString &format) {
|
|
||||||
dateFormat = format;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getDateTimeFormat() {
|
|
||||||
return dateTimeFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getDateFormat() {
|
|
||||||
return dateFormat;
|
|
||||||
}
|
|
||||||
|
|
||||||
} //end namespace
|
|
@ -1,178 +0,0 @@
|
|||||||
/**
|
|
||||||
* QtJson - A simple class for parsing JSON data into a QVariant hierarchies and vice-versa.
|
|
||||||
* Copyright (C) 2011 Eeli Reilin
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \file json.h
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef JSON_H
|
|
||||||
#define JSON_H
|
|
||||||
|
|
||||||
#include <QVariant>
|
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \namespace QtJson
|
|
||||||
* \brief A JSON data parser
|
|
||||||
*
|
|
||||||
* Json parses a JSON data into a QVariant hierarchy.
|
|
||||||
*/
|
|
||||||
namespace QtJson {
|
|
||||||
typedef QVariantMap JsonObject;
|
|
||||||
typedef QVariantList JsonArray;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clone a JSON object (makes a deep copy)
|
|
||||||
*
|
|
||||||
* \param data The JSON object
|
|
||||||
*/
|
|
||||||
QVariant clone(const QVariant &data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insert value to JSON object (QVariantMap)
|
|
||||||
*
|
|
||||||
* \param v The JSON object
|
|
||||||
* \param key The key
|
|
||||||
* \param value The value
|
|
||||||
*/
|
|
||||||
void insert(QVariant &v, const QString &key, const QVariant &value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Append value to JSON array (QVariantList)
|
|
||||||
*
|
|
||||||
* \param v The JSON array
|
|
||||||
* \param value The value
|
|
||||||
*/
|
|
||||||
void append(QVariant &v, const QVariant &value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a JSON string
|
|
||||||
*
|
|
||||||
* \param json The JSON data
|
|
||||||
*/
|
|
||||||
QVariant parse(const QString &json);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse a JSON string
|
|
||||||
*
|
|
||||||
* \param json The JSON data
|
|
||||||
* \param success The success of the parsing
|
|
||||||
*/
|
|
||||||
QVariant parse(const QString &json, bool &success);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method generates a textual JSON representation
|
|
||||||
*
|
|
||||||
* \param data The JSON data generated by the parser.
|
|
||||||
*
|
|
||||||
* \return QByteArray Textual JSON representation in UTF-8
|
|
||||||
*/
|
|
||||||
QByteArray serialize(const QVariant &data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method generates a textual JSON representation
|
|
||||||
*
|
|
||||||
* \param data The JSON data generated by the parser.
|
|
||||||
* \param success The success of the serialization
|
|
||||||
*
|
|
||||||
* \return QByteArray Textual JSON representation in UTF-8
|
|
||||||
*/
|
|
||||||
QByteArray serialize(const QVariant &data, bool &success);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method generates a textual JSON representation
|
|
||||||
*
|
|
||||||
* \param data The JSON data generated by the parser.
|
|
||||||
*
|
|
||||||
* \return QString Textual JSON representation
|
|
||||||
*/
|
|
||||||
QString serializeStr(const QVariant &data);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method generates a textual JSON representation
|
|
||||||
*
|
|
||||||
* \param data The JSON data generated by the parser.
|
|
||||||
* \param success The success of the serialization
|
|
||||||
*
|
|
||||||
* \return QString Textual JSON representation
|
|
||||||
*/
|
|
||||||
QString serializeStr(const QVariant &data, bool &success);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method sets date(time) format to be used for QDateTime::toString
|
|
||||||
* If QString is empty, Qt::TextDate is used.
|
|
||||||
*
|
|
||||||
* \param format The JSON data generated by the parser.
|
|
||||||
*/
|
|
||||||
void setDateTimeFormat(const QString& format);
|
|
||||||
void setDateFormat(const QString& format);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method gets date(time) format to be used for QDateTime::toString
|
|
||||||
* If QString is empty, Qt::TextDate is used.
|
|
||||||
*/
|
|
||||||
QString getDateTimeFormat();
|
|
||||||
QString getDateFormat();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* QVariant based Json object
|
|
||||||
*/
|
|
||||||
class Object : public QVariant {
|
|
||||||
template<typename T>
|
|
||||||
Object& insertKey(Object* ptr, const QString& key) {
|
|
||||||
T* p = (T*)ptr->data();
|
|
||||||
if (!p->contains(key)) p->insert(key, QVariant());
|
|
||||||
return *reinterpret_cast<Object*>(&p->operator[](key));
|
|
||||||
}
|
|
||||||
template<typename T>
|
|
||||||
void removeKey(Object *ptr, const QString& key) {
|
|
||||||
T* p = (T*)ptr->data();
|
|
||||||
p->remove(key);
|
|
||||||
}
|
|
||||||
public:
|
|
||||||
Object() : QVariant() {}
|
|
||||||
Object(const Object& ref) : QVariant(ref) {}
|
|
||||||
|
|
||||||
Object& operator=(const QVariant& rhs) {
|
|
||||||
setValue(rhs);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
Object& operator[](const QString& key) {
|
|
||||||
if (type() == QVariant::Map)
|
|
||||||
return insertKey<QVariantMap>(this, key);
|
|
||||||
else if (type() == QVariant::Hash)
|
|
||||||
return insertKey<QVariantHash>(this, key);
|
|
||||||
|
|
||||||
setValue(QVariantMap());
|
|
||||||
|
|
||||||
return insertKey<QVariantMap>(this, key);
|
|
||||||
}
|
|
||||||
const Object& operator[](const QString& key) const {
|
|
||||||
return const_cast<Object*>(this)->operator[](key);
|
|
||||||
}
|
|
||||||
void remove(const QString& key) {
|
|
||||||
if (type() == QVariant::Map)
|
|
||||||
removeKey<QVariantMap>(this, key);
|
|
||||||
else if (type() == QVariant::Hash)
|
|
||||||
removeKey<QVariantHash>(this, key);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //JSON_H
|
|
@ -26,6 +26,8 @@
|
|||||||
#include "services/owncloud/owncloudcategory.h"
|
#include "services/owncloud/owncloudcategory.h"
|
||||||
#include "services/owncloud/owncloudfeed.h"
|
#include "services/owncloud/owncloudfeed.h"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
|
|
||||||
|
|
||||||
@ -246,8 +248,8 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::triggerFeedUpdate(int feed_i
|
|||||||
QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status,
|
QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status,
|
||||||
const QStringList &custom_ids) {
|
const QStringList &custom_ids) {
|
||||||
QList<QVariant> var_ids;
|
QList<QVariant> var_ids;
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
QtJson::JsonArray ids;
|
QJsonArray ids;
|
||||||
QByteArray raw_output;
|
QByteArray raw_output;
|
||||||
|
|
||||||
QString final_url;
|
QString final_url;
|
||||||
@ -263,13 +265,13 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesRead(RootItem::R
|
|||||||
var_ids.append(id.toInt());
|
var_ids.append(id.toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
ids.append(var_ids);
|
ids.append(QJsonArray::fromVariantList(var_ids));
|
||||||
json["items"] = ids;
|
json["items"] = ids;
|
||||||
|
|
||||||
NetworkResult network_reply = NetworkFactory::uploadData(final_url,
|
NetworkResult network_reply = NetworkFactory::uploadData(final_url,
|
||||||
qApp->settings()->value(GROUP(Feeds),
|
qApp->settings()->value(GROUP(Feeds),
|
||||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||||
QtJson::serialize(json),
|
QJsonDocument(json).toJson(),
|
||||||
"application/json",
|
"application/json",
|
||||||
raw_output,
|
raw_output,
|
||||||
QNetworkAccessManager::PutOperation,
|
QNetworkAccessManager::PutOperation,
|
||||||
@ -286,8 +288,8 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesRead(RootItem::R
|
|||||||
QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance,
|
QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance,
|
||||||
const QStringList &feed_ids,
|
const QStringList &feed_ids,
|
||||||
const QStringList &guid_hashes) {
|
const QStringList &guid_hashes) {
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
QtJson::JsonArray ids;
|
QJsonArray ids;
|
||||||
QByteArray raw_output;
|
QByteArray raw_output;
|
||||||
|
|
||||||
QString final_url;
|
QString final_url;
|
||||||
@ -304,7 +306,7 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesStarred(RootItem
|
|||||||
item.insert(QSL("feedId"), feed_ids.at(i));
|
item.insert(QSL("feedId"), feed_ids.at(i));
|
||||||
item.insert(QSL("guidHash"), guid_hashes.at(i));
|
item.insert(QSL("guidHash"), guid_hashes.at(i));
|
||||||
|
|
||||||
ids.append(item);
|
ids.append(QJsonValue::fromVariant(item));
|
||||||
}
|
}
|
||||||
|
|
||||||
json["items"] = ids;
|
json["items"] = ids;
|
||||||
@ -312,7 +314,7 @@ QNetworkReply::NetworkError OwnCloudNetworkFactory::markMessagesStarred(RootItem
|
|||||||
NetworkResult network_reply = NetworkFactory::uploadData(final_url,
|
NetworkResult network_reply = NetworkFactory::uploadData(final_url,
|
||||||
qApp->settings()->value(GROUP(Feeds),
|
qApp->settings()->value(GROUP(Feeds),
|
||||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||||
QtJson::serialize(json),
|
QJsonDocument(json).toJson(),
|
||||||
"application/json",
|
"application/json",
|
||||||
raw_output,
|
raw_output,
|
||||||
QNetworkAccessManager::PutOperation,
|
QNetworkAccessManager::PutOperation,
|
||||||
@ -335,18 +337,18 @@ void OwnCloudNetworkFactory::setUserId(const QString &userId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
OwnCloudResponse::OwnCloudResponse(const QString &raw_content) {
|
OwnCloudResponse::OwnCloudResponse(const QString &raw_content) {
|
||||||
m_rawContent = QtJson::parse(raw_content).toMap();
|
m_rawContent = QJsonDocument::fromJson(raw_content.toUtf8());;
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnCloudResponse::~OwnCloudResponse() {
|
OwnCloudResponse::~OwnCloudResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OwnCloudResponse::isLoaded() const {
|
bool OwnCloudResponse::isLoaded() const {
|
||||||
return !m_rawContent.empty();
|
return !m_rawContent.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString OwnCloudResponse::toString() const {
|
QString OwnCloudResponse::toString() const {
|
||||||
return QtJson::serializeStr(m_rawContent);
|
return m_rawContent.toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
OwnCloudUserResponse::OwnCloudUserResponse(const QString &raw_content) : OwnCloudResponse(raw_content) {
|
OwnCloudUserResponse::OwnCloudUserResponse(const QString &raw_content) : OwnCloudResponse(raw_content) {
|
||||||
@ -357,7 +359,7 @@ OwnCloudUserResponse::~OwnCloudUserResponse() {
|
|||||||
|
|
||||||
QString OwnCloudUserResponse::displayName() const {
|
QString OwnCloudUserResponse::displayName() const {
|
||||||
if (isLoaded()) {
|
if (isLoaded()) {
|
||||||
return m_rawContent["displayName"].toString();
|
return m_rawContent.object()["displayName"].toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QString();
|
return QString();
|
||||||
@ -366,7 +368,7 @@ QString OwnCloudUserResponse::displayName() const {
|
|||||||
|
|
||||||
QString OwnCloudUserResponse::userId() const {
|
QString OwnCloudUserResponse::userId() const {
|
||||||
if (isLoaded()) {
|
if (isLoaded()) {
|
||||||
return m_rawContent["userId"].toString();
|
return m_rawContent.object()["userId"].toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QString();
|
return QString();
|
||||||
@ -375,7 +377,7 @@ QString OwnCloudUserResponse::userId() const {
|
|||||||
|
|
||||||
QDateTime OwnCloudUserResponse::lastLoginTime() const {
|
QDateTime OwnCloudUserResponse::lastLoginTime() const {
|
||||||
if (isLoaded()) {
|
if (isLoaded()) {
|
||||||
return QDateTime::fromMSecsSinceEpoch(m_rawContent["lastLoginTimestamp"].value<qint64>());
|
return QDateTime::fromMSecsSinceEpoch(m_rawContent.object()["lastLoginTimestamp"].toVariant().value<qint64>());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QDateTime();
|
return QDateTime();
|
||||||
@ -384,7 +386,7 @@ QDateTime OwnCloudUserResponse::lastLoginTime() const {
|
|||||||
|
|
||||||
QIcon OwnCloudUserResponse::avatar() const {
|
QIcon OwnCloudUserResponse::avatar() const {
|
||||||
if (isLoaded()) {
|
if (isLoaded()) {
|
||||||
QString image_data = m_rawContent["avatar"].toMap()["data"].toString();
|
QString image_data = m_rawContent.object()["avatar"].toObject()["data"].toString();
|
||||||
QByteArray decoded_data = QByteArray::fromBase64(image_data.toLocal8Bit());
|
QByteArray decoded_data = QByteArray::fromBase64(image_data.toLocal8Bit());
|
||||||
QPixmap image;
|
QPixmap image;
|
||||||
|
|
||||||
@ -405,7 +407,7 @@ OwnCloudStatusResponse::~OwnCloudStatusResponse() {
|
|||||||
|
|
||||||
QString OwnCloudStatusResponse::version() const {
|
QString OwnCloudStatusResponse::version() const {
|
||||||
if (isLoaded()) {
|
if (isLoaded()) {
|
||||||
return m_rawContent["version"].toString();
|
return m_rawContent.object()["version"].toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QString();
|
return QString();
|
||||||
@ -414,7 +416,7 @@ QString OwnCloudStatusResponse::version() const {
|
|||||||
|
|
||||||
bool OwnCloudStatusResponse::misconfiguredCron() const {
|
bool OwnCloudStatusResponse::misconfiguredCron() const {
|
||||||
if (isLoaded()) {
|
if (isLoaded()) {
|
||||||
return m_rawContent["warnings"].toMap()["improperlyConfiguredCron"].toBool();
|
return m_rawContent.object()["warnings"].toObject()["improperlyConfiguredCron"].toBool();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
@ -437,7 +439,7 @@ RootItem *OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
|
|||||||
cats.insert(0, parent);
|
cats.insert(0, parent);
|
||||||
|
|
||||||
// Process categories first, then process feeds.
|
// Process categories first, then process feeds.
|
||||||
foreach (QVariant cat, QtJson::parse(m_contentCategories).toMap()["folders"].toList()) {
|
foreach (QVariant cat, QJsonDocument::fromJson(m_contentCategories.toUtf8()).object()["folders"].toArray().toVariantList()) {
|
||||||
QMap<QString,QVariant> item = cat.toMap();
|
QMap<QString,QVariant> item = cat.toMap();
|
||||||
OwnCloudCategory *category = new OwnCloudCategory();
|
OwnCloudCategory *category = new OwnCloudCategory();
|
||||||
|
|
||||||
@ -451,7 +453,7 @@ RootItem *OwnCloudGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We have categories added, now add all feeds.
|
// We have categories added, now add all feeds.
|
||||||
foreach (QVariant fed, QtJson::parse(m_contentFeeds).toMap()["feeds"].toList()) {
|
foreach (QVariant fed, QJsonDocument::fromJson(m_contentFeeds.toUtf8()).object()["feeds"].toArray().toVariantList()) {
|
||||||
QMap<QString,QVariant> item = fed.toMap();
|
QMap<QString,QVariant> item = fed.toMap();
|
||||||
OwnCloudFeed *feed = new OwnCloudFeed();
|
OwnCloudFeed *feed = new OwnCloudFeed();
|
||||||
|
|
||||||
@ -490,7 +492,7 @@ OwnCloudGetMessagesResponse::~OwnCloudGetMessagesResponse() {
|
|||||||
QList<Message> OwnCloudGetMessagesResponse::messages() const {
|
QList<Message> OwnCloudGetMessagesResponse::messages() const {
|
||||||
QList<Message> msgs;
|
QList<Message> msgs;
|
||||||
|
|
||||||
foreach (QVariant message, m_rawContent["items"].toList()) {
|
foreach (QVariant message, m_rawContent.object()["items"].toArray().toVariantList()) {
|
||||||
QMap<QString,QVariant> message_map = message.toMap();
|
QMap<QString,QVariant> message_map = message.toMap();
|
||||||
Message msg;
|
Message msg;
|
||||||
|
|
||||||
|
@ -18,14 +18,14 @@
|
|||||||
#ifndef OWNCLOUDNETWORKFACTORY_H
|
#ifndef OWNCLOUDNETWORKFACTORY_H
|
||||||
#define OWNCLOUDNETWORKFACTORY_H
|
#define OWNCLOUDNETWORKFACTORY_H
|
||||||
|
|
||||||
|
#include "core/message.h"
|
||||||
|
#include "services/abstract/rootitem.h"
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QJsonDocument>
|
||||||
#include "qt-json/json.h"
|
|
||||||
#include "core/message.h"
|
|
||||||
#include "services/abstract/rootitem.h"
|
|
||||||
|
|
||||||
|
|
||||||
class OwnCloudResponse {
|
class OwnCloudResponse {
|
||||||
@ -37,7 +37,7 @@ class OwnCloudResponse {
|
|||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QtJson::JsonObject m_rawContent;
|
QJsonDocument m_rawContent;
|
||||||
};
|
};
|
||||||
|
|
||||||
class OwnCloudUserResponse : public OwnCloudResponse {
|
class OwnCloudUserResponse : public OwnCloudResponse {
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
#include "miscellaneous/textfactory.h"
|
#include "miscellaneous/textfactory.h"
|
||||||
#include "network-web/networkfactory.h"
|
#include "network-web/networkfactory.h"
|
||||||
|
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
@ -79,7 +81,7 @@ TtRssLoginResponse TtRssNetworkFactory::login() {
|
|||||||
logout();
|
logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
json["op"] = "login";
|
json["op"] = "login";
|
||||||
json["user"] = m_username;
|
json["user"] = m_username;
|
||||||
json["password"] = m_password;
|
json["password"] = m_password;
|
||||||
@ -87,7 +89,7 @@ TtRssLoginResponse TtRssNetworkFactory::login() {
|
|||||||
QByteArray result_raw;
|
QByteArray result_raw;
|
||||||
NetworkResult network_reply = NetworkFactory::uploadData(m_url, qApp->settings()->value(GROUP(Feeds),
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, qApp->settings()->value(GROUP(Feeds),
|
||||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||||
QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
QJsonDocument(json).toJson(), CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
TtRssLoginResponse login_response(QString::fromUtf8(result_raw));
|
TtRssLoginResponse login_response(QString::fromUtf8(result_raw));
|
||||||
@ -107,14 +109,14 @@ TtRssLoginResponse TtRssNetworkFactory::login() {
|
|||||||
TtRssResponse TtRssNetworkFactory::logout() {
|
TtRssResponse TtRssNetworkFactory::logout() {
|
||||||
if (!m_sessionId.isEmpty()) {
|
if (!m_sessionId.isEmpty()) {
|
||||||
|
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
json["op"] = "logout";
|
json["op"] = "logout";
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
|
|
||||||
QByteArray result_raw;
|
QByteArray result_raw;
|
||||||
NetworkResult network_reply = NetworkFactory::uploadData(m_url, qApp->settings()->value(GROUP(Feeds),
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, qApp->settings()->value(GROUP(Feeds),
|
||||||
SETTING(Feeds::UpdateTimeout)).toInt(),
|
SETTING(Feeds::UpdateTimeout)).toInt(),
|
||||||
QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
QJsonDocument(json).toJson(), CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
|
|
||||||
@ -138,14 +140,15 @@ TtRssResponse TtRssNetworkFactory::logout() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TtRssGetFeedsCategoriesResponse TtRssNetworkFactory::getFeedsCategories() {
|
TtRssGetFeedsCategoriesResponse TtRssNetworkFactory::getFeedsCategories() {
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
json["op"] = "getFeedTree";
|
json["op"] = "getFeedTree";
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
json["include_empty"] = true;
|
json["include_empty"] = true;
|
||||||
|
|
||||||
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
QByteArray result_raw;
|
QByteArray result_raw;
|
||||||
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(QJsonDocument::Compact),
|
||||||
|
CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
TtRssGetFeedsCategoriesResponse result(QString::fromUtf8(result_raw));
|
TtRssGetFeedsCategoriesResponse result(QString::fromUtf8(result_raw));
|
||||||
@ -155,7 +158,7 @@ TtRssGetFeedsCategoriesResponse TtRssNetworkFactory::getFeedsCategories() {
|
|||||||
login();
|
login();
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
|
|
||||||
network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(), CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
result = TtRssGetFeedsCategoriesResponse(QString::fromUtf8(result_raw));
|
result = TtRssGetFeedsCategoriesResponse(QString::fromUtf8(result_raw));
|
||||||
@ -172,7 +175,7 @@ TtRssGetFeedsCategoriesResponse TtRssNetworkFactory::getFeedsCategories() {
|
|||||||
TtRssGetHeadlinesResponse TtRssNetworkFactory::getHeadlines(int feed_id, int limit, int skip,
|
TtRssGetHeadlinesResponse TtRssNetworkFactory::getHeadlines(int feed_id, int limit, int skip,
|
||||||
bool show_content, bool include_attachments,
|
bool show_content, bool include_attachments,
|
||||||
bool sanitize) {
|
bool sanitize) {
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
json["op"] = "getHeadlines";
|
json["op"] = "getHeadlines";
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
json["feed_id"] = feed_id;
|
json["feed_id"] = feed_id;
|
||||||
@ -185,7 +188,8 @@ TtRssGetHeadlinesResponse TtRssNetworkFactory::getHeadlines(int feed_id, int lim
|
|||||||
|
|
||||||
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
QByteArray result_raw;
|
QByteArray result_raw;
|
||||||
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(),
|
||||||
|
CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
TtRssGetHeadlinesResponse result(QString::fromUtf8(result_raw));
|
TtRssGetHeadlinesResponse result(QString::fromUtf8(result_raw));
|
||||||
@ -195,7 +199,7 @@ TtRssGetHeadlinesResponse TtRssNetworkFactory::getHeadlines(int feed_id, int lim
|
|||||||
login();
|
login();
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
|
|
||||||
network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(), CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
result = TtRssGetHeadlinesResponse(QString::fromUtf8(result_raw));
|
result = TtRssGetHeadlinesResponse(QString::fromUtf8(result_raw));
|
||||||
@ -212,7 +216,7 @@ TtRssGetHeadlinesResponse TtRssNetworkFactory::getHeadlines(int feed_id, int lim
|
|||||||
TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList &ids,
|
TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList &ids,
|
||||||
UpdateArticle::OperatingField field,
|
UpdateArticle::OperatingField field,
|
||||||
UpdateArticle::Mode mode) {
|
UpdateArticle::Mode mode) {
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
json["op"] = "updateArticle";
|
json["op"] = "updateArticle";
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
json["article_ids"] = ids.join(QSL(","));
|
json["article_ids"] = ids.join(QSL(","));
|
||||||
@ -221,7 +225,8 @@ TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList
|
|||||||
|
|
||||||
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
QByteArray result_raw;
|
QByteArray result_raw;
|
||||||
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(),
|
||||||
|
CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
TtRssUpdateArticleResponse result(QString::fromUtf8(result_raw));
|
TtRssUpdateArticleResponse result(QString::fromUtf8(result_raw));
|
||||||
@ -231,7 +236,8 @@ TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList
|
|||||||
login();
|
login();
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
|
|
||||||
network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(),
|
||||||
|
CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
result = TtRssUpdateArticleResponse(QString::fromUtf8(result_raw));
|
result = TtRssUpdateArticleResponse(QString::fromUtf8(result_raw));
|
||||||
@ -248,7 +254,7 @@ TtRssUpdateArticleResponse TtRssNetworkFactory::updateArticles(const QStringList
|
|||||||
TtRssSubscribeToFeedResponse TtRssNetworkFactory::subscribeToFeed(const QString &url, int category_id,
|
TtRssSubscribeToFeedResponse TtRssNetworkFactory::subscribeToFeed(const QString &url, int category_id,
|
||||||
bool protectd, const QString &username,
|
bool protectd, const QString &username,
|
||||||
const QString &password) {
|
const QString &password) {
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
json["op"] = "subscribeToFeed";
|
json["op"] = "subscribeToFeed";
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
json["feed_url"] = url;
|
json["feed_url"] = url;
|
||||||
@ -261,7 +267,8 @@ TtRssSubscribeToFeedResponse TtRssNetworkFactory::subscribeToFeed(const QString
|
|||||||
|
|
||||||
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
QByteArray result_raw;
|
QByteArray result_raw;
|
||||||
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(),
|
||||||
|
CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
TtRssSubscribeToFeedResponse result(QString::fromUtf8(result_raw));
|
TtRssSubscribeToFeedResponse result(QString::fromUtf8(result_raw));
|
||||||
@ -271,7 +278,8 @@ TtRssSubscribeToFeedResponse TtRssNetworkFactory::subscribeToFeed(const QString
|
|||||||
login();
|
login();
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
|
|
||||||
network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(),
|
||||||
|
CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
result = TtRssSubscribeToFeedResponse(QString::fromUtf8(result_raw));
|
result = TtRssSubscribeToFeedResponse(QString::fromUtf8(result_raw));
|
||||||
@ -286,14 +294,14 @@ TtRssSubscribeToFeedResponse TtRssNetworkFactory::subscribeToFeed(const QString
|
|||||||
}
|
}
|
||||||
|
|
||||||
TtRssUnsubscribeFeedResponse TtRssNetworkFactory::unsubscribeFeed(int feed_id) {
|
TtRssUnsubscribeFeedResponse TtRssNetworkFactory::unsubscribeFeed(int feed_id) {
|
||||||
QtJson::JsonObject json;
|
QJsonObject json;
|
||||||
json["op"] = "unsubscribeFeed";
|
json["op"] = "unsubscribeFeed";
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
json["feed_id"] = feed_id;
|
json["feed_id"] = feed_id;
|
||||||
|
|
||||||
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
const int timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
|
||||||
QByteArray result_raw;
|
QByteArray result_raw;
|
||||||
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
NetworkResult network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(), CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
TtRssUnsubscribeFeedResponse result(QString::fromUtf8(result_raw));
|
TtRssUnsubscribeFeedResponse result(QString::fromUtf8(result_raw));
|
||||||
@ -303,7 +311,7 @@ TtRssUnsubscribeFeedResponse TtRssNetworkFactory::unsubscribeFeed(int feed_id) {
|
|||||||
login();
|
login();
|
||||||
json["sid"] = m_sessionId;
|
json["sid"] = m_sessionId;
|
||||||
|
|
||||||
network_reply = NetworkFactory::uploadData(m_url, timeout, QtJson::serialize(json), CONTENT_TYPE, result_raw,
|
network_reply = NetworkFactory::uploadData(m_url, timeout, QJsonDocument(json).toJson(), CONTENT_TYPE, result_raw,
|
||||||
QNetworkAccessManager::PostOperation,
|
QNetworkAccessManager::PostOperation,
|
||||||
m_authIsUsed, m_authUsername, m_authPassword);
|
m_authIsUsed, m_authUsername, m_authPassword);
|
||||||
result = TtRssUnsubscribeFeedResponse(QString::fromUtf8(result_raw));
|
result = TtRssUnsubscribeFeedResponse(QString::fromUtf8(result_raw));
|
||||||
@ -350,14 +358,14 @@ void TtRssNetworkFactory::setAuthPassword(const QString &auth_password) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TtRssResponse::TtRssResponse(const QString &raw_content) {
|
TtRssResponse::TtRssResponse(const QString &raw_content) {
|
||||||
m_rawContent = QtJson::parse(raw_content).toMap();
|
m_rawContent = QJsonDocument::fromJson(raw_content.toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
TtRssResponse::~TtRssResponse() {
|
TtRssResponse::~TtRssResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TtRssResponse::isLoaded() const {
|
bool TtRssResponse::isLoaded() const {
|
||||||
return !m_rawContent.empty();
|
return !m_rawContent.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
int TtRssResponse::seq() const {
|
int TtRssResponse::seq() const {
|
||||||
@ -365,7 +373,7 @@ int TtRssResponse::seq() const {
|
|||||||
return CONTENT_NOT_LOADED;
|
return CONTENT_NOT_LOADED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return m_rawContent["seq"].toInt();
|
return m_rawContent.object()["seq"].toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +382,7 @@ int TtRssResponse::status() const {
|
|||||||
return CONTENT_NOT_LOADED;
|
return CONTENT_NOT_LOADED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return m_rawContent["status"].toInt();
|
return m_rawContent.object()["status"].toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,7 +391,7 @@ bool TtRssResponse::isNotLoggedIn() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString TtRssResponse::toString() const {
|
QString TtRssResponse::toString() const {
|
||||||
return QtJson::serializeStr(m_rawContent);
|
return m_rawContent.toJson();
|
||||||
}
|
}
|
||||||
|
|
||||||
TtRssLoginResponse::TtRssLoginResponse(const QString &raw_content) : TtRssResponse(raw_content) {
|
TtRssLoginResponse::TtRssLoginResponse(const QString &raw_content) : TtRssResponse(raw_content) {
|
||||||
@ -397,7 +405,7 @@ int TtRssLoginResponse::apiLevel() const {
|
|||||||
return CONTENT_NOT_LOADED;
|
return CONTENT_NOT_LOADED;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return m_rawContent["content"].toMap()["api_level"].toInt();
|
return m_rawContent.object()["content"].toObject()["api_level"].toInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,7 +414,7 @@ QString TtRssLoginResponse::sessionId() const {
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return m_rawContent["content"].toMap()["session_id"].toString();
|
return m_rawContent.object()["content"].toObject()["session_id"].toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +423,7 @@ QString TtRssResponse::error() const {
|
|||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return m_rawContent["content"].toMap()["error"].toString();
|
return m_rawContent.object()["content"].toObject()["error"].toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,7 +432,7 @@ bool TtRssResponse::hasError() const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return m_rawContent["content"].toMap().contains("error");
|
return m_rawContent.object()["content"].toObject().contains("error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +454,7 @@ RootItem *TtRssGetFeedsCategoriesResponse::feedsCategories(bool obtain_icons, QS
|
|||||||
|
|
||||||
if (status() == API_STATUS_OK) {
|
if (status() == API_STATUS_OK) {
|
||||||
// We have data, construct object tree according to data.
|
// We have data, construct object tree according to data.
|
||||||
QList<QVariant> items_to_process = m_rawContent["content"].toMap()["categories"].toMap()["items"].toList();
|
QList<QVariant> items_to_process = m_rawContent.object()["content"].toObject()["categories"].toObject()["items"].toArray().toVariantList();
|
||||||
QList<QPair<RootItem*,QVariant> > pairs;
|
QList<QPair<RootItem*,QVariant> > pairs;
|
||||||
|
|
||||||
foreach (QVariant item, items_to_process) {
|
foreach (QVariant item, items_to_process) {
|
||||||
@ -527,7 +535,7 @@ TtRssGetHeadlinesResponse::~TtRssGetHeadlinesResponse() {
|
|||||||
QList<Message> TtRssGetHeadlinesResponse::messages() const {
|
QList<Message> TtRssGetHeadlinesResponse::messages() const {
|
||||||
QList<Message> messages;
|
QList<Message> messages;
|
||||||
|
|
||||||
foreach (QVariant item, m_rawContent["content"].toList()) {
|
foreach (QVariant item, m_rawContent.object()["content"].toArray().toVariantList()) {
|
||||||
QMap<QString,QVariant> mapped = item.toMap();
|
QMap<QString,QVariant> mapped = item.toMap();
|
||||||
Message message;
|
Message message;
|
||||||
|
|
||||||
@ -571,8 +579,8 @@ TtRssUpdateArticleResponse::~TtRssUpdateArticleResponse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString TtRssUpdateArticleResponse::updateStatus() const {
|
QString TtRssUpdateArticleResponse::updateStatus() const {
|
||||||
if (m_rawContent.contains(QSL("content"))) {
|
if (m_rawContent.object().contains(QSL("content"))) {
|
||||||
return m_rawContent["content"].toMap()["status"].toString();
|
return m_rawContent.object()["content"].toObject()["status"].toString();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return QString();
|
return QString();
|
||||||
@ -580,8 +588,8 @@ QString TtRssUpdateArticleResponse::updateStatus() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TtRssUpdateArticleResponse::articlesUpdated() const {
|
int TtRssUpdateArticleResponse::articlesUpdated() const {
|
||||||
if (m_rawContent.contains(QSL("content"))) {
|
if (m_rawContent.object().contains(QSL("content"))) {
|
||||||
return m_rawContent["content"].toMap()["updated"].toInt();
|
return m_rawContent.object()["content"].toObject()["updated"].toInt();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return 0;
|
return 0;
|
||||||
@ -595,8 +603,8 @@ TtRssSubscribeToFeedResponse::~TtRssSubscribeToFeedResponse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int TtRssSubscribeToFeedResponse::code() const {
|
int TtRssSubscribeToFeedResponse::code() const {
|
||||||
if (m_rawContent.contains(QSL("content"))) {
|
if (m_rawContent.object().contains(QSL("content"))) {
|
||||||
return m_rawContent["content"].toMap()["status"].toMap()["code"].toInt();
|
return m_rawContent.object()["content"].toObject()["status"].toObject()["code"].toInt();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return STF_UNKNOWN;
|
return STF_UNKNOWN;
|
||||||
@ -611,8 +619,8 @@ TtRssUnsubscribeFeedResponse::~TtRssUnsubscribeFeedResponse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
QString TtRssUnsubscribeFeedResponse::code() const {
|
QString TtRssUnsubscribeFeedResponse::code() const {
|
||||||
if (m_rawContent.contains(QSL("content"))) {
|
if (m_rawContent.object().contains(QSL("content"))) {
|
||||||
QVariantMap map = m_rawContent["content"].toMap();
|
QJsonObject map = m_rawContent.object()["content"].toObject();
|
||||||
|
|
||||||
if (map.contains(QSL("error"))) {
|
if (map.contains(QSL("error"))) {
|
||||||
return map["error"].toString();
|
return map["error"].toString();
|
||||||
|
@ -18,13 +18,12 @@
|
|||||||
#ifndef TTRSSNETWORKFACTORY_H
|
#ifndef TTRSSNETWORKFACTORY_H
|
||||||
#define TTRSSNETWORKFACTORY_H
|
#define TTRSSNETWORKFACTORY_H
|
||||||
|
|
||||||
#include "qt-json/json.h"
|
|
||||||
|
|
||||||
#include "core/message.h"
|
#include "core/message.h"
|
||||||
|
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QNetworkReply>
|
#include <QNetworkReply>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
|
|
||||||
class RootItem;
|
class RootItem;
|
||||||
@ -45,7 +44,7 @@ class TtRssResponse {
|
|||||||
QString toString() const;
|
QString toString() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QtJson::JsonObject m_rawContent;
|
QJsonDocument m_rawContent;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TtRssLoginResponse : public TtRssResponse {
|
class TtRssLoginResponse : public TtRssResponse {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user