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 group name query dialog. |
|
15 |
* |
|
16 |
*/ |
|
17 |
||
18 |
||
19 |
#include "CPguGroupNameQueryDlg.h" |
|
20 |
||
21 |
// Phonebook 2 |
|
22 |
#include "Pbk2GroupConsts.h" |
|
23 |
#include <MPbk2ContactNameFormatter.h> |
|
21
9da50d567e3c
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
20
diff
changeset
|
24 |
#include <pbk2groupuires.rsg> |
20 | 25 |
#include <Pbk2PresentationUtils.h> |
26 |
#include <CPbk2AppUiBase.h> |
|
27 |
#include <MPbk2StartupMonitor.h> |
|
28 |
||
29 |
// Virtual Phonebook |
|
30 |
#include <MVPbkContactGroup.h> |
|
31 |
#include <MVPbkContactStore.h> |
|
32 |
#include <MVPbkContactViewBase.h> |
|
33 |
||
34 |
// System includes |
|
35 |
#include <aknnotewrappers.h> |
|
36 |
#include <StringLoader.h> |
|
37 |
||
38 |
/// Unnamed namespace for local definitions |
|
39 |
namespace { |
|
40 |
||
41 |
/** |
|
42 |
* Strips directionality markers from given text. |
|
43 |
* |
|
44 |
* @param aText The text to strip. |
|
45 |
*/ |
|
46 |
void StripCharacters( TDes& aText) |
|
47 |
{ |
|
48 |
// Strip any directionality markers to get pure text |
|
49 |
const TUint32 KPbk2LeftToRightMarker = 0x200F; |
|
50 |
const TUint32 KPbk2RightToLeftMarker = 0x200E; |
|
51 |
const TInt markersLength( 2 ); |
|
52 |
TBuf<markersLength> bufMarkers; |
|
53 |
bufMarkers.Append( KPbk2LeftToRightMarker ); |
|
54 |
bufMarkers.Append( KPbk2RightToLeftMarker ); |
|
55 |
AknTextUtils::StripCharacters( aText, bufMarkers ); |
|
56 |
} |
|
57 |
||
58 |
} /// namespace |
|
59 |
||
60 |
// -------------------------------------------------------------------------- |
|
61 |
// CPguGroupNameQueryDlg::CPguGroupNameQueryDlg |
|
62 |
// -------------------------------------------------------------------------- |
|
63 |
// |
|
64 |
CPguGroupNameQueryDlg::CPguGroupNameQueryDlg |
|
65 |
( TDes& aDataText, MVPbkContactViewBase& aGroupsView, |
|
66 |
MPbk2ContactNameFormatter& aNameFormatter ) : |
|
67 |
CAknTextQueryDialog( aDataText ), |
|
68 |
iGroupsListView( aGroupsView ), |
|
69 |
iNameFormatter( aNameFormatter ) |
|
70 |
{ |
|
71 |
} |
|
72 |
||
73 |
// -------------------------------------------------------------------------- |
|
74 |
// CPguGroupNameQueryDlg::~CPguGroupNameQueryDlg |
|
75 |
// -------------------------------------------------------------------------- |
|
76 |
// |
|
77 |
CPguGroupNameQueryDlg::~CPguGroupNameQueryDlg() |
|
78 |
{ |
|
79 |
iCoeEnv->RemoveForegroundObserver( *this ); |
|
80 |
delete iOriginalName; |
|
81 |
} |
|
82 |
||
83 |
// -------------------------------------------------------------------------- |
|
84 |
// CPguGroupNameQueryDlg::ConstructL |
|
85 |
// -------------------------------------------------------------------------- |
|
86 |
// |
|
87 |
inline void CPguGroupNameQueryDlg::ConstructL |
|
88 |
( TDes& aDataText, TBool aNameGeneration ) |
|
89 |
{ |
|
90 |
// Take a copy of the original name |
|
91 |
iOriginalName = HBufC::NewL( KGroupLabelLength ); |
|
92 |
TPtr originalTextPtr = iOriginalName->Des(); |
|
93 |
originalTextPtr.Append( aDataText ); |
|
94 |
||
95 |
if ( aNameGeneration ) |
|
96 |
{ |
|
97 |
UpdateGroupTitleL(); |
|
98 |
} |
|
99 |
iCoeEnv->AddForegroundObserverL( *this ); |
|
100 |
} |
|
101 |
||
102 |
// -------------------------------------------------------------------------- |
|
103 |
// CPguGroupNameQueryDlg::NewL |
|
104 |
// -------------------------------------------------------------------------- |
|
105 |
// |
|
106 |
CPguGroupNameQueryDlg* CPguGroupNameQueryDlg::NewL |
|
107 |
( TDes& aDataText, MVPbkContactViewBase& aGroupsView, |
|
108 |
MPbk2ContactNameFormatter& aNameFormatter, |
|
109 |
TBool aNameGeneration ) |
|
110 |
{ |
|
111 |
CPguGroupNameQueryDlg* self = new ( ELeave ) CPguGroupNameQueryDlg |
|
112 |
( aDataText, aGroupsView, aNameFormatter ); |
|
113 |
CleanupStack::PushL( self ); |
|
114 |
self->ConstructL( aDataText, aNameGeneration ); |
|
115 |
CleanupStack::Pop( self ); |
|
116 |
return self; |
|
117 |
} |
|
118 |
||
119 |
// -------------------------------------------------------------------------- |
|
120 |
// CPguGroupNameQueryDlg::OkToExitL |
|
121 |
// -------------------------------------------------------------------------- |
|
122 |
// |
|
123 |
TBool CPguGroupNameQueryDlg::OkToExitL( TInt aButtonId ) |
|
124 |
{ |
|
125 |
TBool result = CAknTextQueryDialog::OkToExitL( aButtonId ); |
|
126 |
||
127 |
HBufC* text = Text().AllocLC(); |
|
128 |
TPtr textPtr( text->Des() ); |
|
129 |
StripCharacters( textPtr ); |
|
130 |
||
131 |
// Format text |
|
132 |
HBufC* formattedText = HBufC::NewLC( text->Length() ); |
|
133 |
TPtr formattedTextPtr( formattedText->Des() ); |
|
134 |
Pbk2PresentationUtils::TrimRightAppend( *text, formattedTextPtr ); |
|
135 |
||
136 |
TBool nameAlreadyExists = ContainsL( *formattedText ); |
|
137 |
||
138 |
if ( nameAlreadyExists ) |
|
139 |
{ |
|
140 |
if (iOriginalName->CompareC( *formattedText ) != 0 ) |
|
141 |
{ |
|
142 |
// Display information note |
|
143 |
HBufC* prompt = StringLoader::LoadLC( |
|
144 |
R_QTN_FLDR_NAME_ALREADY_USED, *formattedText ); |
|
145 |
||
146 |
CAknInformationNote* dlg = new(ELeave) CAknInformationNote( ETrue ); |
|
147 |
dlg->ExecuteLD( *prompt ); |
|
148 |
CleanupStack::PopAndDestroy(); // prompt |
|
149 |
||
150 |
CAknQueryControl* queryControl = QueryControl(); |
|
151 |
if ( queryControl ) |
|
152 |
{ |
|
153 |
CEikEdwin* edwin = static_cast<CEikEdwin*>( |
|
154 |
queryControl->ControlByLayoutOrNull( EDataLayout ) ); |
|
155 |
if ( edwin ) |
|
156 |
{ |
|
157 |
edwin->SetSelectionL( edwin->TextLength(), 0 ); |
|
158 |
} |
|
159 |
} |
|
160 |
result = EFalse; |
|
161 |
} |
|
162 |
} |
|
163 |
||
164 |
CleanupStack::PopAndDestroy( 2 ); // formattedText, text |
|
165 |
return result; |
|
166 |
} |
|
167 |
||
168 |
// -------------------------------------------------------------------------- |
|
169 |
// CPguGroupNameQueryDlg::UpdateGroupTitleL |
|
170 |
// -------------------------------------------------------------------------- |
|
171 |
// |
|
172 |
void CPguGroupNameQueryDlg::UpdateGroupTitleL() |
|
173 |
{ |
|
174 |
HBufC* groupTitle; |
|
175 |
TInt newGroupNumber = iGroupsListView.ContactCountL() + 1; |
|
176 |
groupTitle = StringLoader::LoadL( R_PHONEBOOK2_QTN_FLDR_DEFAULT_GROUP_NAME, newGroupNumber ); |
|
177 |
Text().Copy( *groupTitle ); |
|
178 |
delete groupTitle; |
|
179 |
} |
|
180 |
||
181 |
// -------------------------------------------------------------------------- |
|
182 |
// CPguGroupNameQueryDlg::ContainsL |
|
183 |
// Checks if the group view contains a group named similarly as the given |
|
184 |
// name. |
|
185 |
// -------------------------------------------------------------------------- |
|
186 |
// |
|
187 |
TBool CPguGroupNameQueryDlg::ContainsL( const TDesC& aText ) |
|
188 |
{ |
|
189 |
TBool ret = EFalse; |
|
190 |
||
191 |
const TInt count( iGroupsListView.ContactCountL() ); |
|
192 |
for ( TInt i(0); i < count; ++i ) |
|
193 |
{ |
|
194 |
const MVPbkViewContact& contact = iGroupsListView.ContactAtL( i ); |
|
195 |
HBufC* groupName = iNameFormatter.GetContactTitleOrNullL |
|
196 |
( contact.Fields(), |
|
197 |
MPbk2ContactNameFormatter::EPreserveLeadingSpaces ); |
|
198 |
||
199 |
if ( groupName ) |
|
200 |
{ |
|
201 |
TPtr groupNamePtr( groupName->Des() ); |
|
202 |
StripCharacters( groupNamePtr ); |
|
203 |
||
204 |
if ( groupNamePtr.Compare( aText ) == 0 ) |
|
205 |
{ |
|
206 |
ret = ETrue; |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
delete groupName; |
|
211 |
} |
|
212 |
||
213 |
return ret; |
|
214 |
} |
|
215 |
||
216 |
// -------------------------------------------------------------------------- |
|
217 |
// CPguGroupNameQueryDlg::HandleLosingForeground |
|
218 |
// -------------------------------------------------------------------------- |
|
219 |
// |
|
220 |
void CPguGroupNameQueryDlg::HandleLosingForeground() |
|
221 |
{ |
|
222 |
} |
|
223 |
||
224 |
// -------------------------------------------------------------------------- |
|
225 |
// CPguGroupNameQueryDlg::HandleGainingForeground |
|
226 |
// -------------------------------------------------------------------------- |
|
227 |
// |
|
228 |
void CPguGroupNameQueryDlg::HandleGainingForeground() |
|
229 |
{ |
|
230 |
MPbk2AppUi* pbk2AppUI = NULL; |
|
231 |
pbk2AppUI = Phonebook2::Pbk2AppUi(); |
|
232 |
||
233 |
if ( pbk2AppUI && pbk2AppUI->Pbk2StartupMonitor() ) |
|
234 |
{ |
|
235 |
TAny* extension = pbk2AppUI->Pbk2StartupMonitor() |
|
236 |
->StartupMonitorExtension( KPbk2StartupMonitorExtensionUid ); |
|
237 |
||
238 |
if( extension ) |
|
239 |
{ |
|
240 |
MPbk2StartupMonitorExtension* startupMonitorExtension = |
|
241 |
static_cast<MPbk2StartupMonitorExtension*>( extension ); |
|
242 |
||
243 |
if( startupMonitorExtension ) |
|
244 |
{ |
|
245 |
startupMonitorExtension->DisableMonitoring(); |
|
246 |
} |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
// End of File |