mmsharing/livecommsui/lcui/src/lcviewmanager_p.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     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 
       
    18 // USER INCLUDES
       
    19 #include "lcviewmanager_p.h"
       
    20 #include "lcuicomponentrepository.h"
       
    21 #include "lcuidefs.h"
       
    22 #include "lcuiengine.h"
       
    23 #include "lcview.h"
       
    24 #include "lclogger.h"
       
    25 
       
    26 // SYSTEM INCLUDES
       
    27 #include <hbmainwindow.h>
       
    28 #include <hbdialog.h>
       
    29 #include <hbaction.h>
       
    30 #include <qcoreapplication.h>
       
    31 #include <hbactivitymanager.h>
       
    32 #include <hbapplication.h>
       
    33 #include <hbapplication.h>
       
    34 
       
    35 // CONSTANTS
       
    36 #define LC_VIEWMANAGER_SLOT_ACTIVATE_CURRENT_VIEW "activateCurrentView" 
       
    37 
       
    38 
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // LcMainWindow::LcMainWindow
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 LcMainWindow::LcMainWindow() : 
       
    45     HbMainWindow(0, Hb::WindowFlagFixedHorizontal | Hb::WindowFlagTransparent)
       
    46 {
       
    47     // TODO: remove flag WindowFlagFixedHorizontal if portait layout
       
    48     // is going to be supported.
       
    49     qApp->installEventFilter(this);
       
    50 }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // LcMainWindow::~LcMainWindow
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 LcMainWindow::~LcMainWindow()
       
    57 {
       
    58 }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // LcMainWindow::eventFilter
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 bool LcMainWindow::eventFilter ( QObject * watched, QEvent * event )
       
    65 {    
       
    66     if ( event->type() == QEvent::ApplicationActivate ){
       
    67         LC_QDEBUG( "livecomms [UI] -> LcMainWindow::eventFilter(), ApplicationActivate" )
       
    68         emit appFocusGained();
       
    69     } else if (( event->type() == QEvent::ApplicationDeactivate ) && 
       
    70             ( !this->windowSurface()) ){
       
    71         LC_QDEBUG( "livecomms [UI] -> LcMainWindow::eventFilter(), ApplicationDeactivate" )
       
    72         emit appFocusLost();
       
    73     }
       
    74     return QObject::eventFilter(watched, event);
       
    75 }
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // LcViewManagerPrivate::LcViewManagerPrivate
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 LcViewManagerPrivate::LcViewManagerPrivate(
       
    83     const QString& engineName,
       
    84     const QString& applicationDisplayName) :
       
    85     mEngine( 0 ),
       
    86     mRepository( 0 )
       
    87 {
       
    88     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::LcViewManagerPrivate()" )
       
    89     
       
    90     mEngine = new LcUiEngine( engineName, applicationDisplayName );
       
    91     mRepository = new LcUiComponentRepository( *mEngine );
       
    92     setCurrentView( true );
       
    93         
       
    94     connect(&mMainWindow, SIGNAL(appFocusGained()), mEngine, SLOT(maximize()));
       
    95     connect(&mMainWindow, SIGNAL(appFocusLost()), mEngine, SLOT(minimize()));
       
    96     
       
    97     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::LcViewManagerPrivate()" )
       
    98 }
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // LcViewManagerPrivate::~LcViewManagerPrivate
       
   102 // -----------------------------------------------------------------------------
       
   103 //
       
   104 LcViewManagerPrivate::~LcViewManagerPrivate()
       
   105 {
       
   106     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::~LcViewManagerPrivate()" )
       
   107 
       
   108     delete mEngine;
       
   109     QList<HbView *> views = mMainWindow.views();
       
   110     foreach( HbView* view, views ){
       
   111         mMainWindow.removeView(view);
       
   112     }
       
   113     delete mRepository;    
       
   114 
       
   115     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::~LcViewManagerPrivate()" ) 
       
   116 }
       
   117 
       
   118 // -----------------------------------------------------------------------------
       
   119 // LcViewManagerPrivate::terminateSession
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 void LcViewManagerPrivate::terminateSession()
       
   123 {
       
   124     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::terminateSession" )
       
   125     mEngine->stop(); 
       
   126     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::terminateSession" )
       
   127 }
       
   128 
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // LcViewManagerPrivate::prepareOrientationChange
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 void LcViewManagerPrivate::prepareOrientationChange()
       
   135 {
       
   136     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::prepareOrientationChange()" )
       
   137     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::prepareOrientationChange()" )
       
   138 }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // LcViewManagerPrivate::activateCurrentView
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 void LcViewManagerPrivate::activateCurrentView(bool startup)
       
   145 {
       
   146     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::activateCurrentView()" )
       
   147     if ( mMainWindow.currentView() ) {
       
   148         static_cast<LcView*>( mMainWindow.currentView() )->activated();
       
   149     }
       
   150     
       
   151     if ( startup ){
       
   152         LC_QDEBUG( "livecomms [UI]  Start engine" )
       
   153         startEngine();
       
   154     }
       
   155     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::activateCurrentView()" )
       
   156 }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // LcViewManagerPrivate::startEngine
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void LcViewManagerPrivate::startEngine()
       
   163 {
       
   164     connect(mEngine, SIGNAL(layoutChanged()), this, SLOT(changeView()), 
       
   165         Qt::QueuedConnection );
       
   166     connect(mEngine, SIGNAL(stopped()), this, SLOT(closeApp()), 
       
   167         Qt::QueuedConnection );
       
   168     
       
   169     mEngine->setUiComponents( mRepository->invitingNote(), 
       
   170                               mRepository->waitingNote(), 
       
   171                               mRepository->acceptQuery(), 
       
   172                               mRepository->recipientQuery(),
       
   173                               mRepository->shareOwnVideoQuery() );    
       
   174     mEngine->start();
       
   175 }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // LcViewManagerPrivate::setCurrentView
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 void LcViewManagerPrivate::setCurrentView(bool startup)
       
   182 {
       
   183     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::setCurrentView()" )
       
   184 
       
   185     LcView* currView = currentView();
       
   186     
       
   187     bool found(false);
       
   188     foreach ( HbView* view, mMainWindow.views() ){
       
   189         found |= ( view == currView );
       
   190     }
       
   191     if ( !found ){
       
   192         mMainWindow.addView( currView );
       
   193     }
       
   194     mMainWindow.setCurrentView( currView );
       
   195     
       
   196     LcUtil::asyncSlotCall( 
       
   197         this, LC_VIEWMANAGER_SLOT_ACTIVATE_CURRENT_VIEW, Q_ARG( bool, startup ) );
       
   198     
       
   199     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::setCurrentView()" )
       
   200 }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // LcViewManagerPrivate::currentView
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 LcView* LcViewManagerPrivate::currentView()
       
   207 {
       
   208     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::currentView()" )
       
   209 
       
   210     LcViewLayoutHint hint = mEngine->viewLayout();
       
   211     LcView* nextView = 0;
       
   212     
       
   213     switch ( hint ) {
       
   214         case Lc_ReceivedViewLayout:
       
   215             LC_QDEBUG( "livecomms [UI] - switching to receive view -" )
       
   216             nextView = mRepository->receiveView();
       
   217             break;
       
   218         case Lc_ReceivedOnlyViewLayout:
       
   219             LC_QDEBUG( "livecomms [UI] - switching to receive only view -" )
       
   220             nextView = mRepository->receiveOnlyView();
       
   221             break;
       
   222         case Lc_AllInOneViewLayout:
       
   223             LC_QDEBUG( "livecomms [UI] - switching to allinone view -" )
       
   224             nextView = mRepository->allInOneView();
       
   225             break;
       
   226         case Lc_TwowayViewLayout:
       
   227             LC_QDEBUG( "livecomms [UI] - switching to twoway view -" )
       
   228             nextView = mRepository->twowayView();
       
   229             break;
       
   230         case Lc_SharedViewLayout:
       
   231             LC_QDEBUG( "livecomms [UI] - switching to send view -" )
       
   232             nextView = mRepository->sendView();
       
   233             break;
       
   234         default:
       
   235             LC_QDEBUG( "livecomms [UI] - switching to idle view -" )
       
   236             nextView = mRepository->idleView();
       
   237             break;
       
   238     }
       
   239     if ( !nextView && hint > Lc_IdleViewLayout ) {
       
   240         LC_QDEBUG( "livecomms [UI] ! could not get view !" )
       
   241         LC_QDEBUG( "livecomms [UI] - switching to idle view -" )
       
   242         nextView = mRepository->idleView();
       
   243     }
       
   244     
       
   245     if ( !nextView ) {
       
   246         LC_QCRITICAL( "livecomms [UI] ! still could not get view !. ABORT" )
       
   247         LC_PANIC();
       
   248     }
       
   249     
       
   250     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::currentView()" )
       
   251     return nextView;
       
   252 }
       
   253 
       
   254 // -----------------------------------------------------------------------------
       
   255 // LcViewManagerPrivate::changeView
       
   256 // -----------------------------------------------------------------------------
       
   257 //
       
   258 void LcViewManagerPrivate::changeView()
       
   259 {
       
   260     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::changeView()" )
       
   261 
       
   262     LcView* currentView = static_cast<LcView*>( mMainWindow.currentView() );
       
   263     currentView->deactivated();
       
   264     setCurrentView();
       
   265     
       
   266     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::changeView()" )
       
   267 }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // LcViewManagerPrivate::closeApp
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 void LcViewManagerPrivate::closeApp()
       
   274 {
       
   275     LC_QDEBUG( "livecomms [UI] -> LcViewManagerPrivate::closeApp()" )
       
   276     
       
   277     qApp->exit(0);
       
   278     
       
   279     LC_QDEBUG( "livecomms [UI] <- LcViewManagerPrivate::closeApp()" )
       
   280 }
       
   281 
       
   282 // End of file