add mp3 and ogg torrent url info to JamendoAlbum
[amarok.git] / src / ktrm.h
blob2aa867310c71a5e4f54d67f38bdfb821a6787a47
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. *
10 * *
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. *
15 * *
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 *
19 * USA *
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.
27 #ifndef KTRM_H
28 #define KTRM_H
30 #include <q3valuelist.h>
31 #include <QMap>
32 #include <QObject>
33 #include <QString>
36 /**
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; }
44 class KTRMResult
46 friend class KTRMLookup;
48 public:
49 KTRMResult();
50 KTRMResult(const KTRMResult &result);
51 ~KTRMResult();
53 /**
54 * Returns the title of the track for the potential match.
56 QString title() const;
58 /**
59 * Returns the artist name of the track for the potential match.
61 QString artist() const;
63 /**
64 * Returns the album name of the track for the potential match.
66 QString album() const;
68 /**
69 * Returns the track number of the track for the potential match.
71 int track() const;
73 /**
74 * Returns the original release year of the track for the potential match.
76 int year() const;
78 /**
79 * Returns true if all of the values for the result are empty.
81 bool isEmpty() const;
83 /**
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;
89 /**
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;
95 /**
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;
105 private:
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
118 * for each result.
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
125 Q_OBJECT
127 signals:
128 void sigResult( KTRMResultList, QString );
130 protected slots:
131 virtual void lookupResult( KIO::Job* );
133 public:
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
149 * public API.
151 * @internal
153 int fileId() const;
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
201 * will remain empty.
203 KTRMResultList results() const;
205 protected:
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();
216 private:
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);
227 #endif /*KTRM_H*/