• 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
sites.cpp
Go to the documentation of this file.
1 /*
2  Copyright ( C ) 2004 Richard Lärkäng <nouseforaname@home.se>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or ( at your option ) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include "sites.h"
21 
22 #include <kurl.h>
23 #include <kio/netaccess.h>
24 #include <kio/job.h>
25 #include <QTextStream>
26 #include <kdebug.h>
27 #include <QRegExp>
28 
29 namespace KCDDB
30 {
31  Sites::Sites()
32  {
33 
34  }
35 
36  QList<Mirror>
37  Sites::siteList()
38  {
39  KUrl url;
40  url.setProtocol( QLatin1String( "http" ) );
41  url.setHost( QLatin1String( "freedb.freedb.org" ) );
42  url.setPort( 80 );
43  url.setPath( QLatin1String( "/~cddb/cddb.cgi" ) );
44 
45  url.setQuery( QString::null ); //krazy:exclude=nullstrassign for old broken gcc
46 
47  QString hello = QString::fromLatin1("%1 %2 %3 %4")
48  .arg(QLatin1String( "libkcddb-user" ), QLatin1String( "localHost" ), CDDB::clientName(), CDDB::clientVersion());
49 
50  url.addQueryItem( QLatin1String( "cmd" ), QLatin1String( "sites" ) );
51  url.addQueryItem( QLatin1String( "hello" ), hello );
52  url.addQueryItem( QLatin1String( "proto" ), QLatin1String( "5" ) );
53 
54  QList<Mirror> result;
55 
56  KIO::Job* job = KIO::get( url, KIO::NoReload, KIO::HideProgressInfo );
57  QByteArray data;
58  if( KIO::NetAccess::synchronousRun( job, 0, &data ) )
59  {
60  result = readData( data );
61  }
62 
63  return result;
64  }
65 
66  QList<Mirror>
67  Sites::readData(const QByteArray& data)
68  {
69  QList<Mirror> result;
70 
71  QTextStream ts(data);
72 
73  if (CDDB::statusCode(ts.readLine()) != 210)
74  return result;
75 
76  while (!ts.atEnd())
77  {
78  QString line = ts.readLine();
79  if (line == QLatin1String( "." ))
80  break;
81  result << parseLine(line);
82  }
83 
84  return result;
85  }
86 
87  Mirror
88  Sites::parseLine(const QString& line)
89  {
90  Mirror m;
91 
92  QRegExp rexp(QLatin1String( "([^ ]+) (cddbp|http) (\\d+) ([^ ]+) [N|S]\\d{3}.\\d{2} [E|W]\\d{3}.\\d{2} (.*)" ));
93 
94  if (rexp.indexIn(line) != -1)
95  {
96  m.address = rexp.cap(1);
97 
98  if (rexp.cap(2) == QLatin1String( "cddbp" ))
99  m.transport = Lookup::CDDBP;
100  else
101  m.transport = Lookup::HTTP;
102 
103  m.port = rexp.cap(3).toUInt();
104 
105  if (m.transport == Lookup::HTTP && rexp.cap(4) != QLatin1String( "/~cddb/cddb.cgi" ))
106  kWarning() << "Non default urls are not supported for http";
107 
108  m.description = rexp.cap(5);
109  }
110 
111  return m;
112  }
113 }
KCDDB::CDDB::clientName
static QString clientName()
Definition: cddb.h:41
QByteArray
KCDDB::CDDB::statusCode
static uint statusCode(const QString &)
Definition: cddb.cpp:104
QTextStream
KCDDB::Lookup::HTTP
Definition: lookup.h:43
QRegExp
KCDDB::CDDB::clientVersion
static QString clientVersion()
Definition: cddb.h:42
KCDDB::Lookup::CDDBP
Definition: lookup.h:42
QString
QList
KCDDB::Sites::siteList
QList< Mirror > siteList()
Definition: sites.cpp:37
QLatin1String
sites.h
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
KCDDB::Sites::Sites
Sites()
Definition: sites.cpp:31
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