• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdemultimedia API Reference
  • KDE Home
  • Contact Us
 

libkcddb

  • sources
  • kde-4.14
  • kdemultimedia
  • libkcddb
  • libkcddb
asynchttplookup.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002 Rik Hemsley (rikkus) <rik@kde.org>
3  Copyright (C) 2002 Benjamin Meyer <ben-devel@meyerhome.net>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "asynchttplookup.h"
22 
23 #include <qstringlist.h>
24 #include <qapplication.h>
25 
26 #include <kdebug.h>
27 #include <kio/job.h>
28 
29 namespace KCDDB
30 {
31  AsyncHTTPLookup::AsyncHTTPLookup()
32  : HTTPLookup()
33  {
34  block_ = false;
35  }
36 
37  AsyncHTTPLookup::~AsyncHTTPLookup()
38  {
39  // Empty.
40  }
41 
42  Result
43  AsyncHTTPLookup::lookup
44  (
45  const QString & hostName,
46  uint port,
47  const TrackOffsetList & trackOffsetList
48  )
49  {
50  trackOffsetList_ = trackOffsetList;
51 
52  connect( this, SIGNAL(queryReady()), SLOT(slotQueryReady()) );
53  connect( this, SIGNAL(readReady()), SLOT(requestCDInfoForMatch()) );
54 
55  initURL( hostName, port );
56 
57  // Run a query.
58  result_ = runQuery();
59 
60  return result_;
61  }
62 
63  Result
64  AsyncHTTPLookup::runQuery()
65  {
66  data_ = QByteArray();
67  state_ = WaitingForQueryResponse;
68 
69  result_ = sendQuery();
70 
71  return result_;
72  }
73 
74  void
75  AsyncHTTPLookup::slotQueryReady()
76  {
77  kDebug(60010) << "Matches Found: " << matchList_.count();
78 
79  if ( Success != result_ )
80  {
81  emit finished( result_ );
82  return;
83  }
84 
85  requestCDInfoForMatch();
86  }
87 
88  void
89  AsyncHTTPLookup::requestCDInfoForMatch()
90  {
91  if ( matchList_.isEmpty() )
92  {
93  result_ = cdInfoList_.isEmpty()? NoRecordFound : Success;
94  emit finished( result_ );
95  return;
96  }
97 
98  CDDBMatch match = matchList_.takeFirst();
99 
100  data_ = QByteArray();
101  state_ = WaitingForReadResponse;
102 
103  result_ = sendRead( match );
104 
105  if ( Success != result_ )
106  emit finished( result_ );
107  }
108 
109  void
110  AsyncHTTPLookup::slotData( KIO::Job *, const QByteArray &data )
111  {
112  if (data.size() > 0)
113  data_.append(data);
114  }
115 
116  void
117  AsyncHTTPLookup::slotResult( KJob *job )
118  {
119  if ( 0 != job->error() )
120  {
121  result_ = ServerError;
122  if ( !block_ )
123  emit queryReady();
124  return;
125  }
126 
127  jobFinished();
128  }
129 
130  Result
131  AsyncHTTPLookup::fetchURL()
132  {
133  kDebug(60010) << "About to fetch: " << cgiURL_.url();
134 
135  KIO::TransferJob* job = KIO::get( cgiURL_, KIO::NoReload, KIO::HideProgressInfo );
136 
137  if ( 0 == job )
138  return ServerError;
139 
140  connect( job, SIGNAL(data(KIO::Job*,QByteArray)),
141  SLOT(slotData(KIO::Job*,QByteArray)) );
142  connect( job, SIGNAL(result(KJob*)),
143  SLOT(slotResult(KJob*)) );
144 
145  return Success;
146  }
147 
148 }
149 
150 #include "asynchttplookup.moc"
151 
152 // vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
KCDDB::Lookup::cdInfoList_
CDInfoList cdInfoList_
Definition: lookup.h:60
KCDDB::AsyncHTTPLookup::fetchURL
virtual Result fetchURL()
Definition: asynchttplookup.cpp:131
KCDDB::NoRecordFound
Definition: kcddb.h:43
KCDDB::HTTPLookup::queryReady
void queryReady()
asynchttplookup.h
QByteArray
KCDDB::AsyncHTTPLookup::requestCDInfoForMatch
void requestCDInfoForMatch()
Definition: asynchttplookup.cpp:89
KCDDB::HTTPLookup
Definition: httplookup.h:36
KCDDB::Lookup::matchList_
CDDBMatchList matchList_
Definition: lookup.h:61
KCDDB::AsyncHTTPLookup::lookup
Result lookup(const QString &, uint, const TrackOffsetList &)
Definition: asynchttplookup.cpp:44
QList::count
int count(const T &value) const
QList::isEmpty
bool isEmpty() const
KCDDB::Success
Definition: kcddb.h:39
KCDDB::HTTPLookup::WaitingForReadResponse
Definition: httplookup.h:47
KCDDB::AsyncHTTPLookup::~AsyncHTTPLookup
virtual ~AsyncHTTPLookup()
Definition: asynchttplookup.cpp:37
KCDDB::AsyncHTTPLookup::slotQueryReady
void slotQueryReady()
Definition: asynchttplookup.cpp:75
KCDDB::ServerError
Definition: kcddb.h:40
KCDDB::AsyncHTTPLookup::AsyncHTTPLookup
AsyncHTTPLookup()
Definition: asynchttplookup.cpp:31
KCDDB::HTTPLookup::data_
QByteArray data_
Definition: httplookup.h:73
QString
QList< uint >
KCDDB::HTTPLookup::WaitingForQueryResponse
Definition: httplookup.h:46
KCDDB::HTTPLookup::state_
State state_
Definition: httplookup.h:74
QPair
QByteArray::append
QByteArray & append(char ch)
KCDDB::AsyncHTTPLookup::runQuery
Result runQuery()
Definition: asynchttplookup.cpp:64
QList::takeFirst
T takeFirst()
KCDDB::AsyncHTTPLookup::slotData
void slotData(KIO::Job *, const QByteArray &)
Definition: asynchttplookup.cpp:110
KCDDB::HTTPLookup::sendRead
Result sendRead(const CDDBMatch &)
Definition: httplookup.cpp:52
KCDDB::HTTPLookup::result_
Result result_
Definition: httplookup.h:75
KCDDB::HTTPLookup::sendQuery
Result sendQuery()
Definition: httplookup.cpp:40
KCDDB::Result
Result
Definition: kcddb.h:37
KCDDB::HTTPLookup::cgiURL_
KUrl cgiURL_
Definition: httplookup.h:72
KCDDB::HTTPLookup::block_
bool block_
Definition: httplookup.h:71
KCDDB::AsyncHTTPLookup::finished
void finished(KCDDB::Result)
KCDDB::HTTPLookup::jobFinished
void jobFinished()
Definition: httplookup.cpp:94
QByteArray::size
int size() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KCDDB::AsyncHTTPLookup::slotResult
void slotResult(KJob *)
Definition: asynchttplookup.cpp:117
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:28:13 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkcddb

Skip menu "libkcddb"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdemultimedia API Reference

Skip menu "kdemultimedia API Reference"
  • libkcddb
  • libkcompactdisc

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal