~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to libkcddb/synchttplookup.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

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