Qmmp
Loading...
Searching...
No Matches
playlistmodel.h
1/***************************************************************************
2 * Copyright (C) 2006-2022 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 <QSet>
32#include "playlistitem.h"
33#include "playlisttrack.h"
34#include "playlistgroup.h"
35#include "qmmpui_export.h"
36
37class FileLoader;
38class PlayState;
39class PlayListFormat;
40class PlayListModel;
41class PlayListContainer;
42class QmmpUiSettings;
43class PlayListTask;
44
50{
54 inline bool isValid()const
55 {
56 return (m_bottom != -1) && (m_top != -1);
57 }
61 inline void dump()const
62 {
63 qDebug("top: %d\tbotom: %d", m_top, m_bottom);
64 }
68 inline int count()const
69 {
70 return m_bottom - m_top + 1;
71 }
72 int m_bottom = -1;
73 int m_top = 1;
74 QList<int> m_selected_indexes;
75};
96class QMMPUI_EXPORT PlayListModel : public QObject
97{
98 Q_OBJECT
99public:
105 explicit PlayListModel(const QString &name, QObject *parent = nullptr);
113 QString name() const;
117 void setName(const QString &name);
121 int count() const;
125 int trackCount() const;
129 bool isEmpty() const;
133 int columnCount() const;
145 int indexOf(PlayListItem* item) const;
149 PlayListItem* item(int index) const;
153 PlayListTrack* track(int index) const;
157 PlayListGroup* group(int index) const;
161 int currentIndex() const;
167 bool setCurrent (int index);
177 bool isTrack(int index) const;
182 bool isGroup(int index) const;
186 bool isSelected(int index) const;
192 void setSelected(int index, bool selected = true);
198 void setSelected(const QList<PlayListTrack *> &tracks, bool selected = true);
204 void setSelected(const QList<PlayListItem *> &items, bool selected = true);
211 void setSelected(int first, int last, bool selected = true);
217 void setSelected(const QList<int> &indexes, bool selected = true);
222 bool next();
227 bool previous();
233 QList<PlayListItem *> mid(int pos, int count = -1) const;
237 void moveItems(int from, int to);
241 const QList<PlayListTrack *> &queuedTracks() const;
245 bool isEmptyQueue()const;
249 int queueSize() const;
253 bool isStopAfter(const PlayListItem* item) const;
262 QList<int> selectedIndexes() const;
266 QList<PlayListTrack *> selectedTracks() const;
270 QList<PlayListItem*> items() const;
274 int firstSelectedUpper(int row);
278 int firstSelectedLower(int row);
282 qint64 totalDuration() const;
286 void loadPlaylist(const QString& f_name);
292 void loadPlaylist(const QString &fmt, const QByteArray &data);
296 void savePlaylist(const QString& f_name);
300 bool isLoaderRunning() const;
304 bool contains(const QString &url);
327 int indexOfTrack(int index) const;
332 PlayListTrack *findTrack(int track_index) const;
337 QList<PlayListItem *> findTracks(const QString &str) const;
342 {
343 STRUCTURE = 0x01,
344 SELECTION = 0x02,
345 QUEUE = 0x04,
346 CURRENT = 0x08,
347 STOP_AFTER = 0x10,
348 METADATA = 0x20
349 };
350
351signals:
356 void listChanged(int flags);
366 void nameChanged(const QString& name);
374 void scrollToRequest(int index);
380 void sortingByColumnFinished(int column, bool reverted);
381
382public slots:
386 void add(PlayListTrack *track);
391 void add(const QList<PlayListTrack *> &tracks);
396 void add(const QString &path);
401 void add(const QStringList &paths);
405 void insert(int index, PlayListTrack *track);
409 void insert(PlayListItem *before, PlayListTrack *track);
413 void insert(int index, const QList<PlayListTrack *> &tracks);
418 void insert(int index, const QByteArray &json);
422 void insert(PlayListItem *before, const QList<PlayListTrack *> &tracks);
428 void insert(int index, const QString &path);
434 void insert(int index, const QStringList &paths);
440 void insert(int index, const QList<QUrl> &urls);
444 void clear();
460 void removeTrack(int i);
468 void removeTracks(const QList<PlayListItem *> &items);
472 void removeTracks(const QList<PlayListTrack *> &tracks);
480 void selectAll();
485 void showDetails(QWidget *parent = nullptr);
490 void showDetailsForCurrent(QWidget *parent = nullptr);
498 void scrollTo(int index);
514 void sort(SortMode mode);
518 void sortByColumn(int column);
538 void refresh();
555
556private:
560 int topmostInSelection(int);
564 int bottommostInSelection(int);
569 void removeSelection(bool inverted = false);
570
571 int removeTrackInternal(int i);
572
573private slots:
577 void preparePlayState();
581 void prepareForShufflePlaying(bool yes);
586 void prepareGroups(bool enabled);
587
588 void onTaskFinished();
589
590 void updateMetaData(const QStringList &paths);
591
592private:
593 PlayListTrack *m_current_track = nullptr;
594 PlayListTrack *m_stop_track = nullptr;
595 int m_current = 0;
596 SimpleSelection m_selection;
597 PlayState* m_play_state;
598 qint64 m_total_duration = 0;
599 FileLoader *m_loader;
600 QString m_name;
601 PlayListContainer *m_container;
602 QmmpUiSettings *m_ui_settings;
603 PlayListTask *m_task;
604 QSet<QString> m_paths;
605};
606
607Q_DECLARE_METATYPE(PlayListModel::SortMode)
608
609#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:97
int trackCount() const
SortMode
Definition playlistmodel.h:309
@ ALBUMARTIST
Definition playlistmodel.h:314
@ DATE
Definition playlistmodel.h:317
@ TRACK
Definition playlistmodel.h:318
@ DISCNUMBER
Definition playlistmodel.h:312
@ FILE_CREATION_DATE
Definition playlistmodel.h:319
@ ARTIST
Definition playlistmodel.h:313
@ PATH_AND_FILENAME
Definition playlistmodel.h:316
@ ALBUM
Definition playlistmodel.h:311
@ FILENAME
Definition playlistmodel.h:315
@ FILE_MODIFICATION_DATE
Definition playlistmodel.h:320
int indexOf(PlayListItem *item) const
void sortByColumn(int column)
int indexOfTrack(int index) const
int count() const
void insert(int index, const QByteArray &json)
void removeUnselected()
bool isGroup(int index) const
void add(PlayListTrack *track)
void removeTrack(PlayListItem *track)
bool isStopAfter(const PlayListItem *item) const
void removeDuplicates()
void add(const QString &path)
PlayListItem * item(int index) const
void insert(PlayListItem *before, PlayListTrack *track)
int firstSelectedUpper(int row)
void nameChanged(const QString &name)
void showDetailsForCurrent(QWidget *parent=nullptr)
void scrollTo(int index)
void insert(int index, const QStringList &paths)
void setSelected(const QList< PlayListTrack * > &tracks, bool selected=true)
qint64 totalDuration() const
void insert(int index, PlayListTrack *track)
void savePlaylist(const QString &f_name)
PlayListTrack * findTrack(int track_index) const
void showDetails(QWidget *parent=nullptr)
QList< PlayListItem * > findTracks(const QString &str) const
int currentIndex() const
PlayListModel(const QString &name, QObject *parent=nullptr)
void setSelected(const QList< int > &indexes, bool selected=true)
void sortSelection(SortMode mode)
void setSelected(int index, bool selected=true)
QList< PlayListItem * > mid(int pos, int count=-1) const
void loadPlaylist(const QString &fmt, const QByteArray &data)
void moveItems(int from, int to)
const QList< PlayListTrack * > & queuedTracks() const
PlayListTrack * track(int index) const
bool isSelected(int index) const
QList< PlayListItem * > items() const
void removeInvalidTracks()
void insert(int index, const QString &path)
PlayListGroup * group(int index) const
void updateMetaData()
void clearQueue()
void randomizeList()
void setQueued(PlayListTrack *t)
void removeTracks(const QList< PlayListItem * > &items)
QString name() const
const SimpleSelection & getSelection(int row)
void removeTrack(int i)
void add(const QStringList &paths)
bool setCurrent(PlayListTrack *item)
void removeTracks(const QList< PlayListTrack * > &tracks)
PlayListTrack * currentTrack() const
void loaderFinished()
UpdateFlags
Definition playlistmodel.h:342
bool setCurrent(int index)
int queueSize() const
QList< int > selectedIndexes() 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)
void loadPlaylist(const QString &f_name)
void clearSelection()
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< PlayListTrack * > &tracks)
QList< PlayListTrack * > selectedTracks() const
void insert(int index, const QList< QUrl > &urls)
void doCurrentVisibleRequest()
int firstSelectedLower(int row)
PlayListTrack * nextTrack() const
void add(const QList< PlayListTrack * > &tracks)
void insert(PlayListItem *before, const QList< PlayListTrack * > &tracks)
void reverseList()
void sort(SortMode mode)
void setSelected(const QList< PlayListItem * > &items, bool selected=true)
void addToQueue()
void removeSelected()
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:50
int count() const
Definition playlistmodel.h:68
bool isValid() const
Definition playlistmodel.h:54
QList< int > m_selected_indexes
Definition playlistmodel.h:74
int m_bottom
Definition playlistmodel.h:72
int m_top
Definition playlistmodel.h:73
void dump() const
Definition playlistmodel.h:61