Sayonara Player
Loading...
Searching...
No Matches
PlaylistModel.h
1/* PlaylistItemModel.h */
2
3/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
4 *
5 * This file is part of sayonara player
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22/*
23 * PlaylistItemModel.h
24 *
25 * Created on: Apr 8, 2011
26 * Author: Michael Lugmair (Lucio Carreras)
27 */
28
29#ifndef PLAYLISTITEMMODEL_H
30#define PLAYLISTITEMMODEL_H
31
32#include "Gui/Utils/SearchableWidget/SearchableModel.h"
33
34#include "Utils/Library/Sortorder.h"
35#include "Utils/Pimpl.h"
36#include "Utils/Playlist/PlaylistFwd.h"
37
38#include <QTableView>
39
40namespace Library
41{
42 class InfoAccessor;
43}
44class CustomMimeData;
45class QPixmap;
46
47namespace Playlist
48{
49 class Model :
50 public SearchableTableModel
51 {
52 Q_OBJECT
53 PIMPL(Model)
54
55 signals:
56 void sigDataReady();
57 void sigCurrentTrackChanged(int index);
58 void sigCurrentScannedFileChanged(const QString& filename);
59 void sigBusyChanged(bool b);
60
61 public:
62 enum StyleElement
63 {
64 Italic = 0x2110,
65 Bold = 0x212C
66 };
67
68 enum ColumnName
69 {
70 TrackNumber = 0,
71 Cover,
72 Description,
73 Time,
74 NumColumns
75 };
76
77 enum Roles
78 {
79 RatingRole = Qt::UserRole + 1,
80 DragIndexRole = Qt::UserRole + 2,
81 EntryLookRole = Qt::UserRole + 3,
82 CurrentPlayingRole = Qt::UserRole + 4,
83 EnabledRole = Qt::UserRole + 5,
84 LastTrackBeforeStop = Qt::UserRole + 6
85 };
86
87 Model(const PlaylistPtr& playlist, Library::InfoAccessor* libraryInfoAccessor, QObject* parent);
88 ~Model() override;
89
90 [[nodiscard]] int playlistIndex() const;
91
92 void clear();
93 void removeTracks(const IndexSet& rows);
94 void deleteTracks(const IndexSet& rows);
95
96 void findTrack(int index);
97 void toggleStopAfterTrack(int index);
98
99 IndexSet moveTracks(const IndexSet& rows, int targetIndex);
100 IndexSet moveTracksUp(const IndexSet& rows);
101 IndexSet moveTracksDown(const IndexSet& rows);
102 IndexSet copyTracks(const IndexSet& rows, int targetIndex);
103 void insertTracks(const MetaDataList& tracks, int row);
104 void insertTracks(const QStringList& files, int row);
105
106 [[nodiscard]] int currentTrack() const;
107
108 [[nodiscard]] MetaDataList metadata(const IndexSet& rows) const;
109 [[nodiscard]] bool isEnabled(const int row) const;
110
111 [[nodiscard]] bool hasLocalMedia(const IndexSet& rows) const;
112 [[nodiscard]] bool isLocked() const;
113 void setLocked(bool b);
114 void setDragIndex(int dragIndex);
115 void changeRating(const IndexSet& rows, Rating rating);
116 void changeTrack(int trackIndex, Seconds seconds = 0);
117
118 void setBusy(bool b);
119
120 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index = QModelIndex()) const override;
121 [[nodiscard]] QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
122 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
123 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
124 [[nodiscard]] int columnCount(const QModelIndex& parent = QModelIndex()) const override;
125
126 [[nodiscard]] QMimeData* mimeData(const QModelIndexList& indexes) const override;
127 [[nodiscard]] QMap<QString, QString> searchOptions() const override;
128
129 public slots: // NOLINT(readability-redundant-access-specifiers)
130 void refreshData();
131 void reverseTracks();
132 void randomizeTracks();
133 void sortTracks(Library::TrackSortorder sortorder);
134 void jumpToNextAlbum();
135
136 protected:
137 [[nodiscard]] int itemCount() const override;
138 [[nodiscard]] QString searchableString(int index, const QString& prefix) const override;
139
140 private slots:
141 void playlistChanged(int playlistIndex);
142 void currentTrackChanged(int oldIndex, int newIndex);
143
144 void coversChanged();
145 void coverFound(const QPixmap& pixmap);
146 void coverLookupFinished(bool success);
147
148 private: // NOLINT(readability-redundant-access-specifiers)
149 void startCoverLookup(const MetaData& track) const;
150 void lookChanged();
151 void refreshPlaylist(int rowCount, int columnCount);
152 };
153
154 Util::Set<int> removeDisabledRows(const Util::Set<int>& selectedRows, Model* model);
155}
156
157#endif /* PLAYLISTITEMMODEL_H */
Definition LibraryManager.h:36
Definition MetaDataList.h:34
Definition MetaData.h:43
Definition PlaylistModel.h:51
Definition org_mpris_media_player2_adaptor.h:21
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition Set.h:37