|
1 /* |
|
2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implementation of CCbsUiTopicLIstView class. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <AknUtils.h> // AknTextUtils |
|
23 #include <bldvariant.hrh> // for feature flags |
|
24 #include <featmgr.h> // for feature manager |
|
25 #include <e32def.h> |
|
26 #include <akntitle.h> |
|
27 #include <aknViewAppUi.h> |
|
28 #include <aknnavide.h> |
|
29 #include <akntitle.h> |
|
30 #include <avkon.hrh> |
|
31 #include <barsread.h> |
|
32 #include <StringLoader.h> |
|
33 #include <eikmenup.h> |
|
34 #include <aknnotewrappers.h> |
|
35 #include <hlplch.h> |
|
36 #include <cbsuiApp.rsg> |
|
37 #include "MCbs.h" |
|
38 #include "CCbsUiTopicListView.h" |
|
39 #include "CCbsUiTopicListViewContainer.h" |
|
40 #include "CCbsUiEditTopicDlg.h" |
|
41 #include "Cbsuiapp.hrh" |
|
42 #include "CbsUiPanic.h" |
|
43 #include "CbsUiConstants.h" |
|
44 #include "CCbsUiAddFromIndexDialog.h" |
|
45 #include "CbsUiDebug.h" |
|
46 #include <AknNotifyStd.h> // ECellBroadcastNotification |
|
47 #include <AknSoftNotifier.h> // Soft Notification API |
|
48 |
|
49 |
|
50 // CONSTANTS |
|
51 const TInt KTopicNameLenght = 20; |
|
52 const TInt KCountOfAllTopics = 1000; |
|
53 const TInt KIndexTopic = 0; |
|
54 const TInt KTwoTopics = 2; |
|
55 |
|
56 // MODULE DATA STRUCTURES |
|
57 enum TMessageCounts { EManyNewMessages = -1, ENoNewMessages = 0, EOneNewMessage = 1 }; |
|
58 |
|
59 |
|
60 // ================= MEMBER FUNCTIONS ======================= |
|
61 |
|
62 // C++ default constructor can NOT contain any code, that |
|
63 // might leave. |
|
64 // |
|
65 CCbsUiTopicListView::CCbsUiTopicListView( MCbs& aServer ) : iServer( aServer ), iFocusState( ENoFocusUpdate ) |
|
66 { |
|
67 } |
|
68 |
|
69 // Symbian OS default constructor can leave. |
|
70 void CCbsUiTopicListView::ConstructL() |
|
71 { |
|
72 BaseConstructL(R_CBSUI_TOPICLISTVIEW); |
|
73 iTopicNumberList = new (ELeave) TCbsUiTopicNumberList(KNumberOfStandardTopics); |
|
74 CEikStatusPane* statusPane = StatusPane(); |
|
75 iNaviPane = STATIC_CAST( CAknNavigationControlContainer*, statusPane-> |
|
76 ControlL( TUid::Uid(EEikStatusPaneUidNavi) ) ); |
|
77 __ASSERT_DEBUG( iNaviPane, CbsUiPanic(ENaviPaneError) ); |
|
78 } |
|
79 |
|
80 // Two-phased constructor. |
|
81 CCbsUiTopicListView* CCbsUiTopicListView::NewL( MCbs& aServer ) |
|
82 { |
|
83 CCbsUiTopicListView* self = new (ELeave) CCbsUiTopicListView(aServer); |
|
84 CleanupStack::PushL(self); |
|
85 self->ConstructL(); |
|
86 CleanupStack::Pop(); |
|
87 return self; |
|
88 } |
|
89 |
|
90 // Destructor |
|
91 CCbsUiTopicListView::~CCbsUiTopicListView() |
|
92 { |
|
93 if ( iContainer ) |
|
94 { |
|
95 AppUi()->RemoveFromViewStack(*this, iContainer); |
|
96 } |
|
97 delete iContainer; |
|
98 delete iDecoratedLabel; |
|
99 delete iTopicNumberList; |
|
100 delete iBackgroundNote; |
|
101 } |
|
102 |
|
103 // --------------------------------------------------------- |
|
104 // CCbsUiTopicListView::ReloadTopicsL |
|
105 // |
|
106 // |
|
107 // --------------------------------------------------------- |
|
108 // |
|
109 void CCbsUiTopicListView::ReloadTopicsL() |
|
110 { |
|
111 __ASSERT_DEBUG( iTopicNumberList, CbsUiPanic(ETopicHandleError) ); |
|
112 PrepareReloading(); |
|
113 ReloadL(); |
|
114 EndReloadingL(); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------- |
|
118 // CCbsUiTopicListView::PrepareReloading |
|
119 // |
|
120 // --------------------------------------------------------- |
|
121 // |
|
122 void CCbsUiTopicListView::PrepareReloading() |
|
123 { |
|
124 if ( iContainer ) |
|
125 { |
|
126 iContainer->ReloadStarts(); |
|
127 } |
|
128 } |
|
129 |
|
130 // --------------------------------------------------------- |
|
131 // CCbsUiTopicListView::ReloadL |
|
132 // |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 void CCbsUiTopicListView::ReloadL() |
|
136 { |
|
137 iTopicNumberList->Reset(); |
|
138 |
|
139 TInt count(0); |
|
140 iServer.GetTopicCount(count); |
|
141 __ASSERT_DEBUG( count >= 0, CbsUiPanic(ETopicCountError) ); |
|
142 |
|
143 TCbsTopic topic; |
|
144 |
|
145 for ( TInt index(0); index < count; index++ ) |
|
146 { |
|
147 // First, get the topic. |
|
148 TInt rr( iServer.GetTopic(index, topic) ); |
|
149 __CBSUI_ASSERT( rr == KErrNone, CbsUiPanic(EErrTopicNotFound) ); |
|
150 |
|
151 if ( rr == KErrNone ) |
|
152 { |
|
153 // Offer the topic to the view. |
|
154 if ( iContainer ) |
|
155 { |
|
156 iContainer->ReloadOfferTopicL(topic); |
|
157 } |
|
158 |
|
159 // And append to the handles list. |
|
160 iTopicNumberList->AppendL(topic.iNumber); |
|
161 } |
|
162 } |
|
163 } |
|
164 |
|
165 void CCbsUiTopicListView::EndReloadingL() |
|
166 { |
|
167 iContainer->ReloadEndsL(); |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------- |
|
171 // CCbsUiTopicListView::SetFocusAfterReload |
|
172 // |
|
173 // --------------------------------------------------------- |
|
174 // |
|
175 void CCbsUiTopicListView::SetFocusAfterReload( TTopicListViewFocusState aFocusState ) |
|
176 { |
|
177 if ( aFocusState == ENoFocusUpdate ) |
|
178 { |
|
179 return; |
|
180 } |
|
181 |
|
182 // if the focus need to be changed |
|
183 TInt focusedItem(KCbsErrValue); |
|
184 |
|
185 TBool setFocusToFirstItem( |
|
186 (aFocusState == ESetFocusToFirstItem) || |
|
187 (FindTopicIndexByNumber(focusedItem, iCurrentTopicNumber) != KErrNone) |
|
188 ); |
|
189 |
|
190 if ( setFocusToFirstItem ) |
|
191 { |
|
192 // If there is some error let's try to put focus to first item |
|
193 focusedItem = 0; |
|
194 } |
|
195 |
|
196 __ASSERT_DEBUG( focusedItem != KCbsErrValue, CbsUiPanic(EErrInvalidValue) ); |
|
197 |
|
198 SetFocusToTopic(focusedItem); |
|
199 } |
|
200 |
|
201 // --------------------------------------------------------- |
|
202 // CCbsUiTopicListView::SetFocusToTopic |
|
203 // |
|
204 // --------------------------------------------------------- |
|
205 // |
|
206 void CCbsUiTopicListView::SetFocusToTopic( TInt aIndex ) |
|
207 { |
|
208 if ( iTopicNumberList->Count() <= 0) |
|
209 { |
|
210 return; |
|
211 } |
|
212 |
|
213 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iTopicNumberList->Count(), |
|
214 CbsUiPanic(EErrIndexOutOfBounds) ); |
|
215 |
|
216 if (iContainer) |
|
217 { |
|
218 // first one in the list is the newest |
|
219 iContainer->SetCurrentItemIndex(aIndex); |
|
220 } |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // CCbsUiTopicListView::UpdateCurrentTopicAfterDeletion |
|
225 // |
|
226 // --------------------------------------------------------- |
|
227 // |
|
228 void CCbsUiTopicListView::UpdateCurrentTopicAfterDeletion( TCbsTopicNumber aDeletedTopic ) |
|
229 { |
|
230 |
|
231 TInt topicPosition(-1); |
|
232 TInt err( FindTopicIndexByNumber(topicPosition, aDeletedTopic) ); |
|
233 |
|
234 TBool isLastTopic( |
|
235 ( (topicPosition + 1) == TotalTopics() ) && |
|
236 (topicPosition >= 0) |
|
237 ); |
|
238 |
|
239 if ( isLastTopic ) |
|
240 { |
|
241 // then previous topic should be focused after deletion |
|
242 topicPosition--; |
|
243 } |
|
244 else |
|
245 { |
|
246 // then the next topic will be focused after deletion |
|
247 topicPosition++; |
|
248 } |
|
249 |
|
250 // if there is some error lets put the focus to the first item |
|
251 if ( topicPosition >= TotalTopics() || |
|
252 topicPosition < 0 || |
|
253 err != KErrNone ) |
|
254 { |
|
255 topicPosition = 0; |
|
256 } |
|
257 |
|
258 __ASSERT_DEBUG( err == KErrNone, CbsUiPanic(EErrMsgNotFound) ); |
|
259 |
|
260 iCurrentTopicNumber = iTopicNumberList->At(topicPosition); |
|
261 } |
|
262 |
|
263 // --------------------------------------------------------- |
|
264 // CCbsUiTopicListView::TotalTopics |
|
265 // |
|
266 // --------------------------------------------------------- |
|
267 // |
|
268 TInt CCbsUiTopicListView::TotalTopics() const |
|
269 { |
|
270 __ASSERT_DEBUG( iTopicNumberList->Count() >= 0, CbsUiPanic(EErrTopicsCountError) ); |
|
271 return iTopicNumberList->Count(); |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------- |
|
275 // CCbsUiTopicListView::UpdateTitlePaneL |
|
276 // |
|
277 // --------------------------------------------------------- |
|
278 // |
|
279 void CCbsUiTopicListView::UpdateTitlePaneL() const |
|
280 { |
|
281 CEikStatusPane *sp = StatusPane(); |
|
282 CAknTitlePane *title = STATIC_CAST(CAknTitlePane*, sp-> |
|
283 ControlL( TUid::Uid(EEikStatusPaneUidTitle) ) ); |
|
284 |
|
285 __ASSERT_DEBUG( sp && title, CbsUiPanic(EStatusOrTitlePaneError) ); |
|
286 |
|
287 TResourceReader titleReader; |
|
288 iCoeEnv->CreateResourceReaderLC(titleReader, R_QTN_CB_TITLE_CBS); |
|
289 title->SetFromResourceL(titleReader); |
|
290 CleanupStack::PopAndDestroy(); // titleReader |
|
291 } |
|
292 |
|
293 // --------------------------------------------------------- |
|
294 // CCbsUiTopicListView::UpdateNaviPaneL |
|
295 // |
|
296 // |
|
297 // --------------------------------------------------------- |
|
298 // |
|
299 void CCbsUiTopicListView::UpdateNaviPaneL() |
|
300 { |
|
301 |
|
302 if ( iAddFromIndexDialogIsActive ) |
|
303 { |
|
304 // No need to update navi pane |
|
305 return; |
|
306 } |
|
307 |
|
308 // let's keep a address of the previous |
|
309 // label so it is possible to delete |
|
310 // it, after the new label has been created. |
|
311 CAknNavigationDecorator* oldLabel = iDecoratedLabel; |
|
312 |
|
313 TInt unreadMessages(0); |
|
314 iServer.GetUnreadMessageCount(unreadMessages); |
|
315 |
|
316 CreateNewLabelL( GetInfoResourceId(unreadMessages), unreadMessages ); |
|
317 |
|
318 // Old label has to be deleted and |
|
319 // the final label is destroyed in the destructor. |
|
320 if ( oldLabel ) |
|
321 { |
|
322 delete oldLabel; |
|
323 } |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------- |
|
327 // CCbsUiTopicListView::GetInfoResourceId |
|
328 // |
|
329 // |
|
330 // --------------------------------------------------------- |
|
331 // |
|
332 TInt CCbsUiTopicListView::GetInfoResourceId( TInt aUnreadMessages ) const |
|
333 { |
|
334 __ASSERT_DEBUG( aUnreadMessages >= 0, CbsUiPanic(EErrInvalidValue) ); |
|
335 |
|
336 TInt result(EManyNewMessages); |
|
337 |
|
338 switch ( aUnreadMessages ) |
|
339 { |
|
340 case ENoNewMessages: |
|
341 result = R_CB_TL_NO_NEW_MESSAGES; |
|
342 break; |
|
343 case EOneNewMessage: |
|
344 result = R_CB_TL_ONE_NEW_MESSAGE; |
|
345 break; |
|
346 default: |
|
347 break; |
|
348 } |
|
349 |
|
350 return result; |
|
351 } |
|
352 |
|
353 // --------------------------------------------------------- |
|
354 // CCbsUiTopicListView::CreateNewLabelL |
|
355 // |
|
356 // |
|
357 // --------------------------------------------------------- |
|
358 // |
|
359 void CCbsUiTopicListView::CreateNewLabelL( TInt aResourceId, TInt aUnreadMessages ) |
|
360 { |
|
361 __ASSERT_DEBUG( |
|
362 aResourceId == EManyNewMessages || |
|
363 aResourceId == R_CB_TL_NO_NEW_MESSAGES || |
|
364 aResourceId == R_CB_TL_ONE_NEW_MESSAGE, |
|
365 CbsUiPanic(EErrInvalidValue) ); |
|
366 |
|
367 HBufC* stringHolder = NULL; |
|
368 |
|
369 if ( aResourceId == EManyNewMessages ) |
|
370 { |
|
371 stringHolder = StringLoader::LoadLC( |
|
372 R_CB_TL_NEW_MESSAGES, aUnreadMessages); |
|
373 } |
|
374 else |
|
375 { |
|
376 stringHolder = iCoeEnv->AllocReadResourceLC(aResourceId); |
|
377 } |
|
378 |
|
379 __ASSERT_DEBUG( stringHolder, CbsUiPanic(EErrNullPointer) ); |
|
380 if ( stringHolder ) |
|
381 { |
|
382 iDecoratedLabel = iNaviPane->CreateNavigationLabelL(*stringHolder); |
|
383 CleanupStack::PopAndDestroy(); // stringholder |
|
384 } |
|
385 |
|
386 __ASSERT_DEBUG( iDecoratedLabel, CbsUiPanic(EErrNullPointer) ); |
|
387 iNaviPane->PushL(*iDecoratedLabel); |
|
388 } |
|
389 |
|
390 // --------------------------------------------------------- |
|
391 // CCbsUiTopicListView::ShowTopicQueryL |
|
392 // |
|
393 // |
|
394 // --------------------------------------------------------- |
|
395 // |
|
396 void CCbsUiTopicListView::ShowTopicQueryL( TBool aType, |
|
397 TDes& aTopicName, |
|
398 TDes& aTopicNumber ) |
|
399 { |
|
400 CCbsUiEditTopicDlg* dlg = CCbsUiEditTopicDlg::NewL( |
|
401 aTopicName, aTopicNumber, *this, aType ); |
|
402 dlg->ExecuteLD( R_EDIT_TOPIC_QUERY ); |
|
403 } |
|
404 |
|
405 // --------------------------------------------------------- |
|
406 // CCbsUiTopicListView::ShowEditTopicQueryL |
|
407 // |
|
408 // |
|
409 // --------------------------------------------------------- |
|
410 // |
|
411 void CCbsUiTopicListView::ShowEditTopicQueryL() |
|
412 { |
|
413 TCbsTopic topic; |
|
414 TInt err( iServer.FindTopicByNumber( iCurrentTopicNumber, topic ) ); |
|
415 |
|
416 if ( err != KErrNone ) |
|
417 { |
|
418 User::Leave( KErrNone ); |
|
419 } |
|
420 |
|
421 TBuf<KTopicNumberWidth> number; |
|
422 number.AppendNum( TInt( topic.iNumber ) ); |
|
423 AknTextUtils::DisplayTextLanguageSpecificNumberConversion( number ); |
|
424 ShowTopicQueryL( EFalse, topic.iName, number ); |
|
425 } |
|
426 |
|
427 // --------------------------------------------------------- |
|
428 // CCbsUiTopicListView::EditTopic |
|
429 // |
|
430 // |
|
431 // --------------------------------------------------------- |
|
432 // |
|
433 TInt CCbsUiTopicListView::EditTopic( TBool aType, |
|
434 TCbsTopicNumber aNumber, |
|
435 const TCbsTopicName aName ) |
|
436 { |
|
437 TInt ret( KErrGeneral ); |
|
438 |
|
439 if ( aType ) // add query |
|
440 { |
|
441 ret = AddTopic(aNumber, aName); |
|
442 } |
|
443 else // edit query |
|
444 { |
|
445 ret = UpdateTopic( iCurrentTopicNumber, aNumber, aName ); |
|
446 if( ret == KErrNone ) |
|
447 { |
|
448 iCurrentTopicNumber = aNumber; |
|
449 } |
|
450 } |
|
451 |
|
452 return ret; |
|
453 } |
|
454 |
|
455 // --------------------------------------------------------- |
|
456 // CCbsUiTopicListView::CheckNewTopicCountL |
|
457 // |
|
458 // |
|
459 // --------------------------------------------------------- |
|
460 // |
|
461 void CCbsUiTopicListView::CheckNewTopicCountL() |
|
462 { |
|
463 iNewTopicsCount = GetNewTopicsCount(); |
|
464 |
|
465 __CBSUI_ASSERT( iNewTopicsCount >= 0, CbsUiPanic(EErrInvalidValue) ); |
|
466 |
|
467 if ( iNewTopicsCount > ENoNewMessages ) |
|
468 { |
|
469 if ( !iBackgroundNote ) |
|
470 { |
|
471 iBackgroundNote = CIdle::NewL(CActive::EPriorityIdle); |
|
472 } |
|
473 |
|
474 TCallBack cb(ActivateBackgroundNoteL, this); |
|
475 iBackgroundNote->Start(cb); |
|
476 } |
|
477 |
|
478 } |
|
479 |
|
480 // --------------------------------------------------------- |
|
481 // CCbsUiTopicListView::GetNewTopicsCount |
|
482 // |
|
483 // |
|
484 // --------------------------------------------------------- |
|
485 // |
|
486 TInt CCbsUiTopicListView::GetNewTopicsCount() |
|
487 { |
|
488 TInt newTopics(KCbsErrValue); |
|
489 if ( iServer.Connected() ) |
|
490 { |
|
491 #ifdef _DEBUG |
|
492 TInt ret = |
|
493 #endif |
|
494 iServer.GetNewTopicsCount(newTopics); |
|
495 |
|
496 __CBSUI_ASSERT( ret == KErrNone, CbsUiPanic(EErrTopicsCountError) ); |
|
497 } |
|
498 |
|
499 return newTopics; |
|
500 } |
|
501 |
|
502 // --------------------------------------------------------- |
|
503 // CCbsUiTopicListView::MarkCurrentHandle |
|
504 // |
|
505 // |
|
506 // --------------------------------------------------------- |
|
507 // |
|
508 void CCbsUiTopicListView::MarkCurrentHandle() |
|
509 { |
|
510 TInt index( iContainer->CurrentPosition() ); |
|
511 |
|
512 if ( index >= 0 && iTopicNumberList->Count() > index ) |
|
513 { |
|
514 iCurrentTopicNumber = iTopicNumberList->At( index ); |
|
515 } |
|
516 } |
|
517 |
|
518 // --------------------------------------------------------- |
|
519 // CCbsUiTopicListView::TopicListChangedL |
|
520 // |
|
521 // |
|
522 // --------------------------------------------------------- |
|
523 // |
|
524 void CCbsUiTopicListView::TopicListChangedL( TCbsTopicListEvent /*aEvent*/, TCbsTopicNumber /*aTopicNumber*/ ) |
|
525 { |
|
526 if ( iContainer ) |
|
527 { |
|
528 ReloadTopicsL(); |
|
529 UpdateNaviPaneL(); |
|
530 SetFocusAfterReload(iFocusState); |
|
531 iFocusState = ENoFocusUpdate; |
|
532 } |
|
533 } |
|
534 |
|
535 // --------------------------------------------------------- |
|
536 // CCbsUiTopicListView::HandleCommandL |
|
537 // |
|
538 // |
|
539 // --------------------------------------------------------- |
|
540 // |
|
541 void CCbsUiTopicListView::HandleCommandL( TInt aCommandId ) |
|
542 { |
|
543 |
|
544 switch ( aCommandId ) |
|
545 { |
|
546 case ECbsUiappCmdSwitchOpen: |
|
547 { |
|
548 // To open a right topic |
|
549 MarkCurrentHandle(); |
|
550 ActivateTopicViewL(); |
|
551 break; |
|
552 } |
|
553 case ECbsUiappCmdSwitchSubscribe: |
|
554 { |
|
555 // Change subscription status |
|
556 User::LeaveIfError( |
|
557 iServer.ChangeTopicSubscriptionStatus( |
|
558 iCurrentTopicNumber, ETrue ) ); |
|
559 |
|
560 iFocusState = ESetFocusToCurrentHandle; |
|
561 break; |
|
562 } |
|
563 case ECbsUiappCmdSwitchUnsubscribe: |
|
564 { |
|
565 // Change subscription status |
|
566 User::LeaveIfError( |
|
567 iServer.ChangeTopicSubscriptionStatus( |
|
568 iCurrentTopicNumber, EFalse )); |
|
569 iFocusState = ESetFocusToCurrentHandle; |
|
570 break; |
|
571 } |
|
572 case ECbsUiappCmdSwitchHotmark: // Implementation is almost the same with |
|
573 // ECbsUiappCmdSwitchHotmark and |
|
574 // ECbsUiappCmdSwitchUnhotmark. |
|
575 case ECbsUiappCmdSwitchUnhotmark: |
|
576 { |
|
577 // Requires refresh |
|
578 TBool hot(EFalse); |
|
579 |
|
580 if ( aCommandId == ECbsUiappCmdSwitchHotmark ) |
|
581 { |
|
582 hot = ETrue; |
|
583 TInt focusedItemIndex; |
|
584 if(FindTopicIndexByNumber(focusedItemIndex, iCurrentTopicNumber) == KErrNone) |
|
585 { |
|
586 TCbsTopic topic; |
|
587 // First, get the topic. |
|
588 TInt rr( iServer.GetTopic(focusedItemIndex, topic) ); |
|
589 if ( rr == KErrNone ) |
|
590 { |
|
591 if ( !topic.iSubscribed ) |
|
592 { |
|
593 // Change subscription status to subscribed |
|
594 User::LeaveIfError(iServer.ChangeTopicSubscriptionStatus( |
|
595 iCurrentTopicNumber, ETrue )) ; |
|
596 } |
|
597 } |
|
598 } |
|
599 } |
|
600 |
|
601 User::LeaveIfError(iServer.ChangeTopicHotmarkStatus(iCurrentTopicNumber, hot)); |
|
602 iFocusState = ESetFocusToCurrentHandle; |
|
603 break; |
|
604 } |
|
605 case ECbsUiappCmdSwitchSettings: |
|
606 { |
|
607 ActivateSettingsViewL(); |
|
608 break; |
|
609 } |
|
610 // Topic sub menu pop up window commands. |
|
611 case ECbsUiappCmdSwitchAddManually: |
|
612 { |
|
613 TBuf<KTopicNameLenght> name; |
|
614 TBuf<KTopicNumberWidth> number; |
|
615 |
|
616 ShowTopicQueryL( ETrue, name, number ); |
|
617 AknTextUtils::ConvertDigitsTo( number, EDigitTypeWestern ); |
|
618 |
|
619 TInt topicNumber(KCbsErrValue); |
|
620 if ( number.Length() > 0 ) |
|
621 { |
|
622 TLex lex(number); |
|
623 TInt err( lex.Val(topicNumber) ); |
|
624 |
|
625 if ( err == KErrNone ) |
|
626 { |
|
627 SetCurrentTopicNumber( (TCbsTopicNumber) topicNumber ); |
|
628 } |
|
629 __CBSUI_ASSERT( err == KErrNone, CbsUiPanic(EErrNotANumber) ); |
|
630 } |
|
631 |
|
632 iFocusState = ESetFocusToCurrentHandle; |
|
633 break; |
|
634 } |
|
635 case ECbsUiappCmdSwitchAddFromIndex: |
|
636 { |
|
637 #ifdef _DEBUG |
|
638 GetNewTopicsCount(); // just to reset |
|
639 #endif |
|
640 // topic detection need to shut down when |
|
641 // add from index dialog is shown. |
|
642 TBool topicDetection; |
|
643 iServer.GetTopicDetectionStatus(topicDetection); |
|
644 |
|
645 if ( topicDetection ) |
|
646 { |
|
647 User::LeaveIfError( iServer.SetTopicDetectionStatus(EFalse) ); |
|
648 } |
|
649 |
|
650 iAddFromIndexDialogIsActive = ETrue; |
|
651 ActivateAddFromIndexViewL(); |
|
652 |
|
653 __ASSERT_DEBUG(GetNewTopicsCount() == 0, CbsUiPanic(ETopicCountError) ); |
|
654 |
|
655 iAddFromIndexDialogIsActive = EFalse; |
|
656 UpdateTitlePaneL(); |
|
657 UpdateNaviPaneL(); |
|
658 |
|
659 if ( topicDetection ) |
|
660 { |
|
661 User::LeaveIfError( iServer.SetTopicDetectionStatus(topicDetection) ); |
|
662 } |
|
663 |
|
664 iFocusState = ESetFocusToCurrentHandle; |
|
665 break; |
|
666 } |
|
667 case ECbsUiappCmdSwitchEdit: |
|
668 { |
|
669 ShowEditTopicQueryL(); |
|
670 iFocusState = ESetFocusToCurrentHandle; |
|
671 break; |
|
672 } |
|
673 case ECbsUiappCmdSwitchDelete: |
|
674 { |
|
675 if ( iCurrentTopicNumber != KIndexTopic ) |
|
676 { |
|
677 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
678 |
|
679 if ( dlg->ExecuteLD(R_DELETE_TOPIC_CONFIRMATION_QUERY) ) |
|
680 { |
|
681 TInt unreadHotmarkedMessages; |
|
682 User::LeaveIfError( |
|
683 iServer.DeleteTopic(iCurrentTopicNumber) ); |
|
684 UpdateCurrentTopicAfterDeletion(iCurrentTopicNumber); |
|
685 unreadHotmarkedMessages = iServer.NumberOfUnreadHotmarkedMessages(); |
|
686 if( unreadHotmarkedMessages <= 0 ) |
|
687 { |
|
688 CAknSoftNotifier* notifier = CAknSoftNotifier::NewLC(); |
|
689 notifier->CancelSoftNotificationL( ECellBroadcastNotification); |
|
690 CleanupStack::PopAndDestroy( notifier ); |
|
691 } |
|
692 } |
|
693 iFocusState = ESetFocusToCurrentHandle; |
|
694 } |
|
695 break; |
|
696 } |
|
697 case ECbsUiappCmdSwitchDeleteAll: |
|
698 { |
|
699 TInt queryOk; |
|
700 CAknQueryDialog* dlg = CAknQueryDialog::NewL(); |
|
701 queryOk= dlg->ExecuteLD(R_DELETE_ALL_TOPICS_CONFIRMATION_QUERY ); |
|
702 |
|
703 if( queryOk ) |
|
704 { |
|
705 User::LeaveIfError( iServer.DeleteAllTopics() ); |
|
706 CAknSoftNotifier* notifier = CAknSoftNotifier::NewLC(); // on CS |
|
707 notifier->CancelSoftNotificationL( ECellBroadcastNotification); |
|
708 CleanupStack::PopAndDestroy( notifier ); |
|
709 } |
|
710 iFocusState = ESetFocusToCurrentHandle; |
|
711 break; |
|
712 } |
|
713 case EAknCmdHelp: |
|
714 AppUi()->HandleCommandL(aCommandId); |
|
715 break; |
|
716 case EAknSoftkeyExit: // same functionality |
|
717 case EAknCmdExit: |
|
718 { |
|
719 ( (MEikCommandObserver*)AppUi() )->ProcessCommandL(EAknCmdExit); |
|
720 break; |
|
721 } |
|
722 default: |
|
723 break; |
|
724 } |
|
725 } |
|
726 |
|
727 |
|
728 |
|
729 // --------------------------------------------------------- |
|
730 // CCbsUiTopicListView::HandleRectChangeInContainer |
|
731 // |
|
732 // |
|
733 // --------------------------------------------------------- |
|
734 // |
|
735 void CCbsUiTopicListView::HandleRectChangeInContainer() |
|
736 { |
|
737 if ( iContainer ) |
|
738 { |
|
739 iContainer->SetRect( ClientRect() ); |
|
740 } |
|
741 } |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 // --------------------------------------------------------- |
|
747 // CCbsUiTopicListView::DoActivateL |
|
748 // |
|
749 // |
|
750 // --------------------------------------------------------- |
|
751 // |
|
752 void CCbsUiTopicListView::DoActivateL( const TVwsViewId& /*aPrevViewId*/, |
|
753 TUid aCustomMessageId, |
|
754 const TDesC8& aCustomMessage ) |
|
755 { |
|
756 if ( !iContainer ) |
|
757 { |
|
758 iContainer = CCbsUiTopicListViewContainer::NewL( *this, ClientRect() ); |
|
759 AppUi()->AddToViewStackL( *this, iContainer ); |
|
760 } |
|
761 |
|
762 TTopicListViewFocusState focus = ESetFocusToFirstItem; |
|
763 |
|
764 if ( aCustomMessageId == KSetFocusToId ) |
|
765 { |
|
766 focus = ESetFocusToCurrentHandle; |
|
767 SetCurrentTopicNumber(aCustomMessage); |
|
768 } |
|
769 else if ( aCustomMessageId == KSetFocusToCurrentId ) |
|
770 { |
|
771 focus = ESetFocusToCurrentHandle; |
|
772 } |
|
773 else |
|
774 { |
|
775 focus = ESetFocusToFirstItem; |
|
776 } |
|
777 |
|
778 ReloadTopicsL(); |
|
779 SetFocusAfterReload(focus); |
|
780 UpdateTitlePaneL(); |
|
781 UpdateNaviPaneL(); |
|
782 iContainer->ActivateL(); |
|
783 } |
|
784 |
|
785 |
|
786 // --------------------------------------------------------- |
|
787 // CCbsUiTopicListView::AddTopic |
|
788 // |
|
789 // |
|
790 // --------------------------------------------------------- |
|
791 // |
|
792 TInt CCbsUiTopicListView::AddTopic( const TCbsTopicNumber& aNumber, const TCbsTopicName& aName ) |
|
793 { |
|
794 __ASSERT_DEBUG( &aName, CbsUiPanic(EErrNullPointer) ); |
|
795 |
|
796 TCbsTopic topic; |
|
797 topic.iHotmarked = EFalse; |
|
798 topic.iName = aName; |
|
799 topic.iNumber = aNumber; |
|
800 topic.iProtected = EFalse; |
|
801 topic.iSavedMessages = 0; |
|
802 topic.iUnreadMessages = 0; |
|
803 topic.iSubscribed = 0; |
|
804 return iServer.AddTopic( topic ); |
|
805 } |
|
806 |
|
807 // --------------------------------------------------------- |
|
808 // CCbsUiTopicListView::UpdateTopic |
|
809 // |
|
810 // |
|
811 // --------------------------------------------------------- |
|
812 // |
|
813 TInt CCbsUiTopicListView::UpdateTopic( const TCbsTopicNumber& aOldNumber, |
|
814 const TCbsTopicNumber& aNumber, |
|
815 const TCbsTopicName& aName ) |
|
816 { |
|
817 __ASSERT_DEBUG( &aName, CbsUiPanic(EErrNullPointer) ); |
|
818 return iServer.ChangeTopicNameAndNumber( aOldNumber, aNumber, aName ); |
|
819 } |
|
820 |
|
821 // --------------------------------------------------------- |
|
822 // CCbsUiTopicListView::DoDeactivate |
|
823 // |
|
824 // |
|
825 // --------------------------------------------------------- |
|
826 // |
|
827 void CCbsUiTopicListView::DoDeactivate() |
|
828 { |
|
829 if ( iContainer ) |
|
830 { |
|
831 AppUi()->RemoveFromViewStack( *this, iContainer ); |
|
832 } |
|
833 delete iContainer; |
|
834 iContainer = NULL; |
|
835 } |
|
836 |
|
837 void CCbsUiTopicListView::ViewActivatedL( |
|
838 const TVwsViewId& aPrevViewId, |
|
839 TUid aCustomMessageId,const |
|
840 TDesC8& aCustomMessage) |
|
841 { |
|
842 CheckNewTopicCountL(); |
|
843 CAknView::ViewActivatedL(aPrevViewId, aCustomMessageId, aCustomMessage); |
|
844 } |
|
845 |
|
846 void CCbsUiTopicListView::ViewDeactivated() |
|
847 { |
|
848 // just to update |
|
849 GetNewTopicsCount(); |
|
850 } |
|
851 |
|
852 // --------------------------------------------------------- |
|
853 // CCbsUiTopicListView::DynInitMenuPaneL |
|
854 // |
|
855 // |
|
856 // --------------------------------------------------------- |
|
857 // |
|
858 void CCbsUiTopicListView::DynInitMenuPaneL( TInt aResourceId, |
|
859 CEikMenuPane* aMenuPane ) |
|
860 { |
|
861 __ASSERT_DEBUG( aMenuPane, CbsUiPanic( EMenuPaneNullError ) ); |
|
862 |
|
863 TCbsTopic topic; |
|
864 TInt ret( iServer.GetTopic(iContainer->CurrentPosition() , topic) ); |
|
865 |
|
866 // If topic doesn't exists it is better to leave and close the |
|
867 // menu. |
|
868 User::LeaveIfError(ret); |
|
869 |
|
870 if ( aResourceId == R_CBSUI_TOPICLISTVIEW_MENU ) |
|
871 { |
|
872 MarkCurrentHandle(); // to freeze a selected item |
|
873 |
|
874 // If topic is subscribed,.. |
|
875 if ( topic.iSubscribed ) |
|
876 { |
|
877 // then remove subscribed item. |
|
878 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchSubscribe ); |
|
879 } |
|
880 else |
|
881 { |
|
882 // otherwise remove unsubscribed item. |
|
883 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchUnsubscribe ); |
|
884 } |
|
885 |
|
886 // And the same for hotmark/unhotmark. |
|
887 if ( topic.iHotmarked ) |
|
888 { |
|
889 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchHotmark ); |
|
890 } |
|
891 else |
|
892 { |
|
893 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchUnhotmark ); |
|
894 } |
|
895 |
|
896 if( !FeatureManager::FeatureSupported( KFeatureIdHelp ) ) |
|
897 { |
|
898 aMenuPane->DeleteMenuItem( EAknCmdHelp ); |
|
899 } |
|
900 } |
|
901 else if ( aResourceId == R_CBSUI_TOPIC_MENU ) |
|
902 { |
|
903 TInt topics; |
|
904 topics = iTopicNumberList->Count(); |
|
905 |
|
906 // If there is no room for topics, then remove add manually. |
|
907 if ( topics >= KCountOfAllTopics ) |
|
908 { |
|
909 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchAddManually ); |
|
910 } |
|
911 |
|
912 // If only index topic in topic list then "Delete all" menuitem is not shown |
|
913 if ( topics < KTwoTopics ) |
|
914 { |
|
915 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchDeleteAll ); |
|
916 } |
|
917 |
|
918 // Protected topic can not be edited or deleted. |
|
919 if ( topic.iProtected ) |
|
920 { |
|
921 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchEdit ); |
|
922 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchDelete ); |
|
923 } |
|
924 |
|
925 // Check if there are Index message received. |
|
926 iServer.StartCollectionBrowsing(); |
|
927 |
|
928 if( !iServer.HasNextCollectionTopic() ) |
|
929 { |
|
930 aMenuPane->DeleteMenuItem( ECbsUiappCmdSwitchAddFromIndex ); |
|
931 } |
|
932 } |
|
933 else |
|
934 { |
|
935 //Does nothing |
|
936 } |
|
937 } |
|
938 |
|
939 // --------------------------------------------------------- |
|
940 // CCbsUiTopicListView::SetCurrentTopicNumber |
|
941 // |
|
942 // |
|
943 // --------------------------------------------------------- |
|
944 // |
|
945 void CCbsUiTopicListView::SetCurrentTopicNumber( const TDesC8& aTopicNumber ) |
|
946 { |
|
947 TPckgBuf<TCbsTopicNumber> pckgTopicNumber; |
|
948 pckgTopicNumber.Copy(aTopicNumber); |
|
949 iCurrentTopicNumber = pckgTopicNumber(); |
|
950 } |
|
951 |
|
952 // --------------------------------------------------------- |
|
953 // CCbsUiTopicListView::SetCurrentTopicNumber |
|
954 // |
|
955 // |
|
956 // --------------------------------------------------------- |
|
957 // |
|
958 void CCbsUiTopicListView::SetCurrentTopicNumber( const TCbsTopicNumber aTopicNumber) |
|
959 { |
|
960 iCurrentTopicNumber = aTopicNumber; |
|
961 } |
|
962 |
|
963 // --------------------------------------------------------- |
|
964 // CCbsUiTopicListView::Id |
|
965 // |
|
966 // |
|
967 // --------------------------------------------------------- |
|
968 // |
|
969 TUid CCbsUiTopicListView::Id() const |
|
970 { |
|
971 return TUid::Uid( ECbsUiTopicListViewId ); |
|
972 } |
|
973 |
|
974 // --------------------------------------------------------- |
|
975 // CCbsUiTopicListView::FindTopicIndexByNumber |
|
976 // |
|
977 // |
|
978 // --------------------------------------------------------- |
|
979 // |
|
980 TInt CCbsUiTopicListView::FindTopicIndexByNumber( TInt& aIndex, |
|
981 const TCbsTopicNumber& aTopicNumber ) |
|
982 { |
|
983 TInt ret(KErrGeneral); |
|
984 |
|
985 for ( TInt i(0); i < iTopicNumberList->Count() && ret != KErrNone; i++ ) |
|
986 { |
|
987 if ( iTopicNumberList->At(i) == aTopicNumber ) |
|
988 { |
|
989 ret = KErrNone; |
|
990 aIndex = i; |
|
991 } |
|
992 } |
|
993 return ret; |
|
994 } |
|
995 |
|
996 // --------------------------------------------------------- |
|
997 // CCbsUiTopicListView::ActivateTopicViewL |
|
998 // |
|
999 // |
|
1000 // --------------------------------------------------------- |
|
1001 // |
|
1002 void CCbsUiTopicListView::ActivateTopicViewL() const |
|
1003 { |
|
1004 TPckgBuf<TCbsTopicNumber> message( iCurrentTopicNumber ); |
|
1005 |
|
1006 AppUi()->ActivateLocalViewL( |
|
1007 TUid::Uid(ECbsUiTopicViewId), KCbsUiCustomMessageId, message ); |
|
1008 } |
|
1009 |
|
1010 // --------------------------------------------------------- |
|
1011 // CCbsUiTopicListView::ActivateSettingsViewL |
|
1012 // |
|
1013 // |
|
1014 // --------------------------------------------------------- |
|
1015 // |
|
1016 void CCbsUiTopicListView::ActivateSettingsViewL() const |
|
1017 { |
|
1018 AppUi()->ActivateLocalViewL( TUid::Uid(ECbsUiSettingsViewId) ); |
|
1019 } |
|
1020 |
|
1021 // --------------------------------------------------------- |
|
1022 // CCbsUiTopicListView::ActivateAddFromIndexViewL |
|
1023 // |
|
1024 // |
|
1025 // --------------------------------------------------------- |
|
1026 // |
|
1027 void CCbsUiTopicListView::ActivateAddFromIndexViewL() |
|
1028 { |
|
1029 CCbsUiAddFromIndexDialog* dialog = |
|
1030 new ( ELeave ) CCbsUiAddFromIndexDialog( iServer ); |
|
1031 |
|
1032 dialog->ExecuteLD(R_CBS_ADD_FROM_INDEX_DIALOG); |
|
1033 } |
|
1034 |
|
1035 // --------------------------------------------------------- |
|
1036 // CCbsUiTopicListView::ActivateBackgroundNote |
|
1037 // |
|
1038 // |
|
1039 // --------------------------------------------------------- |
|
1040 // |
|
1041 TInt CCbsUiTopicListView::ActivateBackgroundNoteL( TAny* aTopicList ) |
|
1042 { |
|
1043 __ASSERT_DEBUG( aTopicList, CbsUiPanic(EErrNullPointer) ); |
|
1044 TInt newTopics( STATIC_CAST(CCbsUiTopicListView*, aTopicList)->iNewTopicsCount ); |
|
1045 |
|
1046 if ( newTopics > ENoNewMessages ) |
|
1047 { |
|
1048 HBufC* stringHolder = NULL; |
|
1049 if ( newTopics > EOneNewMessage ) |
|
1050 { |
|
1051 stringHolder = StringLoader::LoadLC( |
|
1052 R_PLURAL_TOPIC_ADDED, newTopics ); |
|
1053 } |
|
1054 else |
|
1055 { |
|
1056 stringHolder = STATIC_CAST(CCbsUiTopicListView*, aTopicList)-> |
|
1057 iCoeEnv->AllocReadResourceLC( |
|
1058 R_TEXT_NOTE_NEW_TOPIC_ADDED ); |
|
1059 } |
|
1060 |
|
1061 CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote; |
|
1062 note->ExecuteLD(*stringHolder); |
|
1063 |
|
1064 CleanupStack::PopAndDestroy(); // stringholder |
|
1065 } |
|
1066 |
|
1067 return KErrNone; |
|
1068 } |
|
1069 |
|
1070 |
|
1071 // End of File |