|
1 /* |
|
2 * Copyright (c) 2005-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: CPS Publishing for text editor. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "xntexteditorpublisher.h" |
|
19 |
|
20 #include "xntexteditoradapter.h" |
|
21 #include <liwservicehandler.h> |
|
22 #include <liwvariant.h> |
|
23 #include <liwgenericparam.h> |
|
24 #include <eikedwin.h> |
|
25 #include <eikedwin.h> |
|
26 #include <utf.h> |
|
27 |
|
28 |
|
29 //#include <StringLoader.h> // StringLoader |
|
30 |
|
31 _LIT8( KCPService, "Service.ContentPublishing" ); |
|
32 _LIT8( KCPInterface, "IDataSource" ); |
|
33 |
|
34 _LIT8( KType, "type" ); |
|
35 _LIT( KCpData, "cp_data" ); |
|
36 |
|
37 _LIT8( KPublisherId, "publisher" ); |
|
38 _LIT8( KContentTypeId, "content_type" ); |
|
39 _LIT8( KContentId, "content_id" ); |
|
40 |
|
41 _LIT(KAI3HSPublisher, "ai3homescreen"); |
|
42 _LIT(KContentType, "editorinput"); |
|
43 |
|
44 _LIT8( KData, "data"); |
|
45 |
|
46 _LIT8( KDataMap, "data_map" ); |
|
47 |
|
48 _LIT8( KItem, "item" ); |
|
49 _LIT8( KAdd, "Add" ); |
|
50 _LIT8( KDelete, "Delete" ); |
|
51 |
|
52 // ============================ LOCAL FUNCTIONS =============================== |
|
53 static void DoResetAndDestroy( TAny* aPtr ) |
|
54 { |
|
55 __ASSERT_DEBUG( aPtr, User::Invariant() ); |
|
56 reinterpret_cast< RCriteriaArray* >( aPtr )->ResetAndDestroy(); |
|
57 } |
|
58 |
|
59 // ============================ MEMBER FUNCTIONS =============================== |
|
60 |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // Two-phased constructor. Can leave. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CXnTextEditorPublisher* CXnTextEditorPublisher::NewL( CXnTextEditorAdapter& aAdapter, |
|
67 const TDesC8& aNodeId ) |
|
68 { |
|
69 CXnTextEditorPublisher* self = new (ELeave) CXnTextEditorPublisher( aAdapter ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL( aNodeId ); |
|
72 CleanupStack::Pop(); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // Destructor |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CXnTextEditorPublisher::~CXnTextEditorPublisher() |
|
81 { |
|
82 if( iNodeId ) |
|
83 { |
|
84 TRAP_IGNORE( RemoveDataFromCpsL( KAI3HSPublisher, KContentType, iNodeId->Des() ) ); |
|
85 } |
|
86 if( iCpsInterface ) |
|
87 { |
|
88 iCpsInterface->Close(); |
|
89 iCpsInterface = NULL; |
|
90 } |
|
91 if( iServiceHandler ) |
|
92 { |
|
93 iServiceHandler->Reset(); |
|
94 delete iServiceHandler; |
|
95 iServiceHandler = NULL; |
|
96 } |
|
97 CEikEdwin* editor = iAdapter.Editor(); |
|
98 if( editor ) |
|
99 { |
|
100 editor->RemoveEdwinObserver( this ); |
|
101 } |
|
102 delete iNodeId; |
|
103 delete iTextBuffer; |
|
104 } |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // C++ default constructor. Must not leave. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 CXnTextEditorPublisher::CXnTextEditorPublisher( CXnTextEditorAdapter& aAdapter ) : |
|
111 iAdapter( aAdapter ) |
|
112 { |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // 2nd phase constructor. Can leave. |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void CXnTextEditorPublisher::ConstructL( const TDesC8& aNodeId ) |
|
120 { |
|
121 iNodeId = CnvUtfConverter::ConvertToUnicodeFromUtf8L( aNodeId ); |
|
122 InitCpsInterfaceL(); |
|
123 CEikEdwin* editor = iAdapter.Editor(); |
|
124 if( editor ) |
|
125 { |
|
126 editor->SetEdwinObserver( this ); |
|
127 TInt len = editor->MaxLength(); |
|
128 iTextBuffer = HBufC::NewL( len ); |
|
129 } |
|
130 } |
|
131 |
|
132 // ----------------------------------------------------------------------------- |
|
133 // Uses the CPS interface to add given data |
|
134 // ----------------------------------------------------------------------------- |
|
135 // |
|
136 void CXnTextEditorPublisher::AddDataToCpsL( const TDesC& aPublisherId, |
|
137 const TDesC& aContentType, const TDesC& aContentId, |
|
138 const TDesC8& aDataKey, const TDesC& aData ) |
|
139 { |
|
140 if( iCpsInterface ) |
|
141 { |
|
142 CLiwGenericParamList& inparam = iServiceHandler->InParamListL(); |
|
143 CLiwGenericParamList& outparam = iServiceHandler->OutParamListL(); |
|
144 |
|
145 TLiwGenericParam cptype( KType, TLiwVariant( KCpData )); |
|
146 cptype.PushL(); |
|
147 |
|
148 inparam.AppendL( cptype ); |
|
149 |
|
150 CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
151 CLiwDefaultMap* map = CLiwDefaultMap::NewLC(); |
|
152 |
|
153 // Add data to data map |
|
154 map->InsertL( aDataKey, TLiwVariant( aData )); |
|
155 |
|
156 // Create content data map |
|
157 cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId )); |
|
158 cpdatamap->InsertL( KContentTypeId, TLiwVariant( aContentType )); |
|
159 cpdatamap->InsertL( KContentId, TLiwVariant( aContentId )); |
|
160 cpdatamap->InsertL( KDataMap, TLiwVariant(map) ); |
|
161 |
|
162 TLiwGenericParam item( KItem, TLiwVariant( cpdatamap )); |
|
163 item.PushL(); |
|
164 |
|
165 inparam.AppendL( item ); |
|
166 |
|
167 iCpsInterface->ExecuteCmdL( KAdd, inparam, outparam); |
|
168 |
|
169 CleanupStack::PopAndDestroy( 4, &cptype ); // &item, map, cpdatamap, |
|
170 |
|
171 outparam.Reset(); |
|
172 inparam.Reset(); |
|
173 } |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 // --------------------------------------------------------------------------- |
|
179 // |
|
180 void CXnTextEditorPublisher::RemoveDataFromCpsL( const TDesC& aPublisherId, |
|
181 const TDesC& aContentType, const TDesC& aContentId ) |
|
182 { |
|
183 if( iCpsInterface && iServiceHandler ) |
|
184 { |
|
185 CLiwGenericParamList& inparam = iServiceHandler->InParamListL(); |
|
186 CLiwGenericParamList& outparam = iServiceHandler->OutParamListL(); |
|
187 |
|
188 TLiwGenericParam cptype( KType, TLiwVariant( KCpData )); |
|
189 cptype.PushL(); |
|
190 inparam.AppendL( cptype ); |
|
191 |
|
192 CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
193 cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId )); |
|
194 cpdatamap->InsertL( KContentTypeId, TLiwVariant( aContentType )); |
|
195 cpdatamap->InsertL( KContentId, TLiwVariant( aContentId )); |
|
196 |
|
197 TLiwGenericParam item( KItem, TLiwVariant( cpdatamap )); |
|
198 item.PushL(); |
|
199 inparam.AppendL( item ); |
|
200 |
|
201 iCpsInterface->ExecuteCmdL( KDelete, inparam, outparam ); |
|
202 |
|
203 CleanupStack::PopAndDestroy( 3, &cptype ); // cpdatamap, &item |
|
204 outparam.Reset(); |
|
205 inparam.Reset(); |
|
206 } |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // Gets the CPS messaging interface |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 void CXnTextEditorPublisher::InitCpsInterfaceL() |
|
214 { |
|
215 if( !iServiceHandler ) |
|
216 { |
|
217 iServiceHandler = CLiwServiceHandler::NewL(); |
|
218 } |
|
219 |
|
220 CLiwGenericParamList& inParam = iServiceHandler->InParamListL(); |
|
221 CLiwGenericParamList& outParam = iServiceHandler->OutParamListL(); |
|
222 |
|
223 RCriteriaArray a; |
|
224 TCleanupItem item( DoResetAndDestroy, &a ); |
|
225 CleanupStack::PushL( item ); |
|
226 |
|
227 CLiwCriteriaItem* crit = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, KCPInterface, |
|
228 KCPService ); |
|
229 crit->SetServiceClass( TUid::Uid(KLiwClassBase) ); |
|
230 |
|
231 a.AppendL(crit); |
|
232 |
|
233 CleanupStack::Pop( crit ); |
|
234 |
|
235 iServiceHandler->AttachL(a); |
|
236 iServiceHandler->ExecuteServiceCmdL( *crit, inParam, outParam ); |
|
237 |
|
238 CleanupStack::PopAndDestroy(); // item; |
|
239 |
|
240 // find service interface |
|
241 TInt pos = 0; |
|
242 MLiwInterface* msgInterface = NULL; |
|
243 outParam.FindFirst( pos, KCPInterface ); |
|
244 if ( pos != KErrNotFound ) |
|
245 { |
|
246 msgInterface = (outParam)[pos].Value().AsInterface(); |
|
247 } |
|
248 outParam.Reset(); |
|
249 inParam.Reset(); |
|
250 iCpsInterface = msgInterface; |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CXnTextEditorPublisher::HandleEdwinEventL |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CXnTextEditorPublisher::HandleEdwinEventL(CEikEdwin* aEdwin, TEdwinEvent aEventType) |
|
258 { |
|
259 if( aEventType == MEikEdwinObserver::EEventTextUpdate) |
|
260 { |
|
261 TPtr bufferDes = iTextBuffer->Des(); |
|
262 bufferDes.Zero(); |
|
263 aEdwin->GetText( bufferDes ); |
|
264 PublishTextL( bufferDes ); |
|
265 } |
|
266 } |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CXnTextEditorPublisher::PublishTextL |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 void CXnTextEditorPublisher::PublishTextL( const TDesC& aText ) |
|
273 { |
|
274 AddDataToCpsL( KAI3HSPublisher, KContentType, iNodeId->Des(), KData, aText ); |
|
275 } |
|
276 |
|
277 // END OF FILE |
|
278 |