examples/SFExamples/symbian_os_communications_programming_book_v2/chapter9/SendWorkBench/SendWorkbenchUIQ/src/SendWorkbenchUIQView.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 <QikCommand.h>
00019 #include <SendWorkbenchUIQ.rsg>
00020 #include <eiklabel.h> // CEikLabel
00021 #include <QikSendAs.h>
00022 #include <mtmuids.h>
00023 #include <QikSendAsLogic.h>
00024 #include <QikListBox.h>
00025 #include <MQikListBoxModel.h>
00026 #include <MQikListBoxData.h>
00027 #include <TXTRICH.H>
00028 
00029 #include "SendWorkbenchUIQAppUi.h"
00030 #include "SendWorkbenchUIQView.h"
00031 #include "SendWorkbenchUIQ.hrh"
00032 #include "SendWorkbenchUIQGlobals.h"
00033 #include "SendWorkBenchTypes.h"
00034 #include "Sender.h"
00035 _LIT(KPrivateAttachmentFile, "C:\\private\\AA1C30BB\\sendasexample.jpg");
00036 _LIT(KAttachmentSource, "c:\\images\\sendasexample.jpg");
00037 
00038 CRichText* PrepareSmallTextLC()
00039         {
00040         CEikonEnv& ee = *CEikonEnv::Static();
00041         
00042         CRichText* rt = CRichText::NewL(ee.SystemParaFormatLayerL(), ee.SystemCharFormatLayerL());      
00043         CleanupStack::PushL(rt);
00044         rt->InsertL(0,_L("This is a small message which should easily fit into a single SMS"));
00045         
00046         return rt;
00047         }
00048 
00049 CRichText* PrepareLargeTextLC()
00050         {
00051         CEikonEnv& ee = *CEikonEnv::Static();
00052         
00053         CRichText* rt = CRichText::NewL(ee.SystemParaFormatLayerL(), ee.SystemCharFormatLayerL());      
00054         CleanupStack::PushL(rt);
00055         for(TInt i=0; i<100; i++)
00056                 {
00057                 rt->InsertL(0,_L("This is a large repeating message which is too big to fit entirely into a single SMS "));
00058                 }
00059                 
00060         return rt;
00061         }
00062 
00068 CSendWorkbenchUIQView* CSendWorkbenchUIQView::NewLC(CQikAppUi& aAppUi)
00069         {
00070         CSendWorkbenchUIQView* self = new(ELeave) CSendWorkbenchUIQView(aAppUi);
00071         CleanupStack::PushL(self);
00072         self->ConstructL();
00073         return self;
00074         }
00075 
00080 CSendWorkbenchUIQView::CSendWorkbenchUIQView(CQikAppUi& aAppUi)
00081         : CQikViewBase(aAppUi, KNullViewId)
00082         {
00083         }
00084 
00088 CSendWorkbenchUIQView::~CSendWorkbenchUIQView()
00089         {
00090         }
00091 
00092 
00093 void CSendWorkbenchUIQView::ConstructL()
00094         {
00095         // Calls ConstructL that initialises the standard values.
00096         // This should always be called in the concrete view implementations.
00097         CQikViewBase::ConstructL();
00098         }
00099 
00104 void CSendWorkbenchUIQView::ViewConstructL()
00105         {
00106         // Loads information about the UI configurations this view supports
00107         // together with definition of each view.
00108         ViewConstructFromResourceL(R_UI_CONFIGURATIONS);
00109         // Get a pointer to the List Box control
00110         CQikListBox* lbx = LocateControlByUniqueHandle<CQikListBox>(ESendWorkbenchUIQListbox);
00111         if(lbx)
00112             {
00113                 MQikListBoxModel& model(lbx->Model());
00114                 model.ModelBeginUpdateLC(); 
00115 
00116                 _LIT(KListItem1, "\tSend short text");
00117                 _LIT(KListItem2, "\tSend long text");
00118                 _LIT(KListItem3, "\tSend JPEG");
00119                 _LIT(KListItem4, "\tSend private JPEG");
00120                 _LIT(KListItem5, "\tUse SendAs to send");
00121                 _LIT(KListItem6, "\tUse SendAs to edit & send");
00122          
00123         // Do your adds/removes/etc here
00124                 MQikListBoxData* data = model.NewDataLC(MQikListBoxModel::EDataNormal);        
00125                 data->AddTextL(KListItem1, EQikListBoxSlotText1); 
00126                 CleanupStack::PopAndDestroy(data);    
00127         
00128                 data = model.NewDataLC(MQikListBoxModel::EDataNormal); 
00129                 data->AddTextL(KListItem2, EQikListBoxSlotText1); 
00130                 CleanupStack::PopAndDestroy(data);        
00131         
00132                 data = model.NewDataLC(MQikListBoxModel::EDataNormal); 
00133                 data->AddTextL(KListItem3, EQikListBoxSlotText1); 
00134                 CleanupStack::PopAndDestroy(data); 
00135         
00136                 data = model.NewDataLC(MQikListBoxModel::EDataNormal); 
00137                 data->AddTextL(KListItem4, EQikListBoxSlotText1); 
00138                 CleanupStack::PopAndDestroy(data); 
00139         
00140                 data = model.NewDataLC(MQikListBoxModel::EDataNormal); 
00141                 data->AddTextL(KListItem5, EQikListBoxSlotText1); 
00142                 CleanupStack::PopAndDestroy(data); 
00143                 
00144                 data = model.NewDataLC(MQikListBoxModel::EDataNormal); 
00145                 data->AddTextL(KListItem6, EQikListBoxSlotText1); 
00146                 CleanupStack::PopAndDestroy(data); 
00147                 
00148                 lbx->SetListBoxObserver(this);
00149                 model.ModelEndUpdateL();  
00150            }    
00151         else
00152                 User::Leave(KErrNotFound);
00153         }
00154 
00160 TVwsViewId CSendWorkbenchUIQView::ViewId()const
00161         {
00162         return TVwsViewId(KUidSendWorkbenchUIQApp, KUidSendWorkbenchUIQView);
00163         }
00164 
00165 void CSendWorkbenchUIQView::HandleListBoxEventL(CQikListBox* aListBox, TQikListBoxEvent aEventType,
00166                                                                                         TInt /*aItemIndex*/, TInt /*aSlotId*/)
00167         {
00168         switch(aEventType)
00169                 {
00170                 case EEventItemConfirmed:
00171                 case EEventItemTapped:
00172                         {// An item has been selected
00173                         HandleSendDialogL(aListBox);
00174                         }
00175                 break;
00176                 default: // Nothing to do
00177                 break;
00178                 };
00179         }
00180 
00181 /*
00182 Handles all commands in the view
00183 Called by the UI framework when a command has been issued.
00184 The command Ids are defined in the .hrh file.
00185 
00186 @param aCommand The command to be executed
00187 @see CQikViewBase::HandleCommandL
00188 */
00189 void CSendWorkbenchUIQView::HandleSendDialogL(CQikListBox* aListBox)
00190         {
00191         ASSERT(aListBox);
00192         using namespace SendTypes;
00193                 
00194         TSendContentType type = static_cast<TSendContentType>(aListBox->CurrentItemIndex());
00195         CQikSendAsLogic* sendAsLogic;
00196         
00197         TUid capability(TUid::Null());
00198         switch(type)
00199                 {       
00200         case ESendUISmallText:
00201                 CRichText* smallText = PrepareSmallTextLC();    
00202                 _LIT(KSmallText, "Small Text");
00203                 sendAsLogic = CQikSendAsLogic::NewL(smallText, KNullDesC, KSmallText);
00204                 CleanupStack::Pop(smallText);
00205                 // RunDlgLD() takes ownership of sendAsLogic and smallText and destroys them on return
00206                 // regardless of the success or failure of the RunDlgLD() call itself
00207                 CQikSendAsDialog::RunDlgLD(sendAsLogic, capability); 
00208                 break;  
00209         case ESendUILargeText:
00210                 CRichText* largeText = PrepareLargeTextLC();    
00211                 _LIT(KLargeText, "Large Text");
00212                 sendAsLogic = CQikSendAsLogic::NewL(largeText, KNullDesC, KLargeText);  
00213                 CleanupStack::Pop(largeText);
00214                 // RunDlgLD() takes ownership of sendAsLogic and largeText and destroys them on return
00215                 // regardless of the success or failure of the RunDlgLD() call itself
00216                 CQikSendAsDialog::RunDlgLD(sendAsLogic, capability); 
00217                 break;
00218         case ESendUIJPEG:
00219                 _LIT(KAttachmentText, "Jpeg");
00220                 sendAsLogic = CQikSendAsLogic::NewL(NULL, KAttachmentSource, KAttachmentText);
00221                 capability = KUidMtmQuerySupportAttachments;
00222                 // RunDlgLD() takes ownership of sendAsLogic and destroys it on return
00223                 // regardless of the success or failure of the RunDlgLD() call itself
00224                 CQikSendAsDialog::RunDlgLD(sendAsLogic, capability); 
00225                 break; 
00226         case ESendUIPrivateJPEG:
00227                 {
00228                 sendAsLogic = CQikSendAsLogic::NewL();
00229                 CleanupStack::PushL(sendAsLogic);
00230                 
00231                 RFs pfs;
00232                 User::LeaveIfError(pfs.Connect());
00233                 CleanupClosePushL(pfs);
00234                 pfs.ShareProtected();
00235                 RFile file;
00236                                 
00237                 User::LeaveIfError(file.Open(pfs, KPrivateAttachmentFile, EFileRead));
00238                 CleanupStack::Pop(&pfs);                
00239                 sendAsLogic->AddAttachmentL(file);      
00240                 capability = KUidMtmQuerySupportAttachments;
00241                 CleanupStack::Pop(sendAsLogic);
00242                 // RunDlgLD() takes ownership of sendAsLogic and destroys it on return
00243                 // regardless of the success or failure of the RunDlgLD() call itself
00244                 CQikSendAsDialog::RunDlgLD(sendAsLogic, capability); 
00245                 }
00246                 break;
00247                 
00248         case ESendAsSend:
00249                 Sender::SendAnSMSL();
00250                 break;
00251         
00252         case ESendAsEditAndSend:
00253                 Sender::EditAndSendSMSL();
00254                 break;
00255 
00256         default:
00257                 ASSERT(EFalse);
00258                 };   
00259         }
00260 
00261 void CSendWorkbenchUIQView::HandleCommandL(CQikCommand& aCommand)
00262         {
00263         CQikViewBase::HandleCommandL(aCommand);
00264         }

Generated by  doxygen 1.6.2