usbuis/usbuinotif/src/usbuinotifmsmmerror.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 - 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".
     9 * Initial Contributors:
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:  USB UI queries notifier class.
    14 * Description:  USB UI MSMM Error notifier class.
    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/hbwidgets/hbdevicenotificationdialogsymbian.h> //discreet
    22 #include <utf.h>             // Unicode character conversion utilities
    22 #include <hb/hbcore/hbtextresolversymbian.h>
    23 #include <StringLoader.h>    // Localisation stringloader
    23 #include <usb/hostms/srverr.h>
    24 #include <AknQueryDialog.h> 
       
    25 #include <aknnotewrappers.h>
       
    26 #include <usb/hostms/srverr.h> 
       
    27 #include <featmgr.h>
       
    28 
       
    29 #include <usbuinotif.h>                     // pck
    24 #include <usbuinotif.h>                     // pck
    30 #include <usbuinotif.rsg>                   // Own resources
       
    31 #include <secondarydisplay/usbuinotifsecondarydisplay.h> // Dialog index for cover UI
       
    32 
       
    33 #include "usbuinotifmsmmerror.h"            // Own class definition
    25 #include "usbuinotifmsmmerror.h"            // Own class definition
    34 #include "usbuinotifdebug.h"                // Debugging macros
    26 #include "usbuinotifdebug.h"                // Debugging macros
    35 
    27 
    36 
    28 
       
    29 // CONSTANTS
       
    30 /** granularity for allocating error strings */
       
    31 const TInt KUsbMsmmErrorGranularity = 5; 
       
    32 _LIT(KUSBUIconFileName, "qtg_large_usb");
    37 // ================= MEMBER FUNCTIONS =========================================
    33 // ================= MEMBER FUNCTIONS =========================================
    38 
    34 
    39 // ----------------------------------------------------------------------------
    35 // ----------------------------------------------------------------------------
    40 // CUsbUiNotifOtgError::NewL
    36 // CUsbUiNotifOtgError::NewL
    41 // Two-phased constructor.
    37 // Two-phased constructor.
    55 // C++ default constructor can NOT contain any code, that
    51 // C++ default constructor can NOT contain any code, that
    56 // might leave.
    52 // might leave.
    57 // ----------------------------------------------------------------------------
    53 // ----------------------------------------------------------------------------
    58 //
    54 //
    59 CUsbUiNotifMSMMError::CUsbUiNotifMSMMError() :
    55 CUsbUiNotifMSMMError::CUsbUiNotifMSMMError() :
    60     iStringIds( KUsbUiNotifOtgGeneralQueryGranularity)
    56     iStringIds(NULL)
    61     {
    57     {
    62     }
    58     }
    63 
    59 
    64 // ----------------------------------------------------------------------------
    60 // ----------------------------------------------------------------------------
    65 // Destructor
    61 // Destructor
    68 CUsbUiNotifMSMMError::~CUsbUiNotifMSMMError()
    64 CUsbUiNotifMSMMError::~CUsbUiNotifMSMMError()
    69     {
    65     {
    70     //Make sure that the request is completed. Note that inside the destructor,
    66     //Make sure that the request is completed. Note that inside the destructor,
    71     //this virtual function call is to local CUsbUiNotifMSMMError::Cancel, 
    67     //this virtual function call is to local CUsbUiNotifMSMMError::Cancel, 
    72     //not to any possibly derived class implementation. 
    68     //not to any possibly derived class implementation. 
       
    69     delete iStringIds;
    73     Cancel();
    70     Cancel();
    74     delete iDialerWatcher;    
       
    75     delete iQuery;    
       
    76     }
    71     }
    77 
    72 
    78 void CUsbUiNotifMSMMError::ConstructL()
    73 void CUsbUiNotifMSMMError::ConstructL()
    79     {
    74     {
    80     CUSBUINotifierBase::ConstructL();
    75     CUSBUINotifierBase::ConstructL();
    81     iStringIds.AppendL( R_USB_MSMM_ERROR_GENERAL_MASS_STORAGE_ERROR);
    76     iStringIds = new (ELeave) CDesCArrayFlat(KUsbMsmmErrorGranularity);
    82     iStringIds.AppendL( R_USB_MSMM_ERROR_UNKNOWN_FILESYSTEM);
    77     _LIT(KGeneralError,"txt_usb_info_error_in_usb_connection_disconnect_d");
    83     iStringIds.AppendL( R_USB_MSMM_ERROR_OUT_OF_MEMORY);  
    78     _LIT(KUnknownFileSys, "txt_usb_info_unknown_file_system_disconnect_devic");
       
    79     _LIT(KOutOfMemory, "txt_usb_info_disk_full_remove_some_files_and_try");
       
    80     _LIT(KSafeToRemove, "txt_usb_dpinfo_safe_to_remove");
       
    81     _LIT(KUnableToEject,"txt_usb_info_unable_to_eject_the_usb_device_some" );
       
    82     
       
    83     iStringIds->AppendL(KGeneralError);
       
    84     iStringIds->AppendL(KUnknownFileSys);
       
    85     iStringIds->AppendL(KOutOfMemory);
       
    86     iStringIds->AppendL(KSafeToRemove);
       
    87     iStringIds->AppendL(KUnableToEject);
    84     }
    88     }
    85 
    89 
    86 // ----------------------------------------------------------------------------
    90 // ----------------------------------------------------------------------------
    87 // CUsbUiNotifMSMMError::RegisterL
    91 // CUsbUiNotifMSMMError::RegisterL
    88 // Register notifier.
    92 // Register notifier.
    99 // ----------------------------------------------------------------------------
   103 // ----------------------------------------------------------------------------
   100 // CUsbUiNotifMSMMError::GetParamsL
   104 // CUsbUiNotifMSMMError::GetParamsL
   101 //  Jump to RunL as soon as possible.
   105 //  Jump to RunL as soon as possible.
   102 // ----------------------------------------------------------------------------
   106 // ----------------------------------------------------------------------------
   103 //
   107 //
   104 void CUsbUiNotifMSMMError::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot,
   108 void CUsbUiNotifMSMMError::StartDialogL(const TDesC8& aBuffer, TInt aReplySlot,
   105         const RMessagePtr2& aMessage)
   109         const RMessagePtr2& aMessage)
   106     {
   110     {
   107     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::GetParamsL"));
   111     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::StartDialogL"));
   108     if (iQuery || iReplySlot != 0 || iNeedToCompleteMessage)
   112     if (iReplySlot != 0 || iNeedToCompleteMessage)
   109         {
   113         {
   110         User::Leave( KErrInUse );
   114         User::Leave( KErrInUse );
   111         }
   115         }
       
   116 
       
   117     InitializeTextResolver();
   112 
   118 
   113     iMessage = aMessage;
   119     iMessage = aMessage;
   114     iNeedToCompleteMessage = ETrue;
   120     iNeedToCompleteMessage = ETrue;
   115     iReplySlot = aReplySlot;
   121     iReplySlot = aReplySlot;
   116 
   122     _LIT(KUsbDisconnected, "txt_usb_dpophead_usb_disconnected");
   117     // Get parameters 
   123     // Get parameters 
   118     //    
   124     //    
   119     THostMsErrData error;
   125     THostMsErrData error;
   120     TPckgC<THostMsErrData> pckg( error);
   126     TPckgC<THostMsErrData> pckg( error );
   121     pckg.Set( aBuffer );
   127     pckg.Set( aBuffer );
       
   128     int errorId = EUsbMSMMGeneralError;
   122     switch (pckg().iError)
   129     switch (pckg().iError)
   123         {
   130         {
   124         case  EHostMsErrUnknownFileSystem:
   131         case  EHostMsErrUnknownFileSystem:
   125             iErrorId = EUsbMSMMUnknownFileSystem;
   132             errorId = EUsbMSMMUnknownFileSystem;
   126             break;        
   133             break;        
   127         case  EHostMsErrOutOfMemory:
   134         case  EHostMsErrOutOfMemory:
   128             iErrorId = EUsbMSMMOutOfMemory;
   135             errorId = EUsbMSMMOutOfMemory;
   129             break;        
   136             break;       
       
   137         case EHostMsErrNone:
       
   138             errorId = EUsbMSMMSafeToRemove;
       
   139             break;
       
   140         case EHostMsErrInUse:
       
   141             errorId = EUsbMSMMUnableToEject;
       
   142             break;
   130         default:
   143         default:
   131             iErrorId = EUsbMSMMGeneralError;
   144             errorId = EUsbMSMMGeneralError;
   132         }
   145         }
   133 
   146     HBufC* stringHolder = HbTextResolverSymbian::LoadLC(iStringIds->MdcaPoint(errorId)); 
   134     SetActive();
   147    
   135     iStatus = KRequestPending;
   148    
   136     TRequestStatus* stat = &iStatus;
   149     if ( errorId == EUsbMSMMSafeToRemove)
   137     User::RequestComplete( stat, KErrNone );
   150         {
   138     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::GetParamsL() completed"));
   151         // "safe to remove" discreet popup
   139     }
   152         HBufC* header = HbTextResolverSymbian::LoadLC(KUsbDisconnected);
   140 
   153         if (iDiscreet)
   141 // ----------------------------------------------------------------------------
       
   142 // CUsbUiNotifMSMMError::RunL
       
   143 // Ask user response and return it to caller.
       
   144 // ----------------------------------------------------------------------------
       
   145 //
       
   146 void CUsbUiNotifMSMMError::RunL()
       
   147     {
       
   148     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::RunL"));
       
   149     TInt returnValue = KErrNone;
       
   150     FeatureManager::InitializeLibL();
       
   151     if ( FeatureManager::FeatureSupported( KFeatureIdFfKeypadNoSendKey ) )
       
   152         { 
       
   153         if (!iDialerWatcher)
       
   154             {
   154             {
   155             iDialerWatcher = CUsbuinotifDialerWatcher::NewL(this);
   155              FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::StartDialogL() deleting previous dialog"));
       
   156              delete iDiscreet;
       
   157              iDiscreet = NULL;
   156             }
   158             }
   157         }        
   159         iDiscreet = CHbDeviceNotificationDialogSymbian::NewL(this);
   158     iDismissed=EFalse;
   160         iDiscreet->SetTitleL(*header);
   159     DisableKeylock();
   161         iDiscreet->SetTextL(*stringHolder);
   160     SuppressAppSwitching( ETrue );
   162         iDiscreet->SetIconNameL(KUSBUIconFileName );
   161 
   163         iDiscreet->ShowL();
   162     //Excute dialog and check return value
   164         CleanupStack::PopAndDestroy( header );   
   163     returnValue = QueryUserResponseL();
   165         }
   164     if (!iDismissed)
   166     else
   165         {
   167         {
   166         SuppressAppSwitching( EFalse );
   168          //Delete the query in case the client didn't cancel the notifier 
   167         RestoreKeylock();
   169    			 //or close the session after the previous query.
   168         delete iDialerWatcher;
   170    
   169         iDialerWatcher = NULL;
   171         if (iQuery)
   170         CompleteMessage( returnValue );
   172             {
   171         }
   173             FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::StartDialogL() deleting previous dialog"));
   172 
   174             delete iQuery;
   173     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::RunL() completed"));
   175             iQuery = NULL;
       
   176             }
       
   177         
       
   178         iQuery = CHbDeviceMessageBoxSymbian::NewL(
       
   179                 CHbDeviceMessageBoxSymbian::EWarning, this);
       
   180         iQuery->SetTimeout(0);
       
   181     
       
   182   
       
   183         iQuery->SetTextL(*stringHolder);
       
   184         iQuery->ShowL();
       
   185         }
       
   186    
       
   187     CleanupStack::PopAndDestroy( stringHolder );
       
   188    
       
   189         
       
   190     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::StartDialogL() completed"));
   174     }
   191     }
   175 
   192 
   176 // ----------------------------------------------------------------------------
   193 // ----------------------------------------------------------------------------
   177 // CUsbUiNotifMSMMError::Cancel
   194 // CUsbUiNotifMSMMError::Cancel
   178 // Release all own resources (member variables)
   195 // Release all own resources (member variables)
   179 // ----------------------------------------------------------------------------
   196 // ----------------------------------------------------------------------------
   180 //
   197 //
   181 void CUsbUiNotifMSMMError::Cancel()
   198 void CUsbUiNotifMSMMError::Cancel()
   182     {
   199     {
   183     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel"));
   200     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel"));
   184     // If dialog is not dismissed this is normal cancel and if query
       
   185     // doesn't exsist notifier is canceled during dismission
       
   186     if (!iDismissed || !iQuery )
       
   187         {        
       
   188         delete iDialerWatcher;
       
   189         iDialerWatcher = NULL;
       
   190         CompleteMessage( KErrCancel );
       
   191         }        
       
   192     if (iQuery)
   201     if (iQuery)
   193         {
   202         {
       
   203         FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel closing iQuery"));
       
   204         iQuery->Close();
       
   205         FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel iQuery closed"));
   194         delete iQuery;
   206         delete iQuery;
       
   207         FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel iQuery deleted"));
   195         iQuery = NULL;
   208         iQuery = NULL;
   196         }
   209         }
   197 
   210     if (iDiscreet)
   198 
   211         {
       
   212         iDiscreet->Close();
       
   213         delete iDiscreet;
       
   214         iDiscreet = NULL;
       
   215         }
       
   216     CUSBUINotifierBase::Cancel();
   199     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel() completed"));
   217     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel() completed"));
   200     }
   218     }
   201 
   219 
   202 // ----------------------------------------------------------------------------
   220 // ----------------------------------------------------------------------------
   203 // CUsbUiNotifOtgError::DialerActivated
   221 // Call back function to observe device message box closing.
   204 // Release all own resources (member variables)
   222 // ----------------------------------------------------------------------------
   205 // ----------------------------------------------------------------------------
   223 //
   206 //
   224 void CUsbUiNotifMSMMError::MessageBoxClosed(
   207 void CUsbUiNotifMSMMError::DialerActivated()
   225         const CHbDeviceMessageBoxSymbian* /*aMessageBox*/,
   208     {
   226         CHbDeviceMessageBoxSymbian::TButtonId aButton)
   209     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::AppKeyPressed()"));
   227     {
   210     if ( iQuery )
   228     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed"));
   211         {
   229     int returnValue = KErrNone;
   212         iDismissed=ETrue;    
   230     
   213         Cancel();
   231     //iQuery will be deleted in Cancel. If Cancel is not called, it will be
   214         }    
   232     //deleted next time the query is shown. 
   215     }
   233 
   216 
   234     if (aButton == CHbDeviceMessageBoxSymbian::EAcceptButton) 
   217 // ----------------------------------------------------------------------------
   235         {
   218 // CUsbUiNotifOtgError::ReActivateDialog
   236         returnValue = KErrNone;
   219 // Release all own resources (member variables)
   237         } 
   220 // ----------------------------------------------------------------------------
   238     else 
   221 //	
   239         {
   222 void CUsbUiNotifMSMMError::ReActivateDialog()
   240         returnValue = KErrCancel;
   223     {    
   241         }
   224     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ReActivateDialog()"));
   242 
   225     if ( !IsActive())
   243     CompleteMessage( returnValue );
   226         {
   244     
   227         SetActive();
   245     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed completed"));    
   228         iStatus = KRequestPending;
   246     }
   229         TRequestStatus* stat = &iStatus;
   247 
   230         User::RequestComplete( stat, KErrNone );
   248 void CUsbUiNotifMSMMError::NotificationDialogActivated(
   231         }
   249      const CHbDeviceNotificationDialogSymbian* /*aDialog*/)
   232     }	
   250 	{
   233 // ----------------------------------------------------------------------------
   251        
   234 // CUsbUiNotifMSMMError::QueryUserResponseL
   252 	}
   235 // Show query dialog. 
   253    
   236 // ----------------------------------------------------------------------------
   254 void CUsbUiNotifMSMMError::NotificationDialogClosed(
   237 //
   255         const CHbDeviceNotificationDialogSymbian* /*aDialog*/, TInt /*aCompletionCode*/)
   238 TInt CUsbUiNotifMSMMError::QueryUserResponseL()
   256 	{
   239     {
   257     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::NotificationDialogClosed()"));
   240     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::QueryUserResponseL"));
   258     CompleteMessage( KErrCancel ); 
   241     TInt returnValue = KErrNone;
   259     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::NotificationDialogClosed() complete"));
   242     TInt resourceId = R_USB_QUERY_OTG_ERROR;
   260     }
   243     if (iDismissed)
       
   244         {
       
   245         iQuery = CAknQueryDialog::NewL();
       
   246         }
       
   247     else
       
   248         {
       
   249         iQuery = CAknQueryDialog::NewL( CAknQueryDialog::EErrorTone );
       
   250         }
       
   251     
       
   252     
       
   253     iDismissed=EFalse;
       
   254     if (iCoverDisplaySupported)
       
   255         {
       
   256         iQuery->PublishDialogL( iErrorId, KUsbUiNotifMsmmError );
       
   257         }
       
   258     HBufC *stringHolder = StringLoader::LoadLC( iStringIds[iErrorId] );
       
   259 
       
   260     TInt keypress = iQuery->ExecuteLD( resourceId, *stringHolder );
       
   261 
       
   262     CleanupStack::PopAndDestroy( stringHolder );
       
   263 
       
   264     iQuery = NULL; // Dialog destroyed
       
   265 
       
   266     returnValue = keypress ? KErrNone : KErrCancel; //OK?
       
   267 
       
   268     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::QueryUserResponseL completed"));
       
   269     return returnValue;
       
   270     }
       
   271 
       
   272 // End of File
   261 // End of File