phonebookui/Phonebook/App/src/CPbkContactInfoAppView.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 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 *       Provides Contact Info App View class methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkContactInfoAppView.h"  // This class' declaration
       
    22 
       
    23 #include <eikmenub.h> // CEikMenuBar
       
    24 #include <AknNoteWrappers.h>
       
    25 #include <FeatMgr.h>
       
    26 #include <StringLoader.h>
       
    27 #include <PbkUID.h>
       
    28 
       
    29 // Phonebook.app include files
       
    30 #include <Phonebook.rsg>
       
    31 #include <PbkView.rsg>
       
    32 
       
    33 // Phone include files
       
    34 #include <SpdiaControl.h>
       
    35 
       
    36 // Send UI
       
    37 #include <sendui.h>
       
    38 #include <sendnorm.rsg>
       
    39 #include <SendUiConsts.h>
       
    40 #include <CMessageData.h>
       
    41 
       
    42 // AIW
       
    43 #include <AiwCommon.hrh>
       
    44 
       
    45 // Clipboard
       
    46 #include <baclipb.h>
       
    47 
       
    48 // PbkEng.dll include files
       
    49 #include <CPbkContactEngine.h>
       
    50 #include <CPbkFieldInfo.h>
       
    51 #include <CPbkContactItem.h>
       
    52 #include <PbkCommandHandler.h>
       
    53 #include <CPbkFieldsInfo.h>
       
    54 #include <PbkFields.hrh>
       
    55 
       
    56 // PbkUi.dll include files
       
    57 #include <MPbkCommand.h>
       
    58 #include <MPbkCommandFactory.h>
       
    59 #include <CPbkAiwInterestArray.h>
       
    60 #include <MenuFilteringFlags.h>
       
    61 
       
    62 // PbkView.dll classes
       
    63 #include <CPbkContactInfoControl.h>
       
    64 #include <CPbkMemoryEntryDefaultsDlg.h>
       
    65 #include <CPbkViewState.h>
       
    66 #include <CPbkPhoneNumberSelect.h>
       
    67 #include <CPbkContactEditorDlg.h>
       
    68 #include <CPbkRingingToneFetch.h>
       
    69 #include <CPbkPrependDlg.h>
       
    70 #include <CPbkFFSCheck.h>
       
    71 
       
    72 // PbkExtension classes
       
    73 #include <CPbkExtGlobals.h>
       
    74 #include <MPbkExtensionFactory.h>
       
    75 #include <MPbkViewExtension.h>
       
    76 #include <cshelp/phob.hlp.hrh>
       
    77 
       
    78 // Postcard Uid
       
    79 #include <SendUiConsts.h>
       
    80 
       
    81 // Phonebook.app include files
       
    82 #include <CPbkControlContainer.h>
       
    83 #include "CPbkAppUi.h"
       
    84 #include "CPbkAppGlobals.h"
       
    85 #include "CPbkDocument.h"
       
    86 #include "MPbkContactInfoNavigationStrategy.h"
       
    87 #include "PbkContactInfoNavigationStrategyFactory.h"
       
    88 #include <pbkconfig.hrh>
       
    89 #include "CPbkCodImageCmd.h"
       
    90 
       
    91 // Debugging headers
       
    92 #include <pbkdebug.h>
       
    93 #include "PbkProfiling.h"
       
    94 
       
    95 /// Unnamed namespace for local definitions
       
    96 namespace {
       
    97 
       
    98 // LOCAL CONSTANTS AND MACROS
       
    99 
       
   100 #ifdef _DEBUG
       
   101 enum TPanicCode
       
   102     {
       
   103     EPanicPostCond_DoActivateL = 1,
       
   104     EPanicPostCond_DoDeactivate,
       
   105     EPanicPreCond_HandleCommandL,
       
   106     EPanicPreCond_ConstructL,
       
   107     EPanicPostCond_ConstructL,
       
   108     EPanicPreCond_CmdSpeedDialL,
       
   109     EPanicPreCond_CmdWriteToContactL,
       
   110     EPanicPreCond_CmdEditMeL,
       
   111     EPanicPostCond_CmdEditMeL,
       
   112     EPanicPreCond_CmdRemoveSpeedDialL, // 10
       
   113     EPanicPreCond_DynInitMenuPaneL,
       
   114     EPanicIcon_StatusPaneUpdateL,
       
   115     EPanicPreCond_HandleCommandKeyL,
       
   116     EPanicPreCond_CmdRemoveCodL,
       
   117     EPanicPreCond_CmdAddCodFieldL,
       
   118     EPanicFieldInfoNotFound_CmdAddCodFieldL,
       
   119     EPanicImageStorageNotFound_CmdAddCodFieldL,
       
   120     EPanicPreCond_CmdEditTextCodFieldL,
       
   121     EPanicFieldInfoNotFound_HandleCodTextChangeL,
       
   122     EPanicTextStorageNotFound_HandleCodTextChangeL
       
   123     };
       
   124 #endif // _DEBUG
       
   125 
       
   126 
       
   127 // ==================== LOCAL FUNCTIONS ====================
       
   128 
       
   129 #ifdef _DEBUG
       
   130 void Panic(TPanicCode aReason)
       
   131     {
       
   132     _LIT(KPanicText, "CPbkContactInfoAppView");
       
   133     User::Panic(KPanicText, aReason);
       
   134     }
       
   135 #endif // _DEBUG
       
   136 
       
   137 }  // namespace
       
   138 
       
   139 
       
   140 // ================= MEMBER FUNCTIONS =======================
       
   141 
       
   142 inline CPbkContactInfoAppView::CPbkContactInfoAppView()
       
   143     {
       
   144     }
       
   145 
       
   146 inline void CPbkContactInfoAppView::ConstructL()
       
   147     {
       
   148     // PreCond
       
   149      __ASSERT_DEBUG(!iContainer && !iViewState,
       
   150         Panic(EPanicPreCond_ConstructL));
       
   151 
       
   152     // Init base class
       
   153     __PBK_PROFILE_START(PbkProfiling::EViewBaseConstruct);
       
   154     BaseConstructL(R_PBK_CONTACTINFO_APPVIEW);
       
   155     __PBK_PROFILE_END(PbkProfiling::EViewBaseConstruct);
       
   156 
       
   157     iExtGlobal = CPbkExtGlobals::InstanceL();
       
   158 
       
   159     // Create AIW interest array for call
       
   160     CreateInterestItemAndAttachL(KAiwCmdCall,
       
   161         R_PHONEBOOK_CALL_MENU, R_PHONEBOOK_CALLUI_AIW_INTEREST, ETrue);
       
   162     // The last parameter is false, since KAiwCmdCall is already attached
       
   163     // to base services above
       
   164     CreateInterestItemAndAttachL(KAiwCmdCall,
       
   165         R_PHONEBOOK_CALL_CONTEXT_MENU, R_PHONEBOOK_CALLUI_AIW_INTEREST, EFalse);
       
   166 
       
   167     // Create AIW interest array for PoC
       
   168     CreateInterestItemAndAttachL(KAiwCmdPoC,
       
   169         R_PHONEBOOK_POC_MENU, R_PHONEBOOK_POCUI_AIW_INTEREST, ETrue);
       
   170     // The last parameter is false, since KAiwCmdPoC is already attached
       
   171     // to base services above
       
   172     CreateInterestItemAndAttachL(KAiwCmdPoC,
       
   173         R_PHONEBOOK_POC_CONTEXT_MENU, R_PHONEBOOK_POCUI_AIW_INTEREST, EFalse);
       
   174 
       
   175     // FFS checker
       
   176     iPbkFFSCheck = CPbkFFSCheck::NewL();
       
   177 
       
   178     // PostCond
       
   179      __ASSERT_DEBUG(!iContainer && !iContactItem && !iViewState,
       
   180         Panic(EPanicPostCond_ConstructL));
       
   181     }
       
   182 
       
   183 CPbkContactInfoAppView* CPbkContactInfoAppView::NewL()
       
   184     {
       
   185     CPbkContactInfoAppView* self = new(ELeave) CPbkContactInfoAppView();
       
   186     CleanupStack::PushL(self);
       
   187     self->ConstructL();
       
   188     CleanupStack::Pop();  // self
       
   189     return self;
       
   190     }
       
   191 
       
   192 CPbkContactInfoAppView::~CPbkContactInfoAppView()
       
   193     {
       
   194     if (iContainer)
       
   195         {
       
   196         // Remove the container from the view stack
       
   197         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   198         // Destroy the control container
       
   199         delete iContainer;
       
   200         }
       
   201     delete iUpdateContact;
       
   202     delete iContactItem;
       
   203     delete iViewState;
       
   204     delete iNaviStrategy;
       
   205     Release(iViewExtension);
       
   206     Release(iExtGlobal);
       
   207     delete iPbkCodImageCmd;
       
   208     delete iPbkFFSCheck;
       
   209     }
       
   210 
       
   211 /**
       
   212  * Command handler: Opens the context sensive menu.
       
   213  */
       
   214 void CPbkContactInfoAppView::CmdContextMenuL()
       
   215     {
       
   216     LaunchPopupMenuL(R_PBK_CONTACTINFO_CONTEXTBAR);
       
   217     }
       
   218 
       
   219 /**
       
   220  * Command handler: Edit contact.
       
   221  */
       
   222 void CPbkContactInfoAppView::CmdEditMeL()
       
   223     {
       
   224     __ASSERT_DEBUG(
       
   225         iContainer && iContainer->Control() && iContactItem,
       
   226         Panic(EPanicPreCond_CmdEditMeL));
       
   227     CPbkContactInfoControl* control = iContainer->Control();
       
   228 
       
   229     // Find focused field's index in contact item
       
   230     const TPbkContactItemField* field = control->CurrentField();
       
   231     const TInt fieldIndex = field ?
       
   232         iContactItem->FindFieldIndex(*field) : KErrNotFound;
       
   233 
       
   234     // Store the view state
       
   235     delete iViewState;
       
   236     iViewState = NULL;
       
   237     iViewState = iContainer->Control()->GetStateL();
       
   238 
       
   239     // Open contact for editing
       
   240     CPbkContactItem* ci = Engine()->OpenContactLCX(iContactItem->Id());
       
   241 
       
   242     // Run the editor dialog
       
   243     CPbkContactEditorDlg* editorDlg = CPbkContactEditorDlg::NewL
       
   244         (*Engine(), *ci, EFalse, fieldIndex);
       
   245     editorDlg->SetExitCommandId(EPbkCmdExit);
       
   246 
       
   247     control->HideThumbnail();
       
   248     iSavedId = KNullContactId;
       
   249     iContainer->SetFocusing( EFalse );
       
   250     iContainer->CoeControl()->SetFocusing( EFalse );
       
   251     TRAPD( err, iSavedId = editorDlg->ExecuteLD() );
       
   252     iContainer->SetFocusing( ETrue );
       
   253     iContainer->CoeControl()->SetFocusing( ETrue );
       
   254     control->ShowThumbnailL();
       
   255     User::LeaveIfError( err );
       
   256 
       
   257     CleanupStack::PopAndDestroy(2);  // lock, ci
       
   258 
       
   259     // delay update so that if desctruction of phonebook
       
   260     // has caused stopping of editor execution, no update is done
       
   261     // if this is deleted.
       
   262     delete iUpdateContact;
       
   263     iUpdateContact = NULL;
       
   264     iUpdateContact = CIdle::NewL(CActive::EPriorityIdle);
       
   265 
       
   266     TCallBack callBack( UpdateContact,this );
       
   267     iUpdateContact->Start( callBack );
       
   268     }
       
   269 
       
   270 TInt CPbkContactInfoAppView::UpdateContact(TAny* aPbkContactInfoAppView)
       
   271     {
       
   272     return static_cast<CPbkContactInfoAppView*>(aPbkContactInfoAppView)->DoUpdateContact();
       
   273     }
       
   274 
       
   275 TInt CPbkContactInfoAppView::DoUpdateContact()
       
   276     {
       
   277     CPbkContactInfoControl* control = NULL;
       
   278     if( iContainer )
       
   279         {
       
   280         control = iContainer->Control();
       
   281         }
       
   282 
       
   283     if ( !iExitInProgress && control )
       
   284         {
       
   285         CPbkContactInfoControl* control = iContainer->Control();
       
   286         if (iSavedId != KNullContactId)
       
   287             {
       
   288             // Reload contact and update UI control. Do this manually here instead
       
   289             // of in HandleDatabaseEventL() because editor dialog restores previous
       
   290             // text into title pane which would be wrong in this case.
       
   291             CPbkContactItem* ci = NULL;
       
   292             TRAPD( err, ci = Engine()->ReadContactL(iSavedId) );
       
   293             if ( err == KErrNone )
       
   294                 {
       
   295                 TRAP( err, control->UpdateL(ci));
       
   296                 if ( err == KErrNone )
       
   297                     {
       
   298                     delete iContactItem;
       
   299                     iContactItem = ci;
       
   300                     if ( iViewState )
       
   301                         {
       
   302                         // Restore UI control state, no harm done
       
   303                         // if this fails, focus just changes
       
   304                         TRAP_IGNORE( iContainer->Control()->RestoreStateL(iViewState) );
       
   305                         // Delete the view state object to save memory
       
   306                         delete iViewState;
       
   307                         iViewState = NULL;
       
   308                         }
       
   309                     control->DrawNow();
       
   310                     }
       
   311                 else
       
   312                     {
       
   313                     delete ci;
       
   314                     }
       
   315                 }
       
   316             if ( err != KErrNone )
       
   317                 {
       
   318                 iContainer->ControlEnv()->HandleError( err );
       
   319                 }
       
   320             }
       
   321         else
       
   322             {
       
   323             // It is just thumbnail, we can manage if that fails to show
       
   324             TRAP_IGNORE( control->ShowThumbnailL() );
       
   325             }
       
   326 
       
   327         __ASSERT_DEBUG(
       
   328             iContainer && iContainer->Control() && iContactItem,
       
   329             Panic(EPanicPostCond_CmdEditMeL));
       
   330         }
       
   331     // Stop idle callback
       
   332     return KErrNone;
       
   333     }
       
   334 
       
   335 /**
       
   336  * Command handler: Default settings.
       
   337  */
       
   338 void CPbkContactInfoAppView::CmdDefaultSettingsL()
       
   339     {
       
   340     CPbkContactInfoControl* control = iContainer->Control();
       
   341     control->HideThumbnail();
       
   342     CPbkMemoryEntryDefaultsDlg* memoryEntryDefaultsDlg =
       
   343         CPbkMemoryEntryDefaultsDlg::NewL(iContactItem->Id(), *Engine());
       
   344     memoryEntryDefaultsDlg->ExecuteLD();
       
   345     control->ShowThumbnailL();
       
   346     }
       
   347 
       
   348 /**
       
   349  * Command handler: Assign a speed dial to a phone number.
       
   350  */
       
   351 void CPbkContactInfoAppView::CmdAssignSpeedDialL()
       
   352     {
       
   353     //PreCond:
       
   354     __ASSERT_DEBUG(iContainer->Control()->FieldCount() > 0,
       
   355         Panic(EPanicPreCond_CmdSpeedDialL));
       
   356 
       
   357     TInt fieldId = iContainer->Control()->CurrentFieldIndex();
       
   358 
       
   359     CSpdiaControl* speedDialDlg = CSpdiaControl::NewL();
       
   360     if (speedDialDlg->ExecuteLD(iContactItem->Id(), fieldId) && !iExitInProgress)
       
   361         {
       
   362         // this can removed when CContactDatabase::SetSpeedDialField sends notifications
       
   363         CPbkContactItem* ci = Engine()->ReadContactLC(iContactItem->Id());
       
   364         // Update the UI control
       
   365         TInt focus = iContainer->Control()->ListBox().CurrentItemIndex();
       
   366         iContainer->Control()->UpdateL(ci);
       
   367         if (focus > 0 && focus < iContainer->Control()->FieldCount())
       
   368             {
       
   369             iContainer->Control()->ListBox().SetCurrentItemIndex(focus);
       
   370             }
       
   371         // Update member
       
   372         delete iContactItem;
       
   373         CleanupStack::Pop(ci);
       
   374         iContactItem = ci;
       
   375         iContainer->Control()->DrawNow();
       
   376         }
       
   377     }
       
   378 
       
   379 /**
       
   380  * Command handler: Removes a speed dial from a phone number.
       
   381  */
       
   382 void CPbkContactInfoAppView::CmdRemoveSpeedDialL()
       
   383     {
       
   384     //PreCond:
       
   385     __ASSERT_DEBUG(iContainer->Control()->FieldCount() > 0,
       
   386         Panic(EPanicPreCond_CmdRemoveSpeedDialL));
       
   387 
       
   388     CSpdiaControl* speedDialDlg = CSpdiaControl::NewL();
       
   389     CleanupStack::PushL( speedDialDlg );
       
   390 
       
   391     CArrayFix<TInt>* speedDialIndexes =
       
   392         iContainer->Control()->CurrentField()->SpeedDialIndexesL();
       
   393     if (speedDialIndexes)
       
   394         {
       
   395         CleanupStack::PushL(speedDialIndexes);
       
   396         for (TInt i = 0; i < speedDialIndexes->Count(); ++i)
       
   397             {
       
   398             speedDialDlg->RemoveDialIndexL(
       
   399                     speedDialDlg->Index( (*speedDialIndexes)[i] ) );
       
   400             }
       
   401         CleanupStack::PopAndDestroy(speedDialIndexes);
       
   402         }
       
   403 
       
   404     CleanupStack::PopAndDestroy( speedDialDlg );
       
   405 
       
   406     // This can removed when CContactDatabase::RemoveSpeedDialFieldL sends notifications
       
   407     CPbkContactItem* ci = Engine()->ReadContactLC(iContactItem->Id());
       
   408     // Update the UI control
       
   409     TInt focus = iContainer->Control()->ListBox().CurrentItemIndex();
       
   410     iContainer->Control()->UpdateL(ci);
       
   411     if (focus > 0 && focus < iContainer->Control()->FieldCount())
       
   412         {
       
   413         iContainer->Control()->ListBox().SetCurrentItemIndex(focus);
       
   414         }
       
   415     // Update member
       
   416     delete iContactItem;
       
   417     CleanupStack::Pop(ci);
       
   418     iContactItem = ci;
       
   419     iContainer->Control()->DrawNow();
       
   420     }
       
   421 
       
   422 /**
       
   423  * Command handler: Personal Ringing tone setting
       
   424  */
       
   425 void CPbkContactInfoAppView::CmdPersonalRingingToneL()
       
   426     {
       
   427     CPbkRingingToneFetch* toneFetch = CPbkRingingToneFetch::NewL(*Engine());
       
   428     CleanupStack::PushL(toneFetch);
       
   429     TFileName ringingToneFile;
       
   430     TPbkContactItemField* field =
       
   431         iContactItem->FindField(EPbkFieldIdPersonalRingingToneIndication);
       
   432     if (field)
       
   433         {
       
   434         ringingToneFile.Copy(field->Text().Left(ringingToneFile.MaxLength()));
       
   435         }
       
   436     if (toneFetch->FetchRingingToneL(ringingToneFile))
       
   437         {
       
   438         CPbkContactItem* item = Engine()->OpenContactLCX(iContactItem->Id());
       
   439         toneFetch->SetRingingToneL(*item, ringingToneFile);
       
   440 
       
   441         // Check disk space before assigning.
       
   442         // If not enough memory then leaves with KErrDiskFull.
       
   443         iPbkFFSCheck->FFSClCheckL();
       
   444 
       
   445         Engine()->CommitContactL(*item);
       
   446         CleanupStack::PopAndDestroy(2); // lock, item
       
   447         }
       
   448     CleanupStack::PopAndDestroy(); // toneFetch
       
   449     }
       
   450 
       
   451 
       
   452 void CPbkContactInfoAppView::CmdSendContactL(TPbkSendingParams aParams)
       
   453     {
       
   454     TPbkContactItemField* field = iContainer->Control()->CurrentField();
       
   455 
       
   456     // Create the send contact command object
       
   457     MPbkCommand* cmd = CPbkAppGlobalsBase::InstanceL()->
       
   458         CommandFactory().CreateSendContactCmdL(aParams,*Engine(),
       
   459         CPbkAppGlobals::InstanceL()->BCardEngL(*Engine()),
       
   460         iContactItem->Id(), field);
       
   461     // Execute the command
       
   462     cmd->ExecuteLD();
       
   463     }
       
   464 
       
   465 /**
       
   466  * Command handler: write message to contact
       
   467  */
       
   468 void CPbkContactInfoAppView::CmdWriteToContactL(TPbkSendingParams aParams)
       
   469     {
       
   470     __ASSERT_DEBUG(
       
   471         iContainer && iContainer->Control() && iContactItem,
       
   472         Panic(EPanicPreCond_CmdWriteToContactL));
       
   473 
       
   474     TPbkContactItemField* currentField = iContainer->Control()->CurrentField();
       
   475 
       
   476     // Create the write message command object
       
   477     MPbkCommand* cmd = CPbkAppGlobalsBase::InstanceL()->
       
   478         CommandFactory().CreateSendMultipleMessageCmdL(
       
   479         *Engine(),
       
   480         aParams,
       
   481         iContainer->Control()->MarkedItemsL(),
       
   482         currentField,
       
   483         EFalse);
       
   484     // Execute the command
       
   485     cmd->ExecuteLD();
       
   486     }
       
   487 
       
   488 
       
   489 /**
       
   490  * Command handler: go to URL command.
       
   491  */
       
   492 void CPbkContactInfoAppView::CmdGoToURLL()
       
   493     {
       
   494     // Create the go to URL command object
       
   495     MPbkCommand* cmd = CPbkAppGlobalsBase::InstanceL()->
       
   496         CommandFactory().CreateGoToURLCmdL(*iContactItem, NULL);
       
   497     // Execute the command
       
   498     cmd->ExecuteLD();
       
   499     }
       
   500 
       
   501 /**
       
   502  * Command handler: prepend.
       
   503  */
       
   504 void CPbkContactInfoAppView::CmdPrependL()
       
   505     {
       
   506     // Get the Phone number
       
   507     RBuf number;
       
   508     number.CreateL( iContainer->Control()->CurrentField()->FieldInfo().MaxLength() );
       
   509     number.CleanupClosePushL();
       
   510     iContainer->Control()->CurrentField()->GetTextL(number);
       
   511 
       
   512     // Convert digits to foreign characters if necessary
       
   513     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(number);
       
   514 
       
   515     CPbkPrependDlg* dlg = CPbkPrependDlg::NewL(number);
       
   516     if (dlg->ExecuteLD(R_PBK_PREPEND_QUERY))
       
   517         {
       
   518         // convert digits back from foreign characters to western digits if necessary
       
   519         AknTextUtils::ConvertDigitsTo(number, EDigitTypeWestern);
       
   520 
       
   521         // Create a temporary contact
       
   522         CPbkContactItem* tempContact = Engine()->CreateEmptyContactL();
       
   523         CleanupStack::PushL(tempContact);
       
   524 
       
   525         // Add the prepended number to it
       
   526         TPbkContactItemField* phoneNumberField =
       
   527             tempContact->AddOrReturnUnusedFieldL(
       
   528                 *Engine()->FieldsInfo().Find(
       
   529                 iContainer->Control()->CurrentField()->FieldInfo().FieldId()));
       
   530 
       
   531         if (phoneNumberField)
       
   532             {
       
   533             phoneNumberField->TextStorage()->SetTextL(number);
       
   534             }
       
   535 
       
   536         // Create an array out of the temp contact
       
   537         CContactIdArray* array = CContactIdArray::NewL();
       
   538         CleanupStack::PushL(array);
       
   539         array->AddL(tempContact->Id());
       
   540 
       
   541         // Now place a call to the temp contact
       
   542         iAiwInterestArray->HandleCommandL(
       
   543                 EPbkCmdCall,
       
   544                 *array,
       
   545                 phoneNumberField,    // "focused field" in this case
       
   546                 KAiwCmdCall);
       
   547 
       
   548         CleanupStack::PopAndDestroy(2); // array, tempContact
       
   549         }
       
   550     CleanupStack::PopAndDestroy(); //number
       
   551     }
       
   552 
       
   553 /**
       
   554  * Command handler: copy number.
       
   555  */
       
   556 void CPbkContactInfoAppView::CmdCopyNumberL()
       
   557     {
       
   558     const TInt KBeginning = 0;
       
   559     // Construct a plain text from the number
       
   560     RBuf number;
       
   561     number.CreateL( iContainer->Control()->CurrentField()->FieldInfo().MaxLength() );
       
   562     number.CleanupClosePushL();
       
   563     iContainer->Control()->CurrentField()->GetTextL(number);
       
   564     CPlainText* plainText = CPlainText::NewL();
       
   565     CleanupStack::PushL(plainText);
       
   566     plainText->InsertL(KBeginning, number);
       
   567 
       
   568     // Copy to clipboard
       
   569     CClipboard* cb = CClipboard::NewForWritingLC(Engine()->FsSession());
       
   570     plainText->CopyToStoreL(cb->Store(), cb->StreamDictionary(),
       
   571         KBeginning, plainText->DocumentLength());
       
   572     cb->CommitL();
       
   573 
       
   574     CleanupStack::PopAndDestroy(2); // cb, plainText
       
   575 
       
   576     // Show a note
       
   577     HBufC* prompt = StringLoader::LoadLC(R_QTN_LOGS_NOTE_COPY_DONE);
       
   578     CAknInformationNote* dlg = new(ELeave) CAknInformationNote(ETrue);
       
   579     dlg->ExecuteLD(*prompt);
       
   580     CleanupStack::PopAndDestroy(); // prompt
       
   581     CleanupStack::PopAndDestroy(); //number
       
   582     }
       
   583 
       
   584 void CPbkContactInfoAppView::ContactChangedL()
       
   585     {
       
   586     // if end key has been pressed, do not update the contact
       
   587     // infromation in info control.
       
   588     if (!iExitInProgress)
       
   589         {
       
   590         ChangeContactL(iContactItem->Id());
       
   591         }
       
   592     }
       
   593 
       
   594 CPbkContactItem* CPbkContactInfoAppView::ContactItemL()
       
   595     {
       
   596     return iContactItem;
       
   597     }
       
   598 
       
   599 TContactItemId CPbkContactInfoAppView::ContactItemId()
       
   600     {
       
   601     return iContactItem->Id();
       
   602     }
       
   603 
       
   604 TBool CPbkContactInfoAppView::HandleCommandKeyL
       
   605         (const TKeyEvent& aKeyEvent,
       
   606         TEventCode aType)
       
   607     {
       
   608     __ASSERT_DEBUG(iContainer && iContactItem && iNaviStrategy,
       
   609                    Panic(EPanicPreCond_HandleCommandKeyL));
       
   610 
       
   611     // Pass the key to the strategy
       
   612     TBool ret = iNaviStrategy->HandleCommandKeyL(aKeyEvent, aType);
       
   613     if (!ret)
       
   614         {
       
   615         // Check was it send key press
       
   616         if (aKeyEvent.iCode == EKeyPhoneSend)
       
   617             {
       
   618             HandleCommandL(EPbkCmdCall);
       
   619             ret = ETrue;
       
   620             }
       
   621         else if (aKeyEvent.iCode == EKeyPoC)
       
   622             {
       
   623             HandleCommandL(EPbkCmdPoc);
       
   624             ret = ETrue;
       
   625             }
       
   626         else
       
   627             {
       
   628             // Pass the key event to base class
       
   629             ret = CPbkMemoryEntryAppView::HandleCommandKeyL(aKeyEvent, aType);
       
   630             }
       
   631         }
       
   632     return ret;
       
   633     }
       
   634 
       
   635 CPbkViewState* CPbkContactInfoAppView::GetViewStateLC() const
       
   636     {
       
   637     return iContainer ? iContainer->Control()->GetStateLC() : NULL;
       
   638     }
       
   639 
       
   640 void CPbkContactInfoAppView::HandleCommandL
       
   641         (TInt aCommandId)
       
   642     {
       
   643     // PreCond: (this is the precond for all Cmd* functions at the same time)
       
   644     __ASSERT_DEBUG(iContainer && iContactItem && iViewExtension,
       
   645                    Panic(EPanicPreCond_HandleCommandL));
       
   646 
       
   647     TInt serviceCmdId = KNullHandle;
       
   648     if (aCommandId == EPbkCmdCall)
       
   649         {
       
   650         serviceCmdId = KAiwCmdCall;
       
   651         }
       
   652     else if (aCommandId == EPbkCmdPoc)
       
   653         {
       
   654         serviceCmdId = KAiwCmdPoC;
       
   655         }
       
   656 
       
   657     // Offer the command first to AIW
       
   658     if (iAiwInterestArray->HandleCommandL(
       
   659             aCommandId,
       
   660             iContainer->Control()->MarkedItemsL(),
       
   661             iContainer->Control()->FocusedField(),
       
   662             serviceCmdId))
       
   663         {
       
   664         return;
       
   665         }
       
   666 
       
   667 
       
   668     // And then to the extension
       
   669     if (iViewExtension->HandleCommandL(aCommandId))
       
   670         {
       
   671         return;
       
   672         }
       
   673 
       
   674     // Process view-specific commands
       
   675     switch (aCommandId)
       
   676         {
       
   677         case EPbkCmdContextMenu:
       
   678             {
       
   679             CmdContextMenuL();
       
   680             break;
       
   681             }
       
   682 
       
   683         case EPbkCmdEditMe:
       
   684             {
       
   685             PbkAppUi()->FFSClCheckL(PbkCommandHandler(this,
       
   686                 &CPbkContactInfoAppView::CmdEditMeL));
       
   687             UpdateUrlFieldInfo();
       
   688             break;
       
   689             }
       
   690 
       
   691         case EPbkCmdDefaultSettings:
       
   692             {
       
   693             PbkAppUi()->FFSClCheckL(PbkCommandHandler(this,
       
   694                 &CPbkContactInfoAppView::CmdDefaultSettingsL));
       
   695             break;
       
   696             }
       
   697 
       
   698         case EPbkCmdAssignSpeedDial:
       
   699             {
       
   700             PbkAppUi()->FFSClCheckL(PbkCommandHandler(this,
       
   701                 &CPbkContactInfoAppView::CmdAssignSpeedDialL));
       
   702             break;
       
   703             }
       
   704 
       
   705         case EPbkCmdRemoveSpeedDial:
       
   706             {
       
   707             CmdRemoveSpeedDialL();
       
   708             break;
       
   709             }
       
   710 
       
   711         case EPbkCmdPersonalRingingTone:
       
   712             {
       
   713             PbkAppUi()->FFSClCheckL(PbkCommandHandler(this,
       
   714                 &CPbkContactInfoAppView::CmdPersonalRingingToneL));
       
   715             break;
       
   716             }
       
   717 
       
   718         case EPbkCmdGoToURL:
       
   719             {
       
   720             CmdGoToURLL();
       
   721             break;
       
   722             }
       
   723 
       
   724         case EPbkCmdPrepend:
       
   725             {
       
   726             CmdPrependL();
       
   727             break;
       
   728             }
       
   729 
       
   730         case EPbkCmdCopyNumber:
       
   731             {
       
   732             CmdCopyNumberL();
       
   733             break;
       
   734             }
       
   735         case EPbkCmdWrite:
       
   736             {
       
   737             TPbkSendingParams params = CreateWriteParamsLC();
       
   738             PbkAppUi()->FFSClCheckL(PbkCommandHandler(this,
       
   739                 &CPbkContactInfoAppView::CmdWriteToContactL,
       
   740                 params));
       
   741             CleanupStack::PopAndDestroy(); //mtmFilter
       
   742             break;
       
   743             }
       
   744         case EPbkCmdSendUICommand:
       
   745             {
       
   746             TPbkSendingParams params = CreateSendParamsLC();
       
   747             CmdSendContactL(params);
       
   748             CleanupStack::PopAndDestroy(); //mtmFilter
       
   749             break;
       
   750             }
       
   751         case EPbkCmdCodRemoveObject:
       
   752             {
       
   753             // Only one Cod field exists at a time.
       
   754             // By callig both functions the existing field
       
   755             // will be deleted
       
   756             CmdRemoveCodL( EPbkFieldIdCodTextID );
       
   757             CmdRemoveCodL( EPbkFieldIdCodImageID );
       
   758             break;
       
   759             }
       
   760         // Following methods need critical level check of memory
       
   761         case EPbkCmdCodAddObjectText:
       
   762         case EPbkCmdCodAddObjectImage:
       
   763             {
       
   764             CmdAddCodFieldL( aCommandId );
       
   765             break;
       
   766             }
       
   767         case EPbkCmdCodEditText:
       
   768             {
       
   769             CmdEditTextCodFieldL();
       
   770             break;
       
   771             }
       
   772         case EPbkCmdCodViewImage:
       
   773             {
       
   774             CmdViewCodImageL();
       
   775             break;
       
   776             }
       
   777         case EPbkCmdCodChangeImage:
       
   778             {
       
   779             CmdAddCodFieldL(EPbkCmdCodAddObjectImage);
       
   780             break;
       
   781             }
       
   782         case EPbkCmdCodAddObjectSubMenu:
       
   783             {
       
   784             break;
       
   785             }
       
   786         case EPbkCmdExit:
       
   787             {
       
   788             // Turn up the iExitInProgress flag to avoid unwanted
       
   789             // contact redraw in exit case. This happens if the editor
       
   790             // dialog is running while exit should be executed.
       
   791             iExitInProgress = ETrue;
       
   792             // fall through to default handler.
       
   793             }
       
   794         default:
       
   795             {
       
   796             CPbkMemoryEntryAppView::HandleCommandL(aCommandId);
       
   797             break;
       
   798             }
       
   799         }
       
   800     }
       
   801 
       
   802 void CPbkContactInfoAppView::DynInitMenuPaneL
       
   803         (TInt aResourceId,
       
   804         CEikMenuPane* aMenuPane)
       
   805     {
       
   806     __ASSERT_DEBUG(iContainer && iViewExtension,
       
   807         Panic(EPanicPreCond_DynInitMenuPaneL));
       
   808 
       
   809     TUint flags = KPbkInfoView;
       
   810     if (iContainer->Control()->FieldCount() == 0)
       
   811         {
       
   812         flags |= KPbkControlEmpty;
       
   813         }
       
   814 
       
   815     TPbkContactItemField* currentField =
       
   816         iContainer->Control()->CurrentField();
       
   817 
       
   818     if (currentField && currentField->FieldInfo().IsPhoneNumberField())
       
   819         {
       
   820         flags |= KPbkCurrentFieldPhoneNumber;
       
   821         }
       
   822 
       
   823     if (currentField && currentField->FieldInfo().IsVoipField())
       
   824         {
       
   825         flags |= KPbkCurrentFieldVoipAddress;
       
   826         }
       
   827 
       
   828     // The flag KPbkCurrentFieldPoc is valid for using only
       
   829     // in PoC context menu filtering in CPbkAiwInterestItemPoc::InitMenuPaneL
       
   830     if ( currentField )
       
   831         {
       
   832         // We can't use the IsPocField() info here, since context
       
   833         // menu filtering is more strict than that
       
   834         const TPbkFieldId fieldId = currentField->FieldInfo().FieldId();
       
   835         switch ( fieldId )
       
   836             {
       
   837             case EPbkFieldIdVOIP:                   // FALLTHROUGH
       
   838             case EPbkFieldIdPushToTalk:             // FALLTHROUGH
       
   839             case EPbkFieldIdShareView:              // FALLTHROUGH
       
   840             case EPbkFieldIdSIPID:
       
   841                 {
       
   842                 flags |= KPbkCurrentFieldPoc;
       
   843                 }
       
   844             default:
       
   845                 {
       
   846                 // Do nothing
       
   847                 }
       
   848             }
       
   849         }
       
   850 
       
   851     // Offer the menu to AIW first
       
   852     if (iAiwInterestArray->InitMenuPaneL(aResourceId, *aMenuPane, flags))
       
   853         {
       
   854         // No need to continue
       
   855         return;
       
   856         }
       
   857 
       
   858     iViewExtension->DynInitMenuPaneL(aResourceId, aMenuPane);
       
   859 
       
   860     switch (aResourceId)
       
   861         {
       
   862         case R_PBK_CONTACTINFO_OPTIONS_MENU:
       
   863             {
       
   864             OptionsMenuFilteringL(*aMenuPane, flags);
       
   865             break;
       
   866             }
       
   867         case R_PBK_CONTACTINFO_CONTEXT_MENU:
       
   868             {
       
   869             ContextMenuFilteringL(*aMenuPane, flags);
       
   870             break;
       
   871             }
       
   872         case R_PBK_ADD_OBJECT_SUBMENU: // Add object menu item
       
   873             {
       
   874             AddObjectSubPaneMenuFilteringL(*aMenuPane, flags);
       
   875             break;
       
   876             }
       
   877         default:
       
   878             {
       
   879             break;
       
   880             }
       
   881         }
       
   882 
       
   883     CPbkMemoryEntryAppView::DynInitMenuPaneL(aResourceId,aMenuPane);
       
   884     }
       
   885 
       
   886 inline void CPbkContactInfoAppView::OptionsMenuFilteringL
       
   887         (CEikMenuPane& aMenuPane,
       
   888         TUint aFlags)
       
   889     {
       
   890     if ((aFlags & KPbkControlEmpty)
       
   891         || Engine()->IsSpeedDialAssigned(*iContactItem,
       
   892             iContainer->Control()->CurrentFieldIndex()))
       
   893         {
       
   894         aMenuPane.SetItemDimmed(EPbkCmdAssignSpeedDial, ETrue);
       
   895         }
       
   896     else if (FeatureManager::FeatureSupported(KFeatureIdCommonVoip))
       
   897         {
       
   898         if (!iContainer->Control()->CurrentField()->
       
   899             FieldInfo().IsVoipField())
       
   900             {
       
   901             aMenuPane.SetItemDimmed(EPbkCmdAssignSpeedDial, ETrue);
       
   902             }
       
   903         }
       
   904     else
       
   905         {
       
   906         if (!iContainer->Control()->CurrentField()->
       
   907             FieldInfo().IsPhoneNumberField())
       
   908             {
       
   909             aMenuPane.SetItemDimmed(EPbkCmdAssignSpeedDial, ETrue);
       
   910             }
       
   911         }
       
   912 
       
   913     if ((aFlags & KPbkControlEmpty) ||
       
   914         !Engine()->IsSpeedDialAssigned(*iContactItem,
       
   915             iContainer->Control()->CurrentFieldIndex()))
       
   916         {
       
   917         // Field is a phone number and speed dial for this field
       
   918         aMenuPane.SetItemDimmed(EPbkCmdRemoveSpeedDial, ETrue);
       
   919         }
       
   920     if ((aFlags & KPbkControlEmpty) || (!iUrlFieldAvailable))
       
   921         {
       
   922         // URL field not present
       
   923         aMenuPane.SetItemDimmed(EPbkCmdGoToURL, ETrue);
       
   924         }
       
   925     if ((aFlags & KPbkControlEmpty) || !(aFlags & KPbkCurrentFieldPhoneNumber))
       
   926         {
       
   927         // Field is not a phone number field
       
   928         aMenuPane.SetItemDimmed(EPbkCmdUseNumber, ETrue);
       
   929         }
       
   930 
       
   931     if (aFlags & KPbkControlEmpty)
       
   932         {
       
   933         aMenuPane.SetItemDimmed(EPbkCmdDefaultSettings, ETrue);
       
   934         aMenuPane.SetItemDimmed(EPbkCmdPersonalRingingTone, ETrue);
       
   935         aMenuPane.SetItemDimmed(EPbkCmdWrite, ETrue);
       
   936         aMenuPane.SetItemDimmed(EPbkCmdSendUICommand, ETrue);
       
   937         }
       
   938     else
       
   939         {
       
   940         aMenuPane.SetItemDimmed(EPbkCmdSendUICommand, EFalse);
       
   941         }
       
   942 
       
   943     if (FeatureManager::FeatureSupported(KFeatureIdCallImagetext))
       
   944         {
       
   945         // Empty contact, no fields
       
   946         if( (aFlags & KPbkControlEmpty) )
       
   947             {
       
   948             aMenuPane.SetItemDimmed( EPbkCmdCodEditText, ETrue );
       
   949             aMenuPane.SetItemDimmed( EPbkCmdCodViewImage, ETrue );
       
   950             aMenuPane.SetItemDimmed( EPbkCmdCodChangeImage, ETrue );
       
   951             aMenuPane.SetItemDimmed( EPbkCmdCodRemoveObject, ETrue );
       
   952             }
       
   953         else
       
   954             {
       
   955             TPbkContactItemField* field = iContainer->Control()->CurrentField();
       
   956             const TPbkFieldId pbkFieldId( field->FieldInfo().FieldId() );
       
   957 
       
   958             if (pbkFieldId == EPbkFieldIdCodTextID && CodTextFieldEnabled())
       
   959                 {
       
   960                 if (CodImageFieldEnabled())
       
   961                     {
       
   962                     // Text field contains Cod image filename
       
   963                     aMenuPane.SetItemDimmed( EPbkCmdCodEditText, ETrue );
       
   964                     }
       
   965                 else
       
   966                     {
       
   967                     // Text field is used for Cod text purposes
       
   968                     aMenuPane.SetItemDimmed( EPbkCmdCodViewImage, ETrue );
       
   969                     aMenuPane.SetItemDimmed( EPbkCmdCodChangeImage, ETrue );
       
   970                     }
       
   971                 }
       
   972             else
       
   973                 {
       
   974                 // Focus is not on the Object for call field.
       
   975                 aMenuPane.SetItemDimmed( EPbkCmdCodEditText, ETrue );
       
   976                 aMenuPane.SetItemDimmed( EPbkCmdCodViewImage, ETrue );
       
   977                 aMenuPane.SetItemDimmed( EPbkCmdCodChangeImage, ETrue );
       
   978                 aMenuPane.SetItemDimmed( EPbkCmdCodRemoveObject, ETrue );
       
   979                 }
       
   980             }
       
   981         }
       
   982     else
       
   983         {
       
   984         // Image/text for call feature not supported.
       
   985         // Dimm all related commands
       
   986         aMenuPane.SetItemDimmed( EPbkCmdCodEditText, ETrue);
       
   987         aMenuPane.SetItemDimmed( EPbkCmdCodViewImage, ETrue);
       
   988         aMenuPane.SetItemDimmed( EPbkCmdCodChangeImage, ETrue);
       
   989         aMenuPane.SetItemDimmed( EPbkCmdCodAddObjectSubMenu, ETrue);
       
   990         aMenuPane.SetItemDimmed( EPbkCmdCodRemoveObject, ETrue);
       
   991         }
       
   992 
       
   993     }
       
   994 
       
   995 inline void CPbkContactInfoAppView::ContextMenuFilteringL
       
   996         (CEikMenuPane& aMenuPane,
       
   997         TUint aFlags)
       
   998     {
       
   999     TPbkContactItemField* field = iContainer->Control()->CurrentField();
       
  1000 
       
  1001     // context sensitive menu filtering
       
  1002     if (aFlags & KPbkControlEmpty)
       
  1003         {
       
  1004         aMenuPane.SetItemDimmed(EPbkCmdWrite, ETrue);
       
  1005         aMenuPane.SetItemDimmed(EPbkCmdUseNumber, ETrue);
       
  1006         aMenuPane.SetItemDimmed(EPbkCmdPersonalRingingTone, ETrue);
       
  1007         aMenuPane.SetItemDimmed(EPbkCmdGoToURL, ETrue);
       
  1008         }
       
  1009     else if (field)
       
  1010         {
       
  1011         switch(field->FieldInfo().FieldId())
       
  1012             {
       
  1013             case EPbkFieldIdPhoneNumberStandard:    // FALLTHROUGH
       
  1014             case EPbkFieldIdPhoneNumberHome:        // FALLTHROUGH
       
  1015             case EPbkFieldIdPhoneNumberWork:        // FALLTHROUGH
       
  1016             case EPbkFieldIdPhoneNumberMobile:      // FALLTHROUGH
       
  1017             case EPbkFieldIdPhoneNumberVideo:       // FALLTHROUGH
       
  1018             case EPbkFieldIdFaxNumber:              // FALLTHROUGH
       
  1019             case EPbkFieldIdAssistantNumber:        // FALLTHROUGH
       
  1020             case EPbkFieldIdCarNumber:
       
  1021                 {
       
  1022                 aMenuPane.SetItemDimmed(EPbkCmdDeleteMe, ETrue);
       
  1023                 aMenuPane.SetItemDimmed(EPbkCmdPersonalRingingTone, ETrue);
       
  1024                 aMenuPane.SetItemDimmed(EPbkCmdGoToURL, ETrue);
       
  1025                 break;
       
  1026                 }
       
  1027             case EPbkFieldIdEmailAddress:
       
  1028                 {
       
  1029                 aMenuPane.SetItemDimmed(EPbkCmdDeleteMe, ETrue);
       
  1030                 aMenuPane.SetItemDimmed(EPbkCmdUseNumber, ETrue);
       
  1031                 aMenuPane.SetItemDimmed(EPbkCmdPersonalRingingTone, ETrue);
       
  1032                 aMenuPane.SetItemDimmed(EPbkCmdGoToURL, ETrue);
       
  1033                 break;
       
  1034                 }
       
  1035             case EPbkFieldIdPersonalRingingToneIndication:
       
  1036                 {
       
  1037                 aMenuPane.SetItemDimmed(EPbkCmdWrite, ETrue);
       
  1038                 aMenuPane.SetItemDimmed(EPbkCmdUseNumber, ETrue);
       
  1039                 aMenuPane.SetItemDimmed(EPbkCmdEditMe, ETrue);
       
  1040                 aMenuPane.SetItemDimmed(EPbkCmdDeleteMe, ETrue);
       
  1041                 aMenuPane.SetItemDimmed(EPbkCmdGoToURL, ETrue);
       
  1042                 break;
       
  1043                 }
       
  1044             case EPbkFieldIdURL:
       
  1045                 {
       
  1046                 aMenuPane.SetItemDimmed(EPbkCmdWrite, ETrue);
       
  1047                 aMenuPane.SetItemDimmed(EPbkCmdUseNumber, ETrue);
       
  1048                 aMenuPane.SetItemDimmed(EPbkCmdDeleteMe, ETrue);
       
  1049                 aMenuPane.SetItemDimmed(EPbkCmdPersonalRingingTone, ETrue);
       
  1050                 break;
       
  1051                 }
       
  1052             default:
       
  1053                 {
       
  1054                 // By default only Edit item is shown
       
  1055                 aMenuPane.SetItemDimmed(EPbkCmdWrite, ETrue);
       
  1056                 aMenuPane.SetItemDimmed(EPbkCmdUseNumber, ETrue);
       
  1057                 aMenuPane.SetItemDimmed(EPbkCmdDeleteMe, ETrue);
       
  1058                 aMenuPane.SetItemDimmed(EPbkCmdPersonalRingingTone, ETrue);
       
  1059                 aMenuPane.SetItemDimmed(EPbkCmdGoToURL, ETrue);
       
  1060                 break;
       
  1061                 }
       
  1062             }
       
  1063         }
       
  1064     }
       
  1065 
       
  1066 TPbkSendingParams CPbkContactInfoAppView::CreateWriteParamsLC()
       
  1067     {
       
  1068     // Construct the MTM filter
       
  1069     CArrayFixFlat<TUid>* mtmFilter =
       
  1070         new(ELeave) CArrayFixFlat<TUid>(4);
       
  1071     CleanupStack::PushL(mtmFilter);
       
  1072 
       
  1073     if (iContainer->Control()->FieldCount() > 0)
       
  1074         {
       
  1075         switch(iContainer->Control()->CurrentField()->FieldInfo().FieldId())
       
  1076             {
       
  1077             case EPbkFieldIdPhoneNumberStandard:    // FALLTHROUGH
       
  1078             case EPbkFieldIdPhoneNumberHome:        // FALLTHROUGH
       
  1079             case EPbkFieldIdPhoneNumberWork:        // FALLTHROUGH
       
  1080             case EPbkFieldIdPhoneNumberMobile:      // FALLTHROUGH
       
  1081             case EPbkFieldIdAssistantNumber:        // FALLTHROUGH
       
  1082             case EPbkFieldIdCarNumber:
       
  1083                 {
       
  1084                 mtmFilter->AppendL(KSenduiMtmSmtpUid); //Email
       
  1085                 break;
       
  1086                 }
       
  1087             case EPbkFieldIdEmailAddress:
       
  1088                 {
       
  1089                 mtmFilter->AppendL(KSenduiMtmSmsUid); //Sms
       
  1090                 break;
       
  1091                 }
       
  1092             default:
       
  1093                 break;
       
  1094             }
       
  1095         }
       
  1096 
       
  1097     TSendingCapabilities capabilities = TSendingCapabilities();
       
  1098     capabilities.iFlags = TSendingCapabilities::ESupportsEditor;
       
  1099     return TPbkSendingParams( mtmFilter, capabilities );
       
  1100     }
       
  1101 
       
  1102 TPbkSendingParams CPbkContactInfoAppView::CreateSendParamsLC()
       
  1103     {
       
  1104     // Construct the MTM filter
       
  1105     CArrayFixFlat<TUid>* mtmFilter =
       
  1106         new(ELeave) CArrayFixFlat<TUid>(4);
       
  1107     CleanupStack::PushL(mtmFilter);
       
  1108 
       
  1109     const TUid KPostcardMtmUid = { KSenduiMtmPostcardUidValue };
       
  1110 
       
  1111     mtmFilter->AppendL(KPostcardMtmUid);    // hide postcard
       
  1112     mtmFilter->AppendL(KSenduiMtmAudioMessageUid); // hide audio message
       
  1113 
       
  1114     TSendingCapabilities capabilities = TSendingCapabilities();
       
  1115     capabilities.iFlags = TSendingCapabilities::ESupportsBioSending;
       
  1116     capabilities.iFlags |= TSendingCapabilities::ESupportsAttachments;
       
  1117     return TPbkSendingParams( mtmFilter, capabilities );
       
  1118     }
       
  1119 
       
  1120 TUid CPbkContactInfoAppView::Id() const
       
  1121     {
       
  1122     return CPbkAppUi::KPbkContactInfoViewUid;
       
  1123     }
       
  1124 
       
  1125 void CPbkContactInfoAppView::HandleStatusPaneSizeChange()
       
  1126     {
       
  1127     // Resize the container to fill the client rectangle
       
  1128     if (iContainer)
       
  1129         {
       
  1130         iContainer->SetRect(ClientRect());
       
  1131         }
       
  1132     }
       
  1133 
       
  1134 void CPbkContactInfoAppView::DoActivateL
       
  1135         (const TVwsViewId& aPrevViewId,
       
  1136          TUid aCustomMessageId,
       
  1137          const TDesC8& aCustomMessage)
       
  1138     {
       
  1139     PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
  1140         ("CPbkContactInfoAppView(%x)::DoActivateL()"), this);
       
  1141 
       
  1142     // reset the exit in progress flag.
       
  1143     iExitInProgress = EFalse;
       
  1144 
       
  1145     // Call base class, this must be done!
       
  1146     CPbkMemoryEntryAppView::DoActivateL(aPrevViewId,
       
  1147         aCustomMessageId, aCustomMessage);
       
  1148 
       
  1149     // Update application-wide state. UI control updates the title pane.
       
  1150     CPbkAppUi::CViewActivationTransaction* viewActivationTransaction =
       
  1151         PbkAppUi()->HandleViewActivationLC
       
  1152             (Id(), aPrevViewId, NULL, NULL,
       
  1153             CPbkAppUi::EUpdateNaviPane | CPbkAppUi::EUpdateContextPane);
       
  1154 
       
  1155     if (aCustomMessageId == CPbkViewState::Uid())
       
  1156         {
       
  1157         // Read the desired UI state from aCustomMessage
       
  1158         CPbkViewState* viewState = CPbkViewState::NewL(aCustomMessage);
       
  1159         if (iViewState)
       
  1160             {
       
  1161             // Merge parameter view state with the stored state
       
  1162             if (viewState->FocusedContactId() != iViewState->FocusedContactId())
       
  1163                 {
       
  1164                 iViewState->SetFocusedContactId(viewState->FocusedContactId());
       
  1165                 iViewState->SetFocusedFieldIndex(-1);
       
  1166                 iViewState->SetTopFieldIndex(-1);
       
  1167                 }
       
  1168             if (viewState->FocusedFieldIndex() >= 0)
       
  1169                 {
       
  1170                 iViewState->SetFocusedFieldIndex(viewState->FocusedFieldIndex());
       
  1171                 }
       
  1172             if (viewState->TopFieldIndex() >= 0)
       
  1173                 {
       
  1174                 iViewState->SetTopFieldIndex(viewState->TopFieldIndex());
       
  1175                 }
       
  1176             if (viewState->ParentContactId() != iViewState->ParentContactId())
       
  1177                 {
       
  1178                 iViewState->SetParentContactId(viewState->ParentContactId());
       
  1179                 }
       
  1180             // delete parameter view state
       
  1181             delete viewState;
       
  1182             }
       
  1183         else
       
  1184             {
       
  1185             // No stored state, use the parameter supplied one
       
  1186             iViewState = viewState;
       
  1187             }
       
  1188         }
       
  1189     else
       
  1190         {
       
  1191         // No UI state specified, restore in previous state
       
  1192         if (!iViewState)
       
  1193             {
       
  1194             // No previous state
       
  1195             User::Leave(KErrArgument);
       
  1196             }
       
  1197         }
       
  1198 
       
  1199     // Read the contact
       
  1200     if (!iContactItem || iContactItem->Id() != iViewState->FocusedContactId())
       
  1201         {
       
  1202         CPbkContactItem* ci = Engine()->ReadContactLC
       
  1203             (iViewState->FocusedContactId());
       
  1204         if (iContainer && iContainer->Control())
       
  1205             {
       
  1206             // Change the contact item inside the UI control
       
  1207             iContainer->Control()->UpdateL(ci);
       
  1208             }
       
  1209         delete iContactItem;
       
  1210         CleanupStack::Pop();  // ci
       
  1211         iContactItem = ci;
       
  1212 
       
  1213         //Check does the contact have an URL field
       
  1214         UpdateUrlFieldInfo();
       
  1215         }
       
  1216 
       
  1217     if (!iContainer)
       
  1218         {
       
  1219         // Create the container control
       
  1220         iContainer = CContainer::NewL(this, *this);
       
  1221 
       
  1222         iContainer->SetHelpContext(TCoeHelpContext(ApplicationUid(),
       
  1223             KPHOB_HLP_CONTACT_INFO_VIEW));
       
  1224 
       
  1225         // Create extension
       
  1226         if (!iViewExtension)
       
  1227             {
       
  1228             iViewExtension =
       
  1229                 iExtGlobal->FactoryL().CreatePbkViewExtensionL
       
  1230                     (Id(), *PbkAppUi()->PbkDocument()->Engine(), *this);
       
  1231             }
       
  1232 
       
  1233         // Create the view-side UI control
       
  1234         CPbkContactInfoControl* control = CPbkContactInfoControl::NewL
       
  1235             (R_PBK_DEFAULT_CONTACTINFO_CONTROL,
       
  1236             *iContainer,
       
  1237             iContactItem,
       
  1238             Engine());
       
  1239 
       
  1240         // Set up the container. iContainer takes ownership of control safely
       
  1241         iContainer->SetControl(control, ClientRect());
       
  1242         iViewExtension->SetContactUiControl(control);
       
  1243         iContainer->ActivateL();
       
  1244 
       
  1245         // create navigation strategy
       
  1246         iNaviStrategy = PbkContactInfoNavigationStrategyFactory::CreateL(
       
  1247                 *Engine(), *this, iViewState->ParentContactId());
       
  1248 
       
  1249         // Add this view and container to the view stack
       
  1250         AppUi()->AddToViewStackL(*this, iContainer);
       
  1251         }
       
  1252 
       
  1253     // Restore UI control state
       
  1254     iContainer->Control()->RestoreStateL(iViewState);
       
  1255     // Delete the view state object to save memory
       
  1256     delete iViewState;
       
  1257     iViewState = NULL;
       
  1258 
       
  1259     // Commit application-wide state changes
       
  1260     viewActivationTransaction->Commit();
       
  1261     CleanupStack::PopAndDestroy();  // viewActivationTransaction
       
  1262 
       
  1263     // Draw the control
       
  1264     iContainer->Control()->DrawNow();
       
  1265 
       
  1266     // PostCond
       
  1267     __ASSERT_DEBUG(
       
  1268         iContainer && iContainer->Control() &&
       
  1269         iContactItem && !iViewState,
       
  1270         Panic(EPanicPostCond_DoActivateL));
       
  1271     }
       
  1272 
       
  1273 void CPbkContactInfoAppView::DoDeactivate()
       
  1274     {
       
  1275     PBK_DEBUG_PRINT(PBK_DEBUG_STRING
       
  1276         ("CPbkContactInfoAppView(%x)::DoDeactivate()"), this);
       
  1277 
       
  1278     // Delete any previous view state
       
  1279     delete iViewState;
       
  1280     iViewState = NULL;
       
  1281 
       
  1282     // delete navigation strategy
       
  1283     delete iNaviStrategy;
       
  1284     iNaviStrategy = NULL;
       
  1285 
       
  1286     if (iContainer)
       
  1287         {
       
  1288         if (iContainer->Control())
       
  1289             {
       
  1290             // Store the view state for next activation
       
  1291             TRAP_IGNORE(iViewState = iContainer->Control()->GetStateL());
       
  1292             }
       
  1293         // Remove view and its control from the view stack
       
  1294         AppUi()->RemoveFromViewStack(*this, iContainer);
       
  1295         // Destroy the container control
       
  1296         delete iContainer;
       
  1297         iContainer = NULL;
       
  1298         }
       
  1299 
       
  1300     if (iViewExtension)
       
  1301         {
       
  1302         iViewExtension->SetContactUiControl(NULL);
       
  1303         }
       
  1304 
       
  1305     // Delete the contact item
       
  1306     delete iContactItem;
       
  1307     iContactItem = NULL;
       
  1308 
       
  1309     // Call base class, this must be done!
       
  1310     CPbkMemoryEntryAppView::DoDeactivate();
       
  1311 
       
  1312     // PostCond
       
  1313     __ASSERT_DEBUG(!iContainer && !iContactItem,
       
  1314         Panic(EPanicPostCond_DoDeactivate));
       
  1315     }
       
  1316 
       
  1317 
       
  1318 void CPbkContactInfoAppView::UpdateUrlFieldInfo()
       
  1319     {
       
  1320     iUrlFieldAvailable = EFalse;
       
  1321     if (iContactItem->FindField(EPbkFieldIdURL))
       
  1322         {
       
  1323         iUrlFieldAvailable = ETrue;
       
  1324         }
       
  1325     }
       
  1326 
       
  1327 void CPbkContactInfoAppView::ChangeContactL
       
  1328         (TContactItemId aContactId)
       
  1329     {
       
  1330     // Load the contact
       
  1331     CPbkContactItem* ci = Engine()->ReadContactLC(aContactId);
       
  1332     // Check if the contact content has changed or the contact
       
  1333     // has changed. CPbkContactItem's == operator only compares
       
  1334     // fields, therefore the id check has to be done manually.
       
  1335     if ((aContactId != iContactItem->Id()) || (*ci != *iContactItem))
       
  1336         {
       
  1337         // Update the UI control
       
  1338         CPbkContactInfoControl* control = iContainer->Control();
       
  1339         CPbkViewState* controlState = control->GetStateLC();
       
  1340         control->UpdateL(ci);
       
  1341         control->RestoreStateL(controlState);
       
  1342         CleanupStack::PopAndDestroy(controlState);
       
  1343         // Update members
       
  1344         delete iContactItem;
       
  1345         CleanupStack::Pop(ci);
       
  1346         iContactItem = ci;
       
  1347         UpdateUrlFieldInfo();
       
  1348         control->DrawNow();
       
  1349         }
       
  1350     else
       
  1351         {
       
  1352         // Contact data not changed, no need to update
       
  1353         CleanupStack::PopAndDestroy();  // ci
       
  1354         }
       
  1355     }
       
  1356 
       
  1357 CEikStatusPane* CPbkContactInfoAppView::GetStatusPane() const
       
  1358     {
       
  1359     return StatusPane();
       
  1360     }
       
  1361 
       
  1362 TContactItemId CPbkContactInfoAppView::GetContactItemId() const
       
  1363     {
       
  1364     return iContactItem->Id();
       
  1365     }
       
  1366 
       
  1367 void CPbkContactInfoAppView::AddObjectSubPaneMenuFilteringL(
       
  1368     CEikMenuPane& aMenuPane, TUint
       
  1369     aFlags
       
  1370     )
       
  1371     {
       
  1372     if (FeatureManager::FeatureSupported(KFeatureIdCallImagetext))
       
  1373         {
       
  1374         // If empty contanct then no more execution needed
       
  1375         if (! (aFlags & KPbkControlEmpty) )
       
  1376             {
       
  1377             if (CodTextFieldEnabled())
       
  1378                 {
       
  1379                 if (CodImageFieldEnabled())
       
  1380                     {
       
  1381                     aMenuPane.SetItemDimmed( EPbkCmdCodAddObjectImage, ETrue );
       
  1382                     }
       
  1383                 else
       
  1384                     {
       
  1385                     aMenuPane.SetItemDimmed( EPbkCmdCodAddObjectText, ETrue );
       
  1386                     }
       
  1387                 }
       
  1388             }
       
  1389         }
       
  1390     else
       
  1391         {
       
  1392         aMenuPane.SetItemDimmed( EPbkCmdCodAddObjectImage, ETrue );
       
  1393         }
       
  1394     }
       
  1395 
       
  1396 /**
       
  1397  * Command handler: Removes object for call from the contact.
       
  1398  */
       
  1399 void CPbkContactInfoAppView::CmdRemoveCodL(TInt aFieldType)
       
  1400     {
       
  1401     //PreCond: Field type id should be either Cod image for Cod text.
       
  1402     __ASSERT_DEBUG( ( aFieldType == EPbkFieldIdCodTextID ||
       
  1403              aFieldType == EPbkFieldIdCodImageID ),
       
  1404         Panic(EPanicPreCond_CmdRemoveCodL) );
       
  1405 
       
  1406     TPbkContactItemField* field = iContactItem->FindField( aFieldType );
       
  1407     if (field && aFieldType == EPbkFieldIdCodTextID )
       
  1408         {
       
  1409         CPbkContactItem* ci = Engine()->OpenContactLCX(iContactItem->Id());
       
  1410         ci->RemoveField(iContactItem->FindFieldIndex(*field));
       
  1411         Engine()->CommitContactL(*ci);
       
  1412         // Update member
       
  1413         CleanupStack::PopAndDestroy(ci);
       
  1414         CleanupStack::PopAndDestroy(); // lock
       
  1415         // UI refresh is handled by HandleDatabaseEventL method in base class
       
  1416         }
       
  1417     else
       
  1418         {
       
  1419         PbkCodImageCmdL().RemoveImageL(iContactItem->Id());
       
  1420         }
       
  1421     }
       
  1422 
       
  1423 inline void CPbkContactInfoAppView::CmdAddCodFieldL( TInt aCommandId )
       
  1424     {
       
  1425     __ASSERT_DEBUG( EPbkCmdCodAddObjectImage == aCommandId ||
       
  1426         EPbkCmdCodAddObjectText == aCommandId,
       
  1427         Panic(EPanicPreCond_CmdAddCodFieldL) );
       
  1428     #ifdef _DEBUG
       
  1429     TInt fieldId(EPbkCmdCodAddObjectText==aCommandId?
       
  1430         EPbkFieldIdCodTextID:EPbkFieldIdCodImageID);
       
  1431     // Field info should be found
       
  1432     CPbkFieldInfo* fieldInfo = Engine()->FieldsInfo().Find(fieldId);
       
  1433     #endif
       
  1434     __ASSERT_DEBUG( fieldInfo,
       
  1435         Panic(EPanicFieldInfoNotFound_CmdAddCodFieldL) );
       
  1436 
       
  1437     if (aCommandId==EPbkCmdCodAddObjectText)
       
  1438         {
       
  1439         // Check if Cod image exists.
       
  1440         if ( CodTextFieldEnabled() && CodImageFieldEnabled() )
       
  1441             {
       
  1442             // Reset data.
       
  1443             CmdRemoveCodL(EPbkFieldIdCodTextID);
       
  1444             CmdRemoveCodL(EPbkFieldIdCodImageID);
       
  1445             }
       
  1446         HandleCodTextChangeL(iContactItem->Id());
       
  1447         }
       
  1448     else
       
  1449         {
       
  1450         HandleCodImageChangeL(iContactItem->Id());
       
  1451         }
       
  1452     }
       
  1453 
       
  1454 inline TBool CPbkContactInfoAppView::HandleCodTextChangeL(TContactItemId aId) const
       
  1455     {
       
  1456     TBool ret(EFalse);
       
  1457 
       
  1458     // Field info should be found
       
  1459     CPbkFieldInfo* fieldInfo = Engine()->FieldsInfo().Find(EPbkFieldIdCodTextID);
       
  1460     __ASSERT_DEBUG( fieldInfo,
       
  1461         Panic( EPanicFieldInfoNotFound_HandleCodTextChangeL ) );
       
  1462 
       
  1463     CPbkContactItem* ci = Engine()->OpenContactLCX(aId);
       
  1464     // Use text field if exists
       
  1465     TPbkContactItemField* field = ci->FindField( EPbkFieldIdCodTextID );
       
  1466     if (!field)
       
  1467         {
       
  1468         // Otherwise create new field for filename purposes
       
  1469         field = ci->AddOrReturnUnusedFieldL(*fieldInfo);
       
  1470         }
       
  1471     __ASSERT_DEBUG( field->TextStorage(),
       
  1472         Panic(EPanicTextStorageNotFound_HandleCodTextChangeL) );
       
  1473 
       
  1474     HBufC* textToBeModified = HBufC::NewMaxLC(KPbkCodTextMaxLength);
       
  1475     CContactTextField& contactTextField = *field->TextStorage();
       
  1476     textToBeModified->Des().Copy(contactTextField.Text().Left(KPbkCodTextMaxLength));
       
  1477     TPtr ptr = textToBeModified->Des();
       
  1478     HBufC* prompt = StringLoader::LoadLC(R_QTN_PHOB_PRTX_TEXT_FOR_CALL);
       
  1479     CAknTextQueryDialog* aknTextQueryDialog = CAknTextQueryDialog::NewL(ptr);
       
  1480     aknTextQueryDialog->SetMaxLength(KPbkCodTextMaxLength);
       
  1481     if (aknTextQueryDialog->ExecuteLD(R_PBK_EDIT_FIELD_TEXT_FOR_QUERY, *prompt))
       
  1482         {
       
  1483         // The text is set if data query not cancelled
       
  1484         contactTextField.SetTextL(*textToBeModified);
       
  1485 
       
  1486         TPbkContactItemField* imageField=ci->FindField(EPbkFieldIdCodImageID);
       
  1487         if (imageField)
       
  1488             {
       
  1489             // Image can not exist if Cod text field is used.
       
  1490             ci->RemoveField(ci->FindFieldIndex(*field));
       
  1491             }
       
  1492         Engine()->CommitContactL(*ci);
       
  1493         ret = ETrue;
       
  1494         }
       
  1495     CleanupStack::PopAndDestroy(4); //textToBeModified, prompt, ci, lock
       
  1496 
       
  1497     return ret;
       
  1498     }
       
  1499 
       
  1500 inline void CPbkContactInfoAppView::CmdEditTextCodFieldL()
       
  1501     {
       
  1502     __ASSERT_DEBUG( iContactItem->FindField(EPbkFieldIdCodTextID),
       
  1503         Panic(EPanicPreCond_CmdEditTextCodFieldL) );
       
  1504     HandleCodTextChangeL(iContactItem->Id());
       
  1505     }
       
  1506 
       
  1507 inline TBool CPbkContactInfoAppView::HandleCodImageChangeL(TContactItemId aId)
       
  1508     {
       
  1509     return PbkCodImageCmdL().FetchImageL(aId);
       
  1510     }
       
  1511 
       
  1512 CPbkCodImageCmd& CPbkContactInfoAppView::PbkCodImageCmdL()
       
  1513     {
       
  1514     if (!iPbkCodImageCmd)
       
  1515         {
       
  1516         iPbkCodImageCmd = CPbkCodImageCmd::NewL(*Engine());
       
  1517         }
       
  1518     return *iPbkCodImageCmd;
       
  1519     }
       
  1520 
       
  1521 inline void CPbkContactInfoAppView::CmdViewCodImageL()
       
  1522     {
       
  1523     PbkCodImageCmdL().ViewImageL(iContactItem->Id());
       
  1524     }
       
  1525 
       
  1526 TBool CPbkContactInfoAppView::CodTextFieldEnabled() const
       
  1527     {
       
  1528     return iContactItem->FindField(EPbkFieldIdCodTextID)?ETrue:EFalse;
       
  1529     }
       
  1530 
       
  1531 TBool CPbkContactInfoAppView::CodImageFieldEnabled() const
       
  1532     {
       
  1533     return iContactItem->FindField(EPbkFieldIdCodImageID)?ETrue:EFalse;
       
  1534     }
       
  1535 
       
  1536 //  End of File