コード例 #1
0
ファイル: qspotifysession.cpp プロジェクト: 2K3O/libQtSpotify
void QSpotifySession::setOfflineMode(bool on, bool forced)
{
    qDebug() << "QSpotifySession::setOfflineMode" << on << forced;
    if (m_offlineMode == on)
        return;

    m_offlineMode = on;

    if (m_offlineMode && m_currentTrack && !m_currentTrack->isAvailableOffline())
        stop();

    if (!forced) {
        settings.setValue("offlineMode", m_offlineMode);

        if (m_offlineMode)
            m_ignoreNextConnectionError = true;
    }

    m_forcedOfflineMode = forced && on;

    setConnectionRules(on ? m_connectionRules & ~AllowNetwork :
                           m_connectionRules | AllowNetwork);

    emit offlineModeChanged();
}
コード例 #2
0
ファイル: qspotifysession.cpp プロジェクト: 2K3O/libQtSpotify
void QSpotifySession::setSyncOverMobile(bool s)
{
    qDebug() << "QSpotifySession::setSyncOverMobile";
    if (m_syncOverMobile == s)
        return;

    m_syncOverMobile = s;

    settings.setValue("syncOverMobile", m_syncOverMobile);

    setConnectionRules(s ? m_connectionRules | AllowSyncOverMobile :
                          m_connectionRules & ~AllowSyncOverMobile);
    emit syncOverMobileChanged();
}
コード例 #3
0
void QSpotifySession::checkNetworkAccess()
{
  //  qDebug() << "QSpotifySession::checkNetworkAccess";
    if (!m_networkConfManager->isOnline()) {
        sp_session_set_connection_type(m_sp_session, SP_CONNECTION_TYPE_NONE);
        setOfflineMode(true, true);
    } else {
        bool wifi = false;
        bool mobile = false;
        bool roaming = false;
        QList<QNetworkConfiguration> confs = m_networkConfManager->allConfigurations(QNetworkConfiguration::Active);
        for (int i = 0; i < confs.count(); ++i) {
            QNetworkConfiguration::BearerType bearer = confs.at(i).bearerType();
            qDebug() << "Network connection type: " << confs.at(i).bearerTypeName();
            if (bearer == QNetworkConfiguration::BearerWLAN || bearer == QNetworkConfiguration::BearerEthernet) {
                wifi = true;
                break;
            } else {
                mobile = true;
            }
            if (confs.at(i).isRoamingAvailable()) {
                roaming = true;
            }
        }

        sp_connection_type type;
        if (wifi)
            type = SP_CONNECTION_TYPE_WIFI;
        else if (roaming)
            type = SP_CONNECTION_TYPE_MOBILE_ROAMING;
        else if (mobile)
            type = SP_CONNECTION_TYPE_MOBILE;
        else
            type = SP_CONNECTION_TYPE_UNKNOWN;

        sp_session_set_connection_type(m_sp_session, type);

        if (m_forcedOfflineMode)
            setOfflineMode(false, true);
        else
            setConnectionRules(m_offlineMode ? m_connectionRules & ~AllowNetwork :
                                               m_connectionRules | AllowNetwork);
    }
}
コード例 #4
0
ファイル: qspotifysession.cpp プロジェクト: 2K3O/libQtSpotify
void QSpotifySession::checkNetworkAccess()
{
    qDebug() << "QSpotifySession::checkNetworkAccess";
    if (!isOnline()) {
        sp_session_set_connection_type(m_sp_session, SP_CONNECTION_TYPE_NONE);
        setOfflineMode(true, true);
    } else {
        bool limited = m_networkingStatus->limitations().contains(ubuntu::connectivity::NetworkingStatus::Limitations::Bandwith);
        sp_connection_type type;
        if (!limited)
            type = SP_CONNECTION_TYPE_WIFI;
        else
            type = SP_CONNECTION_TYPE_MOBILE;

        sp_session_set_connection_type(m_sp_session, type);

        if (m_forcedOfflineMode)
            setOfflineMode(false, true);
        else
            setConnectionRules(m_offlineMode ? m_connectionRules & ~AllowNetwork :
                                               m_connectionRules | AllowNetwork);
    }
}
コード例 #5
0
ファイル: qspotifysession.cpp プロジェクト: 2K3O/libQtSpotify
bool QSpotifySession::event(QEvent *e)
{
    if (e->type() == NotifyMainThreadEventType) {
        qDebug() << "Process spotify event";
        processSpotifyEvents();
        e->accept();
        return true;
    } else if (e->type() == QEvent::Timer) {
        qDebug() << "Timer, start spotify events";
        QTimerEvent *te = static_cast<QTimerEvent *>(e);
        if (te->timerId() == m_timerID) {
            processSpotifyEvents();
            e->accept();
            return true;
        }
    } else if (e->type() == ConnectionErrorEventType) {
        qDebug() << "Connection error";
        QSpotifyConnectionErrorEvent *ev = static_cast<QSpotifyConnectionErrorEvent *>(e);
        setConnectionError(ConnectionError(ev->error()), QString::fromUtf8(sp_error_message(ev->error())));
        e->accept();
        return true;
    } else if (e->type() == MetaDataEventType) {
        qDebug() << "Meta data";
        emit metadataUpdated();
        e->accept();
        return true;
    } else if (e->type() == EndOfTrackEventType) {
        qDebug() << "End track";
        m_trackChangedAutomatically = true;
        playNext();
        e->accept();
        return true;
    } else if (e->type() == StopEventType) {
        qDebug() << "Stop";
        stop();
        e->accept();
        return true;
    } else if (e->type() == TrackProgressEventType) {
        qDebug() << "Track progress";
        if(!m_isPlaying) {
            e->accept();
            return true;
        }
        // Track progressed
        QSpotifyTrackProgressEvent *ev = static_cast<QSpotifyTrackProgressEvent *>(e);
        int currentTrackPositionDelta = ev->delta();
        if (m_previousTrackRemaining > 0) {
            // We're still playing the previous back from our buffer
            int fromPreviousTrack = qMin(currentTrackPositionDelta, m_previousTrackRemaining);
            currentTrackPositionDelta -= fromPreviousTrack;
            m_previousTrackRemaining -= fromPreviousTrack;
        }

        m_currentTrackPosition += currentTrackPositionDelta;
        m_currentTrackPlayedDuration += currentTrackPositionDelta;
        emit currentTrackPositionChanged();
        e->accept();
        return true;
    } else if (e->type() == SendImageRequestEventType) {
        qDebug() << "Send image request";
        QSpotifyRequestImageEvent *ev = static_cast<QSpotifyRequestImageEvent *>(e);
        sendImageRequest(ev->imageId());
        e->accept();
        return true;
    } else if (e->type() == ReceiveImageRequestEventType) {
        qDebug() << "Receive image request";
        QSpotifyReceiveImageEvent *ev = static_cast<QSpotifyReceiveImageEvent *>(e);
        receiveImageResponse(ev->image());
        e->accept();
        return true;
    } else if (e->type() == PlayTokenLostEventType) {
        qDebug() << "Play token lost";
        emit playTokenLost();
        pause();
        e->accept();
        return true;
    } else if (e->type() == LoggedInEventType) {
        qDebug() << "Logged in 1";
        onLoggedIn();
        e->accept();
        return true;
    } else if (e->type() == LoggedOutEventType) {
        qDebug() << "Logged out";
        onLoggedOut();
        e->accept();
        return true;
    } else if (e->type() == OfflineErrorEventType) {
        qDebug() << "Offline error";
        QSpotifyOfflineErrorEvent *ev = static_cast<QSpotifyOfflineErrorEvent *>(e);
        m_offlineErrorMessage = QString::fromUtf8(sp_error_message(ev->error()));
        emit offlineErrorMessageChanged();
        e->accept();
        return true;
    } else if (e->type() == ScrobbleLoginErrorEventType) {
        qDebug() << "Scrobble login error";
        m_lfmLoggedIn = false;
        emit lfmLoggedInChanged();
        emit lfmLoginError();
        e->accept();
        return true;
    } else if (e->type() == ConnectionStateUpdateEventType) {
        qDebug() << "Connectionstate update event";
        setConnectionStatus(ConnectionStatus(sp_session_connectionstate(m_sp_session)));
        if (m_offlineMode && m_connectionStatus == LoggedIn) {
            setConnectionRules(m_connectionRules | AllowNetwork);
            setConnectionRules(m_connectionRules & ~AllowNetwork);
        }
        e->accept();
        return true;
    }
    return QObject::event(e);
}