examples/SFExamples/symbian_os_communications_programming_book_v2/chapter9/SendWorkBench/SendWorkbenchS60/src/SendWorkbenchAppUi.cpp

00001 // 
00002 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
00003 // All rights reserved.
00004 // This component and the accompanying materials are made available
00005 // under the terms of the License "Eclipse Public License v1.0"
00006 // which accompanies this distribution, and is available
00007 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 // 
00009 // Initial Contributors:
00010 // Nokia Corporation - initial contribution.
00011 // 
00012 // Contributors:
00013 // 
00014 // Description:
00015 // 
00016 
00017 
00018 // INCLUDE FILES
00019 #include <avkon.hrh>
00020 #include <SendWorkbench.rsg>
00021 #include <f32file.h>
00022 #include "SendWorkbench.pan"
00023 #include <sendui.h>
00024 #include <cmessagedata.h>
00025 #include <TXTRICH.H>
00026 #include <aknnotewrappers.h>
00027 #include "SendWorkbenchAppView.h"
00028 #include "SendWorkbenchAppUi.h"
00029 #include "SendWorkbench.hrh"
00030 #include "Sender.h"
00031 
00032 
00033 _LIT(KPrivateAttachmentFile, "c:\\private\\A0009979\\sendasexample.jpg");
00034 _LIT(KPublicAttachmentFile, "c:\\data\\images\\sendasexample.jpg");
00035 
00036 // ============================ MEMBER FUNCTIONS ===============================
00037 
00038 
00039 
00040 // -----------------------------------------------------------------------------
00041 // CSendWorkbenchAppUi::CSendWorkbenchAppUi()
00042 // C++ default constructor can NOT contain any code, that might leave.
00043 // -----------------------------------------------------------------------------
00044 
00045 CSendWorkbenchAppUi::CSendWorkbenchAppUi()
00046     {
00047     // No implementation required
00048     }
00049   
00050 // -----------------------------------------------------------------------------
00051 // CSendWorkbenchAppUi::ConstructL()
00052 // Symbian 2nd phase constructor can leave.
00053 // -----------------------------------------------------------------------------
00054 //
00055 void CSendWorkbenchAppUi::ConstructL()
00056         {
00057         BaseConstructL(EAknEnableSkin);
00058         iSendUI = CSendUi::NewL();
00059         
00060         // Create view object
00061         iAppView = CSendWorkbenchAppView::NewL( ClientRect(), *this );
00062         AddToStackL(iAppView);
00063         }
00064   
00065 
00066 // -----------------------------------------------------------------------------
00067 // CSendWorkbenchAppUi::~CSendWorkbenchAppUi()
00068 // Destructor.
00069 // -----------------------------------------------------------------------------
00070 //
00071 CSendWorkbenchAppUi::~CSendWorkbenchAppUi()
00072     {
00073     if ( iAppView )
00074         {
00075         RemoveFromStack(iAppView);
00076         delete iAppView;
00077         iAppView = NULL;
00078         }
00079     
00080         delete iSendUI;
00081 
00082     }
00083 
00084 void CSendWorkbenchAppUi::DynInitMenuPaneL(TInt aResourceId, CEikMenuPane *aMenuPane)
00085         {
00086         using namespace SendTypes;
00087         switch (aResourceId)
00088          {
00089          case R_MENU:
00090             {                    
00091                           
00092                 TSendContentType type = iAppView->CurrentSelection();
00093                 if ( (type!=ESendAs) && (type!=EEditAndSendAs) )                
00094                         {// Enable SendUI menu option and disable SendAs menu options
00095                         aMenuPane->SetItemDimmed(ECommandSendText, ETrue);
00096                         aMenuPane->SetItemDimmed(ECommandSendAndEditText, ETrue);       
00097                         iSendUI->AddSendMenuItemL(*aMenuPane,0, ECommandSendItem);
00098                         }
00099                 
00100                 if (type==ESendAs)
00101                         aMenuPane->SetItemDimmed(ECommandSendAndEditText, ETrue);
00102                 else if (type==EEditAndSendAs)  
00103                         aMenuPane->SetItemDimmed(ECommandSendText, ETrue);
00104                         
00105                 break;
00106             } 
00107          }
00108         }
00109 
00110 void CSendWorkbenchAppUi::DynInitMenuBarL(TInt /*aResourceId*/, CEikMenuBar* /*aMenuBar*/)
00111         {
00112         }
00113         
00114 
00115 
00116 
00117 CRichText* PrepareSmallTextLC()
00118         {
00119         _LIT(KTextSmall, "This is a small message which should easily fit into a single SMS");
00120         
00121         CEikonEnv& ee = *CEikonEnv::Static();
00122         
00123         CRichText* rt = CRichText::NewL(ee.SystemParaFormatLayerL(), ee.SystemCharFormatLayerL());      
00124         CleanupStack::PushL(rt);
00125         rt->InsertL(0,KTextSmall);
00126         
00127         return rt;
00128         }
00129 
00130 CRichText* PrepareLargeTextLC()
00131         {
00132         _LIT(KTextLarge,"This is a large repeating message which should not easily fit into a single SMS ");            
00133         const TInt KNumberOfRepeats = 100;
00134         
00135         CEikonEnv& ee = *CEikonEnv::Static();
00136         
00137         CRichText* rt = CRichText::NewL(ee.SystemParaFormatLayerL(), ee.SystemCharFormatLayerL());      
00138         CleanupStack::PushL(rt);
00139         for(TInt i=0; i<KNumberOfRepeats; i++)
00140                 {
00141                 rt->InsertL(0,KTextLarge); // zero is the begining of the text
00142                 }
00143                 
00144         return rt;
00145         }
00146 
00147 void CSendWorkbenchAppUi::HandleSendMenuL()
00148         {
00149         using namespace SendTypes;
00150         
00151         TSendContentType type = iAppView->CurrentSelection();
00152 
00153         CMessageData* data = CMessageData::NewLC();
00154                 
00155         const TInt KMaximumSizeUnknown = 0;
00156         const TInt KMaximumSizeForSmallMessage = 255;
00157         
00158         TSendingCapabilities sc(0,0,TSendingCapabilities::EAllServices);
00159 
00160         switch(type)
00161                 {
00162                 case ESendUISmallText:
00163                         sc = TSendingCapabilities(KMaximumSizeForSmallMessage,KMaximumSizeForSmallMessage, TSendingCapabilities::ESupportsBodyText);
00164                         CRichText* rtSmall = PrepareSmallTextLC();
00165                         data->SetBodyTextL(rtSmall);
00166                         
00167                         iSendUI->ShowQueryAndSendL(data, sc);
00168                         CleanupStack::PopAndDestroy(2,data);
00169                 break;
00170                 case ESendUILargeText:
00171                         sc = TSendingCapabilities(KMaximumSizeForSmallMessage,KMaximumSizeForSmallMessage, TSendingCapabilities::ESupportsBodyText);            
00172                         CRichText* rtLarge = PrepareLargeTextLC();
00173                         data->SetBodyTextL(rtLarge);    
00174                         
00175                         iSendUI->ShowQueryAndSendL(data, sc);
00176                         CleanupStack::PopAndDestroy(2,data);
00177                 break;
00178                 case ESendUIJPEG:
00179                         sc = TSendingCapabilities(KMaximumSizeUnknown,KMaximumSizeUnknown, TSendingCapabilities::ESupportsAttachments);                 
00180                         data->AppendAttachmentL(KPublicAttachmentFile);
00181                         
00182                         iSendUI->ShowQueryAndSendL(data, sc);
00183                         CleanupStack::PopAndDestroy(data);
00184                 break;
00185                 
00186                 case ESendUIPrivateJPEG:
00187                         {
00188                         sc = TSendingCapabilities(KMaximumSizeUnknown,KMaximumSizeUnknown, TSendingCapabilities::ESupportsAttachments);
00189                         RFs pfs;
00190                         User::LeaveIfError(pfs.Connect());
00191                         CleanupClosePushL(pfs);
00192                         pfs.ShareProtected();
00193                         RFile file;
00194                         User::LeaveIfError(file.Open(pfs, KPrivateAttachmentFile ,EFileRead));                  
00195                         CleanupClosePushL(file);
00196                         data->AppendAttachmentHandleL(file);    
00197                         CleanupStack::PopAndDestroy(2,&pfs);
00198                         
00199                         iSendUI->ShowQueryAndSendL(data, sc);
00200                         CleanupStack::PopAndDestroy(data);
00201                         }
00202                 break;
00203                 
00204                 case ESendAs:
00205                 Sender::SendAnSMSL();
00206                 break;
00207         
00208                 case EEditAndSendAs:
00209                 Sender::EditAndSendSMSL();                              
00210         break;
00211                 default:
00212                         ASSERT(EFalse); // Should not reach here
00213 
00214                 }
00215         }
00216    
00217     
00218 // -----------------------------------------------------------------------------
00219 // CSendWorkbenchAppUi::HandleCommandL()
00220 // Takes care of command handling.
00221 // -----------------------------------------------------------------------------
00222 //
00223 void CSendWorkbenchAppUi::HandleCommandL( TInt aCommand )
00224     {
00225     switch( aCommand )
00226         {
00227         case EEikCmdExit:
00228         case EAknSoftkeyExit:
00229             Exit();
00230             break;
00231 // This method uses CSendUI
00232         case ECommandSendItem:
00233             HandleSendMenuL();
00234             break;
00235 // Methods below use SendAs 
00236                 case ECommandSendText:
00237                 Sender::SendAnSMSL();
00238                         break;
00239                 
00240         case ECommandSendAndEditText:
00241                 Sender::EditAndSendSMSL();                              
00242                 break;
00243                         
00244         default:
00245             Panic( ESendWorkbenchUi );
00246             break;
00247         }
00248     }
00249 // -----------------------------------------------------------------------------
00250 //  Called by the framework when the application status pane
00251 //  size is changed.  Passes the new client rectangle to the
00252 //  AppView
00253 // -----------------------------------------------------------------------------
00254 void CSendWorkbenchAppUi::HandleStatusPaneSizeChange()
00255         {
00256         iAppView->SetRect( ClientRect() );
00257         } 
00258 
00259 // End of File

Generated by  doxygen 1.6.2