/**
*
* @brief Definition of CSendAppUiExampleAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/
// INCLUDE FILES
// Class include
#include "SendAppUiExampleAppUi.h"
// System includes
#include <aknutils.h> // CompleteWithAppPath()
#include <SendAppUiExample.rsg> // Resource ids
#include <SendNorm.rsg> // R_SENDUI_MENU
#include <aknapp.h> // CAknApplication
#include <miutset.h> // KUidMsgTypeSMTP
#include <mmsconst.h> // KUidMsgTypeMultimedia
#include <sendui.h> // CSendAppUi
#include <smut.h> // KUidMsgTypeSMS
#include <stringloader.h> // StringLoader
#include <txtrich.h> // CRichText
// User includes
#include "SendAppUiExampleDialog.h" // CSendAppUiExampleDialog
#include "SendAppUiExample.hrh" // Command ids
const TInt KDefaultGranularity = 4;
// String literals
_LIT(KAttachmentFileName, "Image.jpg");
// ================= MEMBER FUNCTIONS =======================
/**
* Symbian OS 2nd phase constructor. Constructs and executes the application's
* dialog, setting itself as the dialog's MOP parent, and adds it to the control
* stack.
*/
void CSendAppUiExampleAppUi::ConstructL()
{
BaseConstructL();
// Construct dialog
iAppDialog = new (ELeave) CSendAppUiExampleDialog;
iAppDialog->SetMopParent(this);
iAppDialog->ExecuteLD(R_SEND_EXAMPLE_DIALOG);
AddToStackL(iAppDialog);
// Construct the CSendAppUi object
iSendAppUi = CSendAppUi::NewL(ECmdSendAppUiBaseCmdId);
iSendAppUiCapabilities.iFlags = TSendingCapabilities::ESupportsBodyText;
// Construct the CRichText object
// This is really for convenience, as it's used throughout
// and awkward to construct
iRichText = CRichText::NewL(iEikonEnv->SystemParaFormatLayerL(),
iEikonEnv->SystemCharFormatLayerL());
}
/**
* Destructor.
* Removes the applications dialog from the stack and deletes it.
*/
CSendAppUiExampleAppUi::~CSendAppUiExampleAppUi()
{
if (iAppDialog)
{
RemoveFromStack(iAppDialog);
delete iAppDialog;
}
delete iSendAppUi;
delete iRichText;
}
/**
* From CEikAppUi, takes care of command handling.
*
* @param aCommand Command to be handled
*/
void CSendAppUiExampleAppUi::HandleCommandL(TInt aCommand)
{
switch (aCommand)
{
case ECmdCreateSMS:
CreateSMSL();
break;
case ECmdCreateEmail:
CreateEmailL();
break;
case ECmdCreateMMS:
CreateMMSL();
break;
case ECmdCreateGeneralMessage:
CreateGeneralMessageL();
break;
case EEikCmdExit:
Exit();
break;
default:
// It should be a dynamic command ID generated by SendAppUi.
// If not, panic in debug.
if (!HandleSendAppUiCommandL(aCommand))
__ASSERT_DEBUG(EFalse, Panic(EBadCommandId));
break;
}
}
/**
* From MEikMenuObserver, called by the framework immediately prior to a menu
* pane getting activated. It will display a cascaded menu of the message types
* that satisfy the specified sending capabilities.
*
* @param aMenuId Resource id of the menu pane
* @param aMenuPane Menu Pane to initialise
*/
void CSendAppUiExampleAppUi::DynInitMenuPaneL(TInt aMenuId, CEikMenuPane* aMenuPane)
{
// specify the sending capabilities that the message types displayed
// must satisfy
switch (aMenuId)
{
case R_SEND_EXAMPLE_MENU_PANE:
iSendAppUi->DisplaySendMenuItemL(*aMenuPane, 0, iSendAppUiCapabilities);
break;
case R_SENDUI_MENU:
iSendAppUi->DisplaySendCascadeMenuL(*aMenuPane, NULL);
break;
}
}
/**
* Creates an SMS. The SMS editor is displayed with some body text and
* addresses already inserted.
*/
void CSendAppUiExampleAppUi::CreateSMSL()
{
__ASSERT_DEBUG(iRichText && iRichText->DocumentLength() == 0,
Panic(ERichTextNotReady));
// insert text into the message body
HBufC* string = StringLoader::LoadLC(R_SMS_BODY_TEXT);
iRichText->InsertL(0, *string);
CleanupStack::PopAndDestroy(string);
string = NULL;
// display the SMS editor with some text and addresses already inserted
iSendAppUi->CreateAndSendMessageL(KUidMsgTypeSMS, iRichText, NULL,
KNullUid, NULL, NULL, EFalse);
iRichText->Reset();
}
/**
* Creates an email. The email editor is displayed with some body text, addresses
* and an attachment already inserted.
*/
void CSendAppUiExampleAppUi::CreateEmailL()
{
// create an array for addresses and add two to it
CDesCArrayFlat* addressArray = new (ELeave) CDesCArrayFlat(KDefaultGranularity);
CleanupStack::PushL(addressArray);
HBufC* string = StringLoader::LoadLC(R_EMAIL_ADDRESS1);
addressArray->AppendL(*string);
CleanupStack::PopAndDestroy(string);
string = NULL;
string = StringLoader::LoadLC(R_EMAIL_ADDRESS2);
addressArray->AppendL(*string);
CleanupStack::PopAndDestroy(string);
// Display the email editor with addresses already inserted
iSendAppUi->CreateAndSendMessageL(KUidMsgTypeSMTP, NULL, NULL,
KNullUid, addressArray, NULL, ETrue);
CleanupStack::PopAndDestroy(addressArray);
}
/**
* Creates an MMS. The MMS editor is displayed with some body text, addresses
* and an attachment already inserted.
*/
void CSendAppUiExampleAppUi::CreateMMSL()
{
// Declare string for reading resources into
HBufC* string = NULL;
// Create an array for attachments and add one file to it
CDesCArrayFlat* attachmentArray = new (ELeave) CDesCArrayFlat(KDefaultGranularity);
CleanupStack::PushL(attachmentArray);
// Add the first attachment
TFileName attachmentName(KAttachmentFileName);
User::LeaveIfError(CompleteWithAppPath(attachmentName));
attachmentArray->AppendL(attachmentName);
// create an array for aliases and add one to it. This will replace the
// first MMS address in the MMS editor
CDesCArrayFlat* aliasArray = new(ELeave) CDesCArrayFlat(KDefaultGranularity);
CleanupStack::PushL(aliasArray);
string = StringLoader::LoadLC(R_MMS_ALIAS1);
aliasArray->AppendL(*string);
CleanupStack::PopAndDestroy(string);
string = NULL;
// display the MMS editor with attachment and aliases already inserted
iSendAppUi->CreateAndSendMessageL(KUidMsgTypeMultimedia, NULL, attachmentArray,
KNullUid, NULL, aliasArray, ETrue);
CleanupStack::PopAndDestroy(2, attachmentArray); // aliasArray, attachmentArray
}
/**
* Displays a list of the message types which satisfy the specified sending
* capabilities. Once the user chooses one of the message types then the
* associated editor will be displayed with some body text already inserted.
*/
void CSendAppUiExampleAppUi::CreateGeneralMessageL()
{
__ASSERT_DEBUG(iRichText && iRichText->DocumentLength() == 0,
Panic(ERichTextNotReady));
// insert text into the message body
HBufC* string = StringLoader::LoadLC(R_GENERAL_BODY_TEXT);
iRichText->InsertL(0, *string);
CleanupStack::PopAndDestroy(string);
string = NULL;
// set the title of the box which displays the message types
string = StringLoader::LoadLC(R_GENERAL_MESSAGE_POPUP_TITLE);
// display a list of the message types which satisfy the specified
// sending capabilities
iSendAppUi->CreateAndSendMessagePopupQueryL(*string, iSendAppUiCapabilities,
iRichText, NULL, KNullUid, NULL, NULL, NULL, ETrue);