usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp
branchRCL_3
changeset 24 e02eb84a14d2
parent 23 25fce757be94
--- a/usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp	Tue Aug 31 16:13:57 2010 +0300
+++ b/usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp	Wed Sep 01 12:20:49 2010 +0100
@@ -15,25 +15,39 @@
  *
  */
 // INCLUDE FILES
+#include <eikenv.h>          // Eikon environment
+#include <bautils.h>         // BAFL utils (for language file)
+#include <aknlists.h>
+#include <aknPopup.h> 
+#include <StringLoader.h>    // Localisation stringloader
 #include <utf.h>             // Unicode character conversion utilities
-#include <usbman.h>
+#include <AknsUtils.h>
+#include <usb.h>
+#include <usbuinotif.rsg>                   // Own resources
 #include <centralrepository.h> 
 #include <e32property.h>
+//for loading icons USB fork and empty
+#include <AknIconArray.h>
+#include <avkon.mbg>
+#include <AknsConstants.h>
+#include <aknmessagequerydialog.h>
+//for cover display support
+#include <AknMediatorFacade.h>
+#include <secondarydisplay/usbuinotifsecondarydisplay.h> // Dialog index for cover UI
+#include <akndiscreetpopup.h>
 #include <e32uid.h> // KExecutableImageUid
-#include <hb/hbwidgets/hbdevicenotificationdialogsymbian.h>
-#include <hb/hbcore/hbtextresolversymbian.h>
+#include <usbui.mbg>
+
 #include "usbuincableconnectednotifier.h"   // Own class definition
 #include "usbuinotifdebug.h"                // Debugging macros
 #include "UsbWatcherInternalCRKeys.h"
+#include "usbpersonalityids.h"
 #include "usbuinotif.hrh"
 
 // Literals
 
-_LIT(KUSBExe, "USBSettingsApp");
-const TInt KUSBUIUid = 0x2002E70C;
-const TInt KTextIdLength = 40;
-
-_LIT(KUSBUIconFileName, "qtg_large_usb");
+_LIT(KUSBExe, "usbclasschangeui.exe");
+const TInt KUSBUIUid = 0x102068E2;
 
 // ================= MEMBER FUNCTIONS =========================================
 
@@ -60,7 +74,9 @@
 // might leave.
 // ----------------------------------------------------------------------------
 //
-CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier()
+CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier(): 
+    iNoteVisible(EFalse),
+    iNoteTapped(EFalse)
     {
     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::default constructor"));
     }
@@ -76,7 +92,6 @@
     //this virtual function call is to the local CUSBUICableConnectedNotifier::
     //Cancel, not to any possibly derived class implementation. 
     Cancel();
-           
     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed"));
     }
 
@@ -97,44 +112,46 @@
     }
 
 // ----------------------------------------------------------------------------
-// CUSBUICableConnectedNotifier::StartDialogL
+// CUSBUICableConnectedNotifier::GetParamsL
+//  Jump to RunL as soon as possible.
 // ----------------------------------------------------------------------------
 //
