<commit_before>/*
* Copyright (C) 2012 <NAME> <<EMAIL>>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "contacts-list-model.h"
#include "contact.h"

#include <TelepathyQt/Account>
#include <TelepathyQt/Contact>
#include <TelepathyQt/ContactCapabilities>
#include <TelepathyQt/Connection>
#include <TelepathyQt/ContactManager>

#include <KTp/Models/contacts-model.h>
#include <KTp/presence.h>

class KTp::ContactsListModel::Private
{
public:
    QList<Tp::ContactPtr> contacts;
    KTp::GlobalContactManager *contactManager;
};


KTp::ContactsListModel::ContactsListModel(QObject *parent) :
    QAbstractListModel(parent),
    d(new KTp::ContactsListModel::Private())
{
    d->contactManager = 0;
}

KTp::ContactsListModel::~ContactsListModel()
{
    delete d;
}

void KTp::ContactsListModel::setAccountManager(const Tp::AccountManagerPtr &accountManager)
{
    d->contactManager = new KTp::GlobalContactManager(accountManager, this);
    onContactsChanged(d->contactManager->allKnownContacts(), Tp::Contacts());
    connect(d->contactManager, SIGNAL(allKnownContactsChanged(Tp::Contacts,Tp::Contacts)), SLOT(onContactsChanged(Tp::Contacts,Tp::Contacts)));
}

int KTp::ContactsListModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED (parent);
    return d->contacts.size();
}

QVariant KTp::ContactsListModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();

    if (row >=0 && row < d->contacts.size()) {
        const KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(d->contacts[row]);

        switch (role) {
        case ContactsModel::IdRole:
            return contact->id();
        case ContactsModel::TypeRole:
            return ContactsModel::ContactRowType;
        case ContactsModel::ContactRole:
            return QVariant::fromValue(d->contacts[row]); //Tp::ContactPtr and NOT KTp::ContactPtr
        case ContactsModel::AccountRole:
            return QVariant::fromValue(d->contactManager->accountForContact(contact));
        case Qt::DisplayRole:
            return contact->alias();
        case ContactsModel::AliasRole:
            return contact->alias();
        case ContactsModel::PresenceRole:
            return QVariant::fromValue(contact->presence());
        case ContactsModel::PresenceIconRole:
            return QIcon(contact->presence().icon());
        case ContactsModel::PresenceStatusRole:
            return contact->presence().status();
        case ContactsModel::PresenceTypeRole:
            return contact->presence().type();
        case ContactsModel::PresenceMessageRole:
            return contact->presence().statusMessage();
        case ContactsModel::SubscriptionStateRole:
            return contact->subscriptionState();
        case ContactsModel::PublishStateRole:
            return contact->publishState();
        case ContactsModel::BlockedRole:
            return contact->isBlocked();
        case ContactsModel::GroupsRole:
            return contact->groups();
        case ContactsModel::AvatarRole:
            return contact->avatarData().fileName;
        case Qt::DecorationRole:
            return QImage(contact->avatarData().fileName);
        case ContactsModel::TextChatCapabilityRole:
            return contact->capabilities().textChats();
        case ContactsModel::ClientTypesRole:
            return contact->clientTypes();
        case ContactsModel::FileTransferCapabilityRole:
            return contact->fileTransferCapability();
        default:
            break;
        }

    }
    return QVariant();
}

void KTp::ContactsListModel::onContactsChanged(const Tp::Contacts &added, const Tp::Contacts &removed)
{
    //add contacts.

    Q_FOREACH(const Tp::ContactPtr &contact_uncasted, added) {
        KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(contact_uncasted);<commit_msg>Add roles for AudioCallCapability & VideoCallCapability<commit_after>/*
* Copyright (C) 2012 <NAME> <<EMAIL>>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "contacts-list-model.h"
#include "contact.h"

#include <TelepathyQt/Account>
#include <TelepathyQt/Contact>
#include <TelepathyQt/ContactCapabilities>
#include <TelepathyQt/Connection>
#include <TelepathyQt/ContactManager>

#include <KTp/Models/contacts-model.h>
#include <KTp/presence.h>

class KTp::ContactsListModel::Private
{
public:
    QList<Tp::ContactPtr> contacts;
    KTp::GlobalContactManager *contactManager;
};


KTp::ContactsListModel::ContactsListModel(QObject *parent) :
    QAbstractListModel(parent),
    d(new KTp::ContactsListModel::Private())
{
    d->contactManager = 0;
}

KTp::ContactsListModel::~ContactsListModel()
{
    delete d;
}

void KTp::ContactsListModel::setAccountManager(const Tp::AccountManagerPtr &accountManager)
{
    d->contactManager = new KTp::GlobalContactManager(accountManager, this);
    onContactsChanged(d->contactManager->allKnownContacts(), Tp::Contacts());
    connect(d->contactManager, SIGNAL(allKnownContactsChanged(Tp::Contacts,Tp::Contacts)), SLOT(onContactsChanged(Tp::Contacts,Tp::Contacts)));
}

int KTp::ContactsListModel::rowCount(const QModelIndex &parent) const
{
    Q_UNUSED (parent);
    return d->contacts.size();
}

QVariant KTp::ContactsListModel::data(const QModelIndex &index, int role) const
{
    int row = index.row();

    if (row >=0 && row < d->contacts.size()) {
        const KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(d->contacts[row]);

        switch (role) {
        case ContactsModel::IdRole:
            return contact->id();
        case ContactsModel::TypeRole:
            return ContactsModel::ContactRowType;
        case ContactsModel::ContactRole:
            return QVariant::fromValue(d->contacts[row]); //Tp::ContactPtr and NOT KTp::ContactPtr
        case ContactsModel::AccountRole:
            return QVariant::fromValue(d->contactManager->accountForContact(contact));
        case Qt::DisplayRole:
            return contact->alias();
        case ContactsModel::AliasRole:
            return contact->alias();
        case ContactsModel::PresenceRole:
            return QVariant::fromValue(contact->presence());
        case ContactsModel::PresenceIconRole:
            return QIcon(contact->presence().icon());
        case ContactsModel::PresenceStatusRole:
            return contact->presence().status();
        case ContactsModel::PresenceTypeRole:
            return contact->presence().type();
        case ContactsModel::PresenceMessageRole:
            return contact->presence().statusMessage();
        case ContactsModel::SubscriptionStateRole:
            return contact->subscriptionState();
        case ContactsModel::PublishStateRole:
            return contact->publishState();
        case ContactsModel::BlockedRole:
            return contact->isBlocked();
        case ContactsModel::GroupsRole:
            return contact->groups();
        case ContactsModel::AvatarRole:
            return contact->avatarData().fileName;
        case Qt::DecorationRole:
            return QImage(contact->avatarData().fileName);
        case ContactsModel::TextChatCapabilityRole:
            return contact->capabilities().textChats();
        case ContactsModel::ClientTypesRole:
            return contact->clientTypes();
        case ContactsModel::FileTransferCapabilityRole:
            return contact->fileTransferCapability();
        case ContactsModel::AudioCallCapabilityRole:
            return contact->audioCallCapability();
        case ContactsModel::VideoCallCapabilityRole:
            return contact->videoCallCapability();
        default:
            break;
        }

    }
    return QVariant();
}

void KTp::ContactsListModel::onContactsChanged(const Tp::Contacts &added, const Tp::Contacts &removed)
{
    //add contacts.

    Q_FOREACH(const Tp::ContactPtr &contact_uncasted, added) {
        KTp::ContactPtr contact = KTp::ContactPtr::qObjectCast(contact_uncasted);
{'fraction_non_alphanumeric': 0.11105127100387764, 'fraction_numerical': 0.004093063334769496, 'mean_word_length': 3.746932515337423, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 85, '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': '7300212', 'n_tokens_mistral': 2612, 'n_tokens_neox': 2535, 'n_words': 619}