summaryrefslogtreecommitdiffstats
path: root/libk3bdevice/k3bcdtext.h
blob: 10f6c821edac92a9df286089420a1ee355914c05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/* 
 *
 * $Id: k3bcdtext.h 619556 2007-01-03 17:38:12Z trueg $
 * Copyright (C) 2003-2007 Sebastian Trueg <[email protected]>
 *
 * This file is part of the K3b project.
 * Copyright (C) 1998-2007 Sebastian Trueg <[email protected]>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * See the file "COPYING" for the exact licensing terms.
 */


#ifndef _K3B_CDTEXT_H_
#define _K3B_CDTEXT_H_

#include <qstring.h>
#include <qvaluevector.h>
#include "k3bdevice_export.h"

namespace K3bDevice
{
  struct cdtext_pack;

  class TrackCdText
    {
      friend class Device;
      
    public:
      TrackCdText() {
      }

      void clear() {
	m_title.truncate(0);
	m_performer.truncate(0);
	m_songwriter.truncate(0);
	m_composer.truncate(0);
	m_arranger.truncate(0);
	m_message.truncate(0);
	m_isrc.truncate(0);
      }

      const QString& title() const { return m_title; }
      const QString& performer() const { return m_performer; }
      const QString& songwriter() const { return m_songwriter; }
      const QString& composer() const { return m_composer; }
      const QString& arranger() const { return m_arranger; }
      const QString& message() const { return m_message; }
      const QString& isrc() const { return m_isrc; }

      // TODO: use the real CD-TEXT charset (a modified ISO8859-1)
      void setTitle( const QString& s ) { m_title = s; fixup(m_title); }
      void setPerformer( const QString& s ) { m_performer = s; fixup(m_performer); }
      void setSongwriter( const QString& s ) { m_songwriter = s; fixup(m_songwriter); }
      void setComposer( const QString& s ) { m_composer = s; fixup(m_composer); }
      void setArranger( const QString& s ) { m_arranger = s; fixup(m_arranger); }
      void setMessage( const QString& s ) { m_message = s; fixup(m_message); }
      void setIsrc( const QString& s ) { m_isrc = s; fixup(m_isrc); }

      bool isEmpty() const {
	if( !m_title.isEmpty() )
	  return false;
	if( !m_performer.isEmpty() )
	  return false;
	if( !m_songwriter.isEmpty() )
	  return false;
	if( !m_composer.isEmpty() )
	  return false;
	if( !m_arranger.isEmpty() )
	  return false;
	if( !m_message.isEmpty() )
	  return false;
	if( !m_isrc.isEmpty() )
	  return false;

	return true;
      }

      bool operator==( const TrackCdText& ) const;
      bool operator!=( const TrackCdText& ) const;

    private:
      // TODO: remove this (see above)
      void fixup( QString& s ) { s.replace( '/', "_" ); s.replace( '\"', "_" ); }

      QString m_title;
      QString m_performer;
      QString m_songwriter;
      QString m_composer;
      QString m_arranger;
      QString m_message;
      QString m_isrc;

      friend class CdText;
    };

  class LIBK3BDEVICE_EXPORT CdText : public QValueVector<TrackCdText>
    {
      friend class Device;

    public:
      CdText();
      CdText( const unsigned char* data, int len );
      CdText( const QByteArray& );
      CdText( int size );
      CdText( const CdText& );

      void setRawPackData( const unsigned char*, int );
      void setRawPackData( const QByteArray& );

      QByteArray rawPackData() const;

      bool empty() const {
	if( !m_title.isEmpty() )
	  return false;
	if( !m_performer.isEmpty() )
	  return false;
	if( !m_songwriter.isEmpty() )
	  return false;
	if( !m_composer.isEmpty() )
	  return false;
	if( !m_arranger.isEmpty() )
	  return false;
	if( !m_message.isEmpty() )
	  return false;
	if( !m_discId.isEmpty() )
	  return false;
	if( !m_upcEan.isEmpty() )
	  return false;
	
	for( unsigned int i = 0; i < count(); ++i )
	  if( !at(i).isEmpty() )
	    return false;

	return true;
      }

      bool isEmpty() const {
	return empty();
      }

      void clear();

      const QString& title() const { return m_title; }
      const QString& performer() const { return m_performer; }
      const QString& songwriter() const { return m_songwriter; }
      const QString& composer() const { return m_composer; }
      const QString& arranger() const { return m_arranger; }
      const QString& message() const { return m_message; }
      const QString& discId() const { return m_discId; }
      const QString& upcEan() const { return m_upcEan; }

      // TODO: use the real CD-TEXT charset (a modified ISO8859-1)
      void setTitle( const QString& s ) { m_title = s; fixup(m_title); }
      void setPerformer( const QString& s ) { m_performer = s; fixup(m_performer); }
      void setSongwriter( const QString& s ) { m_songwriter = s; fixup(m_songwriter); }
      void setComposer( const QString& s ) { m_composer = s; fixup(m_composer); }
      void setArranger( const QString& s ) { m_arranger = s; fixup(m_arranger); }
      void setMessage( const QString& s ) { m_message = s; fixup(m_message); }
      void setDiscId( const QString& s ) { m_discId = s; fixup(m_discId); }
      void setUpcEan( const QString& s ) { m_upcEan = s; fixup(m_upcEan); }

      void debug() const;

      /**
       * Returns false if found a crc error in the raw cdtext block or it has a
       * wrong length.
       */
      static bool checkCrc( const unsigned char*, int );
      static bool checkCrc( const QByteArray& );

      bool operator==( const CdText& ) const;
      bool operator!=( const CdText& ) const;
	
    private:
      // TODO: remove this (see above)
      void fixup( QString& s ) { s.replace( '/', "_" ); s.replace( '\"', "_" ); }

      const QString& textForPackType( int packType, unsigned int track ) const;
      unsigned int textLengthForPackType( int packType ) const;
      QByteArray createPackData( int packType, unsigned int& ) const;
      void savePack( cdtext_pack* pack, QByteArray& data, unsigned int& dataFill ) const;
      void appendByteArray( QByteArray& a, const QByteArray& b ) const;

      QString m_title;
      QString m_performer;
      QString m_songwriter;
      QString m_composer;
      QString m_arranger;
      QString m_message;
      QString m_discId;
      QString m_upcEan;
    };

  QCString encodeCdText( const QString& s, bool* illegalChars = 0 );
}

#endif