usbuis/usbuinotif/src/usbuinqueriesnotifiermdrv.cpp
changeset 0 1e05558e2206
child 3 47c263f7e521
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     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     TInt returnValue = KErrNone;
       
   167     // for cover display support
       
   168     TInt coverDialogId = EUSBCoverInvalidDialogId;
       
   169 
       
   170     // Choose text and other query attributes
       
   171     //
       
   172     HBufC* stringHolder = GetQueryAttributesLC( coverDialogId, isCancelKey );
       
   173 
       
   174     //check if query text string loading was successful
       
   175     if (NULL != stringHolder)
       
   176         {
       
   177         DisableKeylock();
       
   178         SuppressAppSwitching( ETrue );
       
   179         returnValue = QueryUserResponseL( *stringHolder, coverDialogId,
       
   180                 isCancelKey );
       
   181         SuppressAppSwitching( EFalse );
       
   182         RestoreKeylock();
       
   183         CleanupStack::PopAndDestroy( stringHolder );
       
   184         }
       
   185     else
       
   186         {
       
   187         returnValue = KErrUnknown;
       
   188         }
       
   189 
       
   190     CompleteMessage( returnValue );
       
   191     // cancelling the notifier so that next one on the queue can be displayed.
       
   192     // it may be that the client calls cancel too, but it is ok
       
   193     iManager->CancelNotifier( iInfo.iUid );
       
   194     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RunL() completed"));
       
   195     }
       
   196 
       
   197 // ----------------------------------------------------------------------------
       
   198 // CUSBUIQueriesNotifier::Cancel
       
   199 // Release all own resources (member variables)
       
   200 // ----------------------------------------------------------------------------
       
   201 //
       
   202 void CUSBUIQueriesNotifier::Cancel()
       
   203     {
       
   204     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel"));
       
   205     if (iUSBQueryDlg)
       
   206         {
       
   207         delete iUSBQueryDlg;
       
   208         iUSBQueryDlg = NULL;
       
   209         }
       
   210     CompleteMessage( KErrCancel );
       
   211 
       
   212     CUSBUINotifierBase::Cancel();
       
   213     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel() completed"));
       
   214     }
       
   215 
       
   216 // ----------------------------------------------------------------------------
       
   217 // CUSBUIQueriesNotifier::QueryUserResponseL
       
   218 // Show query dialog. 
       
   219 // ----------------------------------------------------------------------------
       
   220 //
       
   221 TInt CUSBUIQueriesNotifier::QueryUserResponseL(const TDesC& aStringHolder,
       
   222         TInt aCoverDialogId, TBool aIsCancelKey)
       
   223     {
       
   224     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL"));
       
   225     TInt returnValue = KErrNone;
       
   226 
       
   227     iUSBQueryDlg = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
       
   228 
       
   229     // Show dialog with or without the Cancel
       
   230     //
       
   231     if (aIsCancelKey)
       
   232         {
       
   233         iUSBQueryDlg->PrepareLC( R_USB_QUERY_WITH_CANCEL );
       
   234         }
       
   235     else
       
   236         {
       
   237         iUSBQueryDlg->PrepareLC( R_USB_QUERY_WITHOUT_CANCEL );
       
   238         }
       
   239 
       
   240     if (iCoverDisplaySupported)
       
   241         {
       
   242         iUSBQueryDlg->PublishDialogL( aCoverDialogId, KUSBUINotifCategory );
       
   243         }
       
   244 
       
   245     iUSBQueryDlg->SetPromptL( aStringHolder );
       
   246     iUSBQueryDlg->SetFocus( ETrue );
       
   247         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL calling RunLD"));
       
   248     TInt keypress = iUSBQueryDlg->RunLD();
       
   249 
       
   250     iUSBQueryDlg = NULL;
       
   251 
       
   252     if (keypress) // User has accepted the dialog
       
   253         {
       
   254         returnValue = KErrNone;
       
   255             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL keypress"));
       
   256         }
       
   257     else
       
   258         {
       
   259         returnValue = KErrCancel;
       
   260             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL NO keypress"));
       
   261         }
       
   262 
       
   263         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL completed"));
       
   264     return returnValue;
       
   265     }
       
   266 
       
   267 // ----------------------------------------------------------------------------
       
   268 // CUSBUIQueriesNotifier::GetQueryAttributesLC
       
   269 // Get query text and the other attributes for the query dialog. 
       
   270 // ----------------------------------------------------------------------------
       
   271 //
       
   272 HBufC* CUSBUIQueriesNotifier::GetQueryAttributesLC(TInt& aCoverDialogId,
       
   273         TBool& aIsCancelKey)
       
   274     {
       
   275     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetQueryAttributesLC"));
       
   276     HBufC* stringHolder = NULL; // The text for the query
       
   277     aIsCancelKey = EFalse;
       
   278     switch (iQueryType)
       
   279         {
       
   280         case EUSBStorageMediaFailure:
       
   281             {
       
   282                 FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBStorageMediaFailure"));
       
   283             stringHolder = StringLoader::LoadLC( R_USB_STORAGE_MEDIA_FAILURE );
       
   284             aCoverDialogId = EUSBCoverStorageMediaFailure;
       
   285             break;
       
   286             }
       
   287         case EUSBChangeFromMassStorage:
       
   288             {
       
   289                 FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBChangeFromMassStorage"));
       
   290             stringHolder = StringLoader::LoadLC(
       
   291                     R_USB_CHANGE_FROM_MASS_STORAGE );
       
   292             aIsCancelKey = ETrue;
       
   293             aCoverDialogId = EUSBCoverChangeFromMassStorage;
       
   294             break;
       
   295             }
       
   296         case EUSBNoMemoryCard:
       
   297             {
       
   298                 FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBNoMemoryCard"));
       
   299             stringHolder = StringLoader::LoadLC( R_USB_NO_MEMORY_CARD );
       
   300             aCoverDialogId = EUSBCoverNoMemoryCard;
       
   301             break;
       
   302             }
       
   303         default:
       
   304             {
       
   305                 FTRACE( FPrint(
       
   306                                 _L( "[USBUINOTIF]\t CUSBUIQueriesNotifier::ERROR! Unknown query type: %d" ),
       
   307                                 iQueryType ) );
       
   308             }
       
   309         }
       
   310     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetQueryAttributesLC completed"));
       
   311     return stringHolder;
       
   312     }
       
   313 
       
   314 // End of File