author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 14 Sep 2010 20:58:58 +0300 | |
branch | RCL_3 |
changeset 35 | 3321d3e205b6 |
parent 34 | 5456b4e8b3a8 |
permissions | -rw-r--r-- |
34 | 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 |
} |
|
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
97 |
|
34 | 98 |
delete iNodeId; |
99 |
delete iTextBuffer; |
|
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
100 |
delete iTempBuffer; |
34 | 101 |
} |
102 |
||
103 |
// ----------------------------------------------------------------------------- |
|
104 |
// C++ default constructor. Must not leave. |
|
105 |
// ----------------------------------------------------------------------------- |
|
106 |
// |
|
107 |
CXnTextEditorPublisher::CXnTextEditorPublisher( CXnTextEditorAdapter& aAdapter ) : |
|
108 |
iAdapter( aAdapter ) |
|
109 |
{ |
|
110 |
} |
|
111 |
||
112 |
// ----------------------------------------------------------------------------- |
|
113 |
// 2nd phase constructor. Can leave. |
|
114 |
// ----------------------------------------------------------------------------- |
|
115 |
// |
|
116 |
void CXnTextEditorPublisher::ConstructL( const TDesC8& aNodeId ) |
|
117 |
{ |
|
118 |
iNodeId = CnvUtfConverter::ConvertToUnicodeFromUtf8L( aNodeId ); |
|
119 |
InitCpsInterfaceL(); |
|
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
120 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
121 |
CEikEdwin* editor( iAdapter.Editor() ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
122 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
123 |
// Editor must be activated before setting observer |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
124 |
if( editor && editor->TextView() ) |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
125 |
{ |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
126 |
TInt len( editor->MaxLength() ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
127 |
|
34 | 128 |
iTextBuffer = HBufC::NewL( len ); |
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
129 |
iTempBuffer = HBufC::NewL( len ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
130 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
131 |
editor->TextView()->SetObserver( this ); |
34 | 132 |
} |
133 |
} |
|
134 |
||
135 |
// ----------------------------------------------------------------------------- |
|
136 |
// Uses the CPS interface to add given data |
|
137 |
// ----------------------------------------------------------------------------- |
|
138 |
// |
|
139 |
void CXnTextEditorPublisher::AddDataToCpsL( const TDesC& aPublisherId, |
|
140 |
const TDesC& aContentType, const TDesC& aContentId, |
|
141 |
const TDesC8& aDataKey, const TDesC& aData ) |
|
142 |
{ |
|
143 |
if( iCpsInterface ) |
|
144 |
{ |
|
145 |
CLiwGenericParamList& inparam = iServiceHandler->InParamListL(); |
|
146 |
CLiwGenericParamList& outparam = iServiceHandler->OutParamListL(); |
|
147 |
||
148 |
TLiwGenericParam cptype( KType, TLiwVariant( KCpData )); |
|
149 |
cptype.PushL(); |
|
150 |
||
151 |
inparam.AppendL( cptype ); |
|
152 |
||
153 |
CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
154 |
CLiwDefaultMap* map = CLiwDefaultMap::NewLC(); |
|
155 |
||
156 |
// Add data to data map |
|
157 |
map->InsertL( aDataKey, TLiwVariant( aData )); |
|
158 |
||
159 |
// Create content data map |
|
160 |
cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId )); |
|
161 |
cpdatamap->InsertL( KContentTypeId, TLiwVariant( aContentType )); |
|
162 |
cpdatamap->InsertL( KContentId, TLiwVariant( aContentId )); |
|
163 |
cpdatamap->InsertL( KDataMap, TLiwVariant(map) ); |
|
164 |
||
165 |
TLiwGenericParam item( KItem, TLiwVariant( cpdatamap )); |
|
166 |
item.PushL(); |
|
167 |
||
168 |
inparam.AppendL( item ); |
|
169 |
||
170 |
iCpsInterface->ExecuteCmdL( KAdd, inparam, outparam); |
|
171 |
||
172 |
CleanupStack::PopAndDestroy( 4, &cptype ); // &item, map, cpdatamap, |
|
173 |
||
174 |
outparam.Reset(); |
|
175 |
inparam.Reset(); |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
// --------------------------------------------------------------------------- |
|
180 |
// |
|
181 |
// --------------------------------------------------------------------------- |
|
182 |
// |
|
183 |
void CXnTextEditorPublisher::RemoveDataFromCpsL( const TDesC& aPublisherId, |
|
184 |
const TDesC& aContentType, const TDesC& aContentId ) |
|
185 |
{ |
|
186 |
if( iCpsInterface && iServiceHandler ) |
|
187 |
{ |
|
188 |
CLiwGenericParamList& inparam = iServiceHandler->InParamListL(); |
|
189 |
CLiwGenericParamList& outparam = iServiceHandler->OutParamListL(); |
|
190 |
||
191 |
TLiwGenericParam cptype( KType, TLiwVariant( KCpData )); |
|
192 |
cptype.PushL(); |
|
193 |
inparam.AppendL( cptype ); |
|
194 |
||
195 |
CLiwDefaultMap* cpdatamap = CLiwDefaultMap::NewLC(); |
|
196 |
cpdatamap->InsertL( KPublisherId, TLiwVariant( aPublisherId )); |
|
197 |
cpdatamap->InsertL( KContentTypeId, TLiwVariant( aContentType )); |
|
198 |
cpdatamap->InsertL( KContentId, TLiwVariant( aContentId )); |
|
199 |
||
200 |
TLiwGenericParam item( KItem, TLiwVariant( cpdatamap )); |
|
201 |
item.PushL(); |
|
202 |
inparam.AppendL( item ); |
|
203 |
||
204 |
iCpsInterface->ExecuteCmdL( KDelete, inparam, outparam ); |
|
205 |
||
206 |
CleanupStack::PopAndDestroy( 3, &cptype ); // cpdatamap, &item |
|
207 |
outparam.Reset(); |
|
208 |
inparam.Reset(); |
|
209 |
} |
|
210 |
} |
|
211 |
||
212 |
// ----------------------------------------------------------------------------- |
|
213 |
// Gets the CPS messaging interface |
|
214 |
// ----------------------------------------------------------------------------- |
|
215 |
// |
|
216 |
void CXnTextEditorPublisher::InitCpsInterfaceL() |
|
217 |
{ |
|
218 |
if( !iServiceHandler ) |
|
219 |
{ |
|
220 |
iServiceHandler = CLiwServiceHandler::NewL(); |
|
221 |
} |
|
222 |
||
223 |
CLiwGenericParamList& inParam = iServiceHandler->InParamListL(); |
|
224 |
CLiwGenericParamList& outParam = iServiceHandler->OutParamListL(); |
|
225 |
||
226 |
RCriteriaArray a; |
|
227 |
TCleanupItem item( DoResetAndDestroy, &a ); |
|
228 |
CleanupStack::PushL( item ); |
|
229 |
||
230 |
CLiwCriteriaItem* crit = CLiwCriteriaItem::NewLC( KLiwCmdAsStr, KCPInterface, |
|
231 |
KCPService ); |
|
232 |
crit->SetServiceClass( TUid::Uid(KLiwClassBase) ); |
|
233 |
||
234 |
a.AppendL(crit); |
|
235 |
||
236 |
CleanupStack::Pop( crit ); |
|
237 |
||
238 |
iServiceHandler->AttachL(a); |
|
239 |
iServiceHandler->ExecuteServiceCmdL( *crit, inParam, outParam ); |
|
240 |
||
241 |
CleanupStack::PopAndDestroy(); // item; |
|
242 |
||
243 |
// find service interface |
|
244 |
TInt pos = 0; |
|
245 |
MLiwInterface* msgInterface = NULL; |
|
246 |
outParam.FindFirst( pos, KCPInterface ); |
|
247 |
if ( pos != KErrNotFound ) |
|
248 |
{ |
|
249 |
msgInterface = (outParam)[pos].Value().AsInterface(); |
|
250 |
} |
|
251 |
outParam.Reset(); |
|
252 |
inParam.Reset(); |
|
253 |
iCpsInterface = msgInterface; |
|
254 |
} |
|
255 |
||
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
256 |
|
34 | 257 |
// ----------------------------------------------------------------------------- |
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
258 |
// CXnTextEditorPublisher::OnReformatL |
34 | 259 |
// ----------------------------------------------------------------------------- |
260 |
// |
|
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
261 |
void CXnTextEditorPublisher::OnReformatL( const CTextView* aTextView ) |
34 | 262 |
{ |
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
263 |
CEikEdwin* editor( iAdapter.Editor() ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
264 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
265 |
if ( editor ) |
34 | 266 |
{ |
35
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
267 |
editor->OnReformatL( aTextView ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
268 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
269 |
TPtr ptr( iTempBuffer->Des() ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
270 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
271 |
ptr.Zero(); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
272 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
273 |
editor->GetText( ptr ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
274 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
275 |
if ( *iTextBuffer != *iTempBuffer ) |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
276 |
{ |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
277 |
*iTextBuffer = *iTempBuffer; |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
278 |
|
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
279 |
if ( !iAdapter.IsSetText() ) |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
280 |
{ |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
281 |
PublishTextL( *iTextBuffer ); |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
282 |
} |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
283 |
} |
3321d3e205b6
Revision: 201033
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
34
diff
changeset
|
284 |
} |
34 | 285 |
} |
286 |
||
287 |
// ----------------------------------------------------------------------------- |
|
288 |
// CXnTextEditorPublisher::PublishTextL |
|
289 |
// ----------------------------------------------------------------------------- |
|
290 |
// |
|
291 |
void CXnTextEditorPublisher::PublishTextL( const TDesC& aText ) |
|
292 |
{ |
|
293 |
AddDataToCpsL( KAI3HSPublisher, KContentType, iNodeId->Des(), KData, aText ); |
|
294 |
} |
|
295 |
||
296 |
// END OF FILE |
|
297 |