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