コード例 #1
0
ファイル: contact.cpp プロジェクト: saesu/contacts-demo
void Contact::setData(SObject data)
{
    SObject oldData = mData;
    mData = data;

    if (firstName() != oldData.value("firstName"))
        emit firstNameChanged();
    
    if (lastName() != oldData.value("lastName"))
        emit lastNameChanged();

    if (phoneNumber() != oldData.value("phoneNumber"))
        emit phoneNumberChanged();

    // update avatar serial so QML reloads the image
    setAvatarSerial(avatarSerial() + 1);
}
コード例 #2
0
int main(void){
    
    unsigned char testAddr1[IBUTTON_BYTES] = { 1, 2, 66, 78, 52, 6, 7 };
    unsigned char testAddr2[8] = { 6, 6, 8, 9, 5, 8, 78, 90 };
    unsigned char testAddr3[4] = { 7, 9, 7, 5 };
    unsigned char * testAddr4 = NULL;
    int arraySize[4] = {7, 8, 4, 0};
    std::string firstName("Ian");
    std::string lastName("Campbell");
    std::string errorFirstName("");
    std::string newFirstName;
    std::string newLastName;
    unsigned char newAddr[IBUTTON_BYTES] = {0};
    bool testResult = false;
        
        
    printf("Testing class Member:\n");
        
    /*
     Testing the default constructor
    */
    printf("\tTesting default constructor... \n\n");
    Member azend;
    Member otherMember;
        
    /*
    Testing the mutators
    */
    printf("\tTesting setters..... \n\n");
        
    /* Normal Tests */
    printf ("\tNormal Tests..... All should pass\n");
    //firstname
    testResult = azend.SetFirstName(firstName.c_str());
    if (testResult == true){
        printf ("\tResult 1 - PASS\n");
        testResult = false;
    }
    else {
        printf ("\tResult 1 - FAIL\n");
    }
    //lastname
    testResult = azend.SetLastName(lastName.c_str());
    if (testResult == true){
        printf ("\tResult 2 - PASS\n");
        testResult = false;
    }
    else {
        printf ("\tResult 2 - FAIL\n");
    }
    //ibutton
    testResult = azend.SetiButtonAddr(testAddr1, arraySize[0]);
    if (testResult == true){
        printf ("\tResult 3 - PASS\n");
        testResult = false;
    }
    else {
        printf ("\tResult 3 - FAIL\n");
    }
    
    /* Error Tests */
    printf ("\tError Tests...... All should fail.\n");
    //firstname high
    printf("\tThese values are too large to be valid\n");
    testResult = azend.SetFirstName("01234567890123456789012345678901234");
    if (testResult == true){
        printf ("\tResult 1 - PASS\n");
        testResult = false;
    }
    else {
        printf ("\tResult 1 - FAIL\n");
    }
    //lastname high
    testResult = azend.SetLastName("holygadimtrappedinacrappyc++programgetmethehelloutofhere");
    if (testResult == true){
        printf ("\tResult 2 - PASS\n");
        testResult = false;
    }
    else {
        printf ("\tResult 2 - FAIL\n");
    }
    //firstname zero
    printf("\tThese are empty strings therefore invalid\n");
    testResult = azend.SetFirstName("");
    if (testResult == true){
        printf ("\tResult 1 - PASS\n");
        testResult = false;
    }
    else {
        printf ("\tResult 1 - FAIL\n");
    }
    //lastname zero
    testResult = azend.SetLastName("");
    if (testResult == true){
        printf ("\tResult 2 - PASS\n");
        testResult = false;
    }
    else {
        printf ("\tResult 2 - FAIL\n");
    }
    //ibutton high
    printf("\tThis iButton Address is too large\n");
    testResult = azend.SetiButtonAddr(testAddr2, arraySize[1]);
    if (testResult == true){
        printf ("\tResult 3 - PASS\n");
        testResult = false;
    }
    else {
        printf ("\tResult 3 - FAIL\n");
    }
    //ibutton low
    printf("\tThis iButton Address is too small\n");
    testResult = azend.SetiButtonAddr(testAddr3, arraySize[2]);
    if (testResult == true){
        printf ("\tResult 3 - PASS\n\n");
        testResult = false;
    }
    else {
        printf ("\tResult 3 - FAIL\n\n");
    }
    
    /*
    Testing the accessors
    */
    //
    printf("\tTesting accessors......  \n\n");
    //Getting First Name
    newFirstName = azend.GetFirstName();
    printf("\tThe new firstname is: %s\n", newFirstName.c_str());
    //Getting Last Name
    newLastName = azend.GetLastName();
    printf("\tThe new lastname is: %s\n", newLastName.c_str());
    //Getting iButton Address
    /*newAddr = azend.GetiButtonAddr();
    for (int i = 0; i < IBUTTON_BYTES; i++){
        printf("%c", newAddr[i]);
    }*/
    printf("\n\n");
        
    /*
    Testing the iButton Comparison
    */
    /*
    printf("\tTesting iButton comparison..... \n\n");
    testResult = azend.CompareiButton(newAddr);
    if (testResult == true){
        printf("The buttons are the same! YAY!\n");
    }
    else if (testResult == false){
        printf("The buttons are not the same :-(\n");
    }
    */
        
    return 0;
}
コード例 #3
0
/**
	Try to match the phone number given with existing numbers in the database.
*/
void CCrudOperations::MatchContactsByEmailAndSipL()
{
    _LIT(KPass, "Pass");
    _LIT(KFail, "Fail");
    _LIT(KEmailMatchOutputFormat1,"Number of email addresses matched: %d -- %s\n");
    _LIT(KEmailMatchOutputFormat2,"Email address lookup took: %d s %03d\n");
    _LIT(KMatchOutputFormat3, "The contact's first name: %S\n");

    // Test Email address matching

    // this address belongs to the 1000th contact item in the database, which has a photo.
    _LIT(KEmailAddressToFind, "*****@*****.**");
    _LIT(KEmailTestTitle, "\nBeginning Email Address Match testing...\n");

    iTest->Printf(KEmailTestTitle);
    TCntPerfTimer timer;
    timer.StartTimer();

    // Search the database...
    CContactItemFieldDef* fieldsToSearch = new (ELeave) CContactItemFieldDef();
    CleanupStack::PushL(fieldsToSearch);
    fieldsToSearch->AppendL(KUidContactFieldEMail);
    CContactIdArray* idArray = iDb->FindLC(KEmailAddressToFind, fieldsToSearch);
    TInt numMatches = idArray->Count();
    iTest->Printf(KEmailMatchOutputFormat1, numMatches, numMatches ? KPass().Ptr() : KFail().Ptr());

    if (numMatches)
    {
        //fetch first contact item in array
        CContactItem* item = iDb->ReadContactLC((*idArray)[0]);
        CContactItemFieldSet& fieldSet = item->CardFields();
        TInt firstNameFieldId = fieldSet.Find(KUidContactFieldGivenName);
        if (firstNameFieldId == KErrNotFound)
        {
            User::Leave(KErrNotFound);
        }
        CContactItemField& firstNameField = fieldSet[firstNameFieldId];
        CContactTextField* firstNameText = firstNameField.TextStorage();
        TPtrC firstName(firstNameText->Text());
        iTest->Printf(KMatchOutputFormat3, &firstName);
        CleanupStack::PopAndDestroy(item);
    }

    timer.StopTimer();
    CleanupStack::PopAndDestroy(2, fieldsToSearch); // and idArray


    TInt result = timer.Result();
    TBuf<64> formattable;
    formattable.Format(KEmailMatchOutputFormat2, result / 1000000, (result / 1000) % 1000);
    iTest->Printf(formattable);

    // reset variables
    fieldsToSearch = NULL;
    idArray = NULL;
    numMatches = 0;
    timer.ResetTimer();
    result = 0;
    formattable.Zero();


    // Test SIP address matching

    // this address belongs to the 1000th contact item in the database, which has a photo.
    _LIT(KSipAddressToFind, "sip:[email protected]");
    _LIT(KSipTestTitle, "\nBeginning SIP Address Match testing...\n");
    _LIT(KSipMatchOutputFormat1,"Number of SIP addresses matched: %d -- %s\n");
    _LIT(KSipMatchOutputFormat2,"SIP address lookup took: %d s %03d\n");

    iTest->Printf(KSipTestTitle);
    timer.StartTimer();

    // Search the database...
    fieldsToSearch = new (ELeave) CContactItemFieldDef();
    CleanupStack::PushL(fieldsToSearch);
    fieldsToSearch->AppendL(KUidContactFieldSIPID);
    idArray = iDb->FindLC(KSipAddressToFind, fieldsToSearch);
    numMatches = idArray->Count();
    iTest->Printf(KSipMatchOutputFormat1, numMatches, numMatches ? KPass().Ptr() : KFail().Ptr());

    if (numMatches)
    {
        //fetch first contact item in array
        CContactItem* item = iDb->ReadContactLC((*idArray)[0]);
        CContactItemFieldSet& fieldSet = item->CardFields();
        TInt firstNameFieldId = fieldSet.Find(KUidContactFieldGivenName);
        if (firstNameFieldId == KErrNotFound)
        {
            User::Leave(KErrNotFound);
        }
        CContactItemField& firstNameField = fieldSet[firstNameFieldId];
        CContactTextField* firstNameText = firstNameField.TextStorage();
        TPtrC firstName(firstNameText->Text());
        iTest->Printf(KMatchOutputFormat3, &firstName);
        CleanupStack::PopAndDestroy(item);
    }

    timer.StopTimer();
    CleanupStack::PopAndDestroy(2, fieldsToSearch); // and idArray

    result = timer.Result();
    formattable.Format(KSipMatchOutputFormat2, result / 1000000, (result / 1000) % 1000);
    iTest->Printf(formattable);
}
コード例 #4
0
QString CUser::toolTip()
{
    if (u == NULL) return "";
    QString r;
    QString s;
    r = "<nobr>";
    r += name(true);
    r += "</nobr>";
    if (u->Uin < UIN_SPECIAL)
        r += s.sprintf("<br><nobr><font size=-1>UIN:</font> %lu</nobr>", u->Uin);
    QString sFirstName = firstName(true);
    QString sLastName = lastName(true);
    if (sFirstName.length() || sLastName.length()){
        r += "<br>";
        r += sFirstName;
        r += " ";
        r += sLastName;
    }
    QString sEmail = email(true);
    if (sEmail.length()){
        r += "<br>";
        r += sEmail;
    }
    if (u->uStatus == ICQ_STATUS_OFFLINE){
        if (u->StatusTime){
            r += "<br>_____________";
            r += "<br><font size=-1>";
            r += i18n("Last online");
            r += ": </font>";
            r += statusTime();
        }
    }else{
        if (u->OnlineTime){
            r += "<br>_____________";
            r += "<br><font size=-1>";
            r += i18n("Online");
            r += ": </font>";
            r += onlineTime();
        }
        if (u->uStatus & (ICQ_STATUS_AWAY | ICQ_STATUS_NA)){
            r += "<br><font size=-1>";
            r += SIMClient::getStatusText(u->uStatus);
            r += ": </font>";
            r += statusTime();
        }
    }
    if (u->IP || u->RealIP){
        r += "<br>";
        r += addr();
    }
    bool isDiv = false;
    PhoneBook::iterator it;
    for (it = u->Phones.begin(); it != u->Phones.end(); it++){
        PhoneInfo *phone = static_cast<PhoneInfo*>(*it);
        if (phone->Type != SMS) continue;
        if (!isDiv){
            r += "<br>_____________";
            isDiv = true;
        }
        r += "<br><img src=\"icon:cell\">";
        r += pClient->from8Bit(u->Uin, phone->getNumber().c_str());
    }
    for (it = u->Phones.begin(); it != u->Phones.end(); it++){
        PhoneInfo *phone = static_cast<PhoneInfo*>(*it);
        if (!phone->Active) continue;
        if (!isDiv){
            r += "<br>_____________";
            isDiv = true;
        }
        r += "<br><img src=\"icon:phone\">";
        r += pClient->from8Bit(u->Uin, phone->getNumber().c_str());
    }
    QString sAutoReply = autoReply(true);
    if (sAutoReply.length()){
        r += "<br>_____________<br>";
        r += sAutoReply;
    }
    QString sClient = client();
    if (!sClient.isEmpty()){
        r += "<br>_____________<br>";
        r += sClient;
    }
    return r;
}