usbuis/usbuinotif/src/usbuinotifotgerror.cpp
branchRCL_3
changeset 79 25fce757be94
parent 33 d895b6d953c9
child 80 e02eb84a14d2
equal deleted inserted replaced
77:5b2a402e96ac 79:25fce757be94
     1 /*
     1 /*
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007, 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <eikenv.h>          // Eikon environment
    20 #include <hb/hbwidgets/hbdevicemessageboxsymbian.h>      // dialog
    21 #include <bautils.h>         // BAFL utils (for language file)
    21 #include <hb/hbcore/hbtextresolversymbian.h>
    22 #include <utf.h>             // Unicode character conversion utilities
       
    23 #include <StringLoader.h>    // Localisation stringloader
       
    24 #include <AknQueryDialog.h> 
       
    25 #include <aknnotewrappers.h>
       
    26 #include <featmgr.h>
       
    27 
       
    28 #include <usbuinotif.h>                     // pck
    22 #include <usbuinotif.h>                     // pck
    29 #include <usbuinotif.rsg>                   // Own resources
       
    30 #include <secondarydisplay/usbuinotifsecondarydisplay.h> // Dialog index for cover UI
       
    31 
       
    32 #include "usbuinotifotgerror.h"             // Own class definition
    23 #include "usbuinotifotgerror.h"             // Own class definition
    33 #include "usbuinotifdebug.h"                // Debugging macros
    24 #include "usbuinotifdebug.h"                // Debugging macros
       
    25 
       
    26 // CONSTANTS
       
    27 /** granularity for allocating error strings */
       
    28 const TInt KUsbOtgErrorGranularity = 7; 
    34 
    29 
    35 
    30 
    36 // ================= MEMBER FUNCTIONS =========================================
    31 // ================= MEMBER FUNCTIONS =========================================
    37 
    32 
    38 // ----------------------------------------------------------------------------
    33 // ----------------------------------------------------------------------------
    54 // C++ default constructor can NOT contain any code, that
    49 // C++ default constructor can NOT contain any code, that
    55 // might leave.
    50 // might leave.
    56 // ----------------------------------------------------------------------------
    51 // ----------------------------------------------------------------------------
    57 //
    52 //
    58 CUsbUiNotifOtgError::CUsbUiNotifOtgError() :
    53 CUsbUiNotifOtgError::CUsbUiNotifOtgError() :
    59     iStringIds( KUsbUiNotifOtgGeneralQueryGranularity)
    54     iStringIds(NULL)
    60     {
    55     {
    61     }
    56     }
    62 
    57 
    63 // ----------------------------------------------------------------------------
    58 // ----------------------------------------------------------------------------
    64 // Destructor
    59 // Destructor
    67 CUsbUiNotifOtgError::~CUsbUiNotifOtgError()
    62 CUsbUiNotifOtgError::~CUsbUiNotifOtgError()
    68     {
    63     {
    69     //Make sure that the request is completed. Note that inside the destructor,
    64     //Make sure that the request is completed. Note that inside the destructor,
    70     //this virtual function call is to local CUsbUiNotifOtgError::Cancel, 
    65     //this virtual function call is to local CUsbUiNotifOtgError::Cancel, 
    71     //not to any possibly derived class implementation. 
    66     //not to any possibly derived class implementation. 
       
    67     delete iStringIds;
    72     Cancel();
    68     Cancel();
    73     delete iDialerWatcher;    
       
    74     delete iQuery;    
       
    75     }
    69     }
    76 
    70 
    77 void CUsbUiNotifOtgError::ConstructL()
    71 void CUsbUiNotifOtgError::ConstructL()
    78     {
    72     {
    79     CUSBUINotifierBase::ConstructL();
    73     CUSBUINotifierBase::ConstructL();
    80     iStringIds.AppendL( R_USB_OTG_ERROR_CURRENT_LIMIT);
    74     iStringIds = new (ELeave) CDesCArrayFlat(KUsbOtgErrorGranularity);
    81     iStringIds.AppendL( R_USB_OTG_ERROR_TOO_MUCH_CURRENT_REQUIRED);
    75     _LIT(KCurrentLimit, "txt_usb_info_error_in_usb_connection_disconnect_d");
    82     iStringIds.AppendL( R_USB_OTG_ERROR_UNSUPPORTED);
    76     _LIT(KTooMuchCurrent, "txt_usb_info_unsupported_usb_device_disconnect_de");
    83     iStringIds.AppendL( R_USB_OTG_ERROR_HUB_UNSUPPORTED);
    77     _LIT(KUnsupported, "txt_usb_info_unsupported_usb_device_disconnect_de");
    84     iStringIds.AppendL( R_USB_OTG_ERROR_UNRECOVERABLE);
    78     _LIT(KHubUnsupported, "txt_usb_info_hubs_are_not_supported_disconnect_us");
    85     iStringIds.AppendL( R_USB_OTG_ERROR_ATTACH_TIMEDOUT);
    79     _LIT(KUnRecoverable, "txt_usb_info_error_in_usb_connection_disconnect_d");
    86     iStringIds.AppendL( R_USB_ERROR_MEMORY_NOT_ENOUGH);
    80     _LIT(KAttachTimeOut, "txt_usb_info_remove_usb_cable_or_connect_a_device");
       
    81     _LIT(KNotEnoughMemory, "txt_usb_info_memory_full_close_some_applications");
       
    82     iStringIds->AppendL( KCurrentLimit);
       
    83     iStringIds->AppendL( KTooMuchCurrent);
       
    84     iStringIds->AppendL( KUnsupported);
       
    85     iStringIds->AppendL( KHubUnsupported);
       
    86     iStringIds->AppendL( KUnRecoverable);
       
    87     iStringIds->AppendL( KAttachTimeOut);
       
    88     iStringIds->AppendL( KNotEnoughMemory);
       
    89    
    87     }
    90     }
    88 
    91 
    89 // ----------------------------------------------------------------------------
    92 // ----------------------------------------------------------------------------
    90 // CUsbUiNotifOtgError::RegisterL
    93 // CUsbUiNotifOtgError::RegisterL
    91 // Register notifier.
    94 // Register notifier.
   102 // ----------------------------------------------------------------------------
   105 // ----------------------------------------------------------------------------
   103 // CUsbUiNotifOtgError::GetParamsL
   106 // CUsbUiNotifOtgError::GetParamsL
   104 //  Jump to RunL as soon as possible.
   107 //  Jump to RunL as soon as possible.
   105 // ----------------------------------------------------------------------------
   108 // ----------------------------------------------------------------------------
   106 //
   109 //
   107 void CUsbUiNotifOtgError::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot,
   110 void CUsbUiNotifOtgError::StartDialogL(const TDesC8& aBuffer, TInt aReplySlot,
   108         const RMessagePtr2& aMessage)
   111         const RMessagePtr2& aMessage)
   109     {
   112     {
   110     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::GetParamsL"));
   113     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::StartDialogL"));
   111     if (iQuery || iReplySlot != 0 || iNeedToCompleteMessage)
   114     if (iReplySlot != 0 || iNeedToCompleteMessage)
   112         {
   115         {
   113         User::Leave( KErrInUse );
   116         User::Leave( KErrInUse );
   114         }
   117         }
   115         
   118   
   116     // Get parameters 
   119     InitializeTextResolver();
   117     //
   120     
   118     
   121     TInt errorId = 0;
   119     TPckgC<TInt> pckg( iErrorId );
   122     TPckgC<TInt> pckg( errorId );
   120     pckg.Set( aBuffer );
   123     pckg.Set( aBuffer );
   121     iErrorId = pckg();
   124     errorId = pckg();
   122     
   125     
   123     FTRACE(FPrint(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::GetParamsL iErrorId: %d"), iErrorId ));  
   126     FTRACE(FPrint(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::GetParamsL iErrorId: %d"), errorId ));  
   124     if ( iErrorId < 0 || iErrorId >= iStringIds.Count() )
   127     if ( errorId < 0 || errorId >= iStringIds->MdcaCount())
   125         {        
   128         {        
   126         User::Leave( KErrArgument);        
   129         User::Leave( KErrArgument);        
   127         }    
   130         }    
   128         
       
   129     iMessage = aMessage;
   131     iMessage = aMessage;
   130     iNeedToCompleteMessage = ETrue;
   132     iNeedToCompleteMessage = ETrue;
   131     iReplySlot = aReplySlot;  
   133     iReplySlot = aReplySlot;
   132 	  
   134    
   133     SetActive();
   135     if (iQuery)
   134     iStatus = KRequestPending;
   136             {
   135     TRequestStatus* stat = &iStatus;
   137             delete iQuery;
   136     User::RequestComplete( stat, KErrNone );    
   138             iQuery = NULL;
       
   139             }
   137         
   140         
   138     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::GetParamsL() completed"));
   141         iQuery = CHbDeviceMessageBoxSymbian::NewL(
   139     }
   142                 CHbDeviceMessageBoxSymbian::EWarning, this);
   140 
   143         iQuery->SetTimeout(0);
   141 // ----------------------------------------------------------------------------
   144         HBufC* stringHolder = HbTextResolverSymbian::LoadLC(iStringIds->MdcaPoint(errorId) );
   142 // CUsbUiNotifOtgError::RunL
   145         iQuery->SetTextL(*stringHolder);
   143 // Ask user response and return it to caller.
   146         iQuery->ShowL();
   144 // ----------------------------------------------------------------------------
   147         CleanupStack::PopAndDestroy( stringHolder );
   145 //
   148             
   146 void CUsbUiNotifOtgError::RunL()
   149     
   147     {
   150     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::StartDialogL completed"));
   148     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::RunL"));
       
   149     TInt returnValue = KErrNone;
       
   150     FeatureManager::InitializeLibL();
       
   151     if ( FeatureManager::FeatureSupported( KFeatureIdFfKeypadNoSendKey ) )
       
   152         {    
       
   153         if (!iDialerWatcher)
       
   154             {
       
   155             iDialerWatcher = CUsbuinotifDialerWatcher::NewL(this);
       
   156             }
       
   157         }        
       
   158     FeatureManager::UnInitializeLib(); 
       
   159     iDismissed=EFalse;
       
   160     DisableKeylock();
       
   161     SuppressAppSwitching( ETrue );
       
   162 
       
   163     //Excute dialog and check return value
       
   164     returnValue = QueryUserResponseL();
       
   165     if (!iDismissed)
       
   166         {
       
   167         SuppressAppSwitching( EFalse );
       
   168         RestoreKeylock();
       
   169         delete iDialerWatcher;
       
   170         iDialerWatcher = NULL;
       
   171         CompleteMessage( returnValue );
       
   172         }
       
   173 
       
   174     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::RunL() completed"));
       
   175     }
   151     }
   176 
   152 
   177 // ----------------------------------------------------------------------------
   153 // ----------------------------------------------------------------------------
   178 // CUsbUiNotifOtgError::Cancel
   154 // CUsbUiNotifOtgError::Cancel
   179 // Release all own resources (member variables)
   155 // Release all own resources (member variables)
   180 // ----------------------------------------------------------------------------
   156 // ----------------------------------------------------------------------------
   181 //
   157 //
   182 void CUsbUiNotifOtgError::Cancel()
   158 void CUsbUiNotifOtgError::Cancel()
   183     {
   159     {
   184     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::Cancel"));    
   160     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::Cancel"));
   185     
       
   186     // If dialog is not dismissed this is normal cancel and if query
       
   187     // doesn't exsist notifier is canceled during dismission
       
   188     if (!iDismissed || !iQuery )
       
   189         {        
       
   190         delete iDialerWatcher;
       
   191         iDialerWatcher = NULL;
       
   192         CompleteMessage( KErrCancel );
       
   193         }        
       
   194     if (iQuery)
   161     if (iQuery)
   195         {
   162         {
       
   163         iQuery->Close();
   196         delete iQuery;
   164         delete iQuery;
   197         iQuery = NULL;
   165         iQuery = NULL;
   198         }
   166         }
       
   167     CUSBUINotifierBase::Cancel();
       
   168 
   199     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::Cancel() completed"));
   169     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::Cancel() completed"));
   200     }
   170     }
   201 
   171 // ----------------------------------------------------------------------------
   202 // ----------------------------------------------------------------------------
   172 // Call back function to observe device message box closing.
   203 // CUsbUiNotifOtgError::DialerActivated
   173 // ----------------------------------------------------------------------------
   204 // Release all own resources (member variables)
   174 //
   205 // ----------------------------------------------------------------------------
   175 void CUsbUiNotifOtgError::MessageBoxClosed(
   206 //
   176         const CHbDeviceMessageBoxSymbian* /*aMessageBox*/,
   207 void CUsbUiNotifOtgError::DialerActivated()
   177         CHbDeviceMessageBoxSymbian::TButtonId aButton)
   208     {
   178     {
   209     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::AppKeyPressed()"));
   179     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed"));
   210     if ( iQuery )
   180     int returnValue = KErrNone;
   211         {
   181     
   212         iDismissed=ETrue;    
   182     //iQuery will be deleted in Cancel. If Cancel is not called, it will be
   213         Cancel();
   183     //deleted next time the query is shown. 
   214         }    
   184 
   215     }
   185     if (aButton == CHbDeviceMessageBoxSymbian::EAcceptButton) 
   216 
   186         {
   217 // ----------------------------------------------------------------------------
   187         returnValue = KErrNone;
   218 // CUsbUiNotifOtgError::ReActivateDialog
   188         } 
   219 // Release all own resources (member variables)
   189     else 
   220 // ----------------------------------------------------------------------------
   190         {
   221 //   
   191         returnValue = KErrCancel;
   222 void CUsbUiNotifOtgError::ReActivateDialog()
       
   223     {    
       
   224     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ReActivateDialog()"));
       
   225     if ( !IsActive())
       
   226         {
       
   227         SetActive();
       
   228         iStatus = KRequestPending;
       
   229         TRequestStatus* stat = &iStatus;
       
   230         User::RequestComplete( stat, KErrNone );
       
   231         }
   192         }
   232     }
   193 
   233 
   194     CompleteMessage( returnValue );
   234 // ----------------------------------------------------------------------------
   195     
   235 // CUsbUiNotifOtgError::QueryUserResponseL
   196     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed completed"));    
   236 // Show query dialog. 
   197     }
   237 // ----------------------------------------------------------------------------
   198 
   238 //
       
   239 TInt CUsbUiNotifOtgError::QueryUserResponseL()
       
   240     {
       
   241     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::QueryUserResponseL"));
       
   242     TInt returnValue = KErrNone;
       
   243     TInt resourceId = R_USB_QUERY_OTG_ERROR;
       
   244     if (iDismissed)
       
   245         {
       
   246         iQuery = CAknQueryDialog::NewL();
       
   247         }
       
   248     else
       
   249         {
       
   250         iQuery = CAknQueryDialog::NewL( CAknQueryDialog::EErrorTone );
       
   251         }
       
   252     
       
   253     
       
   254     iDismissed=EFalse;
       
   255     if (iCoverDisplaySupported)
       
   256         {
       
   257         iQuery->PublishDialogL( iErrorId, KUsbUiNotifOtgError );
       
   258         }
       
   259     HBufC *stringHolder = StringLoader::LoadLC( iStringIds[iErrorId] );
       
   260 
       
   261     TInt keypress = iQuery->ExecuteLD( resourceId, *stringHolder );
       
   262 
       
   263     CleanupStack::PopAndDestroy( stringHolder );
       
   264 
       
   265     iQuery = NULL; // Dialog destroyed
       
   266 
       
   267     returnValue = keypress ? KErrNone : KErrCancel; //OK?
       
   268 
       
   269     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifOtgError::QueryUserResponseL completed"));
       
   270     return returnValue;
       
   271     }
       
   272 
   199 
   273 // End of File
   200 // End of File