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

📄 gdsms.cpp

📁 send SMS example. send SMS example.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*

        GDSMS.CPP - source file for GDSMS application
        

*/

 
#include <txtrich.h>                // for CRichText
#include <smscmds.h>                // for TSmsMtmCommand (asynchronous sms commands)
#include <eikenv.h>                 // for CEikonEnv
#include <smuthdr.h>                // for CSmsHeader
#include <smsetdlg.h>               // for CSmsAddServiceCentreDialog
#include <comabs.h>                 // for CCommandAbsorbingControl
#include <mtclreg.h>                // for CClientMtmRegistry 
#include <smutset.h>                // for CSmsMessageSettings

#include "gdsms.h"                  // own definitions
#include "gdsms.hrh"                // own resource header
#include <gdsms.rsg>


// this is the content of the message
_LIT(KGDSMSTag, "GDSM");



// Own constants
const TUid KUidGDSMS = { 0x101F3CD9 };      // GDSMS application UID 
const TInt KTagLength = 4;                  // length of our message tag
const TInt KMaxTelephoneNumberLength = 30;  // maximum length for a gsm number


//
// CGDSMSTelNumDialog
//

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

    CGDSMSTelNumDialog::CGDSMSTelNumDialog()

    C++ constructor

    Return values:      None

-----------------------------------------------------------------------------
*/
CGDSMSTelNumDialog::CGDSMSTelNumDialog(TDesC& aRecipientsTelNum)
    : iRecipientsTelNum(&aRecipientsTelNum)                         // Initialise data
    {
    }

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

    CGDSMSTelNumDialog::PreLayoutDynInitL()

    Function for doing pre layout events.

    Return values:      None

-----------------------------------------------------------------------------
*/
void CGDSMSTelNumDialog::PreLayoutDynInitL()  
    {
    (static_cast<CEikTelephoneNumberEditor*>(Control(EGDSMSTelNumEditor)))->SetNumberL(*iRecipientsTelNum);
    }

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

    CGDSMSTelNumDialog::OkToExitL()

    Function for doing on exit events.

    Return values:      ETrue or EFalse

-----------------------------------------------------------------------------
*/
TBool CGDSMSTelNumDialog::OkToExitL(TInt /*aButtonId*/)             // Function for doing on exit events
    {
    TBuf<KMaxTelephoneNumberLength> recipientsTelNum;
    (static_cast<CEikTelephoneNumberEditor*>(Control(EGDSMSTelNumEditor)))->GetNumber(recipientsTelNum);
    if (recipientsTelNum.Length()==0)
        {
        iEikonEnv->InfoMsg(R_GDSMS_TEL_NUMBER_DIALOG);
        return EFalse;
        }
    (static_cast<HBufC*>(iRecipientsTelNum))->Des()=recipientsTelNum; // Number is set to iRecipientsTelNum
    return ETrue;
    }


//
// CGDSMSAppView
//

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

    CGDSMSAppView::NewL()

    2nd phase construction.

    Return values:      CGDSMSAppView*

-----------------------------------------------------------------------------
*/
CGDSMSAppView* CGDSMSAppView::NewL(const TRect& aRect)
    {
    CGDSMSAppView* self=NewLC(aRect);
    CleanupStack::Pop(); // self
    return self;
    }

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

    CGDSMSAppView::NewLC()

    2nd phase construction. Created object is put into CleanupStack
    before calling ConstructL().

    Return values:      CGDSMSAppView*

-----------------------------------------------------------------------------
*/
CGDSMSAppView* CGDSMSAppView::NewLC(const TRect& aRect)
    {
    CGDSMSAppView* self = new(ELeave) CGDSMSAppView();
    CleanupStack::PushL(self);
    self->ConstructL(aRect);
    return self;
    }

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

    CGDSMSAppView::CGDSMSAppView()

    C++ constructor

-----------------------------------------------------------------------------
*/
CGDSMSAppView::CGDSMSAppView()
    {
    }

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

    CGDSMSAppView::ConstructL()

    2nd phase constructor.

    Return values:      CGDSMSAppView*

-----------------------------------------------------------------------------
*/
void CGDSMSAppView::ConstructL(const TRect& aRect)
    {
    CreateWindowL();
    SetRect(aRect);
	ActivateL();
    }

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

    CGDSMSAppView::Draw()

    Simple Draw method (only clears the application area).

