Qmmp
playlistmodel.h
1 /***************************************************************************
2  * Copyright (C) 2006-2020 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 = nullptr);
116  ~PlayListModel();
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;
144  PlayListTrack* currentTrack() const;
148  PlayListTrack* nextTrack() 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);
179  bool setCurrent(PlayListTrack *item);
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(const QList<PlayListTrack *> &tracks, bool selected = true);
211  void setSelected(const QList<PlayListItem *> &items, bool selected = true);
218  void setSelected(int first, int last, bool selected = true);
224  void setSelected(const 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(const 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);
381  void loaderFinished();
385  void scrollToRequest(int index);
391  void sortingByColumnFinished(int column, bool reverted);
392 
393 public slots:
397  void add(PlayListTrack *track);
402  void add(const 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, const QList<PlayListTrack *> &tracks);
428  void insert(PlayListItem *before, const 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();
454  void clearSelection();
458  void removeSelected();
462  void removeUnselected();
466  void removeTrack(int i);
470  void removeTrack(PlayListItem *track);
474  void removeTracks(const QList<PlayListItem *> &items);
478  void removeTracks(const QList<PlayListTrack *> &tracks);
482  void invertSelection();
486  void selectAll();
491  void showDetails(QWidget *parent = nullptr);
496  void showDetailsForCurrent(QWidget *parent = nullptr);
500  void doCurrentVisibleRequest();
504  void scrollTo(int index);
508  void randomizeList();
512  void reverseList();
516  void sortSelection(SortMode mode);
520  void sort(SortMode mode);
524  void sortByColumn(int column);
528  void addToQueue();
532  void setQueued(PlayListTrack* item);
536  void removeInvalidTracks();
540  void removeDuplicates();
544  void refresh();
548  void clearQueue();
552  void stopAfterSelected();
556  void rebuildGroups();
560  void updateMetaData();
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 Q_DECLARE_METATYPE(PlayListModel::SortMode)
612 
613 #endif
The PlayListModel class provides a data model for the playlist.
Definition: playlistmodel.h:103
Definition: playlistmodel.h:322
The PlayListItem class provides an item for use with the PlayListModel class.
Definition: playlistitem.h:31
Definition: playlistmodel.h:330
int m_top
Definition: playlistmodel.h:80
Abstract interface for playlist formats.
Definition: playlistformat.h:42
int count() const
Definition: playlistmodel.h:75
Definition: playlistmodel.h:326
Definition: playlistmodel.h:324
Definition: playlistmodel.h:323
int m_bottom
Definition: playlistmodel.h:79
Helper class that keeps track of a view's selected items.
Definition: playlistmodel.h:48
UpdateFlags
Definition: playlistmodel.h:352
SimpleSelection()
Definition: playlistmodel.h:53
Definition: playlistmodel.h:328
The PlayListTrack class provides a group for use with the PlayListModel class.
Definition: playlistgroup.h:33
bool isValid() const
Definition: playlistmodel.h:61
QList< int > m_selected_indexes
Definition: playlistmodel.h:81
Definition: playlistmodel.h:325
void dump() const
Definition: playlistmodel.h:68
Definition: playlistmodel.h:329
The QmmpUiSettings class provides access to global libqmmpui library settings.
Definition: qmmpuisettings.h:36
The PlayListTrack class provides a track for use with the PlayListModel class.
Definition: playlisttrack.h:36
Definition: playlistmodel.h:331
SortMode
Definition: playlistmodel.h:319
Definition: playlistmodel.h:327