|
Qmmp
|
00001 /*************************************************************************** 00002 * Copyright (C) 2006-2017 by Ilya Kotov * 00003 * forkotov02@ya.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 class PlayListTask; 00041 00046 struct SimpleSelection 00047 { 00051 SimpleSelection() 00052 { 00053 m_bottom = -1; 00054 m_top = 1; 00055 } 00059 inline bool isValid()const 00060 { 00061 return (m_bottom != -1) && (m_top != -1); 00062 } 00066 inline void dump()const 00067 { 00068 qDebug("top: %d\tbotom: %d", m_top, m_bottom); 00069 } 00073 inline int count()const 00074 { 00075 return m_bottom - m_top + 1; 00076 } 00077 int m_bottom; 00078 int m_top; 00079 QList<int> m_selected_indexes; 00080 }; 00101 class PlayListModel : public QObject 00102 { 00103 Q_OBJECT 00104 public: 00110 PlayListModel(const QString &name, QObject *parent = 0); 00114 ~PlayListModel(); 00118 QString name() const; 00122 void setName(const QString &name); 00126 int count() const; 00130 int trackCount() const; 00134 bool isEmpty() const; 00138 int columnCount() const; 00142 PlayListTrack* currentTrack() const; 00146 PlayListTrack* nextTrack() const; 00150 int indexOf(PlayListItem* item) const; 00154 PlayListItem* item(int index) const; 00158 PlayListTrack* track(int index) const; 00162 PlayListGroup* group(int index) const; 00166 int currentIndex() const; 00172 bool setCurrent (int index); 00177 bool setCurrent(PlayListTrack *item); 00182 bool isTrack(int index) const; 00187 bool isGroup(int index) const; 00191 bool isSelected(int index) const; 00197 void setSelected(int index, bool selected = true); 00203 void setSelected(QList<PlayListTrack *> tracks, bool selected = true); 00209 void setSelected(QList<PlayListItem *> items, bool selected = true); 00216 void setSelected(int first, int last, bool selected = true); 00222 void setSelected(QList<int> indexes, bool selected = true); 00227 bool next(); 00232 bool previous(); 00238 QList<PlayListItem *> mid(int pos, int count = -1) const; 00242 void moveItems(int from, int to); 00246 bool isQueued(PlayListTrack* item) const; 00250 bool isEmptyQueue()const; 00254 int queuedIndex(PlayListTrack* track) const; 00258 int queueSize() const; 00262 bool isStopAfter(PlayListItem* item) const; 00267 const SimpleSelection& getSelection(int row); 00271 QList<int> selectedIndexes() const; 00275 QList<PlayListTrack *> selectedTracks() const; 00279 QList<PlayListItem*> items() const; 00283 int firstSelectedUpper(int row); 00287 int firstSelectedLower(int row); 00291 int totalLength() const; 00295 void loadPlaylist(const QString& f_name); 00301 void loadPlaylist(const QString &fmt, const QByteArray &data); 00305 void savePlaylist(const QString& f_name); 00309 bool isLoaderRunning() const; 00313 bool contains(const QString &url); 00317 enum SortMode 00318 { 00319 TITLE = 0, 00320 ALBUM, 00321 DISCNUMBER, 00322 ARTIST, 00323 ALBUMARTIST, 00324 FILENAME, 00325 PATH_AND_FILENAME, 00326 DATE, 00327 TRACK, 00328 FILE_CREATION_DATE, 00329 FILE_MODIFICATION_DATE, 00330 GROUP 00331 }; 00336 int indexOfTrack(int index) const; 00341 PlayListTrack *findTrack(int track_index) const; 00346 QList<PlayListItem *> findTracks(const QString &str) const; 00350 enum UpdateFlags 00351 { 00352 STRUCTURE = 0x01, 00353 SELECTION = 0x02, 00354 QUEUE = 0x04, 00355 CURRENT = 0x08, 00356 STOP_AFTER = 0x10, 00357 METADATA = 0x20 00358 }; 00359 00360 signals: 00365 void listChanged(int flags); 00370 void trackAdded(PlayListTrack *track); 00375 void nameChanged(const QString& name); 00379 void loaderFinished(); 00383 void scrollToRequest(int index); 00389 void sortingByColumnFinished(int column, bool reverted); 00390 00391 public slots: 00395 void add(PlayListTrack *track); 00400 void add(QList <PlayListTrack *> tracks); 00405 void add(const QString &path); 00410 void add(const QStringList &paths); 00414 void insert(int index, PlayListTrack *track); 00418 void insert(PlayListItem *before, PlayListTrack *track); 00422 void insert(int index, QList <PlayListTrack *> tracks); 00426 void insert(PlayListItem *before, QList <PlayListTrack *> tracks); 00432 void insert(int index, const QString &path); 00438 void insert(int index, const QStringList &paths); 00444 void insert(int index, const QList<QUrl> &urls); 00448 void clear(); 00452 void clearSelection(); 00456 void removeSelected(); 00460 void removeUnselected(); 00464 void removeTrack (int i); 00468 void removeTrack (PlayListItem *track); 00472 void invertSelection(); 00476 void selectAll(); 00481 void showDetails(QWidget *parent = 0); 00486 void showDetailsForCurrent(QWidget *parent = 0); 00490 void doCurrentVisibleRequest(); 00494 void scrollTo(int index); 00498 void randomizeList(); 00502 void reverseList(); 00506 void sortSelection(int mode); 00510 void sort(int mode); 00514 void sortByColumn(int column); 00518 void addToQueue(); 00522 void setQueued(PlayListTrack* item); 00526 void removeInvalidTracks(); 00530 void removeDuplicates(); 00534 void refresh(); 00538 void clearQueue(); 00542 void stopAfterSelected(); 00546 void rebuildGroups(); 00550 void updateMetaData(); 00551 00552 private: 00556 int topmostInSelection(int); 00560 int bottommostInSelection(int); 00565 void removeSelection(bool inverted = false); 00566 00567 int removeTrackInternal(int i); 00568 00569 private slots: 00573 void preparePlayState(); 00577 void prepareForShufflePlaying(bool yes); 00582 void prepareGroups(bool enabled); 00583 00584 void onTaskFinished(); 00585 00586 private: 00587 PlayListTrack* m_current_track; 00588 PlayListTrack* m_stop_track; 00589 int m_current; 00590 SimpleSelection m_selection; 00591 QQueue <PlayListTrack*> m_queued_songs; 00592 PlayState* m_play_state; 00593 int m_total_length; 00594 FileLoader *m_loader; 00595 QString m_name; 00596 PlayListContainer *m_container; 00597 QmmpUiSettings *m_ui_settings; 00598 PlayListTask *m_task; 00599 }; 00600 00601 #endif
1.7.6.1