usbuis/usbuinotif/src/usbuinotifmsmmerror.cpp
branchRCL_3
changeset 80 e02eb84a14d2
parent 79 25fce757be94
--- a/usbuis/usbuinotif/src/usbuinotifmsmmerror.cpp	Tue Aug 31 16:13:57 2010 +0300
+++ b/usbuis/usbuinotif/src/usbuinotifmsmmerror.cpp	Wed Sep 01 12:20:49 2010 +0100
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2007 - 2010 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -11,25 +11,29 @@
 *
 * Contributors:
 *
-* Description:  USB UI MSMM Error notifier class.
+* Description:  USB UI queries notifier class.
  *
 */
 
 
 // INCLUDE FILES
-#include <hb/hbwidgets/hbdevicemessageboxsymbian.h>      // dialog
-#include <hb/hbwidgets/hbdevicenotificationdialogsymbian.h> //discreet
-#include <hb/hbcore/hbtextresolversymbian.h>
-#include <usb/hostms/srverr.h>
+#include <eikenv.h>          // Eikon environment
+#include <bautils.h>         // BAFL utils (for language file)
+#include <utf.h>             // Unicode character conversion utilities
+#include <StringLoader.h>    // Localisation stringloader
+#include <AknQueryDialog.h> 
+#include <aknnotewrappers.h>
+#include <usb/hostms/srverr.h> 
+#include <featmgr.h>
+
 #include <usbuinotif.h>                     // pck
+#include <usbuinotif.rsg>                   // Own resources
+#include <secondarydisplay/usbuinotifsecondarydisplay.h> // Dialog index for cover UI
+
 #include "usbuinotifmsmmerror.h"            // Own class definition
 #include "usbuinotifdebug.h"                // Debugging macros
 
 
-// CONSTANTS
-/** granularity for allocating error strings */
-const TInt KUsbMsmmErrorGranularity = 5; 
-_LIT(KUSBUIconFileName, "qtg_large_usb");
 // ================= MEMBER FUNCTIONS =========================================
 
 // ----------------------------------------------------------------------------
@@ -53,7 +57,7 @@
 // ----------------------------------------------------------------------------
 //
 CUsbUiNotifMSMMError::CUsbUiNotifMSMMError() :
-    iStringIds(NULL)
+    iStringIds( KUsbUiNotifOtgGeneralQueryGranularity)
     {
     }
 
@@ -66,25 +70,17 @@
     //Make sure that the request is completed. Note that inside the destructor,
     //this virtual function call is to local CUsbUiNotifMSMMError::Cancel, 
     //not to any possibly derived class implementation. 
-    delete iStringIds;
     Cancel();
+    delete iDialerWatcher;    
+    delete iQuery;    
     }
 
 void CUsbUiNotifMSMMError::ConstructL()
     {
     CUSBUINotifierBase::ConstructL();
-    iStringIds = new (ELeave) CDesCArrayFlat(KUsbMsmmErrorGranularity);
-    _LIT(KGeneralError,"txt_usb_info_error_in_usb_connection_disconnect_d");
-    _LIT(KUnknownFileSys, "txt_usb_info_unknown_file_system_disconnect_devic");
-    _LIT(KOutOfMemory, "txt_usb_info_disk_full_remove_some_files_and_try");
-    _LIT(KSafeToRemove, "txt_usb_dpinfo_safe_to_remove");
-    _LIT(KUnableToEject,"txt_usb_info_unable_to_eject_the_usb_device_some" );
-    
-    iStringIds->AppendL(KGeneralError);
-    iStringIds->AppendL(KUnknownFileSys);
-    iStringIds->AppendL(KOutOfMemory);
-    iStringIds->AppendL(KSafeToRemove);
-    iStringIds->AppendL(KUnableToEject);
+    iStringIds.AppendL( R_USB_MSMM_ERROR_GENERAL_MASS_STORAGE_ERROR);
+    iStringIds.AppendL( R_USB_MSMM_ERROR_UNKNOWN_FILESYSTEM);
+    iStringIds.AppendL( R_USB_MSMM_ERROR_OUT_OF_MEMORY);  
     }
 
 // ----------------------------------------------------------------------------
@@ -105,89 +101,76 @@
 //  Jump to RunL as soon as possible.
 // ----------------------------------------------------------------------------
 //
