Exemplo n.º 1
0
void CSmsFile::send_messageL(const TDesC& recipient, const TDesC& body)
{
    if (iStatus==KRequestPending) {
        User::Leave(KErrServerBusy);
    }

    state=_L("send_messageL");

    TMsvEntry newEntry;								 // This represents an entry in the Message Server index
    newEntry.iMtm = KUidMsgTypeSMS;                         // message type is CSmsFile
    newEntry.iType = KUidMsvMessageEntry;                   // this defines the type of the entry: message
    newEntry.iServiceId = KMsvLocalServiceIndexEntryId;     // ID of local service (containing the standard folders)
    newEntry.iDate.HomeTime();                              // set the date of the entry to home time

    newEntry.SetInPreparation(ETrue);                       // a flag that this message is in preparation


    // get ref to outbox
    state=_L("NewL");
    CMsvEntry *entry =CMsvEntry::NewL(*iSession, KMsvGlobalOutBoxIndexEntryId ,TMsvSelectionOrdering());
    CleanupStack::PushL(entry);

    // create message in outbox
    state=_L("CreateL");
    entry->CreateL(newEntry);

    state=_L("GetEntry");
    entry = iSession->GetEntryL(newEntry.Id());

    // SetCurrentEntryL takes ownership of the CMsvEntry
    state=_L("SetCurrentEntry");
    iMtm->SetCurrentEntryL(entry);

    CleanupStack::Pop(); // entry

    state=_L("Entry()");
    TMsvEntry msvEntry = (iMtm->Entry()).Entry();

    state=_L("Body()");
    CRichText& mtmBody = iMtm->Body();
    mtmBody.Reset();

    state=_L("set message");
    mtmBody.InsertL(0, body);   // insert our msg tag as the body text

    // set iRecipient into the Details of the entry
    msvEntry.iDetails.Set(recipient);  // set recipient info in details
    msvEntry.SetInPreparation(EFalse);         // set inPreparation to false

    msvEntry.SetSendingState(KMsvSendStateWaiting);   // set the sending state (immediately)
    msvEntry.iDate.HomeTime();                        // set time to Home Time

    // To handle the CSmsFile specifics we start using SmsMtm
    CSmsClientMtm* smsMtm = STATIC_CAST(CSmsClientMtm*, iMtm);

    state=_L("RestoreServiceAndSettingsL");
    smsMtm->RestoreServiceAndSettingsL();

    state=_L("set header");
    // CSmsHeader encapsulates data specific for CSmsFile messages,
    // like service center number and options for sending.
    CSmsHeader& header = smsMtm->SmsHeader();
    state=_L("get options");

    if (!sendOptions) {
        sendOptions = CSmsSettings::NewL();
        sendOptions->CopyL(smsMtm->ServiceSettings()); // restore existing settings
        state=_L("SetDelivery");
        sendOptions->SetDelivery(ESmsDeliveryImmediately);      // set to be delivered immediately
    }

    // set send options
    // ERROR HERE!
    state=_L("SetSmsSettingsL");
    header.SetSmsSettingsL(*sendOptions);

    state=_L("check sc");
    // let's check if there's sc address
    if (header.Message().ServiceCenterAddress().Length() == 0)
    {
        // no, there isn't. We assume there is at least one sc number set and use
        // the default SC number.
        CSmsSettings* serviceSettings = &(smsMtm->ServiceSettings());

        // if number of scaddresses in the list is null
        if (!serviceSettings->NumSCAddresses())
        {
            // FIXME: what to do?
            User::Leave(1);
        } else {
            // set sc address to default.
            CSmsNumber* sc = 0;
            sc = &(serviceSettings->SCAddress(serviceSettings->DefaultSC()));
            header.Message().SetServiceCenterAddressL(sc->Address());
        }
    }

    state=_L("add addresses");
    // Add our recipient to the list, takes in two TDesCs, first is real address and second is an alias
    // works also without the alias parameter.
    smsMtm->AddAddresseeL(recipient, msvEntry.iDetails);

    // if message is to be deleted after sending, mark with our UID
    msvEntry.iMtmData3 = KUidRippleVaultApp.iUid;

    state=_L("save");
    // save message
    iMtm->Entry().ChangeL(msvEntry);                // make sure that we are handling the right entry
    smsMtm->SaveMessageL();                 // closes the message

    state=_L("move");
    // This moves the message entry to outbox, we'll schedule it for sending after this.
    //    TMsvId movedId = MoveMessageEntryL( KMsvGlobalOutBoxIndexEntryId );  // move message to outbox
    TMsvId movedId = iMtm->Entry().Entry().Id();

    // We must create an entry selection for message copies (although now we only have one message in selection)
    CMsvEntrySelection* selection = new (ELeave) CMsvEntrySelection;
    CleanupStack::PushL(selection);

    selection->AppendL(movedId);            // add our message to the selection

    TBuf8<1> dummyParams;
    //    CCommandAbsorbingControl::NewLC();

    state=_L("InvokeAsyncFunctionL");
    // invoking async schedule copy command on our mtm
    op=iMtm->InvokeAsyncFunctionL(
           ESmsMtmCommandScheduleCopy,
           *selection,
           dummyParams,
           iStatus);

    CleanupStack::Pop(); // selection

#ifdef __LOGME__
    iAppUi.LogText.Copy(_L("SENT\n"));
    iAppUi.WriteLogFile(iAppUi.LogText);
#endif

    SetActive();

    //return KErrNone;
}