syncmlfw/syncmlnotifier/src/SyncMLDlgNotifier.cpp
branchRCL_3
changeset 25 b183ec05bd8c
parent 24 13d7c31c74e0
child 26 19bba8228ff0
equal deleted inserted replaced
24:13d7c31c74e0 25:b183ec05bd8c
     1 /*
       
     2 * Copyright (c) 2005 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:  Methods for the SyncML Appserver starter notifier
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <eikenv.h>             // Eikon environment
       
    22 #include <SyncMLClient.h>
       
    23 #include <SyncMLClientDS.h>
       
    24 #include <SyncMLClientDM.h>
       
    25 #include <SyncService.h>
       
    26 #include <aknnotewrappers.h>
       
    27 #include <s32mem.h> 
       
    28 #include <in_sock.h>
       
    29 #include <StringLoader.h>    // Localisation stringloader
       
    30 #include <aknlists.h>
       
    31 #include <avkon.mbg>
       
    32 #include <aknconsts.h>
       
    33 #include <utf.h>
       
    34 #include <SyncMLNotifier.rsg>   // Own resources
       
    35 #include "SyncMLDlgNotifier.h"  // Class definition
       
    36 #include "SyncMLTimedMessageQuery.h"
       
    37 #include "SyncMLAppLaunchNotifier.h"
       
    38 #include "SyncMLNotifDebug.h"
       
    39 #include "SyncMLTimedInputTextQuery.h"
       
    40 #include "SyncMLTimedDateQuery.h"
       
    41 #include "SyncMLTimedNumberQueryDialog.h"
       
    42 #include "SyncMLAknPopUplist.h"
       
    43 
       
    44 // CONSTANTS
       
    45 const TInt  KSyncMLuSecsInSec   = 1000000; // Microseconds in a second
       
    46 
       
    47 // ============================ MEMBER FUNCTIONS ===============================
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CSyncMLDlgNotifier::NewL
       
    51 // Two-phased constructor.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 CSyncMLDlgNotifier* CSyncMLDlgNotifier::NewL(
       
    55     CSyncMLAppLaunchNotifier* aAppLaunchNotif )
       
    56     {
       
    57     FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::NewL()") );
       
    58     CSyncMLDlgNotifier* self = new (ELeave) CSyncMLDlgNotifier( aAppLaunchNotif );
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::NewL() completed") );
       
    63     return self;
       
    64     }
       
    65 
       
    66     
       
    67 // -----------------------------------------------------------------------------
       
    68 // Destructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CSyncMLDlgNotifier::~CSyncMLDlgNotifier()
       
    72     {
       
    73     Cancel();   // Free own resources
       
    74     if(iListItems)
       
    75         {
       
    76         delete iListItems;
       
    77         iListItems = NULL;
       
    78         }
       
    79     if(iChunk.Handle())
       
    80         {
       
    81         iChunk.Close();
       
    82         }
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CSyncMLDlgNotifier::EnableSyncProgressNoteL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CSyncMLDlgNotifier::EnableSyncProgressNoteL( TBool aEnable )
       
    90     {
       
    91     FTRACE( FPrint( _L(
       
    92         "[SmlNotif]\t CSyncMLDlgNotifier::EnableSyncProgressNoteL(), aEnable = %d" ),
       
    93         aEnable ) );
       
    94         
       
    95     TSmlJobId currentJobId( KErrNotFound );
       
    96     TSmlUsageType usageType;
       
    97     TUint serviceId = 0;
       
    98     RSyncMLSession syncSession;
       
    99     CleanupClosePushL( syncSession );
       
   100     
       
   101     syncSession.OpenL();
       
   102     syncSession.CurrentJobL( currentJobId, usageType );
       
   103     syncSession.Close();
       
   104     CleanupStack::Pop( &syncSession );
       
   105 
       
   106     if ( currentJobId != KErrNotFound )
       
   107         {
       
   108         switch( usageType )
       
   109             {
       
   110             case ESmlDataSync:
       
   111                 serviceId = KDataSyncServiceStart;
       
   112                 break;
       
   113             case ESmlDevMan:
       
   114                 serviceId = KDevManServiceStart;
       
   115                 break;
       
   116             default:
       
   117                 User::Leave( KErrArgument );
       
   118                 break;
       
   119             }
       
   120 
       
   121         // There should be a valid pointer to the application launcher
       
   122         // notifier, but we can survive without it. Therefore we'll just
       
   123         // check for it to prevent a crash.
       
   124         if ( iAppLaunchNotif )
       
   125             {
       
   126             CSyncService* syncService = iAppLaunchNotif->SyncServiceL( serviceId );
       
   127             if ( syncService )
       
   128                 {
       
   129                 syncService->EnableProgressNoteL( aEnable );
       
   130                 }
       
   131             }
       
   132         }
       
   133     else
       
   134         {
       
   135         User::Leave( KErrNotFound );
       
   136         }
       
   137     FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::EnableSyncProgressNoteL() completed") );
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CSyncMLDlgNotifier::RegisterL
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 CSyncMLDlgNotifier::TNotifierInfo CSyncMLDlgNotifier::RegisterL()
       
   145     {
       
   146     FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::RegisterL()") );
       
   147     iInfo.iUid = KSyncMLDlgNotifierUid;
       
   148     iInfo.iChannel = KSmlDlgChannel;
       
   149     iInfo.iPriority = ENotifierPriorityHigh;
       
   150     FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::RegisterL() completed") );
       
   151     return iInfo;
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CSyncMLDlgNotifier::GetParamsL
       
   156 // Initialize parameters and check if device is already
       
   157 // in registry. Jump to RunL as soon as possible.
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 void CSyncMLDlgNotifier::GetParamsL( const TDesC8& aBuffer,
       
   161                                            TInt    aReplySlot,
       
   162                                      const RMessagePtr2& aMessage )
       
   163     {
       
   164     FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::GetParamsL()") );
       
   165     const TChar KDRSeparator('-');
       
   166     const TChar KChoiceItemSeparator(',');
       
   167     if ( iReplySlot != NULL || iNeedToCompleteMessage )
       
   168         {
       
   169         User::Leave( KErrInUse );
       
   170         }
       
   171     iMessage = aMessage;
       
   172     iNeedToCompleteMessage = ETrue;
       
   173     iReplySlot = aReplySlot;
       
   174 
       
   175     TSyncMLDlgNotifParams param;
       
   176     TPckgC<TSyncMLDlgNotifParams> pckg( param );
       
   177     pckg.Set( aBuffer );
       
   178     iNoteType = pckg().iNoteType;
       
   179     iServerMsg.Copy( pckg().iServerMsg.Left( KSyncMLMaxServerMsgLength ) );
       
   180     iMaxTime = pckg().iMaxTime;
       
   181     iMaxlen = pckg().iMaxLength;
       
   182     //check for iDR is there are not
       
   183     iDR.Copy( pckg().iDR.Left( KSyncMLMaxDefaultResponseMsgLength ) );
       
   184     iIT = pckg().iIT;
       
   185     iET = pckg().iET;
       
   186     //verification of other params as like maxtime
       
   187     if ( iMaxlen <= 0 || iMaxlen >KSyncMLMaxDefaultResponseMsgLength )
       
   188         {
       
   189         iMaxlen = KSyncMLMaxDefaultResponseMsgLength;
       
   190         }
       
   191 
       
   192     if ( iIT < ESyncMLInputTypeAlphaNumeric || iIT > ESyncMLInputTypeIPAddress )
       
   193         {
       
   194         iIT = ESyncMLInputTypeAlphaNumeric;
       
   195         }
       
   196 
       
   197     if ( iET < ESyncMLEchoTypeText || iET > ESyncMLEchoTypePassword )
       
   198         {
       
   199         iET = ESyncMLEchoTypeText;
       
   200         }
       
   201 
       
   202     if( iServerMsg.Length() == 0 )
       
   203         {
       
   204         HBufC* stringholder = NULL;
       
   205         stringholder = StringLoader::LoadLC( R_DEFAULT_ALERT_HEADING );
       
   206         iServerMsg.Copy( stringholder->Des() );
       
   207         CleanupStack::PopAndDestroy( stringholder );
       
   208         }
       
   209     if ( iMaxTime < 0 )
       
   210         {
       
   211         iMaxTime = 0;
       
   212         }
       
   213     if (iNoteType == ESyncMLSingleChoiceQuery || iNoteType == ESyncMLMultiChoiceQuery )
       
   214         {
       
   215 		iNumberOfItems = pckg().iNumberOfItems;  		
       
   216         if(iNumberOfItems > 0)
       
   217             {            
       
   218             iListItems = new (ELeave) CDesCArrayFlat( iNumberOfItems );
       
   219             }
       
   220 		else
       
   221 			{
       
   222 		    aMessage.Complete( KErrCancel );
       
   223 			iNeedToCompleteMessage = EFalse;
       
   224 			return;
       
   225 			}
       
   226         TPtrC8 listitemsptr;
       
   227         TBuf<KSyncMLChoiceItemsLengthBuffer> listlengtharray;                
       
   228         User::LeaveIfError(iChunk.OpenGlobal(pckg().iChunkName,EFalse));
       
   229         TInt size1 = iChunk.Size();
       
   230         listitemsptr.Set(iChunk.Base(),size1);        
       
   231         HBufC* databuf = NULL;
       
   232         TRAPD(errC, databuf = CnvUtfConverter::ConvertToUnicodeFromUtf8L(listitemsptr));
       
   233         iChunk.Close();
       
   234         if(errC)
       
   235             {
       
   236             aMessage.Complete( errC );
       
   237             iNeedToCompleteMessage = EFalse;
       
   238             return;
       
   239             }
       
   240         CleanupStack::PushL(databuf);
       
   241         TPtr listitems = databuf->Des();                       		
       
   242         listlengtharray=pckg().iItemLength;      
       
   243         TPtrC temp1,temp2,temp3,temp4;        
       
   244         TInt currlen=0,itemlength=0;
       
   245         TInt prevcommapos=0;
       
   246         TBuf<4> checkon(_L("0\t"));
       
   247         TBuf<4> checkoff(_L("1\t"));        
       
   248         for(TInt i=0;i<listlengtharray.Length();i++)
       
   249             {            
       
   250             if(listlengtharray[i]== KChoiceItemSeparator )
       
   251                 {
       
   252                 if(prevcommapos)
       
   253                     {
       
   254                     temp1.Set(listlengtharray.LeftTPtr(i));
       
   255                     temp2.Set(temp1.Right(i-(prevcommapos+1)));
       
   256                     prevcommapos=  i;
       
   257                     }
       
   258                 else //firsttime finding comma
       
   259                     {
       
   260                     prevcommapos=  i;
       
   261                     temp1.Set(listlengtharray.LeftTPtr(i));
       
   262                     temp2.Set(temp1.Right(i));
       
   263                     }                
       
   264                 TLex lexval;
       
   265                 lexval.Assign(temp2);
       
   266                 lexval.Val(itemlength);                
       
   267                 temp3.Set(listitems.Left(currlen + itemlength));
       
   268                 temp4.Set(temp3.Right(itemlength));
       
   269                 currlen += itemlength;                
       
   270                 HBufC* item1 = HBufC::NewLC(temp4.Length()+3);
       
   271                 if(iNoteType == ESyncMLMultiChoiceQuery)
       
   272                     {
       
   273                     item1->Des().Append(checkoff);//by default dont show check on                                     
       
   274                     }                
       
   275                 item1->Des().Append(temp4);
       
   276                 iListItems->AppendL(item1->Des());
       
   277                 CleanupStack::PopAndDestroy(1);//item,dataBuf16                
       
   278                 }
       
   279             }
       
   280         CleanupStack::PopAndDestroy(1);
       
   281         }   
       
   282     SetActive();
       
   283     iStatus = KRequestPending;
       
   284     TRequestStatus* stat = &iStatus;
       
   285     User::RequestComplete( stat, KErrNone );
       
   286 
       
   287     FTRACE( FPrint( _L(
       
   288             "[SmlNotif]\t CSyncMLDlgNotifier::GetParamsL() completed, iNoteType = %d, iTimeout = %d, iServerMsg = " ),
       
   289             iNoteType, iMaxTime ) );
       
   290     FTRACE( FPrint( _L(
       
   291             "[SmlNotif]\t \"%S\"" ),
       
   292             &iServerMsg ) );
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // CSyncMLDlgNotifier::Cancel
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 void CSyncMLDlgNotifier::Cancel()
       
   300     {
       
   301     FLOG(_L("[SmlNotif]\t CSyncMLDlgNotifier::Cancel()"));
       
   302 
       
   303     CSyncMLNotifierBase::Cancel();
       
   304 
       
   305     FLOG(_L("[SmlNotif]\t CSyncMLDlgNotifier::Cancel() completed"));
       
   306     }
       
   307 
       
   308 // -----------------------------------------------------------------------------
       
   309 // CSyncMLDlgNotifier::RunL
       
   310 // Ask user response and return it to caller.
       
   311 // Store device into registry if user has accepted authorisation.
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 void CSyncMLDlgNotifier::RunL()
       
   315     {
       
   316     FLOG(_L("[SmlNotif]\t CSyncMLDlgNotifier::RunL()"));
       
   317     const TChar KDRSeparator('-');
       
   318     const TChar KChoiceItemSeparator(',');
       
   319     TInt result( KErrNone );
       
   320  		EndKeyPress = EFalse;
       
   321     // Turn lights on and deactivate apps -key
       
   322     //
       
   323     TurnLightsOn();  
       
   324 
       
   325     switch( iNoteType )
       
   326         {
       
   327         case ESyncMLInfoNote:
       
   328             {
       
   329             CAknInformationNote* infoNote = new (ELeave) CAknInformationNote;
       
   330             TInt maxtime = iMaxTime * KSyncMLuSecsInSec;
       
   331             if ( maxtime < 0  )
       
   332                 {
       
   333                 maxtime = 0;
       
   334                 }
       
   335             infoNote->SetTimeout( (CAknNoteDialog::TTimeout) maxtime );
       
   336             result = infoNote->ExecuteLD( iServerMsg );
       
   337             if ( result == KErrNone )
       
   338                 {
       
   339                 result = EAknSoftkeyOk;
       
   340                 }
       
   341             break;
       
   342             }
       
   343         case ESyncMLErrorNote:
       
   344             {
       
   345             CAknErrorNote* errNote = new (ELeave) CAknErrorNote;
       
   346             TInt maxtime = iMaxTime * KSyncMLuSecsInSec;
       
   347             if ( maxtime < 0  )
       
   348                 {
       
   349                 maxtime = 0;
       
   350                 }
       
   351             errNote->SetTimeout( (CAknNoteDialog::TTimeout) maxtime );
       
   352             result = errNote->ExecuteLD( iServerMsg );
       
   353             if ( result == KErrNone )
       
   354                 {
       
   355                 result = EAknSoftkeyOk;
       
   356                 };
       
   357             break;
       
   358             }
       
   359         case ESyncMLOkQuery:
       
   360             {
       
   361             FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() Ok/Empty query shown") );
       
   362             
       
   363             CSyncMLTimedMessageQuery* dlg =
       
   364                 CSyncMLTimedMessageQuery::NewL( iServerMsg, iMaxTime );
       
   365             
       
   366             // Pushed dialog is popped inside RunLD
       
   367             dlg->PrepareLC( R_SML_MESSAGE_QUERY );
       
   368             	dlg->ButtonGroupContainer().SetCommandSetL( 
       
   369                                         R_AVKON_SOFTKEYS_OK_EMPTY__OK );
       
   370             EnableSyncProgressNoteL( EFalse );
       
   371             result = dlg->RunLD();
       
   372             dlg = NULL;
       
   373             EnableSyncProgressNoteL( ETrue );
       
   374             break;
       
   375             }
       
   376             
       
   377         case ESyncMLQueryNote:  // This enumeration will be removed.
       
   378         case ESyncMLYesNoQuery:
       
   379             {
       
   380             FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() Yes/No query shown") );
       
   381             CSyncMLTimedMessageQuery* dlg = 
       
   382             CSyncMLTimedMessageQuery::NewL( iServerMsg, iMaxTime );
       
   383             // Pushed dialog is popped inside RunLD
       
   384             dlg->PrepareLC( R_SML_MESSAGE_QUERY );
       
   385             dlg->ButtonGroupContainer().SetCommandSetL( 
       
   386                     R_AVKON_SOFTKEYS_YES_NO__YES );
       
   387             EnableSyncProgressNoteL( EFalse );
       
   388             result = dlg->RunLD();
       
   389             dlg = NULL;
       
   390             EnableSyncProgressNoteL( ETrue );
       
   391             break;
       
   392             }
       
   393         case ESyncMLSingleChoiceQuery:
       
   394             {
       
   395 			FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() single choice list query") );             
       
   396             if ( iNumberOfItems > 0 )
       
   397                 {
       
   398                 SuppressAppSwitching( ETrue );
       
   399                 EnableSyncProgressNoteL( EFalse );
       
   400                 CEikFormattedCellListBox* listBox = new ( ELeave )
       
   401                 CAknSinglePopupMenuStyleListBox;
       
   402                 CleanupStack::PushL( listBox );
       
   403                 CSyncMLAknPopUpList* popupList = 
       
   404                 CSyncMLAknPopUpList::NewL( (CAknSingleHeadingPopupMenuStyleListBox*)listBox, 
       
   405                             R_AVKON_SOFTKEYS_OK_CANCEL__OK,
       
   406                             AknPopupLayouts::EMenuWindow,iMaxTime );
       
   407                 CleanupStack::PushL( popupList );
       
   408                 listBox->ConstructL( popupList, ( EAknListBoxSelectionList | EAknListBoxLoopScrolling ) );
       
   409                 listBox->Model()->SetItemTextArray( iListItems );
       
   410                 listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   411                 listBox->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue );
       
   412                 listBox->HandleItemAdditionL();
       
   413                 listBox->CreateScrollBarFrameL( ETrue );
       
   414                 listBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   415                         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   416                 TInt defaultindex = 0;
       
   417                 TLex drval(iDR);                    
       
   418                 drval.Val(defaultindex);
       
   419                 if(defaultindex > 0)
       
   420                     defaultindex--;
       
   421                 else
       
   422                     defaultindex = 0;
       
   423                 listBox->SetCurrentItemIndex(defaultindex);                                   
       
   424                 popupList->SetTitleL( iServerMsg );
       
   425                 CleanupStack::Pop( popupList );
       
   426 				FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() single choice list query shown") ); 
       
   427                 result = popupList->ExecuteLD();
       
   428 				FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() single choice list query dismissed") ); 
       
   429                 popupList = NULL;
       
   430                 if ( result )
       
   431                     {
       
   432                     reply.irettext.Num(listBox->CurrentItemIndex()+1);
       
   433                     }
       
   434                 reply.iretval = result;                
       
   435                 CleanupStack::PopAndDestroy( listBox );  // Destroys also the icon array
       
   436                 EnableSyncProgressNoteL( ETrue );
       
   437                 SuppressAppSwitching( EFalse );
       
   438                 }
       
   439 				else
       
   440 				{
       
   441 				reply.iretval = result;				
       
   442 				}
       
   443 				TSyncMLDlgNotifReturnParamsPckg pkg(reply);
       
   444                 iMessage.WriteL(iReplySlot,pkg);
       
   445             break;
       
   446             }
       
   447         case ESyncMLMultiChoiceQuery:
       
   448             {           
       
   449             if ( iNumberOfItems > 0 )
       
   450                 {
       
   451 				SuppressAppSwitching( ETrue );
       
   452                 EnableSyncProgressNoteL( EFalse );
       
   453                 // create listbox
       
   454                 // list item string format: "0\tLabel" where 0 is an index to icon array
       
   455                 CEikFormattedCellListBox* listBox =
       
   456                 new ( ELeave ) CAknSingleGraphicPopupMenuStyleListBox;
       
   457                 CleanupStack::PushL( listBox );
       
   458                 // create popup
       
   459                 CSyncMLAknPopUpList* popup = 
       
   460                 CSyncMLAknPopUpList::NewL((CAknSingleHeadingPopupMenuStyleListBox*) listBox,
       
   461                             R_AVKON_SOFTKEYS_OK_CANCEL__MARK ,
       
   462                             AknPopupLayouts::EMenuWindow,iMaxTime);
       
   463                 CleanupStack::PushL( popup );
       
   464                 popup->SetTitleL(iServerMsg );
       
   465 #ifdef RD_SCALABLE_UI_V2
       
   466                 if( AknLayoutUtils::PenEnabled() )
       
   467                     {
       
   468                     listBox->ConstructL( popup, EAknListBoxStylusMultiselectionList );
       
   469                     }
       
   470                 else
       
   471                     {
       
   472                     listBox->ConstructL( popup, EAknListBoxMultiselectionList );
       
   473                     }
       
   474 #else
       
   475                 listBox->ConstructL( popup, EAknListBoxMultiselectionList );
       
   476 #endif
       
   477                 listBox->CreateScrollBarFrameL(ETrue);
       
   478                 listBox->ScrollBarFrame()->
       
   479                 SetScrollBarVisibilityL(
       
   480                         CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );                
       
   481                 SetIconsL(listBox);
       
   482                 listBox->Model()->SetItemTextArray( iListItems );
       
   483                 listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
       
   484                 listBox->SetCurrentItemIndex(iDefindex);  
       
   485                 listBox->ItemDrawer()->FormattedCellData()->EnableMarqueeL( ETrue );                
       
   486                 listBox->HandleItemAdditionL();
       
   487                 // set all items as selected
       
   488                 TInt count( listBox->Model()->NumberOfItems() );                
       
   489                 TBuf<20> drcheck;
       
   490                 for( TInt index( 0 ); index < count; index++ )
       
   491                     {
       
   492                     drcheck.Zero();
       
   493                     drcheck.Append(KDRSeparator);
       
   494                     drcheck.AppendNum(index+1);
       
   495                     drcheck.Append(KDRSeparator);
       
   496                     if(iDR.Find(drcheck) >= KErrNone)
       
   497                         {
       
   498                         listBox->View()->SelectItemL( index );
       
   499                         }                                                            
       
   500                     }              
       
   501                 // launch popup
       
   502                 result = popup->ExecuteLD();
       
   503                 // No leaving functions allowed between executeLD and CleanupStack::Pop().
       
   504                 CleanupStack::Pop( popup );                
       
   505                 /// Own: ListBox selection array
       
   506                 const CArrayFix<TInt>* iSelectionArray;                
       
   507                 if( result )
       
   508                     {
       
   509                     iSelectionArray = listBox->View()->SelectionIndexes();
       
   510                     TBuf<20> temp;
       
   511                     TBuf<KSyncMLMaxAlertResultLength> temp1;
       
   512                     for(TInt i=iSelectionArray->Count()-1;i>=0;i--)
       
   513                         {
       
   514                         temp.Num(iSelectionArray->At(i)+1);
       
   515                         if((temp1.Length() + temp.Length()) < KSyncMLMaxAlertResultLength )
       
   516                             {
       
   517                             temp1.Append(temp);
       
   518                             temp1.Append(KDRSeparator);                            
       
   519                             }
       
   520                         else{
       
   521                             break;
       
   522                             }
       
   523                         } 
       
   524                     reply.irettext.Append(temp1);                    
       
   525                     // delete iSelectionArray; this deletion taken care in ~CEIKLISTBOX (eiklbx.cpp)
       
   526                     }
       
   527                 reply.iretval = result;
       
   528                 CleanupStack::PopAndDestroy(); // listBox                
       
   529 				EnableSyncProgressNoteL( ETrue );
       
   530                 SuppressAppSwitching( EFalse );					
       
   531                 }
       
   532 				else
       
   533 				{
       
   534 				reply.iretval = result;				
       
   535 				}
       
   536 				TSyncMLDlgNotifReturnParamsPckg pkg(reply);
       
   537                 iMessage.WriteL(iReplySlot,pkg);                                          
       
   538             break;
       
   539             }
       
   540         case ESyncMLInputQuery: //For 1102 alert
       
   541             {   
       
   542             FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() Input query shown") ); 
       
   543             // For input text server alert
       
   544               
       
   545             SuppressAppSwitching( ETrue );
       
   546 
       
   547              switch( iIT )   
       
   548              {
       
   549              	case ESyncMLInputTypeAlphaNumeric: //Alphanumeric Input type
       
   550              	    {
       
   551              	     
       
   552           				InputTypeAlphaNumericL(result);
       
   553              	     break;
       
   554              	    }
       
   555              	    	
       
   556              	case ESyncMLInputTypeNumeric: //Numeric Input type
       
   557              		{
       
   558              		InputTypeNumericL(result);
       
   559              		break;
       
   560              		}	
       
   561              		
       
   562              	case ESyncMLInputTypeDate: //Date Input type
       
   563              	    {
       
   564 								InputTypeDateL(result);
       
   565              	    break;
       
   566              	    }		
       
   567              			
       
   568              	case ESyncMLInputTypeTime: //Time Input type
       
   569              		{//create TTime from TBuf iDR
       
   570              		//hhmmss
       
   571 								InputTypeTimeL(result);
       
   572              		break;	
       
   573              		}
       
   574              		
       
   575              	case ESyncMLInputTypePhoneNumber: //Phone Number Input type
       
   576              		{
       
   577 								InputTypePhoneNumberL(result);
       
   578              		break;
       
   579              		}	
       
   580              		
       
   581              	case ESyncMLInputTypeIPAddress: //IP Address Input type
       
   582              	    {			
       
   583              	    	TBuf<KSyncMLMaxDefaultResponseMsgLength> InputText(iDR);
       
   584                 	TInetAddr destAddr;
       
   585 					destAddr.Input(iDR);					
       
   586 					EnableSyncProgressNoteL( EFalse );//coment out when using test app
       
   587 					CAknIpAddressQueryDialog* dlg = CAknIpAddressQueryDialog::NewL (destAddr); 
       
   588 					CleanupStack::PushL(dlg);
       
   589 					dlg->SetPromptL(iServerMsg);
       
   590 					CleanupStack::Pop(); //dlg
       
   591 					result=dlg->ExecuteLD( R_NEWALERT_IP_QUERY );
       
   592 					dlg=NULL;
       
   593 					destAddr.Output(InputText);				
       
   594 					reply.iretval = result;
       
   595 					reply.irettext=InputText;					
       
   596              		EnableSyncProgressNoteL( ETrue );//coment out when using test app	
       
   597              	    break;
       
   598              	    }
       
   599              			
       
   600                 default: 
       
   601                     {
       
   602                     	User::Leave( KErrArgument );
       
   603                     }			
       
   604              }
       
   605              SuppressAppSwitching( EFalse );
       
   606              TSyncMLDlgNotifReturnParamsPckg pkg(reply);
       
   607              iMessage.WriteL(iReplySlot,pkg);
       
   608              break;
       
   609             }
       
   610 //#endif
       
   611             
       
   612         default: // Unhandled note type
       
   613             {
       
   614             FLOG(_L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() Note type not handled"));
       
   615             User::Leave( KErrArgument );
       
   616             break;
       
   617             }
       
   618         }
       
   619     // Complete message, if not cancelled
       
   620     if ( iNeedToCompleteMessage )
       
   621         {
       
   622 		 FLOG(_L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() completing the message"));
       
   623         switch ( result )
       
   624             {
       
   625             case EAknSoftkeyYes:
       
   626             case EAknSoftkeyOk:
       
   627             case ETrue:    
       
   628                 {
       
   629 				FLOG(_L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() completing the message with KErrNone"));
       
   630                 iMessage.Complete( KErrNone );
       
   631                 break;
       
   632                 }
       
   633             case EAknSoftkeyCancel:
       
   634             case EAknSoftkeyNo:
       
   635             case KErrNone:  // Pressing "Cancel" or "No" may return zero
       
   636                 {
       
   637 				FLOG(_L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() completing the message with KErrCancel"));
       
   638                 iMessage.Complete( KErrCancel );
       
   639                 break;
       
   640                 }
       
   641             default:
       
   642                 {
       
   643                 iMessage.Complete( result );
       
   644                 break;
       
   645                 }
       
   646             }
       
   647         }
       
   648 
       
   649     iNeedToCompleteMessage = EFalse;
       
   650     iReplySlot = NULL;
       
   651 
       
   652     iServerMsg = KNullDesC;
       
   653 
       
   654     FLOG(_L("[SmlNotif]\t CSyncMLDlgNotifier::RunL() completed"));
       
   655     }
       
   656 
       
   657 // -----------------------------------------------------------------------------
       
   658 // CSyncMLDlgNotifier::CSyncMLDlgNotifier
       
   659 // C++ default constructor can NOT contain any code, that
       
   660 // might leave.
       
   661 // -----------------------------------------------------------------------------
       
   662 //
       
   663 CSyncMLDlgNotifier::CSyncMLDlgNotifier( CSyncMLAppLaunchNotifier* aAppLaunchNotif )
       
   664     : iAppLaunchNotif( aAppLaunchNotif ),iListItems(NULL),iDefindex(0)
       
   665     {
       
   666     }
       
   667 
       
   668 // -----------------------------------------------------------------------------
       
   669 // CSyncMLDlgNotifier::InputTypeAlphaNumericL(TInt & result) 
       
   670 // Process if input type is alphanumeric
       
   671 // -----------------------------------------------------------------------------
       
   672 //    
       
   673 void CSyncMLDlgNotifier::InputTypeAlphaNumericL(TInt & result)    
       
   674 {
       
   675 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypeAlphaNumericL() startedd") );
       
   676 		TBuf<KSyncMLMaxDefaultResponseMsgLength> InputText(iDR);
       
   677 		if( iET == ESyncMLEchoTypePassword ) //for pwd ET
       
   678     {
       
   679     		CSyncMLTimedInputTextQuery* dlg = CSyncMLTimedInputTextQuery::NewL( InputText, iServerMsg, EndKeyPress, iMaxTime);
       
   680 				dlg->SetMaxLength( iMaxlen );
       
   681 				EnableSyncProgressNoteL( EFalse );//coment out when using test app
       
   682 				result = dlg->ExecuteLD( R_NEWALERT_DATA_PWD_QUERY );
       
   683 				if(EndKeyPress)
       
   684 				{
       
   685 					 result = KErrAbort;	
       
   686 				}
       
   687 				reply.iretval = result;
       
   688 				reply.irettext=InputText;
       
   689 				dlg=NULL;
       
   690 				EnableSyncProgressNoteL( ETrue );//coment out when using test app
       
   691     }
       
   692     else
       
   693     {
       
   694         CSyncMLTimedInputTextQuery* dlg = CSyncMLTimedInputTextQuery::NewL( InputText,iServerMsg, EndKeyPress, iMaxTime);
       
   695 				dlg->SetMaxLength( iMaxlen );
       
   696 				EnableSyncProgressNoteL( EFalse );//coment out when using test app
       
   697 				result = dlg->ExecuteLD( R_INPUTTEXT_DATA_QUERY );
       
   698 				if(EndKeyPress )
       
   699 				{					 					 
       
   700 					 result = KErrAbort;
       
   701         }
       
   702 				reply.iretval = result;
       
   703 				reply.irettext=InputText;
       
   704 				dlg=NULL;
       
   705 				EnableSyncProgressNoteL( ETrue );//coment out when using test app		
       
   706     }
       
   707     FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypeAlphaNumericL() completed") );
       
   708 }
       
   709 
       
   710 // -----------------------------------------------------------------------------
       
   711 // CSyncMLDlgNotifier::InputTypeNumericL(TInt & result) 
       
   712 // Process if input type is numeric
       
   713 // -----------------------------------------------------------------------------
       
   714 //    
       
   715 void CSyncMLDlgNotifier::InputTypeNumericL(TInt & result)
       
   716 {
       
   717 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypeNumericL() started") ); 
       
   718 		TBuf<KSyncMLMaxDefaultResponseMsgLength> InputText(iDR);
       
   719 	  TReal value = 0;
       
   720     TLex data(iDR);
       
   721     if( iDR.Length() != 0 )
       
   722     {
       
   723     		data.Val(value);
       
   724     }
       
   725     if ( iET == ESyncMLEchoTypePassword )
       
   726     {
       
   727     		TChar ch = '0';
       
   728         for (TInt i=0;i<iDR.Length();i++)
       
   729         {
       
   730         		ch=iDR[i];
       
   731             if( ch!='+' || ch!='-' || ch!='.' )
       
   732             {
       
   733             		if( !ch.IsDigit() )
       
   734              	  {
       
   735              	  		InputText.Zero();
       
   736              	    	break;	
       
   737              	  }
       
   738             }
       
   739         }
       
   740         CSyncMLTimedInputTextQuery* dlg = CSyncMLTimedInputTextQuery::NewL( InputText, iServerMsg, EndKeyPress, iMaxTime);
       
   741 				dlg->SetMaxLength( iMaxlen );
       
   742 				EnableSyncProgressNoteL( EFalse );//coment out when using test app
       
   743 				result = dlg->ExecuteLD( R_NEWALERT_NUMERIC_PWD_QUERY );
       
   744 				dlg = NULL;
       
   745 				if(EndKeyPress)
       
   746 				{
       
   747 					 result = KErrAbort;	
       
   748 				}
       
   749 		}
       
   750     else
       
   751     {
       
   752     		CSyncMLTimedNumberQueryDialog* dlg =
       
   753 				CSyncMLTimedNumberQueryDialog::NewL( value, iServerMsg, EndKeyPress,  iMaxTime);
       
   754 				    
       
   755 				EnableSyncProgressNoteL( EFalse );//coment out when using test app
       
   756 				result = dlg->ExecuteLD( R_NEWALERT_NUMBER_QUERY );
       
   757 				dlg = NULL;
       
   758 				if(EndKeyPress)
       
   759 				{
       
   760 					result = KErrAbort;	
       
   761 				}
       
   762 				reply.iretval = result;
       
   763 				data.Val( value );
       
   764 				_LIT(KSendFormat ,"%10.10f");
       
   765 				InputText.Format ( KSendFormat, value );
       
   766 		}
       
   767 		reply.iretval = result;
       
   768 		reply.irettext= InputText;
       
   769 								 
       
   770 		EnableSyncProgressNoteL( ETrue );//coment out when using test app  
       
   771 		
       
   772 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypeNumericL() completed") );    		
       
   773 }
       
   774 
       
   775 // -----------------------------------------------------------------------------
       
   776 // CSyncMLDlgNotifier::InputTypeDateL(TInt & result) 
       
   777 // Process if input type is Date
       
   778 // -----------------------------------------------------------------------------
       
   779 //  
       
   780 void CSyncMLDlgNotifier::InputTypeDateL(TInt & result)
       
   781 {
       
   782 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypeDateL() started") ); 
       
   783 		TBuf<KSyncMLMaxDefaultResponseMsgLength> InputText(iDR);
       
   784 	  TTime date(_L("00010101:"));
       
   785     TInt BadData = 1;
       
   786     TChar ch = '0';
       
   787     for (TInt i=0;i<iDR.Length();i++)
       
   788     {
       
   789     		ch=iDR[i];
       
   790         if(!ch.IsDigit())
       
   791         {
       
   792         		BadData=0;
       
   793             break;
       
   794         }
       
   795     }
       
   796     if( iDR.Length() != 0 && iDR.Length()==8 && BadData )
       
   797     {
       
   798     		//iDR.Append(':');
       
   799         TBuf <9> revdate;
       
   800 				revdate.Append(iDR.Mid(4,4));
       
   801 				revdate.Append(iDR.Mid(2,2));
       
   802 				revdate.Append(iDR.Left(2));
       
   803 				revdate.Append(':');
       
   804         date.Set( revdate );
       
   805     }
       
   806 		CSyncMLTimedDateQuery* dlg = CSyncMLTimedDateQuery::NewL( date, iServerMsg,EndKeyPress ,  iMaxTime);
       
   807 		EnableSyncProgressNoteL( EFalse );//coment out when using test app
       
   808 		result = dlg->ExecuteLD(R_NEWALERT_DATE_QUERY); 
       
   809 					
       
   810 		if(EndKeyPress)
       
   811 		{
       
   812 				result = KErrAbort;//0-keypress 1-ok,0-cancel,-1=end key	
       
   813 		}
       
   814 		reply.iretval = result;
       
   815 		_LIT(KDateFormat,"%F%D%M%Y");
       
   816 		TBuf <20> StringDate;					
       
   817 		date.FormatL(StringDate, KDateFormat);
       
   818 		reply.irettext=StringDate;
       
   819 		dlg = NULL;
       
   820 		EnableSyncProgressNoteL( ETrue );//comented out for emulator testing
       
   821 		
       
   822 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypeDateL() completed") );            
       
   823 }		
       
   824 
       
   825 // -----------------------------------------------------------------------------
       
   826 // CSyncMLDlgNotifier::InputTypeTimeL(TInt & result) 
       
   827 // Process if input type is Time
       
   828 // -----------------------------------------------------------------------------
       
   829 //             	    
       
   830 void CSyncMLDlgNotifier::InputTypeTimeL(TInt & result)
       
   831 {            	
       
   832 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypeTimeL() started") );
       
   833 		TBuf<KSyncMLMaxDefaultResponseMsgLength> InputText(iDR);
       
   834     //create TTime from TBuf iDR
       
   835     //hhmmss
       
   836     TTime IpTime(_L("120000."));
       
   837     TInt BadData=1;
       
   838     TChar ch= '0';
       
   839     for (TInt i=0;i<iDR.Length();i++)
       
   840     {
       
   841     		ch=iDR[i];
       
   842         if(!ch.IsDigit())
       
   843         {
       
   844         		BadData=0;
       
   845             break;
       
   846         }
       
   847     }
       
   848     if( iDR.Length() != 0 && iDR.Length() == 6 && BadData )
       
   849     {
       
   850     		iDR.Append('.');
       
   851         IpTime.Set( iDR );
       
   852     }	             	
       
   853 		CSyncMLTimedDateQuery* dlg =
       
   854 		CSyncMLTimedDateQuery::NewL( IpTime, iServerMsg, EndKeyPress, iMaxTime);					
       
   855 		EnableSyncProgressNoteL( EFalse );//comented out for emulator testing
       
   856 		result = dlg->ExecuteLD(R_NEWALERT_TIME_QUERY);					
       
   857 		if(EndKeyPress)
       
   858 		{
       
   859 				result = KErrAbort;//0-keypress 1-ok,0-cancel,-1=end key	
       
   860 		}
       
   861 		reply.iretval = result;				
       
   862 		_LIT(KTimeFormat,"%F%H%T%S");
       
   863 		TBuf <20> StringTime;				
       
   864 		IpTime.FormatL(StringTime, KTimeFormat);
       
   865 		reply.irettext=StringTime;				
       
   866 		dlg = NULL;  
       
   867 		EnableSyncProgressNoteL( ETrue );//coment out when using test app
       
   868 		
       
   869 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypeTimeL() completed") );
       
   870 }
       
   871 
       
   872 // -----------------------------------------------------------------------------
       
   873 // CSyncMLDlgNotifier::InputTypePhoneNumberL(TInt & result) 
       
   874 // Process if input type is Phone number
       
   875 // -----------------------------------------------------------------------------
       
   876 //  
       
   877 void CSyncMLDlgNotifier::InputTypePhoneNumberL(TInt & result)
       
   878 {
       
   879 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypePhoneNumberL() started") );
       
   880 		TBuf<KSyncMLMaxDefaultResponseMsgLength> InputText(iDR);
       
   881 		EnableSyncProgressNoteL( EFalse );//comented out for emulator testing
       
   882 		TInt ret=0;
       
   883 		for(TInt i=0;i<iDR.Length();i++)
       
   884 		{
       
   885 				if(iDR[i] == 'p' || iDR[i] == 'w' || iDR[i] == '+' || iDR[i] == '*' ||iDR[i] == '#')
       
   886 				{
       
   887 						if( iDR[i] == '+' && i > 0)
       
   888 					 	{
       
   889 					 			ret = -1;
       
   890 					 			break;
       
   891 					 	}
       
   892 					 	else
       
   893 					 {
       
   894 							continue;
       
   895 					 }
       
   896 				}
       
   897 				else
       
   898 				{
       
   899 						TChar ch=iDR[i] ;
       
   900 			 			if(!ch.IsDigit())
       
   901 			 			{
       
   902 			  				ret = -1;
       
   903 			 					break;	
       
   904 			 			}
       
   905 				}
       
   906 		}
       
   907 				
       
   908 		if(ret == -1)
       
   909 		InputText.Zero();
       
   910 		CSyncMLTimedInputTextQuery* dlg = CSyncMLTimedInputTextQuery::NewL(InputText,iServerMsg, EndKeyPress, iMaxTime);					
       
   911 		dlg->SetMaxLength( iMaxlen );					 
       
   912 		result = dlg->ExecuteLD( R_NEWALERT_PHONE_QUERY );
       
   913 		if(EndKeyPress )
       
   914 		{
       
   915 					result = KErrAbort;
       
   916 		}
       
   917 		reply.iretval = result;					
       
   918 		reply.irettext=InputText;
       
   919 		dlg=NULL;					
       
   920 		EnableSyncProgressNoteL( ETrue );//coment out when using test app 
       
   921 		FLOG( _L("[SmlNotif]\t CSyncMLDlgNotifier::InputTypePhoneNumberL() completed") );
       
   922 }
       
   923 
       
   924 // -----------------------------------------------------------------------------
       
   925 // CSyncMLDlgNotifier::SetIconsL() 
       
   926 // Sets the icons to multiselection/markable list
       
   927 // -----------------------------------------------------------------------------
       
   928 void CSyncMLDlgNotifier::SetIconsL(CEikFormattedCellListBox* aListBox)
       
   929     {        
       
   930     CAknIconArray* iconArray = new( ELeave ) CAknIconArray( 1 );
       
   931         CleanupStack::PushL( iconArray );
       
   932         CFbsBitmap* checkboxOnBitmap = NULL;
       
   933         CFbsBitmap* checkboxOnBitmapMask = NULL;
       
   934         CFbsBitmap* checkboxOffBitmap = NULL;
       
   935         CFbsBitmap* checkboxOffBitmapMask = NULL;
       
   936 
       
   937         //CListItemDrawer is using this logical color as default for its marked icons
       
   938         TRgb defaultColor;
       
   939         defaultColor = iEikEnv->Color( EColorControlText );
       
   940 
       
   941         // Create 'ON' checkbox icon
       
   942         AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(),
       
   943                     KAknsIIDQgnIndiCheckboxOn,
       
   944                     KAknsIIDQsnIconColors,
       
   945                     EAknsCIQsnIconColorsCG13,
       
   946                     checkboxOnBitmap,
       
   947                     checkboxOnBitmapMask,
       
   948                     KAvkonBitmapFile,
       
   949                     EMbmAvkonQgn_indi_checkbox_on,
       
   950                     EMbmAvkonQgn_indi_checkbox_on_mask,
       
   951                     defaultColor
       
   952                     );
       
   953 
       
   954         CGulIcon* checkboxOnIcon = CGulIcon::NewL( checkboxOnBitmap, checkboxOnBitmapMask );
       
   955         // cleanup checkboxOnBitmap, checkboxOnBitmapMask
       
   956         CleanupStack::Pop( checkboxOnBitmapMask );
       
   957         CleanupStack::Pop( checkboxOnBitmap ); 
       
   958 
       
   959         CleanupStack::PushL( checkboxOnIcon );
       
   960         iconArray->AppendL( checkboxOnIcon );
       
   961 
       
   962         // Create 'OFF' checkbox icon
       
   963         AknsUtils::CreateColorIconLC( AknsUtils::SkinInstance(),
       
   964                     KAknsIIDQgnIndiCheckboxOff,
       
   965                     KAknsIIDQsnIconColors,
       
   966                     EAknsCIQsnIconColorsCG13,
       
   967                     checkboxOffBitmap,
       
   968                     checkboxOffBitmapMask,
       
   969                     KAvkonBitmapFile,
       
   970                     EMbmAvkonQgn_indi_checkbox_off,
       
   971                     EMbmAvkonQgn_indi_checkbox_off_mask,
       
   972                     defaultColor
       
   973                     );
       
   974 
       
   975         CGulIcon* checkboxOffIcon = CGulIcon::NewL( checkboxOffBitmap, checkboxOffBitmapMask );
       
   976         // cleanup checkboxOffBitmap, checkboxOffBitmapMask
       
   977         CleanupStack::Pop( checkboxOffBitmapMask ); //WILL BE DELETED BY CGUIICON
       
   978         CleanupStack::Pop( checkboxOffBitmap ); //WILL BE DELETED BY CGUIICON
       
   979         
       
   980 
       
   981         CleanupStack::PushL( checkboxOffIcon );
       
   982         iconArray->AppendL( checkboxOffIcon );
       
   983         aListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray ); // changes ownership
       
   984         
       
   985         // cleanup checkboxOnIcon, checkboxOffIcon, iconArray
       
   986         CleanupStack::Pop( checkboxOffIcon ); //WILL BE DELETED BY CGUIICON
       
   987         CleanupStack::Pop( checkboxOnIcon ); //WILL BE DELETED BY CGUIICON
       
   988         CleanupStack::Pop( iconArray );//WILL BE DELETED BY CFormattedCellListBoxData::
       
   989 
       
   990     }
       
   991 
       
   992 //  End of File