usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp
changeset 43 4712310216c0
parent 3 47c263f7e521
child 44 5323ec7dc425
equal deleted inserted replaced
3:47c263f7e521 43:4712310216c0
    19 #include <bautils.h>         // BAFL utils (for language file)
    19 #include <bautils.h>         // BAFL utils (for language file)
    20 #include <aknlists.h>
    20 #include <aknlists.h>
    21 #include <aknPopup.h> 
    21 #include <aknPopup.h> 
    22 #include <StringLoader.h>    // Localisation stringloader
    22 #include <StringLoader.h>    // Localisation stringloader
    23 #include <utf.h>             // Unicode character conversion utilities
    23 #include <utf.h>             // Unicode character conversion utilities
    24 #include <AknsUtils.h>
    24 #include <usbman.h>
    25 #include <usb.h>
       
    26 #include <usbuinotif.rsg>                   // Own resources
    25 #include <usbuinotif.rsg>                   // Own resources
    27 #include <centralrepository.h> 
    26 #include <centralrepository.h> 
    28 #include <e32property.h>
    27 #include <e32property.h>
    29 //for loading icons USB fork and empty
       
    30 #include <AknIconArray.h>
       
    31 #include <avkon.mbg>
       
    32 #include <AknsConstants.h>
       
    33 #include <aknmessagequerydialog.h>
       
    34 //for cover display support
       
    35 #include <AknMediatorFacade.h>
       
    36 #include <SecondaryDisplay/usbuinotifsecondarydisplay.h> // Dialog index for cover UI
       
    37 #include <akndiscreetpopup.h>
       
    38 #include <e32uid.h> // KExecutableImageUid
    28 #include <e32uid.h> // KExecutableImageUid
    39 #include <usbui.mbg>
       
    40 #include "usbuincableconnectednotifier.h"   // Own class definition
    29 #include "usbuincableconnectednotifier.h"   // Own class definition
    41 #include "usbuinotifdebug.h"                // Debugging macros
    30 #include "usbuinotifdebug.h"                // Debugging macros
    42 #include "UsbWatcherInternalCRKeys.h"
    31 #include "UsbWatcherInternalCRKeys.h"
    43 #include "usbpersonalityids.h"
       
    44 #include "usbuinotif.hrh"
    32 #include "usbuinotif.hrh"
    45 
    33 
    46 // Literals
    34 // Literals
    47 
    35 
    48 _LIT(KUSBExe, "usbclasschangeui.exe");
    36 _LIT(KUSBExe, "usbapplication.exe");
    49 const TInt KUSBUIUid = 0x102068E2;
    37 const TInt KUSBUIUid = 0x2002BCA3;
    50 _LIT(KFileDrive,"z:");
    38 _LIT(KFileDrive,"z:");
    51 _LIT(KUSBUIconFileName, "usbui.mif");
    39 _LIT(KUSBUIconFileName, "usbui.mif");
    52 
    40 
    53 // ================= MEMBER FUNCTIONS =========================================
    41 // ================= MEMBER FUNCTIONS =========================================
    54 
    42 
    89     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor"));
    77     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor"));
    90     //Make sure that the request is completed. Note that inside the destructor,
    78     //Make sure that the request is completed. Note that inside the destructor,
    91     //this virtual function call is to the local CUSBUICableConnectedNotifier::
    79     //this virtual function call is to the local CUSBUICableConnectedNotifier::
    92     //Cancel, not to any possibly derived class implementation. 
    80     //Cancel, not to any possibly derived class implementation. 
    93     Cancel();
    81     Cancel();
       
    82     delete iDialog;
       
    83          
    94     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed"));
    84     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed"));
    95     }
    85     }
    96 
    86 
    97 // ----------------------------------------------------------------------------
    87 // ----------------------------------------------------------------------------
    98 // CUSBUICableConnectedNotifier::RegisterL
    88 // CUSBUICableConnectedNotifier::RegisterL
   173 // -----------------------------------------------------------------------------------------------------------
   163 // -----------------------------------------------------------------------------------------------------------
   174 // CUSBUICableConnectedNotifier::GetPersonalityStringL
   164 // CUSBUICableConnectedNotifier::GetPersonalityStringL
   175 // Get the strings for ask on connection message query 
   165 // Get the strings for ask on connection message query 
   176 // -----------------------------------------------------------------------------------------------------------
   166 // -----------------------------------------------------------------------------------------------------------
   177 //
   167 //
   178 void CUSBUICableConnectedNotifier::GetPersonalityStringL(
   168 void CUSBUICableConnectedNotifier::GetPersonalityStringLC(
   179        HBufC*& aHeader,HBufC*& aDescription )
   169        HBufC*& aHeader,HBufC*& aDescription )
   180     {
   170     {
   181     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL"));
   171     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL"));
   182     TInt CurrentPersonalityID = 0; // The ID of current USB mode
   172     TInt CurrentPersonalityID = 0; // The ID of current USB mode
   183     GetCurrentIdL(CurrentPersonalityID);
   173     GetCurrentIdL(CurrentPersonalityID);
   185     User::LeaveIfError(usbman.Connect());
   175     User::LeaveIfError(usbman.Connect());
   186     CleanupClosePushL(usbman);
   176     CleanupClosePushL(usbman);
   187     User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID,
   177     User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID,
   188             aDescription));
   178             aDescription));
   189     CleanupStack::PopAndDestroy(&usbman);
   179     CleanupStack::PopAndDestroy(&usbman);
   190    
   180     CleanupStack::PushL(aDescription);
   191     aHeader = StringLoader::LoadL(R_USB_MODE_MSG_HEADER);
   181     aHeader = StringLoader::LoadL(R_USB_MODE_MSG_HEADER);
   192 
   182     CleanupStack::PushL(aHeader);
   193     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed"));
   183     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed"));
   194     }
   184     }
   195 
   185 
   196 // -----------------------------------------------------------------------------------------------------------
   186 // -----------------------------------------------------------------------------------------------------------
   197 // CUSBUICableConnectedNotifier::RunQueryL
   187 // CUSBUICableConnectedNotifier::RunQueryL
   199 // -----------------------------------------------------------------------------------------------------------
   189 // -----------------------------------------------------------------------------------------------------------
   200 //
   190 //
   201 void CUSBUICableConnectedNotifier::RunQueryL()
   191 void CUSBUICableConnectedNotifier::RunQueryL()
   202     {
   192     {
   203     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL()"));
   193     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL()"));
   204   
       
   205    HBufC* header = NULL;
       
   206    HBufC* description =NULL;
       
   207    GetPersonalityStringL(header, description);
       
   208   
       
   209    CleanupStack::PushL(header);
       
   210    CleanupStack::PushL(description);
       
   211   
       
   212    TFileName usbUiIconFilename( KFileDrive );
       
   213    usbUiIconFilename += KDC_APP_BITMAP_DIR;
       
   214    usbUiIconFilename += KUSBUIconFileName;
       
   215    CAknDiscreetPopup::ShowGlobalPopupL(*header,*description,  KAknsIIDQgnPropUsb, AknIconUtils::AvkonIconFileName(),
       
   216            EMbmAvkonQgn_prop_usb, EMbmAvkonQgn_prop_usb_mask,KAknDiscreetPopupDurationLong, EUSBUICmdDiscreetTapped,( MEikCommandObserver* ) this);
       
   217  
   194  
   218     CompleteMessage(KErrCancel);
   195     _LIT(KNotificationType,"com.nokia.hb.devicenotificationdialog/1.0");
       
   196     _LIT(KTouchActivation, "touchActivation");
       
   197     _LIT(KIconName, "iconName");
       
   198     _LIT(KTitle, "title");
       
   199     _LIT(KText, "text");
       
   200 
       
   201     HBufC* header = NULL;
       
   202     HBufC* description =NULL;   
       
   203     GetPersonalityStringLC(header, description);
       
   204    
       
   205     TFileName usbUiIconFilename( KFileDrive );
       
   206     usbUiIconFilename += KDC_APP_BITMAP_DIR;
       
   207     usbUiIconFilename += KUSBUIconFileName;
       
   208     if( iDialog )
       
   209         {
       
   210         delete iDialog;
       
   211         iDialog = NULL;
       
   212         }
       
   213     iDialog = CHbDeviceDialog::NewL();
       
   214     CHbSymbianVariantMap *parameters =CHbSymbianVariantMap::NewL();
       
   215     CleanupStack::PushL(parameters);
       
   216 
       
   217     AddParameterL(parameters, KTitle, header, CHbSymbianVariant::EDes);
       
   218     AddParameterL(parameters, KText, description, CHbSymbianVariant::EDes);
       
   219     AddParameterL(parameters, KIconName, &usbUiIconFilename, CHbSymbianVariant::EDes);
       
   220     TBool activation=ETrue;
       
   221     AddParameterL(parameters, KTouchActivation, &activation, CHbSymbianVariant::EBool);
       
   222 
       
   223     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL() show") );     
       
   224     TBool error = iDialog->Show(KNotificationType ,*parameters, this);
       
   225     FTRACE( FPrint(
       
   226         _L( "[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL() error = %d" ),
       
   227         error ) );
       
   228 
       
   229     CleanupStack::PopAndDestroy(parameters);    
       
   230     CleanupStack::PopAndDestroy(header);
   219     CleanupStack::PopAndDestroy(description);
   231     CleanupStack::PopAndDestroy(description);
   220     CleanupStack::PopAndDestroy(header);
   232     
   221    
       
   222     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL completed"));
   233     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL completed"));
   223     }
   234     }
   224 // ----------------------------------------------------------------------------
   235 // ----------------------------------------------------------------------------
   225 // CUSBUICableConnectedNotifier::GetCurrentIdL
   236 // CUSBUICableConnectedNotifier::GetCurrentIdL
   226 // get the current personality id
   237 // get the current personality id
   231     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL"));
   242     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL"));
   232     // Connecting and initialization:
   243     // Connecting and initialization:
   233     CRepository* repository = CRepository::NewL(KCRUidUsbWatcher);
   244     CRepository* repository = CRepository::NewL(KCRUidUsbWatcher);
   234     CleanupStack::PushL(repository);
   245     CleanupStack::PushL(repository);
   235     // Get the current USB mode
   246     // Get the current USB mode
   236     repository->Get(KUsbWatcherPersonality, aCurrentPersonality);
   247     TInt ret = repository->Get(KUsbWatcherPersonality, aCurrentPersonality);
       
   248     FTRACE( FPrint(
       
   249         _L( "[USBWATCHER]\t CUSBUICableConnectedNotifier::GetCurrentIdL() ret = %d" ),
       
   250         ret ) );    
   237     CleanupStack::PopAndDestroy(repository);
   251     CleanupStack::PopAndDestroy(repository);
   238     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed"));
   252     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed"));
   239     }
   253     }
   240 
   254 
   241 // ----------------------------------------------------------------------------
   255 // ----------------------------------------------------------------------------
   242 // CUSBUICableConnectedNotifier::ProcessCommandL()
   256 // CUSBUICableConnectedNotifier::DataReceived
   243 // when discreet pop up is tapped the command will be handled here 
   257 // launches the QT usb ui setting
   244 // ----------------------------------------------------------------------------
   258 // ----------------------------------------------------------------------------
   245 //
   259 //
   246 void CUSBUICableConnectedNotifier::ProcessCommandL(TInt aCommandId)
   260 void CUSBUICableConnectedNotifier::DataReceived(CHbSymbianVariantMap& aData)
   247     {
   261     {
   248     switch ( aCommandId )
   262     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::DataReceived"));
   249             {
   263     _LIT(KResult, "result");
   250         case EUSBUICmdDiscreetTapped:
   264     _LIT(KActivated, "activated");
   251             {
   265     TInt result = 0;
   252             TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),TUid::Uid(KUSBUIUid));
   266     MDesCArray& keys = aData.Keys();
   253             CreateChosenViewL(KUSBExe(),uidtype);  
   267     HBufC* key = NULL;
   254             }
   268     for(TInt i = 0; i < keys.MdcaCount(); i++)
   255             break;
   269         {
   256         default:
   270         result = keys.MdcaPoint(i).Compare(KResult); 
   257                   
   271         if (result == 0)
   258         break;
   272             {        
   259             }
   273             key = HBufC::New(KResult().Length());
   260     }
   274             if (key)
       
   275                 {
       
   276                 *key = KResult;            
       
   277                 const CHbSymbianVariant* variant = aData.Get(*key);
       
   278                 delete key;
       
   279                 HBufC* value = static_cast<HBufC*>(variant->Data());
       
   280                 result = value->Des().Compare(KActivated);
       
   281                 if (result == 0)
       
   282                     {
       
   283                     TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),
       
   284                             TUid::Uid(KUSBUIUid));
       
   285                     LaunchApplication(KUSBExe(), uidtype);
       
   286                     }
       
   287                 break;
       
   288                 }
       
   289             }            
       
   290         }
       
   291     }
       
   292 
       
   293 // ----------------------------------------------------------------------------
       
   294 // CUSBUICableConnectedNotifier::DeviceDialogClosed
       
   295 // Not implemented
       
   296 // ----------------------------------------------------------------------------
       
   297 //      
       
   298  void CUSBUICableConnectedNotifier::DeviceDialogClosed(TInt /*aCompletionCode*/)
       
   299      {
       
   300      // no implementation    
       
   301      }
       
   302       
   261 // ---------------------------------------------------------------------------
   303 // ---------------------------------------------------------------------------
   262 // CUSBUICableConnectedNotifier::CreateChosenViewL()
   304 // CUSBUICableConnectedNotifier::LaunchApplication()
   263 // creates the USB UI setting view
   305 // launches the application 
   264 // ---------------------------------------------------------------------------
   306 // ---------------------------------------------------------------------------
   265 //  
   307 //  
   266     void CUSBUICableConnectedNotifier::CreateChosenViewL(const TDesC & aProcessName,const TUidType & aUidType) const
   308 void CUSBUICableConnectedNotifier::LaunchApplication(const TDesC & aProcessName, 
       
   309         const TUidType & aUidType) const
   267     {                 
   310     {                 
   268     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() "));
   311     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication()"));
   269         RProcess usbUiProcess;                
   312     RProcess usbUiProcess;                
   270         User::LeaveIfError(usbUiProcess.Create(aProcessName, KNullDesC, aUidType));   
   313     TInt result = usbUiProcess.Create(aProcessName, KNullDesC, aUidType);
   271         usbUiProcess.Resume();
   314     FTRACE( FPrint(
   272         usbUiProcess.Close();                     
   315         _L( "[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() result = %d" ),
   273     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() "));         
   316         result ) );    
       
   317     usbUiProcess.Resume();
       
   318     usbUiProcess.Close();                     
       
   319     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() completed"));             
       
   320     }
   274     
   321     
   275     }
   322 // ---------------------------------------------------------------------------
       
   323 // CUSBUICableConnectedNotifier::AddParameter()
       
   324 // Adds a string parameter to the dialog parameters.
       
   325 // ---------------------------------------------------------------------------
       
   326 //  
       
   327 void CUSBUICableConnectedNotifier::AddParameterL(
       
   328         CHbSymbianVariantMap* aParameters,
       
   329         const TDesC& aKey,
       
   330         const TAny* aData,
       
   331         CHbSymbianVariant::TType aDataType)
       
   332     {
       
   333     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::AddStringParameter()") );
       
   334     FTRACE( FPrint(
       
   335         _L( "[USBWATCHER]\t CUSBUICableConnectedNotifier::RunQueryL() aKey = %S" ),
       
   336         &aKey ) );
       
   337     CHbSymbianVariant* variant = CHbSymbianVariant::NewL(aData, aDataType);
       
   338     //aParameters takes variant ownership
       
   339     User::LeaveIfError(aParameters->Add(aKey, variant));
       
   340     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::AddStringParameter() completed") );
       
   341     }
       
   342 
   276 // End of File
   343 // End of File