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

« back to all changes in this revision

Viewing changes to libkcddb/cddb.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
  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., 59 Temple Place - Suite 330,
 
19
  Boston, MA 02111-1307, USA.
 
20
*/
 
21
 
 
22
#include <qregexp.h>
 
23
#include <qstringlist.h>
 
24
 
 
25
#include <kdebug.h>
 
26
#include <kstringhandler.h>
 
27
#include <klocale.h>
 
28
 
 
29
#include "cddb.h"
 
30
 
 
31
namespace KCDDB
 
32
{
 
33
  CDDB::CDDB()
 
34
    : user_( "libkcddb-user" ),
 
35
      localHostName_( "localHost" ),
 
36
      readOnly_( false )
 
37
  {
 
38
 
 
39
  }
 
40
 
 
41
  CDDB::~CDDB()
 
42
  {
 
43
    // Empty.
 
44
  }
 
45
 
 
46
    QString
 
47
  CDDB::trackOffsetListToId()
 
48
  {
 
49
    return trackOffsetListToId( trackOffsetList_ );
 
50
  }
 
51
    QString
 
52
  CDDB::trackOffsetListToId( const TrackOffsetList & list )
 
53
  {
 
54
    // Taken from version by Michael Matz in kio_audiocd.
 
55
    unsigned int id = 0;
 
56
    int numTracks = list.count() - 2;
 
57
 
 
58
    // The last two in the list are disc begin and disc end.
 
59
    for ( int i = numTracks-1; i >= 0; i-- )
 
60
    {
 
61
      int n = list[ i ]/75;
 
62
      while ( n > 0 )
 
63
      {
 
64
        id += n % 10;
 
65
        n /= 10;
 
66
      }
 
67
    }
 
68
 
 
69
    unsigned int l = (list[numTracks + 1] + 1) / 75;
 
70
    l -= list[0] / 75;
 
71
 
 
72
    id = ( ( id % 255 ) << 24 ) | ( l << 8 ) | numTracks;
 
73
 
 
74
    return QString::number( id, 16 ).rightJustify( 8, '0' );
 
75
  }
 
76
 
 
77
    QString
 
78
  CDDB::trackOffsetListToString()
 
79
  {
 
80
    QString ret;
 
81
    uint numTracks = trackOffsetList_.count()-2;
 
82
 
 
83
    // Disc start.
 
84
    ret.append( QString::number( numTracks ) );
 
85
    ret.append( " " );
 
86
 
 
87
    for ( uint i = 0; i < numTracks; i++ )
 
88
    {
 
89
      ret.append( QString::number( trackOffsetList_[ i ] ) );
 
90
      ret.append( " " );
 
91
    }
 
92
 
 
93
    unsigned int discLengthInSec = ( trackOffsetList_[ numTracks+1 ] ) / 75;
 
94
 
 
95
    // Disc length in seconds.
 
96
    ret.append( QString::number( discLengthInSec ) );
 
97
 
 
98
    return ret;
 
99
  }
 
100
 
 
101
    bool
 
102
  CDDB::parseGreeting( const QString & line )
 
103
  {
 
104
    uint serverStatus = statusCode( line );
 
105
 
 
106
    if ( 200 == serverStatus )
 
107
    {
 
108
      kdDebug(60010) << "Server response: read-only" << endl;
 
109
      readOnly_ = true;
 
110
    }
 
111
    else if ( 201 == serverStatus )
 
112
    {
 
113
      kdDebug(60010) << "Server response: read-write" << endl;
 
114
    }
 
115
    else
 
116
    {
 
117
      kdDebug(60010) << "Server response: bugger off" << endl;
 
118
      return false;
 
119
    }
 
120
 
 
121
    return true;
 
122
  }
 
123
 
 
124
    bool
 
125
  CDDB::parseHandshake( const QString & line )
 
126
  {
 
127
    uint serverStatus = statusCode( line );
 
128
 
 
129
    if ( ( 200 != serverStatus ) && ( 402 != serverStatus ) )
 
130
    {
 
131
      kdDebug(60010) << "Handshake was too tight. Letting go." << endl;
 
132
      return false;
 
133
    }
 
134
 
 
135
    kdDebug(60010) << "Handshake was warm and firm" << endl;
 
136
 
 
137
    return true;
 
138
  }
 
139
 
 
140
    uint
 
141
  CDDB::statusCode( const QString & line )
 
142
  {
 
143
    QStringList tokenList = QStringList::split( ' ', line );
 
144
 
 
145
    uint serverStatus = tokenList[ 0 ].toUInt();
 
146
 
 
147
    return serverStatus;
 
148
  }
 
149
 
 
150
/*    CDDB::Transport
 
151
  CDDB::stringToTransport(const QString & s)
 
152
  {
 
153
    if  ("HTTP" == s )
 
154
      return HTTP;
 
155
    else if ( "CDDBP" == s )
 
156
      return CDDBP;
 
157
    else
 
158
      return SMTP;
 
159
  }*/
 
160
 
 
161
    QString
 
162
  CDDB::resultToString(Result r)
 
163
  {
 
164
    switch (r)
 
165
    {
 
166
      case Success:
 
167
        return i18n("Success");
 
168
        break;
 
169
 
 
170
      case ServerError:
 
171
        return i18n("Server error");
 
172
        break;
 
173
 
 
174
      case HostNotFound:
 
175
        return i18n("Host not found");
 
176
        break;
 
177
 
 
178
      case NoResponse:
 
179
        return i18n("No response");
 
180
        break;
 
181
 
 
182
      case NoRecordFound:
 
183
        return i18n("No record found");
 
184
        break;
 
185
 
 
186
      case MultipleRecordFound:
 
187
        return i18n("Multiple records found");
 
188
        break;
 
189
 
 
190
      case CannotSave:
 
191
        return i18n("Cannot save");
 
192
        break;
 
193
 
 
194
      case InvalidCategory:
 
195
        return i18n("Invalid category");
 
196
        break;
 
197
 
 
198
      default:
 
199
        return i18n("Unknown error");
 
200
        break;
 
201
    }
 
202
  }
 
203
 
 
204
/*    QString
 
205
  CDDB::transportToString(uint t)
 
206
  {
 
207
    switch (Transport(t))
 
208
    {
 
209
      case HTTP:
 
210
        return "HTTP";
 
211
        break;
 
212
 
 
213
      case CDDBP:
 
214
        return "CDDBP";
 
215
        break;
 
216
 
 
217
      case SMTP:
 
218
        return "SMTP";
 
219
        break;
 
220
 
 
221
      default:
 
222
        return "UnknownTransport";
 
223
        break;
 
224
    }
 
225
  }*/
 
226
}
 
227
 
 
228
// vim:tabstop=2:shiftwidth=2:expandtab:cinoptions=(s,U1,m1