20
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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 contact editor ringtone field.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include "CPbk2ContactEditorRingtoneField.h"
|
|
20 |
|
|
21 |
// Phonebook 2
|
|
22 |
#include "MPbk2ContactEditorUiBuilder.h"
|
|
23 |
#include "MPbk2ContactEditorUiBuilderExtension.h"
|
|
24 |
#include "MPbk2ContactEditorFieldVisitor.h"
|
|
25 |
#include <MPbk2FieldProperty.h>
|
|
26 |
#include <CPbk2PresentationContactField.h>
|
|
27 |
#include <Pbk2PresentationUtils.h>
|
|
28 |
#include "Pbk2RingtoneCommands.h"
|
|
29 |
#include "CPbk2ContactEditorReadonlyField.h"
|
|
30 |
#include "Pbk2EditorLineIds.hrh"
|
|
31 |
#include <Pbk2UIControls.hrh>
|
|
32 |
#include <Pbk2Config.hrh>
|
|
33 |
|
|
34 |
// Virtual Phonebook
|
|
35 |
#include <MVPbkContactFieldTextData.h>
|
|
36 |
#include <VPbkFieldType.hrh>
|
|
37 |
#include <MVPbkFieldType.h>
|
|
38 |
#include <Pbk2UIControls.rsg>
|
|
39 |
|
|
40 |
// System includes
|
|
41 |
#include <eikcapc.h>
|
|
42 |
#include <eikedwin.h>
|
|
43 |
#include <AknUtils.h>
|
|
44 |
|
|
45 |
// --------------------------------------------------------------------------
|
|
46 |
// CPbk2ContactEditorRingtoneField::CPbk2ContactEditorRingtoneField
|
|
47 |
// --------------------------------------------------------------------------
|
|
48 |
//
|
|
49 |
CPbk2ContactEditorRingtoneField::CPbk2ContactEditorRingtoneField
|
|
50 |
( CPbk2PresentationContactField& aContactField,
|
|
51 |
MPbk2ContactEditorUiBuilder& aUiBuilder,
|
|
52 |
CPbk2IconInfoContainer& aIconInfoContainer ) :
|
|
53 |
CPbk2ContactEditorFieldBase( aContactField, aUiBuilder,
|
|
54 |
aIconInfoContainer )
|
|
55 |
{
|
|
56 |
}
|
|
57 |
|
|
58 |
// --------------------------------------------------------------------------
|
|
59 |
// CPbk2ContactEditorRingtoneField::~CPbk2ContactEditorRingtoneField
|
|
60 |
// --------------------------------------------------------------------------
|
|
61 |
//
|
|
62 |
CPbk2ContactEditorRingtoneField::~CPbk2ContactEditorRingtoneField()
|
|
63 |
{
|
|
64 |
delete iInitialText;
|
|
65 |
}
|
|
66 |
|
|
67 |
// --------------------------------------------------------------------------
|
|
68 |
// CPbk2ContactEditorRingtoneField::NewLC
|
|
69 |
// --------------------------------------------------------------------------
|
|
70 |
//
|
|
71 |
CPbk2ContactEditorRingtoneField* CPbk2ContactEditorRingtoneField::NewLC
|
|
72 |
( CPbk2PresentationContactField& aContactField,
|
|
73 |
MPbk2ContactEditorUiBuilder& aUiBuilder,
|
|
74 |
CPbk2IconInfoContainer& aIconInfoContainer,
|
|
75 |
TInt aCustomPosition)
|
|
76 |
{
|
|
77 |
CPbk2ContactEditorRingtoneField* self =
|
|
78 |
new ( ELeave ) CPbk2ContactEditorRingtoneField( aContactField,
|
|
79 |
aUiBuilder, aIconInfoContainer );
|
|
80 |
CleanupStack::PushL( self );
|
|
81 |
self->ConstructL(aCustomPosition);
|
|
82 |
return self;
|
|
83 |
}
|
|
84 |
|
|
85 |
// --------------------------------------------------------------------------
|
|
86 |
// CPbk2ContactEditorRingtoneField::ConstructL
|
|
87 |
// Create and insert a line in the dialog
|
|
88 |
// --------------------------------------------------------------------------
|
|
89 |
//
|
|
90 |
void CPbk2ContactEditorRingtoneField::ConstructL(TInt aCustomPosition)
|
|
91 |
{
|
|
92 |
// Create and insert a line in the dialog
|
|
93 |
MPbk2ContactEditorUiBuilderExtension* ext =
|
|
94 |
static_cast<MPbk2ContactEditorUiBuilderExtension*>(
|
|
95 |
iUiBuilder.ContactEditorUiBuilderExtension(KNullUid));
|
|
96 |
|
|
97 |
iControl = static_cast<CPbk2ContactEditorReadonlyField*>(
|
|
98 |
ext->AddCustomFieldToFormL(aCustomPosition, R_PBK2_RINGTONE_LINE));
|
|
99 |
iControl->InitializeL(this);
|
|
100 |
SetTextL();
|
|
101 |
iInitialText = iControl->GetTextInHBufL();
|
|
102 |
iControl->CreateTextViewL();
|
|
103 |
iCaptionedCtrl = iUiBuilder.LineControl(ControlId());
|
|
104 |
iUiBuilder.TryChangeFocusL(ControlId());
|
|
105 |
}
|
|
106 |
|
|
107 |
// --------------------------------------------------------------------------
|
|
108 |
// CPbk2ContactEditorRingtoneField::ControlId
|
|
109 |
// --------------------------------------------------------------------------
|
|
110 |
//
|
|
111 |
TInt CPbk2ContactEditorRingtoneField::ControlId() const
|
|
112 |
{
|
|
113 |
return EPbk2EditorLineRingtone;
|
|
114 |
}
|
|
115 |
|
|
116 |
// --------------------------------------------------------------------------
|
|
117 |
// CPbk2ContactEditorRingtoneField::SetTextL
|
|
118 |
// --------------------------------------------------------------------------
|
|
119 |
//
|
|
120 |
void CPbk2ContactEditorRingtoneField::SetTextL()
|
|
121 |
{
|
|
122 |
// Get ringtone or default text
|
|
123 |
TBool getDefaultText(ETrue);
|
|
124 |
TVPbkFieldStorageType type = iContactField.FieldData().DataType();
|
|
125 |
|
|
126 |
if(type == EVPbkFieldStorageTypeText)
|
|
127 |
{
|
|
128 |
getDefaultText = iContactField.FieldData().IsEmpty();
|
|
129 |
}
|
|
130 |
|
|
131 |
//If cold filename for ringtone, show default text (the filename in database
|
|
132 |
//must remain intact however)
|
|
133 |
if( getDefaultText ||
|
|
134 |
!Pbk2RingtoneCommands::IsRingtoneFieldValidL(iContactField))
|
|
135 |
{
|
|
136 |
HBufC* defaultText = CCoeEnv::Static()->AllocReadResourceLC
|
|
137 |
( R_QTN_PHOB_FIELD_DEFAULT_TONE );
|
|
138 |
TPtrC dataPtr(*defaultText);
|
|
139 |
FormatTextL( dataPtr, ETrue );
|
|
140 |
CleanupStack::PopAndDestroy(defaultText);
|
|
141 |
iTextState = ENoData;
|
|
142 |
}
|
|
143 |
else
|
|
144 |
{
|
|
145 |
TPtrC dataPtr(MVPbkContactFieldTextData::Cast(
|
|
146 |
iContactField.FieldData()).Text());
|
|
147 |
FormatTextL( dataPtr, EFalse );
|
|
148 |
iTextState = EFilename;
|
|
149 |
}
|
|
150 |
}
|
|
151 |
|
|
152 |
// --------------------------------------------------------------------------
|
|
153 |
// CPbk2ContactEditorRingtoneField::FormatTextL
|
|
154 |
// --------------------------------------------------------------------------
|
|
155 |
//
|
|
156 |
void CPbk2ContactEditorRingtoneField::FormatTextL(TPtrC aDataPtr, TBool aIsDefault)
|
|
157 |
{
|
|
158 |
HBufC* textBuf = HBufC::NewLC(aDataPtr.Length());
|
|
159 |
TPtr text = textBuf->Des();
|
|
160 |
text.Zero();
|
|
161 |
Pbk2PresentationUtils::AppendWithNewlineTranslationL(text, aDataPtr);
|
|
162 |
|
|
163 |
TParsePtr fileNameParser( text );
|
|
164 |
TPtrC baseName;
|
|
165 |
if ( aIsDefault )
|
|
166 |
{
|
|
167 |
// If it is a default string, then use FullName() to parse.
|
|
168 |
// The reason is there might be a dot in the end of the string and the
|
|
169 |
// characters after that would be removed if using Name().
|
|
170 |
// Example: "Them h.anh" in Vietnamese.
|
|
171 |
baseName.Set( fileNameParser.FullName() );
|
|
172 |
}
|
|
173 |
else
|
|
174 |
{
|
|
175 |
baseName.Set( fileNameParser.Name() );
|
|
176 |
}
|
|
177 |
// Set formatted text to editor control
|
|
178 |
iControl->SetTextL(&baseName);
|
|
179 |
// SetTextL method above copied the text to the control,
|
|
180 |
// so it is safe to destroy the buffer
|
|
181 |
CleanupStack::PopAndDestroy(textBuf);
|
|
182 |
iUiBuilder.LoadBitmapToFieldL
|
|
183 |
( iContactField.FieldProperty(), iIconInfoContainer, ControlId() );
|
|
184 |
}
|
|
185 |
|
|
186 |
// --------------------------------------------------------------------------
|
|
187 |
// CPbk2ContactEditorRingtoneField::Control
|
|
188 |
// --------------------------------------------------------------------------
|
|
189 |
//
|
|
190 |
CEikEdwin* CPbk2ContactEditorRingtoneField::Control() const
|
|
191 |
{
|
|
192 |
// We don't show anything out
|
|
193 |
return NULL;
|
|
194 |
}
|
|
195 |
|
|
196 |
// -----------------------------------------------------------------------------
|
|
197 |
// CPbk2ContactEditorRingtoneField::ControlTextL
|
|
198 |
// -----------------------------------------------------------------------------
|
|
199 |
//
|
|
200 |
HBufC* CPbk2ContactEditorRingtoneField::ControlTextL() const
|
|
201 |
{
|
|
202 |
return CPbk2ContactEditorFieldBase::ControlTextL();
|
|
203 |
}
|
|
204 |
|
|
205 |
// --------------------------------------------------------------------------
|
|
206 |
// CPbk2ContactEditorRingtoneField::SaveFieldL
|
|
207 |
// --------------------------------------------------------------------------
|
|
208 |
//
|
|
209 |
void CPbk2ContactEditorRingtoneField::SaveFieldL()
|
|
210 |
{
|
|
211 |
HBufC* text = iControl->GetTextInHBufL();
|
|
212 |
CleanupStack::PushL(text);
|
|
213 |
|
|
214 |
if(iInitialText->Compare(*text) )
|
|
215 |
{
|
|
216 |
iContactDataHasChanged = ETrue;
|
|
217 |
}
|
|
218 |
else
|
|
219 |
{
|
|
220 |
iContactDataHasChanged = EFalse;
|
|
221 |
}
|
|
222 |
|
|
223 |
CleanupStack::PopAndDestroy(text);
|
|
224 |
}
|
|
225 |
|
|
226 |
// -----------------------------------------------------------------------------
|
|
227 |
// CPbk2ContactEditorFieldBase::HandleCustomFieldCommandL
|
|
228 |
// -----------------------------------------------------------------------------
|
|
229 |
//
|
|
230 |
TBool CPbk2ContactEditorRingtoneField::HandleCustomFieldCommandL(TInt aCommand )
|
|
231 |
{
|
|
232 |
TBool ret(EFalse);
|
|
233 |
MPbk2ContactEditorUiBuilderExtension* ext =
|
|
234 |
static_cast<MPbk2ContactEditorUiBuilderExtension*>(
|
|
235 |
iUiBuilder.ContactEditorUiBuilderExtension(KNullUid));
|
|
236 |
|
|
237 |
if(aCommand == EPbk2CmdEditorHandleCustomSelect)
|
|
238 |
{
|
|
239 |
#ifdef ECE_DISABLE_CONTEXT_MENU
|
|
240 |
if (ContactField().FieldData().IsEmpty()
|
|
241 |
|| !Pbk2RingtoneCommands::IsRingtoneFieldValidL(ContactField()) )
|
|
242 |
{
|
|
243 |
ret = ext->HandleCustomFieldCommandL(EPbk2CmdEditorChangeRingtone);
|
|
244 |
}
|
|
245 |
else
|
|
246 |
{
|
|
247 |
ret = ext->HandleCustomFieldCommandL(EPbk2CmdEditorContextMenu);
|
|
248 |
}
|
|
249 |
#else
|
|
250 |
ret = ext->HandleCustomFieldCommandL(EPbk2CmdEditorChangeRingtone);
|
|
251 |
#endif
|
|
252 |
}
|
|
253 |
else if(aCommand == EPbk2CmdEditorHandleCustomRemove)
|
|
254 |
{
|
|
255 |
ret = ext->HandleCustomFieldCommandL(EPbk2CmdEditorRemoveRingtone);
|
|
256 |
}
|
|
257 |
return ret;
|
|
258 |
}
|
|
259 |
|
|
260 |
// --------------------------------------------------------------------------
|
|
261 |
// CPbk2ContactEditorRingtoneField::ActivateL
|
|
262 |
// --------------------------------------------------------------------------
|
|
263 |
//
|
|
264 |
void CPbk2ContactEditorRingtoneField::ActivateL()
|
|
265 |
{
|
|
266 |
iCaptionedCtrl->ActivateL();
|
|
267 |
}
|
|
268 |
|
|
269 |
// --------------------------------------------------------------------------
|
|
270 |
// CPbk2ContactEditorRingtoneField::AcceptL
|
|
271 |
// --------------------------------------------------------------------------
|
|
272 |
//
|
|
273 |
void CPbk2ContactEditorRingtoneField::AcceptL
|
|
274 |
( MPbk2ContactEditorFieldVisitor& aVisitor )
|
|
275 |
{
|
|
276 |
aVisitor.VisitL( *this );
|
|
277 |
}
|
|
278 |
|
|
279 |
// -----------------------------------------------------------------------------
|
|
280 |
// CPbk2ContactEditorRingtoneField::ConsumesKeyEvent
|
|
281 |
// -----------------------------------------------------------------------------
|
|
282 |
//
|
|
283 |
TBool CPbk2ContactEditorRingtoneField::ConsumesKeyEvent
|
|
284 |
( const TKeyEvent& aKeyEvent, TEventCode aType )
|
|
285 |
{
|
|
286 |
TKeyResponse keyResponse = iControl->OfferKeyEventL( aKeyEvent, aType );
|
|
287 |
|
|
288 |
if ( EKeyWasConsumed == keyResponse )
|
|
289 |
{
|
|
290 |
return ETrue;
|
|
291 |
}
|
|
292 |
|
|
293 |
return EFalse;
|
|
294 |
}
|
|
295 |
|
|
296 |
// -----------------------------------------------------------------------------
|
|
297 |
// CPbk2ContactEditorImageField::TextState
|
|
298 |
// -----------------------------------------------------------------------------
|
|
299 |
//
|
|
300 |
TInt CPbk2ContactEditorRingtoneField::TextState()
|
|
301 |
{
|
|
302 |
return iTextState;
|
|
303 |
}
|
|
304 |
|
|
305 |
// -----------------------------------------------------------------------------
|
|
306 |
// CPbk2ContactEditorRingtoneField::ContactEditorFieldExtension
|
|
307 |
// -----------------------------------------------------------------------------
|
|
308 |
//
|
|
309 |
TAny* CPbk2ContactEditorRingtoneField::ContactEditorFieldExtension(
|
|
310 |
TUid aExtensionUid )
|
|
311 |
{
|
|
312 |
if( aExtensionUid == KMPbk2ContactEditorFieldExtension2Uid )
|
|
313 |
{
|
|
314 |
return static_cast<MPbk2ContactEditorField2*>( this );
|
|
315 |
}
|
|
316 |
|
|
317 |
return this;
|
|
318 |
}
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
// End of File
|