00001 #ifndef METADATA_H_
00002 #define METADATA_H_
00003
00004
00005 #include <qstring.h>
00006 #include <qstringlist.h>
00007 #include <qptrlist.h>
00008 #include <qvaluelist.h>
00009 #include <qmap.h>
00010 #include <qthread.h>
00011
00012
00013 #include <mythtv/uitypes.h>
00014
00015
00016 #include "treecheckitem.h"
00017
00018
00019 class AllMusic;
00020 class CoverArt;
00021 class PlaylistsContainer;
00022
00023 enum ImageType
00024 {
00025 IT_UNKNOWN = 0,
00026 IT_FRONTCOVER,
00027 IT_BACKCOVER,
00028 IT_CD,
00029 IT_INLAY,
00030 IT_LAST
00031 };
00032
00033 typedef struct AlbumArtImage
00034 {
00035 int id;
00036 QString filename;
00037 ImageType imageType;
00038 QString typeName;
00039 QString description;
00040 bool embedded;
00041 } AlbumArtImage;
00042
00043
00044 class Metadata
00045 {
00046 public:
00047 Metadata(QString lfilename = "", QString lartist = "", QString lcompilation_artist = "",
00048 QString lalbum = "", QString ltitle = "", QString lgenre = "",
00049 int lyear = 0, int ltracknum = 0, int llength = 0, int lid = 0,
00050 int lrating = 0, int lplaycount = 0, QString llastplay = "",
00051 bool lcompilation = false, QString lformat="")
00052 : m_artist(lartist),
00053 m_compilation_artist(lcompilation_artist),
00054 m_album(lalbum),
00055 m_title(ltitle),
00056 m_formattedartist(""),
00057 m_formattedtitle(""),
00058 m_genre(lgenre),
00059 m_format(lformat),
00060 m_year(lyear),
00061 m_tracknum(ltracknum),
00062 m_length(llength),
00063 m_rating(lrating),
00064 m_directoryid(-1),
00065 m_artistid(-1),
00066 m_compartistid(-1),
00067 m_albumid(-1),
00068 m_genreid(-1),
00069 m_lastplay(llastplay),
00070 m_playcount(lplaycount),
00071 m_compilation(lcompilation),
00072 m_albumart(),
00073 m_id(lid),
00074 m_filename(lfilename),
00075 m_changed(false),
00076 m_show(true)
00077 {
00078 checkEmptyFields();
00079 }
00080
00081 Metadata(const Metadata &other)
00082 {
00083 *this = other;
00084 m_changed = false;
00085 }
00086
00087 Metadata& operator=(Metadata *rhs);
00088
00089 QString Artist() const { return m_artist; }
00090 void setArtist(const QString &lartist)
00091 {
00092 m_artist = lartist; m_formattedartist = m_formattedtitle = "";
00093 }
00094
00095 QString CompilationArtist() const { return m_compilation_artist; }
00096 void setCompilationArtist(const QString &lcompilation_artist)
00097 {
00098 m_compilation_artist = lcompilation_artist;
00099 m_formattedartist = m_formattedtitle = "";
00100 }
00101
00102 QString Album() const { return m_album; }
00103 void setAlbum(const QString &lalbum)
00104 {
00105 m_album = lalbum; m_formattedartist = m_formattedtitle = "";
00106 }
00107
00108 QString Title() const { return m_title; }
00109 void setTitle(const QString <itle) { m_title = ltitle; }
00110
00111 QString FormatArtist();
00112 QString FormatTitle();
00113
00114 QString Genre() { return m_genre; }
00115 void setGenre(const QString &lgenre) { m_genre = lgenre; }
00116
00117 void setDirectoryId(int ldirectoryid) { m_directoryid = ldirectoryid; }
00118 int getDirectoryId() const { return m_directoryid; }
00119
00120 void setArtistId(int lartistid) { m_artistid = lartistid; }
00121 int getArtistId() const { return m_artistid; }
00122
00123 void setAlbumId(int lalbumid) { m_albumid = lalbumid; }
00124 int getAlbumId() const { return m_albumid; }
00125
00126 void setGenreId(int lgenreid) { m_genreid = lgenreid; }
00127 int getGenreId() const { return m_genreid; }
00128
00129 int Year() { return m_year; }
00130 void setYear(int lyear) { m_year = lyear; }
00131
00132 int Track() const { return m_tracknum; }
00133 void setTrack(int ltrack) { m_tracknum = ltrack; }
00134
00135 int Length() const { return m_length; }
00136 void setLength(int llength) { m_length = llength; }
00137
00138 int Playcount() const { return m_playcount; }
00139 void setPlaycount(int lplaycount) { m_playcount = lplaycount; }
00140
00141 unsigned int ID() const { return m_id; }
00142 void setID(int lid) { m_id = lid; }
00143
00144 QString Filename() const { return m_filename; }
00145 void setFilename(const QString &lfilename) { m_filename = lfilename; }
00146
00147 QString Format() const { return m_format; }
00148 void setFormat(const QString &lformat) { m_format = lformat; }
00149
00150 int Rating() const { return m_rating; }
00151 void decRating();
00152 void incRating();
00153 void setRating(int lrating) { m_rating = lrating; }
00154
00155 double LastPlay();
00156 QString LastPlayStr() const { return m_lastplay; }
00157 void setLastPlay();
00158
00159 int PlayCount() const { return m_playcount; }
00160 void incPlayCount();
00161
00162 bool isVisible() const { return m_show; }
00163 void setVisible(bool visible) { m_show = visible; }
00164
00165
00166 bool Compilation() const { return m_compilation; }
00167 void setCompilation(bool state)
00168 {
00169 m_compilation = state; m_formattedartist = m_formattedtitle = "";
00170 }
00171 bool determineIfCompilation(bool cd = false);
00172
00173 void setEmbeddedAlbumArt(QValueList<struct AlbumArtImage> art);
00174
00175 bool isInDatabase(void);
00176 void dumpToDatabase(void);
00177 void setField(const QString &field, const QString &data);
00178 void getField(const QString& field, QString *data);
00179 void persist();
00180 bool hasChanged() {return m_changed;}
00181 int compare (Metadata *other);
00182 static void setArtistAndTrackFormats();
00183
00184 static void SetStartdir(const QString &dir);
00185 static QString GetStartdir() { return m_startdir; }
00186
00187 static QStringList fillFieldList(QString field);
00188 static Metadata *getMetadataFromID(int id);
00189
00190
00191 QImage getAlbumArt(void);
00192
00193 QImage getAlbumArt(ImageType type);
00194
00195 private:
00196 void setCompilationFormatting(bool cd = false);
00197 QString formatReplaceSymbols(const QString &format);
00198 void checkEmptyFields(void);
00199
00200 QString m_artist;
00201 QString m_compilation_artist;
00202 QString m_album;
00203 QString m_title;
00204 QString m_formattedartist;
00205 QString m_formattedtitle;
00206 QString m_genre;
00207 QString m_format;
00208 int m_year;
00209 int m_tracknum;
00210 int m_length;
00211 int m_rating;
00212 int m_directoryid;
00213 int m_artistid;
00214 int m_compartistid;
00215 int m_albumid;
00216 int m_genreid;
00217 QString m_lastplay;
00218 int m_playcount;
00219 bool m_compilation;
00220 QValueList<struct AlbumArtImage> m_albumart;
00221
00222 unsigned int m_id;
00223 QString m_filename;
00224 bool m_changed;
00225
00226 bool m_show;
00227
00228 static QString m_startdir;
00229
00230
00231 static QString m_formatnormalfileartist;
00232 static QString m_formatnormalfiletrack;
00233 static QString m_formatnormalcdartist;
00234 static QString m_formatnormalcdtrack;
00235
00236 static QString m_formatcompilationfileartist;
00237 static QString m_formatcompilationfiletrack;
00238 static QString m_formatcompilationcdartist;
00239 static QString m_formatcompilationcdtrack;
00240 };
00241
00242 bool operator==(const Metadata& a, const Metadata& b);
00243 bool operator!=(const Metadata& a, const Metadata& b);
00244
00245 class MetadataPtrList : public QPtrList<Metadata>
00246 {
00247 public:
00248 MetadataPtrList() {}
00249 ~MetadataPtrList() {}
00250
00251 protected:
00252 int compareItems(QPtrCollection::Item item1,
00253 QPtrCollection::Item item2);
00254 };
00255
00256 class MusicNode;
00257 class MusicNodePtrList : public QPtrList<MusicNode>
00258 {
00259 public:
00260 MusicNodePtrList() {}
00261 ~MusicNodePtrList() {}
00262
00263 protected:
00264 int compareItems(QPtrCollection::Item item1,
00265 QPtrCollection::Item item2);
00266 };
00267
00268 class MusicNode
00269 {
00270 public:
00271
00272 MusicNode(const QString &a_title, const QString &tree_level);
00273 ~MusicNode();
00274
00275 QString getTitle(){return my_title;}
00276 void printYourself(int indent_amount);
00277 void putYourselfOnTheListView(TreeCheckItem *parent, bool show_node);
00278 void writeTree(GenericTree *tree_to_write_to, int a_counter);
00279 void sort();
00280 void setPlayCountMin(int tmp_min) { m_playcountMin = tmp_min; }
00281 void setPlayCountMax(int tmp_max) { m_playcountMax = tmp_max; }
00282 void setLastPlayMin(double tmp_min) { m_lastplayMin = tmp_min; }
00283 void setLastPlayMax(double tmp_max) { m_lastplayMax = tmp_max; }
00284
00285 inline void addChild(MusicNode *child) { my_subnodes.append(child); }
00286 inline void addLeaf(Metadata *leaf) { my_tracks.append(leaf); }
00287 inline void setLeaves(MetadataPtrList leaves) { my_tracks = leaves; }
00288
00289 void clear(void) {
00290 my_tracks.clear();
00291 my_subnodes.clear();
00292 }
00293
00294 static void SetStaticData(const QString &startdir, const QString &paths);
00295
00296 private:
00297
00298 MetadataPtrList my_tracks;
00299 MusicNodePtrList my_subnodes;
00300 QString my_title;
00301 QString my_level;
00302
00303 static QString m_startdir;
00304 static QString m_paths;
00305 static int m_RatingWeight;
00306 static int m_PlayCountWeight;
00307 static int m_LastPlayWeight;
00308 static int m_RandomWeight;
00309
00310 int m_playcountMin;
00311 int m_playcountMax;
00312 double m_lastplayMin;
00313 double m_lastplayMax;
00314 };
00315
00316
00317
00318 class MetadataLoadingThread : public QThread
00319 {
00320
00321 public:
00322
00323 MetadataLoadingThread(AllMusic *parent_ptr);
00324 virtual void run();
00325
00326 private:
00327
00328 AllMusic *parent;
00329 };
00330
00331
00332
00333 class AllMusic
00334 {
00335
00336
00337
00338 public:
00339
00340 AllMusic(QString path_assignment, QString a_startdir);
00341 ~AllMusic();
00342
00343 QString getLabel(int an_id, bool *error_flag);
00344 Metadata* getMetadata(int an_id);
00345 bool updateMetadata(int an_id, Metadata *the_track);
00346 int count() const { return m_numPcs; }
00347 int countLoaded() const { return m_numLoaded; }
00348 void save();
00349 bool startLoading(void);
00350 void resync();
00351 void clearCDData();
00352 void addCDTrack(Metadata *the_track);
00353 bool checkCDTrack(Metadata *the_track);
00354 bool getCDMetadata(int m_the_track, Metadata *some_metadata);
00355 QString getCDTitle(){return m_cd_title;}
00356 void setCDTitle(const QString &a_title){m_cd_title = a_title;}
00357 void buildTree();
00358 void printTree();
00359 void sortTree();
00360 inline void clearTree() { m_root_node-> clear(); }
00361 void writeTree(GenericTree *tree_to_write_to);
00362 void setSorting(QString a_paths);
00363 bool putYourselfOnTheListView(TreeCheckItem *where);
00364 void putCDOnTheListView(CDCheckItem *where);
00365 bool doneLoading(){return m_done_loading;}
00366 bool cleanOutThreads();
00367 int getCDTrackCount(){return m_cd_data.count();}
00368 void resetListings(){m_last_listed = -1;}
00369 void setAllVisible(bool visible);
00370
00371 private:
00372
00373 MetadataPtrList m_all_music;
00374 MusicNode *m_root_node;
00375
00376 int m_numPcs;
00377 int m_numLoaded;
00378
00379
00380
00381
00382
00383
00384 typedef QMap<int, Metadata*> MusicMap;
00385 MusicMap music_map;
00386
00387 typedef QValueList<Metadata> ValueMetadata;
00388 ValueMetadata m_cd_data;
00389 QString m_cd_title;
00390
00391 QString m_startdir;
00392 QString m_paths;
00393
00394
00395 MetadataLoadingThread *m_metadata_loader;
00396 bool m_done_loading;
00397 int m_last_listed;
00398
00399 int m_playcountMin;
00400 int m_playcountMax;
00401 double m_lastplayMin;
00402 double m_lastplayMax;
00403
00404 };
00405
00406
00407
00408 class MusicData
00409 {
00410 public:
00411
00412 MusicData();
00413 ~MusicData();
00414
00415 QString paths;
00416 QString startdir;
00417 PlaylistsContainer *all_playlists;
00418 AllMusic *all_music;
00419 bool runPost;
00420 };
00421
00422
00423 extern MPUBLIC MusicData *gMusicData;
00424
00425
00426
00427 class AlbumArtImages: public QObject
00428 {
00429 Q_OBJECT
00430
00431 public:
00432 AlbumArtImages(Metadata *metadata);
00433
00434 uint getImageCount() { return m_imageList.count(); }
00435 AlbumArtImage getImage(ImageType type);
00436 QString getTypeName(ImageType type);
00437 QStringList getImageFilenames();
00438 QPtrList<AlbumArtImage> *getImageList() { return &m_imageList; }
00439 AlbumArtImage getImageAt(uint index);
00440
00441 bool isImageAvailable(ImageType type);
00442
00443 bool saveImageType(const int id, ImageType type);
00444
00445 static ImageType guessImageType(const QString &filename);
00446
00447 private:
00448 void findImages(void);
00449
00450 Metadata *m_parent;
00451 QPtrList<AlbumArtImage> m_imageList;
00452 };
00453
00454 #endif