summaryrefslogtreecommitdiffstats
path: root/kget/kget_plug_in/links.cpp
blob: b1410cefb04ff24e47d1df1410995df8d9794a4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "links.h"

#include <kmimetype.h>
#include <kprotocolinfo.h>

#include <dom/html_misc.h>
#include <dom/html_document.h>

LinkItem::LinkItem( DOM::Element link )
    : m_valid( false )
{
    DOM::NamedNodeMap attrs = link.attributes();
    DOM::Node href = attrs.getNamedItem( "href" );

    // qDebug("*** href: %s", href.nodeValue().string().latin1() );

    TQString urlString = link.ownerDocument().completeURL( href.nodeValue() ).string();
    if ( urlString.isEmpty() )
        return;

    url = KURL::fromPathOrURL( urlString );
    if ( !KProtocolInfo::supportsReading( url ) )
        return;
    

    // somehow getElementsByTagName("#text") doesn't work :(
    DOM::NodeList tqchildren = link.childNodes();
    for ( uint i = 0; i < tqchildren.length(); i++ )
    {
        DOM::Node node = tqchildren.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->icon( TQString(), false ); // dummy parameters
    mimeType = mt->comment();
    
    m_valid = true;
}