Exemple #1
0
void
lastfm::TrackData::onGotInfo()
{
    const QByteArray data = static_cast<QNetworkReply*>(sender())->readAll();

    try
    {
        lastfm::XmlQuery lfm( data );

        QString imageUrl = lfm["track"]["image size=small"].text();
        if ( !imageUrl.isEmpty() ) m_images[lastfm::Small] = imageUrl;
        imageUrl = lfm["track"]["image size=medium"].text();
        if ( !imageUrl.isEmpty() ) m_images[lastfm::Medium] = imageUrl;
        imageUrl = lfm["track"]["image size=large"].text();
        if ( !imageUrl.isEmpty() ) m_images[lastfm::Large] = imageUrl;
        imageUrl = lfm["track"]["image size=extralarge"].text();
        if ( !imageUrl.isEmpty() ) m_images[lastfm::ExtraLarge] = imageUrl;
        imageUrl = lfm["track"]["image size=mega"].text();
        if ( !imageUrl.isEmpty() ) m_images[lastfm::Mega] = imageUrl;

        loved = lfm["track"]["userloved"].text().toInt();

        emit gotInfo( data );
        emit loveToggled( loved );
    }
    catch (...)
    {
        emit gotInfo( data );
    }

    // you should connect everytime you call getInfo
    disconnect( this, SIGNAL(gotInfo(const QByteArray&)), 0, 0);
}
void CollectionScanner::processArtist(FileInfo *file) {

    Artist *artist = new Artist();
    const QString artistTag = file->getTags()->artist;
    artist->setName(DataUtils::cleanTag(artistTag));
    artist->setProperty("originalHash", artist->getHash());

    // qDebug() << "Processing artist:" << artist->getName() << artist->getHash();

    if (filesWaitingForArtists.contains(artist->getHash())) {
        qDebug() << "ERROR Processing artist multiple times!" << artist->getName();
    }

    if (loadedArtists.contains(artist->getHash())) {
        qDebug() << "ERROR Artist already processed!" << artist->getName();
    }

    // add this file to filesWaitingForArtists
    // this also acts as a lock for other files
    // when the info is ready, all waiting files will be processed
    QList<FileInfo *> files;
    files.append(file);
    filesWaitingForArtists.insert(artist->getHash(), files);

    connect(artist, SIGNAL(gotInfo()), SLOT(gotArtistInfo()));
    artist->fetchInfo();

}
Exemple #3
0
void Album::fetchLastFmInfo() {

    /*
    if (QFile::exists(QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/albums/" + getHash())) {
        qDebug() << "Album" << name << "has a photo";
        emit gotInfo();
        return;
    } */

    if (!artist) {
        qDebug() << "Album" << name << "has no artist";
        emit gotInfo();
        return;
    }

    QUrl url("http://ws.audioscrobbler.com/2.0/");
    url.addQueryItem("method", "album.getinfo");
    url.addQueryItem("api_key", Constants::LASTFM_API_KEY);
    if (mbid.isEmpty()) {
        url.addQueryItem("artist", artist->getName());
        url.addQueryItem("album", name);
    } else {
        url.addQueryItem("mbid", mbid);
    }
    QObject *reply = The::http()->get(url);
    connect(reply, SIGNAL(data(QByteArray)), SLOT(parseLastFmInfo(QByteArray)));
    connect(reply, SIGNAL(error(QNetworkReply*)), SIGNAL(gotInfo()));

}
MainWindow::MainWindow(QWidget* parent)
	: QMainWindow{parent}, mUi{new Ui::MainWindow}
{
    mUi->setupUi(this);
    // connect
	/*connect(mUi->pbManInfoRefresh, SIGNAL(clicked()), this,
									SLOT(startStreamInfoReload()));*/ // TODO: implement this with the new weareone.fm site
	connect(mUi->pbRefreshTracklist, SIGNAL(clicked()), this,
			SLOT(startTracklistReload()));
	connect(&mInfoRealoadTimer, SIGNAL(timeout()), this,
			SLOT(startStreamInfoReload()));
    connect(&mInfoGrabber, SIGNAL(gotInfo()), this, SLOT(setupRadioTable()));
	connect(&mInfoGrabber, SIGNAL(gotTracklist()), this,
			SLOT(setupTracklistTable()));

    // get info from the website
	// startStreamInfoReload(); // TODO
	startTracklistReload();

    // player
    mPlayer.setUi(mUi);
	on_hsVolme_valueChanged(50);// set default volume

    // reload timer
	// mInfoRealoadTimer.start(600000); // TODO
}
bool UserInfoTask::take( Transfer * transfer )
{
	if ( forMe( transfer ) )
	{
		setTransfer( transfer );
		Oscar::DWORD seq = 0;
		SnacTransfer* st = dynamic_cast<SnacTransfer*>( transfer );
		if ( st )
			seq = st->snacRequest();

		if ( seq != 0 )
		{
			//AFAIK location info packets always have user info
			Buffer* b = transfer->buffer();
			UserDetails ud;
			ud.fill( b );
			m_sequenceInfoMap[seq] = ud;
			emit gotInfo( seq );

			QList<TLV> list = b->getTLVList();
			QList<TLV>::iterator it = list.begin(), itEnd = list.end();
			QString profile;
			QString away;
			for ( ; it != itEnd; ++it )
			{
				switch( ( *it ).type )
				{
				case 0x0001: //profile text encoding
					kDebug(OSCAR_RAW_DEBUG) << "text encoding is " << QString( ( *it ).data );
					break;
				case 0x0002: //profile text
					kDebug(OSCAR_RAW_DEBUG) << "The profile is '" << QString( ( *it ).data ) << "'";
					profile = QString( ( *it ).data ); // aim always seems to use us-ascii encoding
					emit receivedProfile( m_contactSequenceMap[seq], profile );
					break;
				case 0x0003: //away message encoding
					kDebug(OSCAR_RAW_DEBUG) << "Away message encoding is " << QString( ( *it ).data );
					break;
				case 0x0004: //away message
					kDebug(OSCAR_RAW_DEBUG) << "Away message is '" << QString( ( *it ).data ) << "'";
					away = QString( (*it ).data ); // aim always seems to use us-ascii encoding
					emit receivedAwayMessage( m_contactSequenceMap[seq], away );
					break;
				case 0x0005: //capabilities
					break;
				default: //unknown
					kDebug(14151) << "Unknown user info type " << ( *it ).type;
					break;
				};
			}
			list.clear();
		}
		setTransfer( 0 );
		return true;
	}
	return false;
}
Exemple #6
0
void Album::parseLastFmRedirectedName(QNetworkReply *reply) {
    QString location = reply->header(QNetworkRequest::LocationHeader).toString();
    if (!location.isEmpty()) {
        int slashIndex = location.lastIndexOf('/');
        if (slashIndex > 0) {
            name = location.mid(slashIndex);
            // qDebug() << "*** Redirected name is" << name;
            fetchLastFmSearch();
            return;
        }
    }
    emit gotInfo();
}
Exemple #7
0
void Album::parseMusicBrainzRelease(QByteArray bytes) {
    QString correctTitle = DataUtils::getXMLElementText(bytes, "title");
    mbid = DataUtils::getXMLAttributeText(bytes, "release", "id");
    qDebug() << "Album:" << name << "-> MusicBrainz ->" << correctTitle << mbid;
    if (!correctTitle.isEmpty()) {
        this->name = correctTitle;
    }

    // get a list of tracks for this album
    // fetchMusicBrainzReleaseDetails();

    // And now gently ask the Last.fm guys for some more info
    emit gotInfo();
    // fetchLastFmInfo();
}
Exemple #8
0
void Client::initializeStaticTasks()
{
	//set up the extra tasks
	Connection* c = d->connections.defaultConnection();
	if ( !c )
		return;
	d->errorTask = new ErrorTask( c->rootTask() );
	d->onlineNotifier = new OnlineNotifierTask( c->rootTask() );
	d->ownStatusTask = new OwnUserInfoTask( c->rootTask() );
	d->messageReceiverTask = new MessageReceiverTask( c->rootTask() );
	d->ssiAuthTask = new SSIAuthTask( c->rootTask() );
	d->icqInfoTask = new ICQUserInfoRequestTask( c->rootTask() );
	d->userInfoTask = new UserInfoTask( c->rootTask() );
	d->typingNotifyTask = new TypingNotifyTask( c->rootTask() );
	d->ssiModifyTask = new SSIModifyTask( c->rootTask(), true );

	connect( d->onlineNotifier, SIGNAL( userIsOnline( const QString&, const UserDetails& ) ),
	         this, SIGNAL( receivedUserInfo( const QString&, const UserDetails& ) ) );
	connect( d->onlineNotifier, SIGNAL( userIsOffline( const QString&, const UserDetails& ) ),
	         this, SLOT( offlineUser( const QString&, const UserDetails & ) ) );

	connect( d->ownStatusTask, SIGNAL( gotInfo() ), this, SLOT( haveOwnUserInfo() ) );
	connect( d->ownStatusTask, SIGNAL( buddyIconUploadRequested() ), this,
	         SIGNAL( iconNeedsUploading() ) );

	connect( d->messageReceiverTask, SIGNAL( receivedMessage( const Oscar::Message& ) ),
	         this, SLOT( receivedMessage( const Oscar::Message& ) ) );

	connect( d->ssiAuthTask, SIGNAL( authRequested( const QString&, const QString& ) ),
	         this, SIGNAL( authRequestReceived( const QString&, const QString& ) ) );
	connect( d->ssiAuthTask, SIGNAL( authReplied( const QString&, const QString&, bool ) ),
	         this, SIGNAL( authReplyReceived( const QString&, const QString&, bool ) ) );

	connect( d->icqInfoTask, SIGNAL( receivedInfoFor( const QString&, unsigned int ) ),
	         this, SLOT( receivedIcqInfo( const QString&, unsigned int ) ) );

	connect( d->userInfoTask, SIGNAL( receivedProfile( const QString&, const QString& ) ),
	         this, SIGNAL( receivedProfile( const QString&, const QString& ) ) );
	connect( d->userInfoTask, SIGNAL( receivedAwayMessage( const QString&, const QString& ) ),
	         this, SIGNAL( receivedAwayMessage( const QString&, const QString& ) ) );
	connect( d->typingNotifyTask, SIGNAL( typingStarted( const QString& ) ),
	         this, SIGNAL( userStartedTyping( const QString& ) ) );
	connect( d->typingNotifyTask, SIGNAL( typingFinished( const QString& ) ),
	         this, SIGNAL( userStoppedTyping( const QString& ) ) );
}
Exemple #9
0
void Album::parseLastFmInfo(QByteArray bytes) {
    QXmlStreamReader xml(bytes);

    while(!xml.atEnd() && !xml.hasError()) {
        QXmlStreamReader::TokenType token = xml.readNext();
        if(token == QXmlStreamReader::StartElement) {

            if(xml.name() == "image" && xml.attributes().value("size") == "extralarge") {

                // qDebug() << title << " photo:" << imageUrl;

                bool imageAlreadyPresent = false;
                QString imageLocation = QDesktopServices::storageLocation(QDesktopServices::DataLocation) + "/albums/" + getHash();
                if (QFile::exists(imageLocation)) {
                    QFileInfo imageFileInfo(imageLocation);
                    const uint imagelastModified = imageFileInfo.lastModified().toTime_t();
                    if (imagelastModified > QDateTime::currentDateTime().toTime_t() - 86400*30) {
                        imageAlreadyPresent = true;
                    }
                }

                if (!imageAlreadyPresent) {
                    QString imageUrl = xml.readElementText();
                    // qDebug() << name << " photo:" << imageUrl;
                    if (!imageUrl.isEmpty()) {
                        QUrl url = QUrl::fromEncoded(imageUrl.toUtf8());
                        QObject *reply = The::http()->get(url);
                        connect(reply, SIGNAL(data(QByteArray)), SLOT(setPhoto(QByteArray)));
                    }
                }

            }

            else if(xml.name() == "releasedate") {
                QString releasedateString = xml.readElementText().simplified();
                if (!releasedateString.isEmpty()) {
                    // Something like "6 Apr 1999, 00:00"
                    QDateTime releaseDate = QDateTime::fromString(releasedateString, "d MMM yyyy, hh:mm");
                    int releaseYear = releaseDate.date().year();
                    if (releaseYear > 0) {
                        year = releaseDate.date().year();
                    }
                    // qDebug() << name << releasedateString << releaseDate.toString();
                }
            }

            // wiki
            // TODO check at least parent element name
            else if(xml.name() == "content") {
                QString bio = xml.readElementText();
                // qDebug() << name << " got wiki";
                if (!bio.isEmpty()) {
                    // store bio
                    const QString storageLocation =
                            QDesktopServices::storageLocation(QDesktopServices::DataLocation)
                            + "/albums/wikis/";
                    QDir dir;
                    dir.mkpath(storageLocation);
                    QFile file(storageLocation + getHash());
                    if (!file.open(QIODevice::WriteOnly)) {
                        qDebug() << "Error opening file for writing" << file.fileName();
                    }
                    QTextStream stream( &file ); // we will serialize the data into the file
                    stream << bio;
                }
            }

        }

    }

    /* Error handling. */
    if(xml.hasError()) {
        qDebug() << xml.errorString();
    }

    emit gotInfo();
}
Exemple #10
0
void IrcLayer::infMsg(QString message)
{
	emit gotInfo(message);
}