Ejemplo n.º 1
0
void KNMusicNowPlaying::onActionBackendFinished()
{
    //Add play times on current row.
    if(playingMusicModel() && m_playingIndex.isValid())
    {
        //Add play times on the playing index.
        playingMusicModel()->addPlayingTimes(m_playingIndex);
    }
    //Set the manual playing flag to become false.
    m_manualPlayed=false;
    //If current mode is repeat the current track, then just play it again.
    if(RepeatTrack==m_loopState)
    {
        //Check the backend first.
        if(m_backend!=nullptr &&
                m_playingAnalysisItem.detailInfo.duration>0)
        {
            //Check it's URL.
            if(m_playingAnalysisItem.detailInfo.url.isEmpty())
            {
                //Replay the backend.
                m_backend->play();
            }
            else
            {
                //Simply reset the model.
                reset();
            }
        }
        //Action finished.
        return;
    }
    //Or else, play next.
    playNextRow(false);
}
Ejemplo n.º 2
0
void KNMusicNowPlaying::setPlayingRating(int rating)
{
    //Check the playing model.
    if(!m_playingIndex.isValid())
    {
        //Ignore the playing index.
        return;
    }
    //Update the detail info.
    if(playingMusicModel())
    {
        playingMusicModel()->setTextData(m_playingIndex.row(),
                                         Rating,
                                         QString::number(rating));
    }
}
Ejemplo n.º 3
0
void KNMusicNowPlaying::playMusicRow(KNMusicProxyModel *model,
                                     int row,
                                     KNMusicTab *tab)
{
    //Check the model and chech the music model of the model.
    //Clear whether the previous model is the current model.
    if(m_playingProxyModel!=model)
    {
        //Check the previous model null.
        if(playingMusicModel()!=nullptr)
        {
            //Disconnect all the monitor signals.
            m_musicModelConnections.disconnectAll();
            //Reset the previous proxy odel.
            playingMusicModel()->setPlayingIndex(QModelIndex());
        }
        //Save the new proxy model.
        m_playingProxyModel=model;
        //Emit the proxy model changed signal.
        emit nowPlayingModelChanged(m_playingProxyModel);
        //Save the music tab.
        m_playingTab=tab;
        //Check the music model first, we can only connect when its not null.
        if(playingMusicModel())
        {
            //Connect the monitor signals.
            m_musicModelConnections.append(
                    connect(playingMusicModel(),
                            &KNMusicModel::playingItemRemoved,
                            this,
                            &KNMusicNowPlaying::onActionPlayingItemRemoved));
            m_musicModelConnections.append(
                    connect(playingMusicModel(),
                            &KNMusicModel::dataChanged,
                            this,
                            &KNMusicNowPlaying::onActionModelDataChanged));
        }
    }
    //Reset the current playing index to be empty.
    m_playingIndex=QPersistentModelIndex();
    //Marked last played action is done manually, this parameter will be used in
    //playNext function for checking.
    m_manualPlayed=true;
    //Play the row.
    playRow(row);
}
Ejemplo n.º 4
0
void KNMusicNowPlaying::onActionLoadSuccess()
{
    //Clear out the cannot playing flag.
    playingMusicModel()->setData(m_playingIndex,
                                 false,
                                 CannotPlayFlagRole);
    //Give out the current.
    emit nowPlayingChanged(m_playingAnalysisItem);
}
Ejemplo n.º 5
0
void KNMusicNowPlaying::onActionLoadSuccess()
{
    //Check the model first.
    if(playingMusicModel())
    {
        //Block model signal first.
        playingMusicModel()->blockSignals(true);
        //Clear out the cannot playing flag.
        playingMusicModel()->setData(m_playingIndex,
                                     false,
                                     CannotPlayFlagRole);
        //Block model signal first.
        playingMusicModel()->blockSignals(false);
        //Give out the current.
        emit nowPlayingChanged(m_playingAnalysisItem);
    }
    //Play the backend.
    m_backend->play();
}
Ejemplo n.º 6
0
void KNMusicNowPlaying::resetCurrentPlayingModelData()
{
    //To reset the now playing, clear the backend first.
    //Check whether the backend is valid.
    if(m_backend)
    {
        //Reset the backend.
        m_backend->reset();
    }
    //Clear previous the now playing icon.
    playingMusicModel()->setPlayingIndex(QModelIndex());
    //Emit now playing reset signal.
    emit nowPlayingReset();
}
Ejemplo n.º 7
0
void KNMusicNowPlaying::onActionModelDataChanged(const QModelIndex &topLeft,
                                                 const QModelIndex &bottomRight)
{
    //Get the current row.
    int currentRow=m_playingIndex.row();
    //Check whether the current index is in the range.
    if(currentRow >= topLeft.row() && currentRow <= bottomRight.row())
    {
        //Get the new detail info.
        m_playingAnalysisItem.detailInfo=
                playingMusicModel()->rowDetailInfo(currentRow);
        //Give out the current.
        emit nowPlayingChanged(m_playingAnalysisItem);
    }
}
Ejemplo n.º 8
0
void KNMusicNowPlaying::onActionBackendFinished()
{
    //Add play times on current row.
    if(playingMusicModel() && m_playingIndex.isValid())
    {
        //Add play times on the playing index.
        playingMusicModel()->addPlayingTimes(m_playingIndex);
    }
    //Set the manual playing flag to become false.
    m_manualPlayed=false;
    //If current mode is repeat the current track, then just play it again.
    if(RepeatTrack==m_loopState)
    {
        //Check the backend first.
        if(m_backend!=nullptr)
        {
            m_backend->play();
        }
        //Action finished.
        return;
    }
    //Or else, play next.
    playNextRow(false);
}
Ejemplo n.º 9
0
void KNMusicNowPlaying::onActionLoadFailed()
{
    //Set the cannot playing flag.
    playingMusicModel()->setData(m_playingIndex,
                                 true,
                                 CannotPlayFlagRole);
    //Check if the user play flag is off, then automatically play the next song,
    //Or else we stops here, let user to do the next thing.
    if(m_manualPlayed)
    {
        //Reset the playing model data.
        resetCurrentPlayingModelData();
        //We don't need to tried continued.
        return;
    }
    //Play the next row without loop mode.
    playNextRow(true);
}
Ejemplo n.º 10
0
void KNMusicNowPlaying::onActionModelRemoved(KNMusicModel *model)
{
    //When a music model is going to be removed, check the model is being played
    //or not.
    if(model==playingMusicModel())
    {
        //We need to reset the current playing information and current playing
        //models.
        //Reset current playing first.
        reset();
        //Reset the playing models.
        m_playingProxyModel=nullptr;
        //Emit the proxy model changed signal.
        emit nowPlayingModelChanged(m_playingProxyModel);
        //Reset the shadow proxy model.
        resetShadowModel();
        //Reset the music tab pointer.
        m_playingTab=nullptr;
    }
}
Ejemplo n.º 11
0
void KNMusicNowPlaying::playRow(int proxyRow)
{
    //Assert the pre-check.
    Q_ASSERT(m_playingProxyModel!=nullptr &&
             proxyRow>-1 &&
             proxyRow<m_playingProxyModel->rowCount());
    //Get the music model.
    KNMusicModel *musicModel=playingMusicModel();
    //Get the new playing index.
    m_playingIndex=
            QPersistentModelIndex(m_playingProxyModel->mapToSource(
                                      m_playingProxyModel->index(proxyRow, 0)));
    //Set the playing index.
    musicModel->setPlayingIndex(m_playingIndex);
    //First we need to reanalysis that row, if we cannot analysis that row,
    //means we cannot play that row.
    KNMusicAnalysisItem reanalysisItem;
    //Get a copy from the music model.
    reanalysisItem.detailInfo=musicModel->rowDetailInfo(m_playingIndex.row());
    //Check the parser first, if you cannot play
    if(knMusicGlobal->parser()->reanalysisItem(reanalysisItem))
    {
        //Save the current reanlaysis item.
        m_playingAnalysisItem=reanalysisItem;
        //Get the detail info of the current playing anlaysis item.
        const KNMusicDetailInfo &detailInfo=m_playingAnalysisItem.detailInfo;
        //Update the model if the item is not an url item.
        if(detailInfo.url.isEmpty())
        {
            //Update the music model row.
            musicModel->updateRow(m_playingIndex.row(), m_playingAnalysisItem);
        }
        else
        {
            //Update the artwork from the model.
            m_playingAnalysisItem.coverImage=
                    musicModel->artwork(m_playingIndex.row()).toImage();
        }
        //Check the backend before playing, if there's no parser, do nothing.
        if(m_backend==nullptr)
        {
            //Treat this kind of features as load failed.
            onActionLoadFailed();
            //Finished.
            return;
        }
        //Play the music, according to the detail information. Check the track
        //file path is empty.
        if(!detailInfo.url.isEmpty())
        {
            //Load the url.
            ;
        }
        else if(detailInfo.trackFilePath.isEmpty())
        {
            //Load the whole file.
            m_backend->loadMusic(detailInfo.filePath);
        }
        else
        {
            //Load the whole file, and set the start position and the end
            //position via giving the duration.
            m_backend->loadMusic(detailInfo.filePath,
                                 detailInfo.startPosition,
                                 detailInfo.duration);
        }
        //Mission complete.
        return;
    }
    //Or else, this song should be failed to play, we cannot even analysis it,
    //how could we play it?.
    onActionLoadFailed();
}