phonebookui/Phonebook2/remotecontactlookup/contactactionmenu/src/cfsccontactactionmenuimpl.cpp
changeset 0 e686773b3f54
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementation of the class CFscContactActionMenuImpl.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCUDES
       
    20 #include "emailtrace.h"
       
    21 #include <implementationproxy.h>
       
    22 #include "cfsccontactactionservice.h"
       
    23 #include <eikbtgpc.h>
       
    24 #include <avkon.rsg>
       
    25 #include <avkon.hrh>
       
    26 #include <AknsUtils.h>
       
    27 #include <aknnotewrappers.h> 
       
    28 #include <textresolver.h> 
       
    29 #include <aknstyluspopupmenu.h>
       
    30 
       
    31 #include "cfsccontactactionmenuimpl.h"
       
    32 #include "fsccontactactionmenuuids.hrh"
       
    33 #include "cfsccontactactionmenumodelimpl.h"
       
    34 #include "tfsccontactactionmenuconstructparameters.h"
       
    35 #include "cfsccontactactionmenuitemimpl.h"
       
    36 #include "cfsccontactactionmenucasitemimpl.h"
       
    37 
       
    38 
       
    39 const TImplementationProxy ImplementationTable[] =
       
    40     {
       
    41     IMPLEMENTATION_PROXY_ENTRY( KFscContactActionMenuImplImpUid, 
       
    42                                 CFscContactActionMenuImpl::NewL )
       
    43     };
       
    44       
       
    45     
       
    46 // ======== LOCAL FUNCTIONS ========
       
    47 
       
    48 // ================= MEMBER FUNCTIONS =======================
       
    49 
       
    50 // ======== MEMBER FUNCTIONS ========
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // CFscContactActionMenuImpl::NewL
       
    54 // ---------------------------------------------------------------------------
       
    55 //
       
    56 CFscContactActionMenuImpl* CFscContactActionMenuImpl::NewL(
       
    57     TAny* aParams )
       
    58     {
       
    59     FUNC_LOG;
       
    60 
       
    61     TFscContactActionMenuConstructParameters* params = 
       
    62         reinterpret_cast< TFscContactActionMenuConstructParameters* >( aParams );
       
    63 
       
    64     CFscContactActionMenuImpl* self = 
       
    65         new (ELeave) CFscContactActionMenuImpl( *params );
       
    66     CleanupStack::PushL( self );
       
    67     self->ConstructL( *params );
       
    68     CleanupStack::Pop( self );
       
    69         
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CFscContactActionMenuImpl::~CFscContactActionMenuImpl
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CFscContactActionMenuImpl::~CFscContactActionMenuImpl()
       
    78     {
       
    79     FUNC_LOG;    
       
    80     StopWait();
       
    81     delete iWait;
       
    82     delete iDummyMenuItem;
       
    83     delete iModel;    
       
    84     delete iTextResolver;    
       
    85     CloseStylusPopup();
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // CFscContactActionMenuImpl::ExecuteL
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 TFscActionMenuResult CFscContactActionMenuImpl::ExecuteL( 
       
    93     TFscContactActionMenuPosition /*aPosition*/, TInt /*aIndex*/, MFsActionMenuPositionGiver* aPositionGiver)
       
    94     {
       
    95     FUNC_LOG;
       
    96           
       
    97     // Initialise some member variables
       
    98     iExit = EFalse;
       
    99     iMenuResult = EFscMenuDismissed;
       
   100     iError = KErrNone;
       
   101     
       
   102     // Check if menu is empty
       
   103     if ( iModel->VisibleItemCount() > 0 )
       
   104         {
       
   105         // Execute menu        
       
   106         TRAP( iError, DoExecuteL( aPositionGiver ) );
       
   107         User::LeaveIfError( iError );
       
   108         }
       
   109 
       
   110     return iMenuResult;
       
   111     }
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // CFscContactActionMenuImpl::Dismiss
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void CFscContactActionMenuImpl::Dismiss( TBool aSlide )
       
   118     {
       
   119     FUNC_LOG;
       
   120     iExit = !aSlide;
       
   121     iMenuResult = EFscMenuDismissed;
       
   122     // cancel action execution if running
       
   123     // needs to be canceled to close select popup dialog
       
   124     if ( iIsActionExecuting )
       
   125         {
       
   126         iModel->Service()->CancelExecute();
       
   127         iIsActionExecuting = EFalse;
       
   128         }
       
   129      
       
   130     DoDismiss();
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CFscContactActionMenuImpl::Model
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 MFscContactActionMenuModel& CFscContactActionMenuImpl::Model()
       
   138     {
       
   139     FUNC_LOG;
       
   140     return *iModel; 
       
   141     }
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CFscContactActionMenuImpl::FocusedItemIndex
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 TInt CFscContactActionMenuImpl::FocusedItemIndex()
       
   148     {
       
   149     FUNC_LOG;
       
   150     TInt result = iSelectedItemIndex;
       
   151     return result;
       
   152     }
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CFscContactActionMenuImpl::FocusedItem
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 CFscContactActionMenuItem& CFscContactActionMenuImpl::FocusedItem()
       
   159     {
       
   160     FUNC_LOG;
       
   161     TInt i = FocusedItemIndex();
       
   162     TInt err = KErrNone;
       
   163     
       
   164     CFscContactActionMenuItem* focusedItem = NULL;
       
   165     
       
   166     TRAP( err, focusedItem = &(iModel->ItemL( i )) );
       
   167     if ( err != KErrNone )
       
   168         {
       
   169         CCoeEnv::Static()->HandleError( err );
       
   170         focusedItem = iDummyMenuItem;
       
   171         }
       
   172     
       
   173     return *focusedItem;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CFscContactActionMenuImpl::FadedComponent
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void CFscContactActionMenuImpl::HandleGainingForeground()
       
   181     {
       
   182     FUNC_LOG;
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CFscContactActionMenuImpl::FadedComponent
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 void CFscContactActionMenuImpl::HandleLosingForeground()
       
   190     {
       
   191     FUNC_LOG;
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CFscContactActionMenuImpl::ProcessCommandL
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 void CFscContactActionMenuImpl::ProcessCommandL(TInt aCommandId)
       
   199     {
       
   200     FUNC_LOG;
       
   201     
       
   202     switch ( aCommandId )
       
   203         {
       
   204         case KErrCancel:
       
   205             {
       
   206             
       
   207             iMenuResult = EFscMenuDismissed;
       
   208             iSelectedItemIndex = KErrNotFound;
       
   209             break;
       
   210             }
       
   211             
       
   212         default:
       
   213             {
       
   214             iSelectedItemIndex = aCommandId;
       
   215             HandleItemClick(iSelectedItemIndex);
       
   216             //iMenuResult = EFscCustomItemSelected;
       
   217             break;
       
   218             }
       
   219         }
       
   220     
       
   221     StopWait();
       
   222     }
       
   223     
       
   224 // ---------------------------------------------------------------------------
       
   225 // CFscContactActionMenuImpl::CFscContactActionMenuImpl
       
   226 // ---------------------------------------------------------------------------
       
   227 //
       
   228 CFscContactActionMenuImpl::CFscContactActionMenuImpl( 
       
   229     const TFscContactActionMenuConstructParameters& /*aParams*/ ) 
       
   230     : CFscContactActionMenu(), 
       
   231       iSelectedItemIndex( 0 ), isExecuteCompleted( ETrue )
       
   232     {
       
   233     FUNC_LOG;
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CFscContactActionMenuImpl::ConstructL
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CFscContactActionMenuImpl::ConstructL(
       
   241     const TFscContactActionMenuConstructParameters& aParams )
       
   242     {
       
   243     FUNC_LOG;
       
   244     iWait = new ( ELeave ) CActiveSchedulerWait();
       
   245     iModel = CFscContactActionMenuModelImpl::NewL( aParams.iService );
       
   246     iTextResolver = CTextResolver::NewL( *CCoeEnv::Static() );
       
   247     iDummyMenuItem = CFscContactActionMenuItemImpl::NewL();
       
   248     iDummyMenuItem->SetImplementationUid( KNullUid );   
       
   249     }   
       
   250 
       
   251 
       
   252 void CFscContactActionMenuImpl::DoExecuteL( MFsActionMenuPositionGiver* aPositionGiver )
       
   253     {
       
   254     FUNC_LOG;
       
   255 
       
   256     TPoint positionOfPopup( 0,0 );
       
   257     if ( aPositionGiver )
       
   258         {
       
   259         positionOfPopup = aPositionGiver->ActionMenuPosition();
       
   260         }
       
   261     
       
   262     LaunchStylusPopupMenuL( positionOfPopup );
       
   263     }
       
   264 
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CFscContactActionMenuImpl::DoDismiss
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 void CFscContactActionMenuImpl::DoDismiss()
       
   271     {
       
   272     FUNC_LOG;   
       
   273     
       
   274    
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // From MFscContactActionServiceObserver.
       
   279 // Called when QueryActionsL method is complete.
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CFscContactActionMenuImpl::QueryActionsComplete()
       
   283     {
       
   284     FUNC_LOG;
       
   285     // CAS observer method implementation - not used in this component
       
   286     }
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // From MFscContactActionServiceObserver.
       
   290 // Called when QueryActionsL method failed.
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void CFscContactActionMenuImpl::QueryActionsFailed( TInt /*aError*/ )
       
   294     {
       
   295     FUNC_LOG;
       
   296     // CAS observer method implementation - not used in this component
       
   297     }
       
   298     
       
   299 // ---------------------------------------------------------------------------
       
   300 // From MFscContactActionServiceObserver.
       
   301 // Called when ExecuteL method is complete.
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CFscContactActionMenuImpl::ExecuteComplete()
       
   305     {
       
   306     FUNC_LOG;
       
   307     isExecuteCompleted = ETrue;
       
   308     iIsActionExecuting = EFalse;
       
   309     iMenuResult = EFscCasItemSelectedAndExecuted;
       
   310     DoDismiss();
       
   311     }
       
   312      
       
   313 // ---------------------------------------------------------------------------
       
   314 // From MFscContactActionServiceObserver.
       
   315 // Called when ExecuteL method failed.
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CFscContactActionMenuImpl::ExecuteFailed( TInt aError )
       
   319     {
       
   320     FUNC_LOG;
       
   321     iError = aError;
       
   322     isExecuteCompleted = ETrue;
       
   323     
       
   324     //Fix for: EJKA-7KAEVA
       
   325     if ( KErrCancel != iError )
       
   326         {
       
   327         // Show error note
       
   328         TPtrC buf;
       
   329         buf.Set( iTextResolver->ResolveErrorString( iError ) );
       
   330         if ( buf.Length() > 0 )
       
   331             {
       
   332             CAknWarningNote* note = new CAknWarningNote();
       
   333         
       
   334             if ( note )
       
   335                 {
       
   336                 // If error string was found and note execution is 
       
   337                 // successfull iError will be KErrNone. Otherwise 
       
   338                 // iError will be delivered to the client application
       
   339                 TRAP( iError, note->ExecuteLD( buf ) );
       
   340                 }
       
   341             else
       
   342                 {
       
   343                 iError = KErrNoMemory;
       
   344                 }
       
   345             }
       
   346         }
       
   347     else
       
   348         {
       
   349         iError = KErrNone;
       
   350         iIsActionExecuting = EFalse;
       
   351         iMenuResult = EFscMenuDismissed;
       
   352         }
       
   353     
       
   354     DoDismiss();
       
   355     }
       
   356     
       
   357 
       
   358 // --------------------------------------------------------------------------
       
   359 // CPbk2AppViewBase::DoLaunchStylusPopupL
       
   360 // --------------------------------------------------------------------------
       
   361 //
       
   362 void CFscContactActionMenuImpl::DoLaunchStylusPopupL( const TPoint& aPoint )
       
   363     {
       
   364     iStylusPopup = CAknStylusPopUpMenu::NewL( this, aPoint, NULL );
       
   365     
       
   366     iStylusPopup->SetPosition( aPoint );
       
   367         
       
   368     TInt count = iModel->VisibleItemCount();    
       
   369     for ( TInt index =0; index < count; index++ )
       
   370         {
       
   371         CFscContactActionMenuItem* baseItem = NULL;
       
   372         TRAP_IGNORE( baseItem = &iModel->VisibleItemL( index ) );
       
   373         if ( baseItem )
       
   374             {
       
   375             iStylusPopup->AddMenuItemL( baseItem->MenuText(), index );
       
   376             }
       
   377         }   
       
   378     
       
   379     iStylusPopup->ShowMenu();
       
   380     }
       
   381 
       
   382 
       
   383 // --------------------------------------------------------------------------
       
   384 // CPbk2AppViewBase::CloseStylusPopup
       
   385 // --------------------------------------------------------------------------
       
   386 //
       
   387 void CFscContactActionMenuImpl::CloseStylusPopup()
       
   388     {
       
   389     if ( iStylusPopup )
       
   390         {
       
   391         delete iStylusPopup;
       
   392         iStylusPopup = NULL;
       
   393         }
       
   394     }
       
   395 
       
   396 // --------------------------------------------------------------------------
       
   397 // CPbk2AppViewBase::LaunchStylusPopupMenuL
       
   398 // --------------------------------------------------------------------------
       
   399 //
       
   400 void CFscContactActionMenuImpl::LaunchStylusPopupMenuL( const TPoint& aPoint )
       
   401     {
       
   402     CloseStylusPopup();
       
   403     TRAPD( err, DoLaunchStylusPopupL( aPoint ) );
       
   404     if ( err )
       
   405         {
       
   406         CloseStylusPopup();
       
   407         User::Leave( err );
       
   408         }
       
   409     else
       
   410         {
       
   411         StartWait(); 
       
   412         }
       
   413     }
       
   414 
       
   415 // --------------------------------------------------------------------------
       
   416 // CPbk2AppViewBase::SetEmphasis
       
   417 // --------------------------------------------------------------------------
       
   418 //
       
   419 void CFscContactActionMenuImpl::SetEmphasis(CCoeControl* /*aMenuControl*/,TBool /*aEmphasis*/)
       
   420     {
       
   421     
       
   422     }
       
   423 
       
   424 // ---------------------------------------------------------------------------
       
   425 // CFscContactActionMenuImpl::HandleItemClick
       
   426 // ---------------------------------------------------------------------------
       
   427 //
       
   428 void CFscContactActionMenuImpl::HandleItemClick( TInt selectedItemIndex )
       
   429     {
       
   430     FUNC_LOG;    
       
   431     
       
   432     TInt itemCount = iModel->VisibleItemCount();
       
   433     if ( selectedItemIndex >= 0 && selectedItemIndex < itemCount )
       
   434         {
       
   435         // Check type of selected item
       
   436         CFscContactActionMenuItem* baseItem = NULL;
       
   437         TRAP( iError, baseItem = &iModel->VisibleItemL( selectedItemIndex ) );
       
   438         
       
   439         if ( iError == KErrNone )
       
   440             {
       
   441             // Check type of selected item
       
   442             CFscContactActionMenuCasItemImpl* item =
       
   443                 dynamic_cast<CFscContactActionMenuCasItemImpl*>( baseItem );
       
   444             if ( item != NULL )
       
   445                 {
       
   446                 iMenuResult = EFscCasItemSelectedAndExecuting;
       
   447                 TUid actionUid = item->ImplementationUid();
       
   448                 isExecuteCompleted = EFalse;
       
   449                 iIsActionExecuting = ETrue;
       
   450                 TRAP( iError,
       
   451                     iModel->Service()->ExecuteL( actionUid, this ) );
       
   452                 }
       
   453             else
       
   454                 {
       
   455                 // Custom item is not executed by the menu
       
   456                 iMenuResult = EFscCustomItemSelected;
       
   457                 DoDismiss();
       
   458                 }
       
   459             }
       
   460 
       
   461         if ( iError != KErrNone )
       
   462             {
       
   463             // Show error note
       
   464             TPtrC buf;
       
   465             buf.Set( iTextResolver->ResolveErrorString( iError ) );
       
   466             if ( buf.Length() > 0 )
       
   467                 {
       
   468                 CAknWarningNote* note = new CAknWarningNote();
       
   469                 
       
   470                 if ( note )
       
   471                     {
       
   472                     // If error string was found and note execution is 
       
   473                     // successfull iError will be KErrNone. Otherwise 
       
   474                     // iError will be delivered to the client application
       
   475                     TRAP( iError, note->ExecuteLD( buf ) );
       
   476                     }
       
   477                 else
       
   478                     {
       
   479                     iError = KErrNoMemory;
       
   480                     }
       
   481                 }
       
   482             }
       
   483         }
       
   484     else
       
   485         {
       
   486         iMenuResult = EFscMenuDismissed;
       
   487         }
       
   488         
       
   489     }
       
   490 
       
   491 // ---------------------------------------------------------------------------
       
   492 // CFscContactActionMenuImpl::StartWait
       
   493 // ---------------------------------------------------------------------------
       
   494 //
       
   495 void CFscContactActionMenuImpl::StartWait()
       
   496     {
       
   497     FUNC_LOG;
       
   498     iWait->Start();
       
   499     }
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // CFscContactActionMenuImpl::StopWait
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 void CFscContactActionMenuImpl::StopWait()
       
   506     {
       
   507     FUNC_LOG;
       
   508     if ( iWait->IsStarted() )
       
   509         {
       
   510         iWait->AsyncStop();
       
   511         }
       
   512     }
       
   513     
       
   514 // ======== GLOBAL FUNCTIONS ========
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // ImplementationGroupProxy
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( 
       
   521     TInt& aTableCount )
       
   522     {
       
   523     aTableCount = sizeof( ImplementationTable ) / 
       
   524         sizeof( TImplementationProxy );
       
   525     return ImplementationTable;
       
   526     }
       
   527