|
1 /* |
|
2 * Copyright (c) 2004-2005 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: TPhoneServer interface for image handling. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 |
|
21 #include "RPhCltImageHandler.h" |
|
22 #include "PhCltClientServer.h" |
|
23 #include <RPhCltServer.h> |
|
24 #include <e32std.h> |
|
25 #include <e32base.h> |
|
26 #include <fbs.h> |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // RPhCltImageHandler::RPhCltImageHandler |
|
32 // |
|
33 // C++ constructor can NOT contain any code, that might leave. |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 RPhCltImageHandler::RPhCltImageHandler() |
|
37 : RSubSessionBase() |
|
38 { |
|
39 } |
|
40 |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // RPhCltImageHandler::Open |
|
44 // |
|
45 // Open subsession to Phone Server. |
|
46 // ----------------------------------------------------------------------------- |
|
47 // |
|
48 TInt RPhCltImageHandler::Open( RPhCltServer& aServer ) |
|
49 { |
|
50 __ASSERT_ALWAYS( aServer.Handle(), User::Panic( |
|
51 KPhClientPanicCategory, |
|
52 EPhCltClientSidePanicNullHandle ) ); |
|
53 |
|
54 return CreateSubSession( |
|
55 aServer, |
|
56 EPhoneServerImageHandlerSubSessionOpen, |
|
57 TIpcArgs() ); |
|
58 } |
|
59 |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // RPhCltImageHandler::Close |
|
63 // |
|
64 // Close subsession. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 void RPhCltImageHandler::Close() |
|
68 { |
|
69 iVTBitMaps.ResetAndDestroy(); |
|
70 iOperatorLogos.ResetAndDestroy(); |
|
71 CloseSubSession( EPhoneServerImageHandlerSubSessionClose ); |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // RPhCltImageHandler::SaveImages |
|
76 // |
|
77 // Saves images to Phoneserver. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 TInt RPhCltImageHandler::SaveImages( CPhCltImageParams& aParams ) |
|
81 { |
|
82 __ASSERT_ALWAYS( |
|
83 SubSessionHandle(), User::Panic( |
|
84 KPhClientPanicCategory, EPhCltClientSidePanicNullHandle ) ); |
|
85 |
|
86 return SendReceive( |
|
87 EPhoneServerImageHandlerSubSessionSave, |
|
88 TIpcArgs( |
|
89 &aParams.Images()) ); |
|
90 } |
|
91 |
|
92 // ----------------------------------------------------------------------------- |
|
93 // RPhCltImageHandler::LoadImages |
|
94 // |
|
95 // Loads images from Phoneserver. |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 TInt RPhCltImageHandler::LoadImages( CPhCltImageParams*& aParams ) |
|
99 { |
|
100 __ASSERT_ALWAYS( |
|
101 SubSessionHandle(), User::Panic( |
|
102 KPhClientPanicCategory, EPhCltClientSidePanicNullHandle ) ); |
|
103 |
|
104 const TInt ret = SendReceive( EPhoneServerImageHandlerSubSessionLoad, |
|
105 TIpcArgs( &aParams->Images() ) ); |
|
106 |
|
107 // No point in commiting if failed. |
|
108 if ( ret != KErrNone ) |
|
109 { |
|
110 return ret; |
|
111 } |
|
112 return FinalizeLoad( aParams->Images() ); |
|
113 } |
|
114 |
|
115 // ----------------------------------------------------------------------------- |
|
116 // RPhCltImageHandler::FinalizeLoad |
|
117 // |
|
118 // Duplicates loaded images, and commits transaction. |
|
119 // ----------------------------------------------------------------------------- |
|
120 // |
|
121 TInt RPhCltImageHandler::FinalizeLoad( TPckgBuf< TPhCltImageArray >& aImages ) |
|
122 { |
|
123 TRAPD( err, |
|
124 { |
|
125 switch( aImages.operator()().iType ) |
|
126 { |
|
127 case EPhCltTypeVTStill: |
|
128 case EPhCltTypeVTDefault: |
|
129 CopyStillsL( aImages.operator()() ); |
|
130 break; |
|
131 case EPhCltTypeOperatorLogo: |
|
132 CopyLogosL( aImages.operator()() ); |
|
133 break; |
|
134 default: |
|
135 break; |
|
136 } |
|
137 } ); |
|
138 |
|
139 // Must release in any case |
|
140 const TInt ret = SendReceive( EPhoneServerImageHandlerSubSessionCommitLoad, |
|
141 TIpcArgs( &aImages ) ); |
|
142 |
|
143 return err != KErrNone ? err : ret; |
|
144 |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // RPhCltImageHandler::CopyLogos |
|
149 // |
|
150 // Replaces / appends a new logo. |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 void RPhCltImageHandler::CopyLogosL( TPhCltImageArray& aImages ) |
|
154 { |
|
155 TBool found( EFalse ); |
|
156 CFbsBitmap* bitMap = |
|
157 CreateBitMapL( aImages.iImages[ EPhCltExtOperatorLogoIndex ] ); |
|
158 |
|
159 // Check if there is one stored already, replace handle if so. |
|
160 for ( TInt i = 0; i < iOperatorLogos.Count(); i ++ ) |
|
161 { |
|
162 if ( aImages.iImages[ EPhCltExtCountryCodeIndex ] == |
|
163 iOperatorLogos[ i ]->iCountryCode && |
|
164 aImages.iImages[ EPhCltExtNetworkCodeIndex ] == |
|
165 iOperatorLogos[ i ]->iNetworkCode && |
|
166 aImages.iImages[ EPhCltExtLogoTypeIndex ] == |
|
167 iOperatorLogos[ i ]->iLogoType |
|
168 ) |
|
169 { |
|
170 delete iOperatorLogos[ i ]->iBitmap; |
|
171 iOperatorLogos[ i ]->iBitmap = bitMap; |
|
172 found = ETrue; |
|
173 break; |
|
174 } |
|
175 } |
|
176 |
|
177 // Else add a new one. |
|
178 if ( !found ) |
|
179 { |
|
180 CPhCltOperatorLogoContainer* logo = |
|
181 new (ELeave)CPhCltOperatorLogoContainer( |
|
182 aImages.iImages[ EPhCltExtCountryCodeIndex ], |
|
183 aImages.iImages[ EPhCltExtNetworkCodeIndex ], |
|
184 ( TPhCltExtOperatorLogoType ) |
|
185 aImages.iImages[ EPhCltExtLogoTypeIndex ], |
|
186 bitMap ); |
|
187 iOperatorLogos.Append( logo ); |
|
188 } |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // RPhCltImageHandler::CopyStillsL |
|
193 // |
|
194 // Creates new duplicates of still images. |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void RPhCltImageHandler::CopyStillsL( TPhCltImageArray& aImages ) |
|
198 { |
|
199 // Remove all first. |
|
200 iVTBitMaps.ResetAndDestroy(); |
|
201 |
|
202 for ( TInt i = 0 ; i < aImages.iImageCount; i ++ ) |
|
203 { |
|
204 CFbsBitmap* bitMap = |
|
205 CreateBitMapL( aImages.iImages[ i ] ); |
|
206 iVTBitMaps.Append( bitMap ); |
|
207 } |
|
208 } |
|
209 |
|
210 // ----------------------------------------------------------------------------- |
|
211 // RPhCltImageHandler::CreateBitMapL |
|
212 // |
|
213 // Creates new duplicate of still image. |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 CFbsBitmap* RPhCltImageHandler::CreateBitMapL( const TInt aHandle ) |
|
217 { |
|
218 CFbsBitmap* bitMap = new ( ELeave ) CFbsBitmap(); |
|
219 CleanupStack::PushL( bitMap ); |
|
220 User::LeaveIfError( bitMap->Duplicate( aHandle ) ); |
|
221 CleanupStack::Pop( bitMap ); |
|
222 return bitMap; |
|
223 } |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // RPhCltImageHandler::SaveVtImage |
|
227 // |
|
228 // Saves VT Image. |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 void RPhCltImageHandler::SaveVtImage( |
|
232 TRequestStatus& aStatus, |
|
233 const TDesC& aFilePath ) |
|
234 { |
|
235 __ASSERT_ALWAYS( |
|
236 SubSessionHandle(), User::Panic( |
|
237 KPhClientPanicCategory, EPhCltClientSidePanicNullHandle ) ); |
|
238 const TPtrC8 ptr8( reinterpret_cast<const TUint8*> ( aFilePath.Ptr() ), |
|
239 aFilePath.Size() ); |
|
240 TIpcArgs args( &ptr8 ); |
|
241 SendReceive( |
|
242 EPhoneServerSaveVtImage, |
|
243 args, |
|
244 aStatus ); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // RPhCltImageHandler::CancelSaveVtImage |
|
249 // |
|
250 // |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 void RPhCltImageHandler::CancelSaveVtImage() |
|
254 { |
|
255 SendReceive( EPhoneServerSaveVtImageCancel ); |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // RPhCltImageHandler::OpenVtImage |
|
260 // |
|
261 // Opens VT Image file. |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 TInt RPhCltImageHandler::OpenVtImage( |
|
265 TInt& aFileHandle, |
|
266 const TBool aOpenDefault ) |
|
267 { |
|
268 __ASSERT_ALWAYS( |
|
269 SubSessionHandle(), User::Panic( |
|
270 KPhClientPanicCategory, EPhCltClientSidePanicNullHandle ) ); |
|
271 TPckg<TInt> pckg1( aFileHandle ); |
|
272 TPckg<TBool> pckg2( aOpenDefault ); |
|
273 TIpcArgs args( &pckg1, &pckg2 ); |
|
274 return SendReceive( |
|
275 EPhoneServerOpenVtImage, args ); |
|
276 } |
|
277 |
|
278 // End of File |