examples/Messaging/BIOMessageMgr/Src/BIOMessage.cpp

00001 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 //
00015 
00016 #include "BIOMessage.h"
00017 
00018 
00019 CBioMessage::CBioMessage()
00020         {       
00021                 
00022         }
00023 
00029 CBioMessage::~CBioMessage()
00030         {       
00031         iSendAs.Close();
00032         delete iConsole;
00033         }
00034 
00035 CBioMessage* CBioMessage::NewL()
00036         {
00037         CBioMessage* self = new (ELeave) CBioMessage();
00038         CleanupStack::PushL(self);
00039         self->ConstructL();
00040         CleanupStack::Pop();
00041         return self;
00042         }
00043 
00047 void CBioMessage::ConstructL()
00048         {
00049         
00050         iConsole = Console::NewL(KTestTitle,TSize(KConsFullScreen,KConsFullScreen));
00051         _LIT(KTextWelcome, "### BIO messaging ### \n");
00052         iConsole->Printf ( KTextWelcome );
00053 
00054         _LIT(KTextStartApp, "\n Starting the BIO message application ............ \n");
00055         iConsole->Printf ( KTextStartApp );
00056         
00057         _LIT(KTextPressAKey, "\n Press any key to step through the example ............ \n");
00058         iConsole->Printf ( KTextPressAKey );
00059         iConsole->Getch ();
00060 
00061         _LIT(KTextInit, "\n #1. Intializing ............ \n");
00062         iConsole->Printf ( KTextInit );
00063         
00064         iConsole->Getch ();     
00065                 
00066         }       
00067 
00068 void CBioMessage::StartL()
00069         {
00070         Connect();
00071         RSendAsMessage message;
00072         CreateL(message);
00073         SendL(message);
00074         
00075         _LIT(KTextParserTitle, " \n\n### BIO Message Parsing ### \n");
00076         iConsole->Printf ( KTextParserTitle );
00077         
00078         ParseL();       
00079         CleanupStack::PopAndDestroy(4, iObserver); //selection, iEntry, iSession, iObserver
00080         }
00081 
00087 void CBioMessage::Connect()
00088         {
00089         _LIT(KTextConn, "\n #2. Connecting to message server ............ \n");
00090         iConsole->Printf ( KTextConn );
00091         iConsole->Getch ();
00092 
00093         TInt err = iSendAs.Connect(KSendAsDefaultMessageSlots);
00094         if ( err == KErrNone)
00095                 {
00096                 _LIT(KTextErrInn, "\n Connection is successful\n");
00097                 iConsole->Printf ( KTextErrInn );
00098 
00099                 }
00100         else
00101                 {
00102                 _LIT(KTextErrOut, "\n\n Connection has failed\n");
00103                 iConsole->Printf ( KTextErrOut );
00104                 }
00105         }
00106 
00107 void CBioMessage::CleanMailFolderL(TMsvId aFolderId)
00108         {
00109         CDummyObserver* observer = new(ELeave) CDummyObserver;
00110         CleanupStack::PushL(observer);
00111         CMsvSession* session = CMsvSession::OpenSyncL(*observer);
00112         CleanupStack::PushL(session);   
00113         CMsvEntry* entry = CMsvEntry::NewL(*session, aFolderId, 
00114                 TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue));
00115         CleanupStack::PushL(entry);
00116         
00117         CMsvEntrySelection* selection = entry->ChildrenL();
00118         CleanupStack::PushL(selection);
00119 
00120         TMsvLocalOperationProgress progress;
00121         if (selection->Count() > 0)
00122                 {
00123                 entry->DeleteL(*selection, progress);
00124                 }
00125 
00126         CleanupStack::PopAndDestroy(4); // selection, entry, session, observer
00127         }
00128 
00133 void CBioMessage::CreateL( RSendAsMessage& aMessage)
00134         {
00135         CSendAsMessageTypes* messageTypes = CSendAsMessageTypes::NewL();
00136         CleanupStack::PushL(messageTypes);      
00137 
00138         iSendAs.FilteredMessageTypesL(*messageTypes);
00139 
00140         TUid sendAsMtmUid;
00141                 
00142         // Returning the message UID based on the message type 
00143         // such as 0 for SMTP Client, 1 for SMS Client, 2 for Infrared client MTM and 3 for Bluetooth client MTM.
00144         sendAsMtmUid = messageTypes->UidFromNameL(_L("SMS Client"));
00145         
00146         CleanupStack::PopAndDestroy(messageTypes);      
00147 
00148         _LIT(KTextCreate, "\n #3. Creating a BIO message ............ \n");
00149         iConsole->Printf ( KTextCreate );
00150         iConsole->Getch ();
00151         
00152         CleanMailFolderL(KMsvDraftEntryId);
00153         
00154         iObserver = new(ELeave) CDummyObserver;
00155         CleanupStack::PushL(iObserver);
00156         iSession = CMsvSession::OpenSyncL(*iObserver);
00157         CleanupStack::PushL(iSession);
00158         iEntry = CMsvEntry::NewL(*iSession, KMsvDraftEntryId, 
00159         TMsvSelectionOrdering(KMsvNoGrouping,EMsvSortByNone,ETrue));
00160         CleanupStack::PushL(iEntry);
00161 
00162         iSelection = iEntry->ChildrenL();
00163         CleanupStack::PushL(iSelection);
00164         
00165         TInt count = iSelection->Count();
00166         if ( count == 0) // Check no message
00167                 {
00168                 CleanupStack::PopAndDestroy(iSelection);
00169                 iSelection = NULL;
00170                 }       
00171 
00172         aMessage.CreateL(iSendAs, sendAsMtmUid);
00173         aMessage.SetBodyTextL(KBodyText);
00174         aMessage.AddRecipientL(KAddress1, KAlias1, RSendAsMessage::ESendAsRecipientTo);
00175         aMessage.AddRecipientL(KAddress3, RSendAsMessage::ESendAsRecipientCc);
00176         aMessage.AddRecipientL(KAddress4, KAlias2, RSendAsMessage::ESendAsRecipientCc);
00177 
00178         TUid bioType = KUidBIOVCardMsg;
00179         aMessage.SetBioTypeL(bioType);  
00180         iEntry->SetEntryL(KMsvSentEntryId);
00181         
00182         
00183                 
00184         iEntry->SetEntryL(KMsvDraftEntryId);
00185         iSelection = iEntry->ChildrenL();
00186         CleanupStack::PushL(iSelection);        
00187         if(iSelection->Count() >= 1)
00188                 {
00189                 iEntry->SetEntryL((*iSelection)[0]);
00190                 }
00191         }
00192 
00197 void CBioMessage::SendL(RSendAsMessage& aMessage)
00198         {
00199         _LIT(KTextSend, "\n #4. Sending the BIO message ............ \n");
00200         iConsole->Printf ( KTextSend );
00201         iConsole->Getch ();
00202         
00203         CMsvOperationWait* wait = CMsvOperationWait::NewLC();
00204         wait->iStatus = KRequestPending;
00205         wait->Start();
00206         
00207         aMessage.SendMessageAndCloseL();
00208         
00209         CleanupStack::PopAndDestroy();  // wait
00210         
00211         _LIT(KTextClose, "\n The BIO message has been sent \n");
00212         iConsole->Printf ( KTextClose );
00213         iConsole->Getch ();
00214         }
00215 
00219 void CBioMessage::ParseL()
00220         {
00221         _LIT(KTextParse, "\n #5. Parsing the BIO message ............ \n");
00222         iConsole->Printf ( KTextParse );
00223         iConsole->Getch ();
00224         
00225         CBioParser* bioParser = CBioParser::NewL(iEntry);
00226         bioParser->ParserL();
00227         
00228         _LIT(KTextParsed, "\n The BIO message has been parsed \n");
00229         iConsole->Printf ( KTextParsed );
00230         iConsole->Getch ();
00231         
00232         delete bioParser;
00233         }
00234 
00235 LOCAL_C void MainL()
00236         {
00237         CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
00238         CActiveScheduler::Install( scheduler );
00239         
00240         CBioMessage* app = CBioMessage::NewL();
00241         CleanupStack::PushL(app);
00242         app->StartL();
00243         CleanupStack::PopAndDestroy(app);
00244         
00245         delete scheduler;
00246         }
00247 
00248 GLDEF_C TInt E32Main()
00249         {
00250     __UHEAP_MARK;
00251     CTrapCleanup* cleanup = CTrapCleanup::New();
00252     if(cleanup == NULL)
00253         {
00254         return KErrNoMemory;
00255         }
00256     TRAPD(err, MainL());
00257         if(err != KErrNone)
00258                 {       
00259                 User::Panic(_L("failed to complete"),err);
00260                 }
00261 
00262     delete cleanup;
00263     __UHEAP_MARKEND;
00264     return KErrNone;
00265         }

Generated by  doxygen 1.6.2