1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-01-10 14:57:52 +00:00

Added Json encode support for QVariantList and QStringList

This commit is contained in:
Christophe Dumez 2010-02-28 17:24:35 +00:00
parent b7edfea4ce
commit 8f28804f8c
2 changed files with 30 additions and 23 deletions

View File

@ -231,9 +231,8 @@ QVariantMap EventManager::getGlobalPreferences() const {
data["save_path"] = Preferences::getSavePath();
data["temp_path_enabled"] = Preferences::isTempPathEnabled();
data["temp_path"] = Preferences::getTempPath();
// XXX: json.h does not encode QStringList correctly
//data["scan_dirs"] = Preferences::getScanDirs();
//data["download_in_scan_dirs"] = Preferences::getDownloadInScanDirs();
data["scan_dirs"] = Preferences::getScanDirs();
data["download_in_scan_dirs"] = Preferences::getDownloadInScanDirs();
data["export_dir_enabled"] = Preferences::isTorrentExportEnabled();
data["export_dir"] = Preferences::getExportDir();
data["preallocate_all"] = Preferences::preAllocateAllFiles();

View File

@ -41,15 +41,23 @@ namespace json {
return "null";
switch(v.type())
{
case QVariant::Bool:
case QVariant::Double:
case QVariant::Int:
case QVariant::LongLong:
case QVariant::UInt:
case QVariant::ULongLong:
case QMetaType::Float:
case QVariant::Bool:
case QVariant::Double:
case QVariant::Int:
case QVariant::LongLong:
case QVariant::UInt:
case QVariant::ULongLong:
case QMetaType::Float:
return v.value<QString>();
case QVariant::String:
case QVariant::StringList:
case QVariant::List: {
QStringList strList;
foreach(const QVariant &var, v.toList()) {
strList << toJson(var);
}
return "["+strList.join(",")+"]";
}
case QVariant::String:
{
QString s = v.value<QString>();
QString result = "\"";
@ -58,35 +66,35 @@ namespace json {
QChar ch = s[i];
switch(ch.toAscii())
{
case '\b':
case '\b':
result += "\\b";
break;
case '\f':
case '\f':
result += "\\f";
break;
case '\n':
case '\n':
result += "\\n";
break;
case '\r':
case '\r':
result += "\\r";
break;
case '\t':
case '\t':
result += "\\t";
break;
case '\"':
case '\'':
case '\\':
case '&':
case '\"':
case '\'':
case '\\':
case '&':
result += '\\';
case '\0':
default:
case '\0':
default:
result += ch;
}
}
result += "\"";
return result;
}
default:
default:
qDebug("Unknown QVariantType: %d", (int)v.type());
return "undefined";
}