usbuis/usbuinotif/src/usbuinqueriesnotifiermdrv.cpp
branchGCC_SURGE
changeset 63 ef2686f7597e
parent 25 8c311f9acc5e
parent 38 218231f2b3b3
equal deleted inserted replaced
40:e84fb4c9218b 63:ef2686f7597e
     1 /*
     1 /*
     2  * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies).
     3  * All rights reserved.
     3  * All rights reserved.
     4  * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5  * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6  * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14  * Description:  USB UI queries notifier class.
    14  * Description:  USB UI queries notifier class.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 // INCLUDE FILES
    18 // INCLUDE FILES
    19 #include <eikenv.h>          // Eikon environment
    19 
    20 #include <bautils.h>         // BAFL utils (for language file)
    20 #include <hb/hbwidgets/hbdevicemessageboxsymbian.h>
    21 #include <utf.h>             // Unicode character conversion utilities
    21 #include <hb/hbcore/hbtextresolversymbian.h>
    22 #include <StringLoader.h>    // Localisation stringloader
       
    23 #include <AknQueryDialog.h> 
       
    24 #include <aknnotewrappers.h>
       
    25 
       
    26 #include <usbuinotif.h>                     // pck
    22 #include <usbuinotif.h>                     // pck
    27 #include <usbuinotif.rsg>                   // Own resources
       
    28 #include "usbuinqueriesnotifiermdrv.h"      // Own class definition
    23 #include "usbuinqueriesnotifiermdrv.h"      // Own class definition
    29 #include "usbuinotifdebug.h"                // Debugging macros
    24 #include "usbuinotifdebug.h"                // Debugging macros
    30 #include <SecondaryDisplay/usbuinotifsecondarydisplay.h>     // Dialog index for cover UI
       
    31 
    25 
    32 // ================= MEMBER FUNCTIONS =========================================
    26 // ================= MEMBER FUNCTIONS =========================================
    33 
    27 
    34 // ----------------------------------------------------------------------------
    28 // ----------------------------------------------------------------------------
    35 // CUSBUIQueriesNotifier::NewL
    29 // CUSBUIQueriesNotifier::NewL
    82         // in cableconnected notifier
    76         // in cableconnected notifier
    83     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RegisterL completed"));
    77     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RegisterL completed"));
    84     return iInfo;
    78     return iInfo;
    85     }
    79     }
    86 
    80 
    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 
    81 
   117 // ----------------------------------------------------------------------------
    82 // ----------------------------------------------------------------------------
   118 // CUSBUIQueriesNotifier::GetParamsL
    83 // CUSBUIQueriesNotifier::GetParamsL
   119 //  Jump to RunL as soon as possible.
    84 // ----------------------------------------------------------------------------
   120 // ----------------------------------------------------------------------------
    85 //
   121 //
    86 void CUSBUIQueriesNotifier::StartDialogL(const TDesC8& aBuffer,
   122 void CUSBUIQueriesNotifier::GetParamsL(const TDesC8& aBuffer,
       
   123         TInt aReplySlot, const RMessagePtr2& aMessage)
    87         TInt aReplySlot, const RMessagePtr2& aMessage)
   124     {
    88     {
   125     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetParamsL"));
    89     FLOG(_L("[USBUINOTIF]\t  CUSBUIQueriesNotifier::StartDialogL"));
   126     if (iUSBQueryDlg || iReplySlot != 0 || iNeedToCompleteMessage)
    90     if ( iReplySlot != 0 || iNeedToCompleteMessage)
   127         {
    91         {
   128         User::Leave( KErrInUse );
    92         User::Leave( KErrInUse );
   129         }
    93         }
       
    94         
       
    95     InitializeTextResolver();
   130 
    96 
   131     iMessage = aMessage;
    97     iMessage = aMessage;
   132     iNeedToCompleteMessage = ETrue;
    98     iNeedToCompleteMessage = ETrue;
   133     iReplySlot = aReplySlot;
    99     iReplySlot = aReplySlot;
   134 
   100 
   138     TPckgC<TUSBQueriesNotiferParams> pckg( params );
   104     TPckgC<TUSBQueriesNotiferParams> pckg( params );
   139     pckg.Set( aBuffer );
   105     pckg.Set( aBuffer );
   140     // Save the type of the query for later use (dialog selection)
   106     // Save the type of the query for later use (dialog selection)
   141     //
   107     //
   142     iQueryType = pckg().iQuery;
   108     iQueryType = pckg().iQuery;
   143     if (iQueryType == EUSBNoMemoryCard)
   109          
   144         {
   110     if (iUSBQueryDlg)
   145         iNeedToCompleteMessage = EFalse;
   111         {
   146         }
   112         delete iUSBQueryDlg;
   147     // Call SetActive() so RunL() will be called by the active scheduler
   113         iUSBQueryDlg = NULL;
   148     //
   114         }
   149     SetActive();
   115     iUSBQueryDlg = CHbDeviceMessageBoxSymbian::NewL(
   150     iStatus = KRequestPending;
   116                        CHbDeviceMessageBoxSymbian::EWarning, this);
   151     TRequestStatus* stat = &iStatus;
   117     iUSBQueryDlg->SetTimeout(0);
   152     User::RequestComplete( stat, KErrNone );
   118     HBufC* stringHolder = NULL;
   153     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetParamsL() completed"));
   119     switch (iQueryType)
   154     }
   120             {
   155 
   121             case EUSBStorageMediaFailure:
   156 // ----------------------------------------------------------------------------
   122                 {
   157 // CUSBUIQueriesNotifier::RunL
   123                 _LIT(KMassStorageFail, "txt_usb_info_unable_to_show_a_memory_to_other_devi");
   158 // Ask user response and return it to caller.
   124                 stringHolder = HbTextResolverSymbian::LoadLC( KMassStorageFail );
   159 // ----------------------------------------------------------------------------
   125                  break;
   160 //
   126                 }
   161 void CUSBUIQueriesNotifier::RunL()
   127             case EUSBDiskFull:
   162     {
   128                 {
   163     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RunL"));
   129                 _LIT(KDiskFull, "txt_usb_info_disk_full_remove_some_files_and_try");
   164 
   130                 stringHolder = HbTextResolverSymbian::LoadLC( KDiskFull );
   165     TBool isCancelKey = EFalse;
   131 		         break;
   166     TBool isErrorQuery = EFalse;
   132                 }
   167     TInt returnValue = KErrNone;
   133             case EUSBNotEnoughRam:
   168     // for cover display support
   134                 {
   169     TInt coverDialogId = EUSBCoverInvalidDialogId;
   135                 _LIT(KNotEnoughMemory, "txt_usb_info_memory_full_close_some_applications");
   170 
   136                  stringHolder = HbTextResolverSymbian::LoadLC( KNotEnoughMemory );
   171     // Choose text and other query attributes
   137                  break;
   172     //
   138                 }
   173     HBufC* stringHolder = GetQueryAttributesLC( coverDialogId, isCancelKey, isErrorQuery );
   139             default:
   174 
   140                 {
   175     //check if query text string loading was successful
   141                 FTRACE( FPrint( _L( "[USBUINOTIF]\t CUSBUIQueriesNotifier::ERROR! Unknown query type: %d" ),iQueryType ) );
   176     if (NULL != stringHolder)
   142                 }
   177         {
   143             }
   178         DisableKeylock();
   144    
   179         SuppressAppSwitching( ETrue );
   145     if (stringHolder)
   180         returnValue = QueryUserResponseL( *stringHolder, coverDialogId,
   146         {
   181                 isCancelKey, isErrorQuery );
   147         iUSBQueryDlg->SetTextL(*stringHolder);
   182         SuppressAppSwitching( EFalse );
   148         }
   183         RestoreKeylock();
   149         
   184         CleanupStack::PopAndDestroy( stringHolder );
   150     iUSBQueryDlg->ShowL();
   185         }
   151     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartDialogL() ShowL returned"));     
   186     else
   152     
   187         {
   153     CleanupStack::PopAndDestroy( stringHolder );
   188         returnValue = KErrUnknown;
   154     
   189         }
   155     
   190 
   156     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartDialogL completed"));
   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     }
   157     }
   197 
   158 
   198 // ----------------------------------------------------------------------------
   159 // ----------------------------------------------------------------------------
   199 // CUSBUIQueriesNotifier::Cancel
   160 // CUSBUIQueriesNotifier::Cancel
   200 // Release all own resources (member variables)
   161 // Release all own resources (member variables)
   203 void CUSBUIQueriesNotifier::Cancel()
   164 void CUSBUIQueriesNotifier::Cancel()
   204     {
   165     {
   205     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel"));
   166     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel"));
   206     if (iUSBQueryDlg)
   167     if (iUSBQueryDlg)
   207         {
   168         {
       
   169         iUSBQueryDlg->Close();
   208         delete iUSBQueryDlg;
   170         delete iUSBQueryDlg;
   209         iUSBQueryDlg = NULL;
   171         iUSBQueryDlg = NULL;
   210         }
   172         }
   211     CompleteMessage( KErrCancel );
   173  
   212 
       
   213     CUSBUINotifierBase::Cancel();
   174     CUSBUINotifierBase::Cancel();
   214     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel() completed"));
   175     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel() completed"));
   215     }
   176     }
   216 
   177 
   217 // ----------------------------------------------------------------------------
   178 
   218 // CUSBUIQueriesNotifier::QueryUserResponseL
   179 void CUSBUIQueriesNotifier::MessageBoxClosed(
   219 // Show query dialog. 
   180         const CHbDeviceMessageBoxSymbian* /*aMessageBox*/,
   220 // ----------------------------------------------------------------------------
   181         CHbDeviceMessageBoxSymbian::TButtonId aButton)
   221 //
   182     {
   222 TInt CUSBUIQueriesNotifier::QueryUserResponseL(const TDesC& aStringHolder,
   183     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed"));
   223         TInt aCoverDialogId, TBool aIsCancelKey, TBool aIsErrorQuery)
   184     int returnValue = KErrNone;
   224     {
   185     
   225     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL"));
   186     //iQuery will be deleted in Cancel. If Cancel is not called, it will be
   226     TInt returnValue = KErrNone;
   187     //deleted next time the query is shown. 
   227 
   188 
   228     iUSBQueryDlg = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
   189     if (aButton == CHbDeviceMessageBoxSymbian::EAcceptButton) 
   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         {
   190         {
   261         returnValue = KErrNone;
   191         returnValue = KErrNone;
   262             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL keypress"));
   192         } 
   263         }
   193     else 
   264     else
       
   265         {
   194         {
   266         returnValue = KErrCancel;
   195         returnValue = KErrCancel;
   267             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL NO keypress"));
   196         }
   268         }
   197 
   269 
   198     CompleteMessage( returnValue );
   270         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL completed"));
   199     
   271     return returnValue;
   200     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed completed"));    
   272     }
   201     }
   273 
   202 
   274 // ----------------------------------------------------------------------------
   203 
   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 
   204 
   331 // End of File
   205 // End of File