Ejemplo n.º 1
0
void
CoverFetchInfoPayload::prepareUrls()
{
    KUrl url;
    CoverFetch::Metadata metadata;

    switch( m_src )
    {
    default:
    case CoverFetch::LastFm:
        url.setScheme( "http" );
        url.setHost( "ws.audioscrobbler.com" );
        url.setPath( "/2.0/" );
        url.addQueryItem( "api_key", Amarok::lastfmApiKey() );
        url.addQueryItem( "album", sanitizeQuery( album()->name() ) );

        if( album()->hasAlbumArtist() )
        {
            url.addQueryItem( "artist", sanitizeQuery( album()->albumArtist()->name() ) );
        }
        url.addQueryItem( "method", method() );

        metadata[ "source" ] = "Last.fm";
        metadata[ "method" ] = method();
        break;
    }

    if( url.isValid() )
        m_urls.insert( url, metadata );
}
Ejemplo n.º 2
0
 static KUrl findUrlForAccount( const KMail::ImapAccountBase * a ) {
   assert( a );
   const SieveConfig sieve = a->sieveConfig();
   if ( !sieve.managesieveSupported() )
     return KUrl();
   if ( sieve.reuseConfig() ) {
     // assemble Sieve url from the settings of the account:
     KUrl u;
     u.setProtocol( "sieve" );
     u.setHost( a->host() );
     u.setUser( a->login() );
     u.setPass( a->passwd() );
     u.setPort( sieve.port() );
     u.addQueryItem( "x-mech", a->auth() == "*" ? "PLAIN" : a->auth() ); //translate IMAP LOGIN to PLAIN
     if ( !a->useSSL() && !a->useTLS() )
       u.addQueryItem( "x-allow-unencrypted", "true" );
     u.setFileName( sieve.vacationFileName() );
     return u;
   } else {
     KUrl u = sieve.alternateURL();
     if ( u.protocol().toLower() == "sieve" && !a->useSSL() && !a->useTLS() && u.queryItem("x-allow-unencrypted").isEmpty() )
       u.addQueryItem( "x-allow-unencrypted", "true" );
     u.setFileName( sieve.vacationFileName() );
     return u;
   }
 }
