Changeset View
Changeset View
Standalone View
Standalone View
src/mediaplaylist.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | |||||
83 | 83 | | |||
84 | QHash<int, QByteArray> MediaPlayList::roleNames() const | 84 | QHash<int, QByteArray> MediaPlayList::roleNames() const | ||
85 | { | 85 | { | ||
86 | auto roles = QAbstractItemModel::roleNames(); | 86 | auto roles = QAbstractItemModel::roleNames(); | ||
87 | 87 | | |||
88 | roles[static_cast<int>(ColumnsRoles::IsValidRole)] = "isValid"; | 88 | roles[static_cast<int>(ColumnsRoles::IsValidRole)] = "isValid"; | ||
89 | roles[static_cast<int>(ColumnsRoles::DatabaseIdRole)] = "databaseId"; | 89 | roles[static_cast<int>(ColumnsRoles::DatabaseIdRole)] = "databaseId"; | ||
90 | roles[static_cast<int>(ColumnsRoles::TitleRole)] = "title"; | 90 | roles[static_cast<int>(ColumnsRoles::TitleRole)] = "title"; | ||
91 | roles[static_cast<int>(ColumnsRoles::HttpAddressRole)] = "httpAddress"; | ||||
91 | roles[static_cast<int>(ColumnsRoles::StringDurationRole)] = "duration"; | 92 | roles[static_cast<int>(ColumnsRoles::StringDurationRole)] = "duration"; | ||
92 | roles[static_cast<int>(ColumnsRoles::ArtistRole)] = "artist"; | 93 | roles[static_cast<int>(ColumnsRoles::ArtistRole)] = "artist"; | ||
93 | roles[static_cast<int>(ColumnsRoles::AlbumArtistRole)] = "albumArtist"; | 94 | roles[static_cast<int>(ColumnsRoles::AlbumArtistRole)] = "albumArtist"; | ||
94 | roles[static_cast<int>(ColumnsRoles::AlbumRole)] = "album"; | 95 | roles[static_cast<int>(ColumnsRoles::AlbumRole)] = "album"; | ||
95 | roles[static_cast<int>(ColumnsRoles::TrackNumberRole)] = "trackNumber"; | 96 | roles[static_cast<int>(ColumnsRoles::TrackNumberRole)] = "trackNumber"; | ||
96 | roles[static_cast<int>(ColumnsRoles::DiscNumberRole)] = "discNumber"; | 97 | roles[static_cast<int>(ColumnsRoles::DiscNumberRole)] = "discNumber"; | ||
97 | roles[static_cast<int>(ColumnsRoles::RatingRole)] = "rating"; | 98 | roles[static_cast<int>(ColumnsRoles::RatingRole)] = "rating"; | ||
98 | roles[static_cast<int>(ColumnsRoles::GenreRole)] = "genre"; | 99 | roles[static_cast<int>(ColumnsRoles::GenreRole)] = "genre"; | ||
▲ Show 20 Lines • Show All 105 Lines • ▼ Show 20 Line(s) | 202 | { | |||
204 | if (!index.isValid()) { | 205 | if (!index.isValid()) { | ||
205 | return modelModified; | 206 | return modelModified; | ||
206 | } | 207 | } | ||
207 | 208 | | |||
208 | if (index.row() < 0 || index.row() >= d->mData.size()) { | 209 | if (index.row() < 0 || index.row() >= d->mData.size()) { | ||
209 | return modelModified; | 210 | return modelModified; | ||
210 | } | 211 | } | ||
211 | 212 | | |||
212 | if (role < ColumnsRoles::IsValidRole || role > ColumnsRoles::IsPlayingRole) { | 213 | if ((role != ColumnsRoles::TitleRole && role != ColumnsRoles::ArtistRole) && | ||
214 | (role < ColumnsRoles::IsValidRole || role > ColumnsRoles::IsPlayingRole)) { | ||||
213 | return modelModified; | 215 | return modelModified; | ||
214 | } | 216 | } | ||
215 | 217 | | |||
216 | auto convertedRole = static_cast<ColumnsRoles>(role); | 218 | auto convertedRole = static_cast<ColumnsRoles>(role); | ||
217 | 219 | | |||
218 | switch(convertedRole) | 220 | switch(convertedRole) | ||
219 | { | 221 | { | ||
220 | case ColumnsRoles::IsPlayingRole: | 222 | case ColumnsRoles::IsPlayingRole: | ||
221 | { | 223 | { | ||
222 | modelModified = true; | 224 | modelModified = true; | ||
223 | auto newState = static_cast<PlayState>(value.toInt()); | 225 | auto newState = static_cast<PlayState>(value.toInt()); | ||
224 | d->mData[index.row()].mIsPlaying = newState; | 226 | d->mData[index.row()].mIsPlaying = newState; | ||
225 | Q_EMIT dataChanged(index, index, {role}); | 227 | Q_EMIT dataChanged(index, index, {role}); | ||
226 | 228 | | |||
227 | if (!d->mCurrentTrack.isValid()) { | 229 | if (!d->mCurrentTrack.isValid()) { | ||
228 | resetCurrentTrack(); | 230 | resetCurrentTrack(); | ||
229 | } | 231 | } | ||
230 | 232 | | |||
231 | break; | 233 | break; | ||
232 | } | 234 | } | ||
235 | case ColumnsRoles::TitleRole: | ||||
236 | { | ||||
237 | modelModified = true; | ||||
238 | d->mData[index.row()].mTitle = value; | ||||
239 | d->mTrackData[index.row()][static_cast<TrackDataType::key_type>(role)] = value; | ||||
240 | Q_EMIT dataChanged(index, index, {role}); | ||||
241 | | ||||
242 | if (!d->mCurrentTrack.isValid()) { | ||||
243 | resetCurrentTrack(); | ||||
244 | } | ||||
245 | | ||||
246 | break; | ||||
247 | } | ||||
248 | case ColumnsRoles::ArtistRole: | ||||
249 | { | ||||
250 | modelModified = true; | ||||
251 | d->mData[index.row()].mArtist = value; | ||||
252 | d->mTrackData[index.row()][static_cast<TrackDataType::key_type>(role)] = value; | ||||
253 | Q_EMIT dataChanged(index, index, {role}); | ||||
254 | | ||||
255 | if (!d->mCurrentTrack.isValid()) { | ||||
256 | resetCurrentTrack(); | ||||
257 | } | ||||
258 | | ||||
259 | break; | ||||
260 | } | ||||
233 | default: | 261 | default: | ||
234 | modelModified = false; | 262 | modelModified = false; | ||
235 | } | 263 | } | ||
236 | 264 | | |||
237 | return modelModified; | 265 | return modelModified; | ||
238 | } | 266 | } | ||
239 | 267 | | |||
240 | bool MediaPlayList::removeRows(int row, int count, const QModelIndex &parent) | 268 | bool MediaPlayList::removeRows(int row, int count, const QModelIndex &parent) | ||
▲ Show 20 Lines • Show All 168 Lines • ▼ Show 20 Line(s) | 411 | { | |||
409 | } | 437 | } | ||
410 | 438 | | |||
411 | Q_EMIT tracksCountChanged(); | 439 | Q_EMIT tracksCountChanged(); | ||
412 | Q_EMIT persistentStateChanged(); | 440 | Q_EMIT persistentStateChanged(); | ||
413 | 441 | | |||
414 | Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole}); | 442 | Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole}); | ||
415 | } | 443 | } | ||
416 | 444 | | |||
417 | void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries) | 445 | void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries, ElisaUtils::PlayListEntryType type) | ||
418 | { | 446 | { | ||
419 | enqueueCommon(); | 447 | enqueueCommon(); | ||
420 | 448 | | |||
421 | beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1); | 449 | beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1); | ||
422 | for (const auto &newTrack : newEntries) { | 450 | for (const auto &newTrack : newEntries) { | ||
423 | auto newMediaPlayListEntry = MediaPlayListEntry{std::get<0>(newTrack), std::get<1>(newTrack), ElisaUtils::Track}; | 451 | auto newMediaPlayListEntry = MediaPlayListEntry{std::get<0>(newTrack), std::get<1>(newTrack), type}; | ||
424 | d->mData.push_back(newMediaPlayListEntry); | 452 | d->mData.push_back(newMediaPlayListEntry); | ||
425 | d->mTrackData.push_back({}); | 453 | d->mTrackData.push_back({}); | ||
426 | Q_EMIT newEntryInList(newMediaPlayListEntry.mId, newMediaPlayListEntry.mTitle.toString(), newMediaPlayListEntry.mEntryType); | 454 | Q_EMIT newEntryInList(newMediaPlayListEntry.mId, newMediaPlayListEntry.mTitle.toString(), newMediaPlayListEntry.mEntryType); | ||
427 | } | 455 | } | ||
428 | endInsertRows(); | 456 | endInsertRows(); | ||
429 | 457 | | |||
430 | restorePlayListPosition(); | 458 | restorePlayListPosition(); | ||
431 | if (!d->mCurrentTrack.isValid()) { | 459 | if (!d->mCurrentTrack.isValid()) { | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 536 | { | |||
549 | Q_EMIT tracksCountChanged(); | 577 | Q_EMIT tracksCountChanged(); | ||
550 | Q_EMIT persistentStateChanged(); | 578 | Q_EMIT persistentStateChanged(); | ||
551 | 579 | | |||
552 | Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole}); | 580 | Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole}); | ||
553 | displayOrHideUndoInline(false); | 581 | displayOrHideUndoInline(false); | ||
554 | Q_EMIT undoClearPlayListPlayer(); | 582 | Q_EMIT undoClearPlayListPlayer(); | ||
555 | } | 583 | } | ||
556 | 584 | | |||
585 | void MediaPlayList::updateRadioData(const QVariant &value, int role) | ||||
586 | { | ||||
587 | auto convertedRole = static_cast<ColumnsRoles>(role); | ||||
588 | if(d->mCurrentTrack.data(convertedRole) != value){ | ||||
astippich: code style
if (...) { | |||||
589 | this->setData(d->mCurrentTrack, value, role); | ||||
590 | } | ||||
591 | } | ||||
592 | | ||||
557 | void MediaPlayList::enqueueCommon() | 593 | void MediaPlayList::enqueueCommon() | ||
558 | { | 594 | { | ||
559 | displayOrHideUndoInline(false); | 595 | displayOrHideUndoInline(false); | ||
560 | } | 596 | } | ||
561 | 597 | | |||
562 | void MediaPlayList::copyD() | 598 | void MediaPlayList::copyD() | ||
563 | { | 599 | { | ||
564 | dOld->mData = d->mData; | 600 | dOld->mData = d->mData; | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 639 | { | |||
611 | enqueueCommon(); | 647 | enqueueCommon(); | ||
612 | 648 | | |||
613 | switch (databaseIdType) | 649 | switch (databaseIdType) | ||
614 | { | 650 | { | ||
615 | case ElisaUtils::Album: | 651 | case ElisaUtils::Album: | ||
616 | case ElisaUtils::Artist: | 652 | case ElisaUtils::Artist: | ||
617 | case ElisaUtils::Genre: | 653 | case ElisaUtils::Genre: | ||
618 | case ElisaUtils::Track: | 654 | case ElisaUtils::Track: | ||
655 | case ElisaUtils::Radio: | ||||
619 | enqueueOneEntry(newEntry, databaseIdType); | 656 | enqueueOneEntry(newEntry, databaseIdType); | ||
620 | break; | 657 | break; | ||
621 | case ElisaUtils::FileName: | 658 | case ElisaUtils::FileName: | ||
622 | enqueueFilesList({newEntry}); | 659 | enqueueFilesList({newEntry}); | ||
623 | break; | 660 | break; | ||
624 | case ElisaUtils::Lyricist: | 661 | case ElisaUtils::Lyricist: | ||
625 | case ElisaUtils::Composer: | 662 | case ElisaUtils::Composer: | ||
626 | case ElisaUtils::Unknown: | 663 | case ElisaUtils::Unknown: | ||
Show All 25 Lines | 685 | if (enqueueMode == ElisaUtils::ReplacePlayList) { | |||
652 | clearPlayList(); | 689 | clearPlayList(); | ||
653 | } | 690 | } | ||
654 | 691 | | |||
655 | enqueueCommon(); | 692 | enqueueCommon(); | ||
656 | 693 | | |||
657 | switch (databaseIdType) | 694 | switch (databaseIdType) | ||
658 | { | 695 | { | ||
659 | case ElisaUtils::Track: | 696 | case ElisaUtils::Track: | ||
660 | enqueueTracksListById(newEntries); | 697 | case ElisaUtils::Radio: | ||
698 | enqueueTracksListById(newEntries, databaseIdType); | ||||
661 | break; | 699 | break; | ||
662 | case ElisaUtils::FileName: | 700 | case ElisaUtils::FileName: | ||
663 | enqueueFilesList(newEntries); | 701 | enqueueFilesList(newEntries); | ||
664 | break; | 702 | break; | ||
665 | case ElisaUtils::Album: | 703 | case ElisaUtils::Album: | ||
666 | case ElisaUtils::Artist: | 704 | case ElisaUtils::Artist: | ||
667 | case ElisaUtils::Genre: | 705 | case ElisaUtils::Genre: | ||
668 | enqueueMultipleEntries(newEntries, databaseIdType); | 706 | enqueueMultipleEntries(newEntries, databaseIdType); | ||
▲ Show 20 Lines • Show All 218 Lines • ▼ Show 20 Line(s) | 899 | if (oneEntry.mEntryType != ElisaUtils::Artist && oneEntry.mIsValid) { | |||
887 | Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); | 925 | Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); | ||
888 | 926 | | |||
889 | restorePlayListPosition(); | 927 | restorePlayListPosition(); | ||
890 | 928 | | |||
891 | if (!d->mCurrentTrack.isValid()) { | 929 | if (!d->mCurrentTrack.isValid()) { | ||
892 | resetCurrentTrack(); | 930 | resetCurrentTrack(); | ||
893 | } | 931 | } | ||
894 | continue; | 932 | continue; | ||
933 | } else if(oneEntry.mEntryType == ElisaUtils::Radio ){ | ||||
astippich: code style
} else if (.....) { | |||||
934 | if (track.databaseId() != oneEntry.mId) { | ||||
935 | continue; | ||||
936 | } | ||||
937 | | ||||
938 | d->mTrackData[i] = track; | ||||
939 | oneEntry.mId = track.databaseId(); | ||||
940 | oneEntry.mIsValid = true; | ||||
941 | | ||||
942 | Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); | ||||
943 | | ||||
944 | restorePlayListPosition(); | ||||
945 | | ||||
946 | if (!d->mCurrentTrack.isValid()) { | ||||
947 | resetCurrentTrack(); | ||||
948 | } | ||||
949 | | ||||
950 | break; | ||||
895 | } else if (oneEntry.mEntryType != ElisaUtils::Artist && !oneEntry.mIsValid && !oneEntry.mTrackUrl.isValid()) { | 951 | } else if (oneEntry.mEntryType != ElisaUtils::Artist && !oneEntry.mIsValid && !oneEntry.mTrackUrl.isValid()) { | ||
896 | if (track.title() != oneEntry.mTitle) { | 952 | if (track.title() != oneEntry.mTitle) { | ||
897 | continue; | 953 | continue; | ||
898 | } | 954 | } | ||
899 | 955 | | |||
900 | if (track.album() != oneEntry.mAlbum) { | 956 | if (track.album() != oneEntry.mAlbum) { | ||
901 | continue; | 957 | continue; | ||
902 | } | 958 | } | ||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |
code style
if (...) {