void QSpotifySession::onLoggedIn()
{
    qDebug() << "Logged in";

    if (m_user)
        return;

    m_isLoggedIn = true;
    m_user = new QSpotifyUser(sp_session_user(m_sp_session));
    m_user->init();

    setScrobble(settings.value("scrobble", false).toBool());
    lfmLogin(settings.value("lfmUser", "").toString(), settings.value("lfmPass", "").toString());

    m_pending_connectionRequest = false;
    emit pendingConnectionRequestChanged();
    emit isLoggedInChanged();
    emit userChanged();

    if(!m_uriToOpen.isEmpty()) {
        handleUri(m_uriToOpen);
        m_uriToOpen = "";
    }

    sp_session_flush_caches(m_sp_session);
    checkNetworkAccess();
    qDebug() << "Done";
}
void FavIconTest::testIconForURL()
{
    QString icon = KMimeType::favIconForUrl( KUrl( s_hostUrl ) );
    if ( icon.isEmpty() && !checkNetworkAccess() )
        QSKIP( "no network access", SkipAll );

    QCOMPARE( icon, QString( "favicons/www.google.com" ) );
}
// downloadHostIcon does nothing if the icon is available already, so how to test this?
// We could delete the icon first, but given that we have a different KDEHOME than the kded module,
// that's not really easy...
void FavIconTest::testDownloadHostIcon()
{
    if ( !checkNetworkAccess() )
        QSKIP( "no network access", SkipAll );

    QSignalSpy spy( &m_favIconModule, SIGNAL(iconChanged(bool,QString,QString)) );
    QVERIFY( spy.isValid() );
    QCOMPARE( spy.count(), 0 );

    qDebug( "called downloadHostIcon, waiting" );
    m_favIconModule.downloadHostIcon( QString( s_hostUrl ) );
    waitForSignal();

    QCOMPARE( spy.count(), 1 );
    QCOMPARE( mgr.m_isHost, true );
    QCOMPARE( mgr.m_hostOrURL, KUrl( s_hostUrl ).host() );
    qDebug( "icon: %s", qPrintable( mgr.m_iconName ) );
}
// To avoid hitting the cache, we first set the icon to s_altIconUrl (ibm.com),
// then back to s_iconUrl (kde.org) (to avoid messing up the favicons for the user ;)
void FavIconTest::testSetIconForURL()
{
    if ( !checkNetworkAccess() )
        QSKIP( "no network access", SkipAll );

    QSignalSpy spy( &m_favIconModule, SIGNAL(iconChanged(bool,QString,QString)) );
    QVERIFY( spy.isValid() );
    QCOMPARE( spy.count(), 0 );

    // The call to connect() triggers qdbus initialization stuff, while QSignalSpy doesn't...
    connect(&m_favIconModule, SIGNAL(iconChanged(bool,QString,QString)), &m_eventLoop, SLOT(quit()));

    m_favIconModule.setIconForUrl( QString( s_hostUrl ), QString( s_altIconUrl ) );

    qDebug( "called first setIconForUrl, waiting" );
    if ( spy.count() < 1 ) {
        m_eventLoop.exec( QEventLoop::ExcludeUserInputEvents );
    }

    QCOMPARE( spy.count(), 1 );
    QCOMPARE( spy[0][0].toBool(), false );
    QCOMPARE( spy[0][1].toString(), QString( s_hostUrl ) );
    QCOMPARE( spy[0][2].toString(), QString( "favicons/www.ibm.com" ) );

    m_favIconModule.setIconForUrl( QString( s_hostUrl ), QString( s_iconUrl ) );

    qDebug( "called setIconForUrl again, waiting" );
    if ( spy.count() < 2 ) {
        m_eventLoop.exec( QEventLoop::ExcludeUserInputEvents );
    }

    QCOMPARE( spy.count(), 2 );
    QCOMPARE( spy[1][0].toBool(), false );
    QCOMPARE( spy[1][1].toString(), QString( s_hostUrl ) );
    QCOMPARE( spy[1][2].toString(), QString( "favicons/www.google.com" ) );

    disconnect(&m_favIconModule, SIGNAL(iconChanged(bool,QString,QString)), &m_eventLoop, SLOT(quit()));
}
Exemple #5
0
void FavIconTest::initTestCase()
{
    QStandardPaths::setTestModeEnabled(true);

    // To avoid a runtime dependency on klauncher
    qputenv("KDE_FORK_SLAVES", "yes");
    // To let ctest exit, we shouldn't start kio_http_cache_cleaner
    qputenv("KIO_DISABLE_CACHE_CLEANER", "yes");
    // To get KJob::errorString() in English
    qputenv("LC_ALL", "en_US.UTF-8");

    if (!checkNetworkAccess()) {
        QSKIP("no network access", SkipAll);
    }

    // Ensure we start with no cache on disk
    const QString favIconCacheDir = QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation) + QStringLiteral("/favicons");
    QDir(favIconCacheDir).removeRecursively();
    QVERIFY(!QFileInfo::exists(favIconCacheDir));

    // Enable debug output
    QLoggingCategory::setFilterRules(QStringLiteral("kde.kio.favicons.debug=true"));
}
void QSpotifySession::init()
{
    memset(&m_sp_callbacks, 0, sizeof(m_sp_callbacks));
    m_sp_callbacks.logged_in = callback_logged_in;
    m_sp_callbacks.logged_out = callback_logged_out;
    m_sp_callbacks.metadata_updated = callback_metadata_updated;
    m_sp_callbacks.connection_error = callback_connection_error;
    m_sp_callbacks.notify_main_thread = callback_notify_main_thread;
    m_sp_callbacks.music_delivery = callback_music_delivery;
    m_sp_callbacks.play_token_lost = callback_play_token_lost;
    m_sp_callbacks.log_message = callback_log_message;
    m_sp_callbacks.end_of_track = callback_end_of_track;
    m_sp_callbacks.userinfo_updated = callback_userinfo_updated;
    m_sp_callbacks.offline_error = callback_offline_error;
    m_sp_callbacks.connectionstate_updated = callback_connectionstate_updated;
    m_sp_callbacks.scrobble_error = callback_scrobble_error;

    QString dpString = settings.value("dataPath").toString();
    dataPath = (char *) calloc(strlen(dpString.toLatin1()) + 1, sizeof(char));
    strcpy(dataPath, dpString.toLatin1());

    memset(&m_sp_config, 0, sizeof(m_sp_config));
    m_sp_config.api_version = SPOTIFY_API_VERSION;
    m_sp_config.cache_location = dataPath;
    m_sp_config.settings_location = dataPath;
    m_sp_config.application_key = g_appkey;
    m_sp_config.application_key_size = g_appkey_size;
    m_sp_config.user_agent = "CuteSpot";
    m_sp_config.callbacks = &m_sp_callbacks;
    sp_error error = sp_session_create(&m_sp_config, &m_sp_session);

    if (error != SP_ERROR_OK)
    {
        fprintf(stderr, "failed to create session: %s\n",
                sp_error_message(error));

        m_sp_session = nullptr;
        return;
    }
    Q_ASSERT(m_sp_session);

    sp_session_set_cache_size(m_sp_session, 0);

    // Remove stored login information from older version of MeeSpot
    if (settings.contains("username")) {
        settings.remove("username");
        settings.remove("password");
    }
    // Remove old volume information
    if (settings.contains("volume")) {
        settings.remove("volume");
    }

    m_offlineMode = settings.value("offlineMode", false).toBool();

    checkNetworkAccess();

    StreamingQuality quality = StreamingQuality(settings.value("streamingQuality", int(LowQuality)).toInt());
    setStreamingQuality(quality);

    StreamingQuality syncQuality = StreamingQuality(settings.value("syncQuality", int(HighQuality)).toInt());
    setSyncQuality(syncQuality);

    bool syncMobile = settings.value("syncOverMobile", false).toBool();
    setSyncOverMobile(syncMobile);

    QString storedLogin = getStoredLoginInformation();
    if (!storedLogin.isEmpty()) {
        login(storedLogin);
    }

    bool shuffle = settings.value("shuffle", false).toBool();
    setShuffle(shuffle);

    bool repeat = settings.value("repeat", false).toBool();
    setRepeat(repeat);

    bool repeatOne = settings.value("repeatOne", false).toBool();
    setRepeatOne(repeatOne);

    bool volumeNormalizeSet = settings.value("volumeNormalize", true).toBool();
    setVolumeNormalize(volumeNormalizeSet);

    m_lfmLoggedIn = false;

    // Flush cache regularly as we might get killed by life cycle manager / OOM killer
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(flush()));
    timer->start(60000);

    connect(this, SIGNAL(offlineModeChanged()), m_playQueue, SLOT(onOfflineModeChanged()));

    new MPRISMediaPlayer(this);
    new MPRISMediaPlayerPlayer(this);

    QDBusConnection::sessionBus().registerObject(QString("/org/mpris/MediaPlayer2"), this, QDBusConnection::ExportAdaptors);
    QDBusConnection::sessionBus().registerService("org.mpris.MediaPlayer2.CuteSpot");
}
void QSpotifySession::configurationChanged()
{
    qDebug() << "QSpotifySession::configurationChanged";
    checkNetworkAccess();
}
void QSpotifySession::onOnlineChanged()
{
    qDebug() << "QSpotifySession::onOnlineChanged";
    checkNetworkAccess();
}