Qmmp
playlistmodel.h
1 /***************************************************************************
2  * Copyright (C) 2006-2019 by Ilya Kotov *
3  * forkotov02@ya.ru *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef PLAYLISTMODEL_H
21 #define PLAYLISTMODEL_H
22 
23 #include <QObject>
24 #include <QString>
25 #include <QStringList>
26 #include <QMap>
27 #include <QQueue>
28 #include <QPointer>
29 #include <QVector>
30 #include <QUrl>
31 #include "playlistitem.h"
32 #include "playlisttrack.h"
33 #include "playlistgroup.h"
34 #include "qmmpui_export.h"
35 
36 class FileLoader;
37 class PlayState;
38 class PlayListFormat;
39 class PlayListModel;
40 class PlayListContainer;
41 class QmmpUiSettings;
42 class PlayListTask;
43 
49 {
54  {
55  m_bottom = -1;
56  m_top = 1;
57  }
61  inline bool isValid()const
62  {
63  return (m_bottom != -1) && (m_top != -1);
64  }
68  inline void dump()const
69  {
70  qDebug("top: %d\tbotom: %d", m_top, m_bottom);
71  }
75  inline int count()const
76  {
77  return m_bottom - m_top + 1;
78  }
79  int m_bottom;
80  int m_top;
81  QList<int> m_selected_indexes;
82 };
103 class QMMPUI_EXPORT PlayListModel : public QObject
104 {
105  Q_OBJECT
106 public:
112  PlayListModel(const QString &name, QObject *parent = 0);
120  QString name() const;
124  void setName(const QString &name);
128  int count() const;
132  int trackCount() const;
136  bool isEmpty() const;
140  int columnCount() const;
152  int indexOf(PlayListItem* item) const;
156  PlayListItem* item(int index) const;
160  PlayListTrack* track(int index) const;
164  PlayListGroup* group(int index) const;
168  int currentIndex() const;
174  bool setCurrent (int index);
184  bool isTrack(int index) const;
189  bool isGroup(int index) const;
193  bool isSelected(int index) const;
199  void setSelected(int index, bool selected = true);
205  void setSelected(QList<PlayListTrack *> tracks, bool selected = true);
211  void setSelected(QList<PlayListItem *> items, bool selected = true);
218  void setSelected(int first, int last, bool selected = true);
224  void setSelected(QList<int> indexes, bool selected = true);
229  bool next();
234  bool previous();
240  QList<PlayListItem *> mid(int pos, int count = -1) const;
244  void moveItems(int from, int to);
248  bool isQueued(PlayListTrack* item) const;
252  bool isEmptyQueue()const;
256  int queuedIndex(PlayListTrack* track) const;
260  int queueSize() const;
264  bool isStopAfter(PlayListItem* item) const;
269  const SimpleSelection& getSelection(int row);
273  QList<int> selectedIndexes() const;
277  QList<PlayListTrack *> selectedTracks() const;
281  QList<PlayListItem*> items() const;
285  int firstSelectedUpper(int row);
289  int firstSelectedLower(int row);
293  qint64 totalDuration() const;
297  void loadPlaylist(const QString& f_name);
303  void loadPlaylist(const QString &fmt, const QByteArray &data);
307  void savePlaylist(const QString& f_name);
311  bool isLoaderRunning() const;
315  bool contains(const QString &url);
319  enum SortMode
320  {
321  TITLE = 0,
332  GROUP
333  };
338  int indexOfTrack(int index) const;
343  PlayListTrack *findTrack(int track_index) const;
348  QList<PlayListItem *> findTracks(const QString &str) const;
353  {
354  STRUCTURE = 0x01,
355  SELECTION = 0x02,
356  QUEUE = 0x04,
357  CURRENT = 0x08,
358  STOP_AFTER = 0x10,
359  METADATA = 0x20
360  };
361 
362 signals:
367  void listChanged(int flags);
372  void trackAdded(PlayListTrack *track);
377  void nameChanged(const QString& name);
385  void scrollToRequest(int index);
391  void sortingByColumnFinished(int column, bool reverted);
392 
393 public slots:
397  void add(PlayListTrack *track);
402  void add(QList <PlayListTrack *> tracks);
407  void add(const QString &path);
412  void add(const QStringList &paths);
416  void insert(int index, PlayListTrack *track);
420  void insert(PlayListItem *before, PlayListTrack *track);
424  void insert(int index, QList <PlayListTrack *> tracks);
428  void insert(PlayListItem *before, QList <PlayListTrack *> tracks);
434  void insert(int index, const QString &path);
440  void insert(int index, const QStringList &paths);
446  void insert(int index, const QList<QUrl> &urls);
450  void clear();
466  void removeTrack(int i);
470  void removeTrack(PlayListItem *track);
474  void removeTracks(const QList<PlayListItem *> &items);
478  void removeTracks(const QList<PlayListTrack *> &tracks);
486  void selectAll();
491  void showDetails(QWidget *parent = 0);
496  void showDetailsForCurrent(QWidget *parent = 0);
504  void scrollTo(int index);
512  void reverseList();
516  void sortSelection(int mode);
520  void sort(int mode);
524  void sortByColumn(int column);
528  void addToQueue();
544  void refresh();
548  void clearQueue();
561 
562 private:
566  int topmostInSelection(int);
570  int bottommostInSelection(int);
575  void removeSelection(bool inverted = false);
576 
577  int removeTrackInternal(int i);
578 
579 private slots:
583  void preparePlayState();
587  void prepareForShufflePlaying(bool yes);
592  void prepareGroups(bool enabled);
593 
594  void onTaskFinished();
595 
596 private:
597  PlayListTrack* m_current_track;
598  PlayListTrack* m_stop_track;
599  int m_current;
600  SimpleSelection m_selection;
601  QQueue <PlayListTrack*> m_queued_songs;
602  PlayState* m_play_state;
603  qint64 m_total_duration;
604  FileLoader *m_loader;
605  QString m_name;
606  PlayListContainer *m_container;
607  QmmpUiSettings *m_ui_settings;
608  PlayListTask *m_task;
609 };
610 
611 #endif
Abstract interface for playlist formats.
Definition: playlistformat.h:43
The PlayListTrack class provides a group for use with the PlayListModel class.
Definition: playlistgroup.h:34
The PlayListItem class provides an item for use with the PlayListModel class.
Definition: playlistitem.h:32
The PlayListModel class provides a data model for the playlist.
Definition: playlistmodel.h:104
int trackCount() const
SortMode
Definition: playlistmodel.h:320
@ ALBUMARTIST
Definition: playlistmodel.h:325
@ DATE
Definition: playlistmodel.h:328
@ TRACK
Definition: playlistmodel.h:329
@ DISCNUMBER
Definition: playlistmodel.h:323
@ FILE_CREATION_DATE
Definition: playlistmodel.h:330
@ ARTIST
Definition: playlistmodel.h:324
@ PATH_AND_FILENAME
Definition: playlistmodel.h:327
@ ALBUM
Definition: playlistmodel.h:322
@ FILENAME
Definition: playlistmodel.h:326
@ FILE_MODIFICATION_DATE
Definition: playlistmodel.h:331
int indexOf(PlayListItem *item) const
void sortByColumn(int column)
void setSelected(QList< PlayListItem * > items, bool selected=true)
bool isQueued(PlayListTrack *item) const
PlayListTrack * findTrack(int track_index) const
int indexOfTrack(int index) const
int count() const
void removeUnselected()
bool isGroup(int index) const
void add(PlayListTrack *track)
QList< PlayListItem * > findTracks(const QString &str) const
void removeTrack(PlayListItem *track)
void sortSelection(int mode)
void removeDuplicates()
void add(const QString &path)
void insert(PlayListItem *before, PlayListTrack *track)
int firstSelectedUpper(int row)
void nameChanged(const QString &name)
void setSelected(QList< int > indexes, bool selected=true)
void scrollTo(int index)
void insert(int index, const QStringList &paths)
void insert(int index, QList< PlayListTrack * > tracks)
qint64 totalDuration() const
void insert(int index, PlayListTrack *track)
void savePlaylist(const QString &f_name)
void showDetails(QWidget *parent=0)
int currentIndex() const
void setSelected(int index, bool selected=true)
void insert(PlayListItem *before, QList< PlayListTrack * > tracks)
void loadPlaylist(const QString &fmt, const QByteArray &data)
void moveItems(int from, int to)
void showDetailsForCurrent(QWidget *parent=0)
bool isSelected(int index) const
void removeInvalidTracks()
void insert(int index, const QString &path)
int queuedIndex(PlayListTrack *track) const
void updateMetaData()
void clearQueue()
void randomizeList()
PlayListTrack * track(int index) const
void removeTracks(const QList< PlayListItem * > &items)
QString name() const
void setSelected(QList< PlayListTrack * > tracks, bool selected=true)
QList< PlayListTrack * > selectedTracks() const
void removeTrack(int i)
void add(const QStringList &paths)
PlayListModel(const QString &name, QObject *parent=0)
bool setCurrent(PlayListTrack *item)
PlayListTrack * nextTrack() const
void removeTracks(const QList< PlayListTrack * > &tracks)
bool isStopAfter(PlayListItem *item) const
PlayListItem * item(int index) const
QList< PlayListItem * > mid(int pos, int count=-1) const
QList< int > selectedIndexes() const
void setQueued(PlayListTrack *item)
void loaderFinished()
UpdateFlags
Definition: playlistmodel.h:353
bool setCurrent(int index)
void add(QList< PlayListTrack * > tracks)
int queueSize() const
void setName(const QString &name)
void scrollToRequest(int index)
bool isTrack(int index) const
void listChanged(int flags)
void sortingByColumnFinished(int column, bool reverted)
void selectAll()
bool isLoaderRunning() const
void trackAdded(PlayListTrack *track)
PlayListGroup * group(int index) const
void loadPlaylist(const QString &f_name)
void clearSelection()
const SimpleSelection & getSelection(int row)
void sort(int mode)
QList< PlayListItem * > items() const
bool isEmptyQueue() const
void rebuildGroups()
int columnCount() const
void setSelected(int first, int last, bool selected=true)
void stopAfterSelected()
bool contains(const QString &url)
void invertSelection()
bool isEmpty() const
void insert(int index, const QList< QUrl > &urls)
void doCurrentVisibleRequest()
int firstSelectedLower(int row)
void reverseList()
void addToQueue()
void removeSelected()
PlayListTrack * currentTrack() const
The PlayListTrack class provides a track for use with the PlayListModel class.
Definition: playlisttrack.h:37
The QmmpUiSettings class provides access to global libqmmpui library settings.
Definition: qmmpuisettings.h:37
Helper class that keeps track of a view's selected items.
Definition: playlistmodel.h:49
int count() const
Definition: playlistmodel.h:75
SimpleSelection()
Definition: playlistmodel.h:53
bool isValid() const
Definition: playlistmodel.h:61
QList< int > m_selected_indexes
Definition: playlistmodel.h:81
int m_bottom
Definition: playlistmodel.h:79
int m_top
Definition: playlistmodel.h:80
void dump() const
Definition: playlistmodel.h:68