|
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: Dialog which shows topics, which are not yet in |
|
15 * the topic list view. Enables topics adding manually. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <barsread.h> |
|
23 #include <gulicon.h> |
|
24 #include <eikclbd.h> |
|
25 #include <eikspane.h> |
|
26 #include <aknnavide.h> |
|
27 #include <akntitle.h> |
|
28 #include <avkon.hrh> |
|
29 #include <aknnotewrappers.h> |
|
30 #include <cbsuiApp.rsg> |
|
31 #include <aknlists.h> |
|
32 #include <AknIconArray.h> |
|
33 #include "CCbsUiAddFromIndexDialog.h" |
|
34 #include "Cbsuiapp.hrh" |
|
35 #include "CbsUiPanic.h" |
|
36 #include "MCbs.h" |
|
37 |
|
38 // CONSTANTS |
|
39 const TInt KAssumedAverageOfItems = 5; |
|
40 const TInt KNumberOfIconsInAddFromIndexDialog = 4; |
|
41 _LIT(KCbsIconListSeparator, "1\t"); |
|
42 _LIT(KCbsColumnListSeparator, " "); |
|
43 |
|
44 // if the aTopicInfo.iNumber is shorter than KWidth, |
|
45 // this character will be used to fill empty spaces. |
|
46 const TUint KZeroFill = '0'; |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 // ================= MEMBER FUNCTIONS ======================= |
|
52 // C++ default constructor can NOT contain any code, that |
|
53 // might leave. |
|
54 // |
|
55 CCbsUiAddFromIndexDialog::CCbsUiAddFromIndexDialog( MCbs& aServer ) : |
|
56 iServer(aServer) |
|
57 { |
|
58 } |
|
59 |
|
60 // Destructor |
|
61 CCbsUiAddFromIndexDialog::~CCbsUiAddFromIndexDialog() |
|
62 { |
|
63 delete iHandles; |
|
64 delete iNaviDecorator; |
|
65 } |
|
66 |
|
67 //----------------------------------------------------------------------------- |
|
68 // |
|
69 // CCbsUiAddFromIndexDialog::PreLayoutDynInitL() |
|
70 // |
|
71 // Sets the choices to controls in AddFromIndexdialog |
|
72 // |
|
73 //----------------------------------------------------------------------------- |
|
74 void CCbsUiAddFromIndexDialog::PreLayoutDynInitL() |
|
75 { |
|
76 CEikDialog::PreLayoutDynInitL(); |
|
77 |
|
78 CAknNavigationControlContainer* naviPane = |
|
79 STATIC_CAST( CAknNavigationControlContainer*, |
|
80 iEikonEnv->AppUiFactory()->StatusPane()->ControlL( |
|
81 TUid::Uid( EEikStatusPaneUidNavi) ) ); |
|
82 |
|
83 __ASSERT_DEBUG( naviPane, CbsUiPanic( ENaviPaneError ) ); |
|
84 |
|
85 TResourceReader reader; |
|
86 iCoeEnv->CreateResourceReaderLC( reader, R_QTN_CB_AD_SEL_TOP ); |
|
87 |
|
88 delete iNaviDecorator; |
|
89 iNaviDecorator = NULL; |
|
90 |
|
91 iNaviDecorator = naviPane-> |
|
92 ConstructNavigationDecoratorFromResourceL( reader ); |
|
93 |
|
94 __ASSERT_DEBUG( iNaviDecorator, CbsUiPanic( ENaviDecoratorError ) ); |
|
95 |
|
96 naviPane->PushL( *iNaviDecorator ); |
|
97 CleanupStack::PopAndDestroy(); |
|
98 |
|
99 iListBox = STATIC_CAST( |
|
100 CAknSingleGraphicStyleListBox*, Control(ECbsUiAddFromIndexDlgLine) ); |
|
101 |
|
102 __ASSERT_DEBUG( iListBox, CbsUiPanic( EListBoxInDialogError ) ); |
|
103 |
|
104 SetIconsL(); |
|
105 SetTopicsL(); |
|
106 |
|
107 // Scrollbar |
|
108 iListBox->CreateScrollBarFrameL(ETrue); |
|
109 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto); |
|
110 |
|
111 // order has to be this; otherwise on error add from index title pane |
|
112 // remains. |
|
113 CreateAddFromIndexTitlePaneL(); |
|
114 |
|
115 MEikAppUiFactory* appUiFactory = iEikonEnv->AppUiFactory(); |
|
116 TRect rect = appUiFactory->ClientRect(); |
|
117 iListBox->SetRect( rect ); |
|
118 } |
|
119 |
|
120 //----------------------------------------------------------------------------- |
|
121 // |
|
122 // CCbsUiAddFromIndexDialog::OkToExitL() |
|
123 // |
|
124 // Handles keyevents. In case "Softkey OK" it |
|
125 // add selected topics using member function addtopic |
|
126 // |
|
127 //----------------------------------------------------------------------------- |
|
128 TBool CCbsUiAddFromIndexDialog::OkToExitL( TInt aKeycode ) |
|
129 { |
|
130 TBool result( EFalse ); |
|
131 switch ( aKeycode ) |
|
132 { |
|
133 case EAknSoftkeyOk: |
|
134 { |
|
135 const CListBoxView::CSelectionIndexArray* selArray = |
|
136 iListBox->SelectionIndexes(); |
|
137 |
|
138 if ( selArray ) |
|
139 { |
|
140 // Initialize the marked contact id array using selArray |
|
141 TInt count( selArray->Count() ); |
|
142 TInt ret( KErrNone ); |
|
143 for ( TInt i = 0; i < count && ret == KErrNone; ++i ) |
|
144 { |
|
145 const TInt selIndex( (*selArray)[i] ); |
|
146 ret = AddTopicL( iHandles->At(selIndex) ); |
|
147 } |
|
148 } |
|
149 // Ok to exit, dialog is also removed from the stack |
|
150 result = ETrue; |
|
151 iEikonEnv->RemoveFromStack( this ); |
|
152 break; |
|
153 } |
|
154 // If Mark or Unmark is pressed, the dialog must not exit. |
|
155 // Dialog must also stay in stack. |
|
156 case EAknSoftkeyMark: |
|
157 case EAknSoftkeyUnmark: |
|
158 { |
|
159 result = EFalse; |
|
160 break; |
|
161 } |
|
162 default: |
|
163 break; |
|
164 } |
|
165 |
|
166 return result; |
|
167 } |
|
168 |
|
169 |
|
170 //----------------------------------------------------------------------------- |
|
171 // |
|
172 // CCbsUiAddFromIndexDialog::GetIndexNumber() |
|
173 // |
|
174 // Parses Indexnumber from topic info. Is used by |
|
175 // SetTopics-member function. |
|
176 // |
|
177 //----------------------------------------------------------------------------- |
|
178 void CCbsUiAddFromIndexDialog::GetIndexNumber( const TCbsTopicInfo& aTopicInfo , |
|
179 TBuf<KTopicNumberWidth>& aIndexNumber ) const |
|
180 { |
|
181 TBuf<KTopicNumberWidth> ind; |
|
182 ind.AppendNum( TInt(aTopicInfo.iNumber) ); |
|
183 aIndexNumber.Justify(ind , KTopicNumberWidth, ERight, KZeroFill); |
|
184 } |
|
185 |
|
186 //----------------------------------------------------------------------------- |
|
187 // |
|
188 // CCbsUiAddFromIndexDialog::AddTopicL() |
|
189 // |
|
190 // |
|
191 // |
|
192 //----------------------------------------------------------------------------- |
|
193 TInt CCbsUiAddFromIndexDialog::AddTopicL( const TCbsTopicInfo aTopicInfo ) |
|
194 { |
|
195 TCbsTopic topic; |
|
196 |
|
197 topic.iHotmarked = EFalse; |
|
198 topic.iName = aTopicInfo.iName; |
|
199 topic.iNumber = aTopicInfo.iNumber; |
|
200 topic.iProtected = EFalse; |
|
201 topic.iSavedMessages = 0; |
|
202 topic.iUnreadMessages = 0; |
|
203 topic.iSubscribed = 0; |
|
204 |
|
205 TInt ret( iServer.AddTopic(topic) ); |
|
206 |
|
207 switch ( ret ) |
|
208 { |
|
209 case KErrNone: |
|
210 // ok, do nothing |
|
211 break; |
|
212 case KErrAlreadyExists: // same handling |
|
213 case KErrArgument: // same handling |
|
214 // after this error still tryes to append other items if exists |
|
215 ret = KErrNone; |
|
216 break; |
|
217 default: |
|
218 User::LeaveIfError(ret); |
|
219 break; |
|
220 } |
|
221 |
|
222 return ret; |
|
223 } |
|
224 |
|
225 //----------------------------------------------------------------------------- |
|
226 // |
|
227 // CCbsUiAddFromIndexDialog::SetIconsL() |
|
228 // |
|
229 // Sets the multiselction box-images. |
|
230 // |
|
231 //----------------------------------------------------------------------------- |
|
232 void CCbsUiAddFromIndexDialog::SetIconsL() const |
|
233 { |
|
234 CAknIconArray* icons = new (ELeave) |
|
235 CAknIconArray(KNumberOfIconsInAddFromIndexDialog); |
|
236 |
|
237 CleanupStack::PushL(icons); |
|
238 icons->ConstructFromResourceL(R_CHECKBOX_ICONS); |
|
239 CleanupStack::Pop(); // icons |
|
240 |
|
241 iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons); |
|
242 } |
|
243 |
|
244 //----------------------------------------------------------------------------- |
|
245 // |
|
246 // CCbsUiAddFromIndexDialog::SetTopicsL() |
|
247 // |
|
248 // |
|
249 //----------------------------------------------------------------------------- |
|
250 void CCbsUiAddFromIndexDialog::SetTopicsL() |
|
251 { |
|
252 TCbsTopicInfo topicinfo; |
|
253 |
|
254 iServer.StartCollectionBrowsing(); |
|
255 |
|
256 iHandles = new (ELeave) TCbsTopicInfoHandleList(KAssumedAverageOfItems); |
|
257 |
|
258 __ASSERT_DEBUG( iHandles, CbsUiPanic( ETopicHandleError ) ); |
|
259 |
|
260 iHandles->Reset(); |
|
261 TInt err(KErrNone); |
|
262 |
|
263 while( iServer.HasNextCollectionTopic() && err == KErrNone ) |
|
264 { |
|
265 err = iServer.NextCollectionTopic(topicinfo); |
|
266 if ( err == KErrNone ) |
|
267 { |
|
268 MDesCArray* itemList = iListBox->Model()->ItemTextArray(); |
|
269 CDesCArray* itemArray = STATIC_CAST(CDesCArray*, itemList); |
|
270 |
|
271 TBuf<KTopicNumberWidth> index; |
|
272 GetIndexNumber( topicinfo, index ); |
|
273 |
|
274 HBufC* buffer = HBufC::NewMaxLC( |
|
275 KCbsIconListSeparator().Length() + index.Length() + |
|
276 KCbsColumnListSeparator().Length() + topicinfo.iName.Length() ); |
|
277 |
|
278 TPtr ptr = buffer->Des(); |
|
279 |
|
280 ptr = KCbsIconListSeparator; |
|
281 ptr.Append(index); |
|
282 ptr.Append(KCbsColumnListSeparator); |
|
283 ptr.Append(topicinfo.iName); |
|
284 |
|
285 itemArray->AppendL(*buffer); |
|
286 iHandles->AppendL(topicinfo); |
|
287 CleanupStack::PopAndDestroy(); // buffer |
|
288 } |
|
289 } |
|
290 |
|
291 iListBox->HandleItemAdditionL(); |
|
292 if ( iListBox->Model()->NumberOfItems() == 0 ) |
|
293 { |
|
294 // No warning, but we can close the dialog |
|
295 User::Leave(KErrNone); |
|
296 } |
|
297 } |
|
298 |
|
299 //----------------------------------------------------------------------------- |
|
300 // |
|
301 // CCbsUiAddFromIndexDialog::CreateAddFromIndexTitlePaneL() |
|
302 // |
|
303 // |
|
304 //----------------------------------------------------------------------------- |
|
305 void CCbsUiAddFromIndexDialog::CreateAddFromIndexTitlePaneL() const |
|
306 { |
|
307 CEikStatusPane* sp = STATIC_CAST( CAknAppUi*, CEikonEnv::Static()-> |
|
308 EikAppUi() )->StatusPane(); |
|
309 |
|
310 CAknTitlePane* title = STATIC_CAST(CAknTitlePane*, sp-> |
|
311 ControlL( TUid::Uid(EEikStatusPaneUidTitle) )); |
|
312 |
|
313 __ASSERT_DEBUG( sp && title, CbsUiPanic( EStatusOrTitlePaneError ) ); |
|
314 |
|
315 TResourceReader titlereader; |
|
316 iCoeEnv->CreateResourceReaderLC( titlereader, R_QTN_CB_TITLE_ADD_TOPICS ); |
|
317 title->SetFromResourceL( titlereader ); |
|
318 CleanupStack::PopAndDestroy(); // resource title |
|
319 } |
|
320 |
|
321 // End of File |