author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:54:53 +0300 | |
branch | RCL_3 |
changeset 21 | 9da50d567e3c |
parent 20 | f4a778e096c2 |
permissions | -rw-r--r-- |
20 | 1 |
/* |
2 |
* Copyright (c) 2005-2007 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: Phonebook 2 memory entry defaults assign dialog. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include <CPbk2MemoryEntryDefaultsAssignDlg.h> |
|
20 |
||
21 |
// Phonebook 2 |
|
22 |
#include "MPbk2ClipListBoxText.h" |
|
23 |
#include "CPbk2FieldListBoxModel.h" |
|
24 |
#include <CPbk2IconInfo.h> |
|
25 |
#include <CPbk2IconArray.h> |
|
21
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
26 |
#include <pbk2uicontrols.rsg> |
20 | 27 |
#include <CPbk2PresentationContact.h> |
28 |
#include <CPbk2PresentationContactField.h> |
|
29 |
#include <CPbk2PresentationContactFieldCollection.h> |
|
30 |
#include <CPbk2FieldPropertyArray.h> |
|
31 |
#include <CPbk2ApplicationServices.h> |
|
32 |
#include <CPbk2ServiceManager.h> |
|
33 |
#include <MPbk2ApplicationServices.h> |
|
34 |
||
35 |
// Virtual Phonebook |
|
36 |
#include <CVPbkFieldTypeSelector.h> |
|
37 |
#include <CVPbkContactManager.h> |
|
38 |
#include <CVPbkFieldFilter.h> |
|
39 |
#include <MVPbkFieldType.h> |
|
40 |
#include <MVPbkContactFieldData.h> |
|
41 |
||
42 |
// System includes |
|
43 |
#include <aknlists.h> |
|
44 |
#include <StringLoader.h> |
|
45 |
#include <aknPopup.h> |
|
46 |
#include <barsread.h> |
|
47 |
#include <aknlayoutscalable_avkon.cdl.h> |
|
48 |
||
49 |
// Debugging headers |
|
50 |
#include <Pbk2Config.hrh> |
|
51 |
#include <Pbk2Debug.h> |
|
52 |
||
53 |
/// Unnamed namespace for local definitions |
|
54 |
namespace { |
|
55 |
||
56 |
// LOCAL CONSTANTS AND MACROS |
|
57 |
||
58 |
static const TInt KMaxIntLength( 15 ); |
|
59 |
||
60 |
} /// namespace |
|
61 |
||
62 |
// -------------------------------------------------------------------------- |
|
63 |
// CPbk2MemoryEntryDefaultsAssignDlg::CPbk2MemoryEntryDefaultsAssignDlg |
|
64 |
// -------------------------------------------------------------------------- |
|
65 |
// |
|
66 |
CPbk2MemoryEntryDefaultsAssignDlg::CPbk2MemoryEntryDefaultsAssignDlg() |
|
67 |
{ |
|
68 |
} |
|
69 |
||
70 |
// -------------------------------------------------------------------------- |
|
71 |
// CPbk2MemoryEntryDefaultsAssignDlg::~CPbk2MemoryEntryDefaultsAssignDlg |
|
72 |
// -------------------------------------------------------------------------- |
|
73 |
// |
|
74 |
CPbk2MemoryEntryDefaultsAssignDlg::~CPbk2MemoryEntryDefaultsAssignDlg() |
|
75 |
{ |
|
76 |
Release( iAppServices ); |
|
77 |
||
78 |
if ( iDestroyedPtr ) |
|
79 |
{ |
|
80 |
*iDestroyedPtr = ETrue; |
|
81 |
} |
|
82 |
if ( iPopupList ) |
|
83 |
{ |
|
84 |
iPopupList->CancelPopup(); |
|
85 |
} |
|
86 |
delete iListBox; |
|
87 |
delete iModel; |
|
88 |
} |
|
89 |
||
90 |
// -------------------------------------------------------------------------- |
|
91 |
// CPbk2MemoryEntryDefaultsAssignDlg::NewL |
|
92 |
// -------------------------------------------------------------------------- |
|
93 |
// |
|
94 |
EXPORT_C CPbk2MemoryEntryDefaultsAssignDlg* |
|
95 |
CPbk2MemoryEntryDefaultsAssignDlg::NewL() |
|
96 |
{ |
|
97 |
CPbk2MemoryEntryDefaultsAssignDlg* self = |
|
98 |
new ( ELeave ) CPbk2MemoryEntryDefaultsAssignDlg(); |
|
99 |
CleanupStack::PushL(self); |
|
100 |
self->ConstructL(); |
|
101 |
CleanupStack::Pop(self); |
|
102 |
return self; |
|
103 |
} |
|
104 |
||
105 |
// -------------------------------------------------------------------------- |
|
106 |
// CPbk2MemoryEntryDefaultsAssignDlg::ConstructL |
|
107 |
// -------------------------------------------------------------------------- |
|
108 |
// |
|
109 |
void CPbk2MemoryEntryDefaultsAssignDlg::ConstructL() |
|
110 |
{ |
|
111 |
iAppServices = CPbk2ApplicationServices::InstanceL(); |
|
112 |
} |
|
113 |
||
114 |
// -------------------------------------------------------------------------- |
|
115 |
// CPbk2MemoryEntryDefaultsAssignDlg::ExecuteLD |
|
116 |
// -------------------------------------------------------------------------- |
|
117 |
// |
|
118 |
EXPORT_C TInt CPbk2MemoryEntryDefaultsAssignDlg::ExecuteLD |
|
119 |
( const CPbk2PresentationContactFieldCollection& aFields, |
|
120 |
const CVPbkContactManager& aManager, |
|
121 |
const MPbk2FieldPropertyArray& aFieldProperties, |
|
122 |
const VPbkFieldTypeSelectorFactory::TVPbkContactActionTypeSelector aSelectorID ) |
|
123 |
{ |
|
124 |
CleanupStack::PushL( this ); |
|
125 |
TBool thisDestroyed = EFalse; |
|
126 |
iDestroyedPtr = &thisDestroyed; |
|
127 |
TInt index = KErrCancel; |
|
128 |
iSelectorId = aSelectorID; |
|
129 |
||
130 |
PreparePopupL( aFields, aManager, aFieldProperties ); |
|
131 |
||
132 |
TBool result = EFalse; |
|
133 |
TRAPD( err, result = iPopupList->ExecuteLD() ); |
|
134 |
// Reset iPopupList member |
|
135 |
if ( !thisDestroyed ) |
|
136 |
{ |
|
137 |
iPopupList = NULL; |
|
138 |
} |
|
139 |
// Rethrow any error |
|
140 |
if ( err != KErrNone ) |
|
141 |
{ |
|
142 |
User::Leave( err ); |
|
143 |
} |
|
144 |
||
145 |
if ( thisDestroyed ) |
|
146 |
{ |
|
147 |
index = KErrNotFound; |
|
148 |
CleanupStack::Pop(); // this |
|
149 |
} |
|
150 |
else |
|
151 |
{ |
|
152 |
if ( result ) |
|
153 |
{ |
|
154 |
index = iModel->GetModelIndex( iListBox->CurrentItemIndex() ); |
|
155 |
} |
|
156 |
CleanupStack::PopAndDestroy(); // this |
|
157 |
} |
|
158 |
||
159 |
return index; |
|
160 |
} |
|
161 |
||
162 |
// -------------------------------------------------------------------------- |
|
163 |
// CPbk2MemoryEntryDefaultsAssignDlg::ClipFromBeginning |
|
164 |
// -------------------------------------------------------------------------- |
|
165 |
// |
|
166 |
TBool CPbk2MemoryEntryDefaultsAssignDlg::ClipFromBeginning |
|
167 |
( TDes& aBuffer, TInt aItemIndex, TInt aSubCellNumber ) |
|
168 |
{ |
|
169 |
return AknTextUtils::ClipToFit( |
|
170 |
aBuffer, |
|
171 |
AknTextUtils::EClipFromBeginning, |
|
172 |
iListBox, |
|
173 |
aItemIndex, |
|
174 |
aSubCellNumber ); |
|
175 |
} |
|
176 |
||
177 |
// -------------------------------------------------------------------------- |
|
178 |
// CPbk2MemoryEntryDefaultsAssignDlg::PreparePopupL |
|
179 |
// -------------------------------------------------------------------------- |
|
180 |
// |
|
181 |
inline void CPbk2MemoryEntryDefaultsAssignDlg::PreparePopupL |
|
182 |
( const CPbk2PresentationContactFieldCollection& aFields, |
|
183 |
const CVPbkContactManager& aManager, |
|
184 |
const MPbk2FieldPropertyArray& aFieldProperties ) |
|
185 |
{ |
|
186 |
// Create a list box |
|
187 |
iListBox = static_cast<CEikFormattedCellListBox*>( |
|
188 |
EikControlFactory::CreateByTypeL( |
|
189 |
EAknCtDoubleGraphicPopupMenuListBox).iControl ); |
|
190 |
||
191 |
// Create a popup list |
|
192 |
||
193 |
CAknPopupList* popupList = CAknPopupList::NewL( |
|
194 |
iListBox, |
|
195 |
R_AVKON_SOFTKEYS_OK_CANCEL__OK, |
|
196 |
AknPopupLayouts::EMenuDoubleLargeGraphicWindow ); |
|
197 |
||
198 |
||
199 |
CleanupStack::PushL( popupList ); |
|
200 |
||
201 |
// Init list box |
|
202 |
iListBox->ConstructL( popupList, CEikListBox::ELeftDownInViewRect ); |
|
203 |
iListBox->CreateScrollBarFrameL( ETrue ); |
|
204 |
iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
205 |
CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
206 |
||
207 |
// Set title of popup list |
|
208 |
HBufC* heading = StringLoader::LoadLC |
|
209 |
( R_QTN_PHOB_TITLE_SELECT_DEFAULT ); |
|
210 |
popupList->SetTitleL(*heading); |
|
211 |
CleanupStack::PopAndDestroy(heading); |
|
212 |
||
213 |
// Set icons |
|
214 |
TResourceReader reader; |
|
215 |
CCoeEnv::Static()->CreateResourceReaderLC |
|
216 |
( reader, R_PBK2_FIELDTYPE_ICONS ); |
|
217 |
CPbk2IconArray* iconArray = CPbk2IconArray::NewL( reader ); |
|
218 |
||
219 |
//Calculate preferred size for xsp service icons |
|
220 |
TRect mainPane; |
|
221 |
AknLayoutUtils::LayoutMetricsRect( |
|
222 |
AknLayoutUtils::EMainPane, mainPane ); |
|
223 |
TAknLayoutRect listLayoutRect; |
|
224 |
listLayoutRect.LayoutRect( |
|
225 |
mainPane, |
|
226 |
AknLayoutScalable_Avkon::list_single_graphic_pane_g1(0).LayoutLine() ); |
|
227 |
TSize size(listLayoutRect.Rect().Size()); |
|
228 |
||
229 |
// Add xsp service icons |
|
230 |
CPbk2ServiceManager& servMan(iAppServices->ServiceManager()); |
|
231 |
||
232 |
const CPbk2ServiceManager::RServicesArray& services = servMan.Services(); |
|
233 |
TUid uid; |
|
234 |
uid.iUid = KPbk2ServManId; |
|
235 |
for ( TInt i = 0; i < services.Count(); i++ ) |
|
236 |
{ |
|
237 |
const CPbk2ServiceManager::TService& service = services[i]; |
|
238 |
if ( service.iBitmapId && service.iBitmap ) |
|
239 |
{ |
|
240 |
AknIconUtils::SetSize( |
|
241 |
service.iBitmap, |
|
242 |
size ); |
|
243 |
AknIconUtils::SetSize( |
|
244 |
service.iMask, |
|
245 |
size ); |
|
246 |
TPbk2IconId id = TPbk2IconId( uid, services[i].iBitmapId ); |
|
247 |
CPbk2IconInfo* info = CPbk2IconInfo::NewLC( |
|
248 |
id, services[i].iBitmap, services[i].iMask, size ); |
|
249 |
iconArray->AppendIconL(info); |
|
250 |
CleanupStack::Pop(info); |
|
251 |
} |
|
252 |
} |
|
253 |
||
254 |
CleanupStack::PopAndDestroy(); // reader |
|
255 |
iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray ); |
|
256 |
||
257 |
// Create model |
|
258 |
CreateModelL( aFields, aManager, aFieldProperties, *iconArray ); |
|
259 |
||
260 |
CleanupStack::Pop(); // popupList |
|
261 |
iPopupList = popupList; |
|
262 |
} |
|
263 |
||
264 |
// -------------------------------------------------------------------------- |
|
265 |
// CPbk2MemoryEntryDefaultsAssignDlg::CreateModelL |
|
266 |
// -------------------------------------------------------------------------- |
|
267 |
// |
|
268 |
inline void CPbk2MemoryEntryDefaultsAssignDlg::CreateModelL |
|
269 |
( const CPbk2PresentationContactFieldCollection& aFields, |
|
270 |
const CVPbkContactManager& aManager, |
|
271 |
const MPbk2FieldPropertyArray& aFieldProperties, |
|
272 |
const CPbk2IconArray& aIconArray ) |
|
273 |
{ |
|
274 |
HBufC* timeFormat = CCoeEnv::Static()->AllocReadResourceLC |
|
275 |
( R_QTN_DATE_USUAL ); |
|
276 |
||
277 |
CPbk2FieldListBoxModel::TParams params( |
|
278 |
aFields, |
|
279 |
aManager, |
|
280 |
aFieldProperties, |
|
281 |
*timeFormat, |
|
282 |
aIconArray, |
|
283 |
NULL, // analyzer not used |
|
284 |
NULL, // dynamic properties are not used |
|
285 |
ETrue );// the list items will be duplicated if their content are the same |
|
286 |
||
287 |
iModel = CPbk2FieldListBoxModel::NewL( params ); |
|
288 |
iModel->FormatFieldsL(); |
|
289 |
CleanupStack::PopAndDestroy( timeFormat ); |
|
290 |
iModel->SetClipper( *this ); |
|
291 |
||
292 |
// Insert TEXT_NO_DEFAULT as the last item to the array |
|
293 |
CPbk2FieldListBoxRow* row = CPbk2FieldListBoxRow::NewL(); |
|
294 |
CleanupStack::PushL( row ); |
|
295 |
TBuf<KMaxIntLength> iconBuffer; |
|
296 |
_LIT( KIcon, "%d" ); |
|
297 |
iconBuffer.Format( KIcon, aIconArray.FindIcon( |
|
298 |
TPbk2AppIconId( EPbk2qgn_prop_nrtyp_empty ))); |
|
299 |
row->AppendColumnL( iconBuffer ); |
|
300 |
HBufC* text = StringLoader::LoadLC( R_QTN_PHOB_SETI_NO_DEFAULT ); |
|
301 |
row->AppendColumnL( *text ); |
|
302 |
CleanupStack::PopAndDestroy( text ); |
|
303 |
row->AppendColumnL( KNullDesC ); // empty label column |
|
304 |
iModel->AppendRowL( row ); |
|
305 |
CleanupStack::Pop( row ); |
|
306 |
||
307 |
iListBox->Model()->SetItemTextArray( iModel ); |
|
308 |
iListBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray ); |
|
309 |
iListBox->Reset(); |
|
310 |
} |
|
311 |
||
312 |
// End of File |