Qmmp
playlistmodel.h
1 /***************************************************************************
2  * Copyright (C) 2006-2018 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);
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(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  int 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(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();
454  void clearSelection();
458  void removeSelected();
462  void removeUnselected();
466  void removeTrack (int i);
470  void removeTrack (PlayListItem *track);
474  void invertSelection();
478  void selectAll();
483  void showDetails(QWidget *parent = 0);
488  void showDetailsForCurrent(QWidget *parent = 0);
492  void doCurrentVisibleRequest();
496  void scrollTo(int index);
500  void randomizeList();
504  void reverseList();
508  void sortSelection(int mode);
512  void sort(int mode);
516  void sortByColumn(int column);
520  void addToQueue();
524  void setQueued(PlayListTrack* item);
528  void removeInvalidTracks();
532  void removeDuplicates();
536  void refresh();
540  void clearQueue();
544  void stopAfterSelected();
548  void rebuildGroups();
552  void updateMetaData();
553 
554 private:
558  int topmostInSelection(int);
562  int bottommostInSelection(int);
567  void removeSelection(bool inverted = false);
568 
569  int removeTrackInternal(int i);
570 
571 private slots:
575  void preparePlayState();
579  void prepareForShufflePlaying(bool yes);
584  void prepareGroups(bool enabled);
585 
586  void onTaskFinished();
587 
588 private:
589  PlayListTrack* m_current_track;
590  PlayListTrack* m_stop_track;
591  int m_current;
592  SimpleSelection m_selection;
593  QQueue <PlayListTrack*> m_queued_songs;
594  PlayState* m_play_state;
595  qint64 m_total_duration;
596  FileLoader *m_loader;
597  QString m_name;
598  PlayListContainer *m_container;
599  QmmpUiSettings *m_ui_settings;
600  PlayListTask *m_task;
601 };
602 
603 #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&#39;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