19
|
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: Profile index handler (for use of Settings Container
|
|
15 |
* if multiple profiles are edited)
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDES
|
|
21 |
#include "CProfileIndexHandler.h"
|
|
22 |
|
|
23 |
#include <MProfilesNamesArray.h>
|
|
24 |
#include <eiklbx.h>
|
|
25 |
|
|
26 |
#include "CProfileEngineHandler.h"
|
|
27 |
|
|
28 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
29 |
|
|
30 |
// -----------------------------------------------------------------------------
|
|
31 |
// CProfileIndexHandler::CProfileIndexHandler
|
|
32 |
// C++ constructor can NOT contain any code, that might leave.
|
|
33 |
// -----------------------------------------------------------------------------
|
|
34 |
//
|
|
35 |
CProfileIndexHandler::CProfileIndexHandler(
|
|
36 |
CProfileEngineHandler& aEngineHandler )
|
|
37 |
: iEngineHandler( aEngineHandler )
|
|
38 |
{
|
|
39 |
}
|
|
40 |
|
|
41 |
void CProfileIndexHandler::ConstructL()
|
|
42 |
{
|
|
43 |
}
|
|
44 |
|
|
45 |
EXPORT_C CProfileIndexHandler* CProfileIndexHandler::NewL(
|
|
46 |
CProfileEngineHandler& aEngineHandler )
|
|
47 |
{
|
|
48 |
CProfileIndexHandler* self =
|
|
49 |
new( ELeave ) CProfileIndexHandler( aEngineHandler );
|
|
50 |
CleanupStack::PushL( self );
|
|
51 |
self->ConstructL();
|
|
52 |
CleanupStack::Pop( self );
|
|
53 |
return self;
|
|
54 |
}
|
|
55 |
|
|
56 |
CProfileIndexHandler::~CProfileIndexHandler()
|
|
57 |
{
|
|
58 |
iIndexArray.Close();
|
|
59 |
}
|
|
60 |
|
|
61 |
// -----------------------------------------------------------------------------
|
|
62 |
// CProfileIndexHandler::CurrentProfileIndex
|
|
63 |
// -----------------------------------------------------------------------------
|
|
64 |
//
|
|
65 |
EXPORT_C TInt CProfileIndexHandler::CurrentProfileIndex() const
|
|
66 |
{
|
|
67 |
return iCurrentProfileIndex;
|
|
68 |
}
|
|
69 |
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
// CProfileIndexHandler::SetCurrentProfileIndex
|
|
72 |
// Note that there is no boundary checking.
|
|
73 |
// -----------------------------------------------------------------------------
|
|
74 |
//
|
|
75 |
EXPORT_C void CProfileIndexHandler::SetCurrentProfileIndex( TInt aIndex )
|
|
76 |
{
|
|
77 |
iCurrentProfileIndex = aIndex;
|
|
78 |
}
|
|
79 |
|
|
80 |
// -----------------------------------------------------------------------------
|
|
81 |
// CProfileIndexHandler::CreateIndexArrayL
|
|
82 |
// Resets the index array and populates it with zeroes
|
|
83 |
// -----------------------------------------------------------------------------
|
|
84 |
//
|
|
85 |
void CProfileIndexHandler::CreateIndexArrayL()
|
|
86 |
{
|
|
87 |
iIndexArray.Reset();
|
|
88 |
TItem item = { 0, 0 };
|
|
89 |
TInt count( iEngineHandler.IdArray()->MdcaCount() );
|
|
90 |
while( --count >= 0 )
|
|
91 |
{
|
|
92 |
User::LeaveIfError( iIndexArray.Append( item ) );
|
|
93 |
}
|
|
94 |
}
|
|
95 |
|
|
96 |
// -----------------------------------------------------------------------------
|
|
97 |
// CProfileIndexHandler::StoreIndices
|
|
98 |
// -----------------------------------------------------------------------------
|
|
99 |
//
|
|
100 |
void CProfileIndexHandler::StoreIndices()
|
|
101 |
{
|
|
102 |
if( !iListBox )
|
|
103 |
{
|
|
104 |
return;
|
|
105 |
}
|
|
106 |
|
|
107 |
TItem& item = iIndexArray[iCurrentProfileIndex];
|
|
108 |
item.iIndex = iListBox->View()->CurrentItemIndex();
|
|
109 |
item.iTopIndex = iListBox->View()->TopItemIndex() - item.iIndex;
|
|
110 |
}
|
|
111 |
|
|
112 |
// -----------------------------------------------------------------------------
|
|
113 |
// CProfileIndexHandler::LoadIndices
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
//
|
|
116 |
void CProfileIndexHandler::LoadIndices()
|
|
117 |
{
|
|
118 |
if( !iListBox )
|
|
119 |
{
|
|
120 |
return;
|
|
121 |
}
|
|
122 |
|
|
123 |
const TInt KMaxLastIndex( 2 ); // Three items fit to screen at the same time
|
|
124 |
|
|
125 |
TInt lastIndex( iListBox->Model()->MatchableTextArray()->MdcaCount() - 1 );
|
|
126 |
|
|
127 |
TItem item = iIndexArray[iCurrentProfileIndex];
|
|
128 |
if( item.iIndex > lastIndex )
|
|
129 |
{
|
|
130 |
item.iIndex = lastIndex;
|
|
131 |
}
|
|
132 |
if( item.iIndex < 0 )
|
|
133 |
{
|
|
134 |
item.iIndex = 0;
|
|
135 |
}
|
|
136 |
item.iTopIndex += item.iIndex;
|
|
137 |
if( item.iTopIndex > lastIndex - KMaxLastIndex )
|
|
138 |
{
|
|
139 |
item.iTopIndex = lastIndex - KMaxLastIndex;
|
|
140 |
}
|
|
141 |
if( item.iTopIndex < 0 )
|
|
142 |
{
|
|
143 |
item.iTopIndex = 0;
|
|
144 |
}
|
|
145 |
|
|
146 |
iListBox->View()->SetCurrentItemIndex( item.iIndex );
|
|
147 |
iListBox->View()->SetTopItemIndex( item.iTopIndex );
|
|
148 |
iListBox->DrawDeferred();
|
|
149 |
}
|
|
150 |
|
|
151 |
// -----------------------------------------------------------------------------
|
|
152 |
// CProfileIndexHandler::IndexAt
|
|
153 |
// -----------------------------------------------------------------------------
|
|
154 |
//
|
|
155 |
TInt CProfileIndexHandler::IndexAt( TInt aIndex ) const
|
|
156 |
{
|
|
157 |
return iIndexArray[aIndex].iIndex;
|
|
158 |
}
|
|
159 |
|
|
160 |
// -----------------------------------------------------------------------------
|
|
161 |
// CProfileIndexHandler::TopIndexAt
|
|
162 |
// -----------------------------------------------------------------------------
|
|
163 |
//
|
|
164 |
TInt CProfileIndexHandler::TopIndexAt( TInt aIndex ) const
|
|
165 |
{
|
|
166 |
return iIndexArray[aIndex].iTopIndex;
|
|
167 |
}
|
|
168 |
|
|
169 |
// -----------------------------------------------------------------------------
|
|
170 |
// CProfileIndexHandler::RemoveAndInsert
|
|
171 |
// -----------------------------------------------------------------------------
|
|
172 |
//
|
|
173 |
TInt CProfileIndexHandler::RemoveAndInsert(
|
|
174 |
TInt aOldIndex, TInt aNewIndex, TInt aIndexValue, TInt aTopIndexValue )
|
|
175 |
{
|
|
176 |
TInt count( iIndexArray.Count() );
|
|
177 |
if( aOldIndex < 0 || aOldIndex >= count )
|
|
178 |
{
|
|
179 |
return KErrNotFound;
|
|
180 |
}
|
|
181 |
if( aNewIndex < 0 || aNewIndex > count )
|
|
182 |
{
|
|
183 |
return KErrArgument;
|
|
184 |
}
|
|
185 |
iIndexArray.Remove( aOldIndex );
|
|
186 |
TItem item = { aIndexValue, aTopIndexValue };
|
|
187 |
iIndexArray.Insert( item, aNewIndex );
|
|
188 |
return KErrNone;
|
|
189 |
}
|
|
190 |
|
|
191 |
// -----------------------------------------------------------------------------
|
|
192 |
// CProfileIndexHandler::SetListBox
|
|
193 |
// -----------------------------------------------------------------------------
|
|
194 |
//
|
|
195 |
void CProfileIndexHandler::SetListBox( CEikListBox* aListBox )
|
|
196 |
{
|
|
197 |
iListBox = aListBox;
|
|
198 |
}
|
|
199 |
|
|
200 |
// -----------------------------------------------------------------------------
|
|
201 |
// CProfileIndexHandler::ReadIdArrayAndUpdateL
|
|
202 |
// -----------------------------------------------------------------------------
|
|
203 |
//
|
|
204 |
TInt CProfileIndexHandler::ReadIdArrayAndUpdateL()
|
|
205 |
{
|
|
206 |
// Index of the profile before the engine rearranges the profiles.
|
|
207 |
TInt oldProfileIndex( iCurrentProfileIndex );
|
|
208 |
|
|
209 |
// ID of the profile so that we can find it after the engine
|
|
210 |
// rearranges the profiles.
|
|
211 |
TInt profileId( iEngineHandler.IdForIndex( oldProfileIndex ) );
|
|
212 |
|
|
213 |
// Store the indices for edited profile.
|
|
214 |
StoreIndices();
|
|
215 |
|
|
216 |
TInt newItemIndex( IndexAt( oldProfileIndex ) );
|
|
217 |
TInt newTopItemIndex( TopIndexAt( oldProfileIndex ) );
|
|
218 |
|
|
219 |
// Refresh profile names. Order of the profiles may change.
|
|
220 |
iEngineHandler.ReadIdArrayL();
|
|
221 |
|
|
222 |
// Find out which of the profiles is now the edited profile
|
|
223 |
TInt newProfileIndex( iEngineHandler.IdArray()->FindById( profileId ) );
|
|
224 |
|
|
225 |
// Set it to current profile
|
|
226 |
SetCurrentProfileIndex( newProfileIndex );
|
|
227 |
|
|
228 |
// Update indices
|
|
229 |
User::LeaveIfError( RemoveAndInsert( oldProfileIndex, newProfileIndex,
|
|
230 |
newItemIndex, newTopItemIndex ) );
|
|
231 |
|
|
232 |
return newProfileIndex;
|
|
233 |
}
|
|
234 |
|
|
235 |
// End of File
|