<commit_before>/* * This file is part of qtcontacts-tracker
 * Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
 * Contact: <NAME> <<EMAIL>>
 * This software, including documentation, is protected by copyright controlled by
 * Nokia Corporation. All rights are reserved. Copying, including reproducing, storing,
 * adapting or translating, any or all of this material requires the prior written consent
 * of Nokia Corporation. This material also contains confidential information which may
 * not be disclosed to others without the prior written consent of Nokia.
 */

#include "tracker2qcontact.h"

#include <qcontact.h>
#include <qcontactdetails.h>

#include <QtTracker/ontologies/nco.h>

using namespace SopranoLive;

/**
   QContactPhoneNumber subtypes
 */
void setSubType(Live<nco::PhoneNumber> ncoPhone, QContactPhoneNumber& detail)
{
    //TODO pick one
    // AttributeSubTypeLandline;
    // AttributeSubTypeMobile;
    // AttributeSubTypeFacsimile;
    // AttributeSubTypePager;
    // AttributeSubTypeVoice;
    // AttributeSubTypeModem;
    // AttributeSubTypeVideo;
    // AttributeSubTypeCar;
    // AttributeSubTypeBulletinBoardSystem;
    // AttributeSubTypeMessagingCapable;

    // BUG: hasType is currently not working which means all numbers will be voice numbers.
    if( ncoPhone.hasType<nco::CellPhoneNumber>() ) {
        detail.setAttribute(QContactPhoneNumber::AttributeSubType, QContactPhoneNumber::AttributeSubTypeMobile);
    } else if ( not ncoPhone.hasType<nco::VoicePhoneNumber>() ) {
        // if it is not a voice number then no attributes are set
    } else {
        detail.setAttribute(QContactPhoneNumber::AttributeSubType, QContactPhoneNumber::AttributeSubTypeVoice);
    }
}

/**
   QContactAddress subtypes
 */
void setSubType(Live<nco::PostalAddress> ncoPostalAddress, QContactAddress& detail)
{
    //TODO pick one
    // AttributeSubTypeParcel;
    // AttributeSubTypePostal;
    // AttributeSubTypeDomestic;
    // AttributeSubTypeInternational;

    if( ncoPostalAddress.hasType<nco::PostalAddress>() ) {
        detail.setAttribute(QContactAddress::AttributeSubType, QContactAddress::AttributeSubTypePostal);
    } else {
        detail.setAttribute(QContactAddress::AttributeSubType, QContactAddress::AttributeSubTypeDomestic);
    }
}

/**
   QContactName subtypes
 */
void setSubType(Live<nco::PersonContact> ncoPersonContact, QContactName& detail)
{
    //TODO: No subtypes specified in qcontactname
    Q_UNUSED( ncoPersonContact );
    Q_UNUSED( detail );
}

/**
   QContactEmailAddress subtypes
*/
void setSubType(Live<nco::EmailAddress> ncoEmail, QContactEmailAddress& detail)
{
    //TODO pick one
    // AttributeSubTypeParcel;
    // AttributeSubTypePostal;
    // AttributeSubTypeDomestic;
    // AttributeSubTypeInternational;

    if( ncoEmail.hasType<nco::EmailAddress>() ) {
        detail.setAttribute(QContactEmailAddress::AttributeSubType, QContactEmailAddress::AttributeSubTypeInternet);
    }
}

void setSubType(Live<nfo::FileDataObject> fdo, QContactAvatar& detail)
{
    Q_UNUSED( fdo );
    detail.setAttribute(QContactAvatar::AttributeSubType, QContactAvatar::AttributeSubTypeImage);
}

/**
   Copy nco::PersonContact -> QContactName
*/
void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactName& name)
{
    name.setPrefix     ( ncoContact->getNameHonorificPrefix() );
    name.setFirst      ( ncoContact->getNameGiven() );
    name.setMiddle     ( ncoContact->getNameAdditional() );
    name.setLast       ( ncoContact->getNameFamily() );
    name.setSuffix     ( ncoContact->getNameHonorificSuffix() );
    setSubType( ncoContact, name );
}

