usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp
branchRCL_3
changeset 79 25fce757be94
parent 33 d895b6d953c9
child 80 e02eb84a14d2
equal deleted inserted replaced
77:5b2a402e96ac 79:25fce757be94
    13  *
    13  *
    14  * Description:  USB Cable Connected notifier class.
    14  * Description:  USB Cable Connected notifier class.
    15  *
    15  *
    16  */
    16  */
    17 // INCLUDE FILES
    17 // INCLUDE FILES
    18 #include <eikenv.h>          // Eikon environment
       
    19 #include <bautils.h>         // BAFL utils (for language file)
       
    20 #include <aknlists.h>
       
    21 #include <aknPopup.h> 
       
    22 #include <StringLoader.h>    // Localisation stringloader
       
    23 #include <utf.h>             // Unicode character conversion utilities
    18 #include <utf.h>             // Unicode character conversion utilities
    24 #include <AknsUtils.h>
    19 #include <usbman.h>
    25 #include <usb.h>
       
    26 #include <usbuinotif.rsg>                   // Own resources
       
    27 #include <centralrepository.h> 
    20 #include <centralrepository.h> 
    28 #include <e32property.h>
    21 #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
    22 #include <e32uid.h> // KExecutableImageUid
    39 #include <usbui.mbg>
    23 #include <hb/hbwidgets/hbdevicenotificationdialogsymbian.h>
    40 
    24 #include <hb/hbcore/hbtextresolversymbian.h>
    41 #include "usbuincableconnectednotifier.h"   // Own class definition
    25 #include "usbuincableconnectednotifier.h"   // Own class definition
    42 #include "usbuinotifdebug.h"                // Debugging macros
    26 #include "usbuinotifdebug.h"                // Debugging macros
    43 #include "UsbWatcherInternalCRKeys.h"
    27 #include "UsbWatcherInternalCRKeys.h"
    44 #include "usbpersonalityids.h"
       
    45 #include "usbuinotif.hrh"
    28 #include "usbuinotif.hrh"
    46 
    29 
    47 // Literals
    30 // Literals
    48 
    31 
    49 _LIT(KUSBExe, "usbclasschangeui.exe");
    32 _LIT(KUSBExe, "USBSettingsApp");
    50 const TInt KUSBUIUid = 0x102068E2;
    33 const TInt KUSBUIUid = 0x2002E70C;
       
    34 const TInt KTextIdLength = 40;
       
    35 
       
    36 _LIT(KUSBUIconFileName, "qtg_large_usb");
    51 
    37 
    52 // ================= MEMBER FUNCTIONS =========================================
    38 // ================= MEMBER FUNCTIONS =========================================
    53 
    39 
    54 // ----------------------------------------------------------------------------
    40 // ----------------------------------------------------------------------------
    55 // CUSBUICableConnectedNotifier::NewL
    41 // CUSBUICableConnectedNotifier::NewL
    72 // CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier
    58 // CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier
    73 // C++ default constructor can NOT contain any code, that
    59 // C++ default constructor can NOT contain any code, that
    74 // might leave.
    60 // might leave.
    75 // ----------------------------------------------------------------------------
    61 // ----------------------------------------------------------------------------
    76 //
    62 //
    77 CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier(): 
    63 CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier()
    78     iNoteVisible(EFalse),
       
    79     iNoteTapped(EFalse)
       
    80     {
    64     {
    81     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::default constructor"));
    65     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::default constructor"));
    82     }
    66     }
    83 
    67 
    84 // ----------------------------------------------------------------------------
    68 // ----------------------------------------------------------------------------
    90     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor"));
    74     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor"));
    91     //Make sure that the request is completed. Note that inside the destructor,
    75     //Make sure that the request is completed. Note that inside the destructor,
    92     //this virtual function call is to the local CUSBUICableConnectedNotifier::
    76     //this virtual function call is to the local CUSBUICableConnectedNotifier::
    93     //Cancel, not to any possibly derived class implementation. 
    77     //Cancel, not to any possibly derived class implementation. 
    94     Cancel();
    78     Cancel();
       
    79            
    95     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed"));
    80     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed"));
    96     }
    81     }
    97 
    82 
    98 // ----------------------------------------------------------------------------
    83 // ----------------------------------------------------------------------------
    99 // CUSBUICableConnectedNotifier::RegisterL
    84 // CUSBUICableConnectedNotifier::RegisterL
   110     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RegisterL completed"));
    95     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RegisterL completed"));
   111     return iInfo;
    96     return iInfo;
   112     }
    97     }
   113 
    98 
   114 // ----------------------------------------------------------------------------
    99 // ----------------------------------------------------------------------------
   115 // CUSBUICableConnectedNotifier::GetParamsL
   100 // CUSBUICableConnectedNotifier::StartDialogL
   116 //  Jump to RunL as soon as possible.
   101 // ----------------------------------------------------------------------------
   117 // ----------------------------------------------------------------------------
   102 //
   118 //
   103 void CUSBUICableConnectedNotifier::StartDialogL(const TDesC8& /*aBuffer*/,
   119 void CUSBUICableConnectedNotifier::GetParamsL(const TDesC8& /*aBuffer*/,
       
   120         TInt aReplySlot, const RMessagePtr2& aMessage)
   104         TInt aReplySlot, const RMessagePtr2& aMessage)
   121     {
   105     {
   122     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetParamsL"));
   106     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::StartDialogL"));
   123     if ( iReplySlot != 0 || iNeedToCompleteMessage)
   107     if ( iReplySlot != 0 || iNeedToCompleteMessage)
   124         {
   108         {
   125         User::Leave(KErrInUse);
   109         User::Leave(KErrInUse);
   126         }
   110         }
       
   111 
       
   112     InitializeTextResolver();
   127 
   113 
   128     iMessage = aMessage;
   114     iMessage = aMessage;
   129     iNeedToCompleteMessage = ETrue;
   115     iNeedToCompleteMessage = ETrue;
   130     iReplySlot = aReplySlot;
   116     iReplySlot = aReplySlot;
   131 
   117     if (iDialog)
   132     // Call SetActive() so RunL() will be called by the active scheduler
   118         {
   133     //
   119         FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::StartDialogL() deleting previous dialog"));
   134     iStatus = KRequestPending;
   120         delete iDialog;
   135     TRequestStatus* stat = &iStatus;
   121         iDialog = NULL;
   136     SetActive();
   122         }
   137     User::RequestComplete(stat, KErrNone);
   123     iDialog = CHbDeviceNotificationDialogSymbian::NewL(this);
   138     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetParamsL() completed"));
   124       
   139     }
   125     HBufC* header = NULL;
   140 
   126     HBufC* description =NULL;   
   141 // ----------------------------------------------------------------------------
   127     GetPersonalityStringLC(header, description);
   142 // CUSBUICableConnectedNotifier::RunL
   128    
   143 // Ask user response and return it to caller.
   129     iDialog->SetTitleL(*header);
   144 // ----------------------------------------------------------------------------
   130     iDialog->SetTextL(*description);
   145 //
   131     iDialog->SetIconNameL(KUSBUIconFileName );
   146 void CUSBUICableConnectedNotifier::RunL()
   132     iDialog->EnableTouchActivation(ETrue);
   147     {
   133     iDialog->ShowL();
   148     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunL"));
   134     
   149     iNoteVisible = ETrue;
   135     CleanupStack::PopAndDestroy(header);
   150     DisableKeylock();
   136     CleanupStack::PopAndDestroy(description);
   151     SuppressAppSwitching(ETrue);
   137     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::StartDialogL completed"));
   152     RunQueryL();
       
   153 
       
   154     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunL() completed"));
       
   155     }
   138     }
   156 
   139 
   157 // ----------------------------------------------------------------------------
   140 // ----------------------------------------------------------------------------
   158 // CUSBUICableConnectedNotifier::Cancel()
   141 // CUSBUICableConnectedNotifier::Cancel()
   159 // Release all own resources (member variables)
   142 // Release all own resources (member variables)
   160 // ----------------------------------------------------------------------------
   143 // ----------------------------------------------------------------------------
   161 //
   144 //
   162 void CUSBUICableConnectedNotifier::Cancel()
   145 void CUSBUICableConnectedNotifier::Cancel()
   163     {
   146     {
   164     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() "));
   147     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() "));
   165     // Not allowed to cancel this one before note is closed.
   148     if (iDialog)
   166     if ( iNoteVisible )
   149         {
   167         {
   150         iDialog->Close();
   168         iNoteWaiter.Start();    
   151         delete iDialog;
   169         }
   152         iDialog = NULL;
   170         
   153         }
   171     CompleteMessage(KErrCancel);
   154     CompleteMessage(KErrCancel);
   172     CUSBUINotifierBase::Cancel();
   155     CUSBUINotifierBase::Cancel();
   173 
   156 
   174     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() completed"));
   157     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() completed"));
   175     }
   158     }
   176 
   159 
   177 // ----------------------------------------------------------------------------
   160 // -----------------------------------------------------------------------------------------------------------
   178 // CUSBUICableConnectedNotifier::GetPersonalityStringL
   161 // CUSBUICableConnectedNotifier::GetPersonalityStringL
   179 // Get the strings for ask on connection message query 
   162 // Get the strings for the discreet popup dialog
   180 // ----------------------------------------------------------------------------
   163 // -----------------------------------------------------------------------------------------------------------
   181 //
   164 //
   182 void CUSBUICableConnectedNotifier::GetPersonalityStringL(
   165 void CUSBUICableConnectedNotifier::GetPersonalityStringLC(
   183        HBufC*& aHeader,HBufC*& aDescription )
   166        HBufC*& aHeader,HBufC*& aDescription )
   184     {
   167     {
   185     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL"));
   168     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL"));
       
   169     _LIT(KFixedPart, "txt_usb_dpinfo_");
       
   170     _LIT(KSpace, " ");
       
   171     _LIT(KUnderline, "_");
       
   172     _LIT(KUsbConnected, "txt_usb_dpophead_usb_connected");
   186     TInt CurrentPersonalityID = 0; // The ID of current USB mode
   173     TInt CurrentPersonalityID = 0; // The ID of current USB mode
   187     GetCurrentIdL(CurrentPersonalityID);
   174     GetCurrentIdL(CurrentPersonalityID);
   188     RUsb usbman;
   175     RUsb usbman;
   189     User::LeaveIfError(usbman.Connect());
   176     User::LeaveIfError(usbman.Connect());
       
   177     FLOG(_L("[USBUINOTIF]\t usbman connect called"));     
   190     CleanupClosePushL(usbman);
   178     CleanupClosePushL(usbman);
       
   179     HBufC* description = NULL;
   191     User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID,
   180     User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID,
   192             aDescription));
   181             description));
       
   182      FLOG(_L("[USBUINOTIF]\t get description called"));  
   193     CleanupStack::PopAndDestroy(&usbman);
   183     CleanupStack::PopAndDestroy(&usbman);
   194    
   184     
   195     aHeader = StringLoader::LoadL(R_USB_MODE_MSG_HEADER);
   185     CleanupStack::PushL(description);
   196 
   186     TPtr descriptionPtr = description->Des();
       
   187     TInt position = descriptionPtr.Find(KSpace);
       
   188     while (position != KErrNotFound)
       
   189         {
       
   190         descriptionPtr.Replace(position, 1, KUnderline);     
       
   191         position = descriptionPtr.Find(KSpace); 
       
   192         }
       
   193     HBufC* textId = HBufC::NewL( KTextIdLength );
       
   194     CleanupStack::PushL(textId);
       
   195     TPtr textIdPtr = textId->Des();
       
   196     textIdPtr.Append(KFixedPart);
       
   197     textIdPtr.Append(descriptionPtr);  
       
   198 
       
   199     aDescription = HbTextResolverSymbian::LoadL(textIdPtr);
       
   200     CleanupStack::PopAndDestroy(textId);
       
   201     CleanupStack::PopAndDestroy(description);
       
   202     CleanupStack::PushL(aDescription);
       
   203 
       
   204     FLOG(_L("[USBUINOTIF]\t get description called"));  
       
   205     aHeader = HbTextResolverSymbian::LoadL(KUsbConnected);
       
   206     FLOG(_L("[USBUINOTIF]\t get header called"));  
       
   207  
       
   208     CleanupStack::PushL(aHeader);
       
   209     
   197     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed"));
   210     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed"));
   198     }
   211     }
   199 
   212 
   200 // ----------------------------------------------------------------------------
       
   201 // CUSBUICableConnectedNotifier::RunQueryL
       
   202 // Run the ask on connection message query
       
   203 // ----------------------------------------------------------------------------
       
   204 //
       
   205 void CUSBUICableConnectedNotifier::RunQueryL()
       
   206     {
       
   207     FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL()"));
       
   208   
       
   209     HBufC* header = NULL;
       
   210     HBufC* description =NULL;
       
   211     GetPersonalityStringL(header, description);
       
   212   
       
   213     CleanupStack::PushL(header);
       
   214     CleanupStack::PushL(description);
       
   215   
       
   216     iNoteVisible = ETrue;
       
   217     CAknDiscreetPopup::ShowGlobalPopupL(
       
   218         *header,
       
   219         *description,
       
   220         KAknsIIDQgnPropUsb,
       
   221         AknIconUtils::AvkonIconFileName(),
       
   222         EMbmAvkonQgn_prop_usb,
       
   223         EMbmAvkonQgn_prop_usb_mask,
       
   224         KAknDiscreetPopupDurationLong,
       
   225         EUSBUICmdDiscreetTapped,
       
   226         (MEikCommandObserver*) this);
       
   227    
       
   228     CleanupStack::PopAndDestroy(description);
       
   229     CleanupStack::PopAndDestroy(header);
       
   230    
       
   231     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL completed"));
       
   232     }
       
   233 // ----------------------------------------------------------------------------
   213 // ----------------------------------------------------------------------------
   234 // CUSBUICableConnectedNotifier::GetCurrentIdL
   214 // CUSBUICableConnectedNotifier::GetCurrentIdL
   235 // get the current personality id
   215 // get the current personality id
   236 // ----------------------------------------------------------------------------
   216 // ----------------------------------------------------------------------------
   237 //
   217 //
   240     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL"));
   220     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL"));
   241     // Connecting and initialization:
   221     // Connecting and initialization:
   242     CRepository* repository = CRepository::NewL(KCRUidUsbWatcher);
   222     CRepository* repository = CRepository::NewL(KCRUidUsbWatcher);
   243     CleanupStack::PushL(repository);
   223     CleanupStack::PushL(repository);
   244     // Get the current USB mode
   224     // Get the current USB mode
   245     repository->Get(KUsbWatcherPersonality, aCurrentPersonality);
   225     TInt ret = repository->Get(KUsbWatcherPersonality, aCurrentPersonality);
       
   226     FTRACE( FPrint(
       
   227         _L( "[USBWATCHER]\t CUSBUICableConnectedNotifier::GetCurrentIdL() ret = %d" ),
       
   228         ret ) );    
   246     CleanupStack::PopAndDestroy(repository);
   229     CleanupStack::PopAndDestroy(repository);
   247     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed"));
   230     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed"));
   248     }
   231     }
   249 
   232 
   250 // ----------------------------------------------------------------------------
   233 
   251 // CUSBUICableConnectedNotifier::ProcessCommandL()
   234 
   252 // when discreet pop up is tapped the command will be handled here 
   235 void CUSBUICableConnectedNotifier::NotificationDialogActivated(
   253 // ----------------------------------------------------------------------------
   236         const CHbDeviceNotificationDialogSymbian* /*aDialog*/)
   254 //
   237        {
   255 void CUSBUICableConnectedNotifier::ProcessCommandL(TInt aCommandId)
   238        
   256     {
   239            FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::NotificationDialogActivated()"));
   257     FTRACE(FPrint(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::ProcessCommandL: %d"), 
   240            TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),
   258         aCommandId));
   241                                    TUid::Uid(KUSBUIUid));
   259     SuppressAppSwitching(EFalse);
   242            iDialog->Close();
   260     
   243            LaunchApplication(KUSBExe(), uidtype);
   261     switch ( aCommandId )
   244          
   262         {
   245        }
   263         case EUSBUICmdDiscreetTapped:
   246    
   264             {
   247 void CUSBUICableConnectedNotifier::NotificationDialogClosed(
   265             TUidType uidtype(KExecutableImageUid, TUid::Null(), TUid::Uid(KUSBUIUid));
   248         const CHbDeviceNotificationDialogSymbian* /*aDialog*/, TInt /*aCompletionCode*/)
   266             CreateChosenViewL(KUSBExe(),uidtype);
   249        {
   267             iNoteTapped = ETrue;
   250        FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::NotificationDialogClosed()"));
   268             }
   251        CompleteMessage( KErrCancel ); 
   269             //fall through
   252        FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::NotificationDialogClosed() complete"));
   270         case EAknDiscreetPopupCmdClose:
   253 
   271             if ( iNoteWaiter.IsStarted() )
   254        }
   272                 {
       
   273                 iNoteWaiter.AsyncStop();
       
   274                 }
       
   275             iNoteVisible = EFalse;
       
   276             CompleteMessage( KErrCancel );
       
   277             break;
       
   278         default:
       
   279             break;
       
   280         }
       
   281 
       
   282     if (!iNoteTapped)
       
   283         {
       
   284         FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::ProcessCommandL() restore keylock"));
       
   285         RestoreKeylock();
       
   286         }
       
   287 
       
   288     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::ProcessCommandL() completed"));
       
   289     }
       
   290 
       
   291 // ---------------------------------------------------------------------------
   255 // ---------------------------------------------------------------------------
   292 // CUSBUICableConnectedNotifier::CreateChosenViewL()
   256 // CUSBUICableConnectedNotifier::LaunchApplication()
   293 // creates the USB UI setting view
   257 // launches the application 
   294 // ---------------------------------------------------------------------------
   258 // ---------------------------------------------------------------------------
   295 //  
   259 //  
   296 void CUSBUICableConnectedNotifier::CreateChosenViewL(
   260 void CUSBUICableConnectedNotifier::LaunchApplication(const TDesC & aProcessName, 
   297     const TDesC & aProcessName, const TUidType & aUidType) const
   261         const TUidType & aUidType) const
   298     {                 
   262     {                 
   299     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() "));
   263     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication()"));
   300     RProcess usbUiProcess;
   264     RProcess usbUiProcess;                
   301     User::LeaveIfError(usbUiProcess.Create(aProcessName, KNullDesC, aUidType));
   265     TInt result = usbUiProcess.Create(aProcessName, KNullDesC, aUidType);
       
   266     FTRACE( FPrint(
       
   267         _L( "[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() result = %d" ),
       
   268         result ) );    
   302     usbUiProcess.Resume();
   269     usbUiProcess.Resume();
   303     usbUiProcess.Close();
   270     usbUiProcess.Close();                     
   304     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() "));
   271     FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() completed"));             
   305     }
   272     }
   306 
   273 
   307 // End of File
   274 // End of File