logsui/logsapp/src/logsviewmanager.cpp
changeset 6 41c0a814d878
parent 4 e52d42f9500c
child 8 6c9acdc6adc0
child 10 b04270301d3b
equal deleted inserted replaced
4:e52d42f9500c 6:41c0a814d878
    22 #include "logsdetailsview.h"
    22 #include "logsdetailsview.h"
    23 #include "logsfilter.h"
    23 #include "logsfilter.h"
    24 #include "logsdefs.h"
    24 #include "logsdefs.h"
    25 #include "logslogger.h"
    25 #include "logslogger.h"
    26 #include "logsservicehandler.h"
    26 #include "logsservicehandler.h"
       
    27 #include "logsservicehandlerold.h"
    27 #include "logsmainwindow.h"
    28 #include "logsmainwindow.h"
    28 
    29 
    29 //SYSTEM
    30 //SYSTEM
    30 #include <hbmainwindow.h>
    31 #include <hbmainwindow.h>
    31 #include <hbview.h>
    32 #include <hbview.h>
    32 #include <logsservices.h>
    33 #include <logsservices.h>
    33 #include <QApplication>
    34 #include <QApplication>
    34 #include <hblineedit.h>
    35 #include <hblineedit.h>
    35 #include <dialpad.h>
    36 #include <dialpad.h>
       
    37 #include <hbactivitymanager.h>
       
    38 #include <hbapplication.h>
    36 
    39 
    37 // -----------------------------------------------------------------------------
    40 // -----------------------------------------------------------------------------
    38 // LogsViewManager::LogsViewManager
    41 // LogsViewManager::LogsViewManager
    39 // -----------------------------------------------------------------------------
    42 // -----------------------------------------------------------------------------
    40 //
    43 //
    41 LogsViewManager::LogsViewManager( 
    44 LogsViewManager::LogsViewManager( 
    42         LogsMainWindow& mainWindow, LogsServiceHandler& service ) : 
    45         LogsMainWindow& mainWindow, LogsServiceHandler& service,
    43     QObject( 0 ), mMainWindow( mainWindow ), mService( service ), 
    46         LogsServiceHandlerOld& serviceOld ) : 
       
    47     QObject( 0 ), mMainWindow( mainWindow ), 
       
    48     mService( service ), mServiceOld( serviceOld ),
    44     mFirstActivation(true), mViewActivationShowDialpad(false)
    49     mFirstActivation(true), mViewActivationShowDialpad(false)
    45 {
    50 {
    46     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::LogsViewManager()" );
    51     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::LogsViewManager()" );
    47 
    52 
    48     //It is important that we always handle orientation change first, before
    53     //It is important that we always handle orientation change first, before
    56     connect( &mService, SIGNAL( activateView(LogsServices::LogsView, bool) ), 
    61     connect( &mService, SIGNAL( activateView(LogsServices::LogsView, bool) ), 
    57              this, SLOT( changeRecentView(LogsServices::LogsView, bool) ) );
    62              this, SLOT( changeRecentView(LogsServices::LogsView, bool) ) );
    58 
    63 
    59     connect( &mService, SIGNAL( activateView(QString) ), 
    64     connect( &mService, SIGNAL( activateView(QString) ), 
    60              this, SLOT( changeMatchesView(QString) ));
    65              this, SLOT( changeMatchesView(QString) ));
       
    66 
       
    67     connect( &mServiceOld, SIGNAL( activateView(LogsServices::LogsView, bool) ), 
       
    68              this, SLOT( changeRecentView(LogsServices::LogsView, bool) ) );
       
    69 
       
    70     connect( &mServiceOld, SIGNAL( activateView(QString) ), 
       
    71              this, SLOT( changeMatchesView(QString) ));
    61     
    72     
    62     connect( &mMainWindow, SIGNAL(appFocusGained()), this, SLOT(appFocusGained()) );
    73     connect( &mMainWindow, SIGNAL(appFocusGained()), this, SLOT(appFocusGained()) );
    63     connect( &mMainWindow, SIGNAL(appFocusLost()), this, SLOT(appFocusLost()) );
    74     connect( &mMainWindow, SIGNAL(appFocusLost()), this, SLOT(appFocusLost()) );
       
    75     
       
    76     QObject::connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(saveActivity()));
       
    77 
       
    78     handleFirstActivation();
    64     
    79     
    65     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::LogsViewManager()" );
    80     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::LogsViewManager()" );
    66 }
    81 }
    67 
    82 
    68 
    83 
    84 // -----------------------------------------------------------------------------
    99 // -----------------------------------------------------------------------------
    85 //
   100 //
    86 void LogsViewManager::initViews()
   101 void LogsViewManager::initViews()
    87 {
   102 {
    88     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::initViews()" );
   103     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::initViews()" );
    89     
       
    90     // Disable view switching as otherwise flick gestures change
       
    91     // views which is not desired.
       
    92     //Deprecated:
       
    93     //mMainWindow.setViewSwitchingEnabled(false);
       
    94     
   104     
    95     // Don't activate any view, app focus gaining or service request
   105     // Don't activate any view, app focus gaining or service request
    96     // will cause view activation
   106     // will cause view activation
    97     //
   107     //
    98     LogsRecentCallsView* view = mComponentsRepository->recentCallsView();    
   108     LogsRecentCallsView* view = mComponentsRepository->recentCallsView();    
   127 // -----------------------------------------------------------------------------
   137 // -----------------------------------------------------------------------------
   128 //
   138 //
   129 void LogsViewManager::changeMatchesView(QString dialpadText)
   139 void LogsViewManager::changeMatchesView(QString dialpadText)
   130 {
   140 {
   131     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::changeMatchesView()" );
   141     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::changeMatchesView()" );
   132     Dialpad* dialpad = mComponentsRepository->dialpad();
   142     doActivateView(LogsMatchesViewId, true, QVariant(), dialpadText);
   133     dialpad->editor().setText(dialpadText);
       
   134     LogsModel* model = mComponentsRepository->model();
       
   135     if ( model && model->predictiveSearchStatus() == logsContactSearchEnabled ){
       
   136         LOGS_QDEBUG( "logs [UI]     contact search enabled, go to macthes view" );
       
   137         doActivateView(LogsMatchesViewId, true, QVariant());
       
   138     } else {
       
   139         LOGS_QDEBUG( "logs [UI]     contact search disabled, go to recent view" );
       
   140         doActivateView(LogsRecentViewId, true, QVariant());
       
   141     }
       
   142     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::changeMatchesView()" );
   143     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::changeMatchesView()" );
   143 }
   144 }
   144 
   145 
   145 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   146 // LogsViewManager::appFocusGained
   147 // LogsViewManager::appFocusGained
   154     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::appFocusGained()" );
   155     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::appFocusGained()" );
   155     
   156     
   156     foreach ( LogsBaseView* view, mViewStack ){
   157     foreach ( LogsBaseView* view, mViewStack ){
   157         disconnect( view, SIGNAL(exitAllowed()), this, SLOT(proceedExit()) );
   158         disconnect( view, SIGNAL(exitAllowed()), this, SLOT(proceedExit()) );
   158     }
   159     }
   159     
       
   160     if ( mFirstActivation && !mService.isStartedUsingService() ){
       
   161         changeRecentView( mService.currentlyActivatedView(), false );
       
   162         mMainWindow.bringAppToForeground();
       
   163     }
       
   164     
       
   165     mComponentsRepository->model()->refreshData();
       
   166 
   160 
   167     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::appFocusGained()" );
   161     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::appFocusGained()" );
   168 }
   162 }
   169 
   163 
   170 // -----------------------------------------------------------------------------
   164 // -----------------------------------------------------------------------------
   235     
   229     
   236     LOGS_QDEBUG( "logs [UI] Exit delayed" );
   230     LOGS_QDEBUG( "logs [UI] Exit delayed" );
   237     
   231     
   238     // Fake exit by sending app to background
   232     // Fake exit by sending app to background
   239     mMainWindow.sendAppToBackground();
   233     mMainWindow.sendAppToBackground();
   240     
       
   241     // Set application to default state (recent calls and no dialpad)
       
   242     activateView( LogsRecentViewId, false, QVariant() );
       
   243     mComponentsRepository->recentCallsView()->resetView();
       
   244 
   234 
   245     bool exitAllowed( true );
   235     bool exitAllowed( true );
   246     foreach ( LogsBaseView* view, mViewStack ){
   236     foreach ( LogsBaseView* view, mViewStack ){
   247         if ( !view->isExitAllowed() ){
   237         if ( !view->isExitAllowed() ){
   248             exitAllowed = false;
   238             exitAllowed = false;
   279 // previously activated view and activates new view and place it at top of
   269 // previously activated view and activates new view and place it at top of
   280 // view stack.
   270 // view stack.
   281 // -----------------------------------------------------------------------------
   271 // -----------------------------------------------------------------------------
   282 //
   272 //
   283 bool LogsViewManager::doActivateView(
   273 bool LogsViewManager::doActivateView(
   284         LogsAppViewId viewId, bool showDialpad, QVariant args)
   274         LogsAppViewId viewId, bool showDialpad, QVariant args, const QString& dialpadText)
   285 {
   275 {
   286     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::doActivateView()" );
   276     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::doActivateView()" );
   287     
   277     
   288     bool activated(false);
   278     bool activated(false);
   289     LogsBaseView* newView = 0; 
   279     LogsBaseView* newView = 0; 
   290     LogsBaseView* oldView = mViewStack.count() > 0 ? mViewStack.at(0) : 0;
   280     LogsBaseView* oldView = mViewStack.count() > 0 ? mViewStack.at(0) : 0;
       
   281     
       
   282     viewId = checkMatchesViewTransition(viewId, dialpadText);
   291     
   283     
   292     for ( int i = 0; i < mViewStack.count(); ++i ){
   284     for ( int i = 0; i < mViewStack.count(); ++i ){
   293         if ( mViewStack.at(i)->viewId() == viewId ){
   285         if ( mViewStack.at(i)->viewId() == viewId ){
   294             newView = mViewStack.takeAt(i);
   286             newView = mViewStack.takeAt(i);
   295         }
   287         }
   345 {
   337 {
   346     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::handleOrientationChanged()" );
   338     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::handleOrientationChanged()" );
   347     QMetaObject::invokeMethod(mMainWindow.currentView(), "handleOrientationChanged");
   339     QMetaObject::invokeMethod(mMainWindow.currentView(), "handleOrientationChanged");
   348     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::handleOrientationChanged()" );
   340     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::handleOrientationChanged()" );
   349 }
   341 }
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 //
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 void LogsViewManager::saveActivity()
       
   348 {
       
   349     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::saveActivity()" );
       
   350     
       
   351     if ( mViewStack.count() == 0 ){
       
   352         return;
       
   353     }
       
   354     
       
   355     HbActivityManager* activityManager = static_cast<HbApplication*>(qApp)->activityManager();
       
   356     foreach ( LogsBaseView* view, mViewStack ){
       
   357         view->clearActivity(*activityManager);
       
   358     }
       
   359     
       
   360     QVariantHash metaData;
       
   361     metaData.insert("screenshot", QPixmap::grabWidget(&mMainWindow, mMainWindow.rect()));
       
   362     
       
   363     QByteArray serializedActivity;
       
   364     QDataStream stream(&serializedActivity, QIODevice::WriteOnly | QIODevice::Append);
       
   365     
       
   366     metaData.insert( 
       
   367         logsActivityParamShowDialpad, mComponentsRepository->dialpad()->isOpen() );
       
   368     metaData.insert( 
       
   369         logsActivityParamDialpadText, mComponentsRepository->dialpad()->editor().text() );
       
   370     QString activityId = mViewStack.at(0)->saveActivity(stream, metaData);
       
   371     
       
   372     // add the activity to the activity manager
       
   373     bool ok = activityManager->addActivity(activityId, serializedActivity, metaData);
       
   374     if ( !ok ){
       
   375         LOGS_QDEBUG( "logs [UI] activity adding failed" );
       
   376     }
       
   377     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::saveActivity()" );
       
   378 }
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 bool LogsViewManager::loadActivity()
       
   385 {
       
   386     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::loadActivity()" );
       
   387     bool loaded = false;
       
   388     HbApplication* hbApp = static_cast<HbApplication*>(qApp);
       
   389     QString activityId = hbApp->activateId();
       
   390     LOGS_QDEBUG_2( "logs [UI] activity id:", activityId );
       
   391     bool ok = hbApp->activityManager()->waitActivity();
       
   392     if ( !ok ){
       
   393         LOGS_QDEBUG( "logs [UI] Activity reschedule failed" );
       
   394     }
       
   395     
       
   396     LogsBaseView* matchingView = 0;
       
   397     for ( int i = 0; i < mViewStack.count() && !matchingView; i++ ){
       
   398         if ( mViewStack.at(i)->matchWithActivityId(activityId) ){
       
   399             matchingView =  mViewStack.at(i);
       
   400         }
       
   401     }
       
   402     
       
   403     if ( matchingView ){
       
   404         // Should have only one param hash in the list, use first always
       
   405         QList<QVariantHash> allParams = hbApp->activityManager()->activities();  
       
   406         QVariantHash params = allParams.isEmpty() ? QVariantHash() : allParams.at(0);
       
   407         LOGS_QDEBUG_2( "logs [UI] Activity params", params );
       
   408         bool showDialpad = params.value(logsActivityParamShowDialpad).toBool();
       
   409         QString dialpadText = params.value(logsActivityParamDialpadText).toString();
       
   410         
       
   411         QByteArray serializedActivity = hbApp->activateData().toByteArray();
       
   412         QDataStream stream(&serializedActivity, QIODevice::ReadOnly);
       
   413         
       
   414         QVariant args = matchingView->loadActivity(activityId, stream, params);
       
   415         loaded = doActivateView( matchingView->viewId(), showDialpad, args, dialpadText );
       
   416     }
       
   417     LOGS_QDEBUG_2( "logs [UI] <- LogsViewManager::loadActivity() loaded:", loaded );
       
   418     return loaded;
       
   419 }
       
   420 
       
   421 // -----------------------------------------------------------------------------
       
   422 //
       
   423 // -----------------------------------------------------------------------------
       
   424 //
       
   425 LogsAppViewId LogsViewManager::checkMatchesViewTransition(
       
   426     LogsAppViewId viewId, const QString& dialpadText)
       
   427 {
       
   428     if ( !dialpadText.isEmpty() ){
       
   429         Dialpad* dialpad = mComponentsRepository->dialpad();
       
   430         dialpad->editor().setText(dialpadText);
       
   431     }
       
   432     
       
   433     if ( viewId == LogsMatchesViewId ){
       
   434         LogsModel* model = mComponentsRepository->model();
       
   435         if ( model && model->predictiveSearchStatus() != logsContactSearchEnabled ){
       
   436             LOGS_QDEBUG( "logs [UI]     contact search disabled, go to recent view" );
       
   437             viewId = LogsRecentViewId;
       
   438         }
       
   439     }
       
   440     return viewId;
       
   441 }
       
   442 
       
   443 // -----------------------------------------------------------------------------
       
   444 //
       
   445 // -----------------------------------------------------------------------------
       
   446 //
       
   447 void LogsViewManager::handleFirstActivation()
       
   448 {      
       
   449     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::handleFirstActivation()" );
       
   450     bool useSavedActivity( static_cast<HbApplication*>(qApp)->activateReason() == 
       
   451             Hb::ActivationReasonActivity );
       
   452     
       
   453     if ( useSavedActivity && loadActivity() ){
       
   454         LOGS_QDEBUG( "logs [UI] loaded saved activity" );    
       
   455         mMainWindow.bringAppToForeground();
       
   456     } else if ( mFirstActivation && !mService.isStartedUsingService() && 
       
   457                 !mServiceOld.isStartedUsingService()) {
       
   458         changeRecentView( LogsServices::ViewAll, false );
       
   459         mMainWindow.bringAppToForeground();
       
   460     }
       
   461 
       
   462     // Clear previously stored activations
       
   463 
       
   464     HbActivityManager* activityManager = static_cast<HbApplication*>(qApp)->activityManager();
       
   465     foreach ( LogsBaseView* view, mViewStack ){
       
   466         view->clearActivity(*activityManager);
       
   467     }
       
   468     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::handleFirstActivation()" );
       
   469 }