-void CUSBUICableConnectedNotifier::StartDialogL(const TDesC8& /*aBuffer*/,
+void CUSBUICableConnectedNotifier::GetParamsL(const TDesC8& /*aBuffer*/,
         TInt aReplySlot, const RMessagePtr2& aMessage)
     {
-    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::StartDialogL"));
+    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetParamsL"));
     if ( iReplySlot != 0 || iNeedToCompleteMessage)
         {
         User::Leave(KErrInUse);
         }
 
-    InitializeTextResolver();
-
     iMessage = aMessage;
     iNeedToCompleteMessage = ETrue;
     iReplySlot = aReplySlot;
-    if (iDialog)
-        {
-        FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::StartDialogL() deleting previous dialog"));
-        delete iDialog;
-        iDialog = NULL;
-        }
-    iDialog = CHbDeviceNotificationDialogSymbian::NewL(this);
-      
-    HBufC* header = NULL;
-    HBufC* description =NULL;   
-    GetPersonalityStringLC(header, description);
-   
-    iDialog->SetTitleL(*header);
-    iDialog->SetTextL(*description);
-    iDialog->SetIconNameL(KUSBUIconFileName );
-    iDialog->EnableTouchActivation(ETrue);
-    iDialog->ShowL();
-    
-    CleanupStack::PopAndDestroy(header);
-    CleanupStack::PopAndDestroy(description);
-    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::StartDialogL completed"));
+
+    // Call SetActive() so RunL() will be called by the active scheduler
+    //
+    iStatus = KRequestPending;
+    TRequestStatus* stat = &iStatus;
+    SetActive();
+    User::RequestComplete(stat, KErrNone);
+    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetParamsL() completed"));
+    }
+
+// ----------------------------------------------------------------------------
+// CUSBUICableConnectedNotifier::RunL
+// Ask user response and return it to caller.
+// ----------------------------------------------------------------------------
+//
+void CUSBUICableConnectedNotifier::RunL()
+    {
+    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunL"));
+    iNoteVisible = ETrue;
+    DisableKeylock();
+    SuppressAppSwitching(ETrue);
+    RunQueryL();
+
+    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunL() completed"));
     }
 
 // ----------------------------------------------------------------------------
@@ -145,72 +162,75 @@
 void CUSBUICableConnectedNotifier::Cancel()
     {
     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() "));
-    if (iDialog)
+    // Not allowed to cancel this one before note is closed.
+    if ( iNoteVisible )
         {
-        iDialog->Close();
-        delete iDialog;
-        iDialog = NULL;
+        iNoteWaiter.Start();    
         }
+        
     CompleteMessage(KErrCancel);
     CUSBUINotifierBase::Cancel();
 
     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() completed"));
     }
 
-// -----------------------------------------------------------------------------------------------------------
+// ----------------------------------------------------------------------------
 // CUSBUICableConnectedNotifier::GetPersonalityStringL
-// Get the strings for the discreet popup dialog
-// -----------------------------------------------------------------------------------------------------------
+// Get the strings for ask on connection message query 
+// ----------------------------------------------------------------------------
 //
-void CUSBUICableConnectedNotifier::GetPersonalityStringLC(
+void CUSBUICableConnectedNotifier::GetPersonalityStringL(
        HBufC*& aHeader,HBufC*& aDescription )
     {
     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL"));
-    _LIT(KFixedPart, "txt_usb_dpinfo_");
-    _LIT(KSpace, " ");
-    _LIT(KUnderline, "_");
-    _LIT(KUsbConnected, "txt_usb_dpophead_usb_connected");
     TInt CurrentPersonalityID = 0; // The ID of current USB mode
     GetCurrentIdL(CurrentPersonalityID);
     RUsb usbman;
     User::LeaveIfError(usbman.Connect());
-    FLOG(_L("[USBUINOTIF]\t usbman connect called"));     
     CleanupClosePushL(usbman);
-    HBufC* description = NULL;
     User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID,
-            description));
-     FLOG(_L("[USBUINOTIF]\t get description called"));  
+            aDescription));
     CleanupStack::PopAndDestroy(&usbman);
-    
-    CleanupStack::PushL(description);
-    TPtr descriptionPtr = description->Des();
-    TInt position = descriptionPtr.Find(KSpace);
-    while (position != KErrNotFound)
-        {
-        descriptionPtr.Replace(position, 1, KUnderline);     
-        position = descriptionPtr.Find(KSpace); 
-        }
-    HBufC* textId = HBufC::NewL( KTextIdLength );
-    CleanupStack::PushL(textId);
-    TPtr textIdPtr = textId->Des();
-    textIdPtr.Append(KFixedPart);
-    textIdPtr.Append(descriptionPtr);  
+   
+    aHeader = StringLoader::LoadL(R_USB_MODE_MSG_HEADER);
 
-    aDescription = HbTextResolverSymbian::LoadL(textIdPtr);
-    CleanupStack::PopAndDestroy(textId);
-    CleanupStack::PopAndDestroy(description);
-    CleanupStack::PushL(aDescription);
-
-    FLOG(_L("[USBUINOTIF]\t get description called"));  
-    aHeader = HbTextResolverSymbian::LoadL(KUsbConnected);
-    FLOG(_L("[USBUINOTIF]\t get header called"));  
- 
-    CleanupStack::PushL(aHeader);
-    
     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed"));
     }
 
 // ----------------------------------------------------------------------------
+// CUSBUICableConnectedNotifier::RunQueryL
+// Run the ask on connection message query
+// ----------------------------------------------------------------------------
+//
+void CUSBUICableConnectedNotifier::RunQueryL()
+    {
+    FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL()"));
+  
+    HBufC* header = NULL;
+    HBufC* description =NULL;
+    GetPersonalityStringL(header, description);
+  
+    CleanupStack::PushL(header);
+    CleanupStack::PushL(description);
+  
+    iNoteVisible = ETrue;
+    CAknDiscreetPopup::ShowGlobalPopupL(
+        *header,
+        *description,
+        KAknsIIDQgnPropUsb,
+        AknIconUtils::AvkonIconFileName(),
+        EMbmAvkonQgn_prop_usb,
+        EMbmAvkonQgn_prop_usb_mask,
+        KAknDiscreetPopupDurationLong,
+        EUSBUICmdDiscreetTapped,
+        (MEikCommandObserver*) this);
+   
+    CleanupStack::PopAndDestroy(description);
+    CleanupStack::PopAndDestroy(header);
+   
+    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL completed"));
+    }
+// ----------------------------------------------------------------------------
 // CUSBUICableConnectedNotifier::GetCurrentIdL
 // get the current personality id
 // ----------------------------------------------------------------------------
