meetingui/meetingrequestutils/src/CMRUtilsImpl.cpp
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     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: Implementation for meeting request utils   
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // ----------------------------------------------------------------------------
       
    21 // INCLUDE FILES
       
    22 // ----------------------------------------------------------------------------
       
    23 //
       
    24 #include "CMRUtilsImpl.h"
       
    25 #include "MRUtilsFactory.h"
       
    26 #include "CMRUtilsEmailSender.h"
       
    27 #include "CMRUtilsCalDbMgr.h"
       
    28 #include "MRHelpers.h"
       
    29 #include "ICalUILog.h"
       
    30 #include <CalEntry.h>
       
    31 #include <CalSession.h>
       
    32 #include <CalCommon.h>
       
    33 #include <CalUser.h>
       
    34 #include <cmrmailboxutils.h>
       
    35 #include "CMRUtilsUiServices.h"
       
    36 
       
    37 // CONSTANTS
       
    38 /// Unnamed namespace for local definitions
       
    39 namespace {
       
    40 
       
    41 enum TPanicCode
       
    42     {
       
    43     EPanicSessionSetupAlreadyDone = 1,
       
    44     EPanicMandatoryObserverMissing,
       
    45     EPanicMsvSessionExpected
       
    46     };
       
    47 
       
    48 _LIT( KPanicMsg, "CMRUtilsImpl" );
       
    49 
       
    50 void Panic( TPanicCode aReason )
       
    51     {
       
    52     User::Panic( KPanicMsg, aReason );
       
    53     }
       
    54     
       
    55 }  // namespace
       
    56 
       
    57 // ----------------------------------------------------------------------------
       
    58 // MEMBER FUNCTIONS
       
    59 // ----------------------------------------------------------------------------
       
    60 //
       
    61 
       
    62 // ----------------------------------------------------------------------------
       
    63 // CMRUtilsImpl::NewL
       
    64 // ----------------------------------------------------------------------------
       
    65 //
       
    66 CMRUtilsImpl* CMRUtilsImpl::NewL()
       
    67 	{
       
    68 	LOG("CMRUtilsImpl::NewL()");
       
    69 	CMRUtilsImpl* self = new( ELeave ) CMRUtilsImpl();
       
    70 	CleanupStack::PushL( self );
       
    71 	self->ConstructL();
       
    72 	CleanupStack::Pop();
       
    73 	LOG("CMRUtilsImpl::NewL() -> End");	
       
    74 	return self;
       
    75 	}
       
    76 
       
    77 // ----------------------------------------------------------------------------
       
    78 // CMRUtilsImpl::CMRUtilsImpl
       
    79 //
       
    80 // Constructor.
       
    81 // ----------------------------------------------------------------------------
       
    82 //
       
    83 CMRUtilsImpl::CMRUtilsImpl()
       
    84     : iCalEngStatus( MMRUtilsObserver::ENotReady )
       
    85     {    
       
    86     }
       
    87     
       
    88 // ----------------------------------------------------------------------------
       
    89 // CMRUtilsImpl::~CMRUtilsImpl
       
    90 //
       
    91 // Destructor.
       
    92 // ----------------------------------------------------------------------------
       
    93 //        
       
    94 CMRUtilsImpl::~CMRUtilsImpl()
       
    95     {    
       
    96     delete iCalDbMgr;
       
    97     delete iUiServices;
       
    98     delete iMRMailboxUtils;
       
    99     }
       
   100     
       
   101 // ----------------------------------------------------------------------------
       
   102 // CMRUtilsImpl::ConstructL
       
   103 // ----------------------------------------------------------------------------
       
   104 //    
       
   105 void CMRUtilsImpl::ConstructL()
       
   106     {
       
   107     // See also SessionSetupL() for construction phase functionality    
       
   108     }
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // CMRUtilsImpl::EntryView
       
   112 // ----------------------------------------------------------------------------
       
   113 //
       
   114 CCalEntryView* CMRUtilsImpl::EntryView()
       
   115     {
       
   116     if ( iCalEngStatus == EAvailable ||
       
   117          iCalEngStatus == EAvailableWithoutTombs )
       
   118         {
       
   119         return iCalDbMgr->NormalDbEntryView();
       
   120         }
       
   121     else
       
   122         {
       
   123         return NULL;
       
   124         }
       
   125     }
       
   126 
       
   127 // ----------------------------------------------------------------------------
       
   128 // CMRUtilsImpl::InstanceView
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 CCalInstanceView* CMRUtilsImpl::InstanceView()
       
   132     {
       
   133     if ( iCalEngStatus == EAvailable ||
       
   134          iCalEngStatus == EAvailableWithoutTombs )
       
   135         {
       
   136         return iCalDbMgr->NormalDbInstanceView();
       
   137         }
       
   138     else
       
   139         {
       
   140         return NULL;
       
   141         }
       
   142     }
       
   143 
       
   144 // ----------------------------------------------------------------------------
       
   145 // CMRUtilsImpl::FetchEntriesL
       
   146 // ----------------------------------------------------------------------------
       
   147 //  
       
   148 void CMRUtilsImpl::FetchEntriesL(
       
   149     RPointerArray<CCalEntry>& aCalEntryArray,
       
   150     const CalCommon::TCalTimeRange& aTimeRange )
       
   151     {
       
   152     LeaveIfEngNotAvailableL();
       
   153     iCalDbMgr->FetchEntriesL( aCalEntryArray, aTimeRange );
       
   154     } 
       
   155                                  
       
   156 // ----------------------------------------------------------------------------
       
   157 // CMRUtilsImpl::FetchEntryL
       
   158 // ----------------------------------------------------------------------------
       
   159 //  
       
   160 CCalEntry* CMRUtilsImpl::FetchEntryL(
       
   161     const TDesC8& aUid,
       
   162     const TCalTime& aRecurrenceId )
       
   163     {
       
   164     LeaveIfEngNotAvailableL();
       
   165     return iCalDbMgr->FetchEntryL( aUid, aRecurrenceId );
       
   166     }        
       
   167 
       
   168 // ----------------------------------------------------------------------------
       
   169 // CMRUtilsImpl::UpdateEntryL
       
   170 // ----------------------------------------------------------------------------
       
   171 //          
       
   172 TInt CMRUtilsImpl::UpdateEntryL( const CCalEntry& aCalEntry )
       
   173     {
       
   174     LeaveIfEngNotAvailableL();
       
   175     return iCalDbMgr->UpdateEntryL( aCalEntry ); 
       
   176     }        
       
   177 
       
   178 // ----------------------------------------------------------------------------
       
   179 // CMRUtilsImpl::ResetTombsFileL
       
   180 // ----------------------------------------------------------------------------
       
   181 //          
       
   182 void CMRUtilsImpl::ResetTombsFileL()
       
   183     {
       
   184     LeaveIfEngNotAvailableL();
       
   185     iCalDbMgr->ResetTombsFileL();
       
   186     }
       
   187     
       
   188 // ----------------------------------------------------------------------------
       
   189 // CMRUtilsImpl::DeleteTombstonesL
       
   190 // ----------------------------------------------------------------------------
       
   191 //          
       
   192 void CMRUtilsImpl::DeleteTombstonesL(
       
   193     const CalCommon::TCalTimeRange& aCalTimeRange )
       
   194     {
       
   195     LeaveIfEngNotAvailableL();
       
   196     iCalDbMgr->DeleteTombstonesL( aCalTimeRange );
       
   197     }
       
   198       
       
   199 // ----------------------------------------------------------------------------
       
   200 // CMRUtilsImpl::StoreL
       
   201 // ----------------------------------------------------------------------------
       
   202 //          
       
   203 MMRUtilsTombsExt::TMRUtilsDbResult CMRUtilsImpl::StoreL(
       
   204     CCalEntry& aCalEntry,
       
   205     TBool aResurrect )
       
   206     {
       
   207     LeaveIfEngNotAvailableL();          
       
   208     return iCalDbMgr->StoreEntryCondL( aCalEntry, aResurrect );
       
   209     }
       
   210     
       
   211 // ----------------------------------------------------------------------------
       
   212 // CMRUtilsImpl::CheckEntryCondL
       
   213 // ----------------------------------------------------------------------------
       
   214 //          
       
   215 MMRUtilsTombsExt::TMRUtilsDbResult CMRUtilsImpl::CheckEntryCondL(
       
   216     const CCalEntry& aCalEntry )
       
   217     {
       
   218     LeaveIfEngNotAvailableL();
       
   219     // We want to keep const in CMRUtil API, but CalenInterimApi::StoreL()
       
   220     // takes non-const CCalEntry reference. With this method it is still
       
   221     // safe to cast away constness since in this case we are only performing
       
   222     // a check, not storing actually.
       
   223     CCalEntry& entry = const_cast<CCalEntry&>( aCalEntry );
       
   224     return iCalDbMgr->StoreEntryCondL( entry, EFalse, ETrue );
       
   225     }
       
   226 
       
   227 // ----------------------------------------------------------------------------
       
   228 // CMRUtilsImpl::DeleteL
       
   229 // ----------------------------------------------------------------------------
       
   230 //          
       
   231 void CMRUtilsImpl::DeleteL( const TDesC8& aUid )
       
   232     {
       
   233     LeaveIfEngNotAvailableL();
       
   234     iCalDbMgr->DeleteEntryCondL( aUid );
       
   235     }
       
   236 
       
   237 // ----------------------------------------------------------------------------
       
   238 // CMRUtilsImpl::DeleteL
       
   239 // ----------------------------------------------------------------------------
       
   240 //          
       
   241 void CMRUtilsImpl::DeleteL( const TCalLocalUid& aLocalUid )
       
   242     {
       
   243     LeaveIfEngNotAvailableL();
       
   244     iCalDbMgr->DeleteEntryCondL( aLocalUid );
       
   245     }
       
   246 
       
   247 // ----------------------------------------------------------------------------
       
   248 // CMRUtilsImpl::DeleteL
       
   249 // ----------------------------------------------------------------------------
       
   250 //          
       
   251 void CMRUtilsImpl::DeleteL( const CCalEntry& aCalEntry )
       
   252     {
       
   253     LeaveIfEngNotAvailableL();
       
   254     iCalDbMgr->DeleteEntryCondL( aCalEntry );
       
   255     }
       
   256 
       
   257 // ----------------------------------------------------------------------------
       
   258 // CMRUtilsImpl::DeleteL
       
   259 // ----------------------------------------------------------------------------
       
   260 //          
       
   261 void CMRUtilsImpl::DeleteL(
       
   262     const CalCommon::TCalTimeRange& aCalTimeRange )
       
   263     {
       
   264     LeaveIfEngNotAvailableL();
       
   265     iCalDbMgr->DeleteEntryCondL( aCalTimeRange );    
       
   266     }
       
   267    
       
   268 // ----------------------------------------------------------------------------
       
   269 // CMRUtilsImpl::DeleteWithUiL
       
   270 // ----------------------------------------------------------------------------
       
   271 //          
       
   272 TInt CMRUtilsImpl::DeleteWithUiL( const CCalEntry& aEntry, TMsvId aMailbox )
       
   273     {
       
   274     LeaveIfEngNotAvailableL();
       
   275     LeaveIfUiExtNotAvailableL();
       
   276     return iUiServices->DeleteWithUiL( aEntry, aMailbox );
       
   277     }
       
   278    
       
   279 // ----------------------------------------------------------------------------
       
   280 // CMRUtilsImpl::DeleteWithUiL
       
   281 // ----------------------------------------------------------------------------
       
   282 //          
       
   283 TInt CMRUtilsImpl::DeleteWithUiL( CCalInstance* aInstance, TMsvId aMailbox )
       
   284     {
       
   285     LeaveIfEngNotAvailableL();
       
   286     LeaveIfUiExtNotAvailableL();
       
   287     return iUiServices->DeleteWithUiL( aInstance, aMailbox );
       
   288     }
       
   289         
       
   290 // ----------------------------------------------------------------------------
       
   291 // CMRUtilsImpl::SendWithUiL
       
   292 // ----------------------------------------------------------------------------
       
   293 //  
       
   294 void CMRUtilsImpl::SendWithUiL( const CCalEntry& aEntry, TMsvId aMailbox )
       
   295     {
       
   296     LeaveIfEngNotAvailableL();
       
   297     LeaveIfUiExtNotAvailableL();
       
   298     iUiServices->SendL( aEntry, aMailbox );
       
   299     }
       
   300 
       
   301 // ----------------------------------------------------------------------------
       
   302 // CMRUtilsImpl::RespondWithUiL
       
   303 // ----------------------------------------------------------------------------
       
   304 //                     
       
   305 TInt CMRUtilsImpl::RespondWithUiL(
       
   306     const RPointerArray<CCalEntry>& aEntries,
       
   307     CCalAttendee::TCalStatus aStatus,
       
   308     TMsvId aMailbox )
       
   309     {
       
   310     LeaveIfEngNotAvailableL();
       
   311     LeaveIfUiExtNotAvailableL();
       
   312     return iUiServices->RespondWithUiL( aEntries, aStatus, aMailbox );    
       
   313     }
       
   314                     
       
   315 // ----------------------------------------------------------------------------
       
   316 // CMRUtilsImpl::CancelWithUiL
       
   317 // ----------------------------------------------------------------------------
       
   318 // 
       
   319 TInt CMRUtilsImpl::CancelWithUiL(
       
   320     const RPointerArray<CCalEntry>& aEntries,
       
   321     TMsvId aMailbox )
       
   322     {
       
   323     LeaveIfEngNotAvailableL();
       
   324     LeaveIfUiExtNotAvailableL();
       
   325     return iUiServices->CancelWithUiL( aEntries, aMailbox );    
       
   326     }
       
   327 
       
   328 // ----------------------------------------------------------------------------
       
   329 // CMRUtilsImpl::ReplyToL
       
   330 // ----------------------------------------------------------------------------
       
   331 // 
       
   332 void CMRUtilsImpl::ReplyToL(
       
   333     TMailRecipients aRecipients,
       
   334     const CCalEntry& aCalEntry,
       
   335     const TDesC& aSenderAddr,
       
   336     TMsvId aMailbox )
       
   337     {
       
   338     LeaveIfEngNotAvailableL();
       
   339     LeaveIfUiExtNotAvailableL();
       
   340     iUiServices->ReplyToL( aRecipients, aCalEntry, aSenderAddr, aMailbox );    
       
   341     }
       
   342 
       
   343 // ----------------------------------------------------------------------------
       
   344 // CMRUtilsImpl::MailHeaderFromFieldLC
       
   345 // ----------------------------------------------------------------------------
       
   346 // 
       
   347 HBufC* CMRUtilsImpl::MailHeaderFromFieldLC( TMsvId aMessage )
       
   348     {
       
   349     HBufC* fromField = NULL;
       
   350     if ( !iMsvSession )
       
   351         { // This method should only be called in case of opening from Mail,
       
   352           // -> valid MsvSession given by the client.
       
   353         __ASSERT_DEBUG( EFalse, Panic( EPanicMsvSessionExpected ) );
       
   354         User::Leave( KErrNotSupported );
       
   355         }
       
   356     else
       
   357         {
       
   358         TMsvId dummy( KMsvNullIndexEntryId );
       
   359         TMsvEntry entry;
       
   360         User::LeaveIfError( iMsvSession->GetEntry( aMessage, dummy, entry ) );        
       
   361         fromField = entry.iDetails.AllocLC();
       
   362         }
       
   363     return fromField;
       
   364     }
       
   365 
       
   366 // ----------------------------------------------------------------------------
       
   367 // CMRUtilsImpl::MailHeaderSubjectFieldLC
       
   368 // ----------------------------------------------------------------------------
       
   369 // 
       
   370 HBufC* CMRUtilsImpl::MailHeaderSubjectFieldLC( TMsvId aMessage )
       
   371     {
       
   372     HBufC* subjectField = NULL;
       
   373     if ( !iMsvSession )
       
   374         { // This method should only be called in case of opening from Mail,
       
   375           // -> valid MsvSession given by the client.
       
   376         __ASSERT_DEBUG( EFalse, Panic( EPanicMsvSessionExpected ) );
       
   377         User::Leave( KErrNotSupported );
       
   378         }
       
   379     else
       
   380         {
       
   381         TMsvId dummy( KMsvNullIndexEntryId );
       
   382         TMsvEntry entry;
       
   383         User::LeaveIfError( iMsvSession->GetEntry( aMessage, dummy, entry ) );        
       
   384         subjectField = entry.iDescription.AllocLC();
       
   385         }
       
   386     return subjectField;    
       
   387     }
       
   388     
       
   389 // ----------------------------------------------------------------------------
       
   390 // CMRUtilsImpl::ExtensionL
       
   391 // ----------------------------------------------------------------------------
       
   392 //
       
   393 TAny* CMRUtilsImpl::ExtensionL( TUid aExtensionUid )
       
   394     {
       
   395     if ( aExtensionUid == MMRUtilsTombsExt::ExtensionUid() )
       
   396         {
       
   397         return static_cast<MMRUtilsTombsExt*>( this );
       
   398         }
       
   399     else
       
   400         {        
       
   401         return NULL;
       
   402         }
       
   403     }
       
   404       
       
   405 // ----------------------------------------------------------------------------
       
   406 // CMRUtilsImpl::SessionSetupL
       
   407 // This template method is called as a part of the ECom plugin construction.
       
   408 // This replaces much of the ordinary ConstructL() functionality, a template
       
   409 // method is easier for transmitting parameters.
       
   410 // ----------------------------------------------------------------------------
       
   411 //          
       
   412 void CMRUtilsImpl::SessionSetupL( 
       
   413     CCalSession& aCalSession, 
       
   414     CMsvSession* aMsvSession )
       
   415     {                    
       
   416     LOG("CMRUtilsImpl::SessionSetupL()");
       
   417     iCalSession = &aCalSession;
       
   418     iMsvSession = aMsvSession;   
       
   419     LOG("CMRUtilsImpl::SessionSetupL(), creating mailbox utils");
       
   420     iMRMailboxUtils = CMRMailboxUtils::NewL( aMsvSession );    
       
   421     // This will remain null if no ui environment is available
       
   422     LOG("CMRUtilsImpl::SessionSetupL(), creating ui services");    
       
   423     iUiServices = MRUtilsFactory::CreateUiServicesL( *this,
       
   424                                                      *iCalSession,
       
   425                                                      iMsvSession,
       
   426                                                      *iMRMailboxUtils );    
       
   427     // Asynchronous initialization of CMRUtilsCalDbMgr:     
       
   428     LOG("CMRUtilsImpl::SessionSetupL(), creating db mgr");           
       
   429     iCalDbMgr = MRUtilsFactory::CreateCalDbMgrL( *iCalSession, *this );    
       
   430     LOG("CMRUtilsImpl::SessionSetupL() -> End");    
       
   431     }
       
   432 
       
   433 // ----------------------------------------------------------------------------
       
   434 // CMRUtilsImpl::HandleCalEngStatus
       
   435 // ----------------------------------------------------------------------------
       
   436 //    
       
   437 void CMRUtilsImpl::HandleCalEngStatus( TMRUtilsCalEngStatus aStatus )
       
   438     {
       
   439     iCalEngStatus = aStatus;
       
   440     __ASSERT_DEBUG( iObserver, EPanicMandatoryObserverMissing );
       
   441     iObserver->HandleCalEngStatus( iCalEngStatus );
       
   442     }
       
   443     
       
   444 // ----------------------------------------------------------------------------
       
   445 // CMRUtilsImpl::HandleOperation
       
   446 // ----------------------------------------------------------------------------
       
   447 //    
       
   448 void CMRUtilsImpl::HandleOperation(
       
   449     TInt aType,
       
   450     TInt aPercentageCompleted, 
       
   451     TInt aStatus )
       
   452     {
       
   453     iObserver->HandleOperation( aType, aPercentageCompleted, aStatus );
       
   454     }    
       
   455 
       
   456 // ----------------------------------------------------------------------------
       
   457 // CMRUtilsImpl::LeaveIfEngNotAvailableL
       
   458 // ----------------------------------------------------------------------------
       
   459 //
       
   460 void CMRUtilsImpl::LeaveIfEngNotAvailableL() const
       
   461     {
       
   462     if ( iCalEngStatus == MMRUtilsObserver::ENotReady )
       
   463         {
       
   464         User::Leave( KErrNotReady );
       
   465         }
       
   466     else if ( iCalEngStatus == MMRUtilsObserver::ENotAvailable )
       
   467         {
       
   468         User::Leave( KErrCouldNotConnect );
       
   469         }
       
   470     }
       
   471 
       
   472 // ----------------------------------------------------------------------------
       
   473 // CMRUtilsImpl::LeaveIfEngNotAvailableL
       
   474 // ----------------------------------------------------------------------------
       
   475 //
       
   476 void CMRUtilsImpl::LeaveIfUiExtNotAvailableL() const
       
   477     {
       
   478     if ( !iUiServices )
       
   479         {
       
   480         User::Leave( KErrNotSupported );
       
   481         }
       
   482     }
       
   483       
       
   484 // End of file