wvuing/IMPSAlwaysOnlinePlugin/src/CIMPSReconnectNoteHandler.cpp
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2004 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:  Handles the always online functionality for the presence
       
    15 *				 engine
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include "MIMPSReconnectNoteObserver.h"
       
    23 #include "CIMPSReconnectNoteHandler.h"
       
    24 #include "IMPSCommonUiDebugPrint.h"
       
    25 #include "cimpspresenceaaconnectionng.h"
       
    26 #include "impscommonuibuilddefinitions.h"
       
    27 
       
    28 #include <AknGlobalConfirmationQuery.h>
       
    29 #include <flogger.h>
       
    30 #include <e32std.h>
       
    31 #include <PEngAOPluginNG.rsg>
       
    32 #include <bautils.h>
       
    33 #include <StringLoader.h>
       
    34 #include <data_caging_path_literals.hrh>
       
    35 
       
    36 _LIT( KAOPluginResourceFile, "PENGAOPluginNG.rsc" );
       
    37 
       
    38 _LIT( KAOPluginResourcePath, "\\Resource\\" );
       
    39 
       
    40 
       
    41 // LOCAL CONSTANTS AND MACROS
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CIMPSReconnectNoteHandler::CIMPSReconnectNoteHandler
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CIMPSReconnectNoteHandler::CIMPSReconnectNoteHandler() : CActive( EPriorityStandard )
       
    52     {
       
    53     CActiveScheduler::Add( this );
       
    54     }
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // CIMPSReconnectNoteHandler::ConstructL
       
    58 // Symbian 2nd phase constructor can leave.
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 void CIMPSReconnectNoteHandler::ConstructL( TIMPSConnectionClient aClient )
       
    62     {
       
    63     iGlobalConfirmationQuery = CAknGlobalConfirmationQuery::NewL();
       
    64     iConnectionUI = CIMPSPresenceAAConnection::NewL( aClient );
       
    65     iClient = aClient;
       
    66 
       
    67     User::LeaveIfError( iFs.Connect() );
       
    68 
       
    69     TFileName resourceFileName;
       
    70     resourceFileName.Zero();
       
    71     //artificial variable scope to ease the stack usage
       
    72     TFileName drivePath;
       
    73     Dll::FileName( drivePath );
       
    74     resourceFileName.Append( TParsePtrC( drivePath ).Drive() );
       
    75     //resourceFileName.Append( KDC_RESOURCE_FILES_DIR() )
       
    76     //
       
    77     // contains big letters
       
    78     resourceFileName.Append( KAOPluginResourcePath() );
       
    79     resourceFileName.Append( KAOPluginResourceFile );
       
    80 
       
    81     if ( resourceFileName.Length() > 0 )
       
    82         {
       
    83         // when baflutils gets an empty string, it returns "C:",
       
    84         // which breaks things
       
    85         BaflUtils::NearestLanguageFile( iFs, resourceFileName );
       
    86         }
       
    87 
       
    88     iResFile.OpenL( iFs, resourceFileName );
       
    89     iResFile.ConfirmSignatureL();
       
    90     }
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CIMPSReconnectNoteHandler::NewL
       
    94 // Two-phased constructor.
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 CIMPSReconnectNoteHandler* CIMPSReconnectNoteHandler::NewL( TIMPSConnectionClient aClient )
       
    98     {
       
    99     CIMPSReconnectNoteHandler* self = new( ELeave ) CIMPSReconnectNoteHandler;
       
   100 
       
   101     CleanupStack::PushL( self );
       
   102     self->ConstructL( aClient );
       
   103     CleanupStack::Pop( self );
       
   104 
       
   105     return self;
       
   106     }
       
   107 
       
   108 // Destructor
       
   109 CIMPSReconnectNoteHandler::~CIMPSReconnectNoteHandler()
       
   110     {
       
   111     Cancel();
       
   112     delete iGlobalConfirmationQuery;
       
   113     delete iConnectionUI;
       
   114     iObservers.Close();
       
   115     iResFile.Close();
       
   116     iFs.Close();
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------
       
   120 // CIMPSReconnectNoteHandler::DoCancel
       
   121 //
       
   122 // ---------------------------------------------------------
       
   123 //
       
   124 void CIMPSReconnectNoteHandler::DoCancel()
       
   125     {
       
   126     iGlobalConfirmationQuery->CancelConfirmationQuery();
       
   127     }
       
   128 
       
   129 // ---------------------------------------------------------
       
   130 // CIMPSReconnectNoteHandler::RunL
       
   131 //
       
   132 // ---------------------------------------------------------
       
   133 //
       
   134 void CIMPSReconnectNoteHandler::RunL()
       
   135     {
       
   136     TInt answer( iStatus.Int() );
       
   137     HandleNoteAnswered( answer );
       
   138     Cancel();
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------
       
   142 // CIMPSReconnectNoteHandler::RemoveObserver
       
   143 //
       
   144 // ---------------------------------------------------------
       
   145 //
       
   146 void CIMPSReconnectNoteHandler::RemoveObserver( MIMPSReconnectNoteObserver* aObserver )
       
   147     {
       
   148     TInt index( iObservers.Find( aObserver ) );
       
   149 
       
   150     if ( index != KErrNotFound )
       
   151         {
       
   152         iObservers.Remove( index );
       
   153         }
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------
       
   157 // CIMPSReconnectNoteHandler::ShowNote
       
   158 //
       
   159 // ---------------------------------------------------------
       
   160 //
       
   161 void CIMPSReconnectNoteHandler::ShowNote( MIMPSReconnectNoteObserver* aObserver )
       
   162     {
       
   163     TRAPD( err, DoShowNoteL( aObserver ) );
       
   164     if ( err )
       
   165         {
       
   166         CActiveScheduler::Current()->Error( err );
       
   167         RemoveObserver( aObserver );
       
   168         }
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------
       
   172 // CIMPSReconnectNoteHandler::CancelNoteShowing
       
   173 //
       
   174 // ---------------------------------------------------------
       
   175 //
       
   176 void CIMPSReconnectNoteHandler::CancelNoteShowing( MIMPSReconnectNoteObserver* aObserver )
       
   177     {
       
   178     if ( IsActive() )
       
   179         {
       
   180         Cancel();
       
   181         }
       
   182     RemoveObserver( aObserver );
       
   183     HandleNoteCancelled();
       
   184     iObservers.Reset();
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------
       
   188 // CIMPSReconnectNoteHandler::DoShowNoteL
       
   189 //
       
   190 // ---------------------------------------------------------
       
   191 //
       
   192 void CIMPSReconnectNoteHandler::DoShowNoteL( MIMPSReconnectNoteObserver* aObserver )
       
   193     {
       
   194     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSReconnectNoteHandler::StartShowing" ) );
       
   195 
       
   196     AddObserverL( aObserver );
       
   197 
       
   198     if ( !IsActive() )
       
   199         {
       
   200         HBufC* prompt = PromptTextLC();
       
   201         iGlobalConfirmationQuery->ShowConfirmationQueryL(
       
   202             iStatus, *prompt, R_AVKON_SOFTKEYS_YES_NO__YES );
       
   203         CleanupStack::PopAndDestroy( prompt ); // prompt
       
   204         SetActive();
       
   205         }
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------
       
   209 // CIMPSReconnectNoteHandler::RunError
       
   210 //
       
   211 // ---------------------------------------------------------
       
   212 //
       
   213 TInt CIMPSReconnectNoteHandler::RunError( TInt aError )
       
   214     {
       
   215     IMPSCUI_DP( D_IMPSCUI_LIT( "CIMPSReconnectNoteHandler::RunError [%d]" ), aError );
       
   216     if ( IsActive() )
       
   217         {
       
   218         Cancel();
       
   219         }
       
   220     HandleNoteCancelled();
       
   221     iObservers.Reset();
       
   222     return KErrNone;
       
   223     }
       
   224 
       
   225 
       
   226 // ---------------------------------------------------------
       
   227 // CIMPSReconnectNoteHandler::AddObserverL
       
   228 //
       
   229 // ---------------------------------------------------------
       
   230 //
       
   231 void CIMPSReconnectNoteHandler::AddObserverL( MIMPSReconnectNoteObserver* aObserver )
       
   232     {
       
   233     if ( iObservers.Find( aObserver ) == KErrNotFound )
       
   234         {
       
   235         User::LeaveIfError( iObservers.Append( aObserver ) );
       
   236         }
       
   237     }
       
   238 
       
   239 // ---------------------------------------------------------
       
   240 // CIMPSReconnectNoteHandler::HandleNoteAnswered
       
   241 //
       
   242 // ---------------------------------------------------------
       
   243 //
       
   244 void CIMPSReconnectNoteHandler::HandleNoteAnswered( TInt aAnswer )
       
   245     {
       
   246     for ( TInt index( 0 ); index < iObservers.Count(); ++index )
       
   247         {
       
   248         iObservers[index]->HandleNoteAnswered( aAnswer );
       
   249         }
       
   250     }
       
   251 
       
   252 // ---------------------------------------------------------
       
   253 // CIMPSReconnectNoteHandler::HandleNoteCanceled
       
   254 //
       
   255 // ---------------------------------------------------------
       
   256 //
       
   257 void CIMPSReconnectNoteHandler::HandleNoteCancelled()
       
   258     {
       
   259     for ( TInt index( 0 ); index < iObservers.Count(); ++index )
       
   260         {
       
   261         iObservers[index]->HandleNoteCancelled();
       
   262         }
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------
       
   266 // CIMPSReconnectNoteHandler::PromptTextLC
       
   267 //
       
   268 // ---------------------------------------------------------
       
   269 //
       
   270 HBufC* CIMPSReconnectNoteHandler::PromptTextLC()
       
   271     {
       
   272     HBufC* srvname = iConnectionUI->DefaultServerNameL( iClient );
       
   273     CleanupStack::PushL( srvname );
       
   274     HBufC* prompt = ReadResourceWithDynTextLC( R_QTN_CHAT_RECONNECT_FAILED, *srvname );
       
   275     CleanupStack::Pop( prompt );
       
   276     CleanupStack::PopAndDestroy( srvname );
       
   277     CleanupStack::PushL( prompt );
       
   278     return prompt;
       
   279     }
       
   280 
       
   281 // -----------------------------------------------------------------------------
       
   282 // CIMPSReconnectNoteHandler::ReadResourceLC()
       
   283 // -----------------------------------------------------------------------------
       
   284 //
       
   285 HBufC* CIMPSReconnectNoteHandler::ReadResourceLC( TInt aNoteTextResourceId )
       
   286     {
       
   287     //Own resource reader for AA plug-in environment (no CONE facilities available)
       
   288 
       
   289     //resource texts are hold in TBUFs
       
   290     //TBUF == "A utility struct that holds one non-zero-terminated string."
       
   291     //==> no lead bytes in resource string
       
   292 
       
   293     TInt plainResourceId = 0x00000fff & aNoteTextResourceId; // Remove offset from id
       
   294     HBufC8* rawDataBuf = iResFile.AllocReadLC( plainResourceId );
       
   295 
       
   296     //raw data buffer is actually unicode text ==> treat it so
       
   297     TPtrC16 rawData( ( TUint16* ) rawDataBuf->Ptr(),
       
   298                      rawDataBuf->Length() / 2 );
       
   299 
       
   300     HBufC16* resourceData = rawData.AllocL();
       
   301     CleanupStack::PopAndDestroy( rawDataBuf );
       
   302 
       
   303     CleanupStack::PushL( resourceData );
       
   304 
       
   305     return resourceData;
       
   306     }
       
   307 
       
   308 
       
   309 // -----------------------------------------------------------------------------
       
   310 // CIMPSReconnectNoteHandler::ReadResourceWithDynTextLC()
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 HBufC* CIMPSReconnectNoteHandler::ReadResourceWithDynTextLC( TInt aNoteTextResourceId,
       
   314                                                              const TDesC& aInsertText )
       
   315     {
       
   316     //Own dynamic string loader for AA plug-in environment (no CONE facilities available)
       
   317 
       
   318     HBufC* resStringBuf = ReadResourceLC( aNoteTextResourceId );
       
   319 
       
   320     TInt reqDynLen = resStringBuf->Length() + aInsertText.Length();
       
   321     HBufC* dynStringBuf = HBufC::NewL( reqDynLen );
       
   322     TPtr dynString = dynStringBuf->Des();
       
   323     StringLoader::Format( dynString,
       
   324                           *resStringBuf,
       
   325                           -1,             //No index code in source string
       
   326                           aInsertText );
       
   327 
       
   328     CleanupStack::PopAndDestroy( resStringBuf );
       
   329     CleanupStack::PushL( dynStringBuf );
       
   330     return dynStringBuf;
       
   331     }
       
   332 
       
   333 
       
   334 //  End of File
       
   335