63
|
1 |
/*
|
|
2 |
* Copyright (c) 2002-2007 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:
|
|
15 |
* Set image command event handling class.
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
|
|
20 |
// INCLUDE FILES
|
|
21 |
#include "CPbk2SetImageCmd.h"
|
|
22 |
|
|
23 |
// Phonebook 2
|
|
24 |
#include "CPbk2ImageManager.h"
|
|
25 |
#include "CPbk2DrmManager.h"
|
|
26 |
#include "Pbk2DataCaging.hrh"
|
|
27 |
#include "Pbk2PresentationUtils.h"
|
|
28 |
#include <Pbk2Commands.rsg>
|
|
29 |
#include <Pbk2CommonUi.rsg>
|
|
30 |
#include <MPbk2CommandObserver.h>
|
|
31 |
#include <RPbk2LocalizedResourceFile.h>
|
|
32 |
#include <CPbk2DriveSpaceCheck.h>
|
|
33 |
#include <CPbk2AppUiBase.h>
|
|
34 |
#include <Pbk2CmdExtRes.rsg>
|
|
35 |
|
|
36 |
// Virtual Phonebook
|
|
37 |
#include <MVPbkStoreContact.h>
|
|
38 |
#include <MVPbkFieldType.h>
|
|
39 |
#include <MVPbkContactFieldTextData.h>
|
|
40 |
|
|
41 |
// System includes
|
|
42 |
#include <AknWaitDialog.h>
|
|
43 |
#include <aknnotewrappers.h>
|
|
44 |
#include <StringLoader.h>
|
|
45 |
#include <MGFetch.h>
|
|
46 |
#include <aknnavi.h>
|
|
47 |
#include <aknnavide.h>
|
|
48 |
|
|
49 |
// Debugging headers
|
|
50 |
#include <Pbk2Debug.h>
|
|
51 |
|
|
52 |
/// Unnamed namespace for local definitons
|
|
53 |
namespace {
|
|
54 |
|
|
55 |
#ifdef _DEBUG
|
|
56 |
|
|
57 |
enum TPanicCode
|
|
58 |
{
|
|
59 |
EPanicPreCond_Pbk2ImageSetComplete,
|
|
60 |
EPanicPreCond_Pbk2ImageSetFailed,
|
|
61 |
EPanicPreCond_SetImageRefL
|
|
62 |
};
|
|
63 |
|
|
64 |
void Panic(TInt aReason)
|
|
65 |
{
|
|
66 |
_LIT(KPanicText, "CPbk2SetImageCmd");
|
|
67 |
User::Panic(KPanicText, aReason);
|
|
68 |
}
|
|
69 |
#endif // _DEBUG
|
|
70 |
|
|
71 |
} /// namespace
|
|
72 |
|
|
73 |
|
|
74 |
// ================= MEMBER FUNCTIONS =======================
|
|
75 |
|
|
76 |
// --------------------------------------------------------------------------
|
|
77 |
// CPbk2SetImageCmd::CPbk2SetImageCmd
|
|
78 |
// --------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
CPbk2SetImageCmd::CPbk2SetImageCmd(
|
|
81 |
MPbk2ContactUiControl& aUiControl ) :
|
|
82 |
CPbk2ImageCmdBase( aUiControl )
|
|
83 |
{
|
|
84 |
}
|
|
85 |
|
|
86 |
// --------------------------------------------------------------------------
|
|
87 |
// CPbk2SetImageCmd::ConstructL
|
|
88 |
// --------------------------------------------------------------------------
|
|
89 |
//
|
|
90 |
void CPbk2SetImageCmd::ConstructL()
|
|
91 |
{
|
|
92 |
CPbk2ImageCmdBase::BaseConstructL();
|
|
93 |
CPbk2DriveSpaceCheck* driveSpaceCheck = CPbk2DriveSpaceCheck::NewL
|
|
94 |
( CCoeEnv::Static()->FsSession() );
|
|
95 |
CleanupStack::PushL( driveSpaceCheck );
|
|
96 |
// check FFS situation
|
|
97 |
driveSpaceCheck->DriveSpaceCheckL();
|
|
98 |
CleanupStack::PopAndDestroy( driveSpaceCheck );
|
|
99 |
iDrmManager = CPbk2DrmManager::NewL();
|
|
100 |
}
|
|
101 |
|
|
102 |
// --------------------------------------------------------------------------
|
|
103 |
// CPbk2SetImageCmd::NewL
|
|
104 |
// --------------------------------------------------------------------------
|
|
105 |
//
|
|
106 |
CPbk2SetImageCmd* CPbk2SetImageCmd::NewL(
|
|
107 |
MPbk2ContactUiControl& aUiControl )
|
|
108 |
{
|
|
109 |
CPbk2SetImageCmd* self =
|
|
110 |
new (ELeave) CPbk2SetImageCmd( aUiControl );
|
|
111 |
CleanupStack::PushL( self );
|
|
112 |
self->ConstructL();
|
|
113 |
CleanupStack::Pop( self );
|
|
114 |
return self;
|
|
115 |
}
|
|
116 |
|
|
117 |
// --------------------------------------------------------------------------
|
|
118 |
// CPbk2SetImageCmd::~CPbk2SetImageCmd
|
|
119 |
// --------------------------------------------------------------------------
|
|
120 |
//
|
|
121 |
CPbk2SetImageCmd::~CPbk2SetImageCmd()
|
|
122 |
{
|
|
123 |
delete iDrmManager;
|
|
124 |
delete iImageOperation;
|
|
125 |
delete iWaitNote;
|
|
126 |
}
|
|
127 |
|
|
128 |
// --------------------------------------------------------------------------
|
|
129 |
// CPbk2SetImageCmd::ExecuteCommandL
|
|
130 |
// --------------------------------------------------------------------------
|
|
131 |
//
|
|
132 |
TBool CPbk2SetImageCmd::ExecuteCommandL()
|
|
133 |
{
|
|
134 |
TBool result = EFalse;
|
|
135 |
iImageSetFailed = EFalse;
|
|
136 |
Cancel();
|
|
137 |
|
|
138 |
// fetch image from media gallery
|
|
139 |
CDesCArray* selectedFile = new(ELeave) CDesCArrayFlat( 1 );
|
|
140 |
CleanupStack::PushL( selectedFile );
|
|
141 |
TBool res( EFalse );
|
|
142 |
|
|
143 |
res = MGFetchL( *selectedFile, EImageFile, EFalse, this );
|
|
144 |
|
|
145 |
if ( !iVerificationFailed && res && selectedFile->Count() > 0 )
|
|
146 |
{
|
|
147 |
iWaitNote = new(ELeave) CAknWaitDialog(
|
|
148 |
reinterpret_cast<CEikDialog**>( &iWaitNote ), ETrue );
|
|
149 |
|
|
150 |
iWaitNote->SetCallback( this );
|
|
151 |
iWaitNote->ExecuteLD( R_QTN_GEN_NOTE_FETCHING );
|
|
152 |
|
|
153 |
TPtrC fileName = (*selectedFile)[0];
|
|
154 |
|
|
155 |
// store reference to image field
|
|
156 |
SetImageRefL( fileName );
|
|
157 |
|
|
158 |
// write data to thumbnail field
|
|
159 |
iImageOperation =
|
|
160 |
iImageManager->SetImageAsyncL(
|
|
161 |
*iStoreContact, *iThumbnailFieldType, *this, fileName );
|
|
162 |
|
|
163 |
result = ETrue;
|
|
164 |
}
|
|
165 |
|
|
166 |
CleanupStack::PopAndDestroy( selectedFile );
|
|
167 |
return result;
|
|
168 |
}
|
|
169 |
|
|
170 |
// --------------------------------------------------------------------------
|
|
171 |
// CPbk2SetImageCmd::Pbk2ImageSetComplete
|
|
172 |
// --------------------------------------------------------------------------
|
|
173 |
//
|
|
174 |
void CPbk2SetImageCmd::Pbk2ImageSetComplete
|
|
175 |
( MPbk2ImageOperation& PBK2_DEBUG_ONLY( aOperation ) )
|
|
176 |
{
|
|
177 |
__ASSERT_DEBUG(&aOperation == iImageOperation,
|
|
178 |
Panic(EPanicPreCond_Pbk2ImageSetComplete));
|
|
179 |
|
|
180 |
delete iImageOperation;
|
|
181 |
iImageOperation = NULL;
|
|
182 |
|
|
183 |
DismissWaitNote();
|
|
184 |
|
|
185 |
TRAPD( error, iStoreContact->CommitL( *this ) );
|
|
186 |
if ( error != KErrNone )
|
|
187 |
{
|
|
188 |
CCoeEnv::Static()->HandleError( error );
|
|
189 |
}
|
|
190 |
}
|
|
191 |
|
|
192 |
// --------------------------------------------------------------------------
|
|
193 |
// CPbk2SetImageCmd::Pbk2ImageSetFailed
|
|
194 |
// --------------------------------------------------------------------------
|
|
195 |
//
|
|
196 |
void CPbk2SetImageCmd::Pbk2ImageSetFailed
|
|
197 |
( MPbk2ImageOperation& PBK2_DEBUG_ONLY( aOperation ), TInt aError )
|
|
198 |
{
|
|
199 |
__ASSERT_DEBUG( &aOperation == iImageOperation,
|
|
200 |
Panic( EPanicPreCond_Pbk2ImageSetFailed ) );
|
|
201 |
|
|
202 |
delete iImageOperation;
|
|
203 |
iImageOperation = NULL;
|
|
204 |
|
|
205 |
iImageSetFailed = ETrue;
|
|
206 |
iImageSetError = aError;
|
|
207 |
DismissWaitNote();
|
|
208 |
}
|
|
209 |
|
|
210 |
// --------------------------------------------------------------------------
|
|
211 |
// CPbk2SetImageCmd::DismissWaitNote
|
|
212 |
// --------------------------------------------------------------------------
|
|
213 |
//
|
|
214 |
void CPbk2SetImageCmd::DismissWaitNote()
|
|
215 |
{
|
|
216 |
// Dismiss the wait note
|
|
217 |
if ( iWaitNote )
|
|
218 |
{
|
|
219 |
TRAPD( err, iWaitNote->ProcessFinishedL() );
|
|
220 |
if ( err != KErrNone )
|
|
221 |
{
|
|
222 |
delete iWaitNote;
|
|
223 |
iWaitNote = NULL;
|
|
224 |
|
|
225 |
if( iImageSetFailed )
|
|
226 |
{
|
|
227 |
ShowErrorNoteL();
|
|
228 |
}
|
|
229 |
}
|
|
230 |
}
|
|
231 |
}
|
|
232 |
|
|
233 |
// --------------------------------------------------------------------------
|
|
234 |
// CPbk2SetImageCmd::DialogDismissedL
|
|
235 |
// --------------------------------------------------------------------------
|
|
236 |
//
|
|
237 |
void CPbk2SetImageCmd::DialogDismissedL( TInt /*aButtonId*/ )
|
|
238 |
{
|
|
239 |
if( iImageSetFailed )
|
|
240 |
{
|
|
241 |
ShowErrorNoteL();
|
|
242 |
}
|
|
243 |
}
|
|
244 |
|
|
245 |
// --------------------------------------------------------------------------
|
|
246 |
// CPbk2SetImageCmd::VerifySelectionL
|
|
247 |
// --------------------------------------------------------------------------
|
|
248 |
//
|
|
249 |
TBool CPbk2SetImageCmd::VerifySelectionL
|
|
250 |
(const MDesCArray* aSelectedFiles)
|
|
251 |
{
|
|
252 |
iVerificationFailed = EFalse;
|
|
253 |
TBool ret = ETrue;
|
|
254 |
|
|
255 |
TRAPD( err, ret = DoVerifySelectionL( aSelectedFiles ) );
|
|
256 |
|
|
257 |
if( err != KErrNone )
|
|
258 |
{
|
|
259 |
iVerificationFailed = ETrue;
|
|
260 |
ShowErrorNoteL();
|
|
261 |
}
|
|
262 |
|
|
263 |
// Selection is always accepted if the image is not drm protected.
|
|
264 |
// Image fetch dialog functionality is always same in spite of error
|
|
265 |
// type (DRM check, ImageDecoder, etc. errors) Dialog is always closed.
|
|
266 |
return ret;
|
|
267 |
}
|
|
268 |
|
|
269 |
// --------------------------------------------------------------------------
|
|
270 |
// CPbk2SetImageCmd::DoVerifySelectionL
|
|
271 |
// --------------------------------------------------------------------------
|
|
272 |
//
|
|
273 |
TBool CPbk2SetImageCmd::DoVerifySelectionL
|
|
274 |
(const MDesCArray* aSelectedFiles)
|
|
275 |
{
|
|
276 |
TBool ret = ETrue;
|
|
277 |
|
|
278 |
if ( aSelectedFiles && aSelectedFiles->MdcaCount() > 0 )
|
|
279 |
{
|
|
280 |
// DRM for phonebook image fetch
|
|
281 |
TPtrC fileName = aSelectedFiles->MdcaPoint( 0 );
|
|
282 |
TBool isProtected( ETrue );
|
|
283 |
User::LeaveIfError(
|
|
284 |
iDrmManager->IsProtectedFile( fileName, isProtected ) );
|
|
285 |
|
|
286 |
if ( isProtected )
|
|
287 |
{
|
|
288 |
ret = EFalse;
|
|
289 |
RPbk2LocalizedResourceFile resFile( *CCoeEnv::Static() );
|
|
290 |
resFile.OpenLC(
|
|
291 |
KPbk2RomFileDrive,
|
|
292 |
KDC_RESOURCE_FILES_DIR,
|
|
293 |
Pbk2PresentationUtils::PresentationResourceFile() );
|
|
294 |
// show user copyright note
|
|
295 |
HBufC* prompt =
|
|
296 |
CCoeEnv::Static()->AllocReadResourceLC( R_PBK2_QTN_DRM_NOT_ALLOWED );
|
|
297 |
CAknInformationNote* dlg = new(ELeave) CAknInformationNote( ETrue );
|
|
298 |
dlg->ExecuteLD( *prompt );
|
|
299 |
CleanupStack::PopAndDestroy( 2 ); // resFile, prompt
|
|
300 |
}
|
|
301 |
}
|
|
302 |
|
|
303 |
return ret;
|
|
304 |
}
|
|
305 |
|
|
306 |
// --------------------------------------------------------------------------
|
|
307 |
// CPbk2SetImageCmd::ShowErrorNoteL
|
|
308 |
// --------------------------------------------------------------------------
|
|
309 |
//
|
|
310 |
void CPbk2SetImageCmd::ShowErrorNoteL()
|
|
311 |
{
|
|
312 |
HBufC* prompt = StringLoader::LoadLC( R_QTN_ALBUM_ERR_FORMAT_UNKNOWN );
|
|
313 |
CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue );
|
|
314 |
dlg->ExecuteLD( *prompt );
|
|
315 |
CleanupStack::PopAndDestroy( prompt );
|
|
316 |
|
|
317 |
if( iImageSetFailed )
|
|
318 |
{
|
|
319 |
ProcessDismissed( iImageSetError );
|
|
320 |
iImageSetFailed = EFalse;
|
|
321 |
iImageSetError = KErrNone;
|
|
322 |
}
|
|
323 |
}
|
|
324 |
|
|
325 |
// --------------------------------------------------------------------------
|
|
326 |
// CPbk2SetImageCmd::Cancel
|
|
327 |
// --------------------------------------------------------------------------
|
|
328 |
//
|
|
329 |
void CPbk2SetImageCmd::Cancel()
|
|
330 |
{
|
|
331 |
delete iWaitNote;
|
|
332 |
iWaitNote = NULL;
|
|
333 |
delete iImageOperation;
|
|
334 |
iImageOperation = NULL;
|
|
335 |
}
|
|
336 |
|
|
337 |
// --------------------------------------------------------------------------
|
|
338 |
// CPbk2SetImageCmd::SetImageRefL
|
|
339 |
// --------------------------------------------------------------------------
|
|
340 |
//
|
|
341 |
void CPbk2SetImageCmd::SetImageRefL(const TDesC& aFileName)
|
|
342 |
{
|
|
343 |
__ASSERT_DEBUG(iImageFieldType && iStoreContact, Panic(EPanicPreCond_SetImageRefL));
|
|
344 |
|
|
345 |
MVPbkStoreContactField* field = NULL;
|
|
346 |
TInt fieldIndex = FindFieldIndex( *iImageFieldType );
|
|
347 |
|
|
348 |
if ( fieldIndex != KErrNotFound )
|
|
349 |
{
|
|
350 |
// If filename has been set and the contact has the field
|
|
351 |
// field should be updated.
|
|
352 |
field = &iStoreContact->Fields().FieldAt( fieldIndex );
|
|
353 |
MVPbkContactFieldTextData::Cast( field->FieldData() ).
|
|
354 |
SetTextL( aFileName );
|
|
355 |
}
|
|
356 |
else if ( aFileName.Length() > 0 )
|
|
357 |
{
|
|
358 |
// Contact does not have the field, so create new one.
|
|
359 |
field = iStoreContact->CreateFieldLC( *iImageFieldType );
|
|
360 |
MVPbkContactFieldTextData::Cast( field->FieldData() ).
|
|
361 |
SetTextL( aFileName );
|
|
362 |
iStoreContact->AddFieldL( field );
|
|
363 |
CleanupStack::Pop(); // field
|
|
364 |
}
|
|
365 |
}
|
|
366 |
|
|
367 |
TBool CPbk2SetImageCmd::MGFetchL( CDesCArray& aSelectedFiles,
|
|
368 |
TMediaFileType aMediaType,
|
|
369 |
TBool aMultiSelect,
|
|
370 |
MMGFetchVerifier* aVerifier )
|
|
371 |
{
|
|
372 |
CEikAppUi* pAppUi = CEikonEnv::Static()->EikAppUi();
|
|
373 |
CAknNavigationDecorator *pNaviDecorator = NULL;
|
|
374 |
if ( pAppUi )
|
|
375 |
{
|
|
376 |
CEikStatusPane* StatusPane =
|
|
377 |
static_cast<CAknAppUi*>(pAppUi)->StatusPane();
|
|
378 |
TUid naviPaneUid = TUid::Uid( EEikStatusPaneUidNavi );
|
|
379 |
CAknNavigationControlContainer* naviPane =
|
|
380 |
static_cast<CAknNavigationControlContainer*>(
|
|
381 |
StatusPane->ControlL(naviPaneUid) );
|
|
382 |
pNaviDecorator = naviPane->Top();
|
|
383 |
if ( pNaviDecorator )
|
|
384 |
{
|
|
385 |
pNaviDecorator->MakeVisible( EFalse ); // Hide navi pane
|
|
386 |
pNaviDecorator->DrawNow();
|
|
387 |
}
|
|
388 |
}
|
|
389 |
|
|
390 |
TBool result( EFalse );
|
|
391 |
|
|
392 |
// run image fetch dialog
|
|
393 |
TRAPD(error, result = MGFetch::RunL( aSelectedFiles,
|
|
394 |
aMediaType,
|
|
395 |
aMultiSelect, // multiselection
|
|
396 |
aVerifier)); // provide MMGFetchVerifier interface to check DRM
|
|
397 |
|
|
398 |
if ( pNaviDecorator )
|
|
399 |
{
|
|
400 |
pNaviDecorator->MakeVisible( ETrue ); // Show again
|
|
401 |
pNaviDecorator->DrawNow();
|
|
402 |
}
|
|
403 |
User::LeaveIfError(error);
|
|
404 |
|
|
405 |
return result;
|
|
406 |
}
|
|
407 |
|
|
408 |
// End of File
|