logsui/logsapp/src/logsviewmanager.cpp
changeset 0 4a5361db8937
child 2 7119b73b84d6
equal deleted inserted replaced
-1:000000000000 0:4a5361db8937
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 //USER
       
    18 #include "logsviewmanager.h"
       
    19 #include "logscomponentrepository.h"
       
    20 #include "logsrecentcallsview.h"
       
    21 #include "logsmatchesview.h"
       
    22 #include "logsdetailsview.h"
       
    23 #include "logsfilter.h"
       
    24 #include "logsdefs.h"
       
    25 #include "logslogger.h"
       
    26 #include "logsservicehandler.h"
       
    27 #include "logsmainwindow.h"
       
    28 
       
    29 //SYSTEM
       
    30 #include <hbmainwindow.h>
       
    31 #include <hbview.h>
       
    32 #include <logsservices.h>
       
    33 #include <QApplication>
       
    34 #include <hblineedit.h>
       
    35 #include <dialpad.h>
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // LogsViewManager::LogsViewManager
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 LogsViewManager::LogsViewManager( 
       
    42         LogsMainWindow& mainWindow, LogsServiceHandler& service ) : 
       
    43     QObject( 0 ), mMainWindow( mainWindow ), mService( service ), 
       
    44     mFirstActivation(true), mViewActivationShowDialpad(false)
       
    45 {
       
    46     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::LogsViewManager()" );
       
    47 
       
    48     //It is important that we always handle orientation change first, before
       
    49     //dialpad widget. If connection is moved to a view, then it's not guarantied.
       
    50     connect( &mainWindow, SIGNAL(orientationChanged(Qt::Orientation)),
       
    51             this, SLOT(handleOrientationChanged()) );
       
    52 
       
    53     mComponentsRepository = new LogsComponentRepository(*this);
       
    54     initViews();
       
    55     
       
    56     connect( &mService, SIGNAL( activateView(LogsServices::LogsView, bool) ), 
       
    57              this, SLOT( changeRecentView(LogsServices::LogsView, bool) ) );
       
    58 
       
    59     connect( &mService, SIGNAL( activateView(QString) ), 
       
    60              this, SLOT( changeMatchesView(QString) ));
       
    61     
       
    62     connect( &mMainWindow, SIGNAL(appFocusGained()), this, SLOT(appFocusGained()) );
       
    63     connect( &mMainWindow, SIGNAL(appFocusLost()), this, SLOT(appFocusLost()) );
       
    64     
       
    65     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::LogsViewManager()" );
       
    66 }
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // LogsViewManager::~LogsViewManager
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 LogsViewManager::~LogsViewManager()
       
    74 {
       
    75     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::~LogsViewManager()" );
       
    76      
       
    77     delete mComponentsRepository;
       
    78     
       
    79     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::~LogsViewManager()" );
       
    80 }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // LogsViewManager::initViews
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 void LogsViewManager::initViews()
       
    87 {
       
    88     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     
       
    95     // Don't activate any view, app focus gaining or service request
       
    96     // will cause view activation
       
    97     //
       
    98     LogsRecentCallsView* view = mComponentsRepository->recentCallsView();    
       
    99     Q_ASSERT_X(view != 0, "logs [UI] ", "recentCallsView not found!");
       
   100     LOGS_QDEBUG( "logs [UI] adding view" );
       
   101     mViewStack.append(view);
       
   102     mMainWindow.addView(view);
       
   103         
       
   104     LogsDetailsView* detailsView = mComponentsRepository->detailsView();
       
   105     mViewStack.append(detailsView);
       
   106     mMainWindow.addView(detailsView);
       
   107     
       
   108     LogsMatchesView* matchesView = mComponentsRepository->matchesView();
       
   109     mViewStack.append(matchesView);
       
   110     mMainWindow.addView(matchesView);
       
   111 
       
   112     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::initViews()" );
       
   113 }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // LogsViewManager::changeRecentView
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void LogsViewManager::changeRecentView(LogsServices::LogsView view, bool showDialpad)
       
   120 {
       
   121     QVariant args(view);
       
   122     doActivateView(LogsRecentViewId, showDialpad, args);
       
   123 }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // LogsViewManager::changeMatchesView
       
   127 // -----------------------------------------------------------------------------
       
   128 //
       
   129 void LogsViewManager::changeMatchesView(QString dialpadText)
       
   130 {
       
   131     Dialpad* dialpad = mComponentsRepository->dialpad();
       
   132     dialpad->editor().setText(dialpadText);
       
   133     doActivateView(LogsMatchesViewId, true, QVariant());
       
   134 }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // LogsViewManager::appFocusGained
       
   138 // Activate recent view if gaining focus first time and app was not started
       
   139 // via highway service. If app was started by using service request, 
       
   140 // wait the request to appear before activating view.
       
   141 // -----------------------------------------------------------------------------
       
   142 //
       
   143 void LogsViewManager::appFocusGained()
       
   144 {
       
   145     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::appFocusGained()" );
       
   146     
       
   147     foreach ( LogsBaseView* view, mViewStack ){
       
   148         disconnect( view, SIGNAL(exitAllowed()), this, SLOT(proceedExit()) );
       
   149     }
       
   150     
       
   151     if ( mFirstActivation && !mService.isStartedUsingService() ){
       
   152         changeRecentView( mService.currentlyActivatedView(), false );
       
   153         mMainWindow.bringAppToForeground();
       
   154     }
       
   155     
       
   156     mComponentsRepository->model()->refreshData();
       
   157 
       
   158     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::appFocusGained()" );
       
   159 }
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // LogsViewManager::appFocusLost
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void LogsViewManager::appFocusLost()
       
   166 {
       
   167     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::appFocusLost()" );
       
   168     
       
   169     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::appFocusLost()" );
       
   170 }
       
   171 
       
   172 // -----------------------------------------------------------------------------
       
   173 // LogsViewManager::proceedExit
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void LogsViewManager::proceedExit()
       
   177 {
       
   178     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::proceedExit()" );
       
   179     
       
   180     mComponentsRepository->model()->compressData();
       
   181     
       
   182     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::proceedExit()" );
       
   183 }
       
   184 
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // LogsViewManager::activateView
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 bool LogsViewManager::activateView(LogsAppViewId viewId)
       
   191 {
       
   192     return doActivateView(viewId, false, QVariant());
       
   193 }
       
   194 
       
   195 // -----------------------------------------------------------------------------
       
   196 // LogsViewManager::activateView
       
   197 // -----------------------------------------------------------------------------
       
   198 //
       
   199 bool LogsViewManager::activateView(
       
   200         LogsAppViewId viewId, bool showDialpad, QVariant args)
       
   201 {
       
   202     return doActivateView(viewId, showDialpad, args);
       
   203 }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // LogsViewManager::mainWindow
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 HbMainWindow& LogsViewManager::mainWindow()
       
   210 {
       
   211     return mMainWindow;
       
   212 }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // LogsViewManager::exitApplication
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 void LogsViewManager::exitApplication()
       
   219 {
       
   220     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::exitApplication()" );
       
   221     
       
   222     LOGS_QDEBUG( "logs [UI] Exit delayed" );
       
   223     
       
   224     // Fake exit by sending app to background
       
   225     mMainWindow.sendAppToBackground();
       
   226     
       
   227     // Set application to default state (recent calls and no dialpad)
       
   228     activateView( LogsRecentViewId, false, QVariant() );
       
   229     mComponentsRepository->recentCallsView()->resetView();
       
   230 
       
   231     bool exitAllowed( true );
       
   232     foreach ( LogsBaseView* view, mViewStack ){
       
   233         if ( !view->isExitAllowed() ){
       
   234             exitAllowed = false;
       
   235             connect( view, SIGNAL(exitAllowed()), this, SLOT(proceedExit()) );
       
   236         }
       
   237     }
       
   238     if ( exitAllowed ){
       
   239         LOGS_QDEBUG( "logs [UI] Handle exit immediataly" );
       
   240         proceedExit();
       
   241     } else {
       
   242         // Just wait for signal from view(s) that exiting can proceed
       
   243         LOGS_QDEBUG( "logs [UI] Delayed exit handling" );
       
   244     }
       
   245     
       
   246     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::exitApplication()" );
       
   247 }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // LogsViewManager::activatePreviousView
       
   251 // Previously activated view is at slot 1 of view stack
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 bool LogsViewManager::activatePreviousView()
       
   255 {
       
   256     if ( mViewStack.count() < 2 ){
       
   257         return false;
       
   258     }
       
   259     return doActivateView(mViewStack.at(1)->viewId(), false, QVariant());
       
   260 }
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // LogsViewManager::doActivateView
       
   264 // Currently activated view is always at beginning of view stack. Deactivates
       
   265 // previously activated view and activates new view and place it at top of
       
   266 // view stack.
       
   267 // -----------------------------------------------------------------------------
       
   268 //
       
   269 bool LogsViewManager::doActivateView(
       
   270         LogsAppViewId viewId, bool showDialpad, QVariant args)
       
   271 {
       
   272     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::doActivateView()" );
       
   273     
       
   274     bool activated(false);
       
   275     LogsBaseView* newView = 0; 
       
   276     LogsBaseView* oldView = mViewStack.count() > 0 ? mViewStack.at(0) : 0;
       
   277     
       
   278     for ( int i = 0; i < mViewStack.count(); ++i ){
       
   279         if ( mViewStack.at(i)->viewId() == viewId ){
       
   280             newView = mViewStack.takeAt(i);
       
   281         }
       
   282     }
       
   283     
       
   284     if ( oldView && newView && oldView != newView ){   
       
   285         oldView->deactivated();
       
   286         disconnect( &mMainWindow, SIGNAL( callKeyPressed() ), oldView, 0 );
       
   287     }
       
   288     
       
   289     if ( newView ){
       
   290         mViewStack.insert(0, newView);
       
   291         mMainWindow.setCurrentView(newView);
       
   292         mViewActivationArgs = args;
       
   293         mViewActivationShowDialpad = showDialpad;
       
   294         completeViewActivation();
       
   295         activated = true;
       
   296     }
       
   297 
       
   298     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::doActivateView()" );
       
   299     
       
   300     return activated;
       
   301 }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // LogsViewManager::completeViewActivation
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 void LogsViewManager::completeViewActivation()
       
   308 {
       
   309     LOGS_QDEBUG_2( "logs [UI] -> LogsViewManager::completeViewActivation(), first", 
       
   310                    mFirstActivation );
       
   311     if ( mFirstActivation ){
       
   312         mFirstActivation = false;
       
   313         connect( &mMainWindow, SIGNAL(viewReady()), this, SLOT(completeViewActivation()) );
       
   314     } else {
       
   315         disconnect( &mMainWindow, SIGNAL(viewReady()), this, SLOT(completeViewActivation()) );
       
   316         LogsBaseView* newView = mViewStack.at(0);
       
   317         newView->activated(mViewActivationShowDialpad, mViewActivationArgs);
       
   318         connect( &mMainWindow, SIGNAL( callKeyPressed() ), newView, SLOT( callKeyPressed() ) );
       
   319         
       
   320         // First activation completed, clear counter
       
   321         mComponentsRepository->model()->clearMissedCallsCounter();
       
   322     }
       
   323     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::completeViewActivation()" );
       
   324 }
       
   325 
       
   326 // -----------------------------------------------------------------------------
       
   327 //
       
   328 // -----------------------------------------------------------------------------
       
   329 //
       
   330 void LogsViewManager::handleOrientationChanged()
       
   331 {
       
   332     LOGS_QDEBUG( "logs [UI] -> LogsViewManager::handleOrientationChanged()" );
       
   333     QMetaObject::invokeMethod(mMainWindow.currentView(), "handleOrientationChanged");
       
   334     LOGS_QDEBUG( "logs [UI] <- LogsViewManager::handleOrientationChanged()" );
       
   335 }