usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp
changeset 25 8c311f9acc5e
parent 8 7e15987c4500
child 31 dfdd8240f7c8
equal deleted inserted replaced
8:7e15987c4500 25:8c311f9acc5e
    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 
    73 // CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier
    61 // CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier
    74 // C++ default constructor can NOT contain any code, that
    62 // C++ default constructor can NOT contain any code, that
    75 // might leave.
    63 // might leave.
    76 // ----------------------------------------------------------------------------
    64 // ----------------------------------------------------------------------------
    77 //
    65 //
    78 CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier(): 
    66 CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier()
    79     iNoteVisible(EFalse)
       
    80     {
    67     {
    81     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::default constructor"));
    68     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::default constructor"));
    82     }
    69     }
    83 
    70 
    84 // ----------------------------------------------------------------------------
    71 // ----------------------------------------------------------------------------
    90     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor"));
    77     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor"));
    91     //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,
    92     //this virtual function call is to the local CUSBUICableConnectedNotifier::
    79     //this virtual function call is to the local CUSBUICableConnectedNotifier::
    93     //Cancel, not to any possibly derived class implementation. 
    80     //Cancel, not to any possibly derived class implementation. 
    94     Cancel();
    81     Cancel();
       
    82     delete iDialog;
       
    83          
    95     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed"));
    84     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed"));
    96     }
    85     }
    97 
    86 
    98 // ----------------------------------------------------------------------------
    87 // ----------------------------------------------------------------------------
    99 // CUSBUICableConnectedNotifier::RegisterL
    88 // CUSBUICableConnectedNotifier::RegisterL
   144 // ----------------------------------------------------------------------------
   133 // ----------------------------------------------------------------------------
   145 //
   134 //
   146 void CUSBUICableConnectedNotifier::RunL()
   135 void CUSBUICableConnectedNotifier::RunL()
   147     {
   136     {
   148     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunL"));
   137     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunL"));
   149     iNoteVisible = ETrue;
   138 
   150     DisableKeylock();
   139     DisableKeylock();
   151     SuppressAppSwitching(ETrue);
   140     SuppressAppSwitching(ETrue);
   152     RunQueryL();
   141     RunQueryL();
   153     SuppressAppSwitching(EFalse);
   142     SuppressAppSwitching(EFalse);
   154     RestoreKeylock();
   143     RestoreKeylock();
   162 // ----------------------------------------------------------------------------
   151 // ----------------------------------------------------------------------------
   163 //
   152 //
   164 void CUSBUICableConnectedNotifier::Cancel()
   153 void CUSBUICableConnectedNotifier::Cancel()
   165     {
   154     {
   166     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() "));
   155     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() "));
   167     // Not allowed to cancel this one before note is closed.
   156 
   168     if ( iNoteVisible )
   157     iDialog->Cancel(); // cancel the dialog, if it is active
   169         {
       
   170         iNoteWaiter.Start();    
       
   171         }
       
   172         
       
   173     CompleteMessage(KErrCancel);
   158     CompleteMessage(KErrCancel);
   174     CUSBUINotifierBase::Cancel();
   159     CUSBUINotifierBase::Cancel();
   175 
   160 
   176     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() completed"));
   161     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() completed"));
   177     }
   162     }
   179 // -----------------------------------------------------------------------------------------------------------
   164 // -----------------------------------------------------------------------------------------------------------
   180 // CUSBUICableConnectedNotifier::GetPersonalityStringL
   165 // CUSBUICableConnectedNotifier::GetPersonalityStringL
   181 // Get the strings for ask on connection message query 
   166 // Get the strings for ask on connection message query 
   182 // -----------------------------------------------------------------------------------------------------------
   167 // -----------------------------------------------------------------------------------------------------------
   183 //
   168 //
   184 void CUSBUICableConnectedNotifier::GetPersonalityStringL(
   169 void CUSBUICableConnectedNotifier::GetPersonalityStringLC(
   185        HBufC*& aHeader,HBufC*& aDescription )
   170        HBufC*& aHeader,HBufC*& aDescription )
   186     {
   171     {
   187     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL"));
   172     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL"));
   188     TInt CurrentPersonalityID = 0; // The ID of current USB mode
   173     TInt CurrentPersonalityID = 0; // The ID of current USB mode
   189     GetCurrentIdL(CurrentPersonalityID);
   174     GetCurrentIdL(CurrentPersonalityID);
   191     User::LeaveIfError(usbman.Connect());
   176     User::LeaveIfError(usbman.Connect());
   192     CleanupClosePushL(usbman);
   177     CleanupClosePushL(usbman);
   193     User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID,
   178     User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID,
   194             aDescription));
   179             aDescription));
   195     CleanupStack::PopAndDestroy(&usbman);
   180     CleanupStack::PopAndDestroy(&usbman);
   196    
   181     CleanupStack::PushL(aDescription);
   197     aHeader = StringLoader::LoadL(R_USB_MODE_MSG_HEADER);
   182     aHeader = StringLoader::LoadL(R_USB_MODE_MSG_HEADER);
   198 
   183     CleanupStack::PushL(aHeader);
   199     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed"));
   184     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed"));
   200     }
   185     }
   201 
   186 
   202 // -----------------------------------------------------------------------------------------------------------
   187 // -----------------------------------------------------------------------------------------------------------
   203 // CUSBUICableConnectedNotifier::RunQueryL
   188 // CUSBUICableConnectedNotifier::RunQueryL
   205 // -----------------------------------------------------------------------------------------------------------
   190 // -----------------------------------------------------------------------------------------------------------
   206 //
   191 //
   207 void CUSBUICableConnectedNotifier::RunQueryL()
   192 void CUSBUICableConnectedNotifier::RunQueryL()
   208     {
   193     {
   209     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL()"));
   194     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL()"));
   210   
   195  
   211    HBufC* header = NULL;
   196     _LIT(KNotificationType,"com.nokia.hb.devicenotificationdialog/1.0");
   212    HBufC* description =NULL;
   197     _LIT(KTouchActivation, "touchActivation");
   213    GetPersonalityStringL(header, description);
   198     _LIT(KIconName, "iconName");
   214   
   199     _LIT(KTitle, "title");
   215    CleanupStack::PushL(header);
   200     _LIT(KText, "text");
   216    CleanupStack::PushL(description);
   201 
   217   
   202     HBufC* header = NULL;
   218    TFileName usbUiIconFilename( KFileDrive );
   203     HBufC* description =NULL;   
   219    usbUiIconFilename += KDC_APP_BITMAP_DIR;
   204     GetPersonalityStringLC(header, description);
   220    usbUiIconFilename += KUSBUIconFileName;
       
   221    iNoteVisible = ETrue;
       
   222    CAknDiscreetPopup::ShowGlobalPopupL(*header,*description,  KAknsIIDQgnPropUsb, AknIconUtils::AvkonIconFileName(),
       
   223            EMbmAvkonQgn_prop_usb, EMbmAvkonQgn_prop_usb_mask,KAknDiscreetPopupDurationLong, EUSBUICmdDiscreetTapped,( MEikCommandObserver* ) this);    
       
   224    
   205    
       
   206     TFileName usbUiIconFilename( KFileDrive );
       
   207     usbUiIconFilename += KDC_APP_BITMAP_DIR;
       
   208     usbUiIconFilename += KUSBUIconFileName;
       
   209     if( iDialog )
       
   210         {
       
   211         delete iDialog;
       
   212         iDialog = NULL;
       
   213         }
       
   214     iDialog = CHbDeviceDialog::NewL();
       
   215     CHbSymbianVariantMap *parameters =CHbSymbianVariantMap::NewL();
       
   216     CleanupStack::PushL(parameters);
       
   217 
       
   218     AddParameterL(parameters, KTitle, header, CHbSymbianVariant::EDes);
       
   219     AddParameterL(parameters, KText, description, CHbSymbianVariant::EDes);
       
   220     AddParameterL(parameters, KIconName, &usbUiIconFilename, CHbSymbianVariant::EDes);
       
   221     TBool activation=ETrue;
       
   222     AddParameterL(parameters, KTouchActivation, &activation, CHbSymbianVariant::EBool);
       
   223 
       
   224     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL() show") );     
       
   225     TBool error = iDialog->Show(KNotificationType ,*parameters, this);
       
   226     FTRACE( FPrint(
       
   227         _L( "[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL() error = %d" ),
       
   228         error ) );
       
   229 
       
   230     CleanupStack::PopAndDestroy(parameters);    
       
   231     CleanupStack::PopAndDestroy(header);
   225     CleanupStack::PopAndDestroy(description);
   232     CleanupStack::PopAndDestroy(description);
   226     CleanupStack::PopAndDestroy(header);
   233     
   227    
       
   228     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL completed"));
   234     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL completed"));
   229     }
   235     }
   230 // ----------------------------------------------------------------------------
   236 // ----------------------------------------------------------------------------
   231 // CUSBUICableConnectedNotifier::GetCurrentIdL
   237 // CUSBUICableConnectedNotifier::GetCurrentIdL
   232 // get the current personality id
   238 // get the current personality id
   237     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL"));
   243     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL"));
   238     // Connecting and initialization:
   244     // Connecting and initialization:
   239     CRepository* repository = CRepository::NewL(KCRUidUsbWatcher);
   245     CRepository* repository = CRepository::NewL(KCRUidUsbWatcher);
   240     CleanupStack::PushL(repository);
   246     CleanupStack::PushL(repository);
   241     // Get the current USB mode
   247     // Get the current USB mode
   242     repository->Get(KUsbWatcherPersonality, aCurrentPersonality);
   248     TInt ret = repository->Get(KUsbWatcherPersonality, aCurrentPersonality);
       
   249     FTRACE( FPrint(
       
   250         _L( "[USBWATCHER]\t CUSBUICableConnectedNotifier::GetCurrentIdL() ret = %d" ),
       
   251         ret ) );    
   243     CleanupStack::PopAndDestroy(repository);
   252     CleanupStack::PopAndDestroy(repository);
   244     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed"));
   253     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed"));
   245     }
   254     }
   246 
   255 
   247 // ----------------------------------------------------------------------------
   256 // ----------------------------------------------------------------------------
   248 // CUSBUICableConnectedNotifier::ProcessCommandL()
   257 // CUSBUICableConnectedNotifier::DataReceived
   249 // when discreet pop up is tapped the command will be handled here 
   258 // launches the QT usb ui setting
   250 // ----------------------------------------------------------------------------
   259 // ----------------------------------------------------------------------------
   251 //
   260 //
   252 void CUSBUICableConnectedNotifier::ProcessCommandL(TInt aCommandId)
   261 void CUSBUICableConnectedNotifier::DataReceived(CHbSymbianVariantMap& aData)
   253     {
   262     {
   254     switch ( aCommandId )
   263     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::DataReceived"));
   255             {
   264     _LIT(KResult, "result");
   256         case EUSBUICmdDiscreetTapped:
   265     _LIT(KActivated, "activated");
   257             {
   266     TInt result = 0;
   258             TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),TUid::Uid(KUSBUIUid));
   267     MDesCArray& keys = aData.Keys();
   259             CreateChosenViewL(KUSBExe(),uidtype);  
   268     HBufC* key = NULL;
   260             }
   269     for(TInt i = 0; i < keys.MdcaCount(); i++)
   261         case EAknDiscreetPopupCmdClose:                
   270         {
   262             if ( iNoteWaiter.IsStarted() )
   271         result = keys.MdcaPoint(i).Compare(KResult); 
       
   272         if (result == 0)
       
   273             {        
       
   274             key = HBufC::New(KResult().Length());
       
   275             if (key)
   263                 {
   276                 {
   264                 iNoteWaiter.AsyncStop();
   277                 *key = KResult;            
       
   278                 const CHbSymbianVariant* variant = aData.Get(*key);
       
   279                 delete key;
       
   280                 HBufC* value = static_cast<HBufC*>(variant->Data());
       
   281                 result = value->Des().Compare(KActivated);
       
   282                 if (result == 0)
       
   283                     {
       
   284                     TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),
       
   285                             TUid::Uid(KUSBUIUid));
       
   286                     LaunchApplication(KUSBExe(), uidtype);
       
   287                     }
       
   288                 break;
   265                 }
   289                 }
   266             iNoteVisible = EFalse;    
   290             }            
   267             CompleteMessage( KErrCancel );                    
   291         }
   268             break;
   292     }
   269         default:
   293 
   270                   
   294 // ----------------------------------------------------------------------------
   271         break;
   295 // CUSBUICableConnectedNotifier::DeviceDialogClosed
   272             }
   296 // ----------------------------------------------------------------------------
   273     }
   297 //      
       
   298  void CUSBUICableConnectedNotifier::DeviceDialogClosed(TInt aCompletionCode)
       
   299      {
       
   300      FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::DeviceDialogClosed()"));
       
   301      CompleteMessage(aCompletionCode);  
       
   302      }
       
   303       
   274 // ---------------------------------------------------------------------------
   304 // ---------------------------------------------------------------------------
   275 // CUSBUICableConnectedNotifier::CreateChosenViewL()
   305 // CUSBUICableConnectedNotifier::LaunchApplication()
   276 // creates the USB UI setting view
   306 // launches the application 
   277 // ---------------------------------------------------------------------------
   307 // ---------------------------------------------------------------------------
   278 //  
   308 //  
   279     void CUSBUICableConnectedNotifier::CreateChosenViewL(const TDesC & aProcessName,const TUidType & aUidType) const
   309 void CUSBUICableConnectedNotifier::LaunchApplication(const TDesC & aProcessName, 
       
   310         const TUidType & aUidType) const
   280     {                 
   311     {                 
   281     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() "));
   312     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication()"));
   282         RProcess usbUiProcess;                
   313     RProcess usbUiProcess;                
   283         User::LeaveIfError(usbUiProcess.Create(aProcessName, KNullDesC, aUidType));   
   314     TInt result = usbUiProcess.Create(aProcessName, KNullDesC, aUidType);
   284         usbUiProcess.Resume();
   315     FTRACE( FPrint(
   285         usbUiProcess.Close();                     
   316         _L( "[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() result = %d" ),
   286     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() "));         
   317         result ) );    
       
   318     usbUiProcess.Resume();
       
   319     usbUiProcess.Close();                     
       
   320     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() completed"));             
       
   321     }
   287     
   322     
   288     }
   323 // ---------------------------------------------------------------------------
       
   324 // CUSBUICableConnectedNotifier::AddParameter()
       
   325 // Adds a string parameter to the dialog parameters.
       
   326 // ---------------------------------------------------------------------------
       
   327 //  
       
   328 void CUSBUICableConnectedNotifier::AddParameterL(
       
   329         CHbSymbianVariantMap* aParameters,
       
   330         const TDesC& aKey,
       
   331         const TAny* aData,
       
   332         CHbSymbianVariant::TType aDataType)
       
   333     {
       
   334     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::AddStringParameter()") );
       
   335     FTRACE( FPrint(
       
   336         _L( "[USBWATCHER]\t CUSBUICableConnectedNotifier::RunQueryL() aKey = %S" ),
       
   337         &aKey ) );
       
   338     CHbSymbianVariant* variant = CHbSymbianVariant::NewL(aData, aDataType);
       
   339     //aParameters takes variant ownership
       
   340     User::LeaveIfError(aParameters->Add(aKey, variant));
       
   341     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::AddStringParameter() completed") );
       
   342     }
       
   343 
   289 // End of File
   344 // End of File