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 Street, 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.
30 #include <q3valuelist.h>
37 * This represents a potential match for a TRM lookup. KTRMResultList is
38 * returned from KTRMLookup and will be sorted by relevance (better matches
39 * at the beginning of the list).
42 namespace KIO
{ class Job
; }
46 friend class KTRMLookup
;
50 KTRMResult(const KTRMResult
&result
);
54 * Returns the title of the track for the potential match.
56 QString
title() const;
59 * Returns the artist name of the track for the potential match.
61 QString
artist() const;
64 * Returns the album name of the track for the potential match.
66 QString
album() const;
69 * Returns the track number of the track for the potential match.
74 * Returns the original release year of the track for the potential match.
79 * Returns true if all of the values for the result are empty.
84 * Compares to \a r based on the relevance of the match. Better matches
85 * will be greater than less accurate matches.
87 bool operator<(const KTRMResult
&r
) const;
90 * Compares to \a r based on the relevance of the match. Better matches
91 * will be greater than less accurate matches.
93 bool operator>(const KTRMResult
&r
) const;
96 * Basic assignment operator; required for the QTL
98 KTRMResult
&operator= (const KTRMResult
&r
);
101 * Basic comparison operator; required for the QTL
103 bool operator== (const KTRMResult
&r
) const;
106 class KTRMResultPrivate
;
107 KTRMResultPrivate
*d
;
110 typedef Q3ValueList
<KTRMResult
> KTRMResultList
;
113 * An abstraction for libtunepimp's TRM based lookup and file recognition.
115 * A lookup is started when the object is created. One of the virtual methods
116 * -- recognized(), unrecognized(), collision() or error(). Those methods
117 * should be reimplemented in subclasses to specify what behavior should happen
120 * The lookups themselves happen in a background thread, but the return calls
121 * are guaranteed to run in the GUI thread.
123 class KTRMLookup
: public QObject
128 void sigResult( KTRMResultList
, QString
);
131 virtual void lookupResult( KIO::Job
* );
135 * Creates and starts a lookup for \a file. If \a autoDelete is set to
136 * true the lookup will delete itself when it has finished.
138 explicit KTRMLookup(const QString
&file
, bool autoDelete
= false);
140 virtual ~KTRMLookup();
143 * Returns the file name that was specified in the constructor.
145 QString
file() const;
148 * Returns the TunePimp file ID for the file. This is of no use to the
156 * This method is called when the puid was already generated. It will then do
157 * the lookup with MusicBrainz's server. This may be reimplemented to provide
158 * specific behavion for the lookup.
160 virtual void puidGenerated();
163 * This method is called if the track was recognized by the TRM server.
164 * results() will return just one value. This may be reimplemented to
165 * provide specific behavion in the case of the track being recognized.
167 * \note The base class call should happen at the beginning of the subclass
168 * reimplementation; it populates the values of results().
170 virtual void recognized();
173 * This method is called if the track was not recognized by the TRM server.
174 * results() will return an empty set. This may be reimplemented to provide
175 * specific behavion in the case of the track not being recognized.
177 virtual void unrecognized();
180 * This method is called if there are multiple potential matches for the TRM
181 * value. results() will return a list of the potential matches, sorted by
182 * liklihood. This may be reimplemented to provide
183 * specific behavion in the case of the track not being recognized.
185 * \note The base class call should happen at the beginning of the subclass
186 * reimplementation; it populates the values of results().
188 virtual void collision();
191 * This method is called if the track was not recognized by the TRM server.
192 * results() will return an empty set. This may be reimplemented to provide
193 * specific behavion in the case of the track not being recognized.
195 virtual void error();
198 * Returns the list of matches found by the lookup. In the case that there
199 * was a TRM collision this list will contain multiple entries. In the case
200 * that it was recognized this will only contain one entry. Otherwise it
203 KTRMResultList
results() const;
207 * This method is called when any of terminal states (recognized,
208 * unrecognized, collision or error) has been reached after the specific
209 * method for the result has been called.
211 * This should be reimplemented in the case that there is some general
212 * processing to be done for all terminal states.
214 virtual void finished();
217 class KTRMLookupPrivate
;
218 KTRMLookupPrivate
*d
;
222 * Helper Functions used for sorting MusicBrainz results
224 double stringSimilarity(QString s1
, QString s2
);
225 double stringSimilarity(QStringList
&l
, QString
&s
);