1 /***************************************************************************
2 copyright : (C) 2004 by Scott Wheeler
3 email : wheeler@kde.org
4 ***************************************************************************/
6 /***************************************************************************
7 * This library is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU Lesser General Public License version *
9 * 2.1 as published by the Free Software Foundation. *
11 * This library is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14 * Lesser General Public License for more details. *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with this library; if not, write to the Free Software *
18 * Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301 *
20 ***************************************************************************/
23 * At some point this will likely be a library class, as such it's been written
24 * as such and is LGPL'ed.
33 #include <q3valuelist.h>
36 * This represents a potential match for a TRM lookup. KTRMResultList is
37 * returned from KTRMLookup and will be sorted by relevance (better matches
38 * at the beginning of the list).
41 namespace KIO
{ class Job
; }
45 friend class KTRMLookup
;
49 KTRMResult(const KTRMResult
&result
);
53 * Returns the title of the track for the potential match.
55 QString
title() const;
58 * Returns the artist name of the track for the potential match.
60 QString
artist() const;
63 * Returns the album name of the track for the potential match.
65 QString
album() const;
68 * Returns the track number of the track for the potential match.
73 * Returns the original release year of the track for the potential match.
78 * Returns true if all of the values for the result are empty.
83 * Compares to \a r based on the relevance of the match. Better matches
84 * will be greater than less accurate matches.
86 bool operator<(const KTRMResult
&r
) const;
89 * Compares to \a r based on the relevance of the match. Better matches
90 * will be greater than less accurate matches.
92 bool operator>(const KTRMResult
&r
) const;
95 * Basic assignment operator; required for the QTL
97 KTRMResult
&operator= (const KTRMResult
&r
);
100 * Basic comparison operator; required for the QTL
102 bool operator== (const KTRMResult
&r
) const;
105 class KTRMResultPrivate
;
106 KTRMResultPrivate
*d
;
109 typedef Q3ValueList
<KTRMResult
> KTRMResultList
;
112 * An abstraction for libtunepimp's TRM based lookup and file recognition.
114 * A lookup is started when the object is created. One of the virtual methods
115 * -- recognized(), unrecognized(), collision() or error(). Those methods
116 * should be reimplemented in subclasses to specify what behavior should happen
119 * The lookups themselves happen in a background thread, but the return calls
120 * are guaranteed to run in the GUI thread.
122 class KTRMLookup
: public QObject
127 void sigResult( KTRMResultList
, QString
);
130 virtual void lookupResult( KIO::Job
* );
134 * Creates and starts a lookup for \a file. If \a autoDelete is set to
135 * true the lookup will delete itself when it has finished.
137 explicit KTRMLookup(const QString
&file
, bool autoDelete
= false);
139 virtual ~KTRMLookup();
142 * Returns the file name that was specified in the constructor.
144 QString
file() const;
147 * Returns the TunePimp file ID for the file. This is of no use to the
155 * This method is called when the puid was already generated. It will then do
156 * the lookup with MusicBrainz's server. This may be reimplemented to provide
157 * specific behavion for the lookup.
159 virtual void puidGenerated();
162 * This method is called if the track was recognized by the TRM server.
163 * results() will return just one value. This may be reimplemented to
164 * provide specific behavion in the case of the track being recognized.
166 * \note The base class call should happen at the beginning of the subclass
167 * reimplementation; it populates the values of results().
169 virtual void recognized();
172 * This method is called if the track was not recognized by the TRM server.
173 * results() will return an empty set. This may be reimplemented to provide
174 * specific behavion in the case of the track not being recognized.
176 virtual void unrecognized();
179 * This method is called if there are multiple potential matches for the TRM
180 * value. results() will return a list of the potential matches, sorted by
181 * liklihood. This may be reimplemented to provide
182 * specific behavion in the case of the track not being recognized.
184 * \note The base class call should happen at the beginning of the subclass
185 * reimplementation; it populates the values of results().
187 virtual void collision();
190 * This method is called if the track was not recognized by the TRM server.
191 * results() will return an empty set. This may be reimplemented to provide
192 * specific behavion in the case of the track not being recognized.
194 virtual void error();
197 * Returns the list of matches found by the lookup. In the case that there
198 * was a TRM collision this list will contain multiple entries. In the case
199 * that it was recognized this will only contain one entry. Otherwise it
202 KTRMResultList
results() const;
206 * This method is called when any of terminal states (recognized,
207 * unrecognized, collision or error) has been reached after the specific
208 * method for the result has been called.
210 * This should be reimplemented in the case that there is some general
211 * processing to be done for all terminal states.
213 virtual void finished();
216 class KTRMLookupPrivate
;
217 KTRMLookupPrivate
*d
;
221 * Helper Functions used for sorting MusicBrainz results
223 double stringSimilarity(QString s1
, QString s2
);
224 double stringSimilarity(QStringList
&l
, QString
&s
);