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 :
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 };
85
86 Model(const PlaylistPtr& playlist, Library::InfoAccessor* libraryInfoAccessor, QObject* parent);
87 ~Model() override;
88
89 [[nodiscard]] int playlistIndex() const;
90
91 void clear();
92 void removeTracks(const IndexSet& rows);
93 void deleteTracks(const IndexSet& rows);
94
95 void findTrack(int index);
96
97 IndexSet moveTracks(const IndexSet& rows, int targetIndex);
98 IndexSet moveTracksUp(const IndexSet& rows);
99 IndexSet moveTracksDown(const IndexSet& rows);
100 IndexSet copyTracks(const IndexSet& rows, int targetIndex);
101 void insertTracks(const MetaDataList& tracks, int row);
102 void insertTracks(const QStringList& files, int row);
103
104 [[nodiscard]] int currentTrack() const;
105
106 [[nodiscard]] MetaDataList metadata(const IndexSet& rows) const;
107 [[nodiscard]] bool isEnabled(const int row) const;
108
109 [[nodiscard]] bool hasLocalMedia(const IndexSet& rows) const;
110 [[nodiscard]] bool isLocked() const;
111 void setLocked(bool b);
112 void setDragIndex(int dragIndex);
113 void changeRating(const IndexSet& rows, Rating rating);
114 void changeTrack(int trackIndex, Seconds seconds = 0);
115
116 void setBusy(bool b);
117
118 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex& index = QModelIndex()) const override;
119 [[nodiscard]] QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
120 bool setData(const QModelIndex& index, const QVariant& value, int role) override;
121 [[nodiscard]] int rowCount(const QModelIndex& parent = QModelIndex()) const override;
122 [[nodiscard]] int columnCount(const QModelIndex& parent = QModelIndex()) const override;
123
124 [[nodiscard]] QMimeData* mimeData(const QModelIndexList& indexes) const override;
125 [[nodiscard]] QMap<QString, QString> searchOptions() const override;
126
127 public slots: // NOLINT(readability-redundant-access-specifiers)
128 void refreshData();
129 void reverseTracks();
130 void randomizeTracks();
131 void sortTracks(Library::TrackSortorder sortorder);
132 void jumpToNextAlbum();
133
134 protected:
135 [[nodiscard]] int itemCount() const override;
136 [[nodiscard]] QString searchableString(int index, const QString& prefix) const override;
137
138 private slots:
139 void playlistChanged(int playlistIndex);
140 void currentTrackChanged(int oldIndex, int newIndex);
141
142 void coversChanged();
143 void coverFound(const QPixmap& pixmap);
144 void coverLookupFinished(bool success);
145
146 private: // NOLINT(readability-redundant-access-specifiers)
147 void startCoverLookup(const MetaData& track) const;
148 void lookChanged();
149 void refreshPlaylist(int rowCount, int columnCount);
150 };
151
152 Util::Set<int> removeDisabledRows(const Util::Set<int>& selectedRows, Model* model);
153}
154
155#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
Definition SearchableModel.h:57
A set structure. Inherited from std::set with some useful methods. For integer and String this set is...
Definition SetFwd.h:27