ui/viewmanagement/viewmanager/src/glxviewmanager.cpp
branchRCL_3
changeset 59 8e5f6eea9c9f
equal deleted inserted replaced
57:ea65f74e6de4 59:8e5f6eea9c9f
       
     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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <glxviewmanager.h>
       
    21 #include <glxview.h>
       
    22 #include "glxicondefs.h" //Contains the icon names/Ids
       
    23 #include <glxviewsfactory.h>
       
    24 #include <glxeffectengine.h>
       
    25 #include <hbmainwindow.h>
       
    26 #include <glxexternalutility.h>
       
    27 #include <glxloggerenabler.h>
       
    28 #include <glxmenumanager.h>
       
    29 #include <glxcommandhandlers.hrh>
       
    30 #include <glxplugincommandid.hrh>
       
    31 #include "glxlocalisationstrings.h"
       
    32 
       
    33 #include <hbaction.h>
       
    34 #include <hbtoolbar.h>
       
    35 #include <hbmenu.h>
       
    36 #include <QDebug>
       
    37 #include <hbstyleloader.h>
       
    38 #include <hbprogressdialog.h>
       
    39 #include <QItemSelectionModel>
       
    40 #include <glxmainwindoweventfilter.h>
       
    41 #include <xqsettingsmanager.h>
       
    42 #include <xqsettingskey.h>
       
    43 #include <glxviewids.h>
       
    44 #include "glxmodelroles.h"
       
    45 
       
    46 GlxViewManager::GlxViewManager() 
       
    47     : mBackAction( NULL ), 
       
    48       mMenuManager( NULL ), 
       
    49       mEffectEngine( NULL ), 
       
    50       mViewToolBar( NULL ), 
       
    51       mMarkingToolBar( NULL ), 
       
    52       mSelectionModel ( NULL ),
       
    53       mProgressDialog( NULL )
       
    54 {
       
    55     qDebug("GlxViewManager::GlxViewManager() ");
       
    56 
       
    57     //check the case when application launch through some other application (view plugin)
       
    58     mMainWindow = GlxExternalUtility::instance()->getMainWindow();
       
    59     if(mMainWindow == NULL)	{
       
    60         mMainWindow = new HbMainWindow();
       
    61     }
       
    62     connect(mMainWindow, SIGNAL( viewReady() ), this, SLOT( handleReadyView() ));
       
    63     //Without this Zoom Does not work
       
    64 
       
    65     mWindowEventFilter = new GlxMainWindowEventFilter;
       
    66     mMainWindow->scene()->installEventFilter(mWindowEventFilter);
       
    67     mMainWindow->viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
       
    68     mMainWindow->viewport()->grabGesture(Qt::PinchGesture);
       
    69 
       
    70     HbStyleLoader::registerFilePath(":/data/photos.css");
       
    71 }
       
    72 
       
    73 void GlxViewManager::handleReadyView()
       
    74 {
       
    75     emit actionTriggered( EGlxCmdSetupItem );
       
    76     disconnect( mMainWindow, SIGNAL( viewReady() ), this, SLOT( handleReadyView() ) );
       
    77 }
       
    78 
       
    79 void GlxViewManager::setupItems( )
       
    80 {
       
    81     addBackSoftKeyAction();    
       
    82     addConnection();
       
    83 }
       
    84 
       
    85 void GlxViewManager::launchApplication(qint32 id, QAbstractItemModel *model)
       
    86 {
       
    87     mModel = model;
       
    88     mMenuManager = new GlxMenuManager( mMainWindow );  //menu manager should be created before view.
       
    89     mMenuManager->setModel( mModel );
       
    90     mView = resolveView( id );
       
    91 
       
    92     createToolBar();
       
    93     
       
    94     /* We are showing the toolBar before activating the 
       
    95      * view. This is done to avoid the animation effect seen otherwise 
       
    96      * when the tool bar comes up.
       
    97      * 
       
    98      * If animation Effect is not removed, it leads to flickering effect 
       
    99      * since we are creating a new tool bar..although a fake tool bar was 
       
   100      * already created on the splashscreen
       
   101      * 
       
   102      */
       
   103     mView->activate();
       
   104     mView->setModel( mModel );
       
   105     //visibility of tool bar dependes of view internal state so add the toolbar after setting model
       
   106     mView->addToolBar( mViewToolBar ); 
       
   107     mMainWindow->setCurrentView( mView, false );
       
   108     mMainWindow->showFullScreen();
       
   109 }
       
   110 
       
   111 void GlxViewManager::handleMenuAction(qint32 commandId)
       
   112 {
       
   113     emit actionTriggered(commandId);
       
   114 }
       
   115 
       
   116 void GlxViewManager::handleAction()
       
   117 {
       
   118     HbAction *action = qobject_cast<HbAction*>(sender());
       
   119     action->setChecked( TRUE );
       
   120     qint32 commandId = action->data().toInt();
       
   121     emit actionTriggered(commandId);
       
   122 }
       
   123 
       
   124 void GlxViewManager::addBackSoftKeyAction ( )
       
   125 {
       
   126     qDebug("GlxViewManager::addBackSoftKeyAction ");
       
   127     //create the back soft key action and set the data
       
   128     mBackAction = new HbAction( Hb::BackNaviAction, this );
       
   129     mBackAction->setData( EGlxCmdBack );
       
   130     mBackAction->setObjectName( "App Back" );
       
   131     mView->setNavigationAction( mBackAction );
       
   132 }
       
   133 
       
   134 Qt::Orientation GlxViewManager::orientation() const
       
   135 {
       
   136     return mMainWindow->orientation();
       
   137 }
       
   138 
       
   139 void GlxViewManager::launchView( qint32 id, QAbstractItemModel *model )
       
   140 {
       
   141     qDebug( "GlxViewManager::launchView Id = %d ", id );
       
   142     mModel = model;
       
   143     deActivateView();
       
   144     mMenuManager->setModel( mModel ); //set the model to get the item type info and row count info
       
   145     mView = resolveView( id );
       
   146     activateView();
       
   147 }
       
   148 
       
   149 void GlxViewManager::launchView (qint32 id, QAbstractItemModel *model, GlxEffect effect, GlxViewEffect viewEffect)
       
   150 {
       
   151     qDebug("GlxViewManager::launchView Id = %d effect %d view effect %d", id, effect, viewEffect);
       
   152 
       
   153     //In the case of no animation is play during the view transition just call launch view and return
       
   154     if ( viewEffect == NO_VIEW ) {
       
   155         return launchView(id, model);
       
   156     }
       
   157     
       
   158     //create and registered the effect
       
   159     if ( mEffectEngine == NULL ) { 
       
   160         mEffectEngine = new GlxEffectEngine();
       
   161         mEffectEngine->registerTransitionEffect();
       
   162         connect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinished() ), Qt::QueuedConnection );
       
   163     }
       
   164     
       
   165     QList< QGraphicsItem * > itemList;
       
   166     QGraphicsItem *item = NULL;
       
   167     itemList.clear();
       
   168     
       
   169     //partially clean the view so that animation run smoothly
       
   170     GlxView *curr_view = (GlxView *) mMainWindow->currentView();
       
   171     curr_view->resetView();
       
   172 
       
   173     mMenuManager->setModel( model ); //set the model to get the item type info and row count info
       
   174     mView = resolveView(id);
       
   175     //partially initialise the view so that animation run smoothly
       
   176     mView->initializeView( model, curr_view );
       
   177     mModel = model; 
       
   178 
       
   179     if ( viewEffect == CURRENT_VIEW || viewEffect == BOTH_VIEW ) { 
       
   180         item = curr_view->getAnimationItem(effect);
       
   181         if ( item ) {
       
   182             itemList.append(item);
       
   183             item = NULL;
       
   184         }
       
   185     }
       
   186     
       
   187     if ( viewEffect == LAUNCH_VIEW || viewEffect == BOTH_VIEW ) {
       
   188         item = mView->getAnimationItem(effect);
       
   189         if ( item ) {
       
   190             //increase the z value and show the view to shown the view animation
       
   191             mView->setZValue(curr_view->zValue() + 2);
       
   192             mView->show();
       
   193             item->show();        
       
   194             itemList.append(item);
       
   195         }
       
   196     }
       
   197     
       
   198     if ( effect == GRID_TO_FULLSCREEN ) {
       
   199         mViewToolBar->setZValue( item->zValue() - 5 );
       
   200     }
       
   201     
       
   202     //error check
       
   203     if ( itemList.count() > 0 ) {
       
   204         mEffectEngine->runEffect(itemList, effect);
       
   205         mMainWindow->grabMouse();
       
   206     }
       
   207     else {
       
   208         deActivateView();
       
   209         activateView();       
       
   210     }    
       
   211 }
       
   212 
       
   213 void GlxViewManager::launchProgressDialog( int maxValue )
       
   214 {
       
   215     if ( maxValue <= 0 ) {
       
   216         // TNM return the some error code ( negative value ) until it populated the count
       
   217 		// To show progress dialog 10 is chossen
       
   218 	     maxValue = 10;
       
   219 		          
       
   220     }
       
   221     if ( mProgressDialog == NULL ) {
       
   222         mProgressDialog = new HbProgressDialog( HbProgressDialog::ProgressDialog );
       
   223         mProgressDialog->actions().at(0)->disconnect( SIGNAL( triggered() ) );
       
   224         connect ( mProgressDialog->actions().at(0), SIGNAL( triggered() ), this, SLOT( hideProgressDialog() ) );
       
   225         mProgressDialog->setMinimum( 0 );
       
   226     }
       
   227     mProgressDialog->setMaximum( maxValue );
       
   228     mProgressDialog->setProgressValue( 0 );
       
   229     mProgressDialog->setModal( true );
       
   230     mProgressDialog->actions().at(0)->setText( GLX_BUTTON_HIDE );
       
   231     mProgressDialog->open();
       
   232 }
       
   233 
       
   234 void GlxViewManager::hideProgressDialog( )
       
   235 {
       
   236     mMainWindow->lower();
       
   237 }
       
   238 
       
   239 void GlxViewManager::updateProgressDialog( int currentValue )
       
   240 {
       
   241     static int i = 0;
       
   242     HbIcon icon;
       
   243     User::ResetInactivityTime();  
       
   244 
       
   245     //To:Do temp code remove later
       
   246     if ( mProgressDialog ) {
       
   247         i = ++i % 10;
       
   248         icon = HbIcon( QString( ":/data/Wait/qgn_graf_ring_wait_%1.svg" ).arg( i + 1, 2, 10, QChar( '0' ) ) );
       
   249         mProgressDialog->setIcon(icon);
       
   250         
       
   251         int max = mProgressDialog->maximum() ;
       
   252         if ( currentValue > max ) {
       
   253             mProgressDialog->setMaximum( currentValue );
       
   254             max = currentValue ;
       
   255         }
       
   256         
       
   257         if ( currentValue < 0 ) {
       
   258             mProgressDialog->setText( QString( GLX_REFRESHING ) ); //To:Do string will change later
       
   259             mProgressDialog->setProgressValue( 0 );
       
   260         }
       
   261         else {
       
   262             int value = max - currentValue;
       
   263             mProgressDialog->setProgressValue( value );
       
   264             mProgressDialog->setText( QString( " %1 " ).arg( currentValue ) );
       
   265         }
       
   266     }
       
   267 }
       
   268 
       
   269 //to be called only when the photos plugin was activated by external means
       
   270 void GlxViewManager::deactivateCurrentView()
       
   271 {
       
   272     GlxView *curr_view = (GlxView *) mMainWindow->currentView();
       
   273     if ( curr_view ) {
       
   274         curr_view->deActivate() ;
       
   275     }
       
   276 }
       
   277 
       
   278 void GlxViewManager::updateToolBarIcon(int id)
       
   279 {
       
   280     QString path;
       
   281     int toolBarActionId = (int) GLX_ALL_ACTION_ID;
       
   282     int count = mActionList.count();
       
   283     
       
   284     qDebug("GlxViewManager::updateToolBarIcon() action ID list %d count %d", id, count);
       
   285     
       
   286     for ( int i = 0; i < count ; i++ ) {
       
   287         qDebug("GlxViewManager::updateToolBarIcon() toolBarActionId %d value %d", toolBarActionId, ( id & toolBarActionId ) );
       
   288         //check and get the icon path
       
   289         if ( ( id & toolBarActionId ) == toolBarActionId ) {
       
   290             mActionList[i]->setChecked(TRUE);                        
       
   291         }
       
   292         else {
       
   293             mActionList[i]->setChecked(FALSE);
       
   294         }
       
   295         //to get it the next action id to verify it is selecter or not
       
   296         toolBarActionId = toolBarActionId << 1; 
       
   297     }
       
   298 }
       
   299 
       
   300 void GlxViewManager::checkMarked()
       
   301 {
       
   302     qDebug("GlxViewManager::checkMarked");
       
   303     QModelIndexList selectedModelIndex = mSelectionModel->selectedIndexes();
       
   304     for ( int i = 0 ; i <  mMarkingActionList.count(); i++) {
       
   305         if( mMarkingActionList.at(i)->data()==EGlxCmdSelect) {
       
   306        	    bool noSelection=selectedModelIndex.empty();
       
   307             mMarkingActionList.at(i)->setDisabled(noSelection);
       
   308             break;
       
   309         }
       
   310     }
       
   311 }
       
   312 
       
   313 void GlxViewManager::enterMarkingMode(qint32 viewId)
       
   314 {
       
   315     GlxView *view = findView ( viewId );
       
   316     qDebug("GlxViewManager::enterMarkingMode view ID %d", viewId);
       
   317     
       
   318     if ( mMarkingToolBar == NULL) {
       
   319         createMarkingModeToolBar(); //Marking mode tool bar is different from normal mode tool bar
       
   320     }
       
   321     
       
   322     if ( view ) { 
       
   323         view->enableMarking();
       
   324         view->takeToolBar();
       
   325         view->addToolBar(mMarkingToolBar);
       
   326         mSelectionModel = view->getSelectionModel();
       
   327         if(mSelectionModel) 
       
   328         {
       
   329             connect(mSelectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection& ) ), this, SLOT(checkMarked()));
       
   330             checkMarked();
       
   331         }
       
   332     }
       
   333     qDebug("GlxViewManager::enterMarkingMode view ID %d exit", viewId);
       
   334 }
       
   335 
       
   336 void GlxViewManager::exitMarkingMode(qint32 viewId)
       
   337 {
       
   338     GlxView *view = findView ( viewId );
       
   339     qDebug("GlxViewManager::exitMarkingMode view ID %d", viewId);
       
   340     if ( view ) { 
       
   341         view->disableMarking(); 
       
   342         view->takeToolBar();
       
   343         view->addToolBar(mViewToolBar);
       
   344         if(mSelectionModel)
       
   345         {
       
   346             disconnect(mSelectionModel, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection& ) ), this, SLOT(checkMarked()));
       
   347         }
       
   348     }
       
   349     qDebug("GlxViewManager::exitMarkingMode view ID %d exit", viewId);
       
   350 }
       
   351 
       
   352 void GlxViewManager::handleUserAction(qint32 viewId, qint32 commandId)
       
   353 {
       
   354     GlxView *view = findView ( viewId );
       
   355     qDebug("GlxViewManager::handleUserAction view ID %d command id %d", viewId, commandId);
       
   356     if ( view ) { 
       
   357         view->handleUserAction(commandId);
       
   358     }    
       
   359 }
       
   360 
       
   361 QItemSelectionModel *  GlxViewManager::getSelectionModel(qint32 viewId) 
       
   362 { 
       
   363     GlxView *view = findView ( viewId );
       
   364     if ( view ) { 
       
   365         return view->getSelectionModel();
       
   366     }
       
   367     return NULL;
       
   368 }
       
   369 
       
   370 void GlxViewManager::setModel( QAbstractItemModel *model )
       
   371 {
       
   372     if ( mView ) {
       
   373         mView->setModel( model ) ;
       
   374     }
       
   375     
       
   376     if ( mMenuManager ) {
       
   377         mMenuManager->setModel( model );
       
   378     }    
       
   379 }
       
   380 
       
   381 GlxView * GlxViewManager::resolveView( qint32 id )
       
   382 {
       
   383     qDebug("GlxViewManager::resolveView %d", id );
       
   384     GlxView *view = findView ( id );
       
   385     if ( view ) {
       
   386         return view ;
       
   387     }
       
   388     
       
   389     view = GlxViewsFactory::createView( id, mMainWindow );
       
   390     if ( view ) {
       
   391         connect ( view, SIGNAL( actionTriggered( qint32 ) ), this, SLOT( actionProcess( qint32 ) ), Qt::QueuedConnection );
       
   392         connect ( view, SIGNAL( itemSpecificMenuTriggered( qint32, QPointF ) ), this, SLOT( itemSpecificMenuTriggered( qint32, QPointF ) ), Qt::QueuedConnection );
       
   393         mViewList.append( view );
       
   394         mMainWindow->addView( view );
       
   395         mMenuManager->addMenu( id, view->menu() );
       
   396         
       
   397         if ( mBackAction ) {
       
   398             view->setNavigationAction( mBackAction );
       
   399         }
       
   400     }
       
   401     return view;
       
   402 }
       
   403 
       
   404 void GlxViewManager::itemSpecificMenuTriggered(qint32 viewId,QPointF pos)
       
   405 {
       
   406     mMenuManager->ShowItemSpecificMenu(viewId,pos);
       
   407 }
       
   408 
       
   409 void GlxViewManager::cancelTimer()
       
   410 {
       
   411     emit externalCommand(EGlxPluginCmdUserActivity);
       
   412 }
       
   413 
       
   414 void GlxViewManager::effectFinished( )
       
   415 {
       
   416     qDebug("GlxViewManager::EffectFinished");
       
   417     mMainWindow->releaseMouse();
       
   418     deActivateView();
       
   419     activateView(); 
       
   420 }
       
   421 
       
   422 GlxView * GlxViewManager::findView(qint32 id)
       
   423 {
       
   424     qDebug("GlxViewManager::findView Id = %d ", id);
       
   425     int count = mViewList.count();
       
   426     
       
   427     for ( int i = 0 ; i < count; i++) {
       
   428         if ( mViewList.at(i)->compare(id) ) {
       
   429             return mViewList.at(i);
       
   430         }
       
   431     }
       
   432     return NULL;
       
   433 }
       
   434 
       
   435 void GlxViewManager::deActivateView()
       
   436 {
       
   437     qDebug("GlxViewManager::deActivateCurrentView()");
       
   438     
       
   439     GlxView *view = (GlxView *) mMainWindow->currentView();
       
   440     if ( view ){
       
   441         view->deActivate() ;
       
   442     }
       
   443     if (mView && view) {
       
   444         mView->setZValue(view->zValue());
       
   445     }
       
   446 }
       
   447 
       
   448 void GlxViewManager::activateView()
       
   449 {
       
   450     qDebug("GlxViewManager::activateView()");
       
   451 
       
   452     mView->activate();
       
   453     mView->show();
       
   454     mView->setModel( mModel );
       
   455     //visibility of tool bar dependes of view internal state so add the toolbar after setting model
       
   456     mView->addToolBar( mViewToolBar );
       
   457     mMainWindow->setCurrentView(mView, false);
       
   458     mMainWindow->showFullScreen(); 
       
   459 }
       
   460 
       
   461 void GlxViewManager::createActions()
       
   462 {
       
   463     qDebug("GlxViewManager::createActions() " );
       
   464     mActionList.clear();  
       
   465 
       
   466     int curSubstate = getSubState();    
       
   467     
       
   468     //create the All tool bar button action
       
   469     HbAction* allAction = new HbAction( this );
       
   470 
       
   471     if( curSubstate == FETCHER_ITEM_S ) {
       
   472         allAction->setData( EGlxCmdFetcherAllGridOpen );
       
   473     }else{
       
   474         allAction->setData( EGlxCmdAllGridOpen );
       
   475     }
       
   476 
       
   477     mActionList.append( allAction );    
       
   478     allAction->setIcon( HbIcon( GLXICON_ALL ) ) ;
       
   479     allAction->setObjectName( "All Action" );
       
   480        
       
   481     //create the Album tool bar button action
       
   482     HbAction* albumAction = new HbAction( this );
       
   483 
       
   484     if( curSubstate == FETCHER_ITEM_S ) {
       
   485         albumAction->setData( EGlxCmdFetcherAlbumListOpen );
       
   486     }else{
       
   487         albumAction->setData( EGlxCmdAlbumListOpen );
       
   488     }
       
   489 
       
   490     mActionList.append( albumAction );
       
   491     albumAction->setIcon( HbIcon( GLXICON_ALBUMS ) ) ;
       
   492     albumAction->setObjectName( "Album Action" );
       
   493 	
       
   494 	//in case of fetcher no need to create other actions
       
   495 	if( curSubstate == FETCHER_ITEM_S ) {
       
   496 		return;
       
   497 		}	
       
   498     //create the album tool bar button action
       
   499     HbAction* cameraAction = new HbAction( this );
       
   500     cameraAction->setData( EGlxCmdCameraOpen );
       
   501     mActionList.append( cameraAction );  
       
   502     cameraAction->setIcon( HbIcon( GLXICON_CAMERA ) ) ;
       
   503     cameraAction->setObjectName( "Camera Action" );
       
   504     
       
   505     //Configure the 4 th Action in the tool bar
       
   506     XQSettingsManager *ciSettingsManager = NULL;
       
   507     ciSettingsManager = new XQSettingsManager(this);
       
   508     
       
   509     
       
   510     XQSettingsKey* operatorLinkCenrepKey = NULL;
       
   511     operatorLinkCenrepKey = new XQSettingsKey(XQSettingsKey::TargetCentralRepository, 
       
   512                                             KGlxCi_UidGallery, KGlxOperatorLink);
       
   513     QVariant value = ciSettingsManager->readItemValue(*operatorLinkCenrepKey);
       
   514     
       
   515     
       
   516     switch(value.toInt()) {
       
   517         case KGlxOvi:
       
   518             {
       
   519                 XQSettingsKey* oviCenrepKey = NULL;
       
   520                 oviCenrepKey = new XQSettingsKey(XQSettingsKey::TargetCentralRepository, 
       
   521                                                         KGlxCi_UidGallery, KGlxOvi);
       
   522                 QVariant Ovivalue = ciSettingsManager->readItemValue(*oviCenrepKey, XQSettingsManager::TypeString);
       
   523                 HbAction* configurableAction = new HbAction(this);
       
   524                 configurableAction->setData(EGlxCmdOviOpen);
       
   525                 mActionList.append(configurableAction);
       
   526             
       
   527                 if ( Ovivalue.isValid() && Ovivalue.canConvert<QString>() ) {
       
   528                     configurableAction->setIcon( HbIcon( Ovivalue.toString() ) );
       
   529                 }
       
   530 
       
   531                 delete oviCenrepKey;
       
   532             }
       
   533             break;
       
   534             
       
   535         default:
       
   536             qDebug("GlxViewManager::Configurable Action is empty " );
       
   537             break;
       
   538     }
       
   539     
       
   540     delete operatorLinkCenrepKey;
       
   541     delete ciSettingsManager;
       
   542 }
       
   543 
       
   544 void GlxViewManager::createMarkingModeActions()
       
   545 {
       
   546     mMarkingActionList.clear();
       
   547     
       
   548     //create the ok tool bar button action
       
   549     HbAction* selectAction = new HbAction(GLX_BUTTON_OK, this);
       
   550     selectAction->setData(EGlxCmdSelect);
       
   551     selectAction->setObjectName( "Select Action" );
       
   552     mMarkingActionList.append(selectAction);
       
   553     connect( selectAction, SIGNAL(triggered( )), this, SLOT(handleAction( )), Qt::QueuedConnection );
       
   554     mMarkingToolBar->addAction( selectAction );
       
   555     
       
   556     //create the cancel tool bar button action
       
   557     HbAction* cancelAction = new HbAction(GLX_BUTTON_CANCEL, this);
       
   558     cancelAction->setData(EGlxCmdCancel);
       
   559     cancelAction->setObjectName( "Cancel Action" );
       
   560     mMarkingActionList.append(cancelAction); 
       
   561     connect( cancelAction, SIGNAL(triggered( )), this, SLOT(handleAction( )), Qt::QueuedConnection ); 
       
   562     mMarkingToolBar->addAction( cancelAction );
       
   563 }
       
   564 
       
   565 
       
   566 void GlxViewManager::createToolBar()
       
   567 {
       
   568     qDebug("GlxViewManager::createToolBar() " );
       
   569     
       
   570     mViewToolBar = new HbToolBar();
       
   571     mViewToolBar->setOrientation( Qt::Horizontal );
       
   572     mViewToolBar->setVisible(true);
       
   573     mViewToolBar->clearActions();
       
   574     
       
   575     createActions();    
       
   576     
       
   577     qDebug("GlxViewManager::createToolBar() clear the action" );
       
   578     int count = mActionList.count();
       
   579     for ( int i = 0; i < count; i++ ) {
       
   580         connect( mActionList.at(i), SIGNAL(triggered( )), this, SLOT(handleAction( )) );
       
   581         mActionList.at(i)->setCheckable( TRUE );
       
   582         mViewToolBar->addAction( mActionList.at(i) );      
       
   583     }
       
   584     qDebug("GlxViewManager::createToolBar() exit" );
       
   585 }
       
   586 
       
   587 void GlxViewManager::createMarkingModeToolBar()
       
   588 {
       
   589     qDebug("GlxViewManager::createMarkingModeToolBar() " );
       
   590     mMarkingToolBar = new HbToolBar();
       
   591     mMarkingToolBar->setOrientation( Qt::Horizontal );
       
   592     mMarkingToolBar->setVisible(true);            
       
   593     mMarkingToolBar->clearActions();    
       
   594     createMarkingModeActions();
       
   595 }
       
   596 
       
   597 void GlxViewManager::addConnection()
       
   598 {    
       
   599     if ( mMenuManager )
       
   600         connect(mMenuManager, SIGNAL( commandTriggered(qint32 ) ), this, SLOT( handleMenuAction(qint32 ) ));
       
   601     if ( mBackAction )
       
   602         connect(mBackAction, SIGNAL( triggered() ), this, SLOT( handleAction() ));
       
   603         
       
   604     if ( mEffectEngine )  {
       
   605         connect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinished() ), Qt::QueuedConnection );
       
   606     }        
       
   607 }
       
   608 
       
   609 void GlxViewManager::removeConnection()
       
   610 {
       
   611     int count = mActionList.count();
       
   612     for ( int i = 0; i < count; i++ ) {
       
   613         disconnect( mActionList.at(i), SIGNAL(triggered( )), this, SLOT(handleAction( )) );  
       
   614     }
       
   615     
       
   616     count = mMarkingActionList.count();
       
   617     for ( int i = 0; i < count; i++ ) {
       
   618         disconnect( mMarkingActionList.at(i), SIGNAL(triggered( )), this, SLOT(handleAction( )) );  
       
   619     }
       
   620     
       
   621     count = mViewList.count();
       
   622     for ( int i = 0; i < count; i++ ) {
       
   623         disconnect ( mViewList.at(i), SIGNAL(actionTriggered(qint32 )), this, SLOT(actionProcess(qint32 )) );
       
   624         disconnect ( mViewList.at(i), SIGNAL(itemSpecificMenuTriggered(qint32, QPointF ) ), this, SLOT( itemSpecificMenuTriggered(qint32, QPointF ) ));
       
   625         mMenuManager->removeMenu( mViewList.at(i)->viewId(), mViewList.at(i)->menu() ) ;
       
   626     }
       
   627 	   
       
   628     if ( mMenuManager )
       
   629         disconnect(mMenuManager, SIGNAL( commandTriggered(qint32 ) ), this, SLOT( handleMenuAction(qint32 ) ));
       
   630     
       
   631     if ( mBackAction )
       
   632         disconnect(mBackAction, SIGNAL( triggered() ), this, SLOT( handleAction() ));
       
   633         
       
   634     if ( mEffectEngine )  {
       
   635         disconnect( mEffectEngine, SIGNAL( effectFinished() ), this, SLOT( effectFinished() ) );
       
   636     }
       
   637 }
       
   638 
       
   639 void GlxViewManager::destroyView(qint32 id)
       
   640 {
       
   641     qDebug("GlxViewManager::destroyView ");
       
   642     GlxView *view = findView ( id );
       
   643     mViewList.removeOne(view);
       
   644     delete view;
       
   645 }
       
   646 
       
   647 void GlxViewManager::actionProcess(qint32 id)
       
   648 {
       
   649     qDebug("GlxViewManager::actionProcess action Id = %d ", id);
       
   650     emit actionTriggered(id);
       
   651 }
       
   652 
       
   653 GlxViewManager::~GlxViewManager()
       
   654 {
       
   655     qDebug("GlxViewManager::~GlxViewManager");
       
   656     HbStyleLoader::unregisterFilePath(":/data/photos.css");
       
   657 	
       
   658     removeConnection();
       
   659 	
       
   660     delete mMenuManager;
       
   661     qDebug("GlxViewManager::~GlxViewManager deleted menu manager");    
       
   662     delete mViewToolBar;
       
   663     delete mMarkingToolBar;
       
   664     qDebug("GlxViewManager::~GlxViewManager deleted toolbar");
       
   665     
       
   666     while( mViewList.isEmpty( ) == FALSE){
       
   667         delete mViewList.takeLast() ;
       
   668     }
       
   669     qDebug("GlxViewManager::~GlxViewManager view deleted");    
       
   670         
       
   671     delete mBackAction;
       
   672     delete mProgressDialog;
       
   673     
       
   674     if ( mEffectEngine ) {
       
   675         mEffectEngine->deregistertransitionEffect();
       
   676         delete mEffectEngine;
       
   677     }
       
   678  
       
   679     if( mMainWindow != GlxExternalUtility::instance()->getMainWindow() ){
       
   680         qDebug("GlxViewManager::~GlxViewManager delete mainwindow");
       
   681         delete mMainWindow;
       
   682     }
       
   683     delete mWindowEventFilter;
       
   684     
       
   685     qDebug("GlxViewManager::~GlxViewManager Exit");
       
   686 }
       
   687 
       
   688 int GlxViewManager::getSubState()
       
   689 {
       
   690     int curSubstate = NO_GRID_S;    
       
   691     
       
   692     if ( mModel  ) {    
       
   693         QVariant variant = mModel->data( mModel->index(0,0), GlxSubStateRole );    
       
   694         if ( variant.isValid() &&  variant.canConvert<int> ()  ) {
       
   695             curSubstate = variant.value<int>();
       
   696         }
       
   697     }
       
   698     return curSubstate;
       
   699 }