usbuis/usbuinotif/src/usbuinqueriesnotifiermdrv.cpp
changeset 35 9d8b04ca6939
child 38 218231f2b3b3
equal deleted inserted replaced
34:7858bc6ead78 35:9d8b04ca6939
       
     1 /*
       
     2  * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  USB UI queries notifier class.
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <eikenv.h>          // Eikon environment
       
    20 #include <bautils.h>         // BAFL utils (for language file)
       
    21 #include <utf.h>             // Unicode character conversion utilities
       
    22 #include <StringLoader.h>    // Localisation stringloader
       
    23 #include <AknQueryDialog.h> 
       
    24 #include <aknnotewrappers.h>
       
    25 
       
    26 #include <usbuinotif.h>                     // pck
       
    27 #include <usbuinotif.rsg>                   // Own resources
       
    28 #include "usbuinqueriesnotifiermdrv.h"      // Own class definition
       
    29 #include "usbuinotifdebug.h"                // Debugging macros
       
    30 #include <SecondaryDisplay/usbuinotifsecondarydisplay.h>     // Dialog index for cover UI
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =========================================
       
    33 
       
    34 // ----------------------------------------------------------------------------
       
    35 // CUSBUIQueriesNotifier::NewL
       
    36 // Two-phased constructor.
       
    37 // ----------------------------------------------------------------------------
       
    38 //
       
    39 CUSBUIQueriesNotifier* CUSBUIQueriesNotifier::NewL()
       
    40     {
       
    41         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::NewL"));
       
    42     CUSBUIQueriesNotifier* self = new (ELeave) CUSBUIQueriesNotifier();
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ----------------------------------------------------------------------------
       
    50 // CUSBUIQueriesNotifier::CUSBUIQueriesNotifier
       
    51 // C++ default constructor can NOT contain any code, that
       
    52 // might leave.
       
    53 // ----------------------------------------------------------------------------
       
    54 //
       
    55 CUSBUIQueriesNotifier::CUSBUIQueriesNotifier()
       
    56     {
       
    57     }
       
    58 
       
    59 // ----------------------------------------------------------------------------
       
    60 // Destructor
       
    61 // ----------------------------------------------------------------------------
       
    62 //
       
    63 CUSBUIQueriesNotifier::~CUSBUIQueriesNotifier()
       
    64     {
       
    65     //Make sure that the request is completed. Note that inside the destructor,
       
    66     //this virtual function call is to local CUSBUIQueriesNotifier::Cancel, 
       
    67     //not to any possibly derived class implementation. 
       
    68     Cancel();
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------------------------------
       
    72 // CUSBUIQueriesNotifier::RegisterL
       
    73 // Register notifier.
       
    74 // ----------------------------------------------------------------------------
       
    75 //
       
    76 CUSBUIQueriesNotifier::TNotifierInfo CUSBUIQueriesNotifier::RegisterL()
       
    77     {
       
    78     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RegisterL"));
       
    79     iInfo.iUid = KQueriesNotifier;
       
    80     iInfo.iChannel = KQueriesNotifier;
       
    81     iInfo.iPriority = ENotifierPriorityVHigh; // must be higher than the one 
       
    82         // in cableconnected notifier
       
    83     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RegisterL completed"));
       
    84     return iInfo;
       
    85     }
       
    86 
       
    87 // ----------------------------------------------------------------------------
       
    88 // CUSBUIQueriesNotifier::StartL
       
    89 // Synchronic notifier launch. 
       
    90 // ----------------------------------------------------------------------------
       
    91 //
       
    92 TPtrC8 CUSBUIQueriesNotifier::StartL(const TDesC8& aBuffer)
       
    93     {
       
    94     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartL()"));
       
    95 
       
    96     TUSBQueriesNotiferParams params; //stores parameters from aBuffef
       
    97     TPckgC<TUSBQueriesNotiferParams> pckg( params );
       
    98     pckg.Set( aBuffer );
       
    99     // Save the type of the query for later use (dialog selection)
       
   100     //
       
   101 
       
   102     if (pckg().iQuery == EUSBNoMemoryCard)
       
   103         {
       
   104         TRAPD( err, GetParamsL( aBuffer, 0, iMessage ));
       
   105         if (err)
       
   106             {
       
   107             iNeedToCompleteMessage = EFalse;
       
   108             User::Leave( err );
       
   109             }
       
   110         }
       
   111 
       
   112     TPtrC8 ret( KNullDesC8 );
       
   113     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartL() completed"));
       
   114     return (ret);
       
   115     }
       
   116 
       
   117 // ----------------------------------------------------------------------------
       
   118 // CUSBUIQueriesNotifier::GetParamsL
       
   119 //  Jump to RunL as soon as possible.
       
   120 // ----------------------------------------------------------------------------
       
   121 //
       
   122 void CUSBUIQueriesNotifier::GetParamsL(const TDesC8& aBuffer,
       
   123         TInt aReplySlot, const RMessagePtr2& aMessage)
       
   124     {
       
   125     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetParamsL"));
       
   126     if (iUSBQueryDlg || iReplySlot != 0 || iNeedToCompleteMessage)
       
   127         {
       
   128         User::Leave( KErrInUse );
       
   129         }
       
   130 
       
   131     iMessage = aMessage;
       
   132     iNeedToCompleteMessage = ETrue;
       
   133     iReplySlot = aReplySlot;
       
   134 
       
   135     // Get parameters 
       
   136     //
       
   137     TUSBQueriesNotiferParams params; //stores parameters from aBuffer
       
   138     TPckgC<TUSBQueriesNotiferParams> pckg( params );
       
   139     pckg.Set( aBuffer );
       
   140     // Save the type of the query for later use (dialog selection)
       
   141     //
       
   142     iQueryType = pckg().iQuery;
       
   143     if (iQueryType == EUSBNoMemoryCard)
       
   144         {
       
   145         iNeedToCompleteMessage = EFalse;
       
   146         }
       
   147     // Call SetActive() so RunL() will be called by the active scheduler
       
   148     //
       
   149     SetActive();
       
   150     iStatus = KRequestPending;
       
   151     TRequestStatus* stat = &iStatus;
       
   152     User::RequestComplete( stat, KErrNone );
       
   153     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetParamsL() completed"));
       
   154     }
       
   155 
       
   156 // ----------------------------------------------------------------------------
       
   157 // CUSBUIQueriesNotifier::RunL
       
   158 // Ask user response and return it to caller.
       
   159 // ----------------------------------------------------------------------------
       
   160 //
       
   161 void CUSBUIQueriesNotifier::RunL()
       
   162     {
       
   163     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RunL"));
       
   164 
       
   165     TBool isCancelKey = EFalse;
       
   166     TBool isErrorQuery = EFalse;
       
   167     TInt returnValue = KErrNone;
       
   168     // for cover display support
       
   169     TInt coverDialogId = EUSBCoverInvalidDialogId;
       
   170 
       
   171     // Choose text and other query attributes
       
   172     //
       
   173     HBufC* stringHolder = GetQueryAttributesLC( coverDialogId, isCancelKey, isErrorQuery );
       
   174 
       
   175     //check if query text string loading was successful
       
   176     if (NULL != stringHolder)
       
   177         {
       
   178         DisableKeylock();
       
   179         SuppressAppSwitching( ETrue );
       
   180         returnValue = QueryUserResponseL( *stringHolder, coverDialogId,
       
   181                 isCancelKey, isErrorQuery );
       
   182         SuppressAppSwitching( EFalse );
       
   183         RestoreKeylock();
       
   184         CleanupStack::PopAndDestroy( stringHolder );
       
   185         }
       
   186     else
       
   187         {
       
   188         returnValue = KErrUnknown;
       
   189         }
       
   190 
       
   191     CompleteMessage( returnValue );
       
   192     // cancelling the notifier so that next one on the queue can be displayed.
       
   193     // it may be that the client calls cancel too, but it is ok
       
   194     iManager->CancelNotifier( iInfo.iUid );
       
   195     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RunL() completed"));
       
   196     }
       
   197 
       
   198 // ----------------------------------------------------------------------------
       
   199 // CUSBUIQueriesNotifier::Cancel
       
   200 // Release all own resources (member variables)
       
   201 // ----------------------------------------------------------------------------
       
   202 //
       
   203 void CUSBUIQueriesNotifier::Cancel()
       
   204     {
       
   205     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel"));
       
   206     if (iUSBQueryDlg)
       
   207         {
       
   208         delete iUSBQueryDlg;
       
   209         iUSBQueryDlg = NULL;
       
   210         }
       
   211     CompleteMessage( KErrCancel );
       
   212 
       
   213     CUSBUINotifierBase::Cancel();
       
   214     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel() completed"));
       
   215     }
       
   216 
       
   217 // ----------------------------------------------------------------------------
       
   218 // CUSBUIQueriesNotifier::QueryUserResponseL
       
   219 // Show query dialog. 
       
   220 // ----------------------------------------------------------------------------
       
   221 //
       
   222 TInt CUSBUIQueriesNotifier::QueryUserResponseL(const TDesC& aStringHolder,
       
   223         TInt aCoverDialogId, TBool aIsCancelKey, TBool aIsErrorQuery)
       
   224     {
       
   225     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL"));
       
   226     TInt returnValue = KErrNone;
       
   227 
       
   228     iUSBQueryDlg = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
       
   229 
       
   230     // Show dialog with or without the Cancel
       
   231     //
       
   232     if (aIsErrorQuery) 
       
   233         {
       
   234         // aIsErrorQuery flag is set in GetQueryAttributesLC()
       
   235         // there is no defined QueryDialogError in resources so QueryOTGerror is used (contains Stop icon)
       
   236         iUSBQueryDlg->PrepareLC( R_USB_QUERY_OTG_ERROR );
       
   237         }
       
   238     else if (aIsCancelKey)
       
   239         {
       
   240         iUSBQueryDlg->PrepareLC( R_USB_QUERY_WITH_CANCEL );
       
   241         }
       
   242     else
       
   243         {
       
   244         iUSBQueryDlg->PrepareLC( R_USB_QUERY_WITHOUT_CANCEL );
       
   245         }
       
   246 
       
   247     if (iCoverDisplaySupported)
       
   248         {
       
   249         iUSBQueryDlg->PublishDialogL( aCoverDialogId, KUSBUINotifCategory );
       
   250         }
       
   251 
       
   252     iUSBQueryDlg->SetPromptL( aStringHolder );
       
   253     iUSBQueryDlg->SetFocus( ETrue );
       
   254         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL calling RunLD"));
       
   255     TInt keypress = iUSBQueryDlg->RunLD();
       
   256 
       
   257     iUSBQueryDlg = NULL;
       
   258 
       
   259     if (keypress) // User has accepted the dialog
       
   260         {
       
   261         returnValue = KErrNone;
       
   262             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL keypress"));
       
   263         }
       
   264     else
       
   265         {
       
   266         returnValue = KErrCancel;
       
   267             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL NO keypress"));
       
   268         }
       
   269 
       
   270         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL completed"));
       
   271     return returnValue;
       
   272     }
       
   273 
       
   274 // ----------------------------------------------------------------------------
       
   275 // CUSBUIQueriesNotifier::GetQueryAttributesLC
       
   276 // Get query text and the other attributes for the query dialog. 
       
   277 // ----------------------------------------------------------------------------
       
   278 //
       
   279 HBufC* CUSBUIQueriesNotifier::GetQueryAttributesLC(TInt& aCoverDialogId,
       
   280         TBool& aIsCancelKey, TBool& aIsErrorQuery)
       
   281     {
       
   282     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetQueryAttributesLC"));
       
   283     HBufC* stringHolder = NULL; // The text for the query
       
   284     aIsCancelKey = EFalse;
       
   285     aIsErrorQuery = EFalse;
       
   286     switch (iQueryType)
       
   287         {
       
   288         case EUSBStorageMediaFailure:
       
   289             {
       
   290                 FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBStorageMediaFailure"));
       
   291             stringHolder = StringLoader::LoadLC( R_USB_STORAGE_MEDIA_FAILURE );
       
   292             aCoverDialogId = EUSBCoverStorageMediaFailure;
       
   293             break;
       
   294             }
       
   295         case EUSBChangeFromMassStorage:
       
   296             {
       
   297                 FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBChangeFromMassStorage"));
       
   298             stringHolder = StringLoader::LoadLC(
       
   299                     R_USB_CHANGE_FROM_MASS_STORAGE );
       
   300             aIsCancelKey = ETrue;
       
   301             aCoverDialogId = EUSBCoverChangeFromMassStorage;
       
   302             break;
       
   303             }
       
   304         case EUSBNoMemoryCard:
       
   305             {
       
   306                 FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBNoMemoryCard"));
       
   307             stringHolder = StringLoader::LoadLC( R_USB_NO_MEMORY_CARD );
       
   308             aCoverDialogId = EUSBCoverNoMemoryCard;
       
   309             break;
       
   310             } 
       
   311         case EUSBNotEnoughRam:
       
   312           	{
       
   313             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBNotEnoughRam"));
       
   314             stringHolder = StringLoader::LoadLC( R_USB_ERROR_MEMORY_NOT_ENOUGH );
       
   315             aCoverDialogId = EUSBCoverNoMemoryCard;
       
   316             //set flag to change the icon of querydialog (see QueryUserResponseL())
       
   317             aIsErrorQuery = ETrue;
       
   318             break;
       
   319             }
       
   320         default:
       
   321             {
       
   322                 FTRACE( FPrint(
       
   323                                 _L( "[USBUINOTIF]\t CUSBUIQueriesNotifier::ERROR! Unknown query type: %d" ),
       
   324                                 iQueryType ) );
       
   325             }
       
   326         }
       
   327     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetQueryAttributesLC completed"));
       
   328     return stringHolder;
       
   329     }
       
   330 
       
   331 // End of File