/**
   Copy nco::PostalAddress -> QContactAddress
 */
void copyDetailData(const Live<nco::PostalAddress>& ncoPostalAddress, QContactAddress& address)
{
    //address.setDisplayLabel ("");
    address.setStreet       ( ncoPostalAddress->getStreetAddress() );
    address.setLocality     ( ncoPostalAddress->getLocality() );
    address.setRegion       ( ncoPostalAddress->getRegion() );
    address.setPostcode     ( ncoPostalAddress->getPostalcode() );
    address.setCountry      ( ncoPostalAddress->getCountry() );
    setSubType( ncoPostalAddress, address );
}

/**
   Copy nco::PhoneNumber -> QContactPhoneNumber
 */
void copyDetailData(const Live<nco::PhoneNumber>& ncoPhoneNumber, QContactPhoneNumber& detail)
{
    detail.setNumber (ncoPhoneNumber->getPhoneNumber());
    setSubType(ncoPhoneNumber, detail);
}

/**
   Copy nco::EmailAddress -> QContactEmailAddress
 */
void copyDetailData(const Live<nco::EmailAddress>& ncoEmail, QContactEmailAddress& detail)
{
    detail.setEmailAddress (ncoEmail->getEmailAddress());
    setSubType(ncoEmail, detail);
}

void copyDetailData(const Live<nfo::FileDataObject>& fdo, QContactAvatar& detail)
{
    if( fdo != 0 ) {
        QUrl url = fdo.toString();
        detail.setAvatar (url.toString());
        setSubType( fdo, detail );
    }
}

void copyDetailData(const Live< rdfs::Resource >& url, QContactUrl& detail)
{
    detail.setUrl(url.toString());
}

/*
void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactAnniversary& detail)
{
    Q_UNUSED(ncoContact);
    Q_UNUSED(detail);
    //detail.setDate (QDate());
}
*/

void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactGender& detail)
{
    Q_UNUSED(ncoContact);
    Q_UNUSED(detail);
    const Live< nfo::Gender > gender = ncoContact->getGender();
    detail.setGender(gender.toString());
}

/*
void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactBirthday& detail)
{
    detail.setDate (QDate());
}


void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactGuid& detail)
{
    detail.setGuid (QString());
}

void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactSyncTarget& detail)
{
    detail.setSyncTarget (QString());
}

void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactUrl& detail)
{
    detail.setUrl (QString());
}
*/

