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
98
99
100
101
102
|
/***************************************************************************
copyright : (C) 2006 by Robby Stephenson
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of version 2 of the GNU General Public License as *
* published by the Free Software Foundation; *
* *
***************************************************************************/
// this class is largely copied from kdelibs/knewstuff/provider.cpp
// which is Copyright (c) 2002 Cornelius Schumacher <[email protected]>
// and licensed under GPL v2, just like Tellico
#include "providerloader.h"
#include "../tellico_debug.h"
#include "../latin1literal.h"
#include <kio/job.h>
#include <knewstuff/provider.h>
#include <kglobal.h>
#include <kconfig.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <qdom.h>
using Tellico::NewStuff::ProviderLoader;
ProviderLoader::ProviderLoader( QWidget *parentWidget ) :
mParentWidget( parentWidget ), mTryAlt(true)
{
mProviders.setAutoDelete( true );
}
void ProviderLoader::load( const QString &type, const QString &providersList )
{
mProviders.clear();
mJobData.truncate(0);
// myLog() << "ProviderLoader::load(): providersList: " << providersList << endl;
KIO::TransferJob *job = KIO::get( KURL( providersList ), false, false );
connect( job, SIGNAL( result( KIO::Job * ) ),
SLOT( slotJobResult( KIO::Job * ) ) );
connect( job, SIGNAL( data( KIO::Job *, const QByteArray & ) ),
SLOT( slotJobData( KIO::Job *, const QByteArray & ) ) );
connect( job, SIGNAL( percent (KIO::Job *, unsigned long) ),
SIGNAL( percent (KIO::Job *, unsigned long) ) );
// job->dumpObjectInfo();
}
void ProviderLoader::slotJobData( KIO::Job *, const QByteArray &data )
{
if ( data.size() == 0 ) return;
QCString str( data, data.size() + 1 );
mJobData.append( QString::fromUtf8( str ) );
}
void ProviderLoader::slotJobResult( KIO::Job *job )
{
if ( job->error() ) {
job->showErrorDialog( mParentWidget );
if(mTryAlt && !mAltProvider.isEmpty()) {
mTryAlt = false;
load(QString(), mAltProvider);
} else {
emit error();
}
return;
}
QDomDocument doc;
if ( !doc.setContent( mJobData ) ) {
myDebug() << "ProviderLoader::slotJobResult() - error parsing providers list." << endl;
if(mTryAlt && !mAltProvider.isEmpty()) {
mTryAlt = false;
load(QString(), mAltProvider);
} else {
emit error();
}
return;
}
QDomElement providers = doc.documentElement();
QDomNode n;
for ( n = providers.firstChild(); !n.isNull(); n = n.nextSibling() ) {
QDomElement p = n.toElement();
if ( p.tagName() == Latin1Literal("provider") ) {
mProviders.append( new KNS::Provider( p ) );
}
}
emit providersLoaded( &mProviders );
}
#include "providerloader.moc"
|