|
1 /* |
|
2 * Copyright (c) 2006-2006 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: CPSStateMapperText class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <cfcontextinterface.h> |
|
20 #include <cfcontextobject.h> |
|
21 |
|
22 #include "psstatemappertext.h" |
|
23 |
|
24 /* |
|
25 namespace |
|
26 { |
|
27 #ifdef _DEBUG |
|
28 |
|
29 // Panic category |
|
30 _LIT( KPanicCat, "PSStateMapText" ); |
|
31 |
|
32 // Panic codes |
|
33 enum TPanicReason |
|
34 { |
|
35 EInvalidConstructionParameters |
|
36 }; |
|
37 |
|
38 // Local panic function |
|
39 LOCAL_C void Panic( TInt aCode ) |
|
40 { |
|
41 User::Panic( KPanicCat, aCode ); |
|
42 } |
|
43 |
|
44 #endif |
|
45 } |
|
46 */ |
|
47 |
|
48 CPSStateMapperText* CPSStateMapperText::NewL( |
|
49 MCFContextInterface& aCF ) |
|
50 { |
|
51 CPSStateMapperText* self = CPSStateMapperText::NewLC( aCF ); |
|
52 CleanupStack::Pop(); |
|
53 |
|
54 return self; |
|
55 } |
|
56 |
|
57 CPSStateMapperText* CPSStateMapperText::NewLC( |
|
58 MCFContextInterface& aCF ) |
|
59 { |
|
60 CPSStateMapperText* self = new( ELeave ) CPSStateMapperText( aCF ); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL( ); |
|
63 |
|
64 return self; |
|
65 } |
|
66 |
|
67 // Destructor |
|
68 CPSStateMapperText::~CPSStateMapperText() |
|
69 { |
|
70 if(iStartCB) |
|
71 { |
|
72 iStartCB->Cancel(); |
|
73 delete iStartCB; iStartCB = 0; |
|
74 } |
|
75 iTextMappings.ResetAndDestroy(); |
|
76 } |
|
77 |
|
78 CPSStateMapperText::CPSStateMapperText( |
|
79 MCFContextInterface& aCF ) : CPSStateMapper( aCF ) |
|
80 { |
|
81 } |
|
82 |
|
83 // METHODS |
|
84 |
|
85 TInt CPSStateMapperText::MapperType() const |
|
86 { |
|
87 return EPSTextMapper; |
|
88 } |
|
89 |
|
90 void CPSStateMapperText::AddMappingL(const TDesC& aPSValue, |
|
91 const TDesC& aContextValue) |
|
92 { |
|
93 CTextPair* mapping = CTextPair::NewLC(aPSValue, aContextValue ); |
|
94 iTextMappings.AppendL(mapping); |
|
95 CleanupStack::Pop(); // mapping |
|
96 } |
|
97 |
|
98 |
|
99 void CPSStateMapperText::Define() |
|
100 { |
|
101 RProperty::Define( iPSCategory, |
|
102 iPSKey, |
|
103 RProperty::EText ); |
|
104 |
|
105 iCF.DefineContext( *iSource, |
|
106 *iType, |
|
107 iSecurityPolicy ); |
|
108 } |
|
109 |
|
110 void CPSStateMapperText::InitializeL() |
|
111 { |
|
112 User::LeaveIfError( |
|
113 iProperty.Attach( iPSCategory, iPSKey ) ); |
|
114 iStartCB = new (ELeave) CAsyncCallBack(TCallBack(CPSStateMapperText::StartCallback, this), EPriorityStandard); |
|
115 iStartCB->CallBack(); |
|
116 } |
|
117 |
|
118 //----------------------------------------------------------------------------- |
|
119 // CPSStateMapperText::ProperyChangedL |
|
120 //----------------------------------------------------------------------------- |
|
121 // |
|
122 void CPSStateMapperText::ProperyChangedL() |
|
123 { |
|
124 TBool mappingFound = EFalse; |
|
125 |
|
126 HBufC* psvalue = HBufC::NewLC( 512 ); // >> cleanup |
|
127 TPtr bufPtr = psvalue->Des(); |
|
128 bufPtr.Zero(); |
|
129 |
|
130 if ( iProperty.Get ( bufPtr ) == KErrNone ) |
|
131 { |
|
132 for (TInt i = 0; i < iTextMappings.Count(); i++) |
|
133 { |
|
134 if (iTextMappings[i]->Text1() == *psvalue) |
|
135 { |
|
136 mappingFound = ETrue; |
|
137 |
|
138 // Configure context object |
|
139 iContext->SetSourceL( *iSource ); |
|
140 iContext->SetTypeL( *iType ); |
|
141 iContext->SetValueL( iTextMappings[i]->Text2() ); |
|
142 |
|
143 // Publish |
|
144 RThread thread; |
|
145 iCF.PublishContext( *iContext, thread ); |
|
146 thread.Close(); |
|
147 } |
|
148 } |
|
149 |
|
150 if ( !mappingFound && iPassThrough ) |
|
151 { |
|
152 // Configure context object |
|
153 iContext->SetSourceL( *iSource ); |
|
154 iContext->SetTypeL( *iType ); |
|
155 iContext->SetValueL( *psvalue ); |
|
156 |
|
157 // Publish |
|
158 RThread thread; |
|
159 iCF.PublishContext( *iContext, thread ); |
|
160 thread.Close(); |
|
161 } |
|
162 } |
|
163 |
|
164 CleanupStack::PopAndDestroy(); // psvalue |
|
165 } |
|
166 |
|
167 TInt CPSStateMapperText::StartCallback(TAny* aPtr) |
|
168 { |
|
169 static_cast<CPSStateMapperText*>(aPtr)->DoStart(); |
|
170 |
|
171 return 0; |
|
172 } |
|
173 |
|
174 void CPSStateMapperText::DoStart() |
|
175 { |
|
176 Subscribe(); |
|
177 TRAP_IGNORE(ProperyChangedL()); |
|
178 } |
|
179 |