コード例 #1
0
void PlaylistManager::insertPlaylist(const QString &uuid, PlaylistPtr playlist)
{
    Q_D(PlaylistManager);
    QString deleteID = uuid;

    d->playlists.insert(uuid, playlist);

    connect(playlist.data(), &Playlist::removed,
    this, [ = ] {
        qDebug() << "remove playlist" << deleteID << d->playlists.size();
        Q_EMIT playlistRemove(playlist);
        d->playlists.remove(uuid);
        d->sortUUIDs.removeAll(uuid);
        PlaylistMeta listmeta;
        listmeta.uuid = deleteID;

        QSqlDatabase::database().transaction();
        MediaDatabase::removePlaylist(listmeta);
        saveSortOrder();
        QSqlDatabase::database().commit();
    });

    connect(playlist.data(), &Playlist::musiclistAdded,
    this, [ = ](const MetaPtrList metalist) {
        Q_EMIT musiclistAdded(playlist, metalist);
    });

    connect(playlist.data(), &Playlist::musiclistRemoved,
    this, [ = ](const MetaPtrList metalist) {
        Q_EMIT musiclistRemoved(playlist, metalist);
    });
}
コード例 #2
0
void PlaylistManager::load()
{
    Q_D(PlaylistManager);

    for (auto &playlistmeta : MediaDatabase::instance()->allPlaylistMeta()) {
        PlaylistPtr emptylist(new Playlist(playlistmeta));
        emptylist->load();
        insertPlaylist(playlistmeta.uuid, emptylist);
    }

    QMap<uint, QString> sortUUIDs;
    for (auto playlist : d->playlists) {
        sortUUIDs.insert(playlist->sortID(), playlist->id());
    }

    QSqlDatabase::database().transaction();

    if (sortUUIDs.size() != d->playlists.size()) {
        qWarning() << "playlist order crash, restrot";
        d->sortUUIDs.clear();
        d->sortUUIDs << SearchMusicListID << AllMusicListID << FavMusicListID;

        QStringList sortUUIDs;
        for (auto playlist : d->playlists.values()) {
            sortUUIDs <<  playlist->id();
        }

        sortUUIDs.removeAll(SearchMusicListID);
        sortUUIDs.removeAll(AllMusicListID);
        sortUUIDs.removeAll(FavMusicListID);

        d->sortUUIDs << sortUUIDs;

        saveSortOrder();
    } else {
        for (auto sortID = 0; sortID < sortUUIDs.size(); ++sortID) {
            d->sortUUIDs << sortUUIDs.value(static_cast<uint>(sortID));
        }
    }

    auto all = playlist(AllMusicListID);
    auto trAllName = tr("All Music");
    if (!all.isNull() && all->displayName() != trAllName) {
        all->setDisplayName(trAllName);
    }

    auto fav = playlist(FavMusicListID);
    auto trFavName = tr("My favorites");
    if (!fav.isNull() && fav->displayName() != trFavName) {
        fav->setDisplayName(trFavName);
    }

    auto search = playlist(SearchMusicListID);
    auto searchName = tr("Search result");
    if (!search.isNull() && search->displayName() != searchName) {
        search->setDisplayName(searchName);
    }
    QSqlDatabase::database().commit();
}
コード例 #3
0
void TreeWidget::mouseReleaseEvent(QMouseEvent* event)
{
    if (d.pressedItem && isSortingBlocked()) {
        initSortOrder();
        saveSortOrder();
    }
    setSortingBlocked(false);
    d.pressedItem = 0;
    QTreeWidget::mouseReleaseEvent(event);
}
コード例 #4
0
void PlaylistManager::onCustomResort(QStringList uuids)
{
    Q_D(PlaylistManager);
    Q_ASSERT(uuids.length() == d->playlists.size() - 1);

    uuids.push_front(playlist(SearchMusicListID)->id());

    d->sortUUIDs.clear();
    for (auto sortID = 0; sortID < uuids.length(); ++sortID) {
        d->sortUUIDs << uuids.value(sortID);
    }

    QSqlDatabase::database().transaction();
    saveSortOrder();
    QSqlDatabase::database().commit();
}