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(); }
int MetabarFunctions::getHeight(DOM::HTMLElement &element) { int height = 0; DOM::NodeList children = element.childNodes(); for(uint i = 0; i < children.length(); i++) { DOM::HTMLElement node = static_cast<DOM::HTMLElement>(children.item(i)); DOM::CSSStyleDeclaration style = node.style(); DOM::DOMString css_height = style.getPropertyValue("height"); if(!css_height.isNull()) { height += css_height.string().left(css_height.string().length() - 2).toInt(); } else { int h = 0; if(!node.isNull()) { h = node.getRect().height(); } DOM::DOMString display = style.getPropertyValue("display"); if(display == "none") { h = 0; } else if(h == 0) { h = 20; } height += h; } } return height; }
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; }
static QString textForNode(DOM::Node node) { QString rc; DOM::NodeList nl = node.childNodes(); for (unsigned int i = 0; i < nl.length(); ++i) { DOM::Node n = nl.item(i); if (n.nodeType() == DOM::Node::TEXT_NODE) { rc += n.nodeValue().string(); } } // FIXME: entries need to be escaped for vcard/vevent return rc.stripWhiteSpace(); }
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)); } }
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)); } }
LinkItem::LinkItem( DOM::Element link ) : m_valid( false ) { DOM::NamedNodeMap attrs = link.attributes(); DOM::Node href = attrs.getNamedItem( "href" ); // Load source address of images too DOM::Node src = attrs.getNamedItem( "src" ); if ( href.nodeValue().string().isEmpty() && !src.nodeValue().string().isEmpty() ) href = src; // qDebug("*** href: %s", href.nodeValue().string().latin1() ); QString urlString = link.ownerDocument().completeURL( href.nodeValue() ).string(); if ( urlString.isEmpty() ) return; url = KUrl( urlString ); if ( !KProtocolManager::supportsReading( url ) ) return; // somehow getElementsByTagName("#text") doesn't work :( DOM::NodeList children = link.childNodes(); for ( uint i = 0; i < children.length(); i++ ) { DOM::Node node = children.item( i ); if ( node.nodeType() == DOM::Node::TEXT_NODE ) text.append( node.nodeValue().string() ); } // force "local file" mimetype determination KMimeType::Ptr mt = KMimeType::findByUrl( url, 0, true, true); icon = mt->iconName(); mimeType = mt->comment(); m_valid = true; }