@@ -222,53 +242,66 @@
     CRepository* repository = CRepository::NewL(KCRUidUsbWatcher);
     CleanupStack::PushL(repository);
     // Get the current USB mode
-    TInt ret = repository->Get(KUsbWatcherPersonality, aCurrentPersonality);
-    FTRACE( FPrint(
-        _L( "[USBWATCHER]\t CUSBUICableConnectedNotifier::GetCurrentIdL() ret = %d" ),
-        ret ) );    
+    repository->Get(KUsbWatcherPersonality, aCurrentPersonality);
     CleanupStack::PopAndDestroy(repository);
     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed"));
     }
 
-
+// ----------------------------------------------------------------------------
+// CUSBUICableConnectedNotifier::ProcessCommandL()
+// when discreet pop up is tapped the command will be handled here 
+// ----------------------------------------------------------------------------
+//
+void CUSBUICableConnectedNotifier::ProcessCommandL(TInt aCommandId)
+    {
+    FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::ProcessCommandL: %d"), 
+        aCommandId));
+    SuppressAppSwitching(EFalse);
+    
+    switch ( aCommandId )
+        {
+        case EUSBUICmdDiscreetTapped:
+            {
+            TUidType uidtype(KExecutableImageUid, TUid::Null(), TUid::Uid(KUSBUIUid));
+            CreateChosenViewL(KUSBExe(),uidtype);
+            iNoteTapped = ETrue;
+            }
+            //fall through
+        case EAknDiscreetPopupCmdClose:
+            if ( iNoteWaiter.IsStarted() )
+                {
+                iNoteWaiter.AsyncStop();
+                }
+            iNoteVisible = EFalse;
+            CompleteMessage( KErrCancel );
+            break;
+        default:
+            break;
+        }
 
-void CUSBUICableConnectedNotifier::NotificationDialogActivated(
-        const CHbDeviceNotificationDialogSymbian* /*aDialog*/)
-       {
-       
-           FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::NotificationDialogActivated()"));
-           TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),
-                                   TUid::Uid(KUSBUIUid));
-           iDialog->Close();
-           LaunchApplication(KUSBExe(), uidtype);
-         
-       }
-   
-void CUSBUICableConnectedNotifier::NotificationDialogClosed(
-        const CHbDeviceNotificationDialogSymbian* /*aDialog*/, TInt /*aCompletionCode*/)
-       {
-       FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::NotificationDialogClosed()"));
-       CompleteMessage( KErrCancel ); 
-       FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::NotificationDialogClosed() complete"));
+    if (!iNoteTapped)
+        {
+        FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::ProcessCommandL() restore keylock"));
+        RestoreKeylock();
+        }
 
-       }
+    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::ProcessCommandL() completed"));
+    }
+
 // ---------------------------------------------------------------------------
-// CUSBUICableConnectedNotifier::LaunchApplication()
-// launches the application 
+// CUSBUICableConnectedNotifier::CreateChosenViewL()
+// creates the USB UI setting view
 // ---------------------------------------------------------------------------
 //  
-void CUSBUICableConnectedNotifier::LaunchApplication(const TDesC & aProcessName, 
-        const TUidType & aUidType) const
+void CUSBUICableConnectedNotifier::CreateChosenViewL(
+    const TDesC & aProcessName, const TUidType & aUidType) const
     {                 
-    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication()"));
-    RProcess usbUiProcess;                
-    TInt result = usbUiProcess.Create(aProcessName, KNullDesC, aUidType);
-    FTRACE( FPrint(
-        _L( "[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() result = %d" ),
-        result ) );    
+    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() "));
+    RProcess usbUiProcess;
+    User::LeaveIfError(usbUiProcess.Create(aProcessName, KNullDesC, aUidType));
     usbUiProcess.Resume();
-    usbUiProcess.Close();                     
-    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() completed"));             
+    usbUiProcess.Close();
+    FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() "));
     }
 
 // End of File