00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TaskManager.hrh"
00013 #include "TaskManagerAppView.h"
00014 #include "TaskManagerAppUi.h"
00015 #include "Response.h"
00016
00017 #include <coemain.h>
00018 #include <aknlists.h>
00019 #include <barsread.h>
00020 #include <aknnotewrappers.h>
00021 #include <SocketTaskManager.rsg>
00022 #include <stringloader.h>
00023 #include <e32std.h>
00024 #include <aknquerydialog.h>
00025
00026
00027 #define KListPosition TPoint(0,0)
00028 _LIT(KTab, "\t");
00029 _LIT(KError, "Error: %d");
00030 _LIT(KNoTasks, "No Tasks!");
00031 _LIT(KLoadingTasks, "Loading tasks...");
00032 _LIT(KCompletingTask, "Completing task...");
00033 _LIT(KTaskCompleted, "\n\nTask completed?");
00034 _LIT(KInvalidTask, "Invalid task. Cannot complete.");
00035 _LIT(KTaskFormat, "%d\t%S");
00036 _LIT(KOpeningConnection, "Opening connection...");
00037 const TInt KMaxErrorLength = 30;
00038
00039
00040
00041
00042
00043 CTaskManagerAppView::CTaskManagerAppView(CTaskManagerAppUi& aAppUi)
00044 : iAppUi(aAppUi)
00045 {
00046 iStatusText = KNoTasks;
00047 }
00048
00049
00050 CTaskManagerAppView::~CTaskManagerAppView()
00051 {
00052 delete iTaskList;
00053 }
00054
00055
00056
00057
00058
00059
00060 CTaskManagerAppView *CTaskManagerAppView::NewL(const TRect& aRect, CTaskManagerAppUi& aAppUi)
00061 {
00062 CTaskManagerAppView *self = new(ELeave) CTaskManagerAppView(aAppUi);
00063 CleanupStack::PushL(self);
00064 self->ConstructL(aRect);
00065 CleanupStack::Pop(self);
00066 return self;
00067 }
00068
00069
00070
00071
00072
00073
00074 void CTaskManagerAppView::ConstructL(const TRect& aRect)
00075 {
00076
00077 CreateWindowL();
00078
00079 CreateListL();
00080
00081
00082 SetRect(aRect);
00083
00084
00085 ActivateL();
00086 }
00087
00088
00089
00090
00091
00092
00093
00094 void CTaskManagerAppView::CreateListL()
00095 {
00096 iTaskList = new (ELeave) CAknSingleStyleListBox;
00097 iTaskList->SetContainerWindowL( *this );
00098
00099 iTaskList->SetListBoxObserver( this );
00100
00101 TResourceReader reader;
00102 iEikonEnv->CreateResourceReaderLC( reader, R_TASKMANAGER_TASKLIST );
00103 iTaskList->ConstructFromResourceL( reader );
00104
00105 iTaskList->MakeVisible( EFalse );
00106
00107 CleanupStack::PopAndDestroy();
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 void CTaskManagerAppView::Draw(const TRect& ) const
00120 {
00121
00122 CWindowGc &gc = SystemGc();
00123
00124
00125 TRect rect = Rect();
00126
00127
00128 gc.Clear(rect);
00129
00130
00131 if( !iTaskList->IsVisible() )
00132 {
00133 gc.UseFont( iCoeEnv->NormalFont() );
00134
00135
00136 TInt pointX = rect.Width() / 2 -
00137 iCoeEnv->NormalFont()->TextWidthInPixels( iStatusText ) / 2;
00138
00139 TInt pointY = rect.Height() / 2 -
00140 iCoeEnv->NormalFont()->HeightInPixels() / 2;
00141
00142 gc.DrawText( iStatusText, TPoint( pointX, pointY ) );
00143 }
00144
00145 }
00146
00147
00148
00149
00150
00151
00152
00153 void CTaskManagerAppView::HandleListBoxEventL(CEikListBox* aListBox,
00154 TListBoxEvent aListBoxEvent)
00155 {
00156 if( aListBoxEvent == MEikListBoxObserver::EEventEnterKeyPressed )
00157 {
00158
00159 const MDesCArray* items = aListBox->Model()->MatchableTextArray();
00160
00161
00162 TPtrC pointer = items->MdcaPoint( aListBox->CurrentItemIndex() );
00163
00164 TInt tabOffSet = pointer.Find(KTab);
00165
00166 if (tabOffSet == KErrNotFound || tabOffSet == 0)
00167 {
00168 CAknInformationNote *informationNote = new(ELeave) CAknInformationNote;
00169 informationNote->ExecuteLD(KInvalidTask);
00170 return;
00171 }
00172
00173 TLex lex(pointer.Left(tabOffSet));
00174 TInt taskId;
00175 User::LeaveIfError(lex.Val(taskId));
00176
00177
00178 TBuf<KMaxTaskLength + 20> message = pointer.Mid(tabOffSet+1);
00179 message.Append( KTaskCompleted );
00180
00181
00182 CAknQueryDialog* note = CAknQueryDialog::NewL();
00183 CleanupStack::PushL(note);
00184 note->SetPromptL( message );
00185 CleanupStack::Pop(note);
00186
00187 iAppUi.SetViewBusyL(ETrue);
00188
00189
00190 if( note->ExecuteLD( R_TASKMANAGER_TASK_CONFIRMATION_QUERY ) )
00191 {
00192
00193 ShowStatus(KCompletingTask);
00194
00195 iAppUi.ShowConnectingCbaL(ETrue);
00196 iAppUi.Model().MarkTaskDoneL(taskId);
00197 iTransactionStatus = EMarkingTaskDone;
00198 }
00199
00200 iAppUi.SetViewBusyL(EFalse);
00201 }
00202 }
00203
00204
00205
00206
00207
00208
00209 void CTaskManagerAppView::DeleteSelectedTaskL()
00210 {
00211 CTextListBoxModel* model = iTaskList->Model();
00212 CDesCArray* itemArray = static_cast<CDesCArray*>( model->ItemTextArray() );
00213
00214 TInt currentItem = iTaskList->CurrentItemIndex();
00215
00216 itemArray->Delete( currentItem );
00217
00218 AknListBoxUtils::HandleItemRemovalAndPositionHighlightL( iTaskList,
00219 currentItem,
00220 ETrue );
00221
00222 iTaskList->DrawNow();
00223
00224
00225 if( model->NumberOfItems() == 0 )
00226 {
00227 iTaskList->MakeVisible( EFalse );
00228 }
00229 }
00230
00231
00232
00233
00234
00235
00236 void CTaskManagerAppView::ReadTasksL( const CResponse& aResponse )
00237 {
00238 CTextListBoxModel* model = iTaskList->Model();
00239
00240 model->SetOwnershipType( ELbmOwnsItemArray );
00241 CDesCArray* itemArray = static_cast<CDesCArray*>( model->ItemTextArray() );
00242
00243 itemArray->Reset();
00244
00245 TInt taskCount = aResponse.TaskCount();
00246
00247 TBuf<KMaxTaskLength+10> taskDesc;
00248 for (TInt i = 0; i < taskCount; i++)
00249 {
00250 TBuf<KMaxTaskLength> desc = aResponse.TaskDescription(i);
00251 taskDesc.Format(KTaskFormat, aResponse.TaskId(i), &desc);
00252 itemArray->AppendL(taskDesc);
00253 }
00254
00255
00256 if( model->NumberOfItems() > 0 )
00257 {
00258 iTaskList->HandleItemAdditionL();
00259 iTaskList->DrawNow();
00260 iTaskList->MakeVisible( ETrue );
00261 }
00262 }
00263
00264
00265
00266
00267
00268
00269
00270 TInt CTaskManagerAppView::CountComponentControls() const
00271 {
00272 TInt count = 0;
00273 if (iTaskList)
00274 {
00275 count++;
00276 }
00277
00278 return count;
00279 }
00280
00281
00282
00283
00284
00285
00286 CCoeControl* CTaskManagerAppView::ComponentControl( TInt aIndex ) const
00287 {
00288 switch( aIndex )
00289 {
00290 case 0:
00291 return iTaskList;
00292 default:
00293 return 0;
00294 };
00295 }
00296
00297
00298
00299
00300
00301
00302
00303 void CTaskManagerAppView::SizeChanged()
00304 {
00305 iTaskList->SetExtent( KListPosition, iTaskList->MinimumSize() );
00306 }
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316 TKeyResponse CTaskManagerAppView::OfferKeyEventL( const TKeyEvent& aKeyEvent,
00317 TEventCode aType )
00318 {
00319 if( iTaskList && iTaskList->IsVisible() )
00320 {
00321 return iTaskList->OfferKeyEventL( aKeyEvent, aType );
00322 }
00323 else
00324 {
00325 return EKeyWasNotConsumed;
00326 }
00327 }
00328
00329
00330
00331
00332
00333
00334 void CTaskManagerAppView::OpeningConnectionL()
00335 {
00336 ShowStatus(KOpeningConnection);
00337 iAppUi.ShowConnectingCbaL(ETrue);
00338 }
00339
00340
00341
00342
00343
00344
00345 void CTaskManagerAppView::ConnectingToServerL(const TBool& aLoadingTasks)
00346 {
00347 if (aLoadingTasks)
00348 {
00349 ShowStatus(KLoadingTasks);
00350 }
00351 else
00352 {
00353 ShowStatus(KCompletingTask);
00354 }
00355
00356
00357 iAppUi.ShowConnectingCbaL(ETrue);
00358 }
00359
00360
00361
00362
00363
00364
00365
00366 void CTaskManagerAppView::SuccessL(const CResponse& aResponse)
00367 {
00368
00369
00370 if (aResponse.HasError())
00371 {
00372 CAknInformationNote *informationNote = new(ELeave) CAknInformationNote;
00373 informationNote->ExecuteLD(aResponse.Error());
00374 }
00375
00376 else
00377 {
00378
00379 if (iTransactionStatus == EMarkingTaskDone)
00380 {
00381 iTransactionStatus = EFetchingTasks;
00382 DeleteSelectedTaskL();
00383 }
00384
00385 else
00386 {
00387 ReadTasksL(aResponse);
00388 }
00389 }
00390
00391
00392 ShowStatus(KNoTasks);
00393
00394 iAppUi.ShowConnectingCbaL(EFalse);
00395 }
00396
00397
00398
00399
00400
00401
00402 void CTaskManagerAppView::FailedL(const TInt& aError)
00403 {
00404 TBuf<KMaxErrorLength> error;
00405 error.Format(KError, aError);
00406 CAknInformationNote *informationNote = new(ELeave) CAknInformationNote;
00407 informationNote->ExecuteLD(error);
00408
00409
00410 ShowStatus(KNoTasks);
00411
00412 iAppUi.ShowConnectingCbaL(EFalse);
00413 }
00414
00415
00416
00417
00418
00419
00420
00421 void CTaskManagerAppView::CancelledL()
00422 {
00423
00424 ShowStatus(KNoTasks);
00425
00426 iAppUi.ShowConnectingCbaL(EFalse);
00427 }
00428
00429
00430
00431
00432
00433
00434
00435
00436 void CTaskManagerAppView::ErrorL(const TDesC& aErrorMsg)
00437 {
00438 CAknInformationNote *informationNote = new(ELeave) CAknInformationNote;
00439 informationNote->ExecuteLD(aErrorMsg);
00440
00441
00442 ShowStatus(KNoTasks);
00443
00444 iAppUi.ShowConnectingCbaL(EFalse);
00445 }
00446
00447
00448
00449
00450
00451
00452
00453 TBool CTaskManagerAppView::QueryIapL(TUint32& aId, const TUint32& aDefaultId)
00454 {
00455 TBool retval = EFalse;
00456 RArray<TIap>& iaps = iAppUi.Model().Iaps();
00457 TInt iapCount = iaps.Count();
00458
00459 CDesCArrayFlat* iapArray = new (ELeave) CDesCArrayFlat(iapCount);
00460 CleanupStack::PushL(iapArray);
00461
00462 TInt selectedIndex = 0;
00463
00464
00465 for (TInt i = 0; i < iapCount; i++)
00466 {
00467 if (iaps[i].iId == aDefaultId)
00468 {
00469 selectedIndex = i;
00470 }
00471 iapArray->AppendL(iaps[i].iName);
00472 }
00473
00474 TInt index(0);
00475 CAknListQueryDialog* query = new (ELeave) CAknListQueryDialog(&index);
00476 query->PrepareLC(R_TASKMANAGER_IAP_LIST_QUERY);
00477 query->SetItemTextArray(iapArray);
00478 query->SetOwnershipType(ELbmDoesNotOwnItemArray);
00479 query->ListBox()->SetCurrentItemIndex(selectedIndex);
00480 if (query->RunLD())
00481 {
00482 aId = iaps[index].iId;
00483 retval = ETrue;
00484 }
00485
00486 CleanupStack::PopAndDestroy(iapArray);
00487 return retval;
00488 }
00489
00490
00491
00492
00493
00494
00495 void CTaskManagerAppView::ShowStatus(const TDesC& aStatus)
00496 {
00497 iStatusText = aStatus;
00498
00499
00500 if (aStatus == KNoTasks)
00501 {
00502 if (iTaskList->Model()->NumberOfItems() > 0)
00503 {
00504 iTaskList->MakeVisible(ETrue);
00505 }
00506 }
00507
00508 else
00509 {
00510 iTaskList->MakeVisible(EFalse);
00511 }
00512
00513 DrawNow();
00514 }
00515
00516