00001
00002
00003
00004
00005 #include <aknviewappui.h>
00006 #include <aknconsts.h>
00007 #include <aknnotewrappers.h>
00008 #include <msvids.h>
00009 #include <smsexample.rsg>
00010
00011 #include "SMSExampleListboxView.h"
00012 #include "SMSExampleLogView.h"
00013 #include "SMSExampleMarkableListContainer.h"
00014 #include "SmsExample.hrh"
00015 #include "SMSExampleAppUi.h"
00016
00017 _LIT(KMessages, " messages");
00018 _LIT(KCopiedMessages, "Copied ");
00019 _LIT(KDeletedMessages, "Deleted ");
00020 _LIT(KMovedMessages, "Moved ");
00021 _LIT(KNoMessagesInFolder, "there are no messages in that source folder!");
00022
00023 const TInt KMaxMessageCount(100);
00024
00025
00026
00027
00028
00029
00030 CListboxView* CListboxView::NewL(CSmsEngine* aEngine, CLogView* aView1)
00031 {
00032 CListboxView* self = CListboxView::NewLC(aEngine, aView1);
00033 CleanupStack::Pop(self);
00034
00035 return self;
00036 }
00037
00038
00039
00040
00041
00042
00043 CListboxView* CListboxView::NewLC(CSmsEngine* aEngine, CLogView* aView1)
00044 {
00045 CListboxView* self = new (ELeave) CListboxView(aEngine, aView1);
00046 CleanupStack::PushL(self);
00047 self->ConstructL();
00048 return self;
00049 }
00050
00051
00052
00053
00054
00055
00056
00057 CListboxView::CListboxView(CSmsEngine* aEngine, CLogView* aView1):
00058 iEngine(aEngine), iLogView(aView1)
00059 {
00060 iListBoxContainer = 0;
00061 }
00062
00063
00064
00065
00066
00067
00068 CListboxView::~CListboxView()
00069 {
00070 delete iListBoxContainer;
00071 iListBoxContainer = NULL;
00072
00073 iEngine = 0;
00074 iLogView = 0;
00075 }
00076
00077
00078
00079
00080
00081
00082 void CListboxView::ConstructL()
00083 {
00084 BaseConstructL(R_LISTBOX_MULTIVIEWS_VIEW);
00085 }
00086
00087
00088
00089
00090
00091
00092 TUid CListboxView::Id() const
00093 {
00094 return TUid::Uid(EListboxViewId);
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 void CListboxView::DoActivateL(const TVwsViewId& ,
00107 TUid ,
00108 const TDesC8& )
00109 {
00110 iListBoxContainer = CMarkableListContainer::NewL(ClientRect());
00111
00112 iListBoxContainer->SetMopParent(this);
00113
00114 AppUi()->AddToStackL(*this, iListBoxContainer);
00115 InitializeListBoxL();
00116 }
00117
00118
00119
00120
00121
00122
00123
00124
00125 void CListboxView::SetFolderID(TMsvId aFolderID)
00126 {
00127 iFolderID = aFolderID;
00128 }
00129
00130
00131
00132
00133
00134
00135
00136 void CListboxView::InitializeListBoxL()
00137 {
00138
00139
00140 if ( iFolderID != KMsvGlobalInBoxIndexEntryId &&
00141 iFolderID != KMsvGlobalOutBoxIndexEntryId &&
00142 iFolderID != KMsvDraftEntryId )
00143 {
00144 User::Leave(KErrArgument);
00145 }
00146
00147
00148
00149 CDesCArrayFlat* arrayAddr = 0;
00150 CDesCArrayFlat* arrayMsgBody = 0;
00151 iEngine->GetFolderSMSMessageInformationL(iFolderID,arrayAddr,arrayMsgBody);
00152 iListBoxContainer->SetArraysL( arrayAddr, arrayMsgBody );
00153
00154 RArray<TMsvId>* array = iEngine->GetMessageIds();
00155 iListBoxContainer->SetIdArray ( array );
00156
00157
00158 if ( array->Count() == 0 )
00159 {
00160 iLogView->LogEventBeginningL();
00161 iLogView->DrawTextL( KNoMessagesInFolder );
00162
00163 RArray<TMsvId>* selected = iListBoxContainer->GetSelectedItems();
00164 selected->Reset();
00165 delete selected;
00166 selected = 0;
00167
00168 AppUi()->ActivateLocalViewL(TUid::Uid(ELogViewId));
00169 }
00170 }
00171
00172
00173
00174
00175
00176
00177 void CListboxView::DoDeactivate()
00178 {
00179 if (iListBoxContainer)
00180 {
00181 AppUi()->RemoveFromStack(iListBoxContainer);
00182 delete iListBoxContainer;
00183 iListBoxContainer = NULL;
00184 }
00185 }
00186
00187
00188
00189
00190
00191
00192 void CListboxView::SetListBoxMode(TInt aMode)
00193 {
00194 iMode = aMode;
00195 }
00196
00197
00198
00199
00200
00201
00202 void CListboxView::SetTargetFolderID(TMsvId aTargetFolderID)
00203 {
00204 iTargetFolderID = aTargetFolderID;
00205 }
00206
00207
00208
00209
00210
00211
00212 void CListboxView::HandleClientRectChange()
00213 {
00214 if ( iListBoxContainer )
00215 {
00216 iListBoxContainer->SetRect( ClientRect() );
00217 }
00218 }
00219
00220
00221
00222
00223
00224
00225 void CListboxView::HandleBasedOnModeL()
00226 {
00227 RArray<TMsvId>* array = iListBoxContainer->GetSelectedItems();
00228
00229 if ( !array )
00230 {
00231 return;
00232 }
00233
00234
00235 if ( iMode == ESMSExampleModeCopy )
00236 {
00237
00238 for (TInt i = 0; i < array->Count(); i++)
00239 {
00240 iEngine->CopyMessageL( (*array)[i], iTargetFolderID );
00241 }
00242
00243 iLogView->LogEventBeginningL();
00244 TBuf<KMaxMessageCount> textBuffer;
00245 textBuffer.Append( KCopiedMessages );
00246 textBuffer.AppendNum( array->Count() );
00247 textBuffer.Append(KMessages);
00248
00249 iLogView->DrawTextL( textBuffer );
00250 }
00251
00252
00253 else if ( iMode == ESMSExampleDelete )
00254 {
00255
00256 for (TInt i = 0; i < array->Count(); i++)
00257 {
00258 iEngine->DeleteMessageL( (*array)[i] );
00259 }
00260
00261 iLogView->LogEventBeginningL();
00262 TBuf<KMaxMessageCount> textBuffer;
00263 textBuffer.Append( KDeletedMessages );
00264 textBuffer.AppendNum( array->Count() );
00265 textBuffer.Append(KMessages);
00266
00267 iLogView->DrawTextL( textBuffer );
00268 }
00269
00270
00271 else if ( iMode == ESMSExampleMove )
00272 {
00273
00274 for (TInt i = 0; i < array->Count(); i++)
00275 {
00276 iEngine->MoveToFolderL( (*array)[i], iTargetFolderID );
00277 }
00278
00279 iLogView->LogEventBeginningL();
00280 TBuf<KMaxMessageCount> textBuffer;
00281 textBuffer.Append( KMovedMessages );
00282 textBuffer.AppendNum( array->Count() );
00283 textBuffer.Append(KMessages);
00284
00285 iLogView->DrawTextL( textBuffer );
00286 }
00287
00288 array->Reset();
00289 delete array;
00290 array = 0;
00291
00292 AppUi()->ActivateLocalViewL(TUid::Uid(ELogViewId));
00293 iMode = 0;
00294 }
00295
00296
00297
00298
00299
00300
00301 void CListboxView::HandleCommandL(TInt aCommand)
00302 {
00303 switch ( aCommand )
00304 {
00305 case EAknSoftkeyBack:
00306 {
00307
00308 RArray<TMsvId>* array = iListBoxContainer->GetSelectedItems();
00309 array->Reset();
00310 delete array;
00311 array = 0;
00312
00313
00314 AppUi()->ActivateLocalViewL(TUid::Uid(ELogViewId));
00315
00316 break;
00317 }
00318 case ESMSExampleListBoxSelectAll:
00319 {
00320
00321 iListBoxContainer->MarkAllL(ETrue);
00322 break;
00323 }
00324 case ESMSExampleListBoxDeSelectAll:
00325 {
00326
00327 iListBoxContainer->MarkAllL(EFalse);
00328 break;
00329 }
00330 case ESMSExampleListBoxDone:
00331 {
00332
00333
00334
00335 TRAPD(err, HandleBasedOnModeL() );
00336 if( err )
00337 {
00338 _LIT(KErrText, "Error in SMS handling");
00339 CSMSExampleAppUi* appui =
00340 static_cast <CSMSExampleAppUi*> (AppUi());
00341 appui->ShowMessageL( KErrText );
00342 appui->ShowErrorL(err);
00343 }
00344 break;
00345 }
00346 default:
00347 {
00348 AppUi()->HandleCommandL( aCommand );
00349 break;
00350 }
00351 }
00352 }
00353
00354 void CListboxView::SizeChanged()
00355 {
00356 if( iListBoxContainer )
00357 {
00358 iListBoxContainer->SetRect( ClientRect() );
00359 }
00360 }
00361
00362