usbuis/usbuinotif/src/usbuinotifotgerror.cpp
changeset 35 9d8b04ca6939
child 38 218231f2b3b3
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     1 /*
       
     2 * Copyright (c) 2007, 2009 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:  USB UI queries notifier class.
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <eikenv.h>          // Eikon environment
       
    21 #include <bautils.h>         // BAFL utils (for language file)
       
    22 #include <utf.h>             // Unicode character conversion utilities
       
    23 #include <StringLoader.h>    // Localisation stringloader
       
    24 #include <AknQueryDialog.h> 
       
    25 #include <aknnotewrappers.h>
       
    26 
       
    27 #include <usbuinotif.h>                     // pck
       
    28 #include <usbuinotif.rsg>                   // Own resources
       
    29 #include "usbuinotifotgerror.h"             // Own class definition
       
    30 #include "usbuinotifdebug.h"                // Debugging macros
       
    31 #include "usbuinotifsecondarydisplay.h"     // Dialog index for cover UI
       
    32 // ================= MEMBER FUNCTIONS =========================================
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // CUsbUiNotifOtgError::NewL
       
    36 // Two-phased constructor.
       
    37 // ----------------------------------------------------------------------------
       
    38 //
       
    39 CUsbUiNotifOtgError* CUsbUiNotifOtgError::NewL()
       
    40     {
       
    41     CUsbUiNotifOtgError* self = new (ELeave) CUsbUiNotifOtgError();
       
    42     CleanupStack::PushL( self );
       
    43     self->ConstructL();
       
    44     CleanupStack::Pop( self );
       
    45     return self;
       
    46     }
       
    47 
       
    48 // ----------------------------------------------------------------------------
       
    49 // CUsbUiNotifOtgError::CUsbUiNotifOtgError
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // ----------------------------------------------------------------------------
       
    53 //
       
    54 CUsbUiNotifOtgError::CUsbUiNotifOtgError() :
       
    55     iStringIds( KUsbUiNotifOtgGeneralQueryGranularity)
       
    56     {
       
    57     }
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // Destructor
       
    61 // ----------------------------------------------------------------------------
       
    62 //
       
    63 CUsbUiNotifOtgError::~CUsbUiNotifOtgError()
       
    64     {
       
    65     //Make sure that the request is completed. Note that inside the destructor,
       
    66     //this virtual function call is to local CUsbUiNotifOtgError::Cancel, 
       
    67     //not to any possibly derived class implementation. 
       
    68     Cancel();
       
    69     }
       
    70 
       
    71 void CUsbUiNotifOtgError::ConstructL()
       
    72     {
       
    73     CUSBUINotifierBase::ConstructL();
       
    74     iStringIds.AppendL( R_USB_OTG_ERROR_CURRENT_LIMIT);
       
    75     iStringIds.AppendL( R_USB_OTG_ERROR_TOO_MUCH_CURRENT_REQUIRED);
       
    76     iStringIds.AppendL( R_USB_OTG_ERROR_UNSUPPORTED);
       
    77     iStringIds.AppendL( R_USB_OTG_ERROR_HUB_UNSUPPORTED);
       
    78     iStringIds.AppendL( R_USB_OTG_ERROR_UNRECOVERABLE);
       
    79     iStringIds.AppendL( R_USB_OTG_ERROR_ATTACH_TIMEDOUT);
       
    80     iStringIds.AppendL( R_USB_ERROR_MEMORY_NOT_ENOUGH);
       
    81     }
       
    82 
       
    83 // ----------------------------------------------------------------------------
       
    84 // CUsbUiNotifOtgError::RegisterL
       
    85 // Register notifier.
       
    86 // ----------------------------------------------------------------------------
       
    87 //
       
    88 CUsbUiNotifOtgError::TNotifierInfo CUsbUiNotifOtgError::RegisterL()
       
    89     {
       
    90     iInfo.iUid = KUsbUiNotifOtgError;
       
    91     iInfo.iChannel = KUsbUiNotifOtgError;
       
    92     iInfo.iPriority = ENotifierPriorityVHigh;
       
    93     return iInfo;
       
    94     }
       
    95 
       
    96 // ----------------------------------------------------------------------------
       
    97 // CUsbUiNotifOtgError::GetParamsL
       
    98 //  Jump to RunL as soon as possible.
       
    99 // ----------------------------------------------------------------------------
       
   100 //
       
   101 void CUsbUiNotifOtgError::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot,
       
   102         const RMessagePtr2& aMessage)
       
   103     {
       
   104     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::GetParamsL"));
       
   105     if (iQuery || iReplySlot != 0 || iNeedToCompleteMessage)
       
   106         {
       
   107         User::Leave( KErrInUse );
       
   108         }
       
   109         
       
   110     // Get parameters 
       
   111     //
       
   112     
       
   113     TPckgC<TInt> pckg( iErrorId );
       
   114     pckg.Set( aBuffer );
       
   115     iErrorId = pckg();
       
   116     
       
   117     FTRACE(FPrint(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::GetParamsL iErrorId: %d"), iErrorId ));  
       
   118     if ( iErrorId < 0 || iErrorId >= iStringIds.Count() )
       
   119         {        
       
   120         User::Leave( KErrArgument);        
       
   121         }    
       
   122         
       
   123     iMessage = aMessage;
       
   124     iNeedToCompleteMessage = ETrue;
       
   125     iReplySlot = aReplySlot;  
       
   126 	  
       
   127     SetActive();
       
   128     iStatus = KRequestPending;
       
   129     TRequestStatus* stat = &iStatus;
       
   130     User::RequestComplete( stat, KErrNone );
       
   131     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::GetParamsL() completed"));
       
   132     }
       
   133 
       
   134 // ----------------------------------------------------------------------------
       
   135 // CUsbUiNotifOtgError::RunL
       
   136 // Ask user response and return it to caller.
       
   137 // ----------------------------------------------------------------------------
       
   138 //
       
   139 void CUsbUiNotifOtgError::RunL()
       
   140     {
       
   141     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::RunL"));
       
   142     TInt returnValue = KErrNone;
       
   143 
       
   144     DisableKeylock();
       
   145     SuppressAppSwitching( ETrue );
       
   146 
       
   147     //Excute dialog and check return value
       
   148     returnValue = QueryUserResponseL();
       
   149 
       
   150     SuppressAppSwitching( EFalse );
       
   151     RestoreKeylock();
       
   152     CompleteMessage( returnValue );
       
   153 
       
   154     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::RunL() completed"));
       
   155     }
       
   156 
       
   157 // ----------------------------------------------------------------------------
       
   158 // CUsbUiNotifOtgError::Cancel
       
   159 // Release all own resources (member variables)
       
   160 // ----------------------------------------------------------------------------
       
   161 //
       
   162 void CUsbUiNotifOtgError::Cancel()
       
   163     {
       
   164     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::Cancel"));
       
   165     if (iQuery)
       
   166         {
       
   167         delete iQuery;
       
   168         iQuery = NULL;
       
   169         }
       
   170     CompleteMessage( KErrCancel );
       
   171 
       
   172     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::Cancel() completed"));
       
   173     }
       
   174 
       
   175 // ----------------------------------------------------------------------------
       
   176 // CUsbUiNotifOtgError::QueryUserResponseL
       
   177 // Show query dialog. 
       
   178 // ----------------------------------------------------------------------------
       
   179 //
       
   180 TInt CUsbUiNotifOtgError::QueryUserResponseL()
       
   181     {
       
   182     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::QueryUserResponseL"));
       
   183     TInt returnValue = KErrNone;
       
   184     TInt resourceId = R_USB_QUERY_OTG_ERROR;
       
   185 
       
   186     iQuery = CAknQueryDialog::NewL( CAknQueryDialog::EErrorTone );
       
   187 
       
   188     if (iCoverDisplaySupported)
       
   189         {
       
   190         iQuery->PublishDialogL( iErrorId, KUsbUiNotifOtgError );
       
   191         }
       
   192     HBufC *stringHolder = StringLoader::LoadLC( iStringIds[iErrorId] );
       
   193 
       
   194     TInt keypress = iQuery->ExecuteLD( resourceId, *stringHolder );
       
   195 
       
   196     CleanupStack::PopAndDestroy( stringHolder );
       
   197 
       
   198     iQuery = NULL; // Dialog destroyed
       
   199 
       
   200     returnValue = keypress ? KErrNone : KErrCancel; //OK?
       
   201 
       
   202     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::QueryUserResponseL completed"));
       
   203     return returnValue;
       
   204     }
       
   205 
       
   206 // End of File