bool Tracker2QContact::copyContactData(const Live<nco::PersonContact>& ncoContact, QContact& qcontact )
{
    bool ok;
    QUniqueId id = QString(ncoContact->getContactUID()).toUInt(&ok);
    if( not ok ) {
        qWarning() << "Could not convert id to number";
        return false;
    }
    qcontact.setId(id);

    QContactName detail;
    copyDetailData(ncoContact, detail);
    qcontact.saveDetail(&detail);

    LiveNodes addresses = ncoContact->getHasPostalAddresss(); //Home addresses
    foreach( const Live<nco::PostalAddress>& address, addresses ) {
        QContactAddress detail;
        copyDetailData(address, detail);
        detail.setAttribute(QContactAddress::AttributeContext, QContactAddress::AttributeContextHome);
        qcontact.saveDetail(&detail);
    }

    LiveNodes phoneNumbers = ncoContact->getHasPhoneNumbers(); //Home phone numbers
    foreach( const Live<nco::PhoneNumber>& phoneNumber, phoneNumbers) {
        QContactPhoneNumber detail;
        copyDetailData(phoneNumber, detail);
        detail.setAttribute(QContactPhoneNumber::AttributeContext, QContactPhoneNumber::AttributeContextHome);
        qcontact.saveDetail(&detail);
    }

    LiveNodes emailAddresses = ncoContact->getHasEmailAddresss(); //Home email addresses
    foreach( const Live<nco::EmailAddress>& ncoEmail, emailAddresses) {
        QContactEmailAddress detail;
        copyDetailData(ncoEmail, detail);
        detail.setAttribute(QContactEmailAddress::AttributeContext, QContactEmailAddress::AttributeContextHome);
        detail.setAttribute(QContactEmailAddress::AttributeSubType, QContactEmailAddress::AttributeSubTypeInternet);
        qcontact.saveDetail(&detail);
    }

    foreach( Live<nfo::FileDataObject> fdo, ncoContact->getPhotos() ) { //Home avatars
        if( fdo != 0 ) {
            QContactAvatar detail;
            copyDetailData(fdo, detail);
            detail.setAttribute(QContactAvatar::AttributeContext, QContactAvatar::AttributeContextHome);
            qcontact.saveDetail(&detail);
        }
    }

    LiveNodes imAccounts = ncoContact->getHasIMAccounts();
    foreach (const Live<nco::IMAccount>& imAccount, imAccounts) {
        // TODo replace when QtMobility guys implement support for IMAccount
        QContactOnlineAccount account;;
        account.setValue("Account", imAccount->getImID());
        account.setValue("ServiceName", imAccount->getImAccountType());
        qcontact.saveDetail(&account);
        QContactPresence presence;
        presence.setValue(QContactPresence::FieldNickname, imAccount->getImNickname());
        presence.setValue(QContactPresence::FieldPresence, imAccount->getImStatus());
        presence.setValue(QContactPresence::FieldStatusMessage, imAccount->getImStatusMessage());
        qcontact.saveDetail(&presence);

    }

    foreach( Live< rdfs::Resource > url, ncoContact->getUrls() ) { //Home homepage urls
        QContactUrl detail;
        copyDetailData(url, detail);<commit_msg>Present status message on contact card, some old implementation i forgot to commit<commit_after>/* * This file is part of qtcontacts-tracker
 * Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
 * Contact: <NAME> <<EMAIL>>
 * This software, including documentation, is protected by copyright controlled by
 * Nokia Corporation. All rights are reserved. Copying, including reproducing, storing,
 * adapting or translating, any or all of this material requires the prior written consent
 * of Nokia Corporation. This material also contains confidential information which may
 * not be disclosed to others without the prior written consent of Nokia.
 */

#include "tracker2qcontact.h"

#include <qcontact.h>
#include <qcontactdetails.h>

#include <QtTracker/ontologies/nco.h>

using namespace SopranoLive;

/**
   QContactPhoneNumber subtypes
 */
void setSubType(Live<nco::PhoneNumber> ncoPhone, QContactPhoneNumber& detail)
{
    //TODO pick one
    // AttributeSubTypeLandline;
    // AttributeSubTypeMobile;
    // AttributeSubTypeFacsimile;
    // AttributeSubTypePager;
    // AttributeSubTypeVoice;
    // AttributeSubTypeModem;
    // AttributeSubTypeVideo;
    // AttributeSubTypeCar;
    // AttributeSubTypeBulletinBoardSystem;
    // AttributeSubTypeMessagingCapable;

    // BUG: hasType is currently not working which means all numbers will be voice numbers.
    if( ncoPhone.hasType<nco::CellPhoneNumber>() ) {
        detail.setAttribute(QContactPhoneNumber::AttributeSubType, QContactPhoneNumber::AttributeSubTypeMobile);
    } else if ( not ncoPhone.hasType<nco::VoicePhoneNumber>() ) {
        // if it is not a voice number then no attributes are set
    } else {
        detail.setAttribute(QContactPhoneNumber::AttributeSubType, QContactPhoneNumber::AttributeSubTypeVoice);
    }
}

/**
   QContactAddress subtypes
 */
void setSubType(Live<nco::PostalAddress> ncoPostalAddress, QContactAddress& detail)
{
    //TODO pick one
    // AttributeSubTypeParcel;
    // AttributeSubTypePostal;
    // AttributeSubTypeDomestic;
    // AttributeSubTypeInternational;

    if( ncoPostalAddress.hasType<nco::PostalAddress>() ) {
        detail.setAttribute(QContactAddress::AttributeSubType, QContactAddress::AttributeSubTypePostal);
    } else {
        detail.setAttribute(QContactAddress::AttributeSubType, QContactAddress::AttributeSubTypeDomestic);
    }
}

/**
   QContactName subtypes
 */
void setSubType(Live<nco::PersonContact> ncoPersonContact, QContactName& detail)
{
    //TODO: No subtypes specified in qcontactname
    Q_UNUSED( ncoPersonContact );
    Q_UNUSED( detail );
}

/**
   QContactEmailAddress subtypes
*/
void setSubType(Live<nco::EmailAddress> ncoEmail, QContactEmailAddress& detail)
{
    //TODO pick one
    // AttributeSubTypeParcel;
    // AttributeSubTypePostal;
    // AttributeSubTypeDomestic;
    // AttributeSubTypeInternational;

    if( ncoEmail.hasType<nco::EmailAddress>() ) {
        detail.setAttribute(QContactEmailAddress::AttributeSubType, QContactEmailAddress::AttributeSubTypeInternet);
    }
}

void setSubType(Live<nfo::FileDataObject> fdo, QContactAvatar& detail)
{
    Q_UNUSED( fdo );
    detail.setAttribute(QContactAvatar::AttributeSubType, QContactAvatar::AttributeSubTypeImage);
}

/**
   Copy nco::PersonContact -> QContactName
*/
void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactName& name)
{
    name.setPrefix     ( ncoContact->getNameHonorificPrefix() );
    name.setFirst      ( ncoContact->getNameGiven() );
    name.setMiddle     ( ncoContact->getNameAdditional() );
    name.setLast       ( ncoContact->getNameFamily() );
    name.setSuffix     ( ncoContact->getNameHonorificSuffix() );
    setSubType( ncoContact, name );
}

/**
   Copy nco::PostalAddress -> QContactAddress
 */
void copyDetailData(const Live<nco::PostalAddress>& ncoPostalAddress, QContactAddress& address)
{
    //address.setDisplayLabel ("");
    address.setStreet       ( ncoPostalAddress->getStreetAddress() );
    address.setLocality     ( ncoPostalAddress->getLocality() );
    address.setRegion       ( ncoPostalAddress->getRegion() );
    address.setPostcode     ( ncoPostalAddress->getPostalcode() );
    address.setCountry      ( ncoPostalAddress->getCountry() );
    setSubType( ncoPostalAddress, address );
}

/**
   Copy nco::PhoneNumber -> QContactPhoneNumber
 */
void copyDetailData(const Live<nco::PhoneNumber>& ncoPhoneNumber, QContactPhoneNumber& detail)
{
    detail.setNumber (ncoPhoneNumber->getPhoneNumber());
    setSubType(ncoPhoneNumber, detail);
}

/**
   Copy nco::EmailAddress -> QContactEmailAddress
 */
void copyDetailData(const Live<nco::EmailAddress>& ncoEmail, QContactEmailAddress& detail)
{
    detail.setEmailAddress (ncoEmail->getEmailAddress());
    setSubType(ncoEmail, detail);
}

void copyDetailData(const Live<nfo::FileDataObject>& fdo, QContactAvatar& detail)
{
    if( fdo != 0 ) {
        QUrl url = fdo.toString();
        detail.setAvatar (url.toString());
        setSubType( fdo, detail );
    }
}

void copyDetailData(const Live< rdfs::Resource >& url, QContactUrl& detail)
{
    detail.setUrl(url.toString());
}

/*
void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactAnniversary& detail)
{
    Q_UNUSED(ncoContact);
    Q_UNUSED(detail);
    //detail.setDate (QDate());
}
*/

void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactGender& detail)
{
    Q_UNUSED(ncoContact);
    Q_UNUSED(detail);
    const Live< nfo::Gender > gender = ncoContact->getGender();
    detail.setGender(gender.toString());
}

