コード例 #1
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();
}
コード例 #2
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;
}
コード例 #3
0
QList<QContactDetail> CntMessageAction::supportedDetails(const QContact& contact) const
{
    QList<QContactDetail> details = contact.details(QContactPhoneNumber::DefinitionName);
    QList<QContactDetail> supportedDetails;
    for (int i = 0; i < details.count(); i++)
    {
        if (!static_cast<QContactPhoneNumber>(details[i]).subTypes().isEmpty() 
            && static_cast<QContactPhoneNumber>(details[i]).subTypes().first() == QContactPhoneNumber::SubTypeMobile)
        {
            supportedDetails.append(details[i]);
        }
    } 
    return supportedDetails;
}
コード例 #4
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);
    }
コード例 #5
0
void tst_QContactDetail::templates()
{
    QContact c;
    QContactPhoneNumber p1, p2;
    p1.setNumber("1234");
    p2.setNumber("5678");
    QVERIFY(c.saveDetail(&p1));
    QVERIFY(c.saveDetail(&p2));

    QList<QContactDetail> l = c.details("PhoneNumber");

    QCOMPARE(l.count(), 2);
    QCOMPARE(QContactPhoneNumber(l.at(0)), p1);
    QCOMPARE(QContactPhoneNumber(l.at(1)), p2);

    QList<QContactPhoneNumber> l2 = c.details<QContactPhoneNumber>();
    QCOMPARE(l2.count(), 2);
    QCOMPARE(l2.at(0), p1);
    QCOMPARE(l2.at(1), p2);
}
コード例 #6
0
ファイル: mainwindow.cpp プロジェクト: guoqingkong/QT_code
void MainWindow::on_pushButton_3_clicked()
{

//    qDebug() << "The default manager for the platform is:" << cm.managerName();
//    qDebug() << "It" << (cm.isRelationshipTypeSupported(QContactRelationship::HasAssistant) ? "supports" : "does not support") << "assistant relationships.";
//    qDebug() << "It" << (cm.supportedContactTypes().contains(QContactType::TypeGroup) ? "supports" : "does not support") << "groups.";
//    qDebug() << "It" << (cm.hasFeature(QContactManager::MutableDefinitions) ? "supports" : "does not support") << "mutable detail definitions.";


    QList<QContactLocalId> contactIds = cm.contactIds();
    QContact a = cm.contact(contactIds.first());
    qDebug() << "Viewing the details of" << a.displayLabel();

    QList<QContactDetail> allDetails = a.details();
    for (int i = 0; i < allDetails.size(); i++) {
        QContactDetail detail = allDetails.at(i);
        QContactDetailDefinition currentDefinition = cm.detailDefinition(detail.definitionName());
        QMap<QString, QContactDetailFieldDefinition> fields = currentDefinition.fields();

        qDebug("\tDetail #%d (%s):", i, detail.definitionName().toAscii().constData());
        foreach (const QString& fieldKey, fields.keys()) {
            qDebug() << "\t\t" << fieldKey << "(" << fields.value(fieldKey).dataType() << ") =" << detail.value(fieldKey);
        }
        qDebug();
    }

    QContact b;
    QContactDetail de;
    foreach (const QContactLocalId& ids, contactIds )
        {
            b =  cm.contact(ids);
            de = b.detail("PhoneNumber");
            bool s = de.hasValue("PhoneNumber");
            qDebug()<< " has Value PhoneNumber key"<<s<<"|"<<de.value("PhoneNumber");
            QString show;
            show = b.displayLabel();
            show.append("\t");
            show.append(de.value("PhoneNumber"));
            ui->listWidget_2->addItem(show);
        }
コード例 #7
0
/*! Parses SIM contacts in TLV format.
 *
 * \param rawData SIM contacts in TLV format.
 * \return List of contacts.
*/
QList<QContact> CntSimStorePrivate::decodeSimContactsL(TDes8& rawData) const
{
    PbkPrintToLog(_L("CntSymbianSimEngine::decodeSimContactsL() - IN"));
    QList<QContact> fetchedContacts;
    QContact currentContact;

    TBuf16<KDataClientBuf> buffer;
    TPtrC16 bufPtr(buffer);

    TUint8 tagValue(0);
    CPhoneBookBuffer::TPhBkTagType dataType;

    bool isAdditionalNumber = false;

    CPhoneBookBuffer* pbBuffer = new(ELeave) CPhoneBookBuffer();
    CleanupStack::PushL(pbBuffer);
    pbBuffer->Set(&rawData);
    pbBuffer->StartRead();

    while (pbBuffer->GetTagAndType(tagValue, dataType) == KErrNone) {
        switch (tagValue)
        {
            case RMobilePhoneBookStore::ETagPBAdnIndex:
            {
                //save contact's id (SIM card index) and manager's name
                TUint16  index;
                if (pbBuffer->GetValue(index) == KErrNone) {
                    QScopedPointer<QContactId> contactId(new QContactId());
                    contactId->setLocalId(index);
                    contactId->setManagerUri(m_managerUri);
                    currentContact.setId(*contactId);
                }
                isAdditionalNumber = false;
                break;
            }
            case RMobilePhoneBookStore::ETagPBTonNpi:
            {
                // Note, that TON info can be incorporated into the phone number by Etel
                // implementation (TSY). E.g. this is the case with Nokia TSY.
                // Here general case is implemented.

                // Check number type, we are only interested if it's international or not.
                // We assume here that ETagPBTonNpi always comes after ETagPBNumber, not before.
                TUint8  tonNpi;
                if (pbBuffer->GetValue(tonNpi) == KErrNone) {
                    TUint8  intFlag = (tonNpi & KEtsiTonPosition) >> 4;
                    if (intFlag == 1) {
                        //international number format, append "+" to the last
                        //saved number
                        QList<QContactDetail> phoneNumbers = currentContact.details(
                                QContactPhoneNumber::DefinitionName);
                        if (phoneNumbers.count() > 0) {
                            QContactPhoneNumber lastNumber = static_cast<QContactPhoneNumber>(
                                phoneNumbers.at(phoneNumbers.count() - 1));
                            QString number = lastNumber.number();
                            number.insert(0, "+");
                            lastNumber.setNumber(number);
                            if (m_storeInfo.m_readOnlyAccess)
                                m_engine.setReadOnlyAccessConstraint(&lastNumber);
                            currentContact.saveDetail(&lastNumber);
                        }
                    }
                }

                // We have rearched to the end of the number,
                // invalidate additional number flag.
                isAdditionalNumber = false;
                break;
            }
            case RMobilePhoneBookStore::ETagPBText:
            {
                if (pbBuffer->GetValue(bufPtr) == KErrNone) {
                    if (isAdditionalNumber) {
                        // For additional number bufPtr contains number alpha string,
                        // this is ignored currently
                    }
                    else {
                        // Contact name otherwise
                        QContactName name;
                        QString nameString = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
                        name.setCustomLabel(nameString);
                        if (m_storeInfo.m_readOnlyAccess)
                            m_engine.setReadOnlyAccessConstraint(&name);
                        currentContact.saveDetail(&name);
                        QContactManager::Error error(QContactManager::NoError);
                        m_engine.setContactDisplayLabel(&currentContact, m_engine.synthesizedDisplayLabel(currentContact, &error));
                    }
                }
                break;
            }
            case RMobilePhoneBookStore::ETagPBSecondName:
            {
                if (pbBuffer->GetValue(bufPtr) == KErrNone) {
                    QContactNickname nickName;
                    QString name = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
                    nickName.setNickname(name);
                    if (m_storeInfo.m_readOnlyAccess)
                        m_engine.setReadOnlyAccessConstraint(&nickName);
                    currentContact.saveDetail(&nickName);
                }
                break;
            }
            case RMobilePhoneBookStore::ETagPBNumber:
            {
                if (pbBuffer->GetValue(bufPtr) == KErrNone) {
                    QContactPhoneNumber phoneNumber;
                    QString number = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
                    phoneNumber.setNumber(number);
                    if (m_storeInfo.m_readOnlyAccess)
                        m_engine.setReadOnlyAccessConstraint(&phoneNumber);
                    currentContact.saveDetail(&phoneNumber);
                }
                break;
            }
            case RMobilePhoneBookStore::ETagPBAnrStart:
            {
                // This tag should precede every additional number entry
                isAdditionalNumber = true;
                break;
            }
            case RMobilePhoneBookStore::ETagPBEmailAddress:
            {
                if (pbBuffer->GetValue(bufPtr) == KErrNone) {
                    QContactEmailAddress email;
                    QString emailAddress = QString::fromUtf16(bufPtr.Ptr(), bufPtr.Length());
                    email.setEmailAddress(emailAddress);
                    if (m_storeInfo.m_readOnlyAccess)
                        m_engine.setReadOnlyAccessConstraint(&email);
                    currentContact.saveDetail(&email);
                }
                break;
            }
            case RMobilePhoneBookStore::ETagPBNewEntry:
            {
                // This signals the end of the entry and is a special case
                // which will be handled below.
                break;
            }
            default:
            {
                // An unsupported field type - just skip this value
                pbBuffer->SkipValue(dataType);
                break;
            }
        } //switch

        // save contact to the array of contact to be returned if the whole entry was extracted
        if ((tagValue == RMobilePhoneBookStore::ETagPBNewEntry && currentContact.localId() > 0) ||
            (pbBuffer->RemainingReadLength() == 0 && currentContact.localId() > 0)) {
            fetchedContacts.append(currentContact);
            //clear current contact
            currentContact.clearDetails();
            QScopedPointer<QContactId> contactId(new QContactId());
            contactId->setLocalId(0);
            contactId->setManagerUri(QString());
            currentContact.setId(*contactId);
        }
    } //while
コード例 #8
0
/*!
 * Export QT Contact into Versit Document.
 */
void QVersitContactExporterPrivate::exportContact(
    const QContact& contact,
    QVersitDocument& document)
{
    QList<QContactDetail> allDetails = contact.details();
    foreach (const QContactDetail& detail, allDetails) {
        // If the custom detail handler handles it, we don't have to.
        if (mDetailHandler
            && mDetailHandler->preProcessDetail(contact, detail, &document))
            continue;

        QList<QVersitProperty> removedProperties;
        QList<QVersitProperty> generatedProperties;
        QSet<QString> processedFields;

        if (detail.definitionName() == QContactName::DefinitionName) {
            encodeName(detail, document, &removedProperties, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactPhoneNumber::DefinitionName) {
            encodePhoneNumber(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactEmailAddress::DefinitionName) {
            encodeEmail(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactAddress::DefinitionName) {
            encodeAddress(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactGuid::DefinitionName) {
            encodeUid(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactUrl::DefinitionName) {
            encodeUrl(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactTimestamp::DefinitionName) {
            encodeRev(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactBirthday::DefinitionName) {
            encodeBirthDay(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactGeoLocation::DefinitionName) {
            encodeGeoLocation(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactNote::DefinitionName) {
            encodeNote(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactOrganization::DefinitionName) {
            encodeOrganization(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactRingtone::DefinitionName) {
            encodeRingtone(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactThumbnail::DefinitionName) {
            encodeThumbnail(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactAvatar::DefinitionName){
            encodeAvatar(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactAnniversary::DefinitionName) {
            encodeAnniversary(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactNickname::DefinitionName) {
            encodeNickname(detail, document, &removedProperties, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactTag::DefinitionName) {
            encodeTag(detail, document, &removedProperties, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactGender::DefinitionName) {
            encodeGender(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactOnlineAccount::DefinitionName) {
            encodeOnlineAccount(detail, &generatedProperties, &processedFields);
        } else if (detail.definitionName() == QContactFamily::DefinitionName) {
            encodeFamily(detail, &generatedProperties, &processedFields);
        }

        // run plugin handlers
        foreach (QVersitContactExporterDetailHandlerV2* handler, mPluginDetailHandlers) {
            handler->detailProcessed(contact, detail, document,
                                     &processedFields, &removedProperties, &generatedProperties);
        }
        // run the v2 handler, if set
        if (mDetailHandler2 && mDetailHandlerVersion > 1) {
            mDetailHandler2->detailProcessed(contact, detail, document,
                                             &processedFields, &removedProperties, &generatedProperties);
        }

        foreach(const QVersitProperty& property, removedProperties) {
            document.removeProperty(property);
        }
コード例 #9
0
string DecodedDataDocumentParser::replaceSocamPersonTags (string text)
{

	regex_t regex;
	const char* tag_regex_text = "<\\s*person\\s*>([^,]*),([^<]*)<\\s*/person\\s*>";
	
	compileRegex(&regex, tag_regex_text);	
	size_t ngroups = regex.re_nsub + 1;
	regmatch_t *groups = (regmatch_t *) malloc(ngroups * sizeof(regmatch_t));

	//string text(to_match);

	while (1) {

		const char * p = text.c_str();
		int nomatch = regexec(&regex, p, ngroups, groups, 0);

		if (nomatch) {
	   		break;
		}

		regmatch_t match = groups[0];
		if (groups[0].rm_so == -1) {
			break;
		}

		string name, surname;
		size_t nmatched;
		for (nmatched = 0; nmatched < ngroups; nmatched++) {

			if (groups[nmatched].rm_so == (size_t)(-1)) {
				break;
			}

			string matchStr = text.substr (groups[nmatched].rm_so,groups[nmatched].rm_eo-groups[nmatched].rm_so);
			cout << "Match: "<< matchStr << endl;
			if(nmatched == 1) {
				name = matchStr;
			}
			else if(nmatched == 2) {
				surname = matchStr;
			}
			
		}

		cout << "Parsed: name=" << name << " surname=" << surname << endl;


		string tag = text.substr (match.rm_so,match.rm_eo-match.rm_so);

		QContact contact = getContact(name, surname);
		
		//qWarning("\tContact ID: %d -- UUID: %s",contact.localId(),contact.details("Guid").at(0).value("Guid").toStdString().c_str());
		//qWarning("\t\tDisplayLabel: %s",contact.details("DisplayLabel").at(0).value("Label").toStdString().c_str());
		//qWarning("\t\tEmail %s",contact.details("EmailAddress").at(0).value("EmailAddress").toStdString().c_str());
		//qWarning("\t\tPhoneNumber: %s",contact.details("PhoneNumber").at(0).value("PhoneNumber").toStdString().c_str());
		/*
		QContactDetail(name="DisplayLabel", key=7, "Label"=QVariant(QString, "Self Simulator") );
		QContactDetail(name="Type", key=10, "Type"=QVariant(QString, "Contact") );
		QContactDetail(name="Name", key=13, "CustomLabel"=QVariant(QString, "Self Simulator") , "FirstName"=QVariant(QString, "Self") , "LastName"=QVariant(QString, "Simulator") );
		QContactDetail(name="EmailAddress", key=16, "EmailAddress"=QVariant(QString, "*****@*****.**") );
		QContactDetail(name="PhoneNumber", key=19, "PhoneNumber"=QVariant(QString, "+44123456789") );
		QContactDetail(name="Address", key=22, "Country"=QVariant(QString, "UK") , "Locality"=QVariant(QString, "Leister") , "Street"=QVariant(QString, "56 Edmonton Square") );
		QContactDetail(name="Guid", key=25, "Guid"=QVariant(QString, "0") );
		QContactDetail(name="Timestamp", key=28, "CreationTimestamp"=QVariant(QDateTime, QDateTime("dom 13. mar 12:21:09 2011") ) , "ModificationTimestamp"=QVariant(QDateTime, QDateTime("dom 13. mar 12:21:09 2011") ) );
		*/
		
		ostringstream oss ;

		oss << "<table>";

		oss << "<tr>";
		if(contact.details("DisplayLabel").count()>0) {
			oss << "<td>" << contact.details("DisplayLabel").at(0).value("Label").toStdString() << "</td>";
		}
		oss << "</tr>";

		oss << "<tr>";
		if(contact.details("EmailAddress").count()>0) {
			oss << "<td>" << contact.details("EmailAddress").at(0).value("EmailAddress").toStdString() << "</td>";
		}
		oss << "</tr>";

		oss << "<tr>";
		if(contact.details("PhoneNumber").count()>0) {
			oss << "<td>" << contact.details("PhoneNumber").at(0).value("PhoneNumber").toStdString() << "</td>";
		}
		oss << "</tr>";

		oss << "</table>";

		string newTagContent = oss.str();

		text.replace(match.rm_so,match.rm_eo-match.rm_so,newTagContent);
		cout<<"Replaced:" <<text<<endl;

	}

	regfree (&regex);
	return text;

}