Ejemplo n.º 3
0
PersonListJob* Provider::requestFriend(const QString& id, int page, int pageSize)
{
  KUrl url = createUrl( "friend/data/" + id );
  url.addQueryItem("page", QString::number(page));
  url.addQueryItem("pagesize", QString::number(pageSize));
  kDebug() << "URL:" << url;
  return doRequestPersonList( url );
}
Ejemplo n.º 4
0
void
CoverFetchInfoPayload::prepareDiscogsUrls( const QByteArray &data )
{
    QXmlStreamReader xml( QString::fromUtf8(data) );
    while( !xml.atEnd() && !xml.hasError() )
    {
        xml.readNext();
        if( xml.isStartElement() && xml.name() == "searchresults" )
        {
            while( !xml.atEnd() && !xml.hasError() )
            {
                xml.readNext();
                const QStringRef &n = xml.name();
                if( xml.isEndElement() && n == "searchresults" )
                    break;
                if( !xml.isStartElement() )
                    continue;
                if( n == "result" )
                {
                    while( !xml.atEnd() && !xml.hasError() )
                    {
                        xml.readNext();
                        if( xml.isEndElement() && n == "result" )
                            break;
                        if( !xml.isStartElement() )
                            continue;
                        if( xml.name() == "uri" )
                        {
                            KUrl releaseUrl( xml.readElementText() );
                            QString releaseStr = releaseUrl.url( KUrl::RemoveTrailingSlash );
                            QString releaseId = releaseStr.split( '/' ).last();

                            KUrl url;
                            url.setScheme( "http" );
                            url.setHost( "www.discogs.com" );
                            url.setPath( "/release/" + releaseId );
                            url.addQueryItem( "api_key", Amarok::discogsApiKey() );
                            url.addQueryItem( "f", "xml" );

                            CoverFetch::Metadata metadata;
                            metadata[ "source" ] = "Discogs";

                            if( url.isValid() )
                                m_urls.insert( url, metadata );
                        }
                        else
                            xml.skipCurrentElement();
                    }
                }
                else
                    xml.skipCurrentElement();
            }
        }
    }
}
Ejemplo n.º 5
0
PersonListJob* Provider::requestPersonSearchByLocation(qreal latitude, qreal longitude, qreal distance, int page, int pageSize)
{
  KUrl url = createUrl( "person/data" );
  url.addQueryItem("latitude", QString::number(latitude));
  url.addQueryItem("longitude", QString::number(longitude));
  url.addQueryItem("distance", QString::number(distance));
  url.addQueryItem("page", QString::number(page));
  url.addQueryItem("pagesize", QString::number(pageSize));
  
  qDebug() << "Location-based search:" << latitude << longitude << distance;
  qDebug() << "URL:" << url;
  return doRequestPersonList( url );
}
Ejemplo n.º 6
0
void
ArtistWidget::fetchTopTrack()
{
    // we genere the url for the demand on the lastFM Api
    KUrl url;
    url.setScheme( "http" );
    url.setHost( "ws.audioscrobbler.com" );
    url.setPath( "/2.0/" );
    url.addQueryItem( "method", "artist.getTopTracks" );
    url.addQueryItem( "api_key", Amarok::lastfmApiKey() );
    url.addQueryItem( "artist",  m_artist->name() );

    The::networkAccessManager()->getData( url, this,
         SLOT(parseTopTrack(KUrl,QByteArray,NetworkAccessManagerProxy::Error)) );
}
void
SimilarArtistsEngine::similarArtistsRequest( const QString &artistName )
{
    // we generate the url for the demand on the lastFM Api
    KUrl url;
    url.setScheme( "http" );
    url.setHost( "ws.audioscrobbler.com" );
    url.setPath( "/2.0/" );
    url.addQueryItem( "method", "artist.getSimilar" );
    url.addQueryItem( "api_key", Amarok::lastfmApiKey() );
    url.addQueryItem( "artist", artistName );
    url.addQueryItem( "limit",  QString::number( m_maxArtists ) );

    The::networkAccessManager()->getData( url, this,
         SLOT(parseSimilarArtists(KUrl,QByteArray,NetworkAccessManagerProxy::Error)) );
}
Ejemplo n.º 8
0
KUrl LaconicaSearch::buildUrl(const SearchInfo &searchInfo,
                              ChoqokId sinceStatusId, uint count, uint page)
{
    kDebug();

    QString formattedQuery;
    switch ( searchInfo.option ) {
        case ToUser:
            formattedQuery = searchInfo.query + "/replies/rss";
            break;
        case FromUser:
            formattedQuery = searchInfo.query + "/rss";
            break;
        case ReferenceGroup:
            formattedQuery = "group/" + searchInfo.query + "/rss";
            break;
        case ReferenceHashtag:
            formattedQuery = searchInfo.query;
            break;
        default:
            formattedQuery = searchInfo.query + "/rss";
            break;
    };

    KUrl url;
    TwitterApiAccount *theAccount = qobject_cast<TwitterApiAccount*>(searchInfo.account);
    Q_ASSERT(theAccount);
    if( searchInfo.option == ReferenceHashtag ) {
        url = theAccount->apiUrl();
        url.addPath("/search.atom");
        url.addQueryItem("q", formattedQuery);
        if( !sinceStatusId.isEmpty() )
            url.addQueryItem( "since_id", sinceStatusId );
        int cntStr = Choqok::BehaviorSettings::countOfPosts();
        if( count && count <= 100 )
            cntStr =  count;
        url.addQueryItem( "rpp", QString::number(cntStr) );
        if( page > 1 )
            url.addQueryItem( "page", QString::number( page ) );
    } else {
        url = theAccount->apiUrl().url(KUrl::AddTrailingSlash).remove("api/", Qt::CaseInsensitive);
        url.addPath( formattedQuery );
    }
    return url;
}
bool ImgurTalker::imageUpload(const KUrl& filePath)
{
    kDebug() << "Upload image" << filePath;
    m_currentUrl   = filePath;

    MPForm form;

    KUrl exportUrl = KUrl("http://api.imgur.com/2/upload.json");
    exportUrl.addQueryItem("key", m_apiKey);

    exportUrl.addQueryItem("name", filePath.fileName());
    exportUrl.addQueryItem("title", filePath.fileName()); // this should be replaced with something the user submits
//    exportUrl.addQueryItem("caption", ""); // this should be replaced with something the user submits

    exportUrl.addQueryItem("type", "file");

    form.addFile("image", filePath.path());
    form.finish();

    KIO::TransferJob* job = KIO::http_post(exportUrl, form.formData(), KIO::HideProgressInfo);
    job->addMetaData("content-type", form.contentType());
    job->addMetaData("content-length", QString("Content-Length: %1").arg(form.formData().length()));
    job->addMetaData("UserAgent", m_userAgent);

    connect(job, SIGNAL(data(KIO::Job*, const QByteArray&)),
            this, SLOT(slotData(KIO::Job*, const QByteArray&)));

    connect(job, SIGNAL(result(KJob*)),
            this, SLOT(slotResult(KJob*)));

    m_state = IE_ADDPHOTO;

    emit signalUploadStart(filePath);
    emit signalBusy(true);

    return true;
}
Ejemplo n.º 10
0
void KBugReportPrivate::_k_updateUrl()
{
    url = KUrl( "https://bugs.kde.org/wizard.cgi" );
    url.addQueryItem( "os", os );
    url.addQueryItem( "compiler", KDE_COMPILER_VERSION );
    url.addQueryItem( "kdeVersion", kde_version );
    url.addQueryItem( "appVersion", m_strVersion );
    url.addQueryItem( "package", appcombo->currentText() );
    url.addQueryItem( "kbugreport", "1" );
}
Ejemplo n.º 11
0
KUrl OpenSearchEngine::suggestionsUrl(const QString &searchTerm) const
{
    if (m_suggestionsUrlTemplate.isEmpty())
    {
        return KUrl();
    }

    KUrl retVal = KUrl::fromEncoded(parseTemplate(searchTerm, m_suggestionsUrlTemplate).toUtf8());

    QList<Parameter>::const_iterator i;
    for (i = m_suggestionsParameters.constBegin(); i != m_suggestionsParameters.constEnd(); ++i)
    {
        retVal.addQueryItem(i->first, parseTemplate(searchTerm, i->second));
    }
    return retVal;
}
Ejemplo n.º 12
0
void
AmpacheAccountLogin::authenticate( const KUrl &requestUrl, QByteArray data, NetworkAccessManagerProxy::Error e )
{
    if( !m_lastRequest )
        return;

    QCA::Initializer init;

    DEBUG_BLOCK
    Q_UNUSED( requestUrl );

    QDomDocument doc;
    doc.setContent( data );

    if( !generalVerify( doc, e ) )
        return;

    // so lets figure out what we got here:
    debug() << "Version reply: " << data;
    int version = getVersion( doc );

    KUrl url = getRequestUrl( "handshake" );
    QString timestamp = QString::number( QDateTime::currentDateTime().toTime_t() );
    QString passPhrase;

    // We need to use different authentication strings depending on the version of ampache
    if( version > 350000 )
    {



        debug() << "New Password Scheme " << version;
        url.addQueryItem( "version", "350001" );

        QCA::Hash sha256Hash( "sha256" );
        sha256Hash.update( m_password.toUtf8() );
        QString hashedPassword = QCA::arrayToHex( sha256Hash.final().toByteArray() );

        QString rawHandshake = timestamp + hashedPassword;
        sha256Hash.clear();
        sha256Hash.update( rawHandshake.toUtf8() );

        passPhrase = QCA::arrayToHex( sha256Hash.final().toByteArray() );

    }
Ejemplo n.º 13
0
void
CoverFetchSearchPayload::prepareUrls()
{
    KUrl url;
    url.setScheme( "http" );
    CoverFetch::Metadata metadata;

    switch( m_src )
    {
    default:
    case CoverFetch::LastFm:
        url.setHost( "ws.audioscrobbler.com" );
        url.setPath( "/2.0/" );
        url.addQueryItem( "api_key", Amarok::lastfmApiKey() );
        url.addQueryItem( "limit", QString::number( 20 ) );
        url.addQueryItem( "page", QString::number( m_page ) );
        url.addQueryItem( "album", sanitizeQuery( m_query ) );
        url.addQueryItem( "method", method() );
        metadata[ "source" ] = "Last.fm";
        metadata[ "method" ] = method();
        break;

    case CoverFetch::Discogs:
        url.setHost( "www.discogs.com" );
        url.setPath( "/search" );
        url.addQueryItem( "api_key", Amarok::discogsApiKey() );
        url.addQueryItem( "page", QString::number( m_page + 1 ) );
        url.addQueryItem( "type", "all" );
        url.addQueryItem( "q", sanitizeQuery( m_query ) );
        url.addQueryItem( "f", "xml" );
        metadata[ "source" ] = "Discogs";
        break;

    case CoverFetch::Yahoo:
        url.setHost( "boss.yahooapis.com" );
        url.setPath( "/ysearch/images/v1/" + sanitizeQuery( m_query ) );
        url.addQueryItem( "appid", Amarok::yahooBossApiKey() );
        url.addQueryItem( "count", QString::number( 20 ) );
        url.addQueryItem( "start", QString::number( 20 * m_page ) );
        url.addQueryItem( "format", "xml" );
        metadata[ "source" ] = "Yahoo!";
        break;

    case CoverFetch::Google:
        url.setHost( "images.google.com" );
        url.setPath( "/images" );
        url.addQueryItem( "q", sanitizeQuery( m_query ) );
        url.addQueryItem( "gbv", QChar( '1' ) );
        url.addQueryItem( "filter", QChar( '1' ) );
        url.addQueryItem( "start", QString::number( 20 * m_page ) );
        metadata[ "source" ] = "Google";
        break;
    }

    if( url.isValid() )
        m_urls.insert( url, metadata );
}
Ejemplo n.º 14
0
PersonListJob* Provider::requestPersonSearchByName(const QString& name)
{
  KUrl url = createUrl( "person/data");
  url.addQueryItem("name", name);
  return doRequestPersonList( url );
}
Ejemplo n.º 15
0
	void HTTPTracker::doRequest(WaitJob* wjob)
	{
		KUrl u = url;
		if (!url.isValid())
		{
			requestPending();
			QTimer::singleShot(500, this, SLOT(emitInvalidURLFailure()));
			return;
		}

		Uint16 port = ServerInterface::getPort();

		u.addQueryItem("peer_id", peer_id.toString());
		u.addQueryItem("port", QString::number(port));
		u.addQueryItem("uploaded", QString::number(bytesUploaded()));
		u.addQueryItem("downloaded", QString::number(bytesDownloaded()));

		if (event == "completed")
			u.addQueryItem("left", "0"); // need to send 0 when we are completed
		else
			u.addQueryItem("left", QString::number(tds->bytesLeft()));

		u.addQueryItem("compact", "1");
		if (event != "stopped")
			u.addQueryItem("numwant", "200");
		else
			u.addQueryItem("numwant", "0");

		u.addQueryItem("key", QString::number(key));
		QString cip = Tracker::getCustomIP();
		if (cip.isNull())
			cip = CurrentIPv6Address();
		
		if (!cip.isEmpty())
			u.addQueryItem("ip", cip);
		
		if (event.isEmpty() && supports_partial_seed_extension && tds->isPartialSeed())
			event = "paused";

		if (!event.isEmpty())
			u.addQueryItem("event", event);
		
		QString epq = u.encodedPathAndQuery();
		const SHA1Hash & info_hash = tds->infoHash();
		epq += "&info_hash=" + info_hash.toURLString();


		u.setEncodedPathAndQuery(epq);

		if (active_job)
		{
			announce_queue.append(u);
			Out(SYS_TRK | LOG_NOTICE) << "Announce ongoing, queueing announce" << endl;
		}
		else
		{
			doAnnounce(u);
			// if there is a wait job, add this job to the waitjob
			if (wjob)
				wjob->addExitOperation(new ExitJobOperation(active_job));
		}
	}
Ejemplo n.º 16
0
void
PhotosEngine::update( bool force )
{
    QString tmpYoutStr;
    // prevent
    Meta::TrackPtr currentTrack = The::engineController()->currentTrack();
    if( !currentTrack || !currentTrack->artist() )
    {
        debug() << "invalid current track";
        setData( "photos", Plasma::DataEngine::Data() );
        return;
    }
    else if( !force && currentTrack->artist()->name() == m_artist )
    {
        debug() << "artist name unchanged";
        setData( "photos", Plasma::DataEngine::Data() );
        return;
    }
    else
    {
        unsubscribeFrom( m_currentTrack );
        m_currentTrack = currentTrack;
        subscribeTo( currentTrack );

        if ( !currentTrack )
            return;

        // Save artist
        m_artist = currentTrack->artist()->name();

        removeAllData( "photos" );

        // Show the information
        if( !m_artist.isEmpty() )
        {
            setData( "photos", "message", "Fetching");
            setData( "photos", "artist", m_artist );
        }
        else
        {
            removeAllData( "photos" );
            return;
        }

        QStringList tags = m_keywords;
        tags << m_artist;
        tags.removeDuplicates();

        // Query flickr, order by relevance, 10 max
        // Flickr :http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=9c5a288116c34c17ecee37877397fe31&text=ARTIST&per_page=20
        KUrl flickrUrl;
        flickrUrl.setScheme( "http" );
        flickrUrl.setHost( "api.flickr.com" );
        flickrUrl.setPath( "/services/rest/" );
        flickrUrl.addQueryItem( "method", "flickr.photos.search" );
        flickrUrl.addQueryItem( "api_key", Amarok::flickrApiKey() );
        flickrUrl.addQueryItem( "per_page", QString::number( m_nbPhotos ) );
        flickrUrl.addQueryItem( "sort", "date-posted-desc" );
        flickrUrl.addQueryItem( "media", "photos" );
        flickrUrl.addQueryItem( "content_type", QString::number(1) );
        flickrUrl.addQueryItem( "text", tags.join(" ") );
        debug() << "Flickr url:" << flickrUrl;

        m_flickrUrls << flickrUrl;
        The::networkAccessManager()->getData( flickrUrl, this,
             SLOT(resultFlickr(KUrl,QByteArray,NetworkAccessManagerProxy::Error)) );

    }
}