logsui/logsengine/src/logsmatchesmodel.cpp
branchGCC_SURGE
changeset 12 d56c5d6796ca
parent 11 64a47b97e1e1
child 14 f27aebe284bb
equal deleted inserted replaced
5:8d8fb0db2489 12:d56c5d6796ca
   163     if ( event ){
   163     if ( event ){
   164         return LogsAbstractModel::createMessage(item);
   164         return LogsAbstractModel::createMessage(item);
   165     }
   165     }
   166     const LogsMatchesModelItemContainer& matchItem = 
   166     const LogsMatchesModelItemContainer& matchItem = 
   167         static_cast<const LogsMatchesModelItemContainer&>( item ); 
   167         static_cast<const LogsMatchesModelItemContainer&>( item ); 
   168     LogsMessage* logsMessage = new LogsMessage(matchItem.contact(), matchItem.number(),matchItem.contactName());
   168     LogsMessage* logsMessage = new LogsMessage(
       
   169         matchItem.contact(), matchItem.number(),matchItem.contactNameSimple());
   169     if (!logsMessage->isMessagingAllowed()) {
   170     if (!logsMessage->isMessagingAllowed()) {
   170         delete logsMessage;
   171         delete logsMessage;
   171         logsMessage = 0;
   172         logsMessage = 0;
   172     }
   173     }
   173     QVariant var = qVariantFromValue(logsMessage);
   174     QVariant var = qVariantFromValue(logsMessage);
   293     
   294     
   294     if ( removed ){
   295     if ( removed ){
   295         forceSearchQuery();
   296         forceSearchQuery();
   296     }
   297     }
   297     LOGS_QDEBUG( "logs [ENG] <- LogsMatchesModel::eventsRemoved()" );
   298     LOGS_QDEBUG( "logs [ENG] <- LogsMatchesModel::eventsRemoved()" );
       
   299 }
       
   300 
       
   301 // -----------------------------------------------------------------------------
       
   302 // 
       
   303 // -----------------------------------------------------------------------------
       
   304 //
       
   305 void LogsMatchesModel::eventsResetted()
       
   306 {
       
   307     LOGS_QDEBUG( "logs [ENG] -> LogsMatchesModel::eventsResetted()" );
       
   308     
       
   309     QMap<LogsCntEntryHandle*, LogsEvent*> unusedEvents = mSearchEvents;
       
   310     for ( int i = 0; i < mParentModel.rowCount(); ++i ){
       
   311         LogsEvent* event = qVariantValue<LogsEvent*>( 
       
   312             mParentModel.data( mParentModel.index(i, 0), LogsModel::RoleFullEvent ) );
       
   313         if ( event ){
       
   314             QObject* key = mSearchEvents.key(event);
       
   315             if ( key ){
       
   316                 unusedEvents.remove(key);
       
   317             } else {
       
   318                 addEventForSearching(i, *event);
       
   319             }
       
   320         }
       
   321     }
       
   322     
       
   323     QMap<LogsCntEntryHandle*, LogsEvent*>::iterator unusedIt;
       
   324     for (unusedIt = unusedEvents.begin(); unusedIt != unusedEvents.end(); ++unusedIt){
       
   325         mLogsCntFinder->deleteEntry(*unusedIt.key());
       
   326         mSearchEvents.remove(unusedIt.key());
       
   327     }
       
   328     
       
   329     forceSearchQuery();
       
   330     
       
   331     LOGS_QDEBUG( "logs [ENG] <- LogsMatchesModel::eventsResetted()" );
   298 }
   332 }
   299 
   333 
   300 // -----------------------------------------------------------------------------
   334 // -----------------------------------------------------------------------------
   301 //
   335 //
   302 // -----------------------------------------------------------------------------
   336 // -----------------------------------------------------------------------------
   313                  this, SLOT(eventsUpdated(const QModelIndex&,const QModelIndex&)));
   347                  this, SLOT(eventsUpdated(const QModelIndex&,const QModelIndex&)));
   314         connect( &mParentModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), 
   348         connect( &mParentModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), 
   315                  this, SLOT(eventsAdded(const QModelIndex&,int,int)));
   349                  this, SLOT(eventsAdded(const QModelIndex&,int,int)));
   316         connect( &mParentModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), 
   350         connect( &mParentModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), 
   317                  this, SLOT(eventsRemoved(const QModelIndex&,int,int)));
   351                  this, SLOT(eventsRemoved(const QModelIndex&,int,int)));
   318         connect( &mParentModel, SIGNAL(modelReset()), this, SLOT(doModelReset()));
   352         connect( &mParentModel, SIGNAL(modelReset()), this, SLOT(eventsResetted()));
   319         readEvents(0, mParentModel.rowCount());
   353         readEvents(0, mParentModel.rowCount());
   320         mIconManager = new LogsThumbIconManager();
   354         mIconManager = new LogsThumbIconManager();
   321         connect(mIconManager, SIGNAL(contactIconReady(int)),
   355         connect(mIconManager, SIGNAL(contactIconReady(int)),
   322                 this, SLOT(updateContactIcon(int)));
   356                 this, SLOT(updateContactIcon(int)));
   323     }
   357     }
   371 {
   405 {
   372    for ( int i = first; i < mParentModel.rowCount() && i <= last; ++i ){
   406    for ( int i = first; i < mParentModel.rowCount() && i <= last; ++i ){
   373         LogsEvent* event = qVariantValue<LogsEvent*>( 
   407         LogsEvent* event = qVariantValue<LogsEvent*>( 
   374                 mParentModel.data( mParentModel.index(i, 0), LogsModel::RoleFullEvent ) );
   408                 mParentModel.data( mParentModel.index(i, 0), LogsModel::RoleFullEvent ) );
   375         if ( event ){
   409         if ( event ){
   376             QObject* entryHandle = new QObject(this);
   410             addEventForSearching(i, *event);
   377             LogsCntEntry* entry = new LogsCntEntry(*entryHandle, 0);
       
   378             updateSearchEntry(*entry, *event);
       
   379             mLogsCntFinder->insertEntry(i, entry);
       
   380             mSearchEvents.insert(entryHandle, event);
       
   381         }
   411         }
   382     }
   412     }
   383 }
   413 }
   384 
   414 
   385 // -----------------------------------------------------------------------------
   415 // -----------------------------------------------------------------------------
   445 //
   475 //
   446 // -----------------------------------------------------------------------------
   476 // -----------------------------------------------------------------------------
   447 //
   477 //
   448 void LogsMatchesModel::doModelReset()
   478 void LogsMatchesModel::doModelReset()
   449 {
   479 {
       
   480     LOGS_QDEBUG( "logs [ENG] -> LogsMatchesModel::doModelReset()" );
   450     qDeleteAll(mMatches);
   481     qDeleteAll(mMatches);
   451     mMatches.clear();
   482     mMatches.clear();
   452     mResultCount = 0;
   483     mResultCount = 0;
   453     reset();
   484     reset();
       
   485     LOGS_QDEBUG( "logs [ENG] <- LogsMatchesModel::doModelReset()" );
   454 }
   486 }
   455 
   487 
   456 // -----------------------------------------------------------------------------
   488 // -----------------------------------------------------------------------------
   457 //
   489 //
   458 // -----------------------------------------------------------------------------
   490 // -----------------------------------------------------------------------------
   510 
   542 
   511 // -----------------------------------------------------------------------------
   543 // -----------------------------------------------------------------------------
   512 //
   544 //
   513 // -----------------------------------------------------------------------------
   545 // -----------------------------------------------------------------------------
   514 //
   546 //
       
   547 void LogsMatchesModel::addEventForSearching(int index, LogsEvent& event)
       
   548 {
       
   549      QObject* entryHandle = new QObject(this);
       
   550      LogsCntEntry* entry = new LogsCntEntry(*entryHandle, 0);
       
   551      updateSearchEntry(*entry, event);
       
   552      mLogsCntFinder->insertEntry(index, entry);
       
   553      mSearchEvents.insert(entryHandle, &event);
       
   554 }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 // -----------------------------------------------------------------------------
       
   559 //
   515 LogsMatchesModelItemContainer::LogsMatchesModelItemContainer(
   560 LogsMatchesModelItemContainer::LogsMatchesModelItemContainer(
   516         LogsAbstractModel& parentModel,
   561         LogsAbstractModel& parentModel,
   517 		LogsThumbIconManager& thumbIconManager, 
   562 		LogsThumbIconManager& thumbIconManager, 
   518         int resultIndex) : 
   563         int resultIndex) : 
   519     LogsModelItemContainer(),
   564     LogsModelItemContainer(),
   592 
   637 
   593 // -----------------------------------------------------------------------------
   638 // -----------------------------------------------------------------------------
   594 //
   639 //
   595 // -----------------------------------------------------------------------------
   640 // -----------------------------------------------------------------------------
   596 //
   641 //
       
   642 QString LogsMatchesModelItemContainer::contactNameSimple() const
       
   643 {
       
   644    return mContactNameSimple;
       
   645 }
       
   646 
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 // -----------------------------------------------------------------------------
       
   650 //
   597 bool LogsMatchesModelItemContainer::isNull() const
   651 bool LogsMatchesModelItemContainer::isNull() const
   598 {
   652 {
   599     return ( !mEvent && !mContactId );
   653     return ( !mEvent && !mContactId );
   600 }
   654 }
   601 
   655 
   649 void LogsMatchesModelItemContainer::updateData(const LogsCntEntry& entry)
   703 void LogsMatchesModelItemContainer::updateData(const LogsCntEntry& entry)
   650 {
   704 {
   651     if ( mEvent ){
   705     if ( mEvent ){
   652         mFormattedCallerId = getFormattedCallerId(entry);
   706         mFormattedCallerId = getFormattedCallerId(entry);
   653     } else if ( mContactId > 0 ){
   707     } else if ( mContactId > 0 ){
   654         getFormattedContactInfo(entry, mContactName, mContactNumber);
   708         getFormattedContactInfo(entry, mContactName, mContactNameSimple, mContactNumber);
   655         mAvatarPath.clear();
   709         mAvatarPath.clear();
   656         mAvatarPath = entry.avatarPath();
   710         mAvatarPath = entry.avatarPath();
   657     }
   711     }
   658 }
   712 }
   659 
   713 
   673 //
   727 //
   674 QString LogsMatchesModelItemContainer::getFormattedCallerId(
   728 QString LogsMatchesModelItemContainer::getFormattedCallerId(
   675         const LogsCntEntry& entry) const
   729         const LogsCntEntry& entry) const
   676 {    
   730 {    
   677     QString callerId;
   731     QString callerId;
   678     foreach( LogsCntText name, entry.firstName() ) {
   732     getFormattedName(callerId, entry.firstName());
   679         callerId.append( name.richText() );
       
   680         if ( name.text().length() > 0 ) {
       
   681             callerId.append(" ");
       
   682         }
       
   683     }
       
   684     
   733     
   685     if  ( callerId.length() == 0 ) {
   734     if  ( callerId.length() == 0 ) {
   686         callerId = entry.phoneNumber().richText();
   735         callerId = entry.phoneNumber().richText();
   687     }
   736     }
   688 
   737 
   693 //
   742 //
   694 // -----------------------------------------------------------------------------
   743 // -----------------------------------------------------------------------------
   695 //
   744 //
   696 void LogsMatchesModelItemContainer::getFormattedContactInfo( 
   745 void LogsMatchesModelItemContainer::getFormattedContactInfo( 
   697         const LogsCntEntry& entry,
   746         const LogsCntEntry& entry,
   698         QString& contactName, 
   747         QString& contactName,
       
   748         QString& contactNameSimple,
   699         QString& contactNumber ) const
   749         QString& contactNumber ) const
   700 {
   750 {
   701     contactName.clear();
   751     contactName.clear();
   702     foreach( LogsCntText name, entry.firstName() ) {
   752     
   703         contactName.append( name.richText() );
   753     getFormattedName(contactName, contactNameSimple, entry.firstName());
       
   754     getFormattedName(contactName, contactNameSimple, entry.lastName());
       
   755 
       
   756     contactName = contactName.trimmed();
       
   757     contactNameSimple = contactNameSimple.trimmed();
       
   758     contactNumber = entry.phoneNumber().text();
       
   759 }
       
   760 
       
   761 // -----------------------------------------------------------------------------
       
   762 //
       
   763 // -----------------------------------------------------------------------------
       
   764 //
       
   765 void  LogsMatchesModelItemContainer::getFormattedName(
       
   766     QString& formattedName, const QList<LogsCntText>& list) const
       
   767 {
       
   768     foreach( LogsCntText name, list ) {
   704         if ( name.text().length() > 0 ) {
   769         if ( name.text().length() > 0 ) {
   705             contactName.append(" ");
   770             formattedName.append(name.richText());   
   706         }
   771             formattedName.append(" ");
   707     }
   772         }
   708     
   773     }
   709     foreach( LogsCntText lastname, entry.lastName() ) {
   774 }
   710         contactName.append( lastname.richText() );
   775 
   711         if ( lastname.text().length() > 0 ) {
   776 // -----------------------------------------------------------------------------
   712             contactName.append(" ");
   777 //
   713         }
   778 // -----------------------------------------------------------------------------
   714     }
   779 //
   715     contactName = contactName.trimmed();
   780 void  LogsMatchesModelItemContainer::getFormattedName(
   716     
   781     QString& formattedName, QString& formattedNameSimple,
   717     contactNumber = entry.phoneNumber().richText();    
   782     const QList<LogsCntText>& list) const
   718 }
   783 {
       
   784     foreach( LogsCntText name, list ) {
       
   785         if ( name.text().length() > 0 ) {
       
   786             formattedName.append(name.richText());   
       
   787             formattedName.append(" ");
       
   788             formattedNameSimple.append(name.text());
       
   789             formattedNameSimple.append(" ");
       
   790         }
       
   791     }
       
   792 }