Changeset View
Changeset View
Standalone View
Standalone View
src/models/allalbumsproxymodel.cpp
Show All 16 Lines | |||||
17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | * Boston, MA 02110-1301, USA. | 18 | * Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #include "allalbumsproxymodel.h" | 21 | #include "allalbumsproxymodel.h" | ||
22 | 22 | | |||
23 | #include "allalbumsmodel.h" | 23 | #include "allalbumsmodel.h" | ||
24 | 24 | | |||
25 | #include <QReadLocker> | ||||
26 | #include <QtConcurrentRun> | ||||
27 | | ||||
28 | AllAlbumsProxyModel::AllAlbumsProxyModel(QObject *parent) : AbstractMediaProxyModel(parent) | ||||
29 | { | ||||
30 | } | ||||
31 | | ||||
32 | AllAlbumsProxyModel::~AllAlbumsProxyModel() | ||||
33 | { | ||||
34 | } | ||||
35 | | ||||
25 | bool AllAlbumsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | 36 | bool AllAlbumsProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const | ||
26 | { | 37 | { | ||
27 | bool result = false; | 38 | bool result = false; | ||
28 | 39 | | |||
29 | for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { | 40 | for (int column = 0, columnCount = sourceModel()->columnCount(source_parent); column < columnCount; ++column) { | ||
30 | auto currentIndex = sourceModel()->index(source_row, column, source_parent); | 41 | auto currentIndex = sourceModel()->index(source_row, column, source_parent); | ||
31 | 42 | | |||
32 | const auto &titleValue = sourceModel()->data(currentIndex, AllAlbumsModel::TitleRole).toString(); | 43 | const auto &titleValue = sourceModel()->data(currentIndex, AllAlbumsModel::TitleRole).toString(); | ||
Show All 32 Lines | |||||
65 | } | 76 | } | ||
66 | } | 77 | } | ||
67 | 78 | | |||
68 | return result; | 79 | return result; | ||
69 | } | 80 | } | ||
70 | 81 | | |||
71 | void AllAlbumsProxyModel::enqueueToPlayList() | 82 | void AllAlbumsProxyModel::enqueueToPlayList() | ||
72 | { | 83 | { | ||
73 | MediaPlayList *playList = AbstractMediaProxyModel::mediaPlayList(); | 84 | QtConcurrent::run(&mThreadPool, [=] () { | ||
74 | for (int columnIndex = 0, columnCount = this->columnCount(); columnIndex < columnCount; ++columnIndex) { | 85 | QReadLocker locker(&mDataLock); | ||
75 | for (int rowIndex = 0, rowCount = this->rowCount(); rowIndex < rowCount; ++rowIndex) { | 86 | auto allAlbums = QList<MusicAlbum>(); | ||
76 | auto currentIndex = this->index(rowIndex, columnIndex); | 87 | allAlbums.reserve(rowCount()); | ||
77 | playList->enqueue(this->data(currentIndex,AllAlbumsModel::ContainerDataRole).value<MusicAlbum>()); | 88 | for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { | ||
78 | } | 89 | auto currentIndex = index(rowIndex, 0); | ||
90 | allAlbums.push_back(data(currentIndex, AllAlbumsModel::ContainerDataRole). value<MusicAlbum>()); | ||||
91 | } | ||||
92 | Q_EMIT albumToEnqueue(allAlbums, | ||||
93 | ElisaUtils::AppendPlayList, | ||||
94 | ElisaUtils::DoNotTriggerPlay); | ||||
95 | }); | ||||
79 | } | 96 | } | ||
80 | 97 | | |||
98 | void AllAlbumsProxyModel::replaceAndPlayOfPlayList() | ||||
99 | { | ||||
100 | QtConcurrent::run(&mThreadPool, [=] () { | ||||
101 | QReadLocker locker(&mDataLock); | ||||
102 | auto allAlbums = QList<MusicAlbum>(); | ||||
103 | allAlbums.reserve(rowCount()); | ||||
104 | for (int rowIndex = 0, maxRowCount = rowCount(); rowIndex < maxRowCount; ++rowIndex) { | ||||
105 | auto currentIndex = index(rowIndex, 0); | ||||
106 | allAlbums.push_back(data(currentIndex, AllAlbumsModel::ContainerDataRole). value<MusicAlbum>()); | ||||
107 | } | ||||
108 | Q_EMIT albumToEnqueue(allAlbums, | ||||
109 | ElisaUtils::ReplacePlayList, | ||||
110 | ElisaUtils::TriggerPlay); | ||||
111 | }); | ||||
81 | } | 112 | } | ||
82 | 113 | | |||
114 | | ||||
83 | #include "moc_allalbumsproxymodel.cpp" | 115 | #include "moc_allalbumsproxymodel.cpp" |