Qmmp
playlistmodel.h
1 /***************************************************************************
2  * Copyright (C) 2006-2017 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 "playlistitem.h"
31 #include "playlisttrack.h"
32 #include "playlistgroup.h"
33 
34 class FileLoader;
35 class PlayState;
36 class PlayListFormat;
37 class PlayListModel;
38 class PlayListContainer;
39 class QmmpUiSettings;
40 class PlayListTask;
41 
47 {
52  {
53  m_bottom = -1;
54  m_top = 1;
55  }
59  inline bool isValid()const
60  {
61  return (m_bottom != -1) && (m_top != -1);
62  }
66  inline void dump()const
67  {
68  qDebug("top: %d\tbotom: %d", m_top, m_bottom);
69  }
73  inline int count()const
74  {
75  return m_bottom - m_top + 1;
76  }
77  int m_bottom;
78  int m_top;
79  QList<int> m_selected_indexes;
80 };
101 class PlayListModel : public QObject
102 {
103  Q_OBJECT
104 public:
110  PlayListModel(const QString &name, QObject *parent = 0);
114  ~PlayListModel();
118  QString name() const;
122  void setName(const QString &name);
126  int count() const;
130  int trackCount() const;
134  bool isEmpty() const;
138  int columnCount() const;
142  PlayListTrack* currentTrack() const;
146  PlayListTrack* nextTrack() const;
150  int indexOf(PlayListItem* item) const;
154  PlayListItem* item(int index) const;
158  PlayListTrack* track(int index) const;
162  PlayListGroup* group(int index) const;
166  int currentIndex() const;
172  bool setCurrent (int index);
177  bool setCurrent(PlayListTrack *item);
182  bool isTrack(int index) const;
187  bool isGroup(int index) const;
191  bool isSelected(int index) const;
197  void setSelected(int index, bool selected = true);
203  void setSelected(QList<PlayListTrack *> tracks, bool selected = true);
209  void setSelected(QList<PlayListItem *> items, bool selected = true);
216  void setSelected(int first, int last, bool selected = true);
222  void setSelected(QList<int> indexes, bool selected = true);
227  bool next();
232  bool previous();
238  QList<PlayListItem *> mid(int pos, int count = -1) const;
242  void moveItems(int from, int to);
246  bool isQueued(PlayListTrack* item) const;
250  bool isEmptyQueue()const;
254  int queuedIndex(PlayListTrack* track) const;
258  int queueSize() const;
262  bool isStopAfter(PlayListItem* item) const;
267  const SimpleSelection& getSelection(int row);
271  QList<int> selectedIndexes() const;
275  QList<PlayListTrack *> selectedTracks() const;
279  QList<PlayListItem*> items() const;
283  int firstSelectedUpper(int row);
287  int firstSelectedLower(int row);
291  int totalLength() const;
295  void loadPlaylist(const QString& f_name);
301  void loadPlaylist(const QString &fmt, const QByteArray &data);
305  void savePlaylist(const QString& f_name);
309  bool isLoaderRunning() const;
313  bool contains(const QString &url);
317  enum SortMode
318  {
319  TITLE = 0,
330  GROUP
331  };
336  int indexOfTrack(int index) const;
341  PlayListTrack *findTrack(int track_index) const;
346  QList<PlayListItem *> findTracks(const QString &str) const;
351  {
352  STRUCTURE = 0x01,
353  SELECTION = 0x02,
354  QUEUE = 0x04,
355  CURRENT = 0x08,
356  STOP_AFTER = 0x10,
357  METADATA = 0x20
358  };
359 
360 signals:
365  void listChanged(int flags);
370  void trackAdded(PlayListTrack *track);
375  void nameChanged(const QString& name);
379  void loaderFinished();
383  void scrollToRequest(int index);
389  void sortingByColumnFinished(int column, bool reverted);
390 
391 public slots:
395  void add(PlayListTrack *track);
400  void add(QList <PlayListTrack *> tracks);
405  void add(const QString &path);
410  void add(const QStringList &paths);
414  void insert(int index, PlayListTrack *track);
418  void insert(PlayListItem *before, PlayListTrack *track);
422  void insert(int index, QList <PlayListTrack *> tracks);
426  void insert(PlayListItem *before, QList <PlayListTrack *> tracks);
432  void insert(int index, const QString &path);
438  void insert(int index, const QStringList &paths);
444  void insert(int index, const QList<QUrl> &urls);
448  void clear();
452  void clearSelection();
456  void removeSelected();
460  void removeUnselected();
464  void removeTrack (int i);
468  void removeTrack (PlayListItem *track);
472  void invertSelection();
476  void selectAll();
481  void showDetails(QWidget *parent = 0);
486  void showDetailsForCurrent(QWidget *parent = 0);
490  void doCurrentVisibleRequest();
494  void scrollTo(int index);
498  void randomizeList();
502  void reverseList();
506  void sortSelection(int mode);
510  void sort(int mode);
514  void sortByColumn(int column);
518  void addToQueue();
522  void setQueued(PlayListTrack* item);
526  void removeInvalidTracks();
530  void removeDuplicates();
534  void refresh();
538  void clearQueue();
542  void stopAfterSelected();
546  void rebuildGroups();
550  void updateMetaData();
551 
552 private:
556  int topmostInSelection(int);
560  int bottommostInSelection(int);
565  void removeSelection(bool inverted = false);
566 
567  int removeTrackInternal(int i);
568 
569 private slots:
573  void preparePlayState();
577  void prepareForShufflePlaying(bool yes);
582  void prepareGroups(bool enabled);
583 
584  void onTaskFinished();
585 
586 private:
587  PlayListTrack* m_current_track;
588  PlayListTrack* m_stop_track;
589  int m_current;
590  SimpleSelection m_selection;
591  QQueue <PlayListTrack*> m_queued_songs;
592  PlayState* m_play_state;
593  int m_total_length;
594  FileLoader *m_loader;
595  QString m_name;
596  PlayListContainer *m_container;
597  QmmpUiSettings *m_ui_settings;
598  PlayListTask *m_task;
599 };
600 
601 #endif
The PlayListModel class provides a data model for the playlist.
Definition: playlistmodel.h:101
Definition: playlistmodel.h:320
The PlayListItem class provides an item for use with the PlayListModel class.
Definition: playlistitem.h:31
Definition: playlistmodel.h:328
int m_top
Definition: playlistmodel.h:78
Abstract interface for playlist formats.
Definition: playlistformat.h:41
int count() const
Definition: playlistmodel.h:73
Definition: playlistmodel.h:324
Definition: playlistmodel.h:322
Definition: playlistmodel.h:321
int m_bottom
Definition: playlistmodel.h:77
Helper class that keeps track of a view&#39;s selected items.
Definition: playlistmodel.h:46
UpdateFlags
Definition: playlistmodel.h:350
SimpleSelection()
Definition: playlistmodel.h:51
Definition: playlistmodel.h:326
The PlayListTrack class provides a group for use with the PlayListModel class.
Definition: playlistgroup.h:32
bool isValid() const
Definition: playlistmodel.h:59
QList< int > m_selected_indexes
Definition: playlistmodel.h:79
Definition: playlistmodel.h:323
void dump() const
Definition: playlistmodel.h:66
Definition: playlistmodel.h:327
The QmmpUiSettings class provides access to global libqmmpui library settings.
Definition: qmmpuisettings.h:35
The PlayListTrack class provides a track for use with the PlayListModel class.
Definition: playlisttrack.h:36
Definition: playlistmodel.h:329
SortMode
Definition: playlistmodel.h:317
Definition: playlistmodel.h:325