void LastFmContext::readContextReply() {
    qDebug("Got reply!");
    QString replyString = QString::fromUtf8(contextReply->readAll());

    if (replyString.isEmpty()) {
        emit contextError();
        return; // Avoid empty parsing of XML
    }

    // Parametres
    QString status;
    QString artistName;
    QString artistPicture;
    QString artistSummary;
    QString artistProfile;

    QXmlQuery query;
    query.setFocus(replyString);
    query.setQuery("lfm[@status = 'ok']/count(artist)");
    query.evaluateTo(&status);
    status = status.trimmed();
    qDebug("Status: " + status.toUtf8());

    /*
     * If we got the data successfully, let's read it.
     * I hate XML.
     */
    if (status == "1") {
        query.setQuery("lfm/artist/name/text()");
        query.evaluateTo(&artistName);
        artistName = artistName.trimmed();

        query.setQuery("lfm/artist/url/text()");
        query.evaluateTo(&artistProfile);
        artistProfile = artistProfile.trimmed();

        query.setQuery("lfm/artist/image[@size=\"extralarge\"]/text()");
        query.evaluateTo(&artistPicture);
        artistPicture = artistPicture.trimmed();

        // Summary has HTML entities that must be un-replaced.
        query.setQuery("lfm/artist/bio/summary/text()");
        query.evaluateTo(&artistSummary);
        artistSummary = artistSummary.trimmed().replace("&lt;","<").replace("&gt;",">");

        // Store the context data into... contextData. Nice!
        contextData.clear();
        contextData.insert("artist", artistName);
        contextData.insert("picture", artistPicture);
        contextData.insert("summary", artistSummary);
        contextData.insert("profile", artistProfile);

        // Emit the signal
        emit contextUpdated(contextData);
    }
    else {
        qDebug("FAIL!");
        emit contextError();
    }
}
Beispiel #2
0
FlowContext::FlowContext(FlowBoard *mother, QObject *parent)
    : QObject(parent),
      m_board(mother)
{
    connect(m_board, SIGNAL(boardLoaded(int)),
            this, SLOT(initFlowContext(int)));
    connect(this, SIGNAL(contextUpdated()),
            this, SLOT(calculateRatio()));
    initFlowContext(m_board->getColorCount());
}
Beispiel #3
0
void FlowContext::addRoute(int color, PointSeries route)
{
    for (int d = 0; d < route.size(); d++) {
        QPoint dot = route[d];
        for (int c = 0; c < m_context.size(); c++) {
            for (int i = 0; i < m_context[c].size(); i++)
                if (dot == m_context[c][i])
                    m_context[c].resize(i);
            // truncate paths of all colors with intersection
        }
    }
    m_context[color] = route;
    emit contextUpdated();
}
void InputContextModule::update()
{
    emit contextUpdated();
}
Beispiel #5
0
void FlowContext::clearRouteOf(int color)
{
    m_context[color].clear();
    emit contextUpdated();
}
Beispiel #6
0
void FlowContext::initFlowContext(int color_count)
{
    m_context.clear();
    m_context.resize(color_count);
    emit contextUpdated();
}