usbuis/usbuinotif/src/usbuinqueriesnotifiermdrv.cpp
branchRCL_3
changeset 79 25fce757be94
parent 33 d895b6d953c9
child 80 e02eb84a14d2
equal deleted inserted replaced
77:5b2a402e96ac 79:25fce757be94
    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 <secondarydisplay/usbuinotifsecondarydisplay.h>     // Dialog index for cover UI
       
    29 
       
    30 #include "usbuinqueriesnotifiermdrv.h"      // Own class definition
    23 #include "usbuinqueriesnotifiermdrv.h"      // Own class definition
    31 #include "usbuinotifdebug.h"                // Debugging macros
    24 #include "usbuinotifdebug.h"                // Debugging macros
    32 
    25 
    33 // ================= MEMBER FUNCTIONS =========================================
    26 // ================= MEMBER FUNCTIONS =========================================
    34 
    27 
    83         // in cableconnected notifier
    76         // in cableconnected notifier
    84     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RegisterL completed"));
    77     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RegisterL completed"));
    85     return iInfo;
    78     return iInfo;
    86     }
    79     }
    87 
    80 
    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     }
       
   117 
    81 
   118 // ----------------------------------------------------------------------------
    82 // ----------------------------------------------------------------------------
   119 // CUSBUIQueriesNotifier::GetParamsL
    83 // CUSBUIQueriesNotifier::GetParamsL
   120 //  Jump to RunL as soon as possible.
    84 // ----------------------------------------------------------------------------
   121 // ----------------------------------------------------------------------------
    85 //
   122 //
    86 void CUSBUIQueriesNotifier::StartDialogL(const TDesC8& aBuffer,
   123 void CUSBUIQueriesNotifier::GetParamsL(const TDesC8& aBuffer,
       
   124         TInt aReplySlot, const RMessagePtr2& aMessage)
    87         TInt aReplySlot, const RMessagePtr2& aMessage)
   125     {
    88     {
   126     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetParamsL"));
    89     FLOG(_L("[USBUINOTIF]\t  CUSBUIQueriesNotifier::StartDialogL"));
   127     if (iUSBQueryDlg || iReplySlot != 0 || iNeedToCompleteMessage)
    90     if ( iReplySlot != 0 || iNeedToCompleteMessage)
   128         {
    91         {
   129         User::Leave( KErrInUse );
    92         User::Leave( KErrInUse );
   130         }
    93         }
       
    94         
       
    95     InitializeTextResolver();
   131 
    96 
   132     iMessage = aMessage;
    97     iMessage = aMessage;
   133     iNeedToCompleteMessage = ETrue;
    98     iNeedToCompleteMessage = ETrue;
   134     iReplySlot = aReplySlot;
    99     iReplySlot = aReplySlot;
   135 
   100 
   139     TPckgC<TUSBQueriesNotiferParams> pckg( params );
   104     TPckgC<TUSBQueriesNotiferParams> pckg( params );
   140     pckg.Set( aBuffer );
   105     pckg.Set( aBuffer );
   141     // Save the type of the query for later use (dialog selection)
   106     // Save the type of the query for later use (dialog selection)
   142     //
   107     //
   143     iQueryType = pckg().iQuery;
   108     iQueryType = pckg().iQuery;
   144     if (iQueryType == EUSBNoMemoryCard)
   109          
   145         {
   110     if (iUSBQueryDlg)
   146         iNeedToCompleteMessage = EFalse;
   111         {
   147         }
   112         delete iUSBQueryDlg;
   148     // Call SetActive() so RunL() will be called by the active scheduler
   113         iUSBQueryDlg = NULL;
   149     //
   114         }
   150     SetActive();
   115     iUSBQueryDlg = CHbDeviceMessageBoxSymbian::NewL(
   151     iStatus = KRequestPending;
   116                        CHbDeviceMessageBoxSymbian::EWarning, this);
   152     TRequestStatus* stat = &iStatus;
   117     iUSBQueryDlg->SetTimeout(0);
   153     User::RequestComplete( stat, KErrNone );
   118     HBufC* stringHolder = NULL;
   154     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::GetParamsL() completed"));
   119     switch (iQueryType)
   155     }
   120             {
   156 
   121             case EUSBStorageMediaFailure:
   157 // ----------------------------------------------------------------------------
   122                 {
   158 // CUSBUIQueriesNotifier::RunL
   123                 _LIT(KMassStorageFail, "txt_usb_info_unable_to_show_a_memory_to_other_devi");
   159 // Ask user response and return it to caller.
   124                 stringHolder = HbTextResolverSymbian::LoadLC( KMassStorageFail );
   160 // ----------------------------------------------------------------------------
   125                  break;
   161 //
   126                 }
   162 void CUSBUIQueriesNotifier::RunL()
   127             case EUSBDiskFull:
   163     {
   128                 {
   164     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::RunL"));
   129                 _LIT(KDiskFull, "txt_usb_info_disk_full_remove_some_files_and_try");
   165 
   130                 stringHolder = HbTextResolverSymbian::LoadLC( KDiskFull );
   166     TBool isCancelKey = EFalse;
   131 		         break;
   167     TBool isErrorQuery = EFalse;
   132                 }
   168     TInt returnValue = KErrNone;
   133             case EUSBNotEnoughRam:
   169     // for cover display support
   134                 {
   170     TInt coverDialogId = EUSBCoverInvalidDialogId;
   135                 _LIT(KNotEnoughMemory, "txt_usb_info_memory_full_close_some_applications");
   171 
   136                  stringHolder = HbTextResolverSymbian::LoadLC( KNotEnoughMemory );
   172     // Choose text and other query attributes
   137                  break;
   173     //
   138                 }
   174     HBufC* stringHolder = GetQueryAttributesLC( coverDialogId, isCancelKey, isErrorQuery );
   139             default:
   175 
   140                 {
   176     //check if query text string loading was successful
   141                 FTRACE( FPrint( _L( "[USBUINOTIF]\t CUSBUIQueriesNotifier::ERROR! Unknown query type: %d" ),iQueryType ) );
   177     if (NULL != stringHolder)
   142                 }
   178         {
   143             }
   179         DisableKeylock();
   144    
   180         SuppressAppSwitching( ETrue );
   145     if (stringHolder)
   181         returnValue = QueryUserResponseL( *stringHolder, coverDialogId,
   146         {
   182                 isCancelKey, isErrorQuery );
   147         iUSBQueryDlg->SetTextL(*stringHolder);
   183         SuppressAppSwitching( EFalse );
   148         }
   184         RestoreKeylock();
   149         
   185         CleanupStack::PopAndDestroy( stringHolder );
   150     iUSBQueryDlg->ShowL();
   186         }
   151     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartDialogL() ShowL returned"));     
   187     else
   152     
   188         {
   153     CleanupStack::PopAndDestroy( stringHolder );
   189         returnValue = KErrUnknown;
   154     
   190         }
   155     
   191 
   156     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::StartDialogL completed"));
   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     }
   157     }
   198 
   158 
   199 // ----------------------------------------------------------------------------
   159 // ----------------------------------------------------------------------------
   200 // CUSBUIQueriesNotifier::Cancel
   160 // CUSBUIQueriesNotifier::Cancel
   201 // Release all own resources (member variables)
   161 // Release all own resources (member variables)
   204 void CUSBUIQueriesNotifier::Cancel()
   164 void CUSBUIQueriesNotifier::Cancel()
   205     {
   165     {
   206     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel"));
   166     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel"));
   207     if (iUSBQueryDlg)
   167     if (iUSBQueryDlg)
   208         {
   168         {
       
   169         iUSBQueryDlg->Close();
   209         delete iUSBQueryDlg;
   170         delete iUSBQueryDlg;
   210         iUSBQueryDlg = NULL;
   171         iUSBQueryDlg = NULL;
   211         }
   172         }
   212     CompleteMessage( KErrCancel );
   173  
   213 
       
   214     CUSBUINotifierBase::Cancel();
   174     CUSBUINotifierBase::Cancel();
   215     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel() completed"));
   175     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::Cancel() completed"));
   216     }
   176     }
   217 
   177 
   218 // ----------------------------------------------------------------------------
   178 
   219 // CUSBUIQueriesNotifier::QueryUserResponseL
   179 void CUSBUIQueriesNotifier::MessageBoxClosed(
   220 // Show query dialog. 
   180         const CHbDeviceMessageBoxSymbian* /*aMessageBox*/,
   221 // ----------------------------------------------------------------------------
   181         CHbDeviceMessageBoxSymbian::TButtonId aButton)
   222 //
   182     {
   223 TInt CUSBUIQueriesNotifier::QueryUserResponseL(const TDesC& aStringHolder,
   183     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed"));
   224         TInt aCoverDialogId, TBool aIsCancelKey, TBool aIsErrorQuery)
   184     int returnValue = KErrNone;
   225     {
   185     
   226     FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL"));
   186     //iQuery will be deleted in Cancel. If Cancel is not called, it will be
   227     TInt returnValue = KErrNone;
   187     //deleted next time the query is shown. 
   228 
   188 
   229     iUSBQueryDlg = CAknQueryDialog::NewL( CAknQueryDialog::EConfirmationTone );
   189     if (aButton == CHbDeviceMessageBoxSymbian::EAcceptButton) 
   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
       
   261         {
   190         {
   262         returnValue = KErrNone;
   191         returnValue = KErrNone;
   263             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL keypress"));
   192         } 
   264         }
   193     else 
   265     else
       
   266         {
   194         {
   267         returnValue = KErrCancel;
   195         returnValue = KErrCancel;
   268             FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL NO keypress"));
   196         }
   269         }
   197 
   270 
   198     CompleteMessage( returnValue );
   271         FLOG(_L("[USBUINOTIF]\t CUSBUIQueriesNotifier::QueryUserResponseL completed"));
   199     
   272     return returnValue;
   200     FLOG(_L("[USBUINOTIF]\t CUsbUiNotifMSMMError::MessageBoxClosed completed"));    
   273     }
   201     }
   274 
   202 
   275 // ----------------------------------------------------------------------------
   203 
   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     }
       
   338 
   204 
   339 // End of File
   205 // End of File