nwnotifier/src/networknotifiernotewrapper.cpp
branchRCL_3
changeset 3 a4a774cb6ea7
child 8 1b9ee3c7442d
equal deleted inserted replaced
0:ff3b6d0fd310 3:a4a774cb6ea7
       
     1 /*
       
     2 * Copyright (c) 2010 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: Active object wrapper to handle popup note.
       
    15 *
       
    16 */
       
    17 
       
    18 // System includes
       
    19 #include <avkon.hrh>
       
    20 #include <aknglobalconfirmationquery.h> 
       
    21 #include <bautils.h>
       
    22 #include <pathinfo.h>
       
    23 
       
    24 // Includes
       
    25 #include "networknotifiernotewrapper.h"
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // CNetworkNotifierNoteWrapper::NewLC()
       
    29 // Two-phased constructor.
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CNetworkNotifierNoteWrapper* CNetworkNotifierNoteWrapper::NewL( MNoteWrapperObserver& aObserver,
       
    33                                                                 TInt aResID )
       
    34     {
       
    35     CNetworkNotifierNoteWrapper* self = new( ELeave ) CNetworkNotifierNoteWrapper( aObserver,
       
    36                                                                                    aResID );
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );    
       
    40     return self;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CNetworkNotifierNoteWrapper::ConstructL
       
    45 // 
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CNetworkNotifierNoteWrapper::ConstructL()
       
    49     {
       
    50     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::ConstructL() -START") );
       
    51     
       
    52     User::LeaveIfError( iFs.Connect() );
       
    53     
       
    54     HBufC* note = ReadResourceLC();
       
    55     
       
    56     if( note )
       
    57         {
       
    58         DisplayPopupNoteL( note );
       
    59         CleanupStack::PopAndDestroy( note );
       
    60         }
       
    61     
       
    62     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::ConstructL() -END") );
       
    63     }
       
    64 
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CNetworkNotifierNoteWrapper::CNetworkNotifierNoteWrapper
       
    68 // 
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CNetworkNotifierNoteWrapper::CNetworkNotifierNoteWrapper( MNoteWrapperObserver& aObserver, 
       
    72                                                           TInt aResID ) : 
       
    73                                                           CActive( EPriorityStandard ), 
       
    74                                                           iObserver( aObserver ) 
       
    75     {
       
    76     iErrNotes.Insert( aResID, 0 );
       
    77     CActiveScheduler::Add( this );
       
    78     }
       
    79 
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CNetworkNotifierNoteWrapper::~CNetworkNotifierNoteWrapper
       
    83 // 
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 CNetworkNotifierNoteWrapper::~CNetworkNotifierNoteWrapper()
       
    87     {
       
    88     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::~CNetworkNotifierNoteWrapper() -START") );
       
    89     
       
    90     iFs.Close();
       
    91     iErrNotes.Close(); // cleanup and close
       
    92     
       
    93     Cancel();
       
    94     delete iGlobalQuery;
       
    95     
       
    96     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::~CNetworkNotifierNoteWrapper() -END") );
       
    97     }
       
    98 
       
    99 
       
   100 // -----------------------------------------------------------------------------
       
   101 // CNetworkNotifierNoteWrapper::AppendNote
       
   102 //
       
   103 // Monitor inserts the latest error notification err# from ETEL to this stack
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 void CNetworkNotifierNoteWrapper::AppendNote( const TInt aResID )
       
   107     {
       
   108     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::AppendNote() -START") );
       
   109     iErrNotes.Insert( aResID, 0 );
       
   110     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::AppendNote() -END") );
       
   111     }
       
   112 
       
   113 
       
   114 // -----------------------------------------------------------------------------
       
   115 // CNetworkNotifierNoteWrapper::DisplayPopupNoteL
       
   116 // 
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CNetworkNotifierNoteWrapper::DisplayPopupNoteL( HBufC* aNote )
       
   120     {
       
   121     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::DisplayPopupNoteL() -START") );
       
   122     
       
   123     if( !IsActive() )
       
   124         {   
       
   125         if( !iGlobalQuery )
       
   126 			{
       
   127             iGlobalQuery = CAknGlobalConfirmationQuery::NewL();
       
   128         	}
       
   129 		if( aNote )
       
   130 			{
       
   131         	iGlobalQuery->ShowConfirmationQueryL( iStatus, 
       
   132                                                   *aNote, 
       
   133                                                   R_AVKON_SOFTKEYS_OK_EMPTY, 
       
   134                                                   R_QGN_NOTE_WARNING_ANIM );
       
   135 			}
       
   136 		
       
   137         SetActive();
       
   138         }
       
   139 
       
   140     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::DisplayPopupNoteL() -END") );
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CNetworkNotifierNoteWrapper::ReadResourceLC
       
   145 //
       
   146 // Just to read localized error strings from resource 
       
   147 //
       
   148 // -----------------------------------------------------------------------------
       
   149 //
       
   150 HBufC* CNetworkNotifierNoteWrapper::ReadResourceLC()
       
   151     {
       
   152     RDebug::Print(
       
   153             _L("NW: CNetworkNotifierNoteWrapper::ReadResourceLC() -START") );
       
   154 
       
   155     TInt resId;
       
   156     RResourceFile resFile;
       
   157     TResourceReader reader;
       
   158 
       
   159     TFileName fullFileName;
       
   160     TDriveUnit driveNum = PathInfo::RomRootPath();
       
   161 
       
   162     fullFileName.Insert( 0, driveNum.Name() );
       
   163     fullFileName.Append( KResFile );
       
   164 
       
   165     TFileName file( fullFileName );
       
   166     HBufC16* textBuffer = NULL;
       
   167     
       
   168     // We are interested in the most recent err note at a time
       
   169     resId = iErrNotes[0];
       
   170 
       
   171     // Err# can be removed from the stack now
       
   172     iErrNotes.Remove( 0 );
       
   173         
       
   174     BaflUtils::NearestLanguageFile( iFs, file );   
       
   175     resFile.OpenL( iFs, file );
       
   176     // According to SDK docs, resFile will be closed if this function leaves
       
   177     resFile.ConfirmSignatureL();
       
   178     
       
   179     HBufC8* readBuffer = resFile.AllocReadLC( resId );
       
   180     reader.SetBuffer( readBuffer );
       
   181     
       
   182     TPtrC textdata = reader.ReadTPtrC();
       
   183     textBuffer = HBufC16::NewL( textdata.Length() );
       
   184     *textBuffer = textdata;
       
   185     
       
   186     CleanupStack::PopAndDestroy( readBuffer );
       
   187     CleanupStack::PushL( textBuffer );
       
   188     
       
   189     resFile.Close();
       
   190         
       
   191     RDebug::Print(
       
   192             _L("NW: CNetworkNotifierNoteWrapper::ReadResourceLC() -END"));
       
   193     return textBuffer;
       
   194     }
       
   195 
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CNetworkNotifierNoteWrapper::RunL
       
   199 // Pure virtuals from CActive implemented in this derived class.
       
   200 // iStatus error handling is not needed here, since the service provider for
       
   201 // this AO (in DisplayPopupNoteL) will leave in case of an error, and will 
       
   202 // therefore be handled in RunError.
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 void CNetworkNotifierNoteWrapper::RunL()
       
   206     {
       
   207     RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::RunL -START") );
       
   208         
       
   209     if( iErrNotes.Count() ) // There are more errors to display: 
       
   210         { 
       
   211         HBufC* note = ReadResourceLC();
       
   212         
       
   213         if ( note )
       
   214             {
       
   215             DisplayPopupNoteL( note );
       
   216             CleanupStack::PopAndDestroy( note );
       
   217             }
       
   218         }
       
   219     else
       
   220         { 
       
   221         // Error note stack is empty, since this task has completed and let monitor 
       
   222         // to destruct this instance
       
   223         RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::RunL : No more notes to display") );
       
   224         iObserver.PopupNoteClosed();
       
   225         }
       
   226     }
       
   227 
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // CNetworkNotifierNoteWrapper::DoCancel
       
   231 // 
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void CNetworkNotifierNoteWrapper::DoCancel()
       
   235     {
       
   236     if( iGlobalQuery )
       
   237         {
       
   238         iGlobalQuery->CancelConfirmationQuery();
       
   239         }
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CNetworkNotifierNoteWrapper::RunError()
       
   244 // 
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 TInt CNetworkNotifierNoteWrapper::RunError( TInt aError )
       
   248     {
       
   249     // Resource reader failed in ReadResourceLC
       
   250     // Just reissue the request
       
   251     if ( aError )
       
   252         {
       
   253         RDebug::Print( _L("NW: CNetworkNotifierNoteWrapper::RunError: Showing of the note failed!") );
       
   254         }
       
   255     
       
   256     return KErrNone;
       
   257     }
       
   258 
       
   259 // end of file