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 <QQueue>
00028 #include <QPointer>
00029 #include <QVector>
00030 #include "playlistitem.h"
00031
00032 class FileLoader;
00033 class PlayListItem;
00034 class PlayState;
00035 class PlaylistFormat;
00036 class PlayListModel;
00037
00042 struct SimpleSelection
00043 {
00047 SimpleSelection()
00048 {
00049 ;
00050 }
00054 inline bool isValid()const
00055 {
00056 return (m_bottom != -1) && (m_anchor != -1) && (m_top != -1);
00057 }
00061 inline void dump()const
00062 {
00063 qWarning("top: %d\tbotom: %d\tanchor: %d",m_top,m_bottom,m_anchor);
00064 }
00068 inline int count()const
00069 {
00070 return m_bottom - m_top + 1;
00071 }
00072 int m_bottom;
00073 int m_top;
00074 int m_anchor;
00075 QList<int>m_selected_rows;
00076 };
00082 class TagUpdater : public QObject
00083 {
00084 Q_OBJECT
00085 QObject* m_observable;
00086 PlayListItem* m_item;
00087
00088 public:
00089 TagUpdater(QObject* o, PlayListItem* item);
00090
00091 protected slots:
00092 void updateTag();
00093 };
00099 class PlayListModel : public QObject
00100 {
00101 Q_OBJECT
00102 public:
00108 PlayListModel(const QString &name, QObject *parent = 0);
00112 ~PlayListModel();
00116 QString name() const;
00120 void setName(const QString &name);
00124 int count();
00128 PlayListItem* currentItem();
00132 PlayListItem* nextItem();
00136 int row(PlayListItem* item) const
00137 {
00138 return m_items.indexOf(item);
00139 }
00143 PlayListItem* item(int row) const;
00147 int currentRow();
00153 bool setCurrent (int row);
00158 bool setCurrent(PlayListItem *item);
00162 bool isSelected(int row);
00168 void setSelected(int row, bool selected = true);
00173 bool next();
00178 bool previous();
00184 QStringList getTitles(int first,int last);
00190 QStringList getTimes(int first,int last);
00194 void moveItems(int from, int to);
00198 bool isQueued(PlayListItem* item) const;
00202 void setCurrentToQueued();
00206 bool isEmptyQueue()const;
00210 int queuedIndex(PlayListItem* item) const;
00214 int queueSize() const;
00218 bool isStopAfter(PlayListItem* item) const;
00223 const SimpleSelection& getSelection(int row);
00227 QList<int> selectedRows() const;
00231 QList<PlayListItem*> selectedItems() const;
00235 QList<PlayListItem*> items() const
00236 {
00237 return m_items;
00238 }
00242 int firstSelectedUpper(int row);
00246 int firstSelectedLower(int row);
00250 int totalLength()const
00251 {
00252 return m_total_length;
00253 }
00257 void loadPlaylist(const QString& f_name);
00261 void savePlaylist(const QString& f_name);
00265 bool isRepeatableList() const;
00269 bool isShuffle() const;
00273 bool isLoaderRunning() const;
00277 bool contains(const QString &url);
00281 enum SortMode
00282 {
00283 TITLE,
00284 ALBUM,
00285 ARTIST,
00286 FILENAME,
00287 PATH_AND_FILENAME,
00288 DATE,
00289 TRACK
00290 };
00291
00292 signals:
00296 void listChanged();
00300 void currentChanged();
00305 void itemAdded(PlayListItem *item);
00310 void nameChanged(const QString& name);
00314 void loaderFinished();
00315
00316 public slots:
00320 void add(PlayListItem *item);
00325 void add(QList <PlayListItem *> items);
00330 void add(const QString &path);
00335 void add(const QStringList &paths);
00339 void clear();
00343 void clearSelection();
00347 void removeSelected();
00351 void removeUnselected();
00355 void removeAt (int i);
00359 void removeItem (PlayListItem *item);
00363 void invertSelection();
00367 void selectAll();
00372 void showDetails(QWidget *parent = 0);
00376 void doCurrentVisibleRequest();
00380 void randomizeList();
00384 void reverseList();
00388 void prepareForShufflePlaying(bool yes);
00392 void prepareForRepeatablePlaying(bool);
00396 void sortSelection(int mode);
00400 void sort(int mode);
00404 void addToQueue();
00408 void setQueued(PlayListItem* f);
00412 void removeInvalidItems();
00416 void removeDuplicates();
00420 void clearQueue();
00424 void stopAfterSelected();
00425
00426 private:
00430 void doSort(int mode,QList<PlayListItem*>& list_to_sort);
00434 int topmostInSelection(int);
00438 int bottommostInSelection(int);
00443 void removeSelection(bool inverted = false);
00444
00445 private slots:
00446 void preparePlayState();
00447
00448 private:
00449 QList <PlayListItem*> m_items;
00450 QList <PlayListItem*> m_editing_items;
00451 PlayListItem* m_currentItem;
00452 PlayListItem* m_stop_item;
00453 int m_current;
00457 SimpleSelection m_selection;
00461 QQueue <PlayListItem*> m_queued_songs;
00465 bool is_repeatable_list;
00469 PlayState* m_play_state;
00470 int m_total_length;
00471 FileLoader *m_loader;
00472 bool m_shuffle;
00473 QString m_name;
00474 };
00475
00476
00477 #endif