/*************************************************************************** * Copyright (C) 2004 by Paulo Moura Guedes * * moura@tdewebdev.org * * * * 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 2 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "linkstatus.h" #include "../parser/node.h" #include "../ui/treeview.h" #include #include #include LinktqStatus::~LinktqStatus() { //kdDebug(23100) << "|"; for(uint i = 0; i != tqchildren_nodes_.size(); ++i) { if(tqchildren_nodes_[i]) { delete tqchildren_nodes_[i]; tqchildren_nodes_[i] = 0; } } tqchildren_nodes_.clear(); if(isRedirection()) { if(redirection_) { delete redirection_; redirection_ = 0; } } } void LinktqStatus::reset() { depth_ = -1; external_domain_depth_ = -1; is_root_ = false; error_occurred_ = false; is_redirection_ = false; checked_ = false; only_check_header_ = true; malformed_ = false; Q_ASSERT(!node_); has_base_URI_ = false; label_ = ""; absolute_url_ = ""; doc_html_ = ""; http_header_ = HttpResponseHeader(); error_ = ""; for(uint i = 0; i != tqchildren_nodes_.size(); ++i) { if(tqchildren_nodes_[i]) { delete tqchildren_nodes_[i]; tqchildren_nodes_[i] = 0; } } tqchildren_nodes_.clear(); if(isRedirection()) { if(redirection_) { delete redirection_; redirection_ = 0; } } Q_ASSERT(!parent_); base_URI_ = ""; } TQString const LinktqStatus::toString() const { TQString aux; if(!is_root_) { Q_ASSERT(parent_); aux += i18n( "Parent: %1" ).tqarg( parent()->absoluteUrl().prettyURL() ) + "\n"; } Q_ASSERT(!original_url_.isNull()); aux += i18n( "URL: %1" ).tqarg( absoluteUrl().prettyURL() ) + "\n"; aux += i18n( "Original URL: %1" ).tqarg( originalUrl() ) + "\n"; if(node()) aux += i18n( "Node: %1" ).tqarg( node()->content() ) + "\n"; return aux; } LinktqStatus* LinktqStatus::lastRedirection(LinktqStatus* ls) { if(ls->isRedirection()) if(ls->redirection()) return lastRedirection(ls->redirection()); else return ls; else return ls; } void LinktqStatus::loadNode() { Q_ASSERT(node_); setOriginalUrl(node_->url()); setLabel(node_->linkLabel()); if(malformed()) { setErrorOccurred(true); setError(i18n( "Malformed" )); settqStatus(LinktqStatus::MALFORMED); kdDebug(23100) << "Malformed:" << endl; kdDebug(23100) << "Node: " << node()->content() << endl; //kdDebug(23100) << toString() << endl; // probable segfault } } bool LinktqStatus::malformed() const // don't inline please (#include "node.h") { return (malformed_ || node_->malformed()); } void LinktqStatus::setChildrenNodes(vector const& nodes) // don't inline please (#include "node.h") { tqchildren_nodes_.reserve(nodes.size()); tqchildren_nodes_ = nodes; } void LinktqStatus::setMalformed(bool flag) { malformed_ = flag; if(flag) { setErrorOccurred(true); setError(i18n( "Malformed" )); settqStatus(LinktqStatus::MALFORMED); kdDebug(23100) << "Malformed!" << endl; kdDebug(23100) << node()->content() << endl; //kdDebug(23100) << toString() << endl; // probable segfault } else if(error() == i18n( "Malformed" )) { setErrorOccurred(false); setError(""); settqStatus(LinktqStatus::UNDETERMINED); } } void LinktqStatus::save(TQDomElement& element) const { TQDomElement child_element = element.ownerDocument().createElement("link"); // TQDomElement tmp_1 = element.ownerDocument().createElement("url"); tmp_1.appendChild(element.ownerDocument().createTextNode(absoluteUrl().prettyURL())); child_element.appendChild(tmp_1); // tmp_1 = element.ownerDocument().createElement("status"); tmp_1.setAttribute("broken", ResultView::displayableWithtqStatus(this, ResultView::bad) ? "true" : "false"); tmp_1.appendChild(element.ownerDocument().createTextNode(statusText())); child_element.appendChild(tmp_1); //