phonebookui/Phonebook/App/src/CPbkSendMultipleMessageCmd.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *           Provides phonebook send message command object methods.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbkSendMultipleMessageCmd.h"
       
    22 
       
    23 #include <CPbkContactEngine.h>
       
    24 #include <MPbkContactNameFormat.h>
       
    25 #include <MPbkCommandObserver.h>
       
    26 #include <CPbkContactItem.h>
       
    27 #include <CPbkSmsAddressSelect.h>
       
    28 #include <CPbkEmailOverSmsAddressSelect.h>
       
    29 #include <CPbkMmsAddressSelect.h>
       
    30 #include <CPbkEmailAddressSelect.h>
       
    31 #include "TSingleDesCArray.h"
       
    32 #include "CPbkAppGlobals.h"
       
    33 #include <Phonebook.hrh>
       
    34 #include <Phonebook.rsg>
       
    35 #include <FeatMgr.h>
       
    36 #include <CPbkAttachmentFile.h>
       
    37 
       
    38 #include <sendui.h>             // Send UI API
       
    39 #include <SendUiConsts.h>       // Send UI MTM uid's
       
    40 #include <CMessageData.h>
       
    41 #include <StringLoader.h>
       
    42 #include <aknenv.h>
       
    43 
       
    44 #include <pbkdebug.h>
       
    45 
       
    46 /// Unnamed namespace for local definitions
       
    47 namespace {
       
    48 
       
    49 const TInt KMaxContactIdStringLength = 10;
       
    50 
       
    51 void WritePostcardAttachmentContentL(
       
    52     const CPbkContactItem& aContact,
       
    53     CPbkAttachmentFile& aAttachmentFile )
       
    54     {
       
    55     HBufC* contactId = HBufC::NewLC( KMaxContactIdStringLength );
       
    56     contactId->Des().Num( aContact.Id() );
       
    57     HBufC8* string8 = HBufC8::NewLC( KMaxContactIdStringLength );
       
    58     string8->Des().Append( *contactId );
       
    59     aAttachmentFile.File().Write( *string8 );
       
    60     CleanupStack::PopAndDestroy( 2, contactId );
       
    61     }
       
    62 
       
    63 
       
    64 // LOCAL DEBUG CODE
       
    65 #ifdef _DEBUG
       
    66 
       
    67 enum TPanicCode
       
    68     {
       
    69     EPanicUnknownMedia = 1,
       
    70     };
       
    71 
       
    72 
       
    73 void Panic(TPanicCode aReason)
       
    74     {
       
    75     _LIT(KPanicText, "CPbkSendMultipleMessageCmd");
       
    76     User::Panic(KPanicText,aReason);
       
    77     }
       
    78 #endif
       
    79 
       
    80 
       
    81 }  // namespace
       
    82 
       
    83 
       
    84 // ================= MEMBER FUNCTIONS =======================
       
    85 
       
    86 // Default constructor
       
    87 CPbkSendMultipleMessageCmd::CPbkSendMultipleMessageCmd
       
    88         (
       
    89         CPbkContactEngine& aEngine,
       
    90         TPbkSendingParams aParams,
       
    91         const CContactIdArray& aContacts,
       
    92         const TPbkContactItemField* aFocusedField,
       
    93         TBool aUseDefaultDirectly) :
       
    94         iEngine(aEngine),
       
    95         iParams(aParams),
       
    96         iContacts(aContacts),
       
    97         iFocusedField(aFocusedField),
       
    98         iUseDefaultDirectly(aUseDefaultDirectly)
       
    99     {
       
   100     PBK_DEBUG_PRINT
       
   101         (PBK_DEBUG_STRING("CPbkSendMultipleMessageCmd::CPbkSendMultipleMessageCmd(0x%x)"), this);
       
   102     }
       
   103 
       
   104 // Second phase constructor
       
   105 void CPbkSendMultipleMessageCmd::ConstructL()
       
   106     {
       
   107     }
       
   108 
       
   109 // Static constructor
       
   110 CPbkSendMultipleMessageCmd* CPbkSendMultipleMessageCmd::NewL
       
   111         (
       
   112         CPbkContactEngine& aEngine,
       
   113         TPbkSendingParams aParams,
       
   114         const CContactIdArray& aContacts,
       
   115         const TPbkContactItemField* aFocusedField,
       
   116         TBool aUseDefaultDirectly)
       
   117     {
       
   118     CPbkSendMultipleMessageCmd* self = new(ELeave)
       
   119         CPbkSendMultipleMessageCmd( aEngine, aParams, aContacts, aFocusedField,
       
   120         aUseDefaultDirectly);
       
   121     CleanupStack::PushL(self);
       
   122     self->ConstructL();
       
   123     CleanupStack::Pop(); // self
       
   124     return self;
       
   125     }
       
   126 
       
   127 // Destructor
       
   128 CPbkSendMultipleMessageCmd::~CPbkSendMultipleMessageCmd()
       
   129     {
       
   130     PBK_DEBUG_PRINT
       
   131         (PBK_DEBUG_STRING("CPbkSendMultipleMessageCmd::~CPbkSendMultipleMessageCmd(0x%x)"), this);
       
   132    delete iAttachmentFile;
       
   133    }
       
   134 
       
   135 void CPbkSendMultipleMessageCmd::ExecuteLD()
       
   136     {
       
   137     PBK_DEBUG_PRINT
       
   138         (PBK_DEBUG_STRING("CPbkSendMultipleMessageCmd::ExecuteLD(0x%x)"), this);
       
   139 
       
   140     CleanupStack::PushL(this);
       
   141 
       
   142     iMtmUid = ShowWriteQueryL();
       
   143     if ( iMtmUid == KNullUid )
       
   144         {
       
   145         // User pressed cancel
       
   146         CleanupStack::PopAndDestroy( this ); // this
       
   147         return;
       
   148         }
       
   149     TUid techTypeUid =
       
   150         CPbkAppGlobals::InstanceL()->SendUiL()->TechnologyType( iMtmUid );
       
   151 
       
   152     const TInt contactCount( iContacts.Count() );
       
   153     CMessageData* messageData = CMessageData::NewL();
       
   154     CleanupStack::PushL( messageData );
       
   155     TBool dismissed( EFalse );
       
   156 
       
   157     for ( TInt i( 0 ); i < contactCount && !dismissed; ++i )
       
   158         {
       
   159         TPtrC address( KNullDesC );
       
   160         CPbkContactItem* contact = iEngine.ReadContactLC( iContacts[i] );
       
   161 
       
   162         // Check specific MTMs first
       
   163         if ( iMtmUid ==  KSenduiMtmPostcardUid )
       
   164             {
       
   165             // Create attachment file object
       
   166             delete iAttachmentFile;
       
   167             iAttachmentFile = NULL;
       
   168             HBufC* attFileName = StringLoader::LoadLC( R_PBK_POSTCARD_WRITE_ATTACHMENT_TAG );
       
   169             iAttachmentFile = CPbkAttachmentFile::NewL
       
   170                 (*attFileName, iEngine.FsSession(), EFileWrite|EFileShareAny);
       
   171             CleanupStack::PopAndDestroy( attFileName );
       
   172             WritePostcardAttachmentContentL( *contact, *iAttachmentFile );
       
   173             messageData->AppendAttachmentL( iAttachmentFile->FileName() );
       
   174             iAttachmentFile->Release();
       
   175             }
       
   176         // Otherwise check by technology type to support 3rd party MTMs
       
   177         else if ( iMtmUid == KSenduiMtmSmsUid ||
       
   178                   techTypeUid == KSenduiTechnologySmsUid )
       
   179             {
       
   180             if (FeatureManager::FeatureSupported(KFeatureIdEmailOverSms))
       
   181                 {
       
   182                 CPbkEmailOverSmsAddressSelect::TParams params( *contact );
       
   183                 params.SetFocusedField(iFocusedField);
       
   184                 params.SetUseDefaultDirectly(iUseDefaultDirectly);
       
   185                 CPbkEmailOverSmsAddressSelect* selectDlg = new(ELeave) CPbkEmailOverSmsAddressSelect;
       
   186                 if (selectDlg->ExecuteLD(params))
       
   187                     {
       
   188                     address.Set(params.SelectedField()->Text());
       
   189                     }
       
   190                 }
       
   191             else
       
   192                 {
       
   193                 CPbkSmsAddressSelect::TParams params( *contact );
       
   194                 params.SetFocusedField(iFocusedField);
       
   195                 params.SetUseDefaultDirectly(iUseDefaultDirectly);
       
   196                 CPbkSmsAddressSelect* selectDlg = new(ELeave) CPbkSmsAddressSelect;
       
   197                 if (selectDlg->ExecuteLD(params))
       
   198                     {
       
   199                     address.Set(params.SelectedField()->Text());
       
   200                     }
       
   201                 }
       
   202             }
       
   203         else if ( iMtmUid == KSenduiMtmMmsUid ||
       
   204                   techTypeUid == KSenduiTechnologyMmsUid ||
       
   205                   iMtmUid == KSenduiMtmAudioMessageUid )
       
   206             {
       
   207             CPbkMmsAddressSelect::TParams params( *contact );
       
   208             params.SetFocusedField(iFocusedField);
       
   209             params.SetUseDefaultDirectly(iUseDefaultDirectly);
       
   210             CPbkMmsAddressSelect* selectDlg = new(ELeave) CPbkMmsAddressSelect;
       
   211             if (selectDlg->ExecuteLD(params))
       
   212                 {
       
   213                 address.Set(params.SelectedField()->Text());
       
   214                 }
       
   215             }
       
   216         else if ( iMtmUid == KSenduiMtmSmtpUid ||
       
   217                   techTypeUid == KSenduiTechnologyMailUid )
       
   218             {
       
   219             CPbkEmailAddressSelect::TParams params( *contact );
       
   220             params.SetFocusedField(iFocusedField);
       
   221             params.SetUseDefaultDirectly(iUseDefaultDirectly);
       
   222             CPbkEmailAddressSelect* selectDlg = new(ELeave) CPbkEmailAddressSelect;
       
   223             if (selectDlg->ExecuteLD(params))
       
   224                 {
       
   225                 address.Set(params.SelectedField()->Text());
       
   226                 }
       
   227             }
       
   228         else
       
   229             {
       
   230             if ( iMtmUid != KNullUid )
       
   231                 {
       
   232                 __ASSERT_DEBUG(EFalse, Panic(EPanicUnknownMedia));
       
   233                 }
       
   234             }
       
   235 
       
   236         if (address.Length() > 0)
       
   237             {
       
   238             MPbkContactNameFormat& nameFormatter = iEngine.ContactNameFormat();
       
   239             HBufC* nameBuffer = nameFormatter.GetContactTitleOrNullL( *contact );
       
   240             if ( nameBuffer )
       
   241                 {
       
   242                 CleanupStack::PushL(nameBuffer);
       
   243                 messageData->AppendToAddressL( address, *nameBuffer );
       
   244                 CleanupStack::PopAndDestroy( nameBuffer );
       
   245                 }
       
   246             else
       
   247                 {
       
   248                 messageData->AppendToAddressL( address );
       
   249                 }
       
   250             }
       
   251 
       
   252         if (!dismissed)
       
   253             {
       
   254             // Abort the whole process if end key was pressed during address
       
   255             // selection dialog and Phonebook application was terminated.
       
   256             dismissed = (NULL != CAknEnv::AppWithShutterRunning());
       
   257             }
       
   258 
       
   259         CleanupStack::PopAndDestroy( contact );
       
   260         }
       
   261     if ( !dismissed )
       
   262         {
       
   263         // Empty message editor is not displayed if none of selected contacts
       
   264         // has a valid address information
       
   265         CPbkAppGlobals::InstanceL()->SendUiL()->CreateAndSendMessageL(
       
   266             iMtmUid, messageData );
       
   267         }
       
   268 
       
   269     CleanupStack::PopAndDestroy( messageData );
       
   270 
       
   271     if ( iAttachmentFile )
       
   272         {
       
   273         // no error checking, exiting phonebook would too much for this error
       
   274         iEngine.FsSession().Delete( iAttachmentFile->FileName() );
       
   275         }
       
   276 
       
   277     if ( iObserver )
       
   278         {
       
   279         iObserver->CommandFinished( *this );
       
   280         }
       
   281     // Destroy itself as promised
       
   282     CleanupStack::PopAndDestroy( this ); // this
       
   283     }
       
   284 
       
   285 void CPbkSendMultipleMessageCmd::ProcessFinished(MPbkBackgroundProcess& /*aProcess*/)
       
   286     {
       
   287     PBK_DEBUG_PRINT
       
   288         (PBK_DEBUG_STRING("CPbkSendMultipleMessageCmd::ProcessFinished(0x%x)"), this);
       
   289     }
       
   290 
       
   291 TUid CPbkSendMultipleMessageCmd::ShowWriteQueryL()
       
   292     {
       
   293     TUid uid = CPbkAppGlobals::InstanceL()->SendUiL()
       
   294         ->ShowTypedQueryL( CSendUi::EWriteMenu, NULL, iParams.iCapabilities, iParams.iMtmFilter );
       
   295     return uid;
       
   296     }
       
   297 
       
   298 void CPbkSendMultipleMessageCmd::AddObserver( MPbkCommandObserver& aObserver )
       
   299     {
       
   300     iObserver = &aObserver;
       
   301     }
       
   302 
       
   303 
       
   304 //  End of File