00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "ContactsModelDocument.h"
00032 #include "ContactsModelAppUi.h"
00033
00034 #include <cntfilt.h>
00035 #include <cntitem.h>
00036
00037 const TInt KBufferSize = 256;
00038
00039
00040
00041
00042 CContactsModelDocument::CContactsModelDocument(CEikApplication& aApp)
00043 : CAknDocument(aApp)
00044 {
00045 }
00046
00047
00048 CContactsModelDocument::~CContactsModelDocument()
00049 {
00050 delete iContacts;
00051 delete iTextDef;
00052 }
00053
00054
00055 void CContactsModelDocument::ConstructL()
00056 {
00057 iContacts = NULL;
00058 UpdateContactsL();
00059
00060 iTextDef = CContactTextDef::NewL();
00061
00062 iTextDef->AppendL(TContactTextDefItem(KUidContactFieldGivenName, _L(" ")));
00063 iTextDef->AppendL(TContactTextDefItem(KUidContactFieldFamilyName));
00064 }
00065
00066
00067 CContactsModelDocument* CContactsModelDocument::NewL(
00068 CEikApplication& aApp)
00069 {
00070 CContactsModelDocument* self = new (ELeave) CContactsModelDocument( aApp );
00071 CleanupStack::PushL( self );
00072 self->ConstructL();
00073 CleanupStack::Pop();
00074
00075 return self;
00076 }
00077
00078
00079 HBufC * CContactsModelDocument::GetItemL(TInt anIndex)
00080 {
00081
00082 CContactDatabase* contactsDb = CContactDatabase::OpenL();
00083 CleanupStack::PushL(contactsDb);
00084
00085 TBuf<KBufferSize> buf;
00086
00087 if((*iContacts).Count() >= anIndex)
00088 contactsDb->ReadContactTextDefL((*iContacts)[anIndex], buf, iTextDef);
00089
00090 CleanupStack::PopAndDestroy();
00091 return buf.AllocL();
00092 }
00093
00094
00095 TInt CContactsModelDocument::ItemCount()
00096 {
00097 return iContacts->Count();
00098 }
00099
00100 void CContactsModelDocument::UpdateContactsL()
00101 {
00102
00103
00104 CContactDatabase* contactsDb = CContactDatabase::OpenL();
00105 CleanupStack::PushL(contactsDb);
00106
00107 CCntFilter *filter = CCntFilter::NewLC();
00108
00109
00110 filter->SetContactFilterTypeALL(EFalse);
00111 filter->SetContactFilterTypeCard(ETrue);
00112
00113 contactsDb->FilterDatabaseL(*filter);
00114
00115 if(iContacts)
00116 {
00117 delete iContacts;
00118 iContacts = NULL;
00119 }
00120 iContacts = CContactIdArray::NewL(filter->iIds);
00121
00122 CleanupStack::PopAndDestroy(2);
00123 }
00124
00125 TInt CContactsModelDocument::ImportL(RReadStream& aReadStream)
00126 {
00127
00128 CContactDatabase* contactsDb = CContactDatabase::OpenL();
00129 CleanupStack::PushL(contactsDb);
00130
00131 TBool result = EFalse;
00132 TUid p1;
00133 p1.iUid = KVersitEntityUidVCard;
00134 CArrayPtr<CContactItem>* imported = contactsDb->ImportContactsL(p1,
00135 aReadStream,
00136 result,
00137 CContactDatabase::ETTFormat);
00138 imported->ResetAndDestroy();
00139 delete imported;
00140
00141 CleanupStack::PopAndDestroy();
00142
00143 return result?KErrNone:KErrGeneral;
00144 }
00145
00146 void CContactsModelDocument::ExportL(RWriteStream& aWriteStream, TInt aExportItem)
00147 {
00148
00149 CContactDatabase* contactsDb = CContactDatabase::OpenL();
00150 CleanupStack::PushL(contactsDb);
00151
00152 CContactIdArray* exportContacts = CContactIdArray::NewL();
00153 CleanupStack::PushL(exportContacts);
00154
00155 if((*iContacts).Count() >= aExportItem)
00156 exportContacts->AddL( (*iContacts)[aExportItem] );
00157
00158 TUid p1;
00159 p1.iUid = KVersitEntityUidVCard;
00160 contactsDb->ExportSelectedContactsL(p1,
00161 *exportContacts,
00162 aWriteStream,
00163 CContactDatabase::EExcludeUid);
00164
00165 CleanupStack::PopAndDestroy(2);
00166 }
00167
00168
00169
00170
00171
00172
00173 CEikAppUi* CContactsModelDocument::CreateAppUiL()
00174 {
00175 return new (ELeave) CContactsModelAppUi;
00176 }
00177
00178