Qmmp
|
00001 /*************************************************************************** 00002 * Copyright (C) 2006-2013 by Ilya Kotov * 00003 * forkotov02@hotmail.ru * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the * 00017 * Free Software Foundation, Inc., * 00018 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 #include "playlisttrack.h" 00032 #include "playlistgroup.h" 00033 00034 class FileLoader; 00035 class PlayState; 00036 class PlayListFormat; 00037 class PlayListModel; 00038 class PlayListContainer; 00039 class QmmpUiSettings; 00040 00045 struct SimpleSelection 00046 { 00050 SimpleSelection() 00051 { 00052 ; 00053 } 00057 inline bool isValid()const 00058 { 00059 return (m_bottom != -1) && (m_top != -1); 00060 } 00064 inline void dump()const 00065 { 00066 qWarning("top: %d\tbotom: %d", m_top, m_bottom); 00067 } 00071 inline int count()const 00072 { 00073 return m_bottom - m_top + 1; 00074 } 00075 int m_bottom; 00076 int m_top; 00077 QList<int> m_selected_indexes; 00078 }; 00084 class PlayListModel : public QObject 00085 { 00086 Q_OBJECT 00087 public: 00093 PlayListModel(const QString &name, QObject *parent = 0); 00097 ~PlayListModel(); 00101 QString name() const; 00105 void setName(const QString &name); 00109 int count() const; 00113 int trackCount() const; 00117 PlayListTrack* currentTrack() const; 00121 PlayListTrack* nextTrack() const; 00125 int indexOf(PlayListItem* item) const; 00129 PlayListItem* item(int index) const; 00130 PlayListTrack* track(int index) const; 00131 PlayListGroup* group(int index) const; 00135 int currentIndex() const; 00141 bool setCurrent (int index); 00146 bool setCurrent(PlayListTrack *item); 00147 00148 00149 bool isTrack(int index) const; 00150 00151 bool isGroup(int index) const; 00152 00156 bool isSelected(int index) const; 00162 void setSelected(int index, bool selected = true); 00163 00164 00165 void setSelected(QList<PlayListTrack *> tracks, bool selected = true); 00166 00167 void setSelected(QList<PlayListItem *> items, bool selected = true); 00172 bool next(); 00177 bool previous(); 00183 QList<PlayListItem *> mid(int pos, int count = -1) const; 00187 void moveItems(int from, int to); 00191 bool isQueued(PlayListTrack* item) const; 00195 void setCurrentToQueued(); 00199 bool isEmptyQueue()const; 00203 int queuedIndex(PlayListTrack* track) const; 00207 int queueSize() const; 00211 bool isStopAfter(PlayListItem* item) const; 00216 const SimpleSelection& getSelection(int row); 00220 QList<int> selectedIndexes() const; 00224 QList<PlayListTrack *> selectedTracks() const; 00228 QList<PlayListItem*> items() const; 00232 int firstSelectedUpper(int row); 00236 int firstSelectedLower(int row); 00240 int totalLength() const; 00244 void loadPlaylist(const QString& f_name); 00248 void savePlaylist(const QString& f_name); 00252 bool isLoaderRunning() const; 00256 bool contains(const QString &url); 00260 enum SortMode 00261 { 00262 TITLE = 0, 00263 ALBUM, 00264 DISCNUMBER, 00265 ARTIST, 00266 FILENAME, 00267 PATH_AND_FILENAME, 00268 DATE, 00269 TRACK, 00270 FILE_CREATION_DATE, 00271 FILE_MODIFICATION_DATE, 00272 GROUP 00273 }; 00274 00275 int numberOfTrack(int index) const; 00276 00277 signals: 00281 void listChanged(); 00285 void currentChanged(); 00290 void trackAdded(PlayListTrack *track); 00295 void nameChanged(const QString& name); 00299 void loaderFinished(); 00303 void countChanged(); 00304 00305 public slots: 00309 void add(PlayListTrack *track); 00314 void add(QList <PlayListTrack *> tracks); 00319 void add(const QString &path); 00324 void add(const QStringList &paths); 00328 void insert(int index, PlayListTrack *track); 00329 00330 void insert(PlayListItem *before, PlayListTrack *track); 00334 void insert(int index, QList <PlayListTrack *> tracks); 00340 void insert(int index, const QString &path); 00346 void insert(int index, const QStringList &paths); 00352 void insert(int index, const QList<QUrl> &urls); 00356 void clear(); 00360 void clearSelection(); 00364 void removeSelected(); 00368 void removeUnselected(); 00372 void removeTrack (int i); 00376 void removeTrack (PlayListItem *track); 00380 void invertSelection(); 00384 void selectAll(); 00389 void showDetails(QWidget *parent = 0); 00393 void doCurrentVisibleRequest(); 00397 void randomizeList(); 00401 void reverseList(); 00405 void sortSelection(int mode); 00409 void sort(int mode); 00413 void addToQueue(); 00417 void setQueued(PlayListTrack* item); 00421 void removeInvalidTracks(); 00425 void removeDuplicates(); 00429 void clearQueue(); 00433 void stopAfterSelected(); 00437 void updateGroups(); 00438 00439 private: 00443 int topmostInSelection(int); 00447 int bottommostInSelection(int); 00452 void removeSelection(bool inverted = false); 00453 00454 private slots: 00458 void preparePlayState(); 00462 void prepareForShufflePlaying(bool yes); 00467 void prepareGroups(bool enabled); 00468 00469 private: 00470 PlayListTrack* m_current_track; 00471 PlayListTrack* m_stop_track; 00472 int m_current; 00473 SimpleSelection m_selection; 00474 QQueue <PlayListTrack*> m_queued_songs; 00475 PlayState* m_play_state; 00476 int m_total_length; 00477 FileLoader *m_loader; 00478 QString m_name; 00479 PlayListContainer *m_container; 00480 QmmpUiSettings *m_ui_settings; 00481 }; 00482 00483 #endif