mpxplugins/viewplugins/plugins/waitnotedialogplugin/src/mpxwaitnoteplugin.cpp
changeset 0 ff3acec5bc43
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 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:  Wait Note Plugin
       
    15 *
       
    16 */
       
    17 
       
    18 #include <eikdialg.h>
       
    19 #include <aknnotedialog.h>
       
    20 #include <mpxcustomcommandobserver.h>
       
    21 #include <mpxviewutilitycommanddef.h>
       
    22 #include <mpxlog.h>
       
    23 #include "mpxwaitnotedialog.h"
       
    24 #include "mpxwaitnoteconstructor.h"
       
    25 #include "mpxwaitnoteplugin.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Default Constructor
       
    31 // ---------------------------------------------------------------------------
       
    32 //
       
    33 CMPXWaitNoteDialogPlugin::CMPXWaitNoteDialogPlugin()
       
    34     {
       
    35     iWaitNote = NULL;
       
    36     iOldWaitNote = NULL;
       
    37     iNoteDialog = NULL;
       
    38     }
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Virtual destructor
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CMPXWaitNoteDialogPlugin::~CMPXWaitNoteDialogPlugin()
       
    45     {
       
    46     if (iIdle)
       
    47         {
       
    48         iIdle->Cancel();
       
    49         delete iIdle;
       
    50         iIdle = NULL;
       
    51         }
       
    52     if( iOldWaitNote )
       
    53         {
       
    54         delete iOldWaitNote;
       
    55         iOldWaitNote = NULL;
       
    56         }
       
    57     if( iWaitNote )
       
    58         {
       
    59         delete iWaitNote;
       
    60         iWaitNote = NULL;
       
    61         }
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // Second Phased Constructor
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 void CMPXWaitNoteDialogPlugin::ConstructL()
       
    69     {
       
    70     iIdle = CIdle::NewL(CActive::EPriorityIdle);
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // Destroy previous wait note when callback from CIdle
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 TInt CMPXWaitNoteDialogPlugin::DestroyOldWaiteNote( TAny* aPtr )
       
    78     {
       
    79     MPX_DEBUG1("CMPXWaitNoteDialogPlugin::DestroyOldWaiteNote()");
       
    80     TBool cont = EFalse;
       
    81 
       
    82     CMPXWaitNoteDialogPlugin* waitNotePlugin =
       
    83             static_cast<CMPXWaitNoteDialogPlugin*>(aPtr);
       
    84 
       
    85     if( waitNotePlugin->iOldWaitNote->ReadyToDestroy() )
       
    86         {
       
    87         TRAP_IGNORE( waitNotePlugin->iOldWaitNote->CancelNoteL() );
       
    88         delete waitNotePlugin->iOldWaitNote;
       
    89         waitNotePlugin->iOldWaitNote = NULL;
       
    90         cont = EFalse;
       
    91         }
       
    92     else
       
    93         {
       
    94         cont = ETrue;
       
    95         }
       
    96     return cont;
       
    97     }
       
    98 
       
    99 // ---------------------------------------------------------------------------
       
   100 // Two-Phased Constructor
       
   101 // ---------------------------------------------------------------------------
       
   102 //
       
   103 CMPXWaitNoteDialogPlugin* CMPXWaitNoteDialogPlugin::NewL()
       
   104     {
       
   105     CMPXWaitNoteDialogPlugin* self = new( ELeave ) CMPXWaitNoteDialogPlugin;
       
   106     CleanupStack::PushL( self );
       
   107     self->ConstructL();
       
   108     CleanupStack::Pop( self );
       
   109     return self;
       
   110     }
       
   111 // ---------------------------------------------------------------------------
       
   112 // Get NoteDialog resource
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CMPXWaitNoteDialogPlugin::NoteDialogL( CAknNoteDialog*& aNoteDialog,
       
   116                              TInt aDlgRsc, CAknNoteDialog::TTone aTone  )
       
   117     {
       
   118     MPX_DEBUG1("CMPXWaitNoteDialogPlugin::NoteDialogL()");
       
   119 
       
   120     if ( !iNoteDialog )
       
   121         {
       
   122         iNoteDialog = new ( ELeave ) CAknNoteDialog(
       
   123                 (CEikDialog**)( &iNoteDialog ),
       
   124                 CAknNoteDialog::ENoTone,
       
   125                 CAknNoteDialog::ENoTimeout );
       
   126         iNoteDialog->PrepareLC( aDlgRsc );
       
   127         iNoteDialog->SetTone( aTone );
       
   128         iNoteDialog->RunLD();
       
   129         }
       
   130     aNoteDialog = iNoteDialog;
       
   131     }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // Create the view
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 void CMPXWaitNoteDialogPlugin::CreateViewL()
       
   138     {
       
   139     // Do nothing
       
   140     }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // Destroy the view
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CMPXWaitNoteDialogPlugin::DestroyView()
       
   147     {
       
   148     MPX_DEBUG1("CMPXWaitNoteDialogPlugin::DestroyView()");
       
   149     if( iWaitNote )
       
   150         {
       
   151         TRAP_IGNORE( iWaitNote->CancelNoteL() );
       
   152         }
       
   153     }
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // Activate the view
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CMPXWaitNoteDialogPlugin::ActivateViewL( const TDesC* aParam )
       
   160     {
       
   161     MPX_DEBUG1("CMPXWaitNoteDialogPlugin::ActivateViewL()");
       
   162     // Delete old instance
       
   163     if( iWaitNote )
       
   164         {
       
   165         // delete old will callback and destroy second time, need to use a
       
   166         // old variable, and avoid using old address
       
   167         MPX_DEBUG1("CMPXWaitNoteDialogPlugin::ActivateViewL()");
       
   168         if( iOldWaitNote )
       
   169 	        {
       
   170 			TRAP_IGNORE( iOldWaitNote->CancelNoteL() );
       
   171 			delete iOldWaitNote;
       
   172 			iOldWaitNote = NULL;
       
   173 	        }
       
   174         iOldWaitNote = iWaitNote;
       
   175         iWaitNote = NULL;
       
   176         }
       
   177 
       
   178     // Start the note
       
   179     iWaitNote = CMPXWaitNoteConstructor::ConstructWaitNoteL( *aParam, this );
       
   180     iWaitNote->ExecuteLD();
       
   181     if( iOldWaitNote )
       
   182         {
       
   183 		iOldWaitNote->CancelNoteL();
       
   184         TCallBack callBack( CMPXWaitNoteDialogPlugin::DestroyOldWaiteNote,
       
   185                             this );
       
   186         if( iIdle->IsActive() )
       
   187             {
       
   188             iIdle->Cancel();
       
   189             }
       
   190         iIdle->Start(callBack);
       
   191         }
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // From CMPXViewPlugin
       
   196 // Interface method to activate as default view, will not bring to foreground
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CMPXWaitNoteDialogPlugin::SetAsDefaultViewL()
       
   200     {
       
   201     User::Leave( KErrNotSupported );
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // Deactivate the view
       
   206 // ---------------------------------------------------------------------------
       
   207 //
       
   208 void CMPXWaitNoteDialogPlugin::DeactivateView()
       
   209     {
       
   210     // Cancel the note if we deactivate the view.
       
   211     if (iWaitNote)  // Fix for ESLU-7CFEPF
       
   212         {
       
   213         TRAP_IGNORE( iWaitNote->CancelNoteL() );
       
   214         }
       
   215 
       
   216     if ( iCommandObserver )
       
   217         {
       
   218         TPckgC<TInt> selfPtr( reinterpret_cast<TInt>( this ) );
       
   219         iCommandObserver->HandleCustomCommand(
       
   220             TUid::Uid( KMPXViewUtilityCustomCommand ),
       
   221             EMPXViewUtilCmdViewDeActivated,
       
   222             selfPtr );
       
   223         }
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // Handling when the wait note is dismissed
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 void CMPXWaitNoteDialogPlugin::HandleWaitNoteDismissedL()
       
   231     {
       
   232     // Tell view framework that progress note has been dismissed
       
   233     //
       
   234     MPX_DEBUG1("CMPXWaitNoteDialogPlugin::HandleWaitNoteDismissedL()");
       
   235     if ( iCommandObserver )
       
   236         {
       
   237         TPckgC<TInt> selfPtr( reinterpret_cast<TInt>( this ) );
       
   238         iCommandObserver->HandleCustomCommand(
       
   239             TUid::Uid( KMPXViewUtilityCustomCommand ),
       
   240             EMPXViewUtilCmdViewDeActivated,
       
   241             selfPtr );
       
   242         }
       
   243     }