~ubuntu-branches/ubuntu/gutsy/kid3/gutsy

« back to all changes in this revision

Viewing changes to kid3/musicbrainzclient.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sarah Hobbs
  • Date: 2006-07-14 12:25:16 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060714122516-p2wk0iyzumu6jx42
Tags: 0.7-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#include <qfile.h>
20
20
#include "musicbrainzconfig.h"
21
21
#include "freedbclient.h"
 
22
#include "importtrackdata.h"
22
23
 
23
24
/**
24
25
 * Constructor.
29
30
MusicBrainzClient::MusicBrainzClient(ImportTrackDataVector& trackDataList) :
30
31
        m_trackDataVector(trackDataList), m_tp(0), m_ids(0), m_numFiles(0)
31
32
{
32
 
        m_tp = tp_New("kid3", "0.6");
 
33
        m_tp = tp_New("kid3", VERSION);
 
34
#ifdef WIN32
 
35
        tp_WSAInit(m_tp);
 
36
#endif
 
37
#if HAVE_TUNEPIMP >= 4
 
38
        tp_SetID3Encoding(m_tp, eUTF8);
 
39
#else
 
40
        tp_SetUseUTF8(m_tp, 1);
 
41
#endif
33
42
        tp_SetAutoFileLookup(m_tp, 1);
34
43
        tp_SetRenameFiles(m_tp, 0);
35
44
        tp_SetMoveFiles(m_tp, 0);
46
55
{
47
56
        removeFiles();
48
57
        if (m_tp) {
 
58
#ifdef WIN32
 
59
                tp_WSAStop(m_tp);
 
60
#endif
49
61
                tp_Delete(m_tp);
50
62
        }
51
63
}
92
104
{
93
105
        static const struct id_str_s { TPFileStatus id; const char *str; }
94
106
        id_str[] = {
 
107
#if HAVE_TUNEPIMP >= 4
 
108
    { eMetadataRead,  I18N_NOOP("Metadata Read") },
 
109
#endif
95
110
    { eUnrecognized,  I18N_NOOP("Unrecognized") },
96
111
    { eRecognized,    I18N_NOOP("Recognized") },
97
112
    { ePending,       I18N_NOOP("Pending") },
122
137
void MusicBrainzClient::pollStatus()
123
138
{
124
139
        TPCallbackEnum type;
125
 
        TPFileStatus status;
126
140
        int id;
127
 
        while (tp_GetNotification(m_tp, &type, &id, &status)) {
 
141
#if HAVE_TUNEPIMP >= 4
 
142
        TPFileStatus statusCode;
 
143
        while (tp_GetNotification(m_tp, &type, &id, &statusCode))
 
144
#else
 
145
        while (tp_GetNotification(m_tp, &type, &id))
 
146
#endif
 
147
        {
128
148
                QString fn = getFilename(id);
129
149
                int index = getIndexOfId(id);
130
150
                switch (type) {
136
156
                                break;
137
157
                        case tpFileChanged:
138
158
                        {
 
159
#if HAVE_TUNEPIMP >= 4
 
160
                                if (statusCode == eUnrecognized) {
 
161
                                        char trm[255];
 
162
                                        trm[0] = '\0';
 
163
                                        track_t track = tp_GetTrack(m_tp, id);
 
164
                                        if (track) {
 
165
                                                tr_Lock(track);
 
166
                                                tr_GetTRM(track, trm, sizeof(trm));
 
167
                                                if (trm[0] == '\0') {
 
168
                                                        tr_SetStatus(track, ePending);
 
169
                                                        tp_Wake(m_tp, track);
 
170
                                                }
 
171
                                                tr_Unlock(track);
 
172
                                                tp_ReleaseTrack(m_tp, track);
 
173
                                        }
 
174
                                }
 
175
#else
 
176
                                TPFileStatus statusCode = eLastStatus;
139
177
                                track_t track = tp_GetTrack(m_tp, id);
140
178
                                if (track) {
141
179
                                        tr_Lock(track);
142
 
                                        TPFileStatus statusCode = tr_GetStatus(track);
 
180
                                        statusCode = tr_GetStatus(track);
143
181
                                        tr_Unlock(track);
144
182
                                        tp_ReleaseTrack(m_tp, track);
 
183
                                }
 
184
#endif
 
185
                                if (statusCode != eLastStatus) {
145
186
                                        const char* statusText = getFileStatusText(statusCode);
146
187
                                        emit statusChanged(index, i18n(statusText));
147
188
                                        if (statusCode == eRecognized) {
211
252
                         it = m_trackDataVector.begin();
212
253
                         it != m_trackDataVector.end();
213
254
                         ++it) {
 
255
#if HAVE_TUNEPIMP >= 4
214
256
                m_ids[i++] = tp_AddFile(m_tp, QFile::encodeName((*it).getAbsFilename()), 0);
 
257
#else
 
258
                m_ids[i++] = tp_AddFile(m_tp, QFile::encodeName((*it).getAbsFilename()));
 
259
#endif
215
260
        }
216
261
}
217
262
 
290
335
                                        albumtrackresult_t* res = *albumTrackResults++;
291
336
                                        ImportTrackData trackData;
292
337
                                        trackData.title = QString::fromUtf8(res->name);
 
338
#if HAVE_TUNEPIMP >= 4
293
339
                                        trackData.artist = QString::fromUtf8(res->artist.name);
294
340
                                        trackData.album = QString::fromUtf8(res->album.name);
 
341
                                        trackData.year = res->album.releaseYear;
 
342
#else
 
343
                                        trackData.artist = QString::fromUtf8(res->artist->name);
 
344
                                        trackData.album = QString::fromUtf8(res->album->name);
 
345
                                        trackData.year = res->album->releaseYear;
 
346
#endif
295
347
                                        trackData.track = res->trackNum;
296
 
                                        trackData.year = res->album.releaseYear;
297
348
                                        // year does not seem to work, so at least we should not
298
349
                                        // overwrite it with 0
299
350
                                        if (trackData.year == 0) {