00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PLAYLISTMODEL_H
00021 #define PLAYLISTMODEL_H
00022
00023 #include <QObject>
00024 #include <QString>
00025 #include <QStringList>
00026 #include <QMap>
00027 #include <QPointer>
00028 #include <QVector>
00029 #include "playlistitem.h"
00030
00031 class FileLoader;
00032 class PlayListItem;
00033 class PlayState;
00034 class PlaylistFormat;
00035 class PlayListModel;
00036
00041 struct SimpleSelection
00042 {
00046 SimpleSelection()
00047 {
00048 ;
00049 }
00053 inline bool isValid()const
00054 {
00055 return (m_bottom != -1) && (m_anchor != -1) && (m_top != -1);
00056 }
00060 inline void dump()const
00061 {
00062 qWarning("top: %d\tbotom: %d\tanchor: %d",m_top,m_bottom,m_anchor);
00063 }
00067 inline int count()const
00068 {
00069 return m_bottom - m_top + 1;
00070 }
00071 int m_bottom;
00072 int m_top;
00073 int m_anchor;
00074 QList<int>m_selected_rows;
00075 };
00081 class TagUpdater : public QObject
00082 {
00083 Q_OBJECT
00084 QObject* m_observable;
00085 PlayListItem* m_item;
00086
00087 public:
00088 TagUpdater(QObject* o, PlayListItem* item);
00089
00090 protected slots:
00091 void updateTag();
00092 };
00098 class PlayListModel : public QObject
00099 {
00100 Q_OBJECT
00101 public:
00107 PlayListModel(const QString &name, QObject *parent = 0);
00111 ~PlayListModel();
00115 QString name() const;
00119 void setName(const QString &name);
00123 int count();
00127 PlayListItem* currentItem();
00131 PlayListItem* nextItem();
00135 int row(PlayListItem* item) const
00136 {
00137 return m_items.indexOf(item);
00138 }
00142 PlayListItem* item(int row) const;
00146 int currentRow();
00152 bool setCurrent (int row);
00156 bool isSelected(int row);
00162 void setSelected(int row, bool select);
00167 bool next();
00172 bool previous();
00178 QList <QString> getTitles(int first,int last);
00184 QList <QString> getTimes(int first,int last);
00188 void moveItems(int from, int to);
00192 bool isQueued(PlayListItem* item) const;
00196 void setCurrentToQueued();
00200 bool isEmptyQueue()const;
00204 int queuedIndex(PlayListItem* item) const
00205 {
00206 return m_queued_songs.indexOf(item);
00207 }
00212 const SimpleSelection& getSelection(int row);
00216 QList<int> getSelectedRows() const;
00220 QList<PlayListItem*> getSelectedItems() const;
00224 QList<PlayListItem*> items() const
00225 {
00226 return m_items;
00227 }
00231 int firstSelectedUpper(int row);
00235 int firstSelectedLower(int row);
00239 int totalLength()const
00240 {
00241 return m_total_length;
00242 }
00246 void loadPlaylist(const QString& f_name);
00250 void savePlaylist(const QString& f_name);
00254 bool isRepeatableList() const;
00258 bool isShuffle() const;
00262 bool contains(const QString &url);
00266 enum SortMode
00267 {
00268 TITLE,
00269 ALBUM,
00270 ARTIST,
00271 FILENAME,
00272 PATH_AND_FILENAME,
00273 DATE,
00274 TRACK
00275 };
00276
00277 signals:
00281 void listChanged();
00285 void currentChanged();
00289 void firstAdded();
00294 void nameChanged(const QString& name);
00295
00296 public slots:
00300 void add(PlayListItem *item);
00305 void add(QList <PlayListItem *> items);
00309 void clear();
00313 void clearSelection();
00317 void removeSelected();
00321 void removeUnselected();
00325 void removeAt (int i);
00329 void removeItem (PlayListItem *item);
00333 void invertSelection();
00337 void selectAll();
00341 void showDetails();
00345 void doCurrentVisibleRequest();
00349 void addFile(const QString &path);
00353 void addFiles(const QStringList& l);
00357 void addDirectory(const QString& dir);
00363 bool setFileList(const QStringList &l);
00367 void addFileList(const QStringList &l);
00371 void randomizeList();
00375 void reverseList();
00379 void prepareForShufflePlaying(bool yes);
00383 void prepareForRepeatablePlaying(bool);
00387 void sortSelection(int mode);
00391 void sort(int mode);
00395 void addToQueue();
00399 void setQueued(PlayListItem* f);
00403 void removeInvalidItems();
00407 void removeDuplicates();
00408
00409 private:
00413 void doSort(int mode,QList<PlayListItem*>& list_to_sort);
00417 int topmostInSelection(int);
00421 int bottommostInSelection(int);
00425 FileLoader* createFileLoader();
00429 bool isFileLoaderRunning()const;
00434 void removeSelection(bool inverted = false);
00435
00436 private slots:
00437 void preparePlayState();
00438
00439 private:
00440 QList <PlayListItem*> m_items;
00441 QList <PlayListItem*> m_editing_items;
00442 PlayListItem* m_currentItem;
00443 int m_current;
00447 SimpleSelection m_selection;
00451 QList<PlayListItem*> m_queued_songs;
00455 bool is_repeatable_list;
00459 PlayState* m_play_state;
00460 int m_total_length;
00461 typedef QPointer<FileLoader> GuardedFileLoader;
00467 QVector<GuardedFileLoader> m_running_loaders;
00468 bool m_shuffle;
00469 QString m_name;
00470 };
00471
00472
00473 #endif