~ubuntu-branches/ubuntu/oneiric/kdeplasma-addons/oneiric

« back to all changes in this revision

Viewing changes to dataengines/ocs/lib/knowledgebaselistjob.cpp

Tags: 4:4.4.3-1
* New upstream release:
  - Image providers in picture frame now work correctly. (Closes: #577948)

[ Modestas Vainius ]
* Bump kde-sc-dev-latest build dependency to 4.4.3.
* Release KDE SC 4.4.3 to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of KDE.
3
 
 
4
 
    Copyright (c) 2008 Cornelius Schumacher <schumacher@kde.org>
5
 
    Copyright (c) 2009 Marco Martin <notmart@gmail.com>
6
 
 
7
 
    This program is free software; you can redistribute it and/or modify
8
 
    it under the terms of the GNU General Public License as published by
9
 
    the Free Software Foundation; either version 2 of the License, or
10
 
    (at your option) any later version.
11
 
 
12
 
    This program is distributed in the hope that it will be useful,
13
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 
    GNU General Public License for more details.
16
 
 
17
 
    You should have received a copy of the GNU General Public License
18
 
    along with this program; if not, write to the Free Software
19
 
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20
 
    USA.
21
 
*/
22
 
 
23
 
#include "knowledgebaselistjob.h"
24
 
 
25
 
#include "knowledgebaseparser.h"
26
 
 
27
 
#include <kio/job.h>
28
 
#include <klocale.h>
29
 
 
30
 
#include <QtCore>
31
 
 
32
 
using namespace Attica;
33
 
 
34
 
KnowledgeBaseListJob::KnowledgeBaseListJob()
35
 
  : m_job( 0 )
36
 
{
37
 
}
38
 
 
39
 
void KnowledgeBaseListJob::setUrl( const KUrl &url )
40
 
{
41
 
  m_url = url;
42
 
}
43
 
 
44
 
void KnowledgeBaseListJob::start()
45
 
{
46
 
  QTimer::singleShot( 0, this, SLOT( doWork() ) );
47
 
}
48
 
 
49
 
KnowledgeBase::List KnowledgeBaseListJob::knowledgeBaseList() const
50
 
{
51
 
  return m_knowledgeBaseList;
52
 
}
53
 
 
54
 
KnowledgeBase::Metadata KnowledgeBaseListJob::metadata() const
55
 
{
56
 
  return m_metadata;
57
 
}
58
 
 
59
 
void KnowledgeBaseListJob::doWork()
60
 
{
61
 
  qDebug() << m_url;
62
 
 
63
 
  m_job = KIO::get( m_url, KIO::NoReload, KIO::HideProgressInfo );
64
 
  connect( m_job, SIGNAL( result( KJob * ) ),
65
 
    SLOT( slotJobResult( KJob * ) ) );
66
 
  connect( m_job, SIGNAL( data( KIO::Job *, const QByteArray & ) ),
67
 
    SLOT( slotJobData( KIO::Job *, const QByteArray & ) ) );
68
 
}
69
 
 
70
 
void KnowledgeBaseListJob::slotJobResult( KJob *job )
71
 
{
72
 
  m_job = 0;
73
 
 
74
 
  if ( job->error() ) {
75
 
    setError( job->error() );
76
 
    setErrorText( job->errorText() );
77
 
  
78
 
    emitResult();
79
 
  } else {
80
 
    qDebug() << m_data;
81
 
    KnowledgeBaseParser parser;
82
 
    m_knowledgeBaseList = parser.parseList(
83
 
      QString::fromUtf8( m_data.data() ) );
84
 
    m_metadata = parser.lastMetadata();
85
 
 
86
 
    emitResult();
87
 
  }
88
 
}
89
 
 
90
 
void KnowledgeBaseListJob::slotJobData( KIO::Job *, const QByteArray &data )
91
 
{
92
 
  m_data.append( data );
93
 
}