void IniFile::addValue(const std::string& Name, const std::string& Key, const std::string& Value) { addSection(Name); Section *S = (*this)[Name]; if(!isKey(Name, Key)) { S->insert(std::make_pair(Key, Value)); } else { (*S)[Key] = Value; } }
//! \internal void XmlPreferencesPrivate::parseSection(xmlDocPtr doc, xmlNodePtr rootNode, Section& section) { xmlNodePtr cur = rootNode->xmlChildrenNode; xmlChar* attr = 0; while (cur != 0) { if (xmlStrcmp(cur->name, (const xmlChar*) "setting") != 0) { cur = cur->next; continue; } attr = xmlGetProp(cur, (const xmlChar*) "name"); if (attr == 0) { cur = cur->next; continue; } QString name((const char*) attr); xmlFree(attr); attr = xmlGetProp(cur, (const xmlChar*) "type"); if (attr == 0) { cur = cur->next; continue; } QString type((const char*) attr); xmlFree(attr); if (type == "string") { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { EncVariant v; v.data = QVariant( QString( (const char*)txt ) ); section.insert(name, v); xmlFree(txt); } } else if (type == "stringlist") { xmlNodePtr listNode = cur->xmlChildrenNode; QString listText; QStringList list; while (listNode != 0) { xmlChar* txt = xmlNodeListGetString(doc, listNode->xmlChildrenNode, 1); if (txt != 0) { list.append( QString((const char*) txt) ); xmlFree(txt); } listNode = listNode->next; } EncVariant v; v.data = QVariant(list); section.insert(name, v); } else if (type == "bool") { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { EncVariant v; v.data = QVariant(xmlStrcmp(txt, (const xmlChar*)"true") == 0); section.insert(name, v); xmlFree(txt); } } else if (type == "int") { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); bool ok; int i = n.toInt(&ok); if (ok) { EncVariant v; v.data = QVariant(i); section.insert(name, v); } } } else if (type == "int64") { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); bool ok; qlonglong i = n.toLongLong(&ok); if (ok) { EncVariant v; v.data = QVariant(i); section.insert(name, v); } } } else if (type == "rect") { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); QStringList lst = n.split(';', QString::KeepEmptyParts); // a qrect has 4 values: xpos, ypos, width and height if (lst.size() == 4) { int x, y, w, h; int count = 0; bool ok; x = lst[0].toInt(&ok); if (ok) ++count; y = lst[1].toInt(&ok); if (ok) ++count; w = lst[2].toInt(&ok); if (ok) ++count; h = lst[3].toInt(&ok); if (ok) ++count; if (count == 4) { EncVariant v; v.data = QVariant(QRect(x,y,w,h)); section.insert(name, v); } } } } else if (type == "point") { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); QStringList lst = n.split(';', QString::KeepEmptyParts); // a qrect has 2 values, the x and y coordinates if (lst.size() == 2) { int x, y; int count = 0; bool ok; x = lst[0].toInt(&ok); if (ok) ++count; y = lst[1].toInt(&ok); if (ok) ++count; if (count == 2) { EncVariant v; v.data = QVariant(QPoint(x,y)); section.insert(name, v); } } } } else if (type == "size") { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); QStringList lst = n.split(';', QString::KeepEmptyParts); // a qrect has 2 values: width and height if (lst.size() == 2) { int w, h; int count = 0; bool ok; w = lst[0].toInt(&ok); if (ok) ++count; h = lst[1].toInt(&ok); if (ok) ++count; if (count == 2) { EncVariant v; v.data = QVariant(QSize(w,h)); section.insert(name, v); } } } } else if (type == "bytearray") { xmlChar* attr = xmlGetProp(cur, (const xmlChar*)"encoding"); if (attr != 0) { if (xmlStrcmp(attr, (const xmlChar*)"base64") == 0) { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); QByteArray ba = Base64::decode(n); EncVariant v; v.data = QVariant(ba); v.encoding = XmlPreferences::Base64; section.insert(name, v); } } else if (xmlStrcmp(attr, (const xmlChar*)"csv") == 0) { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); QStringList lst = n.split(',', QString::SkipEmptyParts); uint sz = lst.size(); QByteArray ba(sz, '\0'); bool ok; uint count = 0; for (QStringList::ConstIterator itr=lst.constBegin(); itr!=lst.constEnd(); ++itr) { uint n = (*itr).toUInt(&ok,16); if (ok) ba.data()[count++] = (uchar)n; } if (count < sz) ba.resize(count); EncVariant v; v.data = QVariant(ba); v.encoding = XmlPreferences::CommaSeparatedValues; section.insert(name, v); } } xmlFree(attr); } } else if (type == "bitarray") { QString n; xmlChar* attr = xmlGetProp(cur, (const xmlChar*)"size"); if (attr != 0) { QString n((const char*)attr); xmlFree(attr); bool ok; uint arr_sz = n.toUInt(&ok); if (!ok) { cur = cur->next; continue; } attr = xmlGetProp(cur, (const xmlChar*)"encoding"); if (attr == 0) { cur = cur->next; continue; } if (xmlStrcmp(attr, (const xmlChar*)"base64") == 0) { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); QBitArray ba = Base64::decode(n, arr_sz); EncVariant v; v.data = QVariant(ba); v.encoding = XmlPreferences::Base64; section.insert(name, v); } } else if (xmlStrcmp(attr, (const xmlChar*)"csv") == 0) { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); QStringList lst = n.split(',', QString::SkipEmptyParts); uint sz = lst.size(); if (arr_sz < sz) sz = arr_sz; QBitArray ba(sz); uint count = 0; for (QStringList::ConstIterator itr=lst.constBegin(); itr!=lst.constEnd(); ++itr) { if (*itr == "1") ba.setBit(count++,true); else if (*itr == "0") ba.setBit(count++,false); } if (count < sz) ba.resize(count); EncVariant v; v.data = QVariant(ba); v.encoding = XmlPreferences::CommaSeparatedValues; section.insert(name, v); } } xmlFree(attr); } } #ifndef QT_CORE_ONLY else if (type == "color") { xmlChar* txt = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); if (txt != 0) { QString n( (const char*) txt ); xmlFree(txt); QColor col(n); if (col.isValid()) { EncVariant v; v.data = QVariant(col); section.insert(name, v); } } } #endif // QT_CORE_ONLY cur = cur->next; } // while }