usbuis/usbuinotif/src/usbuinqueriesnotifiermdrv.cpp
branchRCL_3
changeset 80 e02eb84a14d2
parent 79 25fce757be94
equal deleted inserted replaced
79:25fce757be94 80:e02eb84a14d2
    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 
    19 #include <eikenv.h>          // Eikon environment
    20 #include <hb/hbwidgets/hbdevicemessageboxsymbian.h>
    20 #include <bautils.h>         // BAFL utils (for language file)
    21 #include <hb/hbcore/hbtextresolversymbian.h>
    21 #include <utf.h>             // Unicode character conversion utilities
       
    22 #include <StringLoader.h>    // Localisation stringloader
       
    23 #include <AknQueryDialog.h> 
       
    24 #include <aknnotewrappers.h>
       
    25 
    22 #include <usbuinotif.h>                     // pck
    26 #include <usbuinotif.h>                     // pck
       
    27 #include <usbuinotif.rsg>                   // Own resources
       
    28 #include <secondarydisplay/usbuinotifsecondarydisplay.h>     // Dialog index for cover UI
       
    29 
    23 #include "usbuinqueriesnotifiermdrv.h"      // Own class definition
    30 #include "usbuinqueriesnotifiermdrv.h"      // Own class definition
    24 #include "usbuinotifdebug.h"                // Debugging macros
    31 #include "usbuinotifdebug.h"                // Debugging macros
    25 
    32 
    26 // ================= MEMBER FUNCTIONS =========================================
    33 // ================= MEMBER FUNCTIONS =========================================
    27 
    34 
    76         // in cableconnected notifier
    83         // in cableconnected notifier
    77     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RegisterL completed"));
    84     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RegisterL completed"));
    78     return iInfo;
    85     return iInfo;
    79     }
    86     }
    80 
    87 
       
    88 // ----------------------------------------------------------------------------
       
    89 // CUSBUIQueriesNotifier::StartL
       
    90 // Synchronic notifier launch. 
       
    91 // ----------------------------------------------------------------------------
       
    92 //
       
    93 TPtrC8 CUSBUIQueriesNotifier::StartL(const TDesC8& aBuffer)
       
    94     {
       
    95     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartL()"));
       
    96 
       
    97     TUSBQueriesNotiferParams params; //stores parameters from aBuffef
       
    98     TPckgC<TUSBQueriesNotiferParams> pckg( params );
       
    99     pckg.Set( aBuffer );
       
   100     // Save the type of the query for later use (dialog selection)
       
   101     //
       
   102 
       
   103     if (pckg().iQuery == EUSBNoMemoryCard)
       
   104         {
       
   105         TRAPD( err, GetParamsL( aBuffer, 0, iMessage ));
       
   106         if (err)
       
   107             {
       
   108             iNeedToCompleteMessage = EFalse;
       
   109             User::Leave( err );
       
   110             }
       
   111         }
       
   112 
       
   113     TPtrC8 ret( KNullDesC8 );
       
   114     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartL() completed"));
       
   115     return (ret);
       
   116     }
    81 
   117 
    82 // ----------------------------------------------------------------------------
   118 // ----------------------------------------------------------------------------
    83 // CUSBUIQueriesNotifier::GetParamsL
   119 // CUSBUIQueriesNotifier::GetParamsL
    84 // ----------------------------------------------------------------------------
   120 //  Jump to RunL as soon as possible.
    85 //
   121 // ----------------------------------------------------------------------------
    86 void CUSBUIQueriesNotifier::StartDialogL(const TDesC8& aBuffer,
   122 //
       
   123 void CUSBUIQueriesNotifier::GetParamsL(const TDesC8& aBuffer,
    87         TInt aReplySlot, const RMessagePtr2& aMessage)
   124         TInt aReplySlot, const RMessagePtr2& aMessage)
    88     {
   125     {
    89     FLOG(_L("[USBUINOTIF]\t  CUSBUIQueriesNotifier::StartDialogL"));
   126     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetParamsL"));
    90     if ( iReplySlot != 0 || iNeedToCompleteMessage)
   127     if (iUSBQueryDlg || iReplySlot != 0 || iNeedToCompleteMessage)
    91         {
   128         {
    92         User::Leave( KErrInUse );
   129         User::Leave( KErrInUse );
    93         }
   130         }
    94         
       
    95     InitializeTextResolver();
       
    96 
   131 
    97     iMessage = aMessage;
   132     iMessage = aMessage;
    98     iNeedToCompleteMessage = ETrue;
   133     iNeedToCompleteMessage = ETrue;
    99     iReplySlot = aReplySlot;
   134     iReplySlot = aReplySlot;
   100 
   135 
   104     TPckgC<TUSBQueriesNotiferParams> pckg( params );
   139     TPckgC<TUSBQueriesNotiferParams> pckg( params );
   105     pckg.Set( aBuffer );
   140     pckg.Set( aBuffer );
   106     // Save the type of the query for later use (dialog selection)
   141     // Save the type of the query for later use (dialog selection)
   107     //
   142     //
   108     iQueryType = pckg().iQuery;
   143     iQueryType = pckg().iQuery;
   109          
   144     if (iQueryType == EUSBNoMemoryCard)
       
   145         {
       
   146         iNeedToCompleteMessage = EFalse;
       
   147         }
       
   148     // Call SetActive() so RunL() will be called by the active scheduler
       
   149     //
       
   150     SetActive();
       
   151     iStatus = KRequestPending;
       
   152     TRequestStatus* stat = &iStatus;
       
   153     User::RequestComplete( stat, KErrNone );
       
   154     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetParamsL() completed"));
       
   155     }
       
   156 
       
   157 // ----------------------------------------------------------------------------
       
   158 // CUSBUIQueriesNotifier::RunL
       
   159 // Ask user response and return it to caller.
       
   160 // ----------------------------------------------------------------------------
       
   161 //
       
   162 void CUSBUIQueriesNotifier::RunL()
       
   163     {
       
   164     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RunL"));
       
   165 
       
   166     TBool isCancelKey = EFalse;
       
   167     TBool isErrorQuery = EFalse;
       
   168     TInt returnValue = KErrNone;
       
   169     // for cover display support
       
   170     TInt coverDialogId = EUSBCoverInvalidDialogId;
       
   171 
       
   172     // Choose text and other query attributes
       
   173     //
       
   174     HBufC* stringHolder = GetQueryAttributesLC( coverDialogId, isCancelKey, isErrorQuery );
       
   175 
       
   176     //check if query text string loading was successful
       
   177     if (NULL != stringHolder)
       
   178         {
       
   179         DisableKeylock();
       
   180         SuppressAppSwitching( ETrue );
       
   181         returnValue = QueryUserResponseL( *stringHolder, coverDialogId,
       
   182                 isCancelKey, isErrorQuery );
       
   183         SuppressAppSwitching( EFalse );
       
   184         RestoreKeylock();
       
   185         CleanupStack::PopAndDestroy( stringHolder );
       
   186         }
       
   187     else
       
   188         {
       
   189         returnValue = KErrUnknown;
       
   190         }
       
   191 
       
   192     CompleteMessage( returnValue );
       
   193     // cancelling the notifier so that next one on the queue can be displayed.
       
   194     // it may be that the client calls cancel too, but it is ok
       
   195     iManager->CancelNotifier( iInfo.iUid );
       
   196     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RunL() completed"));
       
   197     }
       
   198 
       
   199 // ----------------------------------------------------------------------------
       
   200 // CUSBUIQueriesNotifier::Cancel
       
   201 // Release all own resources (member variables)
       
   202 // ----------------------------------------------------------------------------
       
   203 //
       
   204 void CUSBUIQueriesNotifier::Cancel()
       
   205     {
       
   206     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel"));
   110     if (iUSBQueryDlg)
   207     if (iUSBQueryDlg)
   111         {
   208         {
   112         delete iUSBQueryDlg;
   209         delete iUSBQueryDlg;
   113         iUSBQueryDlg = NULL;
   210         iUSBQueryDlg = NULL;
   114         }
   211         }
   115     iUSBQueryDlg = CHbDeviceMessageBoxSymbian::NewL(
   212     CompleteMessage( KErrCancel );
   116                        CHbDeviceMessageBoxSymbian::EWarning, this);
   213 
   117     iUSBQueryDlg->SetTimeout(0);
       
   118     HBufC* stringHolder = NULL;
       
   119     switch (iQueryType)
       
   120             {
       
   121             case EUSBStorageMediaFailure:
       
   122                 {
       
   123                 _LIT(KMassStorageFail, "txt_usb_info_unable_to_show_a_memory_to_other_devi");
       
   124                 stringHolder = HbTextResolverSymbian::LoadLC( KMassStorageFail );
       
   125                  break;
       
   126                 }
       
   127             case EUSBDiskFull:
       
   128                 {
       
   129                 _LIT(KDiskFull, "txt_usb_info_disk_full_remove_some_files_and_try");
       
   130                 stringHolder = HbTextResolverSymbian::LoadLC( KDiskFull );
       
   131 		         break;
       
   132                 }
       
   133             case EUSBNotEnoughRam:
       
   134                 {
       
   135                 _LIT(KNotEnoughMemory, "txt_usb_info_memory_full_close_some_applications");
       
   136                  stringHolder = HbTextResolverSymbian::LoadLC( KNotEnoughMemory );
       
   137                  break;
       
   138                 }
       
   139             default:
       
   140                 {
       
   141                 FTRACE( FPrint( _L( "[USBUINOTIF]\t CUSBUIQueriesNotifier::ERROR! Unknown query type: %d" ),iQueryType ) );
       
   142                 }
       
   143             }
       
   144    
       
   145     if (stringHolder)
       
   146         {
       
   147         iUSBQueryDlg->SetTextL(*stringHolder);
       
   148         }
       
   149         
       
   150     iUSBQueryDlg->ShowL();
       
   151     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartDialogL() ShowL returned"));     
       
   152     
       
   153     CleanupStack::PopAndDestroy( stringHolder );
       
   154     
       
   155     
       
   156     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartDialogL completed"));
       
   157     }
       
   158 
       
   159 // ----------------------------------------------------------------------------
       
   160 // CUSBUIQueriesNotifier::Cancel
       
   161 // Release all own resources (member variables)
       
   162 // ----------------------------------------------------------------------------
       
   163 //
       
   164 void CUSBUIQueriesNotifier::Cancel()
       
   165     {
       
   166     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel"));
       
   167     if (iUSBQueryDlg)
       
   168         {
       
   169         iUSBQueryDlg->Close();
       
   170         delete iUSBQueryDlg;
       
   171         iUSBQueryDlg = NULL;
       
   172         }
       
   173  
       
   174     CUSBUINotifierBase::Cancel();
   214     CUSBUINotifierBase::Cancel();
   175     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel() completed"));
   215     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel() completed"));
   176     }
   216     }
   177 
   217 
   178 
   218 // ----------------------------------------------------------------------------
   179 void CUSBUIQueriesNotifier::MessageBoxClosed(
   219 // CUSBUIQueriesNotifier::QueryUserResponseL
   180         const CHbDeviceMessageBoxSymbian* /*aMessageBox*/,
   220 // Show query dialog. 
   181         CHbDeviceMessageBoxSymbian::TButtonId aButton)
   221 // ----------------------------------------------------------------------------
   182     {
   222 //
   183     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed"));
   223 TInt CUSBUIQueriesNotifier::QueryUserResponseL(const TDesC& aStringHolder,
   184     int returnValue = KErrNone;
   224         TInt aCoverDialogId, TBool aIsCancelKey, TBool aIsErrorQuery)
   185     
   225     {
   186     //iQuery will be deleted in Cancel. If Cancel is not called, it will be
   226     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL"));
   187     //deleted next time the query is shown. 
   227     TInt returnValue = KErrNone;
   188 
   228 
   189     if (aButton == CHbDeviceMessageBoxSymbian::EAcceptButton) 
   229     iUSBQueryDlg = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
       
   230 
       
   231     // Show dialog with or without the Cancel
       
   232     //
       
   233     if (aIsErrorQuery) 
       
   234         {
       
   235         // aIsErrorQuery flag is set in GetQueryAttributesLC()
       
   236         // there is no defined QueryDialogError in resources so QueryOTGerror is used (contains Stop icon)
       
   237         iUSBQueryDlg->PrepareLC( R_USB_QUERY_OTG_ERROR );
       
   238         }
       
   239     else if (aIsCancelKey)
       
   240         {
       
   241         iUSBQueryDlg->PrepareLC( R_USB_QUERY_WITH_CANCEL );
       
   242         }
       
   243     else
       
   244         {
       
   245         iUSBQueryDlg->PrepareLC( R_USB_QUERY_WITHOUT_CANCEL );
       
   246         }
       
   247 
       
   248     if (iCoverDisplaySupported)
       
   249         {
       
   250         iUSBQueryDlg->PublishDialogL( aCoverDialogId, KUSBUINotifCategory );
       
   251         }
       
   252 
       
   253     iUSBQueryDlg->SetPromptL( aStringHolder );
       
   254     iUSBQueryDlg->SetFocus( ETrue );
       
   255         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL calling RunLD"));
       
   256     TInt keypress = iUSBQueryDlg->RunLD();
       
   257 
       
   258     iUSBQueryDlg = NULL;
       
   259 
       
   260     if (keypress) // User has accepted the dialog
   190         {
   261         {
   191         returnValue = KErrNone;
   262         returnValue = KErrNone;
   192         } 
   263             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL keypress"));
   193     else 
   264         }
       
   265     else
   194         {
   266         {
   195         returnValue = KErrCancel;
   267         returnValue = KErrCancel;
   196         }
   268             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL NO keypress"));
   197 
   269         }
   198     CompleteMessage( returnValue );
   270 
   199     
   271         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL completed"));
   200     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed completed"));    
   272     return returnValue;
   201     }
   273     }
   202 
   274 
   203 
   275 // ----------------------------------------------------------------------------
       
   276 // CUSBUIQueriesNotifier::GetQueryAttributesLC
       
   277 // Get query text and the other attributes for the query dialog. 
       
   278 // ----------------------------------------------------------------------------
       
   279 //
       
   280 HBufC* CUSBUIQueriesNotifier::GetQueryAttributesLC(TInt& aCoverDialogId,
       
   281         TBool& aIsCancelKey, TBool& aIsErrorQuery)
       
   282     {
       
   283     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetQueryAttributesLC"));
       
   284     HBufC* stringHolder = NULL; // The text for the query
       
   285     aIsCancelKey = EFalse;
       
   286     aIsErrorQuery = EFalse;
       
   287     switch (iQueryType)
       
   288         {
       
   289         case EUSBStorageMediaFailure:
       
   290             {
       
   291             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBStorageMediaFailure"));
       
   292             stringHolder = StringLoader::LoadLC( R_USB_STORAGE_MEDIA_FAILURE );
       
   293             aCoverDialogId = EUSBCoverStorageMediaFailure;
       
   294             break;
       
   295             }
       
   296         case EUSBChangeFromMassStorage:
       
   297             {
       
   298             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBChangeFromMassStorage"));
       
   299             stringHolder = StringLoader::LoadLC( 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         case EUSBDiskFull:
       
   321           	{
       
   322             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::EUSBDiskFull"));
       
   323             stringHolder = StringLoader::LoadLC( R_USB_ERROR_DISK_FULL );
       
   324             aCoverDialogId = EUSBCoverNoMemoryCard;
       
   325             //set flag to change the icon of querydialog (see QueryUserResponseL())
       
   326             aIsErrorQuery = ETrue;
       
   327             break;
       
   328             }
       
   329         default:
       
   330             {
       
   331             FTRACE( FPrint( _L( "[USBUINOTIF]\t CUSBUIQueriesNotifier::ERROR! Unknown query type: %d" ),
       
   332                             iQueryType ) );
       
   333             }
       
   334         }
       
   335     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetQueryAttributesLC completed"));
       
   336     return stringHolder;
       
   337     }
   204 
   338 
   205 // End of File
   339 // End of File