localconnectivityservice/dun/utils/src/DunNoteHandler.cpp
branchRCL_3
changeset 39 4096754ee773
parent 38 3dcb815346df
child 40 52a167391590
equal deleted inserted replaced
38:3dcb815346df 39:4096754ee773
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Manages note showing in UI
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bautils.h>
       
    20 #include <featmgr.h>
       
    21 #include <aknSDData.h>
       
    22 #include <secondarydisplay/dunsecondarydisplayapi.h>
       
    23 #include "DunNoteHandler.h"
       
    24 #include "DunDebug.h"
       
    25 
       
    26 _LIT( KDunUtilsDriveSpec, "z:" );
       
    27 _LIT( KDunUtilsResourceFileName, "dunutils.rsc" );
       
    28 
       
    29 const TInt KDunCoverEnumStart     = (ECmdNone + 1);  // start after ECmdNone
       
    30 const TInt KDunPtr8toPtr16Divider = 2;               // Divider for converting
       
    31 const TInt KDunThreeItemsToPop    = 3;
       
    32 
       
    33 // ======== MEMBER FUNCTIONS ========
       
    34 
       
    35 // ---------------------------------------------------------------------------
       
    36 // Two-phased constructor.
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CDunNoteHandler* CDunNoteHandler::NewL()
       
    40     {
       
    41     CDunNoteHandler* self = new (ELeave) CDunNoteHandler();
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Destructor
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CDunNoteHandler::~CDunNoteHandler()
       
    53     {
       
    54     FTRACE(FPrint( _L("CDunNoteHandler::~CDunNoteHandler()") ));
       
    55     ResetData();
       
    56     FTRACE(FPrint( _L("CDunNoteHandler::~CDunNoteHandler() complete") ));
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // Resets data to initial values
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CDunNoteHandler::ResetData()
       
    64     {
       
    65     FTRACE(FPrint( _L("CDunNoteHandler::ResetData()") ));
       
    66     // APIs affecting this:
       
    67     // IssueRequest()
       
    68     Stop();
       
    69     delete iNote;
       
    70     iNote = NULL;
       
    71     // Internal
       
    72     Initialize();
       
    73     FTRACE(FPrint( _L("CDunNoteHandler::ResetData() complete") ));
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // Issues request to start showing UI note
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 TInt CDunNoteHandler::IssueRequest()
       
    81     {
       
    82     FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest()") ));
       
    83     if ( iNoteState != EDunStateIdle )
       
    84         {
       
    85         FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() (not ready) complete") ));
       
    86         return KErrNotReady;
       
    87         }
       
    88     TRAPD( retTrap, DoIssueRequestL() );
       
    89     if ( retTrap != KErrNone )
       
    90         {
       
    91         FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() (trapped!) complete (%d)"), retTrap));
       
    92         return retTrap;
       
    93         }
       
    94     SetActive();
       
    95     iNoteState = EDunStateUiNoting;
       
    96     FTRACE(FPrint( _L("CDunNoteHandler::IssueRequest() complete") ));
       
    97     return KErrNone;
       
    98     }
       
    99 
       
   100 // ---------------------------------------------------------------------------
       
   101 // Stops showing UI note
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 TInt CDunNoteHandler::Stop()
       
   105     {
       
   106     FTRACE(FPrint( _L("CDunNoteHandler::Stop()") ));
       
   107     if ( iNoteState != EDunStateUiNoting )
       
   108         {
       
   109         FTRACE(FPrint( _L("CDunNoteHandler::Stop() (not ready) complete") ));
       
   110         return KErrNotReady;
       
   111         }
       
   112     if ( !iNote )
       
   113         {
       
   114         FTRACE(FPrint( _L("CDunNoteHandler::Stop() (iNote not initialized!) complete") ));
       
   115         return KErrGeneral;
       
   116         }
       
   117     iNote->CancelConfirmationQuery();
       
   118     Cancel();
       
   119     iNoteState = EDunStateIdle;
       
   120     FTRACE(FPrint( _L("CDunNoteHandler::Stop() complete") ));
       
   121     return KErrNone;
       
   122     }
       
   123 
       
   124 // ---------------------------------------------------------------------------
       
   125 // CDunNoteHandler::CDunNoteHandler
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 CDunNoteHandler::CDunNoteHandler() :
       
   129     CActive( EPriorityStandard )
       
   130     {
       
   131     Initialize();
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CDunNoteHandler::ConstructL
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void CDunNoteHandler::ConstructL()
       
   139     {
       
   140     FTRACE(FPrint( _L("CDunNoteHandler::ConstructL()") ));
       
   141     CActiveScheduler::Add( this );
       
   142     FTRACE(FPrint( _L("CDunNoteHandler::ConstructL() complete") ));
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // Initializes this class
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void CDunNoteHandler::Initialize()
       
   150     {
       
   151     FTRACE(FPrint( _L("CDunNoteHandler::Initialize()" ) ));
       
   152     iNote = NULL;
       
   153     iNoteState = EDunStateIdle;
       
   154     FTRACE(FPrint( _L("CDunNoteHandler::Initialize() complete" ) ));
       
   155     }
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 // Issues request to start showing UI note
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 void CDunNoteHandler::DoIssueRequestL()
       
   162     {
       
   163     FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL()") ));
       
   164     if ( iNote )
       
   165         {
       
   166         FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL() (ERROR) complete") ));
       
   167         User::Leave( KErrGeneral );
       
   168         }
       
   169     HBufC16* unicodeString = NULL;
       
   170     ReadResourceTextL( R_DUN_MAXIMUM_DIALUPS, unicodeString );
       
   171     CAknGlobalConfirmationQuery* note = CAknGlobalConfirmationQuery::NewLC();
       
   172     // Publish cover UI note data
       
   173     CAknSDData* sdData = CAknSDData::NewL( KDunNoteCategory,
       
   174                                            ECmdMaxNumber - KDunCoverEnumStart,
       
   175                                            KNullDesC8 );
       
   176     note->SetSecondaryDisplayData( sdData );  // ownership transferred
       
   177     // Start to show note
       
   178     iStatus = KRequestPending;
       
   179     note->ShowConfirmationQueryL( iStatus,
       
   180                                   *unicodeString,
       
   181                                   R_AVKON_SOFTKEYS_OK_EMPTY,
       
   182                                   R_QGN_NOTE_ERROR_ANIM,
       
   183                                   KNullDesC,
       
   184                                   0,
       
   185                                   0,
       
   186                                   CAknQueryDialog::EErrorTone );
       
   187     CleanupStack::Pop( note );
       
   188     delete unicodeString;
       
   189     iNote = note;
       
   190     FTRACE(FPrint( _L("CDunNoteHandler::DoIssueRequestL() complete") ));
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------------------------
       
   194 // Reads resource string
       
   195 // ---------------------------------------------------------------------------
       
   196 //
       
   197 void CDunNoteHandler::ReadResourceTextL( TInt aResourceId, HBufC16*& aUnicode )
       
   198     {
       
   199     FTRACE(FPrint( _L("CDunNoteHandler::ReadNoteResourceL()") ));
       
   200     // Connect to file server (for resource file reading)
       
   201     RFs fileSession;
       
   202     CleanupClosePushL<RFs>( fileSession );
       
   203     User::LeaveIfError( fileSession.Connect() );
       
   204     // Create dunutils.rsc path and file name
       
   205     TFileName fileName;
       
   206     fileName = KDunUtilsDriveSpec;
       
   207     fileName += KDC_RESOURCE_FILES_DIR;
       
   208     fileName += KDunUtilsResourceFileName;
       
   209     // Find nearest language file for resource
       
   210     BaflUtils::NearestLanguageFile( fileSession, fileName );
       
   211     // Read note resource
       
   212     RResourceFile resourceFile;
       
   213     CleanupClosePushL<RResourceFile>( resourceFile );
       
   214     resourceFile.OpenL( fileSession, fileName );
       
   215     resourceFile.ConfirmSignatureL();
       
   216     HBufC8* readBuffer = resourceFile.AllocReadLC( aResourceId );
       
   217     // Convert read HBufC8 to HBufC16
       
   218     const TPtrC16 ptr16(reinterpret_cast<const TUint16*>
       
   219                        (readBuffer->Ptr()),
       
   220                        (readBuffer->Size() / KDunPtr8toPtr16Divider) );
       
   221     aUnicode = HBufC16::NewL( ptr16.Length() );
       
   222     *aUnicode = ptr16;
       
   223     CleanupStack::PopAndDestroy( KDunThreeItemsToPop );  // readBuffer, resourceFile, fileSession
       
   224     FTRACE(FPrint( _L("CDunNoteHandler::ReadNoteResourceL() complete") ));
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------------------------
       
   228 // From class CActive.
       
   229 // Gets called when UI note dismissed
       
   230 // ---------------------------------------------------------------------------
       
   231 //
       
   232 void CDunNoteHandler::RunL()
       
   233     {
       
   234     FTRACE(FPrint( _L("CDunNoteHandler::RunL()" ) ));
       
   235     iNoteState = EDunStateIdle;
       
   236     delete iNote;
       
   237     iNote = NULL;
       
   238     FTRACE(FPrint( _L("CDunNoteHandler::RunL() complete" ) ));
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------------------------
       
   242 // From class CActive.
       
   243 // Gets called on cancel
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 void CDunNoteHandler::DoCancel()
       
   247     {
       
   248     }