summaryrefslogtreecommitdiffstats
path: root/kbugbuster/backend/bugjob.cpp
blob: 1d13913b02c0c073cdbb79a6b326acc832fcf30f (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
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
96
97

#include "bugjob.h"

#include "kbbprefs.h"

#include <kio/job.h>

#include <string.h>
#include <klocale.h>
#include <kdebug.h>

BugJob::BugJob( BugServer *server )
    : Job( false ), mServer( server )
{
}

BugJob::~BugJob()
{
}

void BugJob::start( const KURL &url )
{
    kdDebug() << "BugJob::start(): " << url.url() << endl;

    if ( KBBPrefs::instance()->mDebugMode ) {
        BugSystem::saveQuery( url );
    }

    // ### obey post, if necessary

    KIO::Job *job = KIO::get( url, true /*always 'reload=true', we have our own cache*/, false );

    connect( job, TQT_SIGNAL( result( KIO::Job * ) ),
             this, TQT_SLOT( ioResult( KIO::Job * ) ) );
    connect( job, TQT_SIGNAL( data( KIO::Job *, const TQByteArray & ) ),
             this, TQT_SLOT( ioData( KIO::Job *, const TQByteArray & ) ) );
    connect( job, TQT_SIGNAL( infoMessage( KIO::Job *, const TQString & ) ),
             this, TQT_SLOT( ioInfoMessage( KIO::Job *, const TQString & ) ) );
    connect( job, TQT_SIGNAL( percent( KIO::Job *, unsigned long ) ),
             this, TQT_SLOT( ioInfoPercent( KIO::Job *, unsigned long ) ) );
}

void BugJob::ioResult( KIO::Job *job )
{
    m_error = job->error();
    m_errorText = job->errorText();

    if ( job->error() )
    {
        emit error( m_errorText );
        BugSystem::self()->unregisterJob(this);
        this->kill();
        return;
    }

    infoMessage( i18n( "Parsing..." ) );

#if 0
    kdDebug() << "--START:" << m_data << ":END--" << endl;
#endif

    if ( KBBPrefs::instance()->mDebugMode ) {
        BugSystem::saveResponse( m_data );
    }

    process( m_data );
    infoMessage( i18n( "Ready." ) );

    emit jobEnded( this );

    delete this;
}

void BugJob::ioData( KIO::Job *, const TQByteArray &data )
{
    unsigned int start = m_data.size();

    m_data.resize( m_data.size() + data.size() );
    memcpy( m_data.data() + start, data.data(), data.size() );
}

void BugJob::ioInfoMessage( KIO::Job *, const TQString &_text )
{
    TQString text = _text;
    emit infoMessage( text );
}

void BugJob::ioInfoPercent( KIO::Job *, unsigned long percent )
{
    emit infoPercent( percent );
}

#include "bugjob.moc"

/*
 * vim:sw=4:ts=4:et
 */