|
1 /* |
|
2 * Copyright (c) 2005 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 * Helper class for recipient/phonebook handling |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 // ========== INCLUDE FILES ================================ |
|
22 |
|
23 #include <badesca.h> |
|
24 #include <e32std.h> |
|
25 |
|
26 #include <aknlists.h> // PopupQuery stuff |
|
27 #include <aknPopup.h> |
|
28 #include <aknpopuplayout.h> |
|
29 |
|
30 #include <StringLoader.h> |
|
31 |
|
32 #include <Postcard.rsg> |
|
33 #include "PostcardAppUi.h" |
|
34 #include "PostcardContact.h" |
|
35 #include "PostcardDocument.h" |
|
36 #include "PostcardRecipientWrapper.h" |
|
37 |
|
38 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
39 |
|
40 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
41 |
|
42 // ========== CONSTANTS ==================================== |
|
43 |
|
44 // ========== MACROS ======================================= |
|
45 |
|
46 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
47 |
|
48 // ========== MODULE DATA STRUCTURES ======================= |
|
49 |
|
50 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
51 |
|
52 // ========== LOCAL FUNCTIONS ============================== |
|
53 |
|
54 // ========== MEMBER FUNCTIONS ============================= |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CPostcardRecipientWrapper::CPostcardRecipientWrapper |
|
58 // --------------------------------------------------------- |
|
59 CPostcardRecipientWrapper::CPostcardRecipientWrapper( |
|
60 CPostcardDocument& aDocument, |
|
61 CPostcardAppUi& aAppUi, |
|
62 CPostcardContact& aContact |
|
63 ) : |
|
64 iDocument( aDocument ), |
|
65 iAppUi( aAppUi ), |
|
66 iContact( aContact ) |
|
67 |
|
68 { |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------- |
|
72 // CPostcardRecipientWrapper::~CPostcardRecipientWrapper |
|
73 // --------------------------------------------------------- |
|
74 CPostcardRecipientWrapper::~CPostcardRecipientWrapper( ) |
|
75 { |
|
76 } |
|
77 |
|
78 // --------------------------------------------------------- |
|
79 // CPostcardRecipientWrapper::ConstructL |
|
80 // --------------------------------------------------------- |
|
81 void CPostcardRecipientWrapper::ConstructL( ) |
|
82 { |
|
83 } |
|
84 |
|
85 // --------------------------------------------------------- |
|
86 // CPostcardRecipientWrapper::NewL |
|
87 // --------------------------------------------------------- |
|
88 CPostcardRecipientWrapper* CPostcardRecipientWrapper::NewL( |
|
89 CPostcardDocument& aDocument, |
|
90 CPostcardAppUi& aAppUi, |
|
91 CPostcardContact& aContact |
|
92 ) |
|
93 { |
|
94 CPostcardRecipientWrapper* self = |
|
95 new ( ELeave ) CPostcardRecipientWrapper( |
|
96 aDocument, |
|
97 aAppUi, |
|
98 aContact |
|
99 ); |
|
100 CleanupStack::PushL( self ); |
|
101 self->ConstructL( ); |
|
102 CleanupStack::Pop( self ); |
|
103 return self; |
|
104 } |
|
105 |
|
106 // --------------------------------------------------------- |
|
107 // CPostcardRecipientWrapper::AskLocationL |
|
108 // --------------------------------------------------------- |
|
109 TBool CPostcardRecipientWrapper::AskLocationL( |
|
110 CPostcardContact::TLocation& aLocation ) |
|
111 { |
|
112 static const CPostcardContact::TLocation locations[] = |
|
113 { |
|
114 CPostcardContact::ELocationPreferred, |
|
115 CPostcardContact::ELocationHome, |
|
116 CPostcardContact::ELocationWork |
|
117 }; |
|
118 const TInt KNumLocations = sizeof( locations ) / sizeof( locations[ 0 ] ); |
|
119 |
|
120 CPostcardContact::TLocation foundLocations[ KNumLocations ]; |
|
121 TInt numLocations = 0; |
|
122 |
|
123 // Check if contact has address for possible locations |
|
124 for( TInt i = 0; i < KNumLocations; i++ ) |
|
125 { |
|
126 if ( iContact.HasLocationL(locations[i]) ) |
|
127 { |
|
128 foundLocations[ numLocations++ ] = locations[ i ]; |
|
129 } |
|
130 } |
|
131 |
|
132 CPostcardContact::TLocation location = |
|
133 CPostcardContact::ELocationPreferred; |
|
134 |
|
135 if ( numLocations == 0 ) |
|
136 { |
|
137 // Import only the name fields |
|
138 } |
|
139 else if ( numLocations == 1 ) |
|
140 { // Only one location used -> use that |
|
141 location = foundLocations[ 0 ]; |
|
142 } |
|
143 else |
|
144 { |
|
145 CAknSingleHeadingPopupMenuStyleListBox* listBox = |
|
146 new(ELeave) CAknSingleHeadingPopupMenuStyleListBox(); |
|
147 CleanupStack::PushL( listBox ); |
|
148 CAknPopupList* popupList = CAknPopupList::NewL( listBox, |
|
149 R_POSTCARD_SOFTKEYS_OK_BACK__OK, |
|
150 AknPopupLayouts::EMenuGraphicHeadingWindow ); |
|
151 CleanupStack::PushL( popupList ); |
|
152 listBox->ConstructL( popupList, CEikListBox::ELeftDownInViewRect ); |
|
153 listBox->CreateScrollBarFrameL( ETrue ); |
|
154 listBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
155 CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
156 |
|
157 TInt resId = R_POSTCARD_ADDRESS_SELECTION_TITLE; |
|
158 HBufC* titleText = iAppUi.ReadFromResourceLC( resId ); |
|
159 popupList->SetTitleL( *titleText ); |
|
160 CleanupStack::PopAndDestroy( titleText ); // titleText |
|
161 |
|
162 CDesCArrayFlat* strings = new (ELeave) CDesCArrayFlat( KNumLocations ); |
|
163 CleanupStack::PushL( strings ); |
|
164 |
|
165 for( TInt i = 0; i < numLocations; i++ ) |
|
166 { |
|
167 HBufC* buffer = GetFormattedStringL( foundLocations[ i ] ); |
|
168 CleanupStack::PushL( buffer ); |
|
169 strings->AppendL( *buffer ); |
|
170 CleanupStack::PopAndDestroy( buffer ); |
|
171 } |
|
172 |
|
173 // For each list item replace the %N in the item format with the number |
|
174 // of the icon, the %0N with the label of the address (Default, Home or |
|
175 // Business) and the %1N with the actual combined address string. |
|
176 |
|
177 CTextListBoxModel* model = listBox->Model(); |
|
178 model->SetItemTextArray( strings ); |
|
179 model->SetOwnershipType( ELbmOwnsItemArray ); |
|
180 CleanupStack::Pop( strings ); |
|
181 |
|
182 // And execute the dialog |
|
183 CleanupStack::Pop( popupList ); |
|
184 TInt popupOk = popupList->ExecuteLD(); |
|
185 TInt itemIndex = listBox->CurrentItemIndex(); |
|
186 CleanupStack::PopAndDestroy( listBox ); // listBox; |
|
187 |
|
188 // Coverty fix, Negative return; http://ousrv057/cov.cgi?cid=36961 |
|
189 if ( popupOk && itemIndex > 0) |
|
190 { |
|
191 location = foundLocations[ itemIndex ]; |
|
192 } |
|
193 else |
|
194 { |
|
195 // Nothing was selected so just return.. |
|
196 return EFalse; |
|
197 } |
|
198 } |
|
199 // Set location as out parameter |
|
200 aLocation = location; |
|
201 return ETrue; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------- |
|
205 // CPostcardRecipientWrapper::GetFormattedStringL |
|
206 // --------------------------------------------------------- |
|
207 HBufC* CPostcardRecipientWrapper::GetFormattedStringL( |
|
208 CPostcardContact::TLocation aAddressLocation ) |
|
209 { |
|
210 _LIT(KPostcardSelectItemFormat, "%0U\t%1U"); |
|
211 TPtrC itemFormat(KPostcardSelectItemFormat); |
|
212 |
|
213 TBuf<64> addressBuffer; |
|
214 addressBuffer.Zero(); |
|
215 |
|
216 static const TInt resIds[] = |
|
217 { |
|
218 R_POSTCARD_ADDRESS_SELECTION_NONE, |
|
219 R_POSTCARD_ADDRESS_SELECTION_HOME, |
|
220 R_POSTCARD_ADDRESS_SELECTION_WORK |
|
221 }; |
|
222 TInt resId = resIds[ aAddressLocation ]; |
|
223 HBufC* itemText = iAppUi.ReadFromResourceLC( resId ); |
|
224 iContact.GetContactStringL( addressBuffer, aAddressLocation ); |
|
225 |
|
226 TInt formatBufferLength = itemFormat.Length() + itemText->Length() + addressBuffer.Length(); |
|
227 |
|
228 HBufC* sourceBuffer = HBufC::NewLC(formatBufferLength); |
|
229 HBufC* destinationBuffer = HBufC::NewLC(formatBufferLength); |
|
230 TPtr sourceBufferPtr = sourceBuffer->Des(); |
|
231 TPtr destinationBufferPtr = destinationBuffer->Des(); |
|
232 |
|
233 sourceBufferPtr.Copy(itemFormat); |
|
234 |
|
235 // List item label -> location 0, value itemText |
|
236 StringLoader::Format(destinationBufferPtr, sourceBufferPtr, 0, itemText->Des( ) ); |
|
237 sourceBufferPtr.Copy(destinationBufferPtr); |
|
238 |
|
239 // List item text (address string) -> location 1, value addressBuffer |
|
240 StringLoader::Format(destinationBufferPtr, sourceBufferPtr, 1, addressBuffer); |
|
241 |
|
242 CleanupStack::Pop( destinationBuffer ); |
|
243 CleanupStack::PopAndDestroy( 2, itemText ); // itemText, sourceBuffer |
|
244 return destinationBuffer; |
|
245 } |
|
246 |
|
247 // EOF |