<commit_before>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of contactsd.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <QtTracker/ontologies/nco.h>
#include <QtTracker/ontologies/nie.h>
#include <QtTracker/Tracker>

#include "cdtpquery.h"
#include "cdtpstorage.h"

using namespace SopranoLive;

/* --- CDTpSelectQuery --- */

CDTpSelectQuery::CDTpSelectQuery(const RDFSelect &select, QObject *parent)
    : QObject(parent)
{
    setSelect(select);
}

CDTpSelectQuery::CDTpSelectQuery(QObject *parent) : QObject(parent)
{
}

void CDTpSelectQuery::setSelect(const RDFSelect &select)
{
    mReply = ::tracker()->modelQuery(select);
    connect(mReply.model(),
            SIGNAL(modelUpdated()),
            SLOT(onModelUpdated()));
}

void CDTpSelectQuery::onModelUpdated()
{
    Q_EMIT finished(this);
    deleteLater();
}

/* --- CDTpContactsSelectQuery --- */

CDTpContactsSelectQuery::CDTpContactsSelectQuery(const QList<CDTpContactPtr> &contacts, QObject *parent)
    : CDTpSelectQuery(parent), mReplyParsed(false)
{
    setSelect(contacts);
}

CDTpContactsSelectQuery::CDTpContactsSelectQuery(const QString &accountObjectPath, QObject *parent)
    : CDTpSelectQuery(parent), mReplyParsed(false)
{
    RDFVariable imContact = RDFVariable::fromType<nco::PersonContact>();
    RDFVariable imAffiliation = imContact.property<nco::hasAffiliation>();
    RDFVariable imAddress = imAffiliation.property<nco::hasIMAddress>();
    imAddress.hasPrefix(QString("telepathy:%1").arg(accountObjectPath));

    setSelect(imContact, imAffiliation, imAddress);
}

CDTpContactsSelectQuery::CDTpContactsSelectQuery(QObject *parent)
    : CDTpSelectQuery(parent), mReplyParsed(false)
{
}

QList<CDTpContactsSelectItem> CDTpContactsSelectQuery::items()
{
    ensureParsed();
    return mItems;
}

void CDTpContactsSelectQuery::setSelect(const QList<CDTpContactPtr> &contacts)
{
    RDFVariable imContact = RDFVariable::fromType<nco::PersonContact>();
    RDFVariable imAffiliation = imContact.property<nco::hasAffiliation>();
    RDFVariable imAddress = imAffiliation.property<nco::hasIMAddress>();
    imContact.notEqual(nco::default_contact_me::iri());

    RDFVariableList members;
    Q_FOREACH (CDTpContactPtr contactWrapper, contacts) {
        members << RDFVariable(CDTpStorage::contactImAddress(contactWrapper));
    }
    imAddress.isMemberOf(members);

    setSelect(imContact, imAffiliation, imAddress);
}

void CDTpContactsSelectQuery::setSelect(const RDFVariable &imContact,
    const RDFVariable &imAffiliation, const RDFVariable &imAddress)
{
    RDFSelect select;
    select.addColumn("contact", imContact);
    select.addColumn("affiliation", imAffiliation);
    select.addColumn("address", imAddress);
    select.addColumn("generator", imContact.property<nie::generator>());
    select.addColumn("localUID", imContact.property<nco::contactLocalUID>());

    CDTpSelectQuery::setSelect(select);
}

void CDTpContactsSelectQuery::ensureParsed()
{
    if (mReplyParsed) {
        return;
    }

    LiveNodes result = reply();
    for (int i = 0; i < result->rowCount(); i++) {
        CDTpContactsSelectItem item;
        item.imContact     = result->index(i, 0).data().toString();
        item.imAffiliation = result->index(i, 1).data().toString();
        item.imAddress     = result->index(i, 2).data().toString();
        item.generator     = result->index(i, 3).data().toString();
        item.localUID      = result->index(i, 4).data().toString();

        mItems << item;
    }

    mReplyParsed = true;
}

/* --- CDTpAccountContactsSelectQuery --- */
<commit_msg>Changes: generator is optional, me-contact does not have it<commit_after>/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (<EMAIL>)
**
** This file is part of contactsd.
**
** If you have questions regarding the use of this file, please contact
** Nokia at <EMAIL>.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include <QtTracker/ontologies/nco.h>
#include <QtTracker/ontologies/nie.h>
#include <QtTracker/Tracker>

