⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mmsdemo1appui.cpp

📁 这是一个在symbian操作系统下编写的发送彩信的程序。
💻 CPP
📖 第 1 页 / 共 2 页
字号:

        // iMmsEngine::AddTextObjectL() can also be called without a filename parameter
        iMmsEngine->AddTextObjectL(text, _L("mmsdemo1.wad"));
        }

    if(!iReply) // reply message already has one To addressee
        {
        // TODO: support for multiple addressees (now only supports single address)
        // add To addressee
        iMmsEngine->AddAddresseeL(iTo);
        }

    // TODO: support for multiple addressees (now only supports single address)
    // add Cc addressee
    if(iCc.Length() > 0)
        {
        iMmsEngine->AddAddresseeL(iCc, ETypeCc);
        }

    iMmsEngine->SetSubjectL(_L("Web Address Description"));
        

    // Make sure that message is saved before sending
    iMmsEngine->SaveMessageL();

// --- Send message ---

    iMmsEngine->SendMessageL();    
    }

// ----------------------------------------------------
// CMMSDemo1AppUi::WriteMessageL()
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::WriteMessageL()
    {
    // Updating Navi pane information
    iNaviPane->Pop();
    delete iNaviDecorator;
    TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader,	R_MMSDEMO1_NAVI_CREATE);
	iNaviDecorator = iNaviPane->CreateNavigationLabelL(reader);
	CleanupStack::PopAndDestroy();  // resource reader
	iNaviPane->PushL(*iNaviDecorator);

    // Clear descriptors
    iUrl.Delete(0, iUrl.Length());
    iDesc.Delete(0, iDesc.Length());
    iTo.Delete(0, iTo.Length());
    iCc.Delete(0, iCc.Length());
    
    // Ask new message content from user (open message editor form).
    iForm = CMMSDemo1Form::NewL(ETrue, iUrl, iDesc, iTo, iCc);	
    iForm->ExecuteLD(R_MYFORMS_DIALOG);

    // reset function id variable
    iFunctionId = 0;
    }

// ----------------------------------------------------
// CMMSDemo1AppUi::OpenMessageL(TMsvId aFolder)
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::OpenMessageL()
    {
    // Updating Navi pane information
    iNaviPane->Pop();
    delete iNaviDecorator;
    TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader,	R_MMSDEMO1_NAVI_OPEN);
    iNaviDecorator = iNaviPane->CreateNavigationLabelL(reader);
	CleanupStack::PopAndDestroy();  // resource reader
	iNaviPane->PushL(*iNaviDecorator);

    // Messages and ids have been read from MmsEngine
    // CompleteReadL() returns the ID of the selected message, otherwise NULL

    TMsvId msgId = CompleteReadL();
    if(msgId != NULL)
        {
        // load message to the engine's MTM
        if( iMmsEngine->LoadMessageL(msgId) )
            {
            // Remember msgId globally in case for possible Forward & Reply
            // commands issued from the opened message form.
            iMsgId = msgId;
            // Here we read the message params to our UI decriptor fields
            UpdateDescriptorsL();   
            
            // We open the message viewer form with Boolean params EFalse and ETrue,
            // the first indicates this is not a forward and the second indicate that this
            // is a message opened from the message store (form UI will be a bit different).
            // Both boolean values default to EFalse and can be omitted when creating
            // a new message (see above WriteMessageL).
            iMessageOpen = ETrue;
            iForm = CMMSDemo1Form::NewL(EFalse, iUrl, iDesc, iTo, iCc, EFalse, ETrue);	
            iForm->ExecuteLD(R_MYFORMS_DIALOG_OPEN);
            iMessageOpen = EFalse;
            }
        }

    // reset launcher attribute
    iFunctionId = 0;
    }

