meetingrequest/mrcasplugin/src/cesmrcaspluginuilauncher.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: This file implements class CESMRCasPluginUiLauncher.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include "cesmrcaspluginuilauncher.h"
       
    21 #include "mesmrcaspluginuilauncherobserver.h"
       
    22 #include "esmrinternaluid.h"
       
    23 // <cmail> Profiler removed. </cmail>
       
    24 
       
    25 #include <badesca.h>
       
    26 //<cmail>
       
    27 #include "tfsccontactactionpluginparams.h"
       
    28 #include <MVPbkStoreContact.h>
       
    29 #include <CalenInterimUtils2.h>
       
    30 #include <cmrmailboxutils.h>
       
    31 #include <calsession.h>
       
    32 #include <calentry.h>
       
    33 #include <CAgnEntryUi.h>
       
    34 #include <caluser.h>
       
    35 #include "mfscactionutils.h"
       
    36 //</cmail>
       
    37 #include <aknPopup.h>
       
    38 #include <aknlists.h>
       
    39 #include <utf.h>
       
    40 #include <ecom/ecom.h>
       
    41 #include "esmrcommands.h"
       
    42 #include <esmrcasplugindata.rsg>
       
    43 #include <StringLoader.h>
       
    44 #include <aknnotewrappers.h>
       
    45 
       
    46 
       
    47 // Unnamed namespace for local definitions and functions
       
    48 namespace { // codescanner::namespace
       
    49 
       
    50 #ifdef _DEBUG
       
    51     enum TPanic
       
    52         {
       
    53         EPanicIndexOOB = 1
       
    54         };
       
    55 
       
    56     void Panic( TPanic aPanic )
       
    57         {
       
    58         _LIT( KCntxt, "CESMRCasPluginUiLauncher" );
       
    59         User::Panic( KCntxt(), aPanic );
       
    60         }
       
    61 #endif // _DEBUG
       
    62 
       
    63 const TUint KMRSequenceNo( 0 );
       
    64 const TInt KOneHour( 1 );
       
    65 
       
    66 // Constants for rounding up MR start time
       
    67 const TInt KMinuteRoundToHourStart( 46 );
       
    68 const TInt KMinuteRoundToHourEnd( 15 );
       
    69 
       
    70 const TInt KHourMinutes( 0 );
       
    71 const TInt KHalfHourMinutes( 30 );
       
    72 
       
    73 /**
       
    74  * Prompts user to select default mailbox.
       
    75  */
       
    76 TInt PromptForDefaultMailboxL(
       
    77         RArray<CMRMailboxUtils::TMailboxInfo>& aMailBoxes )
       
    78     {
       
    79     FUNC_LOG;
       
    80     TInt selected( KErrCancel );
       
    81 
       
    82     TInt mbCount = aMailBoxes.Count();
       
    83     if( mbCount > 0)
       
    84         {
       
    85         CAknSinglePopupMenuStyleListBox* list =
       
    86             new (ELeave) CAknSinglePopupMenuStyleListBox;
       
    87         CleanupStack::PushL(list);
       
    88 
       
    89         CAknPopupList* popupList = CAknPopupList::NewL(
       
    90                                             list,
       
    91                                             R_AVKON_SOFTKEYS_OK_CANCEL);
       
    92         CleanupStack::PushL(popupList);
       
    93 
       
    94         list->ConstructL(popupList, CEikListBox::ELeftDownInViewRect);
       
    95         list->CreateScrollBarFrameL(ETrue);
       
    96         list->ScrollBarFrame()->SetScrollBarVisibilityL(
       
    97             CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
    98 
       
    99         CEikonEnv* eikEnv = CEikonEnv::Static();// codescanner::eikonenvstatic
       
   100 
       
   101         CDesCArrayFlat* items = new (ELeave)CDesCArrayFlat(mbCount);
       
   102         CleanupStack::PushL(items);
       
   103         for(TInt i=0; i<mbCount; ++i)
       
   104             {
       
   105             items->AppendL( aMailBoxes[i].iName );
       
   106             }
       
   107         CleanupStack::Pop(items);
       
   108         CTextListBoxModel* model = list->Model();
       
   109 
       
   110         //Pass ownersip of items to model
       
   111         model->SetItemTextArray(items);
       
   112 
       
   113         HBufC* title = KNullDesC().AllocLC();
       
   114         popupList->SetTitleL(*title);
       
   115         CleanupStack::PopAndDestroy(title);
       
   116 
       
   117         TBool accepted = popupList->ExecuteLD();
       
   118         CleanupStack::Pop( popupList );
       
   119 
       
   120         if(accepted)
       
   121             {
       
   122             selected = list->CurrentItemIndex();
       
   123             }
       
   124         else
       
   125             {
       
   126             selected = KErrCancel;
       
   127             }
       
   128 
       
   129         CleanupStack::PopAndDestroy( list );
       
   130         }
       
   131     else
       
   132         {
       
   133         //No mailboxes defined.  Could prompt user to define one here.
       
   134         selected = KErrCancel;
       
   135         }
       
   136 
       
   137     return selected;
       
   138     }
       
   139 
       
   140 /**
       
   141  * Fetches the supported mailboxes.
       
   142  * @param aMBUtils utils class
       
   143  * @param aMailBoxes to test
       
   144  */
       
   145 void SupportedMailboxesL(
       
   146         CMRMailboxUtils& aMBUtils,
       
   147         RArray<CMRMailboxUtils::TMailboxInfo>& aMailBoxes )
       
   148     {
       
   149     FUNC_LOG;
       
   150     aMBUtils.ListMailBoxesL( aMailBoxes );
       
   151 
       
   152     RImplInfoPtrArrayOwn implArray;
       
   153     CleanupClosePushL( implArray );
       
   154 
       
   155     //Get all MRViewers Implementation
       
   156     const TUid mrViewersIface = TUid::Uid(KMRViewersInterfaceUID);
       
   157     REComSession::ListImplementationsL(mrViewersIface, implArray );
       
   158     TInt mrviewerCount( implArray.Count() );
       
   159 
       
   160     TInt index(0);
       
   161     TInt mailboxCount( aMailBoxes.Count() );
       
   162     while ( index < mailboxCount )
       
   163          {
       
   164          TBool supported( EFalse );
       
   165 
       
   166          for ( TInt i(0); (i < mrviewerCount) && !supported; ++ i )
       
   167              {
       
   168              TBuf16<KMaxUidName> mbName;
       
   169              CnvUtfConverter::ConvertToUnicodeFromUtf8(
       
   170                      mbName,
       
   171                      implArray[i]->DataType() );
       
   172              __ASSERT_DEBUG( aMailBoxes.Count() > index, Panic( EPanicIndexOOB ) );
       
   173              if( aMailBoxes[index].iMtmUid.Name().CompareF(mbName) == 0)
       
   174                   {
       
   175                   supported = ETrue;
       
   176                  }
       
   177              }
       
   178 
       
   179          if ( supported )
       
   180              {
       
   181              index++;
       
   182              }
       
   183          else
       
   184              {
       
   185              aMailBoxes.Remove( index );
       
   186              mailboxCount = aMailBoxes.Count();
       
   187              }
       
   188          }
       
   189     CleanupStack::PopAndDestroy( &implArray );
       
   190     }
       
   191 
       
   192 }//namespace
       
   193 
       
   194 
       
   195 // ======== MEMBER FUNCTIONS ========
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CESMRCasPluginUiLauncher::CESMRCasPluginUiLauncher
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 inline CESMRCasPluginUiLauncher::CESMRCasPluginUiLauncher(
       
   202         CCalSession& aCalSession,
       
   203         CCalenInterimUtils2& aCalUtils,
       
   204         CMRMailboxUtils& aMBUtils,
       
   205         const TFscContactActionPluginParams& aParams,
       
   206         MESMRCasPluginUiLauncherObserver& aExecuteObserver )
       
   207 :   iInParams(
       
   208             TUid::Uid( KUidCalendarApplication ),
       
   209             aCalSession,
       
   210             MAgnEntryUi::ECreateNewEntry ),
       
   211     iCalSession( aCalSession ),
       
   212     iParams( aParams ),
       
   213     iCalUtils( aCalUtils ),
       
   214     iMBUtils( aMBUtils ),
       
   215     iExecuteObserver( aExecuteObserver )
       
   216     {
       
   217     FUNC_LOG;
       
   218     iInParams.iMsgSession = NULL;
       
   219     iInParams.iSpare = 0;
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // CESMRCasPluginUiLauncher::~CESMRCasPluginUiLauncher
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 CESMRCasPluginUiLauncher::~CESMRCasPluginUiLauncher()
       
   227     {
       
   228     FUNC_LOG;
       
   229     delete iMtmUid;
       
   230     delete iCalEntry;
       
   231     }
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // CESMRCasPluginUiLauncher::NewL
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 CESMRCasPluginUiLauncher* CESMRCasPluginUiLauncher::NewL(
       
   238         CCalSession& aCalSession,
       
   239         CCalenInterimUtils2& aCalUtils,
       
   240         CMRMailboxUtils& aMBUtils,
       
   241         const TFscContactActionPluginParams& aParams,
       
   242         MESMRCasPluginUiLauncherObserver& aExecuteObserver )
       
   243     {
       
   244     FUNC_LOG;
       
   245     CESMRCasPluginUiLauncher* self =
       
   246             new (ELeave ) CESMRCasPluginUiLauncher(
       
   247                     aCalSession,
       
   248                     aCalUtils,
       
   249                     aMBUtils,
       
   250                     aParams,
       
   251                     aExecuteObserver );
       
   252 
       
   253     CleanupStack::PushL( self );
       
   254     self->ConstructL();
       
   255     CleanupStack::Pop( self );
       
   256     return self;
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CESMRCasPluginUiLauncher::ConstructL
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 void CESMRCasPluginUiLauncher::ConstructL()
       
   264     {
       
   265     FUNC_LOG;
       
   266     //nothing to do here
       
   267     }
       
   268 
       
   269 
       
   270 // ---------------------------------------------------------------------------
       
   271 // CESMRCasPluginUiLauncher::LaunchMeetingRequestViewL
       
   272 // ---------------------------------------------------------------------------
       
   273 //
       
   274 void CESMRCasPluginUiLauncher::LaunchMeetingRequestViewL(
       
   275         const RPointerArray<CCalUser>& aAttendees  )
       
   276     {
       
   277     FUNC_LOG;
       
   278 
       
   279     HBufC8* guidBuf = iCalUtils.GlobalUidL();
       
   280     CleanupStack::PushL( guidBuf );
       
   281 
       
   282     delete iCalEntry; iCalEntry = NULL;
       
   283     iCalEntry = CCalEntry::NewL(
       
   284                     CCalEntry::EAppt,
       
   285                     guidBuf,
       
   286                     CCalEntry::EMethodRequest,
       
   287                     KMRSequenceNo );
       
   288 
       
   289     CleanupStack::Pop (guidBuf ); // Ownership is transferred
       
   290 
       
   291     AddOrganizerL();
       
   292     AddAttendeesL( aAttendees );
       
   293     SetStartAndEndTimeL();
       
   294 
       
   295     // Launch Entry UI
       
   296     RPointerArray<CCalEntry> entries;
       
   297     CleanupClosePushL ( entries );
       
   298     entries.AppendL( iCalEntry );
       
   299 
       
   300     MAgnEntryUi* editorsPlugin =  NULL;
       
   301     if ( iCalUtils.MRViewersEnabledL( ETrue ) )
       
   302         {
       
   303         //CAgnEntryUi resolves Meeting request viewer based on mtm uid
       
   304         TBuf8<KMaxUidName> mrMtm;
       
   305         CnvUtfConverter::ConvertFromUnicodeToUtf8(
       
   306                 mrMtm,
       
   307                 *iMtmUid );
       
   308         editorsPlugin = CAgnEntryUi::NewL( mrMtm );
       
   309         CleanupDeletePushL(editorsPlugin );
       
   310         }
       
   311     else
       
   312         {
       
   313         // MR is not supported --> Leave
       
   314         User::Leave (KErrNotSupported );
       
   315         }
       
   316 
       
   317     editorsPlugin->ExecuteViewL( entries, iInParams, iOutParams, *this );
       
   318 
       
   319     if (iOutParams.iAction == MAgnEntryUi::EMeetingSaved)
       
   320     	{
       
   321     	TInt res = R_FS_MR_NOTE_SAVED;
       
   322         HBufC* prompt = StringLoader::LoadLC( res, CEikonEnv::Static() );
       
   323         CAknConfirmationNote* dialog = new( ELeave )CAknConfirmationNote();
       
   324         dialog->ExecuteLD( *prompt );
       
   325         CleanupStack::PopAndDestroy( prompt );
       
   326     	}
       
   327 
       
   328     CleanupStack::PopAndDestroy( editorsPlugin );
       
   329     CleanupStack::PopAndDestroy( &entries );
       
   330 
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CESMRCasPluginUiLauncher::ProcessCommandL
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 void CESMRCasPluginUiLauncher::ProcessCommandL(
       
   338         TInt aCommandId )
       
   339     {
       
   340     FUNC_LOG;
       
   341     ProcessCommandWithResultL( aCommandId );
       
   342     }
       
   343 
       
   344 // ---------------------------------------------------------------------------
       
   345 // CESMRCasPluginUiLauncher::ProcessCommandWithResultL
       
   346 // ---------------------------------------------------------------------------
       
   347 //
       
   348 TInt CESMRCasPluginUiLauncher::ProcessCommandWithResultL(
       
   349         TInt aCommandId )
       
   350     {
       
   351     FUNC_LOG;
       
   352     if ( aCommandId == EESMRCmdEditorInitializationComplete )
       
   353         {
       
   354         iExecuteObserver.MREditorInitializationComplete();
       
   355         }
       
   356     return KErrNone;
       
   357     }
       
   358 
       
   359 // ---------------------------------------------------------------------------
       
   360 // CESMRCasPluginUiLauncher::IsCommandAvailable
       
   361 // ---------------------------------------------------------------------------
       
   362 //
       
   363 TBool CESMRCasPluginUiLauncher::IsCommandAvailable(
       
   364         TInt aCommandId )
       
   365     {
       
   366     FUNC_LOG;
       
   367     TBool retVal = EFalse;
       
   368     if ( aCommandId == EESMRCmdEditorInitializationComplete )
       
   369         {
       
   370         retVal = ETrue;
       
   371         }
       
   372     return retVal;
       
   373     }
       
   374 
       
   375 // ---------------------------------------------------------------------------
       
   376 // CESMRCasPluginUiLauncher::AddOrganizerL
       
   377 // ---------------------------------------------------------------------------
       
   378 //
       
   379 void CESMRCasPluginUiLauncher::AddOrganizerL()
       
   380     {
       
   381     FUNC_LOG;
       
   382     CMRMailboxUtils::TMailboxInfo defaultMailBox;
       
   383     
       
   384     RArray<CMRMailboxUtils::TMailboxInfo> mailBoxes;
       
   385 	CleanupClosePushL( mailBoxes );
       
   386 	SupportedMailboxesL( iMBUtils, mailBoxes );
       
   387         
       
   388     if ( KErrNone == iMBUtils.GetDefaultMRMailBoxL(defaultMailBox) )
       
   389 		{
       
   390 			for ( TInt i(0); i < mailBoxes.Count(); i++ )
       
   391 			{
       
   392 				if ( (defaultMailBox.iEntryId != mailBoxes[i].iEntryId) && 
       
   393 					( i == mailBoxes.Count() - 1 ) )
       
   394 				{
       
   395 				TInt selectedMailbox( PromptForDefaultMailboxL(mailBoxes) );
       
   396 				
       
   397 				if ( KErrCancel != selectedMailbox )
       
   398 					{
       
   399 					iMBUtils.SetDefaultMRMailBoxL( mailBoxes[selectedMailbox].iEntryId );
       
   400 					iMBUtils.GetDefaultMRMailBoxL(defaultMailBox);
       
   401 					}
       
   402 				
       
   403 				// This will leave if user cancelled the mailbox selection
       
   404 				User::LeaveIfError( selectedMailbox );
       
   405 				}
       
   406 			}
       
   407 		}
       
   408     
       
   409     CleanupStack::PopAndDestroy( &mailBoxes );
       
   410     
       
   411     delete iMtmUid; iMtmUid = NULL;
       
   412     iMtmUid = defaultMailBox.iMtmUid.Name().AllocL();
       
   413 
       
   414     //Set the organizer from the selected mailbox
       
   415     CCalUser* organizer = CCalUser::NewL( defaultMailBox.iEmailAddress );
       
   416     CleanupStack::PushL(organizer );
       
   417     iCalEntry->SetOrganizerL(organizer );
       
   418     CleanupStack::Pop( organizer ); // Ownership trasferred
       
   419     }
       
   420 
       
   421 // ---------------------------------------------------------------------------
       
   422 // CESMRCasPluginUiLauncher::AddAttendeesL
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 void CESMRCasPluginUiLauncher::AddAttendeesL(
       
   426         const RPointerArray<CCalUser>& aAttendees   )
       
   427     {
       
   428     FUNC_LOG;
       
   429     //Add attendees from contact set
       
   430     TInt attendeeCount( aAttendees.Count() );
       
   431     for (TInt i=0; i < attendeeCount; ++i )
       
   432         {
       
   433         CCalAttendee* attendee = CCalAttendee::NewL( aAttendees[i]->Address() );
       
   434         CleanupStack::PushL( attendee );
       
   435 
       
   436         attendee->SetCommonNameL( aAttendees[i]->CommonName() );
       
   437         attendee->SetRoleL( CCalAttendee::EReqParticipant );
       
   438 
       
   439         iCalEntry->AddAttendeeL( attendee );
       
   440 
       
   441         CleanupStack::Pop( attendee );
       
   442         }
       
   443     }
       
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // CESMRCasPluginUiLauncher::SetStartAndEndTimeL
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 void CESMRCasPluginUiLauncher::SetStartAndEndTimeL()
       
   450     {
       
   451     FUNC_LOG;
       
   452     // Adjust start time to future
       
   453     TTime start;
       
   454     start.UniversalTime();
       
   455     start = start + TTimeIntervalMinutes( KHalfHourMinutes );
       
   456     
       
   457     // Round up start time. 
       
   458     // Minutes between 46 ... 15 ==> 00
       
   459     // Minutes between 16 ... 45 ==> 30
       
   460     
       
   461     TDateTime currentTime = start.DateTime();
       
   462     TInt minute( currentTime.Minute() );
       
   463     
       
   464     if ( minute >= KMinuteRoundToHourStart || 
       
   465          minute <= KMinuteRoundToHourEnd   )
       
   466         {
       
   467         // Rounding to hour
       
   468         currentTime.SetMinute( KHourMinutes );
       
   469         }
       
   470     else
       
   471         {
       
   472         currentTime.SetMinute( KHalfHourMinutes );
       
   473         }
       
   474     
       
   475     start = currentTime;
       
   476     
       
   477     TTime end = start + TTimeIntervalHours( KOneHour );
       
   478 
       
   479     TCalTime startCalTime;
       
   480     startCalTime.SetTimeUtcL( start );
       
   481 
       
   482     TCalTime endCalTime;
       
   483     endCalTime.SetTimeUtcL( end );
       
   484 
       
   485     iCalEntry->SetStartAndEndTimeL( startCalTime, endCalTime );
       
   486 
       
   487     // Set time for input parameters
       
   488     TUint8 timemode = iCalEntry->StartTimeL().TimeMode ( );
       
   489     if (timemode == TCalTime::EFloating )
       
   490         {
       
   491         iInParams.iInstanceDate.SetTimeLocalFloatingL( start );
       
   492         }
       
   493     else
       
   494         {
       
   495         iInParams.iInstanceDate.SetTimeUtcL (start );
       
   496         }
       
   497     }
       
   498 
       
   499 // EOF
       
   500