#include "cdtpquery.h"
#include "cdtpstorage.h"

using namespace SopranoLive;

/* --- CDTpSelectQuery --- */

CDTpSelectQuery::CDTpSelectQuery(const RDFSelect &select, QObject *parent)
    : QObject(parent)
{
    setSelect(select);
}

CDTpSelectQuery::CDTpSelectQuery(QObject *parent) : QObject(parent)
{
}

void CDTpSelectQuery::setSelect(const RDFSelect &select)
{
    mReply = ::tracker()->modelQuery(select);
    connect(mReply.model(),
            SIGNAL(modelUpdated()),
            SLOT(onModelUpdated()));
}

void CDTpSelectQuery::onModelUpdated()
{
    Q_EMIT finished(this);
    deleteLater();
}

/* --- CDTpContactsSelectQuery --- */

CDTpContactsSelectQuery::CDTpContactsSelectQuery(const QList<CDTpContactPtr> &contacts, QObject *parent)
    : CDTpSelectQuery(parent), mReplyParsed(false)
{
    setSelect(contacts);
}

CDTpContactsSelectQuery::CDTpContactsSelectQuery(const QString &accountObjectPath, QObject *parent)
    : CDTpSelectQuery(parent), mReplyParsed(false)
{
    RDFVariable imContact = RDFVariable::fromType<nco::PersonContact>();
    RDFVariable imAffiliation = imContact.property<nco::hasAffiliation>();
    RDFVariable imAddress = imAffiliation.property<nco::hasIMAddress>();
    imAddress.hasPrefix(QString("telepathy:%1").arg(accountObjectPath));

    setSelect(imContact, imAffiliation, imAddress);
}

CDTpContactsSelectQuery::CDTpContactsSelectQuery(QObject *parent)
    : CDTpSelectQuery(parent), mReplyParsed(false)
{
}

QList<CDTpContactsSelectItem> CDTpContactsSelectQuery::items()
{
    ensureParsed();
    return mItems;
}

void CDTpContactsSelectQuery::setSelect(const QList<CDTpContactPtr> &contacts)
{
    RDFVariable imContact = RDFVariable::fromType<nco::PersonContact>();
    RDFVariable imAffiliation = imContact.property<nco::hasAffiliation>();
    RDFVariable imAddress = imAffiliation.property<nco::hasIMAddress>();
    imContact.notEqual(nco::default_contact_me::iri());

    RDFVariableList members;
    Q_FOREACH (CDTpContactPtr contactWrapper, contacts) {
        members << RDFVariable(CDTpStorage::contactImAddress(contactWrapper));
    }
    imAddress.isMemberOf(members);

    setSelect(imContact, imAffiliation, imAddress);
}

void CDTpContactsSelectQuery::setSelect(const RDFVariable &imContact,
    const RDFVariable &imAffiliation, const RDFVariable &imAddress)
{
    RDFSelect select;
    select.addColumn("contact", imContact);
    select.addColumn("affiliation", imAffiliation);
    select.addColumn("address", imAddress);
    select.addColumn("generator", imContact.optional().property<nie::generator>());
    select.addColumn("localUID", imContact.property<nco::contactLocalUID>());

    CDTpSelectQuery::setSelect(select);
}

void CDTpContactsSelectQuery::ensureParsed()
{
    if (mReplyParsed) {
        return;
    }

    LiveNodes result = reply();
    for (int i = 0; i < result->rowCount(); i++) {
        CDTpContactsSelectItem item;
        item.imContact     = result->index(i, 0).data().toString();
        item.imAffiliation = result->index(i, 1).data().toString();
        item.imAddress     = result->index(i, 2).data().toString();
        item.generator     = result->index(i, 3).data().toString();
        item.localUID      = result->index(i, 4).data().toString();

        mItems << item;
    }

    mReplyParsed = true;
}

/* --- CDTpAccountContactsSelectQuery --- */

{'fraction_non_alphanumeric': 0.16296999169730755, 'fraction_numerical': 0.0030838571936899536, 'mean_word_length': 4.95059985885674, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2623569', 'n_tokens_mistral': 2615, 'n_tokens_neox': 2472, 'n_words': 494}