logsui/logsengine/src/logsmodel.cpp
changeset 2 7119b73b84d6
parent 0 4a5361db8937
child 4 e52d42f9500c
equal deleted inserted replaced
0:4a5361db8937 2:7119b73b84d6
    27 #include "logsmessage.h"
    27 #include "logsmessage.h"
    28 #include "logseventdata.h"
    28 #include "logseventdata.h"
    29 #include "logscommondata.h"
    29 #include "logscommondata.h"
    30 #include <hbicon.h>
    30 #include <hbicon.h>
    31 #include <QStringList>
    31 #include <QStringList>
       
    32 #include <QtGui>
       
    33 #include <hbfontspec.h>
       
    34 #include <hbinstance.h>
    32 
    35 
    33 Q_DECLARE_METATYPE(LogsEvent *)
    36 Q_DECLARE_METATYPE(LogsEvent *)
    34 Q_DECLARE_METATYPE(LogsCall *)
    37 Q_DECLARE_METATYPE(LogsCall *)
    35 Q_DECLARE_METATYPE(LogsDetailsModel *)
    38 Q_DECLARE_METATYPE(LogsDetailsModel *)
    36 Q_DECLARE_METATYPE(LogsMessage *)
    39 Q_DECLARE_METATYPE(LogsMessage *)
    54             this, SLOT( dataAdded(QList<int>) ));
    57             this, SLOT( dataAdded(QList<int>) ));
    55     connect( mDbConnector, SIGNAL( dataUpdated(QList<int>) ), 
    58     connect( mDbConnector, SIGNAL( dataUpdated(QList<int>) ), 
    56             this, SLOT( dataUpdated(QList<int>) ));
    59             this, SLOT( dataUpdated(QList<int>) ));
    57     connect( mDbConnector, SIGNAL( dataRemoved(QList<int>) ), 
    60     connect( mDbConnector, SIGNAL( dataRemoved(QList<int>) ), 
    58             this, SLOT( dataRemoved(QList<int>) ));
    61             this, SLOT( dataRemoved(QList<int>) ));
       
    62     connect( hbInstance->theme(), SIGNAL ( changeFinished() ),
       
    63             this, SLOT ( resetModel()));
    59     mDbConnector->init();
    64     mDbConnector->init();
    60     mDbConnector->start();
    65     mDbConnector->start();
    61     
    66     
    62     LOGS_QDEBUG( "logs [ENG] <- LogsModel::LogsModel()" )
    67     LOGS_QDEBUG( "logs [ENG] <- LogsModel::LogsModel()" )
    63 }
    68 }
   149 
   154 
   150 // -----------------------------------------------------------------------------
   155 // -----------------------------------------------------------------------------
   151 //
   156 //
   152 // -----------------------------------------------------------------------------
   157 // -----------------------------------------------------------------------------
   153 //
   158 //
   154 int LogsModel::predictiveSearchStatus()
   159 int LogsModel::updateConfiguration(LogsConfigurationParams& params)
   155 {
   160 {
   156     return mDbConnector->predictiveSearchStatus();
   161     LOGS_QDEBUG( "logs [ENG] -> LogsModel::updateConfiguration()" )
   157 }
   162     int currWidth = 
   158 
   163         LogsCommonData::getInstance().currentConfiguration().listItemTextWidth();
   159 // -----------------------------------------------------------------------------
   164     int newWidth = params.listItemTextWidth();
   160 //
   165     LOGS_QDEBUG_3( "logs [ENG]    Curr and new width", currWidth, newWidth )   
   161 // -----------------------------------------------------------------------------
   166     int retVal = LogsCommonData::getInstance().updateConfiguration(params);
   162 //
   167     
   163 int LogsModel::setPredictiveSearch(bool enabled)
   168     // Do model reset if list item width has changed as we need to ensure 
   164 {
   169     // missed call's duplicate info visibility
   165     return mDbConnector->setPredictiveSearch(enabled);
   170     bool unseenExists = false;
   166 }
   171     for ( int i = 0; i < mEvents.count() && !unseenExists; i++ ){
   167 
   172         LogsEvent* event = mEvents.at(i);
       
   173         if ( event->duplicates() > 0 && !event->isSeenLocally() ){
       
   174             unseenExists = true;
       
   175         }
       
   176     }
       
   177     if ( unseenExists && currWidth > 0 && currWidth != newWidth ){
       
   178         LOGS_QDEBUG( "logs [ENG]    Do model reset" )
       
   179         resetModel();
       
   180     }
       
   181     LOGS_QDEBUG( "logs [ENG] <- LogsModel::updateConfiguration()" )
       
   182     return retVal;
       
   183 }
   168 
   184 
   169 // -----------------------------------------------------------------------------
   185 // -----------------------------------------------------------------------------
   170 // From QAbstractListModel
   186 // From QAbstractListModel
   171 // -----------------------------------------------------------------------------
   187 // -----------------------------------------------------------------------------
   172 //
   188 //
   280 //
   296 //
   281 QList< QList<int> > LogsModel::findSequentialIndexes(const QList<int>& indexes)
   297 QList< QList<int> > LogsModel::findSequentialIndexes(const QList<int>& indexes)
   282 {
   298 {
   283     QList< QList<int> > sequences;
   299     QList< QList<int> > sequences;
   284     QList<int> currSequence;
   300     QList<int> currSequence;
   285     int prevIndex = indexes.at(0) - 1;
   301     int prevIndex = indexes.count() > 0 ? ( indexes.at(0) - 1 ) : -1;
   286     for ( int i = 0; i < indexes.count(); i++ ){
   302     for ( int i = 0; i < indexes.count(); i++ ){
   287         int currIndex = indexes.at(i);
   303         int currIndex = indexes.at(i);
   288         if ( prevIndex+1 != currIndex ){
   304         if ( prevIndex+1 != currIndex ){
   289             
   305             
   290             sequences.append(currSequence);
   306             sequences.append(currSequence);
   317     }
   333     }
   318     if ( callerId.length() == 0 && event.logsEventData() ){
   334     if ( callerId.length() == 0 && event.logsEventData() ){
   319         callerId = event.logsEventData()->remoteUrl();
   335         callerId = event.logsEventData()->remoteUrl();
   320     }
   336     }
   321     if ( callerId.length() == 0 ){
   337     if ( callerId.length() == 0 ){
   322         callerId = tr("No number");
   338         if ( event.isRemotePartyPrivate() ){
       
   339             callerId = hbTrId("txt_dial_dblist_call_id_val_privat_number");
       
   340         }
       
   341         else if ( event.isRemotePartyUnknown() ){
       
   342             callerId = hbTrId("txt_dial_dblist_call_id_val_unknown_number");
       
   343         }
       
   344         
   323     }
   345     }
   324     int duplicates = event.duplicates();
   346     int duplicates = event.duplicates();
   325     if ( duplicates > 0 && !event.isSeenLocally() ){
   347     if ( duplicates > 0 && !event.isSeenLocally() ){
   326         callerId.append( "(" );
   348         QString callerIdBaseString = callerId;
   327         callerId.append( QString::number(duplicates + 1) );
   349         QString callerIdDupString = "(" + QString::number(duplicates + 1) + ")";
   328         callerId.append( ")");
   350         int width = LogsCommonData::getInstance().currentConfiguration().listItemTextWidth();
       
   351         callerId =  SqueezedString(callerIdBaseString,callerIdDupString,width);
   329     }
   352     }
   330     return callerId;
   353     return callerId;
   331 }
   354 }
   332 
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // basestring: string to be cutted if not fited to maxwidth
       
   358 // secondarystring: string to show fully in the end of basestring
       
   359 // maxwidth: maximum width (in pixels) available for basestring + secondarystring
       
   360 //
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 QString LogsModel::SqueezedString(
       
   364     QString basestring, QString secondarystring, qreal maxwidth) const
       
   365 {
       
   366     QFontMetricsF fontMetrics(HbFontSpec(HbFontSpec::Primary).font());
       
   367     QString fullString = basestring + secondarystring;
       
   368     qreal totalwidth = 0;
       
   369     int x = 0;
       
   370     if (fontMetrics.width(fullString) > maxwidth){
       
   371     		maxwidth = maxwidth - fontMetrics.width(tr("...")+secondarystring);
       
   372         for (x = 0; (x < basestring.count()) && (totalwidth < maxwidth); x++){
       
   373             totalwidth  = totalwidth + fontMetrics.width(basestring[x]);
       
   374         }
       
   375         if ( ( totalwidth > maxwidth ) && ( x>0 ) ) x--;
       
   376         return basestring.left(x) + tr("...") + secondarystring;
       
   377     } else {
       
   378         return fullString;  
       
   379     }
       
   380 }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 void LogsModel::resetModel()
       
   387 {
       
   388    this->reset();
       
   389 }
   333 // -----------------------------------------------------------------------------
   390 // -----------------------------------------------------------------------------
   334 //
   391 //
   335 // -----------------------------------------------------------------------------
   392 // -----------------------------------------------------------------------------
   336 //
   393 //
   337 void LogsModel::initIcons()
   394 void LogsModel::initIcons()