Example #1
0
void FileHandler::share(QString name, QString body)
{
    // tell tracker about the file before it's created
    QString queryStr = "INSERT { _:1 a nfo:FileDataObject, nfo:TextDocument ; "
            "nie:mimeType \"text/plain\" ; "
            "nie:url ?:path ; "
            "nie:byteSize ?:size ."
            "}";

    m_path = SAVEDIR_PATH + name;
    // QFileInfo fileInfo(file);
    // m_path = "file://" + fileInfo.canonicalFilePath();

    QSparqlQuery query (queryStr, QSparqlQuery::InsertStatement);
    query.bindValue ("path", "file://" + m_path);
    query.bindValue ("size", body.size());
    qDebug() << query.preparedQueryText();

    QSparqlConnection connection("QTRACKER_DIRECT");
    if (!connection.isValid()) {
        qDebug() << "Invalid tracker connection";
        return;
    }

    QSparqlResult* result = connection.syncExec(query);
    if (result->hasError()) {
        qDebug() << "Query error";
        qDebug() << result->lastError();
    }

    save(name, body);
    startShareUi();
}
int FaceDatabaseProvider::countImages(QList<XQFaceRegion> regions)
{
    QString sparqlSentence("SELECT\n"
                           "  COUNT(?urn)\n"
                           "WHERE {\n"
                           "  ?urn rdf:type nfo:Visual ;\n"
                           "       tracker:available \"true\"^^xsd:boolean .\n"
                           "  FILTER(?urn IN (%1) ).\n"
                           "}\n");
    QString urnList;
    QListIterator<XQFaceRegion> iter(regions);
    while (iter.hasNext()) {
        urnList += "<" + iter.next().sourceId() + ">";
        if (iter.hasNext()) {
            urnList += " , ";
        }
    }
    QSparqlQuery query = QSparqlQuery(sparqlSentence.arg(urnList));

    int count = 0;
    QSparqlResult *result = m_sparqlConnection->syncExec(query);
    if (!result->hasError() && result->first()) {
        count = result->value(0).toInt();
    }

    delete result;

    return count;
}
QStringList FaceDatabaseProvider::resolveContact(QString &contactUrn)
{
    static QSparqlQuery query("SELECT\n"
                              " tracker:coalesce(fn:concat(nco:nameGiven(?:contact), \" \",\n"
                              "                            nco:nameFamily(?:contact)),\n"
                              "                            nco:nameGiven(?:contact),\n"
                              "                            nco:nickname(?:contact),\n"
                              "                            nco:nameFamily(?:contact),\n"
                              "                            nco:fullname(?:contact)\n"
                              "                  )\n"
                              " ?photoUrl \n"
                              "WHERE {\n"
                              " ?:contact rdf:type nco:PersonContact .\n"
                              " OPTIONAL {\n"
                              "     ?:contact nco:photo ?photoUrn .\n"
                              "     ?photoUrn nie:url ?photoUrl .\n"
                              " }\n"
                              "}\n");

    query.bindValue("contact", QUrl(contactUrn));
    QSparqlResult *result = m_sparqlConnection->syncExec(query);
    if (result->hasError() || !result->first()) {
        delete result;
        return QStringList();
    } else {
        QStringList stringResult;
        stringResult << result->value(0).toString() << result->value(1).toString();
        delete result;
        return stringResult;
    }
}
void TrackerDocumentProvider::searchFinished()
{
    QSparqlResult *r = qobject_cast<QSparqlResult*>(sender());
    if (!r->hasError()) {
        // d->model->clear();
        // Mark all current entries in the model dirty.
        d->model->setAllItemsDirty(true);
        while (r->next()) {
            // This will remove the dirty flag for already
            // existing entries.
            d->model->addItem(
                r->binding(0).value().toString(),
                r->binding(1).value().toString(),
                r->binding(1).value().toString().split('.').last(),
                r->binding(2).value().toInt(),
                r->binding(3).value().toDateTime(),
                r->binding(4).value().toString()
            );
        }
        // Remove all entries with the dirty mark.
        d->model->removeItemsDirty();
        if (!d->ready) {
            d->ready = true;
            emit readyChanged();
        }
    }

    emit countChanged();
}
Example #5
0
void PlaylistModel::onQueryFinished()
{
    QSparqlResult *result = static_cast<QSparqlResult*>(sender());

    if (result->size() > 0) {
        result->next();
        QSparqlResultRow row(result->current());

        PlaylistTrack *track = m_tracks.at(result->property("trackIndex").toInt());

        track->title = row.value("title").toString();
        track->duration = row.value("duration").toLongLong();

        QVariant artist(row.value("artist"));
        if (artist.isValid()) {
            track->artist = artist.toString();
        } else {
            track->artist = tr("Unknown artist");
            track->unknownArtist = true;
        }

        QVariant album(row.value("album"));
        if (album.isValid()) {
            track->album = album.toString();
        } else {
            track->album = tr("Unknown album");
            track->unknownAlbum = true;
        }
    }

    m_loadedTracks++;

    if (m_loadedTracks == m_tracks.size()) {
        m_loaded = true;
        emit loadedChanged();

        beginResetModel();
        m_rowCount = m_tracks.size();
        endResetModel();

        qDeleteAll(m_queries);
        m_queries.clear();
    }
}
Example #6
0
void PlaylistModel::componentComplete()
{
    QStringList tracksList(PlaylistUtils::parsePlaylist(m_url));

    if (tracksList.isEmpty()) {
        m_loaded = true;
        emit loadedChanged();
    } else {
        QSparqlConnection *connection = new QSparqlConnection("QTRACKER_DIRECT", QSparqlConnectionOptions(), this);

        for (int i = 0, max = tracksList.size(); i < max; i++) {
            QString url(tracksList.at(i));
            m_tracks.append(new PlaylistTrack(url));

            QSparqlResult *result = connection->exec(QSparqlQuery(PlaylistUtils::trackSparqlQuery(url),
                                                                  QSparqlQuery::SelectStatement));
            result->setProperty("trackIndex", i);
            connect(result, &QSparqlResult::finished, this, &PlaylistModel::onQueryFinished);
            m_queries.append(result);
        }
    }
}