-----------------------------------------------------------------------------
*/
void CGDSMSAppView::Draw(const TRect& /*aRect*/) const
    {
    CWindowGc& gc = SystemGc();
    gc.Clear();
    }


//
// CGDSMSAppUi
//

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

  CGDSMSAppUi::ConstructL()                          
  
  2nd phase constructor

-----------------------------------------------------------------------------
*/
void CGDSMSAppUi::ConstructL()
    {

    BaseConstructL();                                   // init this AppUi with standard values
    iAppView=CGDSMSAppView::NewL(ClientRect()); 

    iRecipient=HBufC::NewL(KMaxTelephoneNumberLength);  // for recipient sms number
    iMsvId = NULL;                                      // MsvId for keeping track of the message server entries. 

    // Create CMsvSession
    iSession = CMsvSession::OpenAsyncL(*this); // new session is opened asynchronously
                                               // CompleteConstructL() is called when async finishes

    }

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

    CGDSMSAppUi::~CGDSMSAppUi()

    Destructor.

-----------------------------------------------------------------------------
*/
CGDSMSAppUi::~CGDSMSAppUi()
    {
    delete iAppView;
    
    delete iRecipient;

    delete iMtm;
    delete iMtmReg;

    iMsvId = NULL;

    delete iSession;    // session must be deleted last (and constructed first)
    }




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

    CGDSMSAppUi::CompleteConstructL()

    Creates client MTM registry when session is ready for use. 
    This completes model construction and is called after 'server
    ready' event is received after async opening of CMsvSession.

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

void CGDSMSAppUi::CompleteConstructL()
    {
    // We get a MtmClientRegistry from our session
    // this registry is used to instantiate new mtms.
    iMtmReg = CClientMtmRegistry::NewL(*iSession);

    // notify the user with a InfoWin
    iEikonEnv->InfoWinL(_L("Construction"),_L("Server session opened."));
    }



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

    CGDSMSAppUi::HandleSessionEventL()

    Handles session event observer and calls event handling functions in
    observer. Note that if additional session event handlers are defined in
    the session, they are called before this function (as this is the
    main session observer).

    The type of event is indicated by the value of aEvent. The 
    interpretation of the TAny arguments depends on this type. For most 
    event types, the action that is taken, for example, updating the 
    display, is client-specific. All clients though should respond to 
    EMsvCloseSession and EMsvServerTerminated events. 

-----------------------------------------------------------------------------
*/
void CGDSMSAppUi::HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/)
    {
    switch (aEvent)
        {

        case EMsvEntriesCreated:        // A new entry has been created in the message server
            // We are interested in messages that are created in Inbox
            TMsvId* entryId;
            entryId = static_cast<TMsvId*>(aArg2);          // entry id from the session event
            
            if ( *entryId == KMsvGlobalInBoxIndexEntryId )  // new entry has been created in Inbox folder
                {
                // We take the created entries into a selection
                CMsvEntrySelection* entries = static_cast<CMsvEntrySelection*>(aArg1);

                // entry pointer for making changes in the actual message contexts
                CMsvEntry* entry;

                //Process each created entry, one at a time.
                for(TInt i = 0; i < entries->Count(); i++)
                    {
                    // Setting all messages in the selection as invisible
                    entry = iSession->GetEntryL( entries->At(i) );  // this reserves memory for a new CMsvEntry
                    TMsvEntry msvEntry(entry->Entry());
                    msvEntry.SetVisible(EFalse);                    // set as invisible

                    if( MessageReceivedL(entries->At(i)) ) // this checks the entry and handles it if it is targeted to GDSMS app   
                        {
                        // this is our message, set also as read
                        msvEntry.SetUnread(EFalse);
                        msvEntry.iMtmData3 = KUidGDSMS.iUid;        // use our app uid as an identifier
                        }
                    else
                        {
                        // message was not for us, settin it as visible again
                        msvEntry.SetVisible(ETrue);
                        }

                    entry->ChangeL( msvEntry );                     // commit changes
                    delete entry;
                    }
                }
            break;

        case EMsvEntriesMoved:      // this event is given when message entries are moved
            {
            // An entry has been moved to another parent
            // We are interested messages that have been moved to Sent folder
            TMsvId* entryId;
            entryId = static_cast<TMsvId*>(aArg2); 

⌨️ 快捷键说明

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