usbuis/usbuinotif/src/usbnotifier.cpp
branchRCL_3
changeset 80 e02eb84a14d2
parent 79 25fce757be94
--- a/usbuis/usbuinotif/src/usbnotifier.cpp	Tue Aug 31 16:13:57 2010 +0300
+++ b/usbuis/usbuinotif/src/usbnotifier.cpp	Wed Sep 01 12:20:49 2010 +0100
@@ -16,14 +16,18 @@
  */
 
 // INCLUDE FILES
-
+#include <eikenv.h>          // Eikon environment
 #include <bautils.h>         // BAFL utils (for language file)
+#include <StringLoader.h>    // Localisation stringloader
+#include <centralrepository.h> 
+#include <coreapplicationuisdomainpskeys.h>
 #include <data_caging_path_literals.hrh> 
-#include <hb/hbcore/hbtextresolversymbian.h>
+#include <featmgr.h>
+#include <AknNotiferAppServerApplication.h>
 
 #include "usbnotifier.h"     // Own class 
 #include "usbuinotifdebug.h"
-
+#include "aknkeylock.h" //RAknKeyLock
 // CONSTANTS
 
 // ================= MEMBER FUNCTIONS =========================================
@@ -35,9 +39,11 @@
 // itself to the active scheduler stack.
 // ----------------------------------------------------------------------------
 //
-CUSBUINotifierBase::CUSBUINotifierBase() 
+CUSBUINotifierBase::CUSBUINotifierBase() :
+    CActive( EPriorityStandard )
     {
         FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Default constructor()"));
+    CActiveScheduler::Add( this );
     }
 
 // ----------------------------------------------------------------------------
@@ -49,16 +55,27 @@
 void CUSBUINotifierBase::ConstructL()
     {
     iEikEnv = CEikonEnv::Static();
-   
+    iAppsKeyBlocked = EFalse;
+    iKeylockChanged = EFalse;
+
     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL()"));
-        
-    // use TLS as a boolean, set to EFalse
-    TBool initialized = EFalse;
-    TInt error;
-    error = Dll::SetTls((TAny* )initialized); 
-    error = error; // to suppress a compiler warning
-    FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:SetTls returned %d"), error ));       
-   
+    TFileName filename;
+
+    const TDriveNumber KStoreDrive = EDriveZ;
+    TDriveUnit driveUnit( KStoreDrive );
+    TDriveName drive = driveUnit.Name();
+    filename.Insert( 0, drive );
+
+    filename += KDC_RESOURCE_FILES_DIR; // From data_caging_path_literals.hrh
+    filename += KResourceFileName;
+    BaflUtils::NearestLanguageFile( iEikEnv->FsSession(), filename );
+    iResourceFileFlag = iEikEnv->AddResourceFileL( filename );
+
+    FeatureManager::InitializeLibL();
+    iCoverDisplaySupported = FeatureManager::FeatureSupported(
+            KFeatureIdCoverDisplay );
+    FeatureManager::UnInitializeLib();
+
     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::ConstructL() completed"));
     }
 
@@ -73,11 +90,18 @@
     //this virtual function call is to the local CUSBUINotifierBase::Cancel, 
     //not to any possibly derived class implementation. 
     Cancel();
- 
+    iEikEnv->DeleteResourceFile( iResourceFileFlag );
+
     // Complete the RMessage2 if needed
     //
     CompleteMessage( KErrDied );
 
+    // Activate apps -key again (if not previously activated yet)
+    SuppressAppSwitching( EFalse );
+
+    //Don't call RestoreKeylock here. It's up to specific note notfier logic. 
+    //If failed to RestoreKeylock there, it doesn't matter to leave keylock open.
+
     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Destructor completed"));
     }
 
