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