Example #1
0
void tst_QVersitContactPlugins::testExporterPlugins() {
    QVersitContactExporter exporter("Test");
    QContact contact;
    QContactName name;
    name.setFirstName("first name");
    contact.saveDetail(&name);
    QVERIFY(exporter.exportContacts(QList<QContact>() << contact));
    QCOMPARE(exporter.documents().size(), 1);
    QList<QVersitProperty> properties(exporter.documents().first().properties());

    // The plugins have had their index set such that they should be executed in reverse order
    // Check that they are all loaded, and run in the correct order
    int n = 0;
    foreach (QVersitProperty property, properties) {
        if (property.name() == "TEST-PROPERTY") {
            switch (n) {
                case 0: QCOMPARE(property.value(), QLatin1String("5")); break;
                case 1: QCOMPARE(property.value(), QLatin1String("4")); break;
                case 2: QCOMPARE(property.value(), QLatin1String("3")); break;
                case 3: QCOMPARE(property.value(), QLatin1String("2")); break;
                case 4: QCOMPARE(property.value(), QLatin1String("1")); break;
            }
            n++;
        }
    }
    QCOMPARE(n, 5);
}
Example #2
0
void MessageModel::setContact(const QContact& contact)
{
    clear();

    // Locate messages whose sender is this contact
    QMailMessageKey msgsFrom;

    // Locate messages whose recipients list contains this contact
    QMailMessageKey msgsTo;

    // Match on any of contact's phone numbers
    foreach(const QString& number, contact.phoneNumbers().values()) {
        msgsFrom |= QMailMessageKey(QMailMessageKey::Sender, number);
        msgsTo |= QMailMessageKey(QMailMessageKey::Recipients, number, QMailMessageKey::Contains);
    }

    // Match on any of contact's email addresses
    foreach(const QString& address, contact.emailList()) {
        msgsFrom |= QMailMessageKey(QMailMessageKey::Sender, address);
        msgsTo |= QMailMessageKey(QMailMessageKey::Recipients, address, QMailMessageKey::Contains);
    }

    // Sort messages by timestamp, newest to oldest
    QMailMessageSortKey sort(QMailMessageSortKey::TimeStamp, Qt::DescendingOrder);

    // Fetch the messages matching either of our queries, and return them sorted
    QMailIdList matches(QMailStore::instance()->queryMessages(msgsFrom | msgsTo, sort));

    // Add each returned message to our data model
    foreach (const QMailId& id, matches)
        appendRow(new MessageItem(id));
}
Example #3
0
void MT_CntVersitMyCardPlugin::exportOwnContact()
{
    //create contact
    QContact phonecontact;
    QContactName contactName;
    contactName.setFirstName("Jo");
    contactName.setLastName("Black");
    phonecontact.saveDetail(&contactName);
    QContactPhoneNumber number;
    number.setContexts("Home");
    number.setSubTypes("Mobile");
    number.setNumber("+02644424429");
    phonecontact.saveDetail(&number);
    
    //set MyCard detail
    QContactDetail myCard(MYCARD_DEFINTION_NAME);
    phonecontact.saveDetail(&myCard);
    
    //export
    QList<QContact> list;
    list.append(phonecontact);
    QVersitContactExporter exporter;
    QVERIFY(exporter.exportContacts(list, QVersitDocument::VCard21Type));
    QList<QVersitDocument> documents = exporter.documents();
    
    //X-SELF property is exported if MyCard
    QVersitDocument document  = documents.first();
    QVersitProperty property;
    property.setName(QLatin1String("X-SELF"));
    property.setValue("0");
    bool propertyFound = document.properties().contains(property);
    QVERIFY(propertyFound);
}
Example #4
0
void ContactConnection::addContact(QContact contact)
{
    mEngine->setNotifySimulator(false);
    QContactManager::Error error;
    QContactChangeSet changeSet;

    // if the created contact would get a too high id, delete
    // the contacts that the simulator knows nothing about
    QContactMemoryEngineData *edata = QContactMemoryEngineData::data(mEngine);
    if (edata->m_nextContactId + 1 > contact.localId()) {
        for (QContactLocalId id = contact.localId(); id <= edata->m_nextContactId; ++id)
            mEngine->removeContact(id, changeSet, &error);
    }

    // make sure the inserted contact gets the same id as in the simulator
    edata->m_nextContactId = contact.localId() - 1;

    // add (set localid to 0 first, otherwise the engine thinks we want to update a contact)
    QContactId newId = contact.id();
    newId.setLocalId(0);
    contact.setId(newId);
    mEngine->saveContact(&contact, changeSet, &error);

    mEngine->setNotifySimulator(true);
}
Example #5
0
void TestSimPlugin::testEmpty()
{
    QContactManager &m(m_controller->contactManager());

    // Add the Forrest Gump contact manually
    QContact forrest;

    QContactNickname n;
    n.setNickname("Forrest Gump");
    forrest.saveDetail(&n);

    QContactSyncTarget st;
    st.setSyncTarget(QStringLiteral("sim-test"));
    forrest.saveDetail(&st);

    QVERIFY(m.saveContact(&forrest));

    QCOMPARE(getAllSimContacts(m).count(), 1);
    QCOMPARE(m_controller->busy(), false);

    // Process an empty VCard
    m_controller->simPresenceChanged(true);
    m_controller->vcardDataAvailable(QString());
    QCOMPARE(m_controller->busy(), true);

    QTRY_VERIFY(m_controller->busy() == false);

    // No-longer-present contact should be removed
    QList<QContact> simContacts(getAllSimContacts(m));
    QCOMPARE(simContacts.count(), 0);
}
void TestSymbianEngine::saveContacts()
{
    QContactManager::Error err;
    QContactFilter defaultFilter = QContactFilter();
    QList<QContactSortOrder> sortOrders;
    QList<QContact> contacts;
    QContactId empty;
    int count = 5;

    int init_count = m_engine->contactIds(defaultFilter, sortOrders, &err).count();
    QVERIFY(err == QContactManager::NoError);

    // NULL
    QMap<int, QContactManager::Error> errorMap;
    QVERIFY(!m_engine->saveContacts(NULL, &errorMap, &err));
    QVERIFY(errorMap.count() == 0);
    QVERIFY(err == QContactManager::BadArgumentError);
    int current_count = m_engine->contactIds(defaultFilter, sortOrders, &err).count();
    QVERIFY(err == QContactManager::NoError);
    QVERIFY(init_count == current_count);

    // Save a "non contact(Jargon) type" contacts
    for(int i=0; i<count; i++) {
        QContact alice;
        alice.setType("Jargon");
        contacts.append(alice);
    }
    QVERIFY(!m_engine->saveContacts(&contacts, &errorMap, &err));
    QVERIFY(err == QContactManager::InvalidDetailError);
    foreach(QContactManager::Error err, errorMap) {
        QVERIFY(err == QContactManager::InvalidDetailError);
    }
void SymbianPluginPerfomance::createSimpleContacts()
{
    // Create N contacts
    QList<QContact> contactsList;

    for(int i=0; i<NO_OF_CONTACTS; i++) {
        QString c = QString::number(i);
        QString first("Alice");
        QContact alice;

        // Contact details
        QContactName aliceName;
        aliceName.setFirstName(first.append(c));
        alice.saveDetail(&aliceName);

        contactsList.append(alice);
    }

    // Save the contacts
    mTime.start();
    mCntMng->saveContacts(&contactsList, 0);
    int elapsed = mTime.elapsed();
    qDebug() << "Created " << contactsList.count() << " simple contacts in"
        << elapsed / 1000 << "s" << elapsed % 1000 << "ms";
}
void TestCntPresenceInfoProvider::testHandlePresenceUpdate()
{
    QSignalSpy spy(mCntPresenceInfoProvider, SIGNAL(infoFieldReady(CntInfoProvider*, int, ContactInfoField, const QString&)));
    
    PrcPresenceWriter *writer = PrcPresenceWriter::createWriter();
    PrcPresenceReader *reader = PrcPresenceReader::createReader();
    
    PrcPresenceBuddyInfoQt *dummyBuddy = PrcPresenceBuddyInfoQt::createInstance();
    dummyBuddy->setIdentity("sip:[email protected]");
    dummyBuddy->setAvailability(PrcPresenceBuddyInfoQt::PrcAvailable, "meh");
    writer->writePresence(*dummyBuddy);
    
    mCntPresenceInfoProvider->handlePresenceUpdate(true, dummyBuddy);
    QCOMPARE(spy.count(), 0);

    mCntPresenceInfoProvider->handlePresenceUpdate(false, dummyBuddy);
    QCOMPARE(spy.count(), 0);

    mCntPresenceInfoProvider->handlePresenceUpdate(true, NULL);
    QCOMPARE(spy.count(), 0);
    
    PrcPresenceBuddyInfoQt *buddy = reader->presenceInfo("sip:[email protected]");
    buddy->setAvailability(PrcPresenceBuddyInfoQt::PrcNotAvailable, "meh");
    writer->writePresence(*buddy);
    QTest::qWait(5000);
    QCOMPARE(spy.count(), 1);
    
    QContactManager manager("symbian");
    QContact c = manager.contact(mCntPresenceInfoProvider->mBuddyMap.value("sip:[email protected]"));
    
    QList<QContactOnlineAccount> accounts = c.details<QContactOnlineAccount>();
    foreach (QContactOnlineAccount account, accounts)
    {
        c.removeDetail(&account);
    }
/*! 
 * Returns a synthesised display label of a contact
 * \a contact to read the data from .
 * \a error On return, contains the possible error.
 * \return synthesised display label 
 */
QString CntDisplayLabel::synthesizedDisplayLabel(const QContact& contact, QContactManager::Error* error)
{
    QString displayLabel;
    *error = QContactManager::NoError;
    
    int value = m_settings->getValue();
    if (value != -1 && value != m_nameOrder) {
        m_nameOrder = value;
        setDisplayLabelDetails();
    }
    //contact
    if(contact.type() == QContactType::TypeContact) {
        displayLabel = generateDisplayLabel(contact, m_contactDisplayLabelDetails);    
    }
    
    //group
    else if (contact.type() == QContactType::TypeGroup) {
        displayLabel = generateDisplayLabel(contact, m_groupDisplayLabelDetails);
    } 
    
    //invalid type
    else {
        *error = QContactManager::InvalidContactTypeError;
    }
    
    return displayLabel;
}
QContactManager::Error
GContactsBackend::modifyContact(const QString &aID,
                                QContact &aContact)
{
    FUNCTION_CALL_TRACE;

    Q_ASSERT (iMgr);

    LOG_DEBUG("Modifying a Contact with ID" << aID);

    QContactManager::Error modificationStatus = QContactManager::UnspecifiedError;

    QContact oldContactData;
    getContact(QContactId::fromString(aID), oldContactData);

    aContact.setId(oldContactData.id());
    oldContactData = aContact;

    bool modificationOk = iMgr->saveContact(&oldContactData);
    modificationStatus = iMgr->error();

    if(!modificationOk) {
        // either contact exists or something wrong with one of the detailed definitions
        LOG_WARNING("Contact Modification Failed");
    } // no else

    return modificationStatus;
}
Example #11
0
void TestSimPlugin::testAddAndRemove()
{
    QContactManager &m(m_controller->contactManager());

    // Add the Forrest Gump contact manually
    QContact forrest;

    QContactNickname n;
    n.setNickname("Forrest Gump");
    forrest.saveDetail(&n);

    QContactSyncTarget st;
    st.setSyncTarget(QStringLiteral("sim-test"));
    forrest.saveDetail(&st);

    QVERIFY(m.saveContact(&forrest));

    QCOMPARE(getAllSimContacts(m).count(), 1);
    QCOMPARE(m_controller->busy(), false);

    // Process a VCard set not containing Forrest Gump but another contact
    m_controller->simPresenceChanged(true);
    m_controller->vcardDataAvailable(QStringLiteral(
"BEGIN:VCARD\n"
"VERSION:3.0\n"
"FN:Forrest Whittaker\n"
"TEL;TYPE=HOME,VOICE:(404) 555-1234\n"
"END:VCARD\n"));
    QTRY_VERIFY(m_controller->busy() == false);

    // Forrest Gump should be removed, Forrest Whittaker added
    QList<QContact> simContacts(getAllSimContacts(m));
    QCOMPARE(simContacts.count(), 1);
    QCOMPARE(simContacts.at(0).detail<QContactNickname>().nickname(), QStringLiteral("Forrest Whittaker"));
}
SeasideCache::ContactIdType SeasideCache::apiId(const QContact &contact)
{
#ifdef USING_QTPIM
    return contact.id();
#else
    return contact.id().localId();
#endif
}
Example #13
0
QDebug operator<<(QDebug dbg, const QContact& contact)
{
    dbg.nospace() << "QContact(" << contact.id() << ")";
    foreach (const QContactDetail& detail, contact.details()) {
        dbg.space() << '\n' << detail;
    }
    return dbg.maybeSpace();
}
Example #14
0
/*!
    \relates QContact
    Returns the hash value for \a key.
*/
uint qHash(const QContact &key)
{
    uint hash = qHash(key.id());
    foreach (const QContactDetail& detail, key.details()) {
        hash += qHash(detail);
    }
    return hash;
}
void TestCntActions::emptyContactNoActionSupport()
{
    QContact contact;
    m_manager->saveContact(&contact);
    
    //expected no actions found
    QList<QContactActionDescriptor> actions = contact.availableActions();
    QVERIFY(actions.count() == 0);
}
bool CntSimStorePrivate::read(int index, int numSlots, QContactManager::Error *error)
{
    if (IsActive()) {
        *error = QContactManager::LockedError;
        return false;
    }
    
    // ON store requires different read approach.
    // fetch ON contacts synchronously since there are usually only couple of them  
    if (m_storeInfo.m_storeName == KParameterValueSimStoreNameOn) {

        TRequestStatus status;
        QList<QContact> fetchedContacts; 
        for (int i = index; i <= numSlots; i++) {
            RMobileONStore::TMobileONEntryV1 onEntry;
            onEntry.iIndex = i;         
            RMobileONStore::TMobileONEntryV1Pckg onEntryPkg(onEntry);
            m_etelOnStore.Read(status, onEntryPkg);
            User::WaitForRequest(status);
            if (status.Int() == KErrNone) {
                QContact c;
                c.setType(QContactType::TypeContact);
                QContactName name;
                name.setCustomLabel(QString::fromUtf16(onEntry.iText.Ptr(),
                        onEntry.iText.Length()));
                c.saveDetail(&name);
                
                QContactPhoneNumber number;
                number.setNumber(QString::fromUtf16(onEntry.iNumber.iTelNumber.Ptr(),
                        onEntry.iNumber.iTelNumber.Length()));
                c.saveDetail(&number);
                
                QScopedPointer<QContactId> contactId(new QContactId());
                contactId->setLocalId(i);
                contactId->setManagerUri(m_managerUri);
                c.setId(*contactId);
                fetchedContacts.append(c);
            }
        }
        emit m_simStore.readComplete(fetchedContacts, QContactManager::NoError);
        *error = QContactManager::NoError;
        return true;
    }        
    
    // start reading
    m_buffer.Zero();
    m_buffer.ReAlloc(KOneSimContactBufferSize*numSlots);
    m_etelStore.Read(iStatus, index, numSlots, m_buffer);
    
    SetActive();
    m_state = ReadState;
    
    *error = QContactManager::NoError;
    return true;
}
Example #17
0
void SeasideCache::removePerson(SeasidePerson *person)
{
    QContact contact = person->contact();

    instance->m_contactsToRemove.append(contact.localId());
    instance->removeContactData(contact.localId(), SeasideFilteredModel::FilterFavorites);
    instance->removeContactData(contact.localId(), SeasideFilteredModel::FilterOnline);
    instance->removeContactData(contact.localId(), SeasideFilteredModel::FilterAll);

    instance->requestUpdate();
}
/*! Adds contacts in  \a newContacts into \a manager, converting categories specified
  with tags into group membership relationships.  Note that this implementation uses the
  synchronous API of QContactManager for clarity.  It is recommended that the asynchronous
  API is used in practice.

  Relationships are added so that if a contact, A, has a tag "b", then a HasMember relationship is
  created between a group contact in the manager, B with display label "b", and contact A.  If there
  does not exist a group contact with display label "b", one is created.
  */
void insertWithGroups(const QList<QContact>& newContacts, QContactManager* manager)
{
    // Cache map from group names to QContactIds
    QMap<QString, QContactId> groupMap;

    foreach (QContact contact, newContacts) {
        if (!manager->saveContact(&contact))
            continue; // In practice, better error handling may be required
        foreach (const QContactTag& tag, contact.details<QContactTag>()) {
            QString groupName = tag.tag();
            QContactId groupId;
            if (groupMap.contains(groupName)) {
                // We've already seen a group with the right name
                groupId = groupMap.value(groupName);
            } else {
                QContactDetailFilter groupFilter;
                groupFilter.setDetailDefinitionName(QContactType::DefinitionName);
                groupFilter.setValue(QLatin1String(QContactType::TypeGroup));
                groupFilter.setMatchFlags(QContactFilter::MatchExactly);
                // In practice, some detail other than the display label could be used
                QContactDetailFilter nameFilter = QContactDisplayLabel::match(groupName);
                QList<QContactLocalId> matchingGroups = manager->contactIds(groupFilter & nameFilter);
                if (!matchingGroups.isEmpty()) {
                    // Found an existing group in the manager
                    QContactId groupId;
                    groupId.setManagerUri(manager->managerUri());
                    groupId.setLocalId(matchingGroups.first());
                    groupMap.insert(groupName, groupId);
                }
                else {
                    // Make a new group
                    QContact groupContact;
                    QContactName name;
                    name.setCustomLabel(groupName);
                    // Beware that not all managers support custom label
                    groupContact.saveDetail(&name);
                    if (!manager->saveContact(&groupContact))
                        continue; // In practice, better error handling may be required
                    groupId = groupContact.id();
                    groupMap.insert(groupName, groupId);
                }
            }
            // Add the relationship
            QContactRelationship rel;
            rel.setFirst(groupId);
            rel.setRelationshipType(QContactRelationship::HasMember);
            rel.setSecond(contact.id());
            manager->saveRelationship(&rel);
        }
    }
}
void TestBirthdayPlugin::testChangeName()
{
    const QString contactID = QUuid::createUuid().toString();
    const QDateTime contactBirthDate = QDateTime::currentDateTime();

    // Add contact with birthday to tracker.
    QContactName contactName;
    contactName.setFirstName(contactID);
    QContactBirthday contactBirthday;
    contactBirthday.setDateTime(contactBirthDate);
    QContact contact;
    QVERIFY(contact.saveDetail(&contactName));
    QVERIFY(contact.saveDetail(&contactBirthday));
    QVERIFY2(mManager->saveContact(&contact), "Error saving contact to tracker");

    // Wait until calendar event gets to calendar.
    loopWait(calendarTimeout);

    // Open calendar database.
    mKCal::ExtendedCalendar::Ptr calendar =
        mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
    mKCal::ExtendedStorage::Ptr storage =
        mKCal::ExtendedCalendar::defaultStorage(calendar);
    storage->open();
    QVERIFY2(not storage->notebook(calNotebookId).isNull(), "No calendar database found");

    // Check calendar database for contact.
    QVERIFY2(storage->loadNotebookIncidences(calNotebookId), "Unable to load events from notebook");
    KCalCore::Event::List eventList = calendar->events();
    QCOMPARE(countCalendarEvents(eventList, contact), 1);

    // Change the contact name and see if the calendar is updated.
    const QString newContactID = QUuid::createUuid().toString();
    contactName.setFirstName(newContactID);
    QVERIFY(contact.saveDetail(&contactName));
    // TODO: Should it be necessary to refetch the contact to get the synthesised displayLabel?
    contact = mManager->contact(apiId(contact));
    QVERIFY2(mManager->saveContact(&contact), "Unable to update test contact in tracker");

    // Wait until calendar event gets to calendar.
    loopWait(calendarTimeout);

    // Search for any events in the calendar.
    QVERIFY2(storage->loadNotebookIncidences(calNotebookId), "Unable to load events from notebook");
    eventList = calendar->events();
    QCOMPARE(countCalendarEvents(eventList, contact), 1);

    // Close the calendar.
    QVERIFY2(storage->close(), "Error closing the calendar");
}
void TestCntActions::noUrlSupport()
{
    QContact contact;
    m_manager->saveContact(&contact);
    
    //expected no actions found
    QList<QContactActionDescriptor> actionDescriptors = contact.availableActions();
    QStringList actions;
    for (int i = 0;i < actionDescriptors.count();i++)
    {
        QString action = actionDescriptors.at(i).actionName();
        actions << action;
    }
    QVERIFY(actions.contains("url", Qt::CaseInsensitive) == false);
}
void TestBirthdayPlugin::testLeapYears()
{
    const QString contactID = QUuid::createUuid().toString();
    QFETCH(QDate, contactBirthDate);

    // Add contact with birthday to tracker.
    QContactName contactName;
    contactName.setFirstName(contactID);
    QContactBirthday contactBirthday;
    contactBirthday.setDate(contactBirthDate);
    QContact contact;
    QVERIFY(contact.saveDetail(&contactName));
    QVERIFY(contact.saveDetail(&contactBirthday));
    QVERIFY(saveContact(contact));

    // Wait until calendar event gets to calendar.
    loopWait(calendarTimeout);

    // Open calendar database.
    mKCal::ExtendedCalendar::Ptr calendar =
        mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
    mKCal::ExtendedStorage::Ptr storage =
        mKCal::ExtendedCalendar::defaultStorage(calendar);

    QVERIFY(storage->open());
    QVERIFY(not storage->notebook(calNotebookId).isNull());

    // Check calendar database for contact.
    QVERIFY(storage->loadNotebookIncidences(calNotebookId));
    const KCalCore::Event::List eventList = findCalendarEvents(calendar->events(), contact);
    QCOMPARE(eventList.count(), 1);

    const KCalCore::Event::Ptr event = eventList.first();
    QCOMPARE(event->summary(), contactID);
    QCOMPARE(event->dtStart().date(), contactBirthDate);
    QCOMPARE(event->allDay(), true);

    // Check number of recurrences and their values.
    const KDateTime first(QDate(2000, 1, 1), QTime(), KDateTime::ClockTime);
    const KDateTime last(QDate(2020, 12, 31), QTime(), KDateTime::ClockTime);
    const KCalCore::DateTimeList instances = event->recurrence()->timesInInterval(first, last);

    QCOMPARE(instances.length(), 13);

    for(int i = 0; i < instances.length(); ++i) {
        QCOMPARE(instances.at(i).date(), contactBirthDate.addYears(i));
    }
}
KCalCore::Event::List TestBirthdayPlugin::findCalendarEvents(const KCalCore::Event::List &eventList,
                                                             const QContact &contact) const
{
    KCalCore::Event::List matches;

    Q_FOREACH(const KCalCore::Event::Ptr event, eventList) {
        if(event->dtStart().date() == contact.detail<QContactBirthday>().date()) {
#ifdef USING_QTPIM
            if(event->summary() == contact.detail<QContactDisplayLabel>().label()) {
#else
            if(event->summary() == contact.displayLabel()) {
#endif
                matches += event;
            }
        }
    }

    return matches;
}

bool TestBirthdayPlugin::saveContact(QContact &contact)
{
    const bool success = mManager->saveContact(&contact);

    if (success) {
        mContactIDs.insert(apiId(contact));
    }

    return success;
}

CONTACTSD_TEST_MAIN(TestBirthdayPlugin)
Example #23
0
void QDeclarativeContact::setContact(const QContact& contact)
{
    m_id = contact.id();
    foreach (QDeclarativeContactDetail *detail, m_details)
        delete detail;
    m_details.clear();
    m_preferredDetails.clear();

    QList<QContactDetail> details(contact.details());
    foreach (const QContactDetail &detail, details) {
        QDeclarativeContactDetail *contactDetail = QDeclarativeContactDetailFactory::createContactDetail(static_cast<QDeclarativeContactDetail::DetailType>(detail.type()));
        contactDetail->setParent(this);
        contactDetail->setDetail(detail);
        connect(contactDetail, SIGNAL(detailChanged()), this, SIGNAL(contactChanged()));
        m_details.append(contactDetail);
    }
Example #24
0
void BusinessCardHandling::saveAvatar(const QString filename, QPixmap p, QContact& contact)
{

    // Path to store avatar picture
    QString path;
#ifdef Q_OS_SYMBIAN
    path.append("c:/System/");
#endif
    path.append(filename);

    // Remove same file if exists
    QFile file;
    if (file.exists(path))
        file.remove(path);

    // Save pixmap into file
    bool saveRet = p.save(path);

    if (saveRet) {
        // Create avatar
        QContactAvatar contactAvatar;
        contactAvatar.setImageUrl(QUrl(path));
        bool saveAvatar = contact.saveDetail(&contactAvatar);

        // Save contact
        if (saveAvatar)
            m_contactManager->saveContact(&contact);

        // NOTE: Do not remove picture, system needs it for showing avatar
        // Remove picture file
        //bool removeRet = file.remove(path);
    }
}
void TestCntActions::phonenumberCallSupport()
{
    QContact contact;
    
    //Add phonenumber to contact
    QContactPhoneNumber number;
    number.setSubTypes(QContactPhoneNumber::SubTypeMobile);
    number.setNumber("555111222");
    contact.saveDetail(&number);
    m_manager->saveContact(&contact);
    
    //verify that the contact has a phonenumber
    QList<QContactPhoneNumber> numberList = contact.details<QContactPhoneNumber>();
    QVERIFY(numberList.count() >  0);
    
    //get the actions
    QList<QContactActionDescriptor> actionDescriptors = contact.availableActions();
    QStringList actions;
    for (int i = 0;i < actionDescriptors.count();i++)
    {
        QString action = actionDescriptors.at(i).actionName();
        actions << action;
    }
    
    //verify that it includes the actiosn
    QVERIFY(actions.contains("call", Qt::CaseInsensitive));
    
    //verify that the action works
    QList<QContactActionDescriptor> callActionDescriptors = QContactAction::actionDescriptors("call", "symbian");
    QVERIFY(callActionDescriptors.count() == 1);
    QContactAction *callAction = QContactAction::action(callActionDescriptors.at(0));
    QVERIFY(callAction != 0);
    QContactAction::State state = callAction->state();
    QVERIFY(state != QContactAction::InactiveState);
    QVERIFY(callAction->isDetailSupported(numberList.at(0)) == true);
    QList<QContactDetail> supportedDetails = callAction->supportedDetails(contact);
    QVERIFY(supportedDetails.count() != 0);
    QVariantMap variantMap = callAction->metaData();
    QVERIFY(variantMap.count() == 0);
    variantMap = callAction->results();
    QVERIFY(variantMap.count() == 0);
    QSignalSpy spyCallAction(callAction, SIGNAL(stateChanged(QContactAction::State)));
    callAction->invokeAction(contact, numberList.at(0));
    callAction->invokeAction(contact);
    QTRY_COMPARE(spyCallAction.count(), 2); // make sure the signal was emitted exactly one time
    delete callAction;
}
Example #26
0
void ContactDetails::init( const QContact &entry )
{
    // If we redisplay the same entry, don't shift our view around too much
    bool sameEntry = (entry.uid() == ent.uid());

    ent = entry;
    mLink.clear();

    /* Create our members, if we haven't */
    if ( !mModel ) {
        mModel = new QContactModel(this);
        connect(mModel, SIGNAL(modelReset()), this, SLOT(modelChanged()));

        mTabs = new QTabWidget();

        mQuickTab = new ContactOverview(0);
        mDetailsTab = new ContactBrowser(0);
#if defined(QTOPIA_TELEPHONY)
        mCallHistoryTab = new ContactCallHistoryList(0);
#endif
        mMessageHistoryTab = new ContactMessageHistoryList(0);

        mTabs->addTab(mQuickTab, QIcon(":icon/contactdetails"), tr("Overview"));
        mTabs->addTab(mDetailsTab, QIcon(":icon/details"), tr("Details"));
#if defined(QTOPIA_TELEPHONY)
        mTabs->addTab(mCallHistoryTab, QIcon(":icon/phone/calls"), tr("Calls"));
#endif
        mTabs->addTab(mMessageHistoryTab, QIcon(":icon/email"), tr("Messages"));

        connect(mQuickTab, SIGNAL(externalLinkActivated()), this, SIGNAL(externalLinkActivated()));
        connect(mQuickTab, SIGNAL(backClicked()), this, SIGNAL(backClicked()));
        connect(mDetailsTab, SIGNAL(externalLinkActivated()), this, SIGNAL(externalLinkActivated()));
        connect(mDetailsTab, SIGNAL(backClicked()), this, SIGNAL(backClicked()));
#if defined(QTOPIA_TELEPHONY)
        connect(mCallHistoryTab, SIGNAL(externalLinkActivated()), this, SIGNAL(externalLinkActivated()));
        connect(mCallHistoryTab, SIGNAL(backClicked()), this, SIGNAL(backClicked()));
#endif
        connect(mMessageHistoryTab, SIGNAL(externalLinkActivated()), this, SIGNAL(externalLinkActivated()));
        connect(mMessageHistoryTab, SIGNAL(backClicked()), this, SIGNAL(backClicked()));

        connect(mQuickTab, SIGNAL(callContact()), this, SIGNAL(callContact()));
        connect(mQuickTab, SIGNAL(textContact()), this, SIGNAL(textContact()));
        connect(mQuickTab, SIGNAL(emailContact()), this, SIGNAL(emailContact()));
        connect(mQuickTab, SIGNAL(editContact()), this, SIGNAL(editContact()));

        connect(mDetailsTab, SIGNAL(highlighted(QString)), this, SIGNAL(highlighted(QString)));

        QVBoxLayout *v = new QVBoxLayout();
        v->addWidget(mTabs);
        v->setMargin(0);
        setLayout(v);
    }

    modelChanged();

    if (!sameEntry)
        mTabs->setCurrentIndex(0);
    mTabs->currentWidget()->setFocus();
}
QMap<int,GContactsStatus>
GContactsBackend::modifyContacts( QList<QContact> &aContactList,
                                  const QStringList &aContactIdList)
{
    FUNCTION_CALL_TRACE;

    Q_ASSERT (iMgr);
    GContactsStatus status;

    QMap<int,QContactManager::Error> errors;
    QMap<int,GContactsStatus> statusMap;

    for (int i = 0; i < aContactList.size(); i++) {
        LOG_DEBUG("Replacing item's ID " << aContactList.at(i));
        LOG_DEBUG("Id of the contact to be replaced" << aContactIdList.at(i));
        QContact contact;
        getButeoContact(QContactId::fromString(aContactIdList.at(i)), contact);
        if (!contact.isEmpty()) {
            aContactList[i].setId(QContactId::fromString(aContactIdList.at(i)));
        }
    }

    if(iMgr->saveContacts(&aContactList , &errors)) {
        LOG_DEBUG("Batch Modification of Contacts Succeeded");
    } else {
        LOG_DEBUG("Batch Modification of Contacts Failed");
    }

    // QContactManager will populate errorMap only for errors, but we use this as a status map,
    // so populate NoError if there's no error.
    // TODO QContactManager populates indices from the aContactList, but we populate keys, is this OK?
    for (int i = 0; i < aContactList.size(); i++) {
        QContactId contactId = aContactList.at(i).id();
        if( !errors.contains(i) ) {
            LOG_DEBUG("No error for contact with id " << contactId << " and index " << i);
            status.errorCode = QContactManager::NoError;
            statusMap.insert(i, status);
        } else {
            LOG_DEBUG("contact with id " << contactId << " and index " << i <<" is in error");
            QContactManager::Error errorCode = errors.value(i);
            status.errorCode = errorCode;
            statusMap.insert(i, status);
        }
    }
    return statusMap;
}
void TestBirthdayPlugin::testAddAndRemoveBirthday()
{
    const QString contactID = QUuid::createUuid().toString();
    const QDateTime contactBirthDate = QDateTime::currentDateTime();

    // Add contact with birthday to tracker.
    QContactName contactName;
    contactName.setFirstName(contactID);
    QContactBirthday contactBirthday;
    contactBirthday.setDateTime(contactBirthDate);
    QContact contact;
    QVERIFY(contact.saveDetail(&contactName));
    QVERIFY(contact.saveDetail(&contactBirthday));
    QVERIFY2(mManager->saveContact(&contact), "Error saving contact to tracker");

    // Wait until calendar event gets to calendar.
    loopWait(calendarTimeout);

    // Open calendar database, which should have been created by the birthday plugin.
    mKCal::ExtendedCalendar::Ptr calendar =
        mKCal::ExtendedCalendar::Ptr(new mKCal::ExtendedCalendar(KDateTime::Spec::LocalZone()));
    mKCal::ExtendedStorage::Ptr storage =
        mKCal::ExtendedCalendar::defaultStorage(calendar);
    storage->open();
    QVERIFY2(not storage->notebook(calNotebookId).isNull(), "No calendar database found");

    // Check calendar database for contact.
    QVERIFY2(storage->loadNotebookIncidences(calNotebookId), "Unable to load events from notebook");
    KCalCore::Event::List eventList = calendar->events();
    QCOMPARE(countCalendarEvents(eventList, contact), 1);

    // Delete the contact and see if the birthday is also deleted.
    QVERIFY2(mManager->removeContact(apiId(contact)), "Unable to delete test contact from tracker database");

    // Wait until calendar event gets to calendar.
    loopWait(calendarTimeout);

    // Search for any events in the calendar.
    QVERIFY2(storage->loadNotebookIncidences(calNotebookId), "Unable to load events from notebook");
    eventList = calendar->events();
    QCOMPARE(countCalendarEvents(eventList, contact), 0);

    // Close the calendar.
    QVERIFY2(storage->close(), "Error closing the calendar");
}
void
ut_qtcontacts_trackerplugin_common::setTestNicknameToContact(QContact &contact,
                                                             const QString &id) const
{
    QContactNickname nicknameDetail;
    const QString nickname = makeUniqueName(id);
    nicknameDetail.setNickname(nickname);
    QVERIFY(contact.saveDetail(&nicknameDetail));
}
Example #30
0
void SeasideCache::appendContacts(const QList<QContact> &contacts)
{
    QVector<QContactLocalId> &cacheIds = m_contacts[m_fetchFilter];
    QList<SeasideFilteredModel *> &models = m_models[m_fetchFilter];

    cacheIds.reserve(contacts.count());

    const int begin = cacheIds.count();
    int end = contacts.count() - 1;

#ifndef SEASIDE_SPARQL_QUERIES
    // Exclude the self contact Id.
    for (int i = cacheIds.count(); i < contacts.count(); ++i) {
        if (contacts.at(i).localId() == m_selfId) {
            --end;
            break;
        }
    }
#endif

    for (int i = 0; i < models.count(); ++i)
        models.at(i)->sourceAboutToInsertItems(begin, end);

    for (int i = cacheIds.count(); i < contacts.count(); ++i) {
        QContact contact = contacts.at(i);

#ifndef SEASIDE_SPARQL_QUERIES
        if (contact.localId() == m_selfId)
            continue;
#endif

        cacheIds.append(contact.localId());
        SeasideCacheItem &cacheItem = m_people[contact.localId()];
        cacheItem.contact = contact;
        cacheItem.filterKey = QStringList();

        QList<QContactPhoneNumber> phoneNumbers = contact.details<QContactPhoneNumber>();
        for (int j = 0; j < phoneNumbers.count(); ++j)
            m_phoneNumberIds[phoneNumbers.at(j).number()] = contact.localId();
    }

    for (int i = 0; i < models.count(); ++i)
        models.at(i)->sourceItemsInserted(begin, end);
}