18
|
1 |
/*
|
|
2 |
* Copyright (c) 2002 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: LandmarksUi Content File - Provides LM UI class methods.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
// INCLUDE FILES
|
|
25 |
#include "CLmkMsgViewerAppUi.h"
|
|
26 |
#include "CLmkMsgViewerAppView.h"
|
|
27 |
#include "landmarks.hrh"
|
|
28 |
#include "CLmkMsgViewerDocument.h"
|
|
29 |
#include "CLmkParser.h"
|
|
30 |
#include "CLmkSender.h"
|
|
31 |
#include "CLmkPackageEditorImpl.h"
|
|
32 |
#include "CLmkDlgPackageSelectorImpl.h"
|
|
33 |
#include "LmkConsts.h"
|
|
34 |
#include "CLmkEditorDlg.h"
|
|
35 |
#include <AknsUtils.h>
|
|
36 |
#include <AknWaitDialog.h>
|
|
37 |
#include <EPos_CPosLandmarkDatabase.h>
|
|
38 |
#include <lmkmsgviewer.rsg>
|
|
39 |
#include <aknnotewrappers.h>
|
|
40 |
#include <StringLoader.h>
|
|
41 |
#include "LmkNotes.h"
|
|
42 |
#include <lmkerrors.h>
|
|
43 |
|
|
44 |
#if defined(_DEBUG)
|
|
45 |
// CONSTANTS
|
|
46 |
/// Unnamed namespace for local definitions
|
|
47 |
namespace {
|
|
48 |
|
|
49 |
_LIT( KPanicMsg, "CLmkMsgViewerAppUi");
|
|
50 |
|
|
51 |
void Panic( TPanicCode aReason )
|
|
52 |
{
|
|
53 |
User::Panic( KPanicMsg, aReason );
|
|
54 |
}
|
|
55 |
} // namespace
|
|
56 |
#endif
|
|
57 |
|
|
58 |
// Constant for periodic timer
|
|
59 |
const TInt KOneMicroSec = 1;
|
|
60 |
|
|
61 |
// ================= LOCAL FUNCTIONS =======================
|
|
62 |
|
|
63 |
//-----------------------------------------------------------------------
|
|
64 |
// ErrorNoteL
|
|
65 |
// ----------------------------------------------------------------------------
|
|
66 |
//
|
|
67 |
void ErrorNoteL(const TInt aResourceId)
|
|
68 |
{
|
|
69 |
HBufC* noteText = CEikonEnv::Static()->AllocReadResourceLC(aResourceId);
|
|
70 |
|
|
71 |
CAknErrorNote* dialog =
|
|
72 |
new( ELeave ) CAknErrorNote( R_AKN_INFORMATION_NOTE_WAIT );
|
|
73 |
dialog->ExecuteLD( *noteText );
|
|
74 |
|
|
75 |
CleanupStack::PopAndDestroy(noteText); //noteText
|
|
76 |
}
|
|
77 |
|
|
78 |
// ================= MEMBER FUNCTIONS =======================
|
|
79 |
|
|
80 |
// ----------------------------------------------------------
|
|
81 |
// CLmkMsgViewerAppUi::ConstructL
|
|
82 |
// ----------------------------------------------------------
|
|
83 |
//
|
|
84 |
void CLmkMsgViewerAppUi::ConstructL()
|
|
85 |
{
|
|
86 |
|
|
87 |
BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible);
|
|
88 |
|
|
89 |
iAppView = CLmkMsgViewerAppView::NewL( ClientRect() );
|
|
90 |
|
|
91 |
// Start an idle timer to start the dialog synchronously.
|
|
92 |
iIdleTimer = CPeriodic::NewL(CActive::EPriorityIdle);
|
|
93 |
iIdleTimer->Start(KOneMicroSec, KOneMicroSec,
|
|
94 |
TCallBack(CallBackFuncL,this));
|
|
95 |
}
|
|
96 |
|
|
97 |
// ----------------------------------------------------
|
|
98 |
// CLmkMsgViewerAppUi::~CLmkMsgViewerAppUi
|
|
99 |
// Destructor
|
|
100 |
// Frees reserved resources
|
|
101 |
// ----------------------------------------------------
|
|
102 |
//
|
|
103 |
CLmkMsgViewerAppUi::~CLmkMsgViewerAppUi()
|
|
104 |
{
|
|
105 |
if ( iIdleTimer )
|
|
106 |
{
|
|
107 |
delete iIdleTimer;
|
|
108 |
iIdleTimer = NULL;
|
|
109 |
}
|
|
110 |
|
|
111 |
TInt err = KErrNone;
|
|
112 |
TRAP(err, CloseWaitNoteL());
|
|
113 |
|
|
114 |
delete iAppView;
|
|
115 |
delete iLmkSender;
|
|
116 |
delete iParser;
|
|
117 |
delete iDb;
|
|
118 |
|
|
119 |
if( iDoorObserver )
|
|
120 |
{
|
|
121 |
iDoorObserver->NotifyExit( MApaEmbeddedDocObserver::EEmpty );
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
// ----------------------------------------------------
|
|
126 |
// CLmkMsgViewerAppUi::HandleCommandL
|
|
127 |
// ----------------------------------------------------
|
|
128 |
//
|
|
129 |
void CLmkMsgViewerAppUi::HandleCommandL( TInt aCommand )
|
|
130 |
{
|
|
131 |
switch ( aCommand )
|
|
132 |
{
|
|
133 |
// these all are same: save & exit
|
|
134 |
case EAknSoftkeyBack:
|
|
135 |
case EAknSoftkeyExit:
|
|
136 |
case EAknCmdExit:
|
|
137 |
case EEikCmdExit:
|
|
138 |
{
|
|
139 |
Exit();
|
|
140 |
break;
|
|
141 |
}
|
|
142 |
default:
|
|
143 |
{
|
|
144 |
break;
|
|
145 |
}
|
|
146 |
}
|
|
147 |
}
|
|
148 |
|
|
149 |
// ----------------------------------------------------
|
|
150 |
// CLmkMsgViewerAppUi::LmkSender
|
|
151 |
// ----------------------------------------------------
|
|
152 |
//
|
|
153 |
CLmkSender& CLmkMsgViewerAppUi::LmkSender() const
|
|
154 |
{
|
|
155 |
__ASSERT_DEBUG( iLmkSender, Panic( KLmkPanicNullMember ) );
|
|
156 |
return *iLmkSender;
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
// ----------------------------------------------------------------------------
|
|
161 |
// CLmkMsgViewerAppUi::OpenFileL
|
|
162 |
// This is called by framework when application is already open in background
|
|
163 |
// and user opens other file
|
|
164 |
// New file to been shown is passed via aFileName.
|
|
165 |
// ----------------------------------------------------------------------------
|
|
166 |
//
|
|
167 |
void CLmkMsgViewerAppUi::OpenFileL( const TDesC& aFileName )
|
|
168 |
{
|
|
169 |
// File changed.
|
|
170 |
|
|
171 |
// TODO: What to do with the possibly existing package?
|
|
172 |
// Should we just leave or do something else?
|
|
173 |
if ( iParser )
|
|
174 |
{
|
|
175 |
User::Leave( KErrAlreadyExists );
|
|
176 |
}
|
|
177 |
else
|
|
178 |
{
|
|
179 |
Document()->OpenFileL( EFalse, aFileName, iEikonEnv->FsSession() );
|
|
180 |
}
|
|
181 |
}
|
|
182 |
|
|
183 |
|
|
184 |
// ----------------------------------------------------------------------------
|
|
185 |
// CLmkMsgViewerAppUi::OpenFileL
|
|
186 |
// This is called by framework when application is already open in background
|
|
187 |
// and user opens other file
|
|
188 |
// New file to been shown is passed via aFileName.
|
|
189 |
// ----------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
void CLmkMsgViewerAppUi::OpenFileL(RFile& aFileHandle )
|
|
192 |
{
|
|
193 |
// File changed.
|
|
194 |
if ( iParser )
|
|
195 |
{
|
|
196 |
User::Leave( KErrAlreadyExists );
|
|
197 |
}
|
|
198 |
else
|
|
199 |
{
|
|
200 |
CFileStore* aFileStore = NULL;
|
|
201 |
static_cast<CLmkMsgViewerDocument*>(Document())->OpenFileL(aFileStore, aFileHandle);
|
|
202 |
}
|
|
203 |
}
|
|
204 |
|
|
205 |
// ----------------------------------------------------------------------------
|
|
206 |
// CLmkMsgViewerAppUi::ProcessCommandParametersL
|
|
207 |
// This method must return true or documents OpenFileL() get wrong file name.
|
|
208 |
// ----------------------------------------------------------------------------
|
|
209 |
//
|
|
210 |
TBool CLmkMsgViewerAppUi::ProcessCommandParametersL(
|
|
211 |
TApaCommand /*aCommand*/,
|
|
212 |
TFileName& /*aDocumentName*/,
|
|
213 |
const TDesC8& /*aTail*/ )
|
|
214 |
{
|
|
215 |
// Never call CEikAppUi::ProcessCommandParametersL(..) because
|
|
216 |
// it is so harmful to overwrite and destroy aDocumentName.
|
|
217 |
|
|
218 |
// Return ETrue so that CLmkMsgViewerAppUi::OpenFileL() gets
|
|
219 |
// the right document name.
|
|
220 |
return ETrue;
|
|
221 |
}
|
|
222 |
|
|
223 |
|
|
224 |
// ----------------------------------------------------
|
|
225 |
// CLmkMsgViewerAppUi::HandleOperationL
|
|
226 |
// ----------------------------------------------------
|
|
227 |
//
|
|
228 |
void CLmkMsgViewerAppUi::HandleOperationL(
|
|
229 |
TOperationTypes aType,
|
|
230 |
TReal32 /*aProgress*/,
|
|
231 |
TInt aStatus )
|
|
232 |
{
|
|
233 |
__ASSERT_DEBUG( ( aType == EInitialize ||
|
|
234 |
aType == EParse ) &&
|
|
235 |
aStatus != KPosLmOperationNotComplete,
|
|
236 |
Panic( KLmkPanicAlreadyActive ) );
|
|
237 |
|
|
238 |
TInt err = KErrNone;
|
|
239 |
if (aType == EInitialize)
|
|
240 |
{
|
|
241 |
TRAP(err, HandleDbInitFinishedL(aStatus));
|
|
242 |
}
|
|
243 |
else // (aType == EParse)
|
|
244 |
{
|
|
245 |
TRAP(err, HandleParseFinishedL(aStatus));
|
|
246 |
}
|
|
247 |
|
|
248 |
if (err)
|
|
249 |
{
|
|
250 |
CloseWaitNoteL(); // when wait note closes, application exits
|
|
251 |
}
|
|
252 |
}
|
|
253 |
|
|
254 |
// ----------------------------------------------------
|
|
255 |
// CLmkMsgViewerAppUi::HandleDbInitFinishedL
|
|
256 |
// ----------------------------------------------------
|
|
257 |
//
|
|
258 |
void CLmkMsgViewerAppUi::HandleDbInitFinishedL( TInt aStatus )
|
|
259 |
{
|
|
260 |
if (aStatus != KErrNone)
|
|
261 |
{
|
|
262 |
CCoeEnv::Static()->HandleError(aStatus);
|
|
263 |
User::Leave(aStatus);
|
|
264 |
}
|
|
265 |
iParser->StartParsingL();
|
|
266 |
}
|
|
267 |
|
|
268 |
// ----------------------------------------------------
|
|
269 |
// CLmkMsgViewerAppUi::HandleParseFinishedL
|
|
270 |
// ----------------------------------------------------
|
|
271 |
//
|
|
272 |
void CLmkMsgViewerAppUi::HandleParseFinishedL( TInt aStatus )
|
|
273 |
{
|
|
274 |
if (aStatus != KErrNone)
|
|
275 |
{
|
|
276 |
ErrorNoteL(R_LMK_BADPACKAGE_ERROR);
|
|
277 |
User::Leave(aStatus);
|
|
278 |
}
|
|
279 |
// now everything's ready for viewing
|
|
280 |
iDataReadyForView = ETrue;
|
|
281 |
CloseWaitNoteL(); // when wait note closes, view dialog opens
|
|
282 |
}
|
|
283 |
|
|
284 |
void CLmkMsgViewerAppUi::CloseWaitNoteL()
|
|
285 |
{
|
|
286 |
if (iWaitDialog)
|
|
287 |
{
|
|
288 |
iWaitDialog->ProcessFinishedL();
|
|
289 |
iWaitDialog = NULL;
|
|
290 |
}
|
|
291 |
}
|
|
292 |
|
|
293 |
// ----------------------------------------------------
|
|
294 |
// CLmkMsgViewerAppUi::ExecuteLmViewerL
|
|
295 |
// ----------------------------------------------------
|
|
296 |
//
|
|
297 |
void CLmkMsgViewerAppUi::ExecuteLmViewerL()
|
|
298 |
{
|
|
299 |
__ASSERT_DEBUG( iParser->NumOfParsedLandmarks() == 1,
|
|
300 |
Panic( KLmkPanicOutOfRange ) );
|
|
301 |
|
|
302 |
CLmkPackageEditorImpl* editorImpl =
|
|
303 |
CLmkPackageEditorImpl::NewL( *iDb, *iParser, *iLmkSender, 0 );
|
|
304 |
|
|
305 |
// Parser observing responsibility is given to the lm viewer,
|
|
306 |
// application is not interested in it anymore:
|
|
307 |
iParser->ChangeObserver( *editorImpl );
|
|
308 |
editorImpl->ExecuteLD();
|
|
309 |
}
|
|
310 |
|
|
311 |
// ----------------------------------------------------
|
|
312 |
// CLmkMsgViewerAppUi::ExecutePkgViewerL
|
|
313 |
// ----------------------------------------------------
|
|
314 |
//
|
|
315 |
void CLmkMsgViewerAppUi::ExecutePkgViewerL()
|
|
316 |
{
|
|
317 |
__ASSERT_DEBUG( iParser->NumOfParsedLandmarks() > 1,
|
|
318 |
Panic( KLmkPanicOutOfRange ) );
|
|
319 |
|
|
320 |
CLmkDlgPackageSelectorImpl* pkgViewer =
|
|
321 |
CLmkDlgPackageSelectorImpl::NewL( *iDb, *iParser, *iLmkSender );
|
|
322 |
CleanupStack::PushL( pkgViewer );
|
|
323 |
|
|
324 |
// Parser observing responsibility is given to the package viewer,
|
|
325 |
// application is not interested in it anymore:
|
|
326 |
iParser->ChangeObserver( *pkgViewer );
|
|
327 |
|
|
328 |
CArrayFix<TInt>* selectedItems =
|
|
329 |
new( ELeave ) CArrayFixFlat<TInt>( KLmkMultiSelectionGranularity );
|
|
330 |
CleanupStack::PushL( selectedItems );
|
|
331 |
|
|
332 |
pkgViewer->ExecuteL( *selectedItems, iParser->PackageName());
|
|
333 |
CleanupStack::PopAndDestroy( selectedItems );
|
|
334 |
CleanupStack::PopAndDestroy( pkgViewer );
|
|
335 |
}
|
|
336 |
|
|
337 |
// ----------------------------------------------------
|
|
338 |
// CLmkMsgViewerAppUi::OpenL
|
|
339 |
// ----------------------------------------------------
|
|
340 |
//
|
|
341 |
void CLmkMsgViewerAppUi::OpenL( const TDesC& aFilename )
|
|
342 |
{
|
|
343 |
iParser = CLmkParser::NewL( aFilename, *iDb, *this, EFalse );
|
|
344 |
DoOpenL();
|
|
345 |
Exit();
|
|
346 |
}
|
|
347 |
|
|
348 |
// ----------------------------------------------------
|
|
349 |
// CLmkMsgViewerAppUi::OpenL
|
|
350 |
// ----------------------------------------------------
|
|
351 |
//
|
|
352 |
void CLmkMsgViewerAppUi::OpenL(RFile& aFile)
|
|
353 |
{
|
|
354 |
iParser = CLmkParser::NewL( aFile, *iDb, *this, EFalse );
|
|
355 |
DoOpenL();
|
|
356 |
Exit();
|
|
357 |
}
|
|
358 |
|
|
359 |
void CLmkMsgViewerAppUi::DoOpenL()
|
|
360 |
{
|
|
361 |
// We need to initialize db before we start parsing:
|
|
362 |
iParser->InitializeDbL();
|
|
363 |
|
|
364 |
iWaitDialog = new( ELeave ) CAknWaitDialog( NULL, ETrue );
|
|
365 |
if (!iWaitDialog->ExecuteLD( R_LMK_MSGVIEWER_WAIT ))
|
|
366 |
{
|
|
367 |
//making iWaitDialog null, since framework destroys waitnote
|
|
368 |
//dialog on pressing cancel.
|
|
369 |
|
|
370 |
iWaitDialog = NULL;
|
|
371 |
}
|
|
372 |
|
|
373 |
if( iDataReadyForView )
|
|
374 |
{
|
|
375 |
if ( iParser->NumOfParsedLandmarks() == 1 )
|
|
376 |
{
|
|
377 |
ExecuteLmViewerL();
|
|
378 |
}
|
|
379 |
else if ( iParser->NumOfParsedLandmarks() > 1 )
|
|
380 |
{
|
|
381 |
ExecutePkgViewerL();
|
|
382 |
}
|
|
383 |
else
|
|
384 |
{
|
|
385 |
// exit
|
|
386 |
}
|
|
387 |
}
|
|
388 |
}
|
|
389 |
|
|
390 |
// -----------------------------------------------------------------------------
|
|
391 |
// CLmkMsgViewerAppUi::CallBackFuncL()
|
|
392 |
// Used to callback by the idle timer in order to launch
|
|
393 |
// the dialog
|
|
394 |
// -----------------------------------------------------------------------------
|
|
395 |
//
|
|
396 |
TInt CLmkMsgViewerAppUi::CallBackFuncL(TAny *aPtr)
|
|
397 |
{
|
|
398 |
CLmkMsgViewerAppUi* appUi =
|
|
399 |
static_cast< CLmkMsgViewerAppUi* >( aPtr );
|
|
400 |
|
|
401 |
if ( appUi )
|
|
402 |
{
|
|
403 |
return ( appUi->LaunchDialogL() );
|
|
404 |
}
|
|
405 |
else
|
|
406 |
{
|
|
407 |
// To indicate that the timer is not
|
|
408 |
// called again, return false to the timer
|
|
409 |
// RunL
|
|
410 |
return ( EFalse );
|
|
411 |
}
|
|
412 |
}
|
|
413 |
|
|
414 |
|
|
415 |
// -----------------------------------------------------------------------------
|
|
416 |
// CLmkMsgViewerAppUi::LaunchDialogL()
|
|
417 |
// This function accesses the document and launches the
|
|
418 |
// content.
|
|
419 |
// -----------------------------------------------------------------------------
|
|
420 |
//
|
|
421 |
TBool CLmkMsgViewerAppUi::LaunchDialogL()
|
|
422 |
{
|
|
423 |
if(!iIsDbOpen)
|
|
424 |
{
|
|
425 |
// Try to open DB
|
|
426 |
TRAPD( err, iDb = CPosLandmarkDatabase::OpenL() );
|
|
427 |
|
|
428 |
if( KErrNone != err )
|
|
429 |
{
|
|
430 |
// Cancel the periodic timer
|
|
431 |
if ( iIdleTimer->IsActive() )
|
|
432 |
{
|
|
433 |
iIdleTimer->Cancel();
|
|
434 |
}
|
|
435 |
// Display general system error note
|
|
436 |
HBufC* noteText = StringLoader::LoadL( R_LMK_ERR_EIKON_GENERAL, iEikonEnv );
|
|
437 |
CleanupStack::PushL( noteText );
|
|
438 |
CAknErrorNote* dialog = new(ELeave)CAknErrorNote( ETrue );
|
|
439 |
dialog->SetTone( CAknNoteDialog::EErrorTone );
|
|
440 |
dialog->ExecuteLD( *noteText );
|
|
441 |
CleanupStack::PopAndDestroy( noteText ); //noteText
|
|
442 |
// exit LmkMsgViewer app
|
|
443 |
Exit();
|
|
444 |
}
|
|
445 |
// DB was opened successfully
|
|
446 |
iIsDbOpen = ETrue;
|
|
447 |
iLmkSender = CLmkSender::NewL( *iDb );
|
|
448 |
}
|
|
449 |
CLmkMsgViewerDocument* document =
|
|
450 |
static_cast<CLmkMsgViewerDocument*>(iDocument);
|
|
451 |
|
|
452 |
// Check if file-handle in document is valid
|
|
453 |
if (document->IsFileHandleValid())
|
|
454 |
{
|
|
455 |
// Obtain the file-handle
|
|
456 |
RFile& fileHandle = document->GetLandmarkContentFileHandle();
|
|
457 |
|
|
458 |
// Cancel the periodic timer
|
|
459 |
if ( iIdleTimer->IsActive() )
|
|
460 |
{
|
|
461 |
iIdleTimer->Cancel();
|
|
462 |
}
|
|
463 |
// Launch the content
|
|
464 |
TRAPD(err,OpenL(fileHandle));
|
|
465 |
if(err != KErrNone)
|
|
466 |
{
|
|
467 |
if( err == KErrNotSupported)
|
|
468 |
{
|
|
469 |
LmkNotes::InformationNoteL( iEikonEnv, R_LMK_BADPACKAGE_ERROR );
|
|
470 |
}
|
|
471 |
Exit();
|
|
472 |
}
|
|
473 |
// Delete and reset the idle-timer
|
|
474 |
delete iIdleTimer;
|
|
475 |
iIdleTimer = NULL;
|
|
476 |
|
|
477 |
// Return False to indicate that
|
|
478 |
// timer need not callback further.
|
|
479 |
return EFalse;
|
|
480 |
}
|
|
481 |
else
|
|
482 |
{
|
|
483 |
// Return True to indicate that the
|
|
484 |
// timer needs to callback this function
|
|
485 |
// again, as the file-handle is not valid
|
|
486 |
// yet.
|
|
487 |
return ETrue;
|
|
488 |
}
|
|
489 |
}
|
|
490 |
|
|
491 |
// -----------------------------------------------------------------------------
|
|
492 |
// CLmkMsgViewerAppUi::HandleResourceChangeL()
|
|
493 |
// -----------------------------------------------------------------------------
|
|
494 |
//
|
|
495 |
void CLmkMsgViewerAppUi::HandleResourceChangeL(TInt aType)
|
|
496 |
{
|
|
497 |
CAknAppUi::HandleResourceChangeL( aType );
|
|
498 |
if ( aType == KEikDynamicLayoutVariantSwitch )
|
|
499 |
{
|
|
500 |
iAppView->SetRect(ClientRect());
|
|
501 |
}
|
|
502 |
}
|
|
503 |
// End of File
|