• 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
cddbplookup.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  Copyright ( C ) 2002 Nadeem Hasan <nhasan@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or ( at your option ) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "cddbplookup.h"
23 
24 #include <kdebug.h>
25 
26 #include <qbytearray.h>
27 
28 namespace KCDDB
29 {
30  CDDBPLookup::CDDBPLookup()
31  : Lookup()
32  , socket_(0)
33  {
34 
35  }
36 
37  CDDBPLookup::~CDDBPLookup()
38  {
39  if (socket_)
40  delete socket_;
41  }
42 
43  void
44  CDDBPLookup::sendHandshake()
45  {
46  QString handshake = QString::fromLatin1( "cddb hello %1 %2 %3 %4" )
47  .arg( user_ )
48  .arg( localHostName_ )
49  .arg( clientName() )
50  .arg( clientVersion() );
51 
52  writeLine( handshake );
53  }
54 
55  void
56  CDDBPLookup::sendProto()
57  {
58  writeLine( QLatin1String( "proto 6" ) );
59  }
60 
61  void
62  CDDBPLookup::sendQuery()
63  {
64  QString query = QString::fromLatin1( "cddb query %1 %2" )
65  .arg( trackOffsetListToId() )
66  .arg( trackOffsetListToString() );
67 
68  writeLine( query );
69  }
70 
71  void
72  CDDBPLookup::sendRead( const CDDBMatch & match )
73  {
74  category_ = match.first;
75  discid_ = match.second;
76 
77  QString readRequest = QString::fromLatin1( "cddb read %1 %2" )
78  .arg( category_ )
79  .arg( discid_ );
80 
81  writeLine( readRequest );
82  }
83 
84  void
85  CDDBPLookup::sendQuit()
86  {
87  writeLine( QLatin1String( "quit" ) );
88  }
89 
90  void
91  CDDBPLookup::close()
92  {
93  kDebug(60010) << "Disconnect from server...";
94  if ( isConnected() )
95  {
96  socket_->close();
97  }
98  }
99 
100  bool
101  CDDBPLookup::parseGreeting( const QString & line )
102  {
103  uint serverStatus = statusCode( line );
104 
105  if ( 200 == serverStatus )
106  {
107  kDebug(60010) << "Server response: read-only";
108  readOnly_ = true;
109  }
110  else if ( 201 == serverStatus )
111  {
112  kDebug(60010) << "Server response: read-write";
113  }
114  else
115  {
116  kDebug(60010) << "Server response: bugger off";
117  return false;
118  }
119 
120  return true;
121  }
122 
123  bool
124  CDDBPLookup::parseHandshake( const QString & line )
125  {
126  uint serverStatus = statusCode( line );
127 
128  if ( ( 200 != serverStatus ) && ( 402 != serverStatus ) )
129  {
130  kDebug(60010) << "Handshake was too tight. Letting go.";
131  return false;
132  }
133 
134  kDebug(60010) << "Handshake was warm and firm";
135 
136  return true;
137  }
138 
139 
140  qint64
141  CDDBPLookup::writeLine( const QString & line )
142  {
143  if ( !isConnected() )
144  {
145  kDebug(60010) << "socket status: " << socket_->state();
146  return -1;
147  }
148 
149  kDebug(60010) << "WRITE: [" << line << "]";
150  QByteArray buf(line.toUtf8());
151  buf.append( '\n' );
152 
153  return socket_->write( buf );
154  }
155 }
156 
157 // vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1
KCDDB::CDDBPLookup::sendQuery
void sendQuery()
Definition: cddbplookup.cpp:62
KCDDB::CDDB::clientName
static QString clientName()
Definition: cddb.h:41
KCDDB::CDDBPLookup::sendHandshake
void sendHandshake()
Definition: cddbplookup.cpp:44
QAbstractSocket::state
SocketState state() const
QByteArray
KCDDB::Lookup::discid_
QString discid_
Definition: lookup.h:63
KCDDB::CDDBPLookup::CDDBPLookup
CDDBPLookup()
Definition: cddbplookup.cpp:30
KCDDB::CDDBPLookup::sendRead
void sendRead(const CDDBMatch &)
Definition: cddbplookup.cpp:72
KCDDB::Lookup
Definition: lookup.h:36
KCDDB::CDDB::statusCode
static uint statusCode(const QString &)
Definition: cddb.cpp:104
KCDDB::CDDBPLookup::close
void close()
Definition: cddbplookup.cpp:91
KCDDB::CDDBPLookup::sendQuit
void sendQuit()
Definition: cddbplookup.cpp:85
KCDDB::CDDB::trackOffsetListToId
QString trackOffsetListToId()
Definition: cddb.cpp:48
KCDDB::CDDBPLookup::parseGreeting
bool parseGreeting(const QString &)
Definition: cddbplookup.cpp:101
KCDDB::CDDB::clientVersion
static QString clientVersion()
Definition: cddb.h:42
QAbstractSocket::close
virtual void close()
cddbplookup.h
KCDDB::CDDB::user_
QString user_
Definition: cddb.h:52
QString
KCDDB::Lookup::category_
QString category_
Definition: lookup.h:62
QPair
QByteArray::append
QByteArray & append(char ch)
KCDDB::CDDB::localHostName_
QString localHostName_
Definition: cddb.h:53
KCDDB::CDDBPLookup::parseHandshake
bool parseHandshake(const QString &)
Definition: cddbplookup.cpp:124
KCDDB::CDDBPLookup::sendProto
void sendProto()
Definition: cddbplookup.cpp:56
QLatin1String
KCDDB::CDDBPLookup::~CDDBPLookup
virtual ~CDDBPLookup()
Definition: cddbplookup.cpp:37
QIODevice::write
qint64 write(const char *data, qint64 maxSize)
QString::fromLatin1
QString fromLatin1(const char *str, int size)
KCDDB::CDDBPLookup::writeLine
qint64 writeLine(const QString &)
Definition: cddbplookup.cpp:141
KCDDB::CDDB::trackOffsetListToString
QString trackOffsetListToString()
Definition: cddb.cpp:81
KCDDB::CDDBPLookup::isConnected
bool isConnected()
Definition: cddbplookup.h:50
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
KCDDB::CDDBPLookup::socket_
QTcpSocket * socket_
Definition: cddbplookup.h:53
KCDDB::CDDB::readOnly_
bool readOnly_
Definition: cddb.h:55
QString::toUtf8
QByteArray toUtf8() const
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