|
Qmmp
|
00001 /*************************************************************************** 00002 * Copyright (C) 2006-2016 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 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 qWarning("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); 00221 bool next(); 00226 bool previous(); 00232 QList<PlayListItem *> mid(int pos, int count = -1) const; 00236 void moveItems(int from, int to); 00240 bool isQueued(PlayListTrack* item) const; 00244 bool isEmptyQueue()const; 00248 int queuedIndex(PlayListTrack* track) const; 00252 int queueSize() const; 00256 bool isStopAfter(PlayListItem* item) const; 00261 const SimpleSelection& getSelection(int row); 00265 QList<int> selectedIndexes() const; 00269 QList<PlayListTrack *> selectedTracks() const; 00273 QList<PlayListItem*> items() const; 00277 int firstSelectedUpper(int row); 00281 int firstSelectedLower(int row); 00285 int totalLength() const; 00289 void loadPlaylist(const QString& f_name); 00293 void savePlaylist(const QString& f_name); 00297 bool isLoaderRunning() const; 00301 bool contains(const QString &url); 00305 enum SortMode 00306 { 00307 TITLE = 0, 00308 ALBUM, 00309 DISCNUMBER, 00310 ARTIST, 00311 ALBUMARTIST, 00312 FILENAME, 00313 PATH_AND_FILENAME, 00314 DATE, 00315 TRACK, 00316 FILE_CREATION_DATE, 00317 FILE_MODIFICATION_DATE, 00318 GROUP 00319 }; 00324 int indexOfTrack(int index) const; 00329 PlayListTrack *findTrack(int track_index) const; 00333 enum UpdateFlags 00334 { 00335 STRUCTURE = 0x01, 00336 SELECTION = 0x02, 00337 QUEUE = 0x04, 00338 CURRENT = 0x08, 00339 STOP_AFTER = 0x10, 00340 METADATA = 0x20 00341 }; 00342 00343 signals: 00348 void listChanged(int flags); 00353 void trackAdded(PlayListTrack *track); 00358 void nameChanged(const QString& name); 00362 void loaderFinished(); 00366 void currentVisibleRequest(); 00372 void sortingByColumnFinished(int column, bool reverted); 00373 00374 public slots: 00378 void add(PlayListTrack *track); 00383 void add(QList <PlayListTrack *> tracks); 00388 void add(const QString &path); 00393 void add(const QStringList &paths); 00397 void insert(int index, PlayListTrack *track); 00401 void insert(PlayListItem *before, PlayListTrack *track); 00405 void insert(int index, QList <PlayListTrack *> tracks); 00409 void insert(PlayListItem *before, QList <PlayListTrack *> tracks); 00415 void insert(int index, const QString &path); 00421 void insert(int index, const QStringList &paths); 00427 void insert(int index, const QList<QUrl> &urls); 00431 void clear(); 00435 void clearSelection(); 00439 void removeSelected(); 00443 void removeUnselected(); 00447 void removeTrack (int i); 00451 void removeTrack (PlayListItem *track); 00455 void invertSelection(); 00459 void selectAll(); 00464 void showDetails(QWidget *parent = 0); 00469 void showDetailsForCurrent(QWidget *parent = 0); 00473 void doCurrentVisibleRequest(); 00477 void randomizeList(); 00481 void reverseList(); 00485 void sortSelection(int mode); 00489 void sort(int mode); 00493 void sortByColumn(int column); 00497 void addToQueue(); 00501 void setQueued(PlayListTrack* item); 00505 void removeInvalidTracks(); 00509 void removeDuplicates(); 00513 void refresh(); 00517 void clearQueue(); 00521 void stopAfterSelected(); 00525 void rebuildGroups(); 00529 void updateMetaData(); 00530 00531 private: 00535 int topmostInSelection(int); 00539 int bottommostInSelection(int); 00544 void removeSelection(bool inverted = false); 00545 00546 int removeTrackInternal(int i); 00547 00548 private slots: 00552 void preparePlayState(); 00556 void prepareForShufflePlaying(bool yes); 00561 void prepareGroups(bool enabled); 00562 00563 void onTaskFinished(); 00564 00565 private: 00566 PlayListTrack* m_current_track; 00567 PlayListTrack* m_stop_track; 00568 int m_current; 00569 SimpleSelection m_selection; 00570 QQueue <PlayListTrack*> m_queued_songs; 00571 PlayState* m_play_state; 00572 int m_total_length; 00573 FileLoader *m_loader; 00574 QString m_name; 00575 PlayListContainer *m_container; 00576 QmmpUiSettings *m_ui_settings; 00577 PlayListTask *m_task; 00578 }; 00579 00580 #endif
1.7.6.1