00001 #ifndef PLAYLIST_H_
00002 #define PLAYLIST_H_
00003
00004 #include <qvaluelist.h>
00005 #include <qlistview.h>
00006 #include <qptrlist.h>
00007 #include <qthread.h>
00008
00009 #include "metadata.h"
00010 #include "treecheckitem.h"
00011 #include <mythtv/uitypes.h>
00012 #include <mythtv/uilistbtntype.h>
00013
00014 class PlaylistsContainer;
00015
00016
00017 enum InsertPLOption
00018 {
00019 PL_REPLACE = 1,
00020 PL_INSERTATBEGINNING,
00021 PL_INSERTATEND,
00022 PL_INSERTAFTERCURRENT,
00023 PL_FILTERONLY
00024 };
00025
00026 enum PlayPLOption
00027 {
00028 PL_FIRST = 1,
00029 PL_FIRSTNEW,
00030 PL_CURRENT
00031 };
00032
00033 class Track
00034 {
00035
00036
00037
00038
00039
00040 public:
00041 Track(int x, AllMusic *all_music_ptr);
00042
00043 void postLoad(PlaylistsContainer *grandparent);
00044
00045 void setParent(Playlist *parent_ptr);
00046 void setValue(int x){index_value = x;}
00047
00048 void putYourselfOnTheListView(UIListGenericTree *a_listviewitem);
00049
00050 int getValue(){return index_value;}
00051
00052 void deleteYourWidget();
00053 void deleteYourself();
00054 void moveUpDown(bool flag);
00055
00056 PlaylistTrack* getWidget(void) { return my_widget; }
00057 bool badReference(void) { return bad_reference; }
00058 void setCDFlag(bool yes_or_no) { cd_flag = yes_or_no; }
00059 bool getCDFlag(void) { return cd_flag; }
00060
00061 private:
00062 int index_value;
00063 PlaylistTrack *my_widget;
00064 AllMusic *all_available_music;
00065 QString label;
00066 Playlist *parent;
00067 bool bad_reference;
00068 bool cd_flag;
00069 };
00070
00071 class Playlist
00072 {
00073 public:
00074 Playlist(AllMusic *all_music_ptr);
00075 ~Playlist();
00076
00077 Playlist& operator=(const Playlist& rhs);
00078
00079 void setParent(PlaylistsContainer *myparent) { parent = myparent; }
00080
00081 void postLoad(void);
00082
00083 void loadPlaylist(QString a_name, QString a_host);
00084 void loadPlaylistByID(int id, QString a_host);
00085
00086 void savePlaylist(QString a_name, QString a_host);
00087
00088 void putYourselfOnTheListView(UIListGenericTree *a_parent);
00089
00090 int writeTree(GenericTree *tree_to_write_to, int a_counter);
00091
00092 void describeYourself(void);
00093
00094 void fillSongsFromCD();
00095 void fillSongsFromSonglist(bool filter);
00096 void fillSongsFromSonglist(QString songList, bool filter);
00097 void fillSonglistFromSongs();
00098 void fillSonglistFromQuery(QString whereClause,
00099 bool removeDuplicates = false,
00100 InsertPLOption insertOption = PL_REPLACE,
00101 int currentTrackID = 0);
00102 void fillSonglistFromSmartPlaylist(QString category, QString name,
00103 bool removeDuplicates = false,
00104 InsertPLOption insertOption = PL_REPLACE,
00105 int currentTrackID = 0);
00106 QString getSonglist(void) { return raw_songlist; }
00107
00108 void moveTrackUpDown(bool flag, Track *the_track);
00109
00110 bool checkTrack(int a_track_id, bool cd_flag);
00111
00112 void addTrack(int the_track_id, bool update_display, bool cd_flag);
00113
00114 void removeTrack(int the_track_id, bool cd_flag);
00115 void removeAllTracks(void);
00116 void removeAllWidgets(void);
00117
00118 void copyTracks(Playlist *to_ptr, bool update_display);
00119
00120 bool hasChanged(void) { return changed; }
00121 void Changed(void) { changed = true; }
00122
00123 QString getName(void) { return name; }
00124 void setName(QString a_name) { name = a_name; }
00125
00126 int getID(void) { return playlistid; }
00127 int getFirstTrackID(void);
00128 void setID(int x) { playlistid = x; }
00129
00130 bool containsReference(int to_check, int depth);
00131 void ripOutAllCDTracksNow();
00132
00133 void computeSize(double &size_in_MB, double &size_in_sec);
00134 int CreateCDMP3(void);
00135 int CreateCDAudio(void);
00136
00137 private:
00138 QString removeDuplicateTracks(const QString &new_songlist);
00139 int playlistid;
00140 QString name;
00141 QString raw_songlist;
00142 QPtrList<Track> songs;
00143 AllMusic *all_available_music;
00144 PlaylistsContainer *parent;
00145 bool changed;
00146 };
00147
00148 class PlaylistLoadingThread : public QThread
00149 {
00150 public:
00151 PlaylistLoadingThread(PlaylistsContainer *parent_ptr,
00152 AllMusic *all_music_ptr);
00153 virtual void run();
00154
00155 private:
00156 PlaylistsContainer* parent;
00157 AllMusic* all_music;
00158 };
00159
00160 class PlaylistsContainer
00161 {
00162 public:
00163 PlaylistsContainer(AllMusic *all_music, QString host_name);
00164 ~PlaylistsContainer();
00165
00166 void load();
00167 void describeYourself();
00168
00169 Playlist* getActive(void) { return active_playlist; }
00170 Playlist* getPlaylist(int id);
00171
00172 void setActiveWidget(PlaylistTitle *widget);
00173 PlaylistTitle* getActiveWidget(void) { return active_widget; }
00174
00175 GenericTree* writeTree(GenericTree *tree_to_write_to);
00176 void clearCDList();
00177 void addCDTrack(int x);
00178 void removeCDTrack(int x);
00179 bool checkCDTrack(int x);
00180 void save();
00181
00182 void createNewPlaylist(QString name);
00183 void copyNewPlaylist(QString name);
00184 void copyToActive(int index);
00185
00186 void showRelevantPlaylists(TreeCheckItem *alllist);
00187 void refreshRelevantPlaylists(TreeCheckItem *alllist);
00188
00189 QString getPlaylistName(int index, bool &reference);
00190
00191 void postLoad();
00192
00193 void deletePlaylist(int index);
00194 void renamePlaylist(int index, QString new_name);
00195
00196 void popBackPlaylist();
00197 bool pendingWriteback();
00198 void setPending(int x){pending_writeback_index = x;}
00199 int getPending(){return pending_writeback_index;}
00200
00201 bool nameIsUnique(QString a_name, int which_id);
00202
00203 void clearActive();
00204
00205 bool doneLoading(){return done_loading;}
00206
00207 bool cleanOutThreads();
00208
00209 void FillIntelliWeights(int &rating, int &playcount,
00210 int &lastplay, int &random);
00211 private:
00212 Playlist *active_playlist;
00213 Playlist *backup_playlist;
00214 QValueList<int> cd_playlist;
00215 QPtrList<Playlist> *all_other_playlists;
00216 AllMusic *all_available_music;
00217 PlaylistTitle *active_widget;
00218 int pending_writeback_index;
00219
00220 PlaylistLoadingThread *playlists_loader;
00221 bool done_loading;
00222 QString my_host;
00223
00224 int RatingWeight;
00225 int PlayCountWeight;
00226 int LastPlayWeight;
00227 int RandomWeight;
00228 };
00229
00230 #endif