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; | ||
225 | auto before = d->mCurrentTrack.data(role); | ||||
223 | auto newState = static_cast<PlayState>(value.toInt()); | 226 | auto newState = static_cast<PlayState>(value.toInt()); | ||
224 | d->mData[index.row()].mIsPlaying = newState; | 227 | d->mData[index.row()].mIsPlaying = newState; | ||
225 | Q_EMIT dataChanged(index, index, {role}); | 228 | Q_EMIT dataChanged(index, index, {role}); | ||
226 | 229 | | |||
230 | auto after = d->mCurrentTrack.data(role); | ||||
231 | | ||||
232 | if (!d->mCurrentTrack.isValid()) { | ||||
233 | resetCurrentTrack(); | ||||
234 | } | ||||
235 | | ||||
236 | break; | ||||
237 | } | ||||
238 | case ColumnsRoles::TitleRole: | ||||
239 | { | ||||
240 | modelModified = true; | ||||
241 | d->mData[index.row()].mTitle = value; | ||||
242 | d->mTrackData[index.row()][static_cast<TrackDataType::key_type>(role)] = value; | ||||
243 | Q_EMIT dataChanged(index, index, {role}); | ||||
244 | | ||||
245 | auto test = d->mData[index.row()].mTitle; | ||||
246 | auto myNewIndex = this->index(d->mCurrentPlayListPosition,0); | ||||
247 | auto automyNewTitle = myNewIndex.data(convertedRole); | ||||
248 | auto after = d->mCurrentTrack.data(convertedRole); | ||||
249 | | ||||
250 | if (!d->mCurrentTrack.isValid()) { | ||||
251 | resetCurrentTrack(); | ||||
252 | } | ||||
253 | | ||||
254 | break; | ||||
255 | } | ||||
256 | case ColumnsRoles::ArtistRole: | ||||
257 | { | ||||
258 | modelModified = true; | ||||
259 | d->mData[index.row()].mArtist = value; | ||||
260 | d->mTrackData[index.row()][static_cast<TrackDataType::key_type>(role)] = value; | ||||
261 | Q_EMIT dataChanged(index, index, {role}); | ||||
262 | | ||||
227 | if (!d->mCurrentTrack.isValid()) { | 263 | if (!d->mCurrentTrack.isValid()) { | ||
228 | resetCurrentTrack(); | 264 | resetCurrentTrack(); | ||
229 | } | 265 | } | ||
230 | 266 | | |||
231 | break; | 267 | break; | ||
232 | } | 268 | } | ||
233 | default: | 269 | default: | ||
234 | modelModified = false; | 270 | modelModified = false; | ||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Line(s) | 419 | { | |||
409 | } | 445 | } | ||
410 | 446 | | |||
411 | Q_EMIT tracksCountChanged(); | 447 | Q_EMIT tracksCountChanged(); | ||
412 | Q_EMIT persistentStateChanged(); | 448 | Q_EMIT persistentStateChanged(); | ||
413 | 449 | | |||
414 | Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole}); | 450 | Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole}); | ||
415 | } | 451 | } | ||
416 | 452 | | |||
417 | void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries) | 453 | void MediaPlayList::enqueueTracksListById(const ElisaUtils::EntryDataList &newEntries, ElisaUtils::PlayListEntryType type) | ||
418 | { | 454 | { | ||
419 | enqueueCommon(); | 455 | enqueueCommon(); | ||
420 | 456 | | |||
421 | beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1); | 457 | beginInsertRows(QModelIndex(), d->mData.size(), d->mData.size() + newEntries.size() - 1); | ||
422 | for (const auto &newTrack : newEntries) { | 458 | for (const auto &newTrack : newEntries) { | ||
423 | auto newMediaPlayListEntry = MediaPlayListEntry{std::get<0>(newTrack), std::get<1>(newTrack), ElisaUtils::Track}; | 459 | auto newMediaPlayListEntry = MediaPlayListEntry{std::get<0>(newTrack), std::get<1>(newTrack), type}; | ||
424 | d->mData.push_back(newMediaPlayListEntry); | 460 | d->mData.push_back(newMediaPlayListEntry); | ||
425 | d->mTrackData.push_back({}); | 461 | d->mTrackData.push_back({}); | ||
426 | Q_EMIT newEntryInList(newMediaPlayListEntry.mId, newMediaPlayListEntry.mTitle.toString(), newMediaPlayListEntry.mEntryType); | 462 | Q_EMIT newEntryInList(newMediaPlayListEntry.mId, newMediaPlayListEntry.mTitle.toString(), newMediaPlayListEntry.mEntryType); | ||
427 | } | 463 | } | ||
428 | endInsertRows(); | 464 | endInsertRows(); | ||
429 | 465 | | |||
430 | restorePlayListPosition(); | 466 | restorePlayListPosition(); | ||
431 | if (!d->mCurrentTrack.isValid()) { | 467 | if (!d->mCurrentTrack.isValid()) { | ||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 544 | { | |||
549 | Q_EMIT tracksCountChanged(); | 585 | Q_EMIT tracksCountChanged(); | ||
550 | Q_EMIT persistentStateChanged(); | 586 | Q_EMIT persistentStateChanged(); | ||
551 | 587 | | |||
552 | Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole}); | 588 | Q_EMIT dataChanged(index(rowCount() - 1, 0), index(rowCount() - 1, 0), {MediaPlayList::IsPlayingRole}); | ||
553 | displayOrHideUndoInline(false); | 589 | displayOrHideUndoInline(false); | ||
554 | Q_EMIT undoClearPlayListPlayer(); | 590 | Q_EMIT undoClearPlayListPlayer(); | ||
555 | } | 591 | } | ||
556 | 592 | | |||
593 | void MediaPlayList::updateRadioData(const QVariant &value, int role) | ||||
594 | { | ||||
595 | auto convertedRole = static_cast<ColumnsRoles>(role); | ||||
596 | if(d->mCurrentTrack.data(convertedRole) != value){ | ||||
astippich: code style
if (...) { | |||||
597 | this->setData(d->mCurrentTrack, value, role); | ||||
598 | } | ||||
599 | } | ||||
600 | | ||||
557 | void MediaPlayList::enqueueCommon() | 601 | void MediaPlayList::enqueueCommon() | ||
558 | { | 602 | { | ||
559 | displayOrHideUndoInline(false); | 603 | displayOrHideUndoInline(false); | ||
560 | } | 604 | } | ||
561 | 605 | | |||
562 | void MediaPlayList::copyD() | 606 | void MediaPlayList::copyD() | ||
563 | { | 607 | { | ||
564 | dOld->mData = d->mData; | 608 | dOld->mData = d->mData; | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 647 | { | |||
611 | enqueueCommon(); | 655 | enqueueCommon(); | ||
612 | 656 | | |||
613 | switch (databaseIdType) | 657 | switch (databaseIdType) | ||
614 | { | 658 | { | ||
615 | case ElisaUtils::Album: | 659 | case ElisaUtils::Album: | ||
616 | case ElisaUtils::Artist: | 660 | case ElisaUtils::Artist: | ||
617 | case ElisaUtils::Genre: | 661 | case ElisaUtils::Genre: | ||
618 | case ElisaUtils::Track: | 662 | case ElisaUtils::Track: | ||
663 | case ElisaUtils::Radio: | ||||
619 | enqueueOneEntry(newEntry, databaseIdType); | 664 | enqueueOneEntry(newEntry, databaseIdType); | ||
620 | break; | 665 | break; | ||
621 | case ElisaUtils::FileName: | 666 | case ElisaUtils::FileName: | ||
622 | enqueueFilesList({newEntry}); | 667 | enqueueFilesList({newEntry}); | ||
623 | break; | 668 | break; | ||
624 | case ElisaUtils::Lyricist: | 669 | case ElisaUtils::Lyricist: | ||
625 | case ElisaUtils::Composer: | 670 | case ElisaUtils::Composer: | ||
626 | case ElisaUtils::Unknown: | 671 | case ElisaUtils::Unknown: | ||
Show All 25 Lines | 693 | if (enqueueMode == ElisaUtils::ReplacePlayList) { | |||
652 | clearPlayList(); | 697 | clearPlayList(); | ||
653 | } | 698 | } | ||
654 | 699 | | |||
655 | enqueueCommon(); | 700 | enqueueCommon(); | ||
656 | 701 | | |||
657 | switch (databaseIdType) | 702 | switch (databaseIdType) | ||
658 | { | 703 | { | ||
659 | case ElisaUtils::Track: | 704 | case ElisaUtils::Track: | ||
660 | enqueueTracksListById(newEntries); | 705 | case ElisaUtils::Radio: | ||
706 | enqueueTracksListById(newEntries, databaseIdType); | ||||
661 | break; | 707 | break; | ||
662 | case ElisaUtils::FileName: | 708 | case ElisaUtils::FileName: | ||
663 | enqueueFilesList(newEntries); | 709 | enqueueFilesList(newEntries); | ||
664 | break; | 710 | break; | ||
665 | case ElisaUtils::Album: | 711 | case ElisaUtils::Album: | ||
666 | case ElisaUtils::Artist: | 712 | case ElisaUtils::Artist: | ||
667 | case ElisaUtils::Genre: | 713 | case ElisaUtils::Genre: | ||
668 | enqueueMultipleEntries(newEntries, databaseIdType); | 714 | enqueueMultipleEntries(newEntries, databaseIdType); | ||
▲ Show 20 Lines • Show All 218 Lines • ▼ Show 20 Line(s) | 907 | if (oneEntry.mEntryType != ElisaUtils::Artist && oneEntry.mIsValid) { | |||
887 | Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); | 933 | Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); | ||
888 | 934 | | |||
889 | restorePlayListPosition(); | 935 | restorePlayListPosition(); | ||
890 | 936 | | |||
891 | if (!d->mCurrentTrack.isValid()) { | 937 | if (!d->mCurrentTrack.isValid()) { | ||
892 | resetCurrentTrack(); | 938 | resetCurrentTrack(); | ||
893 | } | 939 | } | ||
894 | continue; | 940 | continue; | ||
941 | } else if(oneEntry.mEntryType == ElisaUtils::Radio ){ | ||||
astippich: code style
} else if (.....) { | |||||
942 | if (track.databaseId() != oneEntry.mId) { | ||||
943 | continue; | ||||
944 | } | ||||
945 | | ||||
946 | d->mTrackData[i] = track; | ||||
947 | oneEntry.mId = track.databaseId(); | ||||
948 | oneEntry.mIsValid = true; | ||||
949 | | ||||
950 | Q_EMIT dataChanged(index(i, 0), index(i, 0), {}); | ||||
951 | | ||||
952 | restorePlayListPosition(); | ||||
953 | | ||||
954 | if (!d->mCurrentTrack.isValid()) { | ||||
955 | resetCurrentTrack(); | ||||
956 | } | ||||
957 | | ||||
958 | break; | ||||
895 | } else if (oneEntry.mEntryType != ElisaUtils::Artist && !oneEntry.mIsValid && !oneEntry.mTrackUrl.isValid()) { | 959 | } else if (oneEntry.mEntryType != ElisaUtils::Artist && !oneEntry.mIsValid && !oneEntry.mTrackUrl.isValid()) { | ||
896 | if (track.title() != oneEntry.mTitle) { | 960 | if (track.title() != oneEntry.mTitle) { | ||
897 | continue; | 961 | continue; | ||
898 | } | 962 | } | ||
899 | 963 | | |||
900 | if (track.album() != oneEntry.mAlbum) { | 964 | if (track.album() != oneEntry.mAlbum) { | ||
901 | continue; | 965 | continue; | ||
902 | } | 966 | } | ||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |
code style
if (...) {