logsui/logsapp/src/logsviewmanager.cpp
changeset 18 acd4e87b24b4
parent 17 90fe74753f71
child 21 2f0af9ba7665
equal deleted inserted replaced
17:90fe74753f71 18:acd4e87b24b4
    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 "logsservicehandlerold.h"
    28 #include "logsmainwindow.h"
    28 #include "logsmainwindow.h"
    29 #include "logsapplication.h"
    29 #include "logsappsettings.h"
       
    30 #include "logsforegroundwatcher.h"
    30 
    31 
    31 //SYSTEM
    32 //SYSTEM
    32 #include <hbmainwindow.h>
    33 #include <hbmainwindow.h>
    33 #include <hbview.h>
    34 #include <hbview.h>
    34 #include <QApplication>
    35 #include <QApplication>
    42 // LogsViewManager::LogsViewManager
    43 // LogsViewManager::LogsViewManager
    43 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    44 //
    45 //
    45 LogsViewManager::LogsViewManager( 
    46 LogsViewManager::LogsViewManager( 
    46         LogsMainWindow& mainWindow, LogsServiceHandler& service,
    47         LogsMainWindow& mainWindow, LogsServiceHandler& service,
    47         LogsServiceHandlerOld& serviceOld ) : 
    48         LogsServiceHandlerOld& serviceOld,
       
    49         LogsAppSettings& settings) : 
    48     QObject( 0 ), mMainWindow( mainWindow ), 
    50     QObject( 0 ), mMainWindow( mainWindow ), 
    49     mService( service ), mServiceOld( serviceOld ),
    51     mService( service ), mServiceOld( serviceOld ), mSettings( settings ),
    50     mFirstActivation(true), mViewActivationShowDialpad(false)
    52     mFirstActivation(true), mViewActivationShowDialpad(false), 
       
    53     mBackgroundStartupWatcher(0)
    51 {
    54 {
    52     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::LogsViewManager()" );
    55     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::LogsViewManager()" );
    53 
    56 
    54     //It is important that we always handle orientation change first, before
    57     //It is important that we always handle orientation change first, before
    55     //dialpad widget. If connection is moved to a view, then it's not guarantied.
    58     //dialpad widget. If connection is moved to a view, then it's not guarantied.
    56     connect( &mainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
    59     connect( &mainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
    57             this, SLOT(handleOrientationChanged()) );
    60             this, SLOT(handleOrientationChanged()) );
    58     connect( &mainWindow, SIGNAL(appGainedForeground()), this, SLOT(appGainedForeground()) );
    61     connect( &mainWindow, SIGNAL(appGainedForeground()), this, SLOT(appGainedForeground()) );
       
    62     connect( &mainWindow, SIGNAL(appLostForeground()), this, SLOT(appLostForeground()) );
    59 
    63 
    60     mComponentsRepository = new LogsComponentRepository(*this);
    64     mComponentsRepository = new LogsComponentRepository(*this);
    61     
    65     
    62     connect( &mService, SIGNAL( activateView(XQService::LogsViewIndex, bool, QString) ), 
    66     connect( &mService, SIGNAL( activateView(XQService::LogsViewIndex, bool, QString) ), 
    63              this, SLOT( changeRecentViewViaService(XQService::LogsViewIndex, bool, QString) ) );
    67              this, SLOT( changeRecentViewViaService(XQService::LogsViewIndex, bool, QString) ) );
    86 LogsViewManager::~LogsViewManager()
    90 LogsViewManager::~LogsViewManager()
    87 {
    91 {
    88     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::~LogsViewManager()" );
    92     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::~LogsViewManager()" );
    89      
    93      
    90     delete mComponentsRepository;
    94     delete mComponentsRepository;
       
    95     delete mBackgroundStartupWatcher;
    91     
    96     
    92     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::~LogsViewManager()" );
    97     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::~LogsViewManager()" );
    93 }
    98 }
    94 
    99 
    95 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   129 //
   134 //
   130 void LogsViewManager::proceedExit()
   135 void LogsViewManager::proceedExit()
   131 {
   136 {
   132     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::proceedExit()" );
   137     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::proceedExit()" );
   133     
   138     
   134     if ( static_cast<LogsApplication*>( qApp )->logsFeatureFakeExitEnabled() ){
   139     if ( mSettings.logsFeatureFakeExitEnabled() ){
   135         doFakeExit();
   140         doFakeExit();
   136     } else {
   141     } else {
   137         qApp->quit();
   142         qApp->quit();
   138     }
   143     }
   139     
   144     
   175 //
   180 //
   176 void LogsViewManager::exitApplication()
   181 void LogsViewManager::exitApplication()
   177 {
   182 {
   178     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::exitApplication()" );
   183     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::exitApplication()" );
   179     
   184     
   180     LOGS_QDEBUG( "logs [UI] Exit delayed" );
   185     // Send app immetiately to background as there might be some async stuff
   181     
   186     // that needs to complete before the process can be terminated.
   182     // Fake exit by sending app to background
       
   183     mMainWindow.sendAppToBackground();
   187     mMainWindow.sendAppToBackground();
   184 
   188 
   185     bool exitAllowed( true );
   189     doExitApplication();
   186     foreach ( LogsBaseView* view, mViewStack ){
       
   187         if ( !view->isExitAllowed() ){
       
   188             exitAllowed = false;
       
   189             connect( view, SIGNAL(exitAllowed()),
       
   190                      this, SLOT(proceedExit()), 
       
   191                      Qt::UniqueConnection );
       
   192         }
       
   193     }
       
   194     if ( exitAllowed ){
       
   195         LOGS_QDEBUG( "logs [UI] Handle exit immediataly" );
       
   196         proceedExit();
       
   197     } else {
       
   198         // Just wait for signal from view(s) that exiting can proceed
       
   199         LOGS_QDEBUG( "logs [UI] Delayed exit handling" );
       
   200     }
       
   201     
   190     
   202     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::exitApplication()" );
   191     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::exitApplication()" );
   203 }
   192 }
   204 
   193 
   205 // -----------------------------------------------------------------------------
   194 // -----------------------------------------------------------------------------
   390 // -----------------------------------------------------------------------------
   379 // -----------------------------------------------------------------------------
   391 //
   380 //
   392 void LogsViewManager::handleFirstActivation()
   381 void LogsViewManager::handleFirstActivation()
   393 {      
   382 {      
   394     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::handleFirstActivation()" );
   383     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::handleFirstActivation()" );
   395     LogsApplication* app = static_cast<LogsApplication*>(qApp);
   384 
   396     Hb::ActivationReason reason = app->activateReason();
   385     if ( mSettings.logsFeaturePreloadingEnabled() ) {
   397     bool isStartedByService( 
   386         delete mBackgroundStartupWatcher;
   398         mService.isStartedUsingService() || mServiceOld.isStartedUsingService() );
   387         mBackgroundStartupWatcher = 0;
   399     if ( !app->logsFeaturePreloadingEnabled() || 
   388         mBackgroundStartupWatcher = new LogsForegroundWatcher();
   400          reason == Hb::ActivationReasonActivity || 
   389         connect( mBackgroundStartupWatcher, SIGNAL(gainingForeground()), 
   401          isStartedByService ){
   390                  this, SLOT(bgStartupForegroundGained()) );
       
   391         setTaskSwitcherVisibility(false);
       
   392 
       
   393     } else {
       
   394         Hb::ActivationReason reason = static_cast<HbApplication*>(qApp)->activateReason();
       
   395         bool isStartedByService( 
       
   396             mService.isStartedUsingService() || mServiceOld.isStartedUsingService() );
       
   397         
   402         // Start immediately using all possible resources
   398         // Start immediately using all possible resources
   403         mComponentsRepository->model()->refreshData();
   399         mComponentsRepository->model()->refreshData();
   404     }
   400         
   405     
   401         if ( reason == Hb::ActivationReasonActivity && loadActivity() ){
   406     if ( reason == Hb::ActivationReasonActivity && loadActivity() ){
   402             LOGS_QDEBUG( "logs [UI] loaded saved activity" );    
   407         LOGS_QDEBUG( "logs [UI] loaded saved activity" );    
   403             mMainWindow.bringAppToForeground();
   408         mMainWindow.bringAppToForeground();
   404         } else if ( mFirstActivation && !isStartedByService ) {
   409     } else if ( mFirstActivation && !isStartedByService ) {
   405             activateDefaultView();
   410         changeRecentView( XQService::LogsViewAll, false );
   406             mMainWindow.bringAppToForeground();
   411         mMainWindow.bringAppToForeground();
   407         }
   412     }
   408         
   413 
   409         clearActivities();
   414     clearActivities();
   410     }
   415 
   411 
   416     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::handleFirstActivation()" );
   412     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::handleFirstActivation()" );
   417 }
   413 }
   418 
   414 
   419 // -----------------------------------------------------------------------------
   415 // -----------------------------------------------------------------------------
   459     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::appGainedForeground()" );
   455     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::appGainedForeground()" );
   460     foreach ( LogsBaseView* view, mViewStack ){
   456     foreach ( LogsBaseView* view, mViewStack ){
   461         disconnect( view, SIGNAL(exitAllowed()), this, SLOT(proceedExit()) );
   457         disconnect( view, SIGNAL(exitAllowed()), this, SLOT(proceedExit()) );
   462     }
   458     }
   463     
   459     
   464     if ( static_cast<LogsApplication*>( qApp )->logsFeatureFakeExitEnabled() || 
   460     if ( mSettings.logsFeatureFakeExitEnabled() || mSettings.logsFeaturePreloadingEnabled() ){
   465          static_cast<LogsApplication*>( qApp )->logsFeaturePreloadingEnabled() ){
   461         endFakeExit();
   466         mComponentsRepository->model()->refreshData();
       
   467         TsTaskSettings taskSettings;
       
   468         taskSettings.setVisibility(true);
       
   469     }
   462     }
   470     
   463     
   471     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::appGainedForeground()" );
   464     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::appGainedForeground()" );
       
   465 }
       
   466 
       
   467 // -----------------------------------------------------------------------------
       
   468 //
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 void LogsViewManager::appLostForeground()
       
   472 {
       
   473     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::appLostForeground()" );
       
   474     
       
   475     if ( mSettings.logsFeatureFakeExitEnabled() ){
       
   476         doExitApplication(false); // Bypass view exit handling
       
   477     }
       
   478     // TODO: non-continuus app should also do exit at this point if 
       
   479     // didn't loose foreground because of embedded app. However, no sensible
       
   480     // way at the moment for handling embedded app foreground monitoring.
       
   481     
       
   482     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::appLostForeground()" );
   472 }
   483 }
   473 
   484 
   474 // -----------------------------------------------------------------------------
   485 // -----------------------------------------------------------------------------
   475 //
   486 //
   476 // -----------------------------------------------------------------------------
   487 // -----------------------------------------------------------------------------
   477 //
   488 //
   478 void LogsViewManager::activityRequested(const QString &activityId)
   489 void LogsViewManager::activityRequested(const QString &activityId)
   479 {
   490 {
   480     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::activityRequested()" );
   491     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::activityRequested()" );
   481     if ( doLoadActivity(activityId) ){
   492     if ( doLoadActivity(activityId) ){
   482         clearActivities();
       
   483         mMainWindow.bringAppToForeground();
   493         mMainWindow.bringAppToForeground();
   484     }
   494     }
   485     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::activityRequested()" );
   495     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::activityRequested()" );
       
   496 }
       
   497 
       
   498 // -----------------------------------------------------------------------------
       
   499 //
       
   500 // -----------------------------------------------------------------------------
       
   501 //
       
   502 void LogsViewManager::bgStartupForegroundGained()
       
   503 {
       
   504     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::bgStartupForegroundGained()" );
       
   505     delete mBackgroundStartupWatcher;
       
   506     mBackgroundStartupWatcher = 0;
       
   507     endFakeExit();
       
   508     mMainWindow.bringAppToForeground(); 
       
   509     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::bgStartupForegroundGained()" );
   486 }
   510 }
   487 
   511 
   488 // -----------------------------------------------------------------------------
   512 // -----------------------------------------------------------------------------
   489 //
   513 //
   490 // -----------------------------------------------------------------------------
   514 // -----------------------------------------------------------------------------
   495     HbActivityManager* activityManager = 
   519     HbActivityManager* activityManager = 
   496         static_cast<HbApplication*>(qApp)->activityManager();
   520         static_cast<HbApplication*>(qApp)->activityManager();
   497     connect( activityManager, SIGNAL(activityRequested(QString)), 
   521     connect( activityManager, SIGNAL(activityRequested(QString)), 
   498              this, SLOT(activityRequested(QString)), Qt::UniqueConnection );
   522              this, SLOT(activityRequested(QString)), Qt::UniqueConnection );
   499     mComponentsRepository->model()->compressData();
   523     mComponentsRepository->model()->compressData();
   500     TsTaskSettings taskSettings;
   524     setTaskSwitcherVisibility(false);
   501     taskSettings.setVisibility(false);
   525 }
       
   526 
       
   527 // -----------------------------------------------------------------------------
       
   528 //
       
   529 // -----------------------------------------------------------------------------
       
   530 //
       
   531 void LogsViewManager::endFakeExit()
       
   532 {
       
   533     setTaskSwitcherVisibility(true);
       
   534     mComponentsRepository->model()->refreshData();
       
   535     if ( !mMainWindow.currentView() ){
       
   536         activateDefaultView();
       
   537     }
       
   538     clearActivities();
   502 }
   539 }
   503 
   540 
   504 // -----------------------------------------------------------------------------
   541 // -----------------------------------------------------------------------------
   505 //
   542 //
   506 // -----------------------------------------------------------------------------
   543 // -----------------------------------------------------------------------------
   544         QByteArray serializedActivity = hbApp->activateData().toByteArray();
   581         QByteArray serializedActivity = hbApp->activateData().toByteArray();
   545         QDataStream stream(&serializedActivity, QIODevice::ReadOnly);
   582         QDataStream stream(&serializedActivity, QIODevice::ReadOnly);
   546         
   583         
   547         QVariant args = matchingView->loadActivity(activityId, stream, params);
   584         QVariant args = matchingView->loadActivity(activityId, stream, params);
   548         loaded = doActivateView( 
   585         loaded = doActivateView( 
   549             matchingView->viewId(), showDialpad, args, dialpadText, true );
   586             matchingView->viewId(), showDialpad, args, dialpadText );
   550     }
   587     }
   551     
   588     
   552     LOGS_QDEBUG_2( "logs [UI] <- LogsViewManager::doLoadActivity() loaded:", loaded );
   589     LOGS_QDEBUG_2( "logs [UI] <- LogsViewManager::doLoadActivity() loaded:", loaded );
   553     return loaded;
   590     return loaded;
   554 }
   591 }
   577     const QString& dialpadText, const QVariant& args)
   614     const QString& dialpadText, const QVariant& args)
   578 {
   615 {
   579     LOGS_QDEBUG_2( "logs [UI] -> LogsViewManager::activateViewViaService()", viewId );
   616     LOGS_QDEBUG_2( "logs [UI] -> LogsViewManager::activateViewViaService()", viewId );
   580     clearActivities();
   617     clearActivities();
   581     closeEmbeddedApplication();
   618     closeEmbeddedApplication();
   582     mMainWindow.bringAppToForeground();
       
   583     Dialpad* dpad = mComponentsRepository->dialpad();
   619     Dialpad* dpad = mComponentsRepository->dialpad();
   584     if ( !showDialpad ){
   620     if ( !showDialpad ){
   585         dpad->closeDialpad();
   621         dpad->closeDialpad();
   586     }
   622     }
   587     dpad->editor().setText(dialpadText);
   623     dpad->editor().setText(dialpadText);
   588     doActivateView(viewId, showDialpad, args, QString(), true);
   624     if ( doActivateView(viewId, showDialpad, args, QString(), true) ){
       
   625         mMainWindow.bringAppToForeground();
       
   626     }
   589     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::activateViewViaService()" );
   627     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::activateViewViaService()" );
   590 }
   628 }
       
   629 
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 // -----------------------------------------------------------------------------
       
   633 //
       
   634 void LogsViewManager::setTaskSwitcherVisibility(bool visible)
       
   635 {
       
   636     LOGS_QDEBUG_2( "logs [UI] -> LogsViewManager::setTaskSwitcherVisibility()", visible );
       
   637     TsTaskSettings taskSettings;
       
   638     taskSettings.setVisibility(visible);
       
   639 }
       
   640 
       
   641 // -----------------------------------------------------------------------------
       
   642 //
       
   643 // -----------------------------------------------------------------------------
       
   644 //
       
   645 void LogsViewManager::doExitApplication(bool viewExitHandling)
       
   646 {
       
   647     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::doExitApplication()" );
       
   648     
       
   649     bool exitAllowed( true );
       
   650     foreach ( LogsBaseView* view, mViewStack ){
       
   651         if ( viewExitHandling ){
       
   652             view->handleExit();
       
   653         }
       
   654         if ( !view->isExitAllowed() ){
       
   655             exitAllowed = false;
       
   656             connect( view, SIGNAL(exitAllowed()),
       
   657                      this, SLOT(proceedExit()), 
       
   658                      Qt::UniqueConnection );
       
   659         }
       
   660     }
       
   661     if ( exitAllowed ){
       
   662         LOGS_QDEBUG( "logs [UI] Handle exit immediately" );
       
   663         proceedExit();
       
   664     } else {
       
   665         // Just wait for signal from view(s) that exiting can proceed
       
   666         LOGS_QDEBUG( "logs [UI] Delayed exit handling" );
       
   667     }
       
   668     
       
   669     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::doExitApplication()" );
       
   670 }
       
   671 
       
   672 // -----------------------------------------------------------------------------
       
   673 //
       
   674 // -----------------------------------------------------------------------------
       
   675 //
       
   676 void LogsViewManager::activateDefaultView()
       
   677 {
       
   678     changeRecentView( XQService::LogsViewAll, false );
       
   679 }