// ----------------------------------------------------
// CMMSDemo1AppUi::UpdateDescriptorsL()
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::UpdateDescriptorsL()
    {
    // Clear descriptors
    iUrl.Delete(0, iUrl.Length());
    iDesc.Delete(0, iDesc.Length());
    iTo.Delete(0, iTo.Length());
    iCc.Delete(0, iCc.Length());

    // Read attachment & parse text into buffers
    CPlainText* textAtt = CPlainText::NewL();
    CleanupStack::PushL(textAtt);
    TBuf<KAttachmentTextLimit> buf; // temp buffer

    CDesC16ArrayFlat* attArr = new (ELeave)CDesC16ArrayFlat(4);
    CleanupStack::PushL(attArr);
    // Get message attachments from MMS engine
    // message only has one attachment that is combined of two parts: url and description text.
    // Those parts are read and separated here. 
    if( iMmsEngine->GetObjectsL(*attArr) )
        {
        // we know there is only one file path in the array
        textAtt->ImportTextFileL( 0, (TDes16&)(*attArr)[0], CPlainText::EOrganiseByLine );
        textAtt->Extract( buf, 0);

        // locate field separator and read data
        TInt pos;
        User::LeaveIfError(pos = buf.Locate(';'));
        iUrl = buf.Left(pos);
        iDesc = buf.Right( buf.Length() - (pos+1) );
        }

    CleanupStack::PopAndDestroy(2); // attArr, textAtt
    
    // Read addressees   
    // To:
    const CDesC16Array& arr = iMmsEngine->GetAddresseesL(ETypeTo);
    for(TInt i = 0; i < arr.Count(); i++)    
        {        
        iTo.Append(arr[i]);        
        if(i < (arr.Count() - 1) )        
            {            
            iTo.Append('\n');            
            }    
        }
    // 
    // Cc:
    const CDesC16Array& arr2 = iMmsEngine->GetAddresseesL(ETypeCc);    
    for(TInt j = 0; j < arr2.Count(); j++)    
        {        
        iCc.Append(arr2[j]);
        
        if(j < (arr.Count() - 1) )        
            {            
            iCc.Append('\n');
            }            
        }
    }

// ----------------------------------------------------
// CMMSDemo1AppUi::ReadMessagesL(TMsvId aFolder)
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::ReadMessagesL(TMsvId aFolder)
    {
    // Updating Navi pane information
    iNaviPane->Pop();
    delete iNaviDecorator;
    TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader,	R_MMSDEMO1_NAVI_READ);
	iNaviDecorator = iNaviPane->CreateNavigationLabelL(reader);
	CleanupStack::PopAndDestroy();  // resource reader
	iNaviPane->PushL(*iNaviDecorator);

    // read all MMSs and give them to the user in a list control
    // This list will be populated by ReadMessagesL call below.
    CDesC16ArrayFlat* messageDescriptors = new(ELeave)CDesC16ArrayFlat(5);
    CleanupStack::PushL(messageDescriptors);
    if(iSelection)
        {
        delete iSelection;
        }
    iSelection = iMmsEngine->ReadMessagesL(aFolder, *messageDescriptors);

    // launch selection list
    if( iContainer->DisplayTheListboxL( *messageDescriptors ) )
        {
        iListOpen = ETrue;
        iContainer->DrawNow();
        }
    else  // could not open the list (messageDescriptors was empty)
        {
        iListOpen = EFalse;
        iFunctionId = 0;     // reset function addressing index

        _LIT(KNote, "Folder contains no MMS messages");
        CAknGlobalNote* globalNote = CAknGlobalNote::NewLC();
	    globalNote->ShowNoteL(EAknGlobalInformationNote, KNote);
        CleanupStack::PopAndDestroy(); // GlobalNote

        }
    // When list is closed we get an application command 
    // (EMMSDemo1CmdSelect/EMMSDemo1CmdCancel) that is handled in HandleCommandL()
    // after this, reading is completed in CompleteReadL().
    CleanupStack::PopAndDestroy(); // messageDescriptors
    }

// ----------------------------------------------------
// CMMSDemo1AppUi::CompleteReadL()
// ?implementation_description
// ----------------------------------------------------
//
TMsvId CMMSDemo1AppUi::CompleteReadL()
    {
    // the user has selected one message from the list
    // and the Id of that message is returned into iListIndex (see: HandleCommandL())
    TMsvId id = 0;
    if(iFormReply) // This is 1 if user pressed "select", else 0
        {
        id = (*iSelection)[iListIndex];
        }

    // free memory
    if(iSelection)
        {
        delete iSelection;
        iSelection = NULL;
        }     
    
    return id;  // return the right TMsvId for the selected message item
    }

