greghaynes / kdelicious

A Konqueror del.icio.us plugin

laurent Montel (author)
Thu Apr 09 00:12:54 -0700 2009
greghaynes (committer)
Thu Apr 09 00:12:54 -0700 2009
kdelicious / request.cpp
100644 95 lines (75 sloc) 1.58 kb
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "request.h"
 
#include <QXmlSimpleReader>
#include <QXmlInputSource>
 
#include <QDebug>
 
#include "request.moc"
 
namespace QtLicious
{
 
Request::Request( const QUrl &path, QObject *parent )
: QObject( parent )
, m_path( path )
, buffer( new QBuffer( this ) )
, m_isFinished( false )
{
buffer->open(QBuffer::ReadWrite);
connect( buffer, SIGNAL(readyRead()),
this, SLOT(slotReadyRead()) );
}
 
Request::~Request()
{
delete buffer;
}
 
const QUrl &Request::path() const
{
return m_path;
}
 
void Request::setPath( const QUrl &path )
{
m_path = path;
}
 
bool Request::isFinished() const
{
return m_isFinished;
}
 
void Request::run( QHttp *qhttp )
{
qDebug() << "Run request " << path().toEncoded();
qhttp->get( path().toEncoded(), buffer );
}
 
const QVariant &Request::responseData() const
{
return data;
}
 
void Request::slotReadyRead()
{
QXmlInputSource source;
source.setData( buffer->data() );
QXmlSimpleReader reader;
reader.setContentHandler( this );
reader.setErrorHandler( this );
if( !reader.parse( source ) )
qDebug() << "Parsing failed.";
emitFinished();
}
 
bool Request::error( const QXmlParseException &exception )
{
emit( parsingError( exception.message() ) );
emitFinished();
return false;
}
 
bool Request::warning( const QXmlParseException &exception )
{
qDebug() << "Parsing warning: " << exception.message();
return true;
}
 
 
bool Request::fatalError( const QXmlParseException &exception )
{
emit( parsingError( exception.message() ) );
emitFinished();
return false;
}
 
void Request::emitFinished()
{
emit( finished() );
}
 
}