logsui/logsapp/src/logsrecentcallsview.cpp
changeset 6 41c0a814d878
parent 4 e52d42f9500c
child 8 6c9acdc6adc0
child 10 b04270301d3b
equal deleted inserted replaced
4:e52d42f9500c 6:41c0a814d878
    41 #include <hblineedit.h>
    41 #include <hblineedit.h>
    42 #include <hbgroupbox.h>
    42 #include <hbgroupbox.h>
    43 #include <hbmessagebox.h>
    43 #include <hbmessagebox.h>
    44 #include <hbmainwindow.h>
    44 #include <hbmainwindow.h>
    45 #include <QTimer>
    45 #include <QTimer>
       
    46 #include <hbactivitymanager.h>
    46 
    47 
    47 Q_DECLARE_METATYPE(LogsMatchesModel*)
    48 Q_DECLARE_METATYPE(LogsMatchesModel*)
    48 
    49 
    49 const int logsMissedCallsMarkingDelayMs = 1000;
    50 const int logsMissedCallsMarkingDelayMs = 1000;
    50 const int logsSwipeAngleDelta = 30; // angle is from 0 to 360
    51 const int logsSwipeAngleDelta = 30; // angle is from 0 to 360
    65       mEffectHandler(0),
    66       mEffectHandler(0),
    66       mListViewX(0),
    67       mListViewX(0),
    67       mMatchesModel(0),
    68       mMatchesModel(0),
    68       mMarkingMissedAsSeen(false),
    69       mMarkingMissedAsSeen(false),
    69       mPageIndicator(0),
    70       mPageIndicator(0),
    70       mResetted(false)
    71       mFirstActivation(true)
    71 {
    72 {
    72     LOGS_QDEBUG( "logs [UI] <-> LogsRecentCallsView::LogsRecentCallsView()" );
    73     LOGS_QDEBUG( "logs [UI] <-> LogsRecentCallsView::LogsRecentCallsView()" );
    73     mModel = mRepository.model();
    74     mModel = mRepository.model();
    74     	
    75     	
    75     //TODO: taking away due to toolbar bug. If toolbar visibility changes on view
    76     //TODO: taking away due to toolbar bug. If toolbar visibility changes on view
    76     //activation, there will be a crash due to previous view effect is playing
    77     //activation, there will be a crash due to previous view effect is playing
    77     //addViewSwitchingEffects();
    78     //addViewSwitchingEffects();
       
    79     
       
    80     // Important to add in the same order as mCurrentView enums as correct
       
    81     // activity id is taken directly from the array based on the enum
       
    82     mActivities.append( logsActivityIdViewRecent );
       
    83     mActivities.append( logsActivityIdViewReceived );
       
    84     mActivities.append( logsActivityIdViewCalled );
       
    85     mActivities.append( logsActivityIdViewMissed );
    78 }
    86 }
    79     
    87     
    80 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
    81 // LogsRecentCallsView::~LogsRecentCallsView
    89 // LogsRecentCallsView::~LogsRecentCallsView
    82 // -----------------------------------------------------------------------------
    90 // -----------------------------------------------------------------------------
   103 {
   111 {
   104     LOGS_QDEBUG( "logs [UI] -> LogsRecentCallsView::activated()" );
   112     LOGS_QDEBUG( "logs [UI] -> LogsRecentCallsView::activated()" );
   105     // base class handling first
   113     // base class handling first
   106     LogsBaseView::activated(showDialer, args);
   114     LogsBaseView::activated(showDialer, args);
   107     
   115     
   108     LogsServices::LogsView view = static_cast<LogsServices::LogsView>( args.toInt() );
   116     int internalViewId = args.toInt();
       
   117     if ( internalViewId < 0 || internalViewId > LogsServices::ViewMissed ){
       
   118         internalViewId = LogsServices::ViewAll;
       
   119     }
       
   120     LogsServices::LogsView view = static_cast<LogsServices::LogsView>( internalViewId );
   109 
   121 
   110     // View update is needed when we activate view for the first time (!mFilter)
   122     // View update is needed when we activate view for the first time (!mFilter)
   111     // or if view has to be changed
   123     // or if view has to be changed
   112     if (  !mFilter || ( !args.isNull() && (mCurrentView != view) ) ) {
   124     if (  !mFilter || ( !args.isNull() && (mCurrentView != view) ) ) {
   113         updateView( view );
   125         updateView( view );
   114     }
   126     }
   115     activateEmptyListIndicator(mFilter);
   127     activateEmptyListIndicator(mFilter);
   116     
   128     
   117     mPageIndicator->setActiveItemIndex(mConversionMap.value(mCurrentView));
   129     mPageIndicator->setActiveItemIndex(mConversionMap.value(mCurrentView));
   118     
   130 
   119     if ( mResetted ){
   131     mFirstActivation = false;
   120         // After reset, first data addition should cause scrolling to topitem
   132     
   121         connect( mFilter, SIGNAL(rowsInserted(const QModelIndex&,int,int)), 
       
   122                  this, SLOT(scrollToTopItem()) );
       
   123         mResetted = false;
       
   124     }
       
   125 
       
   126     LOGS_QDEBUG( "logs [UI] <- LogsRecentCallsView::activated()" );  
   133     LOGS_QDEBUG( "logs [UI] <- LogsRecentCallsView::activated()" );  
   127 }
   134 }
   128 
   135 
   129 // -----------------------------------------------------------------------------
   136 // -----------------------------------------------------------------------------
   130 // LogsRecentCallsView::deactivated
   137 // LogsRecentCallsView::deactivated
   159 
   166 
   160 // -----------------------------------------------------------------------------
   167 // -----------------------------------------------------------------------------
   161 //
   168 //
   162 // -----------------------------------------------------------------------------
   169 // -----------------------------------------------------------------------------
   163 //
   170 //
   164 void LogsRecentCallsView::resetView()
   171 QString LogsRecentCallsView::saveActivity(
   165 {
   172     QDataStream& serializedActivity, QVariantHash& metaData)
   166     LOGS_QDEBUG( "logs [UI] -> LogsRecentCallsView::resetView()" );
   173 {
   167     LogsBaseView::resetView();
   174     Q_UNUSED( serializedActivity );
   168     mResetted = true;
   175     Q_UNUSED( metaData );
   169     LOGS_QDEBUG( "logs [UI] <- LogsRecentCallsView::resetView()" );
   176     if ( mCurrentView >= 0 && mCurrentView < mActivities.count() ){
   170 }
   177         return mActivities.at( mCurrentView );
       
   178     }
       
   179     return QString();
       
   180 }
       
   181 
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 QVariant LogsRecentCallsView::loadActivity(
       
   187     const QString& activityId, QDataStream& serializedActivity, QVariantHash& metaData)
       
   188 {
       
   189     Q_UNUSED( serializedActivity );
       
   190     Q_UNUSED( metaData );
       
   191     return mActivities.indexOf(activityId);
       
   192 }
       
   193 
   171 
   194 
   172 // -----------------------------------------------------------------------------
   195 // -----------------------------------------------------------------------------
   173 // LogsRecentCallsView::initView
   196 // LogsRecentCallsView::initView
   174 // -----------------------------------------------------------------------------
   197 // -----------------------------------------------------------------------------
   175 //
   198 //
   716 // LogsRecentCallsView::getListItemTextWidth
   739 // LogsRecentCallsView::getListItemTextWidth
   717 // -----------------------------------------------------------------------------
   740 // -----------------------------------------------------------------------------
   718 //
   741 //
   719 int LogsRecentCallsView::getListItemTextWidth()
   742 int LogsRecentCallsView::getListItemTextWidth()
   720 {
   743 {
   721     LOGS_QDEBUG( "logs [UI] -> LogsRecentCallsView::ListItemText()" );
   744     LOGS_QDEBUG( "logs [UI] -> LogsRecentCallsView::getListItemTextWidth()" );
   722 
   745 
   723     qreal width = 0;
   746     qreal width = 0.0;
   724 
   747     QRectF screenRect = mViewManager.mainWindow().layoutRect();
   725     // layoutrect broken, fix will be in MCL wk14, use workaround meanwhile
       
   726     //QRectF screenRect = mViewManager.mainWindow().layoutRect();
       
   727     QRectF screenRect = (mViewManager.mainWindow().orientation() == Qt::Horizontal) ? 
       
   728             QRectF(0,0,640,360) : QRectF(0,0,360,640);
       
   729     LOGS_QDEBUG_2( "logs [UI]  screenRect:", screenRect );
   748     LOGS_QDEBUG_2( "logs [UI]  screenRect:", screenRect );
   730     
   749     
   731     // Cannot use hb-param-screen-width in expressions currently due bug in layoutrect
   750     // Cannot use hb-param-screen-width in expressions currently due bug in layoutrect
   732     qreal modifier = 0.0;
   751     qreal modifier = 0.0;
   733     QString expr;
   752     QString expr;
   734     if (mListView->layoutName() == QLatin1String(logsListDefaultLayout)) {
   753     if (mListView->layoutName() == QLatin1String(logsListDefaultLayout)) {
   735         expr = "expr(var(hb-param-graphic-size-primary-medium) + var(hb-param-margin-gene-left) + var(hb-param-margin-gene-right) + var(hb-param-margin-gene-middle-horizontal))";
   754         expr = "expr(var(hb-param-graphic-size-primary-medium) + var(hb-param-margin-gene-left) ";
       
   755         expr += "+ var(hb-param-margin-gene-right) + var(hb-param-margin-gene-middle-horizontal))";
   736         width = screenRect.width();
   756         width = screenRect.width();
   737     } else {
   757     } else {
   738         expr = "expr(var(hb-param-graphic-size-primary-medium) + var(hb-param-margin-gene-left) + var(hb-param-margin-gene-right))";
   758         expr = "expr(var(hb-param-graphic-size-primary-medium) + var(hb-param-margin-gene-left) ";
       
   759         expr += "+ var(hb-param-margin-gene-right))";
   739         width = screenRect.width() / 2;
   760         width = screenRect.width() / 2;
   740     }
   761     }
   741     
   762     
   742     if ( expr.isEmpty() || !style()->parameter(expr, modifier) ){
   763     if ( expr.isEmpty() || !style()->parameter(expr, modifier) ){
   743         LOGS_QDEBUG( "logs [UI] No expression or incorrect expression" );
   764         LOGS_QDEBUG( "logs [UI] No expression or incorrect expression" );
   744     }
   765     }
   745     width -= modifier;
   766     width -= modifier;
   746     
   767     
   747     LOGS_QDEBUG_2( "logs [UI] <- LogsRecentCallsView::ListItemText(): ", width );   
   768     LOGS_QDEBUG_2( "logs [UI] <- LogsRecentCallsView::getListItemTextWidth(): ", width );   
   748     return qRound(width);
   769     return qRound(width);
   749 }
   770 }
   750 
   771 
   751 
   772 
   752 // -----------------------------------------------------------------------------
   773 // -----------------------------------------------------------------------------
   767 // LogsRecentCallsView::handleMissedCallsMarking
   788 // LogsRecentCallsView::handleMissedCallsMarking
   768 // -----------------------------------------------------------------------------
   789 // -----------------------------------------------------------------------------
   769 //
   790 //
   770 void LogsRecentCallsView::handleMissedCallsMarking()
   791 void LogsRecentCallsView::handleMissedCallsMarking()
   771 {
   792 {
   772     if ( mFilter && !mMarkingMissedAsSeen && !mResetted && 
   793     if ( mFilter && !mMarkingMissedAsSeen && !mFirstActivation && 
   773           ( mFilter->filterType() == LogsFilter::Missed || 
   794           ( mFilter->filterType() == LogsFilter::Missed || 
   774             mFilter->filterType() == LogsFilter::All ) ){
   795             mFilter->filterType() == LogsFilter::All ) ){
   775         // Don't care if timer would be already running, slot's implementation
   796         // Don't care if timer would be already running, slot's implementation
   776         // takes care that marking is done only once
   797         // takes care that marking is done only once
   777         LOGS_QDEBUG( "logs [UI] <-> LogsRecentCallsView::handleMissedCallsMarking()" );
   798         LOGS_QDEBUG( "logs [UI] <-> LogsRecentCallsView::handleMissedCallsMarking()" );