// ----------------------------------------------------
// CMMSDemo1AppUi::DeleteMessagesL(TMsvId aFolder)
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::DeleteMessagesL(TMsvId aFolder)
    {
    // Idea of deleting is that user selects messages from list one at a time
    // and presses "cancel" when he is done deleting.

    TMsvId id = CompleteReadL(); 
    iMmsEngine->DeleteMessageL(aFolder, id);
    // Launch the same function again (re-open the listbox, 
    // user can delete messages one by one until he presses "cancel") 
    ReadMessagesL(aFolder); 
    }

// ----------------------------------------------------
// CMMSDemo1AppUi::ReplyL()
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::ReplyL()
    {
    // Updating Navi pane information
    iNaviPane->Pop();
    delete iNaviDecorator;
    TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader,	R_MMSDEMO1_NAVI_REPLY);
	iNaviDecorator = iNaviPane->CreateNavigationLabelL(reader);
	CleanupStack::PopAndDestroy();  // resource reader
	iNaviPane->PushL(*iNaviDecorator);
    
    TMsvId msgId;
    if(!iMessageOpen)
        {
        msgId = CompleteReadL();
        }
    else
        {
        msgId = iMsgId;
        }

    if( msgId != NULL )
        {        
        iReply = ETrue;
        // create reply msg by the MMS engine
        // mmsengine loads the forward msg. automatically
        iMmsEngine->CreateReplyL(msgId);

        // read msg params into local data
        UpdateDescriptorsL();
        // show message on screen
        iForm = CMMSDemo1Form::NewL(ETrue,iUrl,iDesc,iTo,iCc);	
        iForm->ExecuteLD(R_MYFORMS_DIALOG);
        }
    iReply = EFalse;
    // reset launcher attribute
    iFunctionId = 0;
    }

// ----------------------------------------------------
// CMMSDemo1AppUi::ForwardL()
// ?implementation_description
// ----------------------------------------------------
//
void CMMSDemo1AppUi::ForwardL()
    {
    // Updating Navi pane information
    iNaviPane->Pop();
    delete iNaviDecorator;
    TResourceReader reader;
	iCoeEnv->CreateResourceReaderLC(reader,	R_MMSDEMO1_NAVI_FORWARD);
	iNaviDecorator = iNaviPane->CreateNavigationLabelL(reader);
	CleanupStack::PopAndDestroy();  // resource reader
	iNaviPane->PushL(*iNaviDecorator);

    TMsvId msgId;
    if(!iMessageOpen)
        {
        msgId = CompleteReadL();
        }
    else
        {
        msgId = iMsgId;
        }

    if( msgId != NULL )
        {
        iForward = ETrue;
        // create forward msg by the MMS engine
        // mmsengine loads the forward msg. automatically
        iMmsEngine->CreateForwardL( msgId );

        // read msg params into local data
        UpdateDescriptorsL();
        // show message on screen NOTICE: here we give a last parameter ETrue
        // to indicate that this message is a forward 
        // (user can't edit the URL and Description fields)
        iForm = CMMSDemo1Form::NewL(ETrue,iUrl,iDesc,iTo,iCc, ETrue);	
        iForm->ExecuteLD(R_MYFORMS_DIALOG);
        }
    iForward = EFalse;
    // reset launcher attribute
    iFunctionId = 0;
    }

/*
-----------------------------------------------------------------------------

    CMMSDemo1AppUi::OpenFileL()
    
	Return values:	N/A
    
-----------------------------------------------------------------------------
*/
void CMMSDemo1AppUi::OpenFileL(const TDesC& aFileName)
	{
	// Are we in embedded mode ? (iDoorObserver != NULL)
	if( iDoorObserver )
		{
        // open objects and show them on screen
        // Read attachment & parse text into buffers
        CPlainText* textAtt = CPlainText::NewL();
        CleanupStack::PushL(textAtt);

        // Read file
        textAtt->ImportTextFileL( 0, (TDes16&)aFileName, CPlainText::EOrganiseByLine );

        TBuf<KAttachmentTextLimit> buf; // temp buffer
        textAtt->Extract( buf, 0);

        CleanupStack::PopAndDestroy();  // textAtt


        // locate field separator and read data
        TInt pos;
        User::LeaveIfError(pos = buf.Locate(';'));

        iUrl = buf.Left(pos);
        iDesc = buf.Right( buf.Length() - (pos+1) );

        // Showing only URL text on screen
        iContainer->SetTextL(iUrl, iUrl.Length());    
		}		
	}

// End of File  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -