void KonqMFIcon::extractCard(DOM::Node node) { QString name, value; DOM::NodeList nodes = node.childNodes(); unsigned int n = nodes.length(); value += "BEGIN:VCARD\nVERSION:3.0\n"; for (unsigned int i = 0; i < n; ++i) { DOM::Node node = nodes.item(i); DOM::NamedNodeMap map = node.attributes(); for (unsigned int j = 0; j < map.length(); ++j) { if (map.item(j).nodeName().string() != "class") { continue; } QStringList l = QStringList::split(' ', map.item(j).nodeValue().string()); for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { if (*it == "photo") { } else if (*it == "adr") { value += "ADR:" + extractAddress(node) + "\n"; } else if (*it == "tel") { value += "TEL;TYPE=VOICE:" + textForNode(node) + "\n"; } else if (*it == "fn") { name = textForNode(node); value += "FN:" + name + "\n"; } else if (*it == "url") { DOM::Node at = node.attributes().getNamedItem("href"); if (!at.isNull()) { value += "URL:" + at.nodeValue().string().stripWhiteSpace() + "\n"; } } else if (*it == "email") { DOM::Node at = node.attributes().getNamedItem("href"); if (!at.isNull()) { QString v = at.nodeValue().string(); if (v.startsWith("mailto:")) { v = v.mid(7); } value += "EMAIL:" + v.stripWhiteSpace() + "\n"; } } else if (*it == "org") { value += "ORG:" + textForNode(node) + "\n"; } } } } if (!name.isEmpty()) { value += "END:VCARD\n"; _cards.append(qMakePair(name, value)); } }
static QString extractAddress(DOM::Node node) { QString rc = ";;"; QMap<QString,QString> entry; DOM::NodeList nodes = node.childNodes(); unsigned int n = nodes.length(); for (unsigned int i = 0; i < n; ++i) { DOM::Node node = nodes.item(i); DOM::NamedNodeMap map = node.attributes(); for (unsigned int j = 0; j < map.length(); ++j) { if (map.item(j).nodeName().string() != "class") { continue; } QString a = map.item(j).nodeValue().string(); if (a == "street-address") { entry["street-address"] = textForNode(node); } else if (a == "locality") { entry["locality"] = textForNode(node); } else if (a == "region") { entry["region"] = textForNode(node); } else if (a == "postal-code") { entry["postal-code"] = textForNode(node); } } } rc += entry["street-address"] + ";" + entry["locality"] + ";" + entry["region"] + ";" + entry["postal-code"] + ";" + entry["country"]; return rc.stripWhiteSpace(); }
bool KonqMFIcon::hasMicroFormat(DOM::NodeList nodes) { bool ok = false; unsigned int n = nodes.length(); for (unsigned int i = 0; i < n; ++i) { DOM::Node node = nodes.item(i); DOM::NamedNodeMap map = node.attributes(); for (unsigned int j = 0; j < map.length(); ++j) { if (map.item(j).nodeName().string() != "class") { continue; } if (map.item(j).nodeValue().string() == "vevent") { ok = true; extractEvent(node); break; } if (map.item(j).nodeValue().string() == "vcard") { ok = true; extractCard(node); break; } } if (hasMicroFormat(node.childNodes())) { ok = true; } } return ok; }
void KonqMFIcon::extractEvent(DOM::Node node) { QString name, value = "BEGIN:VCALENDAR\nPRODID:-//Konqueror//EN\nVERSION:2.0\nBEGIN:VEVENT\n"; DOM::NodeList nodes = node.childNodes(); unsigned int n = nodes.length(); for (unsigned int i = 0; i < n; ++i) { DOM::Node node = nodes.item(i); DOM::NamedNodeMap map = node.attributes(); for (unsigned int j = 0; j < map.length(); ++j) { if (map.item(j).nodeName().string() != "class") { continue; } QStringList l = QStringList::split(' ', map.item(j).nodeValue().string()); for (QStringList::ConstIterator it = l.begin(); it != l.end(); ++it) { if (*it == "url") { DOM::Node at = node.attributes().getNamedItem("href"); if (!at.isNull()) { value += "URL:" + at.nodeValue().string().stripWhiteSpace() + "\n"; } } else if (*it == "dtstart") { DOM::Node at = node.attributes().getNamedItem("title"); if (!at.isNull()) { value += "DTSTART:" + at.nodeValue().string().stripWhiteSpace() + "\n"; } } else if (*it == "dtend") { DOM::Node at = node.attributes().getNamedItem("title"); if (!at.isNull()) { value += "DTEND:" + at.nodeValue().string().stripWhiteSpace() + "\n"; } } else if (*it == "summary") { name = textForNode(node); value += "SUMMARY:" + name + "\n"; } else if (*it == "location") { value += "LOCATION:" + textForNode(node) + "\n"; } } } } if (!name.isEmpty()) { value += "END:VEVENT\nEND:VCALENDAR\n"; _events.append(qMakePair(name, value)); } }