/*
void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactBirthday& detail)
{
    detail.setDate (QDate());
}


void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactGuid& detail)
{
    detail.setGuid (QString());
}

void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactSyncTarget& detail)
{
    detail.setSyncTarget (QString());
}

void copyDetailData(const Live<nco::PersonContact>& ncoContact, QContactUrl& detail)
{
    detail.setUrl (QString());
}
*/

bool Tracker2QContact::copyContactData(const Live<nco::PersonContact>& ncoContact, QContact& qcontact )
{
    bool ok;
    QUniqueId id = QString(ncoContact->getContactUID()).toUInt(&ok);
    if( not ok ) {
        qWarning() << "Could not convert id to number";
        return false;
    }
    qcontact.setId(id);

    QContactName detail;
    copyDetailData(ncoContact, detail);
    qcontact.saveDetail(&detail);

    LiveNodes addresses = ncoContact->getHasPostalAddresss(); //Home addresses
    foreach( const Live<nco::PostalAddress>& address, addresses ) {
        QContactAddress detail;
        copyDetailData(address, detail);
        detail.setAttribute(QContactAddress::AttributeContext, QContactAddress::AttributeContextHome);
        qcontact.saveDetail(&detail);
    }

    LiveNodes phoneNumbers = ncoContact->getHasPhoneNumbers(); //Home phone numbers
    foreach( const Live<nco::PhoneNumber>& phoneNumber, phoneNumbers) {
        QContactPhoneNumber detail;
        copyDetailData(phoneNumber, detail);
        detail.setAttribute(QContactPhoneNumber::AttributeContext, QContactPhoneNumber::AttributeContextHome);
        qcontact.saveDetail(&detail);
    }

    LiveNodes emailAddresses = ncoContact->getHasEmailAddresss(); //Home email addresses
    foreach( const Live<nco::EmailAddress>& ncoEmail, emailAddresses) {
        QContactEmailAddress detail;
        copyDetailData(ncoEmail, detail);
        detail.setAttribute(QContactEmailAddress::AttributeContext, QContactEmailAddress::AttributeContextHome);
        detail.setAttribute(QContactEmailAddress::AttributeSubType, QContactEmailAddress::AttributeSubTypeInternet);
        qcontact.saveDetail(&detail);
    }

    foreach( Live<nfo::FileDataObject> fdo, ncoContact->getPhotos() ) { //Home avatars
        if( fdo != 0 ) {
            QContactAvatar detail;
            copyDetailData(fdo, detail);
            detail.setAttribute(QContactAvatar::AttributeContext, QContactAvatar::AttributeContextHome);
            qcontact.saveDetail(&detail);
        }
    }

    LiveNodes imAccounts = ncoContact->getHasIMAccounts();
    foreach (const Live<nco::IMAccount>& imAccount, imAccounts) {
        // TODo replace when QtMobility guys implement support for IMAccount
        QContactOnlineAccount account;;
        account.setValue("Account", imAccount->getImID());
        account.setValue("ServiceName", imAccount->getImAccountType());
        qcontact.saveDetail(&account);
        QContactPresence presence;
        presence.setValue(QContactPresence::FieldNickname, imAccount->getImNickname());
        presence.setValue(QContactPresence::FieldPresence, imAccount->getImStatus());
        presence.setValue(QContactPresence::FieldStatusMessage, imAccount->getImStatusMessage());
qDebug()<<Q_FUNC_INFO<<imAccount->getImStatusMessage();
        qcontact.saveDetail(&presence);

    }

    foreach( Live< rdfs::Resource > url, ncoContact->getUrls() ) { //Home homepage urls
        QContactUrl detail;
        copyDetailData(url, detail);
{'fraction_non_alphanumeric': 0.1122702434177844, 'fraction_numerical': 0.0008831484241320307, 'mean_word_length': 4.3241257713781955, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 132, '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': '4079933', 'n_tokens_mistral': 5331, 'n_tokens_neox': 5230, 'n_words': 1028}