• 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
synchttplookup.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 "synchttplookup.h"
22 
23 #include <qstringlist.h>
24 #include <qapplication.h>
25 
26 #include <kdebug.h>
27 #include <kio/job.h>
28 #include <kio/netaccess.h>
29 
30 namespace KCDDB
31 {
32  SyncHTTPLookup::SyncHTTPLookup()
33  : HTTPLookup()
34  {
35  }
36 
37  SyncHTTPLookup::~SyncHTTPLookup()
38  {
39  // Empty.
40  }
41 
42  Result
43  SyncHTTPLookup::lookup
44  (
45  const QString & hostName,
46  uint port,
47  const TrackOffsetList & trackOffsetList
48  )
49  {
50  trackOffsetList_ = trackOffsetList;
51 
52  initURL( hostName, port );
53 
54  // Run a query.
55  result_ = runQuery();
56 
57  if ( Success != result_ )
58  return result_;
59 
60  kDebug(60010) << matchList_.count() << " matches found.";
61 
62  if (matchList_.isEmpty())
63  return NoRecordFound;
64 
65  // For each match, read the cd info from the server and save it to
66  // cdInfoList.
67  CDDBMatchList::ConstIterator matchIt = matchList_.constBegin();
68 
69  while ( matchIt != matchList_.constEnd() )
70  {
71  CDDBMatch match( *matchIt );
72  result_ = matchToCDInfo( match );
73  ++matchIt;
74  }
75 
76  return result_;
77  }
78 
79  Result
80  SyncHTTPLookup::runQuery()
81  {
82  data_ = QByteArray();
83  state_ = WaitingForQueryResponse;
84 
85  result_ = sendQuery();
86 
87  if ( Success != result_ )
88  return result_;
89 
90  kDebug(60010) << "runQuery() Result: " << resultToString(result_);
91 
92  return result_;
93  }
94 
95  Result
96  SyncHTTPLookup::matchToCDInfo( const CDDBMatch & match )
97  {
98  data_ = QByteArray();
99  state_ = WaitingForReadResponse;
100 
101  result_ = sendRead( match );
102 
103  if ( Success != result_ )
104  return result_;
105 
106  return result_;
107  }
108 
109  Result
110  SyncHTTPLookup::fetchURL()
111  {
112  kDebug(60010) << "About to fetch: " << cgiURL_.url();
113 
114  KIO::TransferJob* job = KIO::get( cgiURL_, KIO::NoReload, KIO::HideProgressInfo );
115 
116  if ( 0 == job )
117  return ServerError;
118 
119  if (!KIO::NetAccess::synchronousRun(job, 0, &data_))
120  return ServerError;
121 
122  jobFinished();
123 
124  return Success;
125  }
126 }
127 
128 // vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
KCDDB::SyncHTTPLookup::matchToCDInfo
Result matchToCDInfo(const CDDBMatch &)
Definition: synchttplookup.cpp:96
KCDDB::NoRecordFound
Definition: kcddb.h:43
QByteArray
KCDDB::SyncHTTPLookup::fetchURL
virtual Result fetchURL()
Definition: synchttplookup.cpp:110
KCDDB::HTTPLookup
Definition: httplookup.h:36
KCDDB::SyncHTTPLookup::~SyncHTTPLookup
virtual ~SyncHTTPLookup()
Definition: synchttplookup.cpp:37
KCDDB::Success
Definition: kcddb.h:39
KCDDB::HTTPLookup::WaitingForReadResponse
Definition: httplookup.h:47
KCDDB::ServerError
Definition: kcddb.h:40
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
KCDDB::SyncHTTPLookup::lookup
Result lookup(const QString &, uint, const TrackOffsetList &)
Definition: synchttplookup.cpp:44
synchttplookup.h
KCDDB::SyncHTTPLookup::runQuery
Result runQuery()
Definition: synchttplookup.cpp:80
KCDDB::HTTPLookup::sendRead
Result sendRead(const CDDBMatch &)
Definition: httplookup.cpp:52
KCDDB::HTTPLookup::result_
Result result_
Definition: httplookup.h:75
KCDDB::SyncHTTPLookup::SyncHTTPLookup
SyncHTTPLookup()
Definition: synchttplookup.cpp:32
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
QList< CDDBMatch >::ConstIterator
typedef ConstIterator
KCDDB::resultToString
QString resultToString(Result r)
Definition: kcddb.cpp:27
KCDDB::HTTPLookup::jobFinished
void jobFinished()
Definition: httplookup.cpp:94
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