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