25
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: Implementation for mrui address selection query
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include "emailtrace.h"
|
|
21 |
#include "cesmraddressselectionquery.h"
|
|
22 |
|
|
23 |
#include <aknlists.h>
|
|
24 |
#include <aknpopup.h>
|
|
25 |
#include <bautils.h>
|
|
26 |
#include <esmrgui.rsg>
|
|
27 |
#include <data_caging_path_literals.hrh>
|
|
28 |
|
|
29 |
#include "esmrhelper.h"//locateresourcefile
|
|
30 |
|
|
31 |
// CONSTANTS
|
|
32 |
// Unnamed namespace for local definitions
|
|
33 |
namespace { // codescanner::namespace
|
|
34 |
|
|
35 |
// resource file:
|
|
36 |
_LIT( KResourceFileName, "esmrgui.rsc" );
|
|
37 |
|
|
38 |
// List box format
|
|
39 |
_LIT( KListItemFormat, "%S\t%S" );
|
|
40 |
|
|
41 |
// List box data separator
|
|
42 |
_LIT( KSeparator, "\t" );
|
|
43 |
|
|
44 |
// Address can be 255 max, plus separators
|
|
45 |
const TInt KMaxLength( 300 );
|
|
46 |
|
|
47 |
// Additional length for buffer needed due to separator
|
|
48 |
const TInt KSeparatorLength( 1 );
|
|
49 |
|
|
50 |
|
|
51 |
} // namespace
|
|
52 |
|
|
53 |
// ======== MEMBER FUNCTIONS ========
|
|
54 |
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
// CESMRAddressSelectionQuery::CESMRAddressSelectionQuery
|
|
57 |
// C++ default constructor can NOT contain any code, that
|
|
58 |
// might leave.
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
CESMRAddressSelectionQuery::CESMRAddressSelectionQuery()
|
|
62 |
{
|
|
63 |
FUNC_LOG;
|
|
64 |
// Do nothing
|
|
65 |
}
|
|
66 |
|
|
67 |
// -----------------------------------------------------------------------------
|
|
68 |
// CESMRAddressSelectionQuery::~CESMRAddressSelectionQuery
|
|
69 |
// -----------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
CESMRAddressSelectionQuery::~CESMRAddressSelectionQuery()
|
|
72 |
{
|
|
73 |
FUNC_LOG;
|
|
74 |
iEnv->DeleteResourceFile( iResourceOffset );
|
|
75 |
}
|
|
76 |
|
|
77 |
// -----------------------------------------------------------------------------
|
|
78 |
// CESMRAddressSelectionQuery::NewL
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
CESMRAddressSelectionQuery* CESMRAddressSelectionQuery::NewL()
|
|
82 |
{
|
|
83 |
FUNC_LOG;
|
|
84 |
CESMRAddressSelectionQuery* self = new (ELeave) CESMRAddressSelectionQuery();
|
|
85 |
CleanupStack::PushL( self );
|
|
86 |
self->ConstructL( );
|
|
87 |
CleanupStack::Pop( self );
|
|
88 |
return self;
|
|
89 |
}
|
|
90 |
|
|
91 |
// -----------------------------------------------------------------------------
|
|
92 |
// CESMRAddressSelectionQuery::ConstructL
|
|
93 |
// -----------------------------------------------------------------------------
|
|
94 |
//
|
|
95 |
void CESMRAddressSelectionQuery::ConstructL()
|
|
96 |
{
|
|
97 |
FUNC_LOG;
|
|
98 |
TFileName filename;
|
|
99 |
|
|
100 |
iEnv = CEikonEnv::Static(); // codescanner::eikonenvstatic
|
|
101 |
|
|
102 |
ESMRHelper::LocateResourceFile(
|
|
103 |
KResourceFileName,
|
|
104 |
KDC_RESOURCE_FILES_DIR,
|
|
105 |
filename,
|
|
106 |
&iEnv->FsSession() );
|
|
107 |
|
|
108 |
//for localization
|
|
109 |
BaflUtils::NearestLanguageFile(iEnv->FsSession(),filename);
|
|
110 |
iResourceOffset = iEnv->AddResourceFileL(filename);
|
|
111 |
}
|
|
112 |
|
|
113 |
// -----------------------------------------------------------------------------
|
|
114 |
// CESMRAddressSelectionQuery::ExecuteAddressSelectionListL
|
|
115 |
// -----------------------------------------------------------------------------
|
|
116 |
//
|
|
117 |
TInt CESMRAddressSelectionQuery::ExecuteAddressSelectionListL(
|
|
118 |
const RPointerArray<HBufC>& aAddressArray )
|
|
119 |
{
|
|
120 |
FUNC_LOG;
|
|
121 |
TInt ret = ExecuteL( aAddressArray );
|
|
122 |
return ret;
|
|
123 |
}
|
|
124 |
|
|
125 |
// -----------------------------------------------------------------------------
|
|
126 |
// CESMRAddressSelectionQuery::ExecuteL
|
|
127 |
// -----------------------------------------------------------------------------
|
|
128 |
//
|
|
129 |
TInt CESMRAddressSelectionQuery::ExecuteL(
|
|
130 |
const RPointerArray<HBufC>& aAddressArray )
|
|
131 |
{
|
|
132 |
FUNC_LOG;
|
|
133 |
TInt response( KErrCancel );
|
|
134 |
|
|
135 |
CAknDoublePopupMenuStyleListBox* list =
|
|
136 |
new( ELeave )CAknDoublePopupMenuStyleListBox;
|
|
137 |
CleanupStack::PushL( list );
|
|
138 |
|
|
139 |
CAknPopupList* popupList = CAknPopupList::NewL( list,
|
|
140 |
R_AVKON_SOFTKEYS_SELECT_CANCEL,
|
|
141 |
AknPopupLayouts::EMenuDoubleWindow );
|
|
142 |
CleanupStack::PushL( popupList );
|
|
143 |
|
|
144 |
list->ConstructL( popupList, EAknListBoxMenuList );
|
|
145 |
list->CreateScrollBarFrameL( ETrue );
|
|
146 |
list->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
|
|
147 |
CEikScrollBarFrame::EOn );
|
|
148 |
|
|
149 |
CDesCArrayFlat* itemArray = new(ELeave)CDesCArrayFlat( aAddressArray.Count() );
|
|
150 |
CleanupStack::PushL( itemArray );
|
|
151 |
|
|
152 |
SetListQueryTextsL( itemArray, popupList, aAddressArray );
|
|
153 |
|
|
154 |
CleanupStack::Pop( itemArray );
|
|
155 |
list->Model()->SetItemTextArray( itemArray );
|
|
156 |
list->Model()->SetOwnershipType( ELbmOwnsItemArray );
|
|
157 |
|
|
158 |
// Show popup list
|
|
159 |
TInt popupOk = popupList->ExecuteLD();
|
|
160 |
|
|
161 |
if ( popupOk )
|
|
162 |
{
|
|
163 |
response = list->CurrentItemIndex();
|
|
164 |
}
|
|
165 |
|
|
166 |
CleanupStack::Pop( popupList );
|
|
167 |
CleanupStack::PopAndDestroy( list );
|
|
168 |
|
|
169 |
return response;
|
|
170 |
}
|
|
171 |
|
|
172 |
// -----------------------------------------------------------------------------
|
|
173 |
// CESMRAddressSelectionQuery::SetListQueryTextsL
|
|
174 |
// -----------------------------------------------------------------------------
|
|
175 |
//
|
|
176 |
|
|
177 |
void CESMRAddressSelectionQuery::SetListQueryTextsL(
|
|
178 |
CDesCArrayFlat* aItemArray,
|
|
179 |
CAknPopupList* aPopupList,
|
|
180 |
const RPointerArray<HBufC>& aAddressArray )
|
|
181 |
{
|
|
182 |
FUNC_LOG;
|
|
183 |
// Set title for popup
|
|
184 |
aPopupList->SetTitleL( *iEnv->AllocReadResourceAsDes16LC(
|
|
185 |
R_QTN_MEET_REQ_LOC_ADDRESS_SELECTION_TITLE ) );
|
|
186 |
CleanupStack::PopAndDestroy(); // Resource string
|
|
187 |
|
|
188 |
// Amount of addresses the contact has
|
|
189 |
TInt itemCount = aAddressArray.Count();
|
|
190 |
|
|
191 |
RBuf item;
|
|
192 |
item.Create( KMaxLength );
|
|
193 |
item.CleanupClosePushL();
|
|
194 |
|
|
195 |
for ( TInt i(0); i < itemCount; ++i )
|
|
196 |
{
|
|
197 |
// Descriptor has separator between label and the actual address
|
|
198 |
TPtr16 temp = aAddressArray[i]->Des();
|
|
199 |
|
|
200 |
// Let's truncate too long adresses
|
|
201 |
if( temp.Length() > KMaxLength )
|
|
202 |
{
|
|
203 |
temp.SetLength( KMaxLength );
|
|
204 |
}
|
|
205 |
|
|
206 |
// Finding the first instance of a separator
|
|
207 |
TInt offset = temp.Find( KSeparator );
|
|
208 |
|
|
209 |
if( 0 <= offset && offset < KMaxLength )
|
|
210 |
{
|
|
211 |
// Forming label from the beginning to the first separator
|
|
212 |
TPtrC16 tempLabel = temp.Mid( 0, offset );
|
|
213 |
|
|
214 |
// Forming address from the first separator to the end
|
|
215 |
TPtrC16 tempAddress = temp.Mid(
|
|
216 |
offset + KSeparatorLength,
|
|
217 |
temp.Length() - offset - KSeparatorLength );
|
|
218 |
|
|
219 |
// appending address item to array
|
|
220 |
item.Format( KListItemFormat, &tempLabel, &tempAddress );
|
|
221 |
aItemArray->AppendL( item );
|
|
222 |
}
|
|
223 |
|
|
224 |
}
|
|
225 |
CleanupStack::PopAndDestroy( &item );
|
|
226 |
}
|
|
227 |
|
|
228 |
// End of File
|
|
229 |
|