diff -r 000000000000 -r 4a5361db8937 logsui/logsengine/tsrc/stubs/logscntfinder_stub.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/logsui/logsengine/tsrc/stubs/logscntfinder_stub.cpp Tue May 04 12:39:37 2010 +0300 @@ -0,0 +1,469 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "logscntfinder.h" +#include "logslogger.h" + +#include +#include +#include +#include +#include + +// ----------------------------------------------------------------------------- +// LogsCntEntry::richText() +// ----------------------------------------------------------------------------- +// +QString LogsCntText::richText( QString startTag, + QString endTag ) const +{ + QString str = text(); + if ( str.length() > 0 && highlights() > 0 ) { + str.insert( highlights() , endTag ); + str.insert( 0, startTag ); + } + + return str; + +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::LogsCntEntry() +// ----------------------------------------------------------------------------- +// +LogsCntEntry::LogsCntEntry( LogsCntEntryHandle& handle, + quint32 cid ) + : mType( EntryTypeHistory ), mCid( cid ), + mCached( false ),mHandle(&handle) +{ + LogsCntText empty; + mFirstName.append( empty ); + mLastName.append( empty ); + mAvatarPath = "c:\\data\\images\\bg_1.png"; +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::LogsCntEntry() +// ----------------------------------------------------------------------------- +// +LogsCntEntry::LogsCntEntry( quint32 cid ) + : mType( EntryTypeContact ), mCid( cid ), + mCached( false ),mHandle(0) +{ + LogsCntText empty; + mFirstName.append( empty ); + mLastName.append( empty ); +} + +// ----------------------------------------------------------------------------- +// copy LogsCntEntry::LogsCntEntry() +// ----------------------------------------------------------------------------- +// +LogsCntEntry::LogsCntEntry( const LogsCntEntry& entry ) + : mType(entry.mType), + mCid(entry.mCid), + mFirstName(entry.mFirstName), + mLastName(entry.mLastName), + mCached(entry.mCached), + mHandle(entry.mHandle), + mPhoneNumber(entry.mPhoneNumber) +{ +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::~LogsCntEntry() +// ----------------------------------------------------------------------------- +// +LogsCntEntry::~LogsCntEntry() +{ +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::LogsCntEntry() +// ----------------------------------------------------------------------------- +// +const LogsCntTextList& LogsCntEntry::firstName() const +{ + return mFirstName; +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::lastName() +// ----------------------------------------------------------------------------- +// +const LogsCntTextList& LogsCntEntry::lastName() const +{ + return mLastName; +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::avatarPath() +// ----------------------------------------------------------------------------- +// +const QString& LogsCntEntry::avatarPath() const +{ + return mAvatarPath; +} + + +// ----------------------------------------------------------------------------- +// LogsCntEntry::phoneNumber() +// ----------------------------------------------------------------------------- +// +const LogsCntText& LogsCntEntry::phoneNumber() const +{ + return mPhoneNumber; +} + + +// ----------------------------------------------------------------------------- +// LogsCntEntry::contactId() +// ----------------------------------------------------------------------------- +// +quint32 LogsCntEntry::contactId() const +{ + return mCid; +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::handle() +// ----------------------------------------------------------------------------- +// +LogsCntEntryHandle* LogsCntEntry::handle() const +{ + return mHandle; +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::setFirstName() +// ----------------------------------------------------------------------------- +// +void LogsCntEntry::setFirstName( const QString& name ) +{ + mCached=true; + mFirstName.clear(); + doSetText( name, mFirstName ); +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::setLastName() +// ----------------------------------------------------------------------------- +// +void LogsCntEntry::setLastName( const QString& name ) +{ + mCached=true; + mLastName.clear(); + doSetText( name, mLastName ); +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::setPhoneNumber() +// ----------------------------------------------------------------------------- +// +void LogsCntEntry::setPhoneNumber( const QString& number ) +{ + mPhoneNumber.mText = number; +} + +// ----------------------------------------------------------------------------- +// LogsCntEntry::doSetText() +// ----------------------------------------------------------------------------- +// +void LogsCntEntry::doSetText( const QString& text, LogsCntTextList& textlist ) +{ + const QChar separ(' '); + QStringList parts = text.split( separ, QString::SkipEmptyParts ); + for( int i=0;i LogsCntFinder::LogsCntFinder()" ) + + // Create manager ourselves, object takes care of deletion when registering + // as parent. + QMap dummyParams; + mContactManager = new QContactManager("symbian", dummyParams, this); + + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::LogsCntFinder()" ) +} + +// ----------------------------------------------------------------------------- +// LogsCntFinder::LogsCntFinder() +// ----------------------------------------------------------------------------- +// +LogsCntFinder::LogsCntFinder(QContactManager& contactManager) +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::LogsCntFinder(), cntmgr from client" ) + + mContactManager = &contactManager; + + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::LogsCntFinder()" ) +} + + +// ----------------------------------------------------------------------------- +// LogsCntFinder::~LogsCntFinder() +// ----------------------------------------------------------------------------- +// +LogsCntFinder::~LogsCntFinder() +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::~LogsCntFinder()" ) + + qDeleteAll( mResults ); + qDeleteAll( mHistoryEvents ); + + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::~LogsCntFinder()" ) +} + + +// ----------------------------------------------------------------------------- +// LogsCntFinder::predictiveSearchQuery +// ----------------------------------------------------------------------------- +// +void LogsCntFinder::predictiveSearchQuery( const QString& pattern ) +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::predictiveSearchQuery()" ) + LOGS_QDEBUG_2( "logs [FINDER] pattern= ", pattern ) + + bool patternChanged = pattern != mCurrentPredictivePattern; + mCurrentPredictivePattern = pattern; + + if ( !mCurrentPredictivePattern.isEmpty() && patternChanged ) { + qDeleteAll( mResults ); + mResults.clear(); + doPredictiveHistoryQuery(); + doPredictiveContactQuery(); + } + //emit queryReady(); // commented off to ease testing + + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::predictiveSearchQuery()" ) +} + +// ----------------------------------------------------------------------------- +// LogsCntFinder::doPredictiveHistoryQuery +// ----------------------------------------------------------------------------- +// +void LogsCntFinder::doPredictiveHistoryQuery() +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::doPredictiveHistoryQuery()" ) + + QListIterator iter(mHistoryEvents); + + while( iter.hasNext() ) { + LogsCntEntry* e = iter.next(); + if ( e->match( mCurrentPredictivePattern ) ) { + LogsCntEntry* entry = new LogsCntEntry( *e ); + mResults.append( entry ); + } + } + + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::doPredictiveHistoryQuery()" ) +} + +// ----------------------------------------------------------------------------- +// LogsCntFinder::doPredictiveContactQuery +// ----------------------------------------------------------------------------- +// +void LogsCntFinder::doPredictiveContactQuery() +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::doPredictiveContactQuery()" ) +/* + int index = 0; + while( index < cntIds.count() ) { + LogsCntEntry* entry = new LogsCntEntry( cntIds.at( index++ ) ); + mResults.append( entry ); + } + */ + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::doPredictiveContactQuery()" ) + +} + + +// ----------------------------------------------------------------------------- +// LogsCntFinder::resultsCount +// ----------------------------------------------------------------------------- +// +int LogsCntFinder::resultsCount() const +{ + return mResults.count(); +} + +// ----------------------------------------------------------------------------- +// LogsCntFinder::resultAt +// ----------------------------------------------------------------------------- +// +const LogsCntEntry& LogsCntFinder::resultAt( int index ) +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::resultAt()" ) + LOGS_QDEBUG_2( "logs [FINDER] index=", index ) + + LogsCntEntry* entry = mResults.at( index ); + if ( !entry->isCached() ) { + QContact contact = mContactManager->contact( entry->contactId() ); + QContactName contactName = contact.detail( QContactName::DefinitionName ); + entry->setFirstName( contactName.value( QContactName::FieldFirst ) ); + entry->setLastName( contactName.value( QContactName::FieldLast ) ); + QContactPhoneNumber contactPhoneNumber = + contact.detail( QContactPhoneNumber::DefinitionName ); + entry->setPhoneNumber( + contactPhoneNumber.value( QContactPhoneNumber::FieldNumber ) ); + + entry->setHighlights( mCurrentPredictivePattern ); + } + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::resultAt()" ) + return *entry; + +} + +// ----------------------------------------------------------------------------- +// LogsCntFinder::insertEntry +// ----------------------------------------------------------------------------- +// +void LogsCntFinder::insertEntry( int index, LogsCntEntry* entry ) +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::insertEntry()" ) + LOGS_QDEBUG_4( "logs [FINDER] handle=", entry->handle()," to index ", index ) + + mHistoryEvents.insert( index, entry ); + + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::insertEntry()" ) +} + +// ----------------------------------------------------------------------------- +// LogsCntFinder::getEntry +// ----------------------------------------------------------------------------- +// +LogsCntEntry* LogsCntFinder::getEntry( const LogsCntEntryHandle& handle ) const +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::getEntry()" ) + return doGetEntry( mHistoryEvents, handle ); +} + +// ----------------------------------------------------------------------------- +// LogsCntFinder::doGetEntry +// ----------------------------------------------------------------------------- +// +LogsCntEntry* LogsCntFinder::doGetEntry( const LogsCntEntryList& list, + const LogsCntEntryHandle& handle ) const +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::doGetEntry()" ) + LOGS_QDEBUG_2( "logs [FINDER] handle= ", &handle ) + + LogsCntEntry* entry = 0; + QListIterator iter(list); + + while( iter.hasNext() && !entry ) { + LogsCntEntry* e = iter.next(); + entry = e->handle() == &handle ? e : 0; + } + + LOGS_QDEBUG_2( "logs [FINDER] found=", (entry!=0) ) + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::doGetEntry()" ) + return entry; +} + +// ----------------------------------------------------------------------------- +// LogsCntFinder::deleteEntry +// ----------------------------------------------------------------------------- +// +void LogsCntFinder::deleteEntry( const LogsCntEntryHandle& handle ) +{ + LOGS_QDEBUG( "logs [FINDER] -> LogsCntFinder::deleteEntry()" ) + LOGS_QDEBUG_2( "logs [FINDER] handle= ", &handle ) + + LogsCntEntry* toRemoveHistoryEv = doGetEntry( mHistoryEvents, handle ); + mHistoryEvents.removeOne( toRemoveHistoryEv ); + delete toRemoveHistoryEv; + + LOGS_QDEBUG( "logs [FINDER] <- LogsCntFinder::deleteEntry()" ) + +} + + + +