@@ -125,7 +149,7 @@
         const RMessagePtr2& aMessage)
     {
     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::StartL()"));
-    TRAPD( err, StartDialogL( aBuffer, aReplySlot, aMessage ));
+    TRAPD( err, GetParamsL( aBuffer, aReplySlot, aMessage ));
     if (err)
         {
         aMessage.Complete( err );
@@ -143,9 +167,8 @@
 void CUSBUINotifierBase::Cancel()
     {
     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel()"));
-    //The message box closed callback gets not run in subclass cancel calls.
-    CompleteMessage(KErrCancel);
-    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel completed"));
+    CActive::Cancel();
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::Cancel completed()"));
     }
 
 // ----------------------------------------------------------------------------
@@ -160,6 +183,64 @@
     }
 
 // ----------------------------------------------------------------------------
+// CUSBUINotifierBase::DoCancel
+// This method will be called by framework (CActive)
+// if active object is still active.
+// Does nothing here.
+// ----------------------------------------------------------------------------
+//
+void CUSBUINotifierBase::DoCancel()
+    {
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DoCancel()"));
+    }
+
+// ----------------------------------------------------------------------------
+// CUSBUINotifierBase::RunError
+// This method is called if any leaving has been occured
+// during RunL. Optional method for CActive derived objects.
+// ----------------------------------------------------------------------------
+//
+TInt CUSBUINotifierBase::RunError(TInt aError)
+    {
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RunError()"));
+
+    // Activate apps -key again (if not previously activated yet)
+    //
+    SuppressAppSwitching( EFalse );
+
+    // Write error message to caller
+    //
+    CompleteMessage( aError );
+
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RunError() completed"));
+
+    return aError;
+    }
+
+// ----------------------------------------------------------------------------
+// CUSBUINotifierBase::SuppressAppSwitching
+// 
+// ----------------------------------------------------------------------------
+//
+void CUSBUINotifierBase::SuppressAppSwitching(TBool aEnable)
+    {
+    FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() %d"), aEnable));
+
+    if (iAppsKeyBlocked != aEnable)
+        {
+        TInt err = iAknServer.ConnectAndSendAppsKeySuppress( aEnable ); // error is stored only for logging purposes
+        iAppsKeyBlocked = aEnable;
+        FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() ConnectAndSendAppsKeySuppress returned %d"), err ));
+        }
+
+    if (!iAppsKeyBlocked)
+        {
+        iAknServer.Close(); // close the connection once we have re-enabled swithcing
+        }
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::SuppressAppSwitching() completed"));
+    }
+
+// ----------------------------------------------------------------------------
 // CUSBUINotifierBase::CompleteMessage
 // Check if message needs to be completed and complete it. 
 // ----------------------------------------------------------------------------
@@ -176,33 +257,61 @@
     FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::CompleteMessage() completed"));
     }
 
-void CUSBUINotifierBase::InitializeTextResolver()
+// ----------------------------------------------------------------------------
+// CUSBUINotifierBase::DisableKeylock
+// ----------------------------------------------------------------------------
+// Turn off the keyguard if it was on.
+//
+void CUSBUINotifierBase::DisableKeylock()
     {
-    _LIT(KFileName, "usbdialogs_");
-    _LIT(KPath, "z:/resource/qt/translations/");         
-    TInt error = KErrNone;
-        
-    iTranslator = (TBool )Dll::Tls();
-    
-    FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:Tls returned %d"), iTranslator ));    
-    
-    if (!iTranslator)
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock()"));
+    RAknKeylock2 keylock;
+    iKeylockChanged = EFalse;
+    if (KErrNone == keylock.Connect())
         {
-        iTranslator = HbTextResolverSymbian::Init(KFileName, KPath);
-        FTRACE(FPrint(_L("[USBUINOTIF]\t HbTextResolverSymbian::Init returned %d"), iTranslator ));    
-        if (iTranslator)
+        if (keylock.IsKeyLockEnabled()) //Check and save the keylock status
             {
-            error = Dll::SetTls((TAny* )iTranslator);      
+            keylock.DisableWithoutNote();// Unlock
+            iKeylockChanged = ETrue;
             }
-        FTRACE(FPrint(_L("[USBUINOTIF]\t Dll:SetTls returned %d"), error ));    
-        }    
-       
-     error = error;   // to suppress a compiler warning
-     FTRACE( FPrint(
-        _L( "[USBUINOTIF]\t CUSBUINotifierBase::InitializeTextResolver result = %d" ),
-        iTranslator ) );                     
-        
+        keylock.Close();
+        }
+    else
+        {
+        FLOG( _L( "[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock() fail caused by RAknKeylock2::Connect()") );
+        }
+
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::DisableKeylock() completed"));
     }
 
+// ----------------------------------------------------------------------------
+// CUSBUINotifierBase::RestoreKeylock
+// ----------------------------------------------------------------------------
+// Restore the keyguard on.
+//
+void CUSBUINotifierBase::RestoreKeylock()
+    {
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock()"));
+    if (iKeylockChanged)
+        {
+        FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): iKeylockChanged true"));
+        RAknKeylock2 keylock;
+        FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2 initialized"));
+        if (KErrNone == keylock.Connect())
+            {
+            FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::Connect() complete"));
+            keylock.EnableWithoutNote();// Lock back
+            FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::EnableWithoutNote() complete"));
+            keylock.Close();
+            FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock(): RAknKeyLock2::Close() complete"));
+            iKeylockChanged = EFalse;
+            }
+        else
+            {
+            FLOG( _L( "[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock() fail caused by RAknKeylock2::Connect()") );
+            }
+        }
+    FLOG(_L("[USBUINOTIF]\t CUSBUINotifierBase::RestoreKeylock() completed"));
+    }
 
 // End of File