phonebookengines_old/contactsmodel/src/CNTFILT.CPP
changeset 40 b46a585f6909
equal deleted inserted replaced
37:fd64c38c277d 40:b46a585f6909
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <cntfilt.h>
       
    17 #include "CNTSTD.H"
       
    18 
       
    19 
       
    20 EXPORT_C CCntFilter* CCntFilter::NewL()
       
    21 /** Allocates and constructs a default contact database filter.
       
    22 
       
    23 @return Pointer to the new filter. */
       
    24 	{
       
    25 	return new(ELeave) CCntFilter;
       
    26 	};
       
    27 
       
    28 /** Allocates and constructs a default contact database filter. 
       
    29 
       
    30 @return Pointer to the new filter. This is left on 
       
    31 the cleanup stack. 
       
    32 */
       
    33 EXPORT_C CCntFilter* CCntFilter::NewLC()
       
    34 	{
       
    35 	CCntFilter* newFilter=CCntFilter::NewL();
       
    36 	CleanupStack::PushL(newFilter);
       
    37 	return newFilter;
       
    38 	};
       
    39 
       
    40 
       
    41 EXPORT_C CCntFilter* CCntFilter::NewL(const CCntFilter* aFilter)
       
    42 /** Allocates and constructs a contact database filter based on another one. 
       
    43 
       
    44 The state value, type flags, the date/time value and the ID array are copied.
       
    45 
       
    46 @param aFilter Pointer to the filter to copy.
       
    47 @return Pointer to the new filter. */
       
    48 	{
       
    49 	CCntFilter* newFilter=CCntFilter::NewLC(aFilter);
       
    50 	CleanupStack::Pop(); // newFilter
       
    51 	return newFilter;
       
    52 	};
       
    53 
       
    54 
       
    55 EXPORT_C CCntFilter* CCntFilter::NewLC(const CCntFilter* aFilter)
       
    56 /** Allocates and constructs a contact database filter based on another one. 
       
    57 
       
    58 The state value, type flags, the date/time value and the ID array are copied.
       
    59 
       
    60 @param aFilter Pointer to the filter to copy.
       
    61 @return Pointer to the new filter. This is left on the cleanup stack. */
       
    62 	{
       
    63 	CCntFilter* newFilter=new(ELeave) CCntFilter(aFilter);
       
    64 	CleanupStack::PushL(newFilter);
       
    65 	return newFilter;
       
    66 	};
       
    67 
       
    68 /** Allocates and constructs a contact database filter based on a RReadStream. 
       
    69 
       
    70 The state value, type flags, the date/time value and the ID array are copied.
       
    71 
       
    72 @param aStream RReadStream containing object to internalize.
       
    73 @return Pointer to the new filter. This is left on the cleanup stack. 
       
    74 @internalTechnology 
       
    75 */	
       
    76 CCntFilter* CCntFilter::NewLC(RReadStream& aStream)
       
    77 	{
       
    78 	CCntFilter* newFilter=CCntFilter::NewLC();
       
    79 	newFilter->InternalizeL(aStream);	
       
    80 	return newFilter;
       
    81 	}		
       
    82 
       
    83 EXPORT_C void CCntFilter::Reset()
       
    84 /** Resets the filter. The state value is set to EIncludeAllContacts and the contact 
       
    85 ID array is reset. */
       
    86 	{
       
    87 	iInclude=EIncludeAllContacts; 
       
    88 	if (iIds)
       
    89 		iIds->Reset();
       
    90 	};
       
    91 
       
    92 EXPORT_C void CCntFilter::SetIncludeModifiedContacts(TBool aIncludeModified)
       
    93 /** Sets the filter to include only contacts modified since the filter's date/time.
       
    94 
       
    95 @param aIncludeModified ETrue to include only contacts modified since the 
       
    96 filter's date/time, EFalse to include contact items in all states. */
       
    97 	{
       
    98 	if (aIncludeModified)
       
    99 		iInclude = EIncludeModifiedContacts;
       
   100 	else
       
   101 		iInclude = EIncludeAllContacts;
       
   102 	}; 
       
   103 
       
   104 EXPORT_C void CCntFilter::SetIncludeNewContacts(TBool aIncludeNew)
       
   105 /** Sets the filter to include only contacts created since the filter's date/time.
       
   106 
       
   107 @param aIncludeNew ETrue to include only contacts created since the filter's 
       
   108 date/time, EFalse to include contact items in all states. */
       
   109 	{
       
   110 	if (aIncludeNew)
       
   111 		iInclude = EIncludeNewContacts;
       
   112 	else
       
   113 		iInclude = EIncludeAllContacts;
       
   114 	}; 
       
   115 
       
   116 EXPORT_C void CCntFilter::SetIncludeDeletedContacts(TBool aIncludeDeleted)
       
   117 /** Sets the filter to include only contacts deleted since the filter's date/time.
       
   118 
       
   119 @param aIncludeDeleted ETrue to include only contacts deleted since the filter's 
       
   120 date/time, EFalse to include contact items in all states. */
       
   121 	{
       
   122 	if (aIncludeDeleted)
       
   123 		iInclude = EIncludeDeletedContacts;
       
   124 	else
       
   125 		iInclude = EIncludeAllContacts;
       
   126 	}; 
       
   127 
       
   128 EXPORT_C TBool CCntFilter::TestContactFilterType(TUid aTypeUid)
       
   129 /** Tests whether a contact item type, identified by its UID is included in or 
       
   130 excluded from the filter.
       
   131 
       
   132 @param aTypeUid UID which identifies a contact item type. One of: KUidContactCard, 
       
   133 KUidContactGroup, KUidContactCardTemplate or KUidContactOwnCard.
       
   134 @return ETrue if the specified contact type is included in the filter, EFalse 
       
   135 not. */
       
   136 	{	
       
   137 	if (ContactFilterTypeALL())
       
   138 		return ETrue;	// all types are set to be search
       
   139 	else if (aTypeUid == KUidContactCard && ContactFilterTypeCard())
       
   140 		return ETrue;
       
   141 	else if (aTypeUid == KUidContactGroup && ContactFilterTypeGroup())
       
   142 		return ETrue;
       
   143 	else if (aTypeUid == KUidContactCardTemplate && ContactFilterTypeTemplate())
       
   144 		return ETrue;
       
   145 	else if (aTypeUid == KUidContactOwnCard && ContactFilterTypeOwnCard())
       
   146 		return ETrue;
       
   147 	return EFalse;
       
   148 	}
       
   149 
       
   150 EXPORT_C void CCntFilter::SetContactFilterTypeALL(TBool aFilterAllContacts)
       
   151 /** Sets whether all contact item types (contact card groups, contact cards, own 
       
   152 cards and contact card templates) should be included in the filter.
       
   153 
       
   154 @param aFilterAllContacts ETrue if all contact item types should be included 
       
   155 in the filter, EFalse if not. */
       
   156 	{
       
   157 	if (aFilterAllContacts)
       
   158 		iContactType |= EIncludeAllTypes;
       
   159 	else
       
   160 		iContactType &= ~EIncludeAllTypes ;
       
   161 	};
       
   162 
       
   163 
       
   164 EXPORT_C void CCntFilter::SetContactFilterTypeCard(TBool aFileterCards)
       
   165 /** Sets whether contact cards should be included in or excluded from the filter.
       
   166 
       
   167 @param aFileterCards ETrue to include contact cards in the filter, EFalse to exclude them. */		
       
   168 	{
       
   169 	if (aFileterCards)
       
   170 		iContactType |= EContactCards;
       
   171 	else
       
   172 		iContactType &= ~EContactCards;
       
   173 	};
       
   174 
       
   175 EXPORT_C void CCntFilter::SetContactFilterTypeGroup(TBool aFilterGroups)
       
   176 /** Sets whether contact card groups should be included in or excluded from the 
       
   177 filter.
       
   178 
       
   179 @param aFilterGroups ETrue to include contact card groups in the filter, EFalse 
       
   180 to exclude them. */
       
   181 	{
       
   182 	if (aFilterGroups)
       
   183 		iContactType |= EContactGroups;
       
   184 	else
       
   185 		iContactType &= ~EContactGroups;
       
   186 
       
   187 	};
       
   188 
       
   189 EXPORT_C void CCntFilter::SetContactFilterTypeTemplate(TBool aFilterTemplates)
       
   190 /** Sets whether contact card templates should be included in or excluded from 
       
   191 the filter.
       
   192 
       
   193 @param aFilterTemplates ETrue to include contact card templates in the filter, 
       
   194 EFalse to exclude them. */
       
   195 	{
       
   196 	if (aFilterTemplates)
       
   197 		iContactType |= EContactTemplates;
       
   198 	else
       
   199 		iContactType &= ~EContactTemplates;
       
   200 	};
       
   201 
       
   202 EXPORT_C void CCntFilter::SetContactFilterTypeOwnCard(TBool aFilterOwnCard)
       
   203 /** Sets whether own cards should be included in or excluded from the filter.
       
   204 
       
   205 @param aFilterOwnCard ETrue to include own cards in the filter, EFalse to 
       
   206 exclude them. */
       
   207 	{
       
   208 	if (aFilterOwnCard)
       
   209 		iContactType |= EContactOwnCard;
       
   210 	else
       
   211 		iContactType &= ~EContactOwnCard;
       
   212 
       
   213 	};	
       
   214 
       
   215 
       
   216 EXPORT_C CCntFilter::~CCntFilter()
       
   217 /** Deletes all resources owned by the filter prior to its destruction. */
       
   218 	{
       
   219 	delete iIds;
       
   220 	};
       
   221 
       
   222 //	TVersion Version() const;
       
   223 //	virtual TBool IsValid(const Whatever& aWhatever) const; void SetSinceDate(const TTime&);
       
   224 
       
   225 CCntFilter::CCntFilter()
       
   226 	{
       
   227 	};
       
   228 
       
   229 CCntFilter::CCntFilter(const CCntFilter* aFilter)
       
   230 :iIds(aFilter->iIds), iSinceDateTime(aFilter->iSinceDateTime),iInclude(aFilter->iInclude),
       
   231 	iContactType(aFilter->iContactType)
       
   232 	{
       
   233 	};
       
   234 	
       
   235 void CCntFilter::InternalizeL(RReadStream& aStream)
       
   236 /** Internalises a CCntFilter object from a read stream. 
       
   237 @param aStream Stream from which the object should be internalised. */
       
   238 	{
       
   239 	// CContactIdArray* iIds;
       
   240 	if (iIds)
       
   241 		{
       
   242 		delete iIds;		
       
   243 		iIds = NULL;
       
   244 		}
       
   245 		
       
   246 	//TBool CheckIfExists=aStream.ReadInt32L();
       
   247 	if (aStream.ReadInt32L())
       
   248 		{
       
   249 		iIds = CContactIdArray::NewL();		
       
   250 		iIds->InternalizeL(aStream);
       
   251 		}			
       
   252 			
       
   253 	// TTime iSinceDateTime;
       
   254 	TInt64 tempInt64;
       
   255 	aStream >> tempInt64;
       
   256 	iSinceDateTime = TTime(tempInt64);	
       
   257 	
       
   258 	// TInclude	iInclude;
       
   259 	iInclude = static_cast<TInclude>(aStream.ReadInt32L());
       
   260 
       
   261 	// TInt32 iContactType;
       
   262 	iContactType = aStream.ReadInt32L();
       
   263 	
       
   264 	// TAny* iReserved1;
       
   265 	// TAny* iReserved2;	
       
   266 	}
       
   267 
       
   268 void CCntFilter::ExternalizeL(RWriteStream& aStream) const 
       
   269 /** Externalises a CCntFilter object to a write stream.
       
   270 @param aStream Stream to which the object should be externalised. */
       
   271 	{
       
   272 	// CContactIdArray* iIds;
       
   273 	if(iIds)
       
   274 		{
       
   275 		aStream.WriteInt32L(1);
       
   276 		iIds->ExternalizeL(aStream);
       
   277 		}
       
   278 	else
       
   279 		{
       
   280 		aStream.WriteInt32L(0); // Empty array
       
   281 		}
       
   282 			
       
   283 	// TTime iSinceDateTime;	
       
   284 	aStream << iSinceDateTime.Int64();
       
   285 	
       
   286 	// TInclude	iInclude;
       
   287 	aStream.WriteInt32L(iInclude);
       
   288 		
       
   289 	// TInt32 iContactType;
       
   290 	aStream.WriteInt32L(iContactType);	
       
   291 	
       
   292 	// TAny* iReserved1;
       
   293 	// TAny* iReserved2;
       
   294 		
       
   295 	}			
       
   296 
       
   297 /*
       
   298 protected:
       
   299 	TTime            iSinceDate;
       
   300 	TBool            iIncludeChangedContacts; 
       
   301 	TBool            iIncludeDeletedContacts; 
       
   302 	TBool            iIncludeInsertedContacts; 
       
   303 	TAny*	         iReserved1;
       
   304 	TAny*			 iReserved2;
       
   305 */
       
   306 
       
   307