phoneuis/easydialing/tsrc/edta/src/edta_createtestcontactbase.cpp
branchRCL_3
changeset 3 8871b09be73b
equal deleted inserted replaced
2:c84cf270c54f 3:8871b09be73b
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Easy dialing test application.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <cntdb.h> 
       
    21 #include <cntitem.h> 
       
    22 #include <cntfldst.h> 
       
    23 #include <cpbkcontactitem.h>
       
    24 #include <cpbkcontactengine.h>
       
    25 #include "edta_debugprint.h"
       
    26 
       
    27 
       
    28 /*
       
    29  * Number of contacts in contactdata array.
       
    30  */
       
    31 const TInt nbr_of_contacts = 15;
       
    32 
       
    33 /*
       
    34  * Contact data contains contact data as text strings.
       
    35  * Each contact takes six line:
       
    36  * - first name
       
    37  * - last name
       
    38  * - cell number
       
    39  * - home number
       
    40  * - company name
       
    41  * - e-mail address
       
    42  */
       
    43 const char* contactdata[] = 
       
    44 {
       
    45     "Dummy",
       
    46     "Contact",
       
    47     "+1056439939",
       
    48     "035558756",
       
    49     "Ericsson",
       
    50     "dummy.contact@ericsson.sw",
       
    51     
       
    52     "Jaakko",
       
    53     "Helanti",
       
    54     "+358405287761",
       
    55     "034447611",
       
    56     "Nokia",
       
    57     "jaakko.helanti@nokia.com",
       
    58     
       
    59     "Stan",
       
    60     "Laurel",
       
    61     "+0104438839992",
       
    62     "+0104438839000",
       
    63     "MGM",
       
    64     "stan.laurel@heaven.com",
       
    65     
       
    66     "Oliver",
       
    67     "Hardy",
       
    68     "+01078398927",
       
    69     "+10364537882",
       
    70     "MGM",
       
    71     "oliver.hardy@heaven.com",
       
    72     
       
    73     "Harold",
       
    74     "Lloyd",
       
    75     "+102843947",
       
    76     "+10290503958",
       
    77     "Universal",
       
    78     "harold.lloyd@universal.com",
       
    79     
       
    80     "Tauno",
       
    81     "Palo",
       
    82     "+358405557631",
       
    83     "014445466",
       
    84     "Suomi Filmi",
       
    85     "tauno.palo@gmail.com",
       
    86     
       
    87     "Tea",
       
    88     "Ista",
       
    89     "+358475554590",
       
    90     "018723195",
       
    91     "Helsingin Kaupungin Teatteri",
       
    92     "tea.ista@cultureclub.com",
       
    93 
       
    94     "Ansa",
       
    95     "Ikonen",
       
    96     "+358471134099",
       
    97     "012388192",
       
    98     "Suomi Filmi",
       
    99     "ansa.ikonen@gmail.com",
       
   100 
       
   101     "Bertil",
       
   102     "Nystrom",
       
   103     "+35866377334",
       
   104     "074500998",
       
   105     "Rovaniemen Viuluveistämö",
       
   106     "bertil.nystrom@rvv.com",
       
   107         
       
   108     "",
       
   109     "Onlylastname",
       
   110     "+3585556743",
       
   111     "+35835552727",
       
   112     "",
       
   113     "",
       
   114     
       
   115     "Onlyfirstname",
       
   116     "",
       
   117     "+358405559874",
       
   118     "035553747",
       
   119     "",
       
   120     "",
       
   121        
       
   122     "",
       
   123     "Two-Part Lastname",
       
   124     "+358405557432",
       
   125     "",
       
   126     "",
       
   127     "",
       
   128     
       
   129     "",
       
   130     "",
       
   131     "+35866377334",
       
   132     "074500998",
       
   133     "Just Companyname",
       
   134     "john.doe@justcompanyname.com",
       
   135         
       
   136     "One",
       
   137     "Number",
       
   138     "",
       
   139     "075553266",
       
   140     "Idaho",
       
   141     "",
       
   142     
       
   143     "No",
       
   144     "Number",
       
   145     "",
       
   146     "",
       
   147     "Ericsson",
       
   148     "no.number@ericsson.com",    
       
   149 };
       
   150 
       
   151 
       
   152 HBufC* CreateFieldStringL(TInt aIx)
       
   153     {
       
   154     const char* str = contactdata[aIx];
       
   155     TInt len = 0;
       
   156     
       
   157     while (str[len] != '\0')
       
   158         {
       
   159         len++;
       
   160         }
       
   161     
       
   162     if ( len == 0 )
       
   163         {
       
   164         return NULL;
       
   165         }
       
   166     
       
   167     HBufC *field = HBufC::NewL( len );
       
   168     TPtr des = field->Des();
       
   169     des.SetLength( len );
       
   170     
       
   171     for (TInt i = 0; i < len; i++)
       
   172         {
       
   173         des[i] = (TChar) str[i];
       
   174         }
       
   175     
       
   176     return field;
       
   177     }
       
   178 
       
   179 
       
   180 void AddFieldStringL( CPbkContactItem* aContact, TInt aIx, TInt aFieldId )
       
   181     {
       
   182     HBufC* fieldName = CreateFieldStringL( aIx );
       
   183     
       
   184     if ( fieldName ) 
       
   185         {
       
   186         CleanupStack::PushL( fieldName );
       
   187         aContact->FindField( aFieldId )->TextStorage()->SetTextL( *fieldName );
       
   188         CleanupStack::PopAndDestroy(fieldName); 
       
   189         }
       
   190     }
       
   191 
       
   192 
       
   193 void AddContactL(CPbkContactEngine* engine, TInt aIx)
       
   194     {
       
   195     CPbkContactItem* contact = engine->CreateEmptyContactL();
       
   196     CleanupStack::PushL( contact );
       
   197     
       
   198     AddFieldStringL( contact, aIx * 6 + 0, EPbkFieldIdFirstName );
       
   199     AddFieldStringL( contact, aIx * 6 + 1, EPbkFieldIdLastName );
       
   200     AddFieldStringL( contact, aIx * 6 + 2, EPbkFieldIdPhoneNumberMobile );
       
   201     AddFieldStringL( contact, aIx * 6 + 3, EPbkFieldIdPhoneNumberGeneral );
       
   202     AddFieldStringL( contact, aIx * 6 + 4, EPbkFieldIdCompanyName );
       
   203     AddFieldStringL( contact, aIx * 6 + 5, EPbkFieldIdEmailAddress );
       
   204         
       
   205     engine->AddNewContactL( *contact );
       
   206     
       
   207     CleanupStack::PopAndDestroy( contact );
       
   208     }
       
   209 
       
   210 
       
   211 
       
   212 // ---------------------------------------------------------
       
   213 // CreateTestContactDatabaseL
       
   214 //
       
   215 // Creates a test contact database if it hasn't been created yet.
       
   216 // The existence of test base is done through testing if there
       
   217 // is a contact matching with word "Dummy". Test data base has
       
   218 // a contact for Mr Dummy Contact.
       
   219 // This is the primary function of this file. 
       
   220 // ---------------------------------------------------------
       
   221 //
       
   222 TInt CreateTestContactDatabaseL()
       
   223     {
       
   224     DebugPrintF(_L("CreateTestContactDatabaseL: Contacts creation started.."));
       
   225 
       
   226     CPbkContactEngine* engine = CPbkContactEngine::NewL();
       
   227     CleanupStack::PushL( engine );
       
   228     
       
   229     _LIT(KDummyContact, "Dummy");
       
   230         
       
   231     CContactIdArray* findings = engine->FindLC( KDummyContact );
       
   232     
       
   233     // If dummy contact is found, the test database has already been created. 
       
   234     if (findings->Count() > 0)
       
   235         {
       
   236         CleanupStack::PopAndDestroy( findings );
       
   237         CleanupStack::PopAndDestroy( engine );
       
   238         DebugPrintF(_L("CreateTestContactDatabaseL: Database already set up"));
       
   239         return 0;
       
   240         }
       
   241     
       
   242     CleanupStack::PopAndDestroy( findings );
       
   243 
       
   244     for (TInt i = 0; i < nbr_of_contacts; i++ )
       
   245         {
       
   246         AddContactL( engine, i );
       
   247         }
       
   248     
       
   249     CleanupStack::PopAndDestroy(engine);
       
   250 
       
   251     DebugPrintF(_L("CreateTestContactDatabaseL: Contacts creation completed, number of contacts: %d"), nbr_of_contacts );
       
   252 
       
   253     return nbr_of_contacts;
       
   254     }
       
   255 
       
   256 
       
   257 
       
   258 
       
   259 
       
   260 
       
   261 
       
   262 
       
   263 
       
   264 
       
   265 
       
   266