-void CUsbUiNotifMSMMError::StartDialogL(const TDesC8& aBuffer, TInt aReplySlot,
+void CUsbUiNotifMSMMError::GetParamsL(const TDesC8& aBuffer, TInt aReplySlot,
         const RMessagePtr2& aMessage)
     {
-    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::StartDialogL"));
-    if (iReplySlot != 0 || iNeedToCompleteMessage)
+    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::GetParamsL"));
+    if (iQuery || iReplySlot != 0 || iNeedToCompleteMessage)
         {
         User::Leave( KErrInUse );
         }
 
-    InitializeTextResolver();
-
     iMessage = aMessage;
     iNeedToCompleteMessage = ETrue;
     iReplySlot = aReplySlot;
-    _LIT(KUsbDisconnected, "txt_usb_dpophead_usb_disconnected");
+
     // Get parameters 
     //    
     THostMsErrData error;
-    TPckgC<THostMsErrData> pckg( error );
+    TPckgC<THostMsErrData> pckg( error);
     pckg.Set( aBuffer );
-    int errorId = EUsbMSMMGeneralError;
     switch (pckg().iError)
         {
         case  EHostMsErrUnknownFileSystem:
-            errorId = EUsbMSMMUnknownFileSystem;
+            iErrorId = EUsbMSMMUnknownFileSystem;
             break;        
         case  EHostMsErrOutOfMemory:
-            errorId = EUsbMSMMOutOfMemory;
-            break;       
-        case EHostMsErrNone:
-            errorId = EUsbMSMMSafeToRemove;
-            break;
-        case EHostMsErrInUse:
-            errorId = EUsbMSMMUnableToEject;
-            break;
+            iErrorId = EUsbMSMMOutOfMemory;
+            break;        
         default:
-            errorId = EUsbMSMMGeneralError;
+            iErrorId = EUsbMSMMGeneralError;
         }
-    HBufC* stringHolder = HbTextResolverSymbian::LoadLC(iStringIds->MdcaPoint(errorId)); 
-   
-   
-    if ( errorId == EUsbMSMMSafeToRemove)
-        {
-        // "safe to remove" discreet popup
-        HBufC* header = HbTextResolverSymbian::LoadLC(KUsbDisconnected);
-        if (iDiscreet)
+
+    SetActive();
+    iStatus = KRequestPending;
+    TRequestStatus* stat = &iStatus;
+    User::RequestComplete( stat, KErrNone );
+    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::GetParamsL() completed"));
+    }
+
+// ----------------------------------------------------------------------------
+// CUsbUiNotifMSMMError::RunL
+// Ask user response and return it to caller.
+// ----------------------------------------------------------------------------
+//
+void CUsbUiNotifMSMMError::RunL()
+    {
+    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::RunL"));
+    TInt returnValue = KErrNone;
+    FeatureManager::InitializeLibL();
+    if ( FeatureManager::FeatureSupported( KFeatureIdFfKeypadNoSendKey ) )
+        { 
+        if (!iDialerWatcher)
             {
-             FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::StartDialogL() deleting previous dialog"));
-             delete iDiscreet;
-             iDiscreet = NULL;
+            iDialerWatcher = CUsbuinotifDialerWatcher::NewL(this);
             }
-        iDiscreet = CHbDeviceNotificationDialogSymbian::NewL(this);
-        iDiscreet->SetTitleL(*header);
-        iDiscreet->SetTextL(*stringHolder);
-        iDiscreet->SetIconNameL(KUSBUIconFileName );
-        iDiscreet->ShowL();
-        CleanupStack::PopAndDestroy( header );   
-        }
-    else
+        }        
+    iDismissed=EFalse;
+    DisableKeylock();
+    SuppressAppSwitching( ETrue );
+
+    //Excute dialog and check return value
+    returnValue = QueryUserResponseL();
+    if (!iDismissed)
         {
-         //Delete the query in case the client didn't cancel the notifier 
-   			 //or close the session after the previous query.
-   
-        if (iQuery)
-            {
-            FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::StartDialogL() deleting previous dialog"));
-            delete iQuery;
-            iQuery = NULL;
-            }
-        
-        iQuery = CHbDeviceMessageBoxSymbian::NewL(
-                CHbDeviceMessageBoxSymbian::EWarning, this);
-        iQuery->SetTimeout(0);
-    
-  
-        iQuery->SetTextL(*stringHolder);
-        iQuery->ShowL();
+        SuppressAppSwitching( EFalse );
+        RestoreKeylock();
+        delete iDialerWatcher;
+        iDialerWatcher = NULL;
+        CompleteMessage( returnValue );
         }
-   
-    CleanupStack::PopAndDestroy( stringHolder );
-   
-        
-    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::StartDialogL() completed"));
+
+    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::RunL() completed"));
     }
 
 // ----------------------------------------------------------------------------
@@ -198,64 +181,92 @@
 void CUsbUiNotifMSMMError::Cancel()
     {
     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel"));
+    // If dialog is not dismissed this is normal cancel and if query
+    // doesn't exsist notifier is canceled during dismission
+    if (!iDismissed || !iQuery )
+        {        
+        delete iDialerWatcher;
+        iDialerWatcher = NULL;
+        CompleteMessage( KErrCancel );
+        }        
     if (iQuery)
         {
-        FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel closing iQuery"));
-        iQuery->Close();
-        FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel iQuery closed"));
         delete iQuery;
-        FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel iQuery deleted"));
         iQuery = NULL;
         }
-    if (iDiscreet)
-        {
-        iDiscreet->Close();
-        delete iDiscreet;
-        iDiscreet = NULL;
-        }
-    CUSBUINotifierBase::Cancel();
+
+
     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::Cancel() completed"));
     }
 
 // ----------------------------------------------------------------------------
-// Call back function to observe device message box closing.
+// CUsbUiNotifOtgError::DialerActivated
+// Release all own resources (member variables)
+// ----------------------------------------------------------------------------
+//
+void CUsbUiNotifMSMMError::DialerActivated()
+    {
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::AppKeyPressed()"));
+    if ( iQuery )
+        {
+        iDismissed=ETrue;    
+        Cancel();
+        }    
+    }
+
+// ----------------------------------------------------------------------------
+// CUsbUiNotifOtgError::ReActivateDialog
+// Release all own resources (member variables)
+// ----------------------------------------------------------------------------
+//	
+void CUsbUiNotifMSMMError::ReActivateDialog()
+    {    
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ReActivateDialog()"));
+    if ( !IsActive())
+        {
+        SetActive();
+        iStatus = KRequestPending;
+        TRequestStatus* stat = &iStatus;
+        User::RequestComplete( stat, KErrNone );
+        }
+    }	
+// ----------------------------------------------------------------------------
+// CUsbUiNotifMSMMError::QueryUserResponseL
+// Show query dialog. 
 // ----------------------------------------------------------------------------
 //
-void CUsbUiNotifMSMMError::MessageBoxClosed(
-        const CHbDeviceMessageBoxSymbian* /*aMessageBox*/,
-        CHbDeviceMessageBoxSymbian::TButtonId aButton)
+TInt CUsbUiNotifMSMMError::QueryUserResponseL()
     {
-    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed"));
-    int returnValue = KErrNone;
+    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::QueryUserResponseL"));
+    TInt returnValue = KErrNone;
+    TInt resourceId = R_USB_QUERY_OTG_ERROR;
+    if (iDismissed)
+        {
+        iQuery = CAknQueryDialog::NewL();
+        }
+    else
+        {
+        iQuery = CAknQueryDialog::NewL( CAknQueryDialog::EErrorTone );
+        }
     
-    //iQuery will be deleted in Cancel. If Cancel is not called, it will be
-    //deleted next time the query is shown. 
+    
+    iDismissed=EFalse;
+    if (iCoverDisplaySupported)
+        {
+        iQuery->PublishDialogL( iErrorId, KUsbUiNotifMsmmError );
+        }
+    HBufC *stringHolder = StringLoader::LoadLC( iStringIds[iErrorId] );
 
-    if (aButton == CHbDeviceMessageBoxSymbian::EAcceptButton) 
-        {
-        returnValue = KErrNone;
-        } 
-    else 
-        {
-        returnValue = KErrCancel;
-        }
+    TInt keypress = iQuery->ExecuteLD( resourceId, *stringHolder );
+
+    CleanupStack::PopAndDestroy( stringHolder );
 
-    CompleteMessage( returnValue );
-    
-    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed completed"));    
+    iQuery = NULL; // Dialog destroyed
+
+    returnValue = keypress ? KErrNone : KErrCancel; //OK?
+
+    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::QueryUserResponseL completed"));
+    return returnValue;
     }
 
-void CUsbUiNotifMSMMError::NotificationDialogActivated(
-     const CHbDeviceNotificationDialogSymbian* /*aDialog*/)
-	{
-       
-	}
-   
-void CUsbUiNotifMSMMError::NotificationDialogClosed(
-        const CHbDeviceNotificationDialogSymbian* /*aDialog*/, TInt /*aCompletionCode*/)
-	{
-    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::NotificationDialogClosed()"));
-    CompleteMessage( KErrCancel ); 
-    FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::NotificationDialogClosed() complete"));
-    }
 // End of File