|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: USB Cable Connected notifier class. |
|
15 * |
|
16 */ |
|
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 |
|
24 #include <aknsutils.h> |
|
25 #include <usb.h> |
|
26 #include <USBUINotif.rsg> // Own resources |
|
27 #include <centralrepository.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> |
|
38 #include <e32uid.h> // KExecutableImageUid |
|
39 #include <usbui.mbg> |
|
40 #include "usbuincableconnectednotifier.h" // Own class definition |
|
41 #include "usbuinotifdebug.h" // Debugging macros |
|
42 #include "usbwatcherinternalcrkeys.h" |
|
43 #include "usbpersonalityids.h" |
|
44 #include "usbuinotif.hrh" |
|
45 |
|
46 // Literals |
|
47 |
|
48 _LIT(KUSBExe, "usbclasschangeui.exe"); |
|
49 const TInt KUSBUIUid = 0x102068E2; |
|
50 _LIT(KFileDrive,"z:"); |
|
51 _LIT(KUSBUIconFileName, "usbui.mif"); |
|
52 |
|
53 // ================= MEMBER FUNCTIONS ========================================= |
|
54 |
|
55 // ---------------------------------------------------------------------------- |
|
56 // CUSBUICableConnectedNotifier::NewL |
|
57 // Two-phased constructor. |
|
58 // ---------------------------------------------------------------------------- |
|
59 // |
|
60 CUSBUICableConnectedNotifier* CUSBUICableConnectedNotifier::NewL() |
|
61 { |
|
62 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::NewL")); |
|
63 CUSBUICableConnectedNotifier* self = |
|
64 new (ELeave) CUSBUICableConnectedNotifier(); |
|
65 CleanupStack::PushL(self); |
|
66 self->ConstructL(); |
|
67 CleanupStack::Pop(self); |
|
68 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::NewL completed")); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // ---------------------------------------------------------------------------- |
|
73 // CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier |
|
74 // C++ default constructor can NOT contain any code, that |
|
75 // might leave. |
|
76 // ---------------------------------------------------------------------------- |
|
77 // |
|
78 CUSBUICableConnectedNotifier::CUSBUICableConnectedNotifier() |
|
79 { |
|
80 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::default constructor")); |
|
81 } |
|
82 |
|
83 // ---------------------------------------------------------------------------- |
|
84 // Destructor |
|
85 // ---------------------------------------------------------------------------- |
|
86 // |
|
87 CUSBUICableConnectedNotifier::~CUSBUICableConnectedNotifier() |
|
88 { |
|
89 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor")); |
|
90 //Make sure that the request is completed. Note that inside the destructor, |
|
91 //this virtual function call is to the local CUSBUICableConnectedNotifier:: |
|
92 //Cancel, not to any possibly derived class implementation. |
|
93 Cancel(); |
|
94 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed")); |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // CUSBUICableConnectedNotifier::RegisterL |
|
99 // Register notifier. |
|
100 // ---------------------------------------------------------------------------- |
|
101 // |
|
102 CUSBUICableConnectedNotifier::TNotifierInfo CUSBUICableConnectedNotifier::RegisterL() |
|
103 { |
|
104 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RegisterL")); |
|
105 iInfo.iUid = KCableConnectedNotifierUid; |
|
106 iInfo.iChannel = KQueriesNotifier; // work in the same channel with the other |
|
107 // queries so that we can use priorities |
|
108 iInfo.iPriority = ENotifierPriorityLow; // must be smaller than queries notifier |
|
109 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RegisterL completed")); |
|
110 return iInfo; |
|
111 } |
|
112 |
|
113 // ---------------------------------------------------------------------------- |
|
114 // CUSBUICableConnectedNotifier::GetParamsL |
|
115 // Jump to RunL as soon as possible. |
|
116 // ---------------------------------------------------------------------------- |
|
117 // |
|
118 void CUSBUICableConnectedNotifier::GetParamsL(const TDesC8& /*aBuffer*/, |
|
119 TInt aReplySlot, const RMessagePtr2& aMessage) |
|
120 { |
|
121 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetParamsL")); |
|
122 if ( iReplySlot != 0 || iNeedToCompleteMessage) |
|
123 { |
|
124 User::Leave(KErrInUse); |
|
125 } |
|
126 |
|
127 iMessage = aMessage; |
|
128 iNeedToCompleteMessage = ETrue; |
|
129 iReplySlot = aReplySlot; |
|
130 |
|
131 // Call SetActive() so RunL() will be called by the active scheduler |
|
132 // |
|
133 iStatus = KRequestPending; |
|
134 TRequestStatus* stat = &iStatus; |
|
135 SetActive(); |
|
136 User::RequestComplete(stat, KErrNone); |
|
137 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetParamsL() completed")); |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------------------------------- |
|
141 // CUSBUICableConnectedNotifier::RunL |
|
142 // Ask user response and return it to caller. |
|
143 // ---------------------------------------------------------------------------- |
|
144 // |
|
145 void CUSBUICableConnectedNotifier::RunL() |
|
146 { |
|
147 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunL")); |
|
148 |
|
149 DisableKeylock(); |
|
150 SuppressAppSwitching(ETrue); |
|
151 RunQueryL(); |
|
152 SuppressAppSwitching(EFalse); |
|
153 RestoreKeylock(); |
|
154 |
|
155 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunL() completed")); |
|
156 } |
|
157 |
|
158 // ---------------------------------------------------------------------------- |
|
159 // CUSBUICableConnectedNotifier::Cancel() |
|
160 // Release all own resources (member variables) |
|
161 // ---------------------------------------------------------------------------- |
|
162 // |
|
163 void CUSBUICableConnectedNotifier::Cancel() |
|
164 { |
|
165 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() ")); |
|
166 |
|
167 CompleteMessage(KErrCancel); |
|
168 CUSBUINotifierBase::Cancel(); |
|
169 |
|
170 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::Cancel() completed")); |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------------------------------------- |
|
174 // CUSBUICableConnectedNotifier::GetPersonalityStringL |
|
175 // Get the strings for ask on connection message query |
|
176 // ----------------------------------------------------------------------------------------------------------- |
|
177 // |
|
178 void CUSBUICableConnectedNotifier::GetPersonalityStringL( |
|
179 HBufC*& aHeader,HBufC*& aDescription ) |
|
180 { |
|
181 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL")); |
|
182 TInt CurrentPersonalityID = 0; // The ID of current USB mode |
|
183 GetCurrentIdL(CurrentPersonalityID); |
|
184 RUsb usbman; |
|
185 User::LeaveIfError(usbman.Connect()); |
|
186 CleanupClosePushL(usbman); |
|
187 User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID, |
|
188 aDescription)); |
|
189 CleanupStack::PopAndDestroy(&usbman); |
|
190 |
|
191 aHeader = StringLoader::LoadL(R_USB_MODE_MSG_HEADER); |
|
192 |
|
193 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed")); |
|
194 } |
|
195 |
|
196 // ----------------------------------------------------------------------------------------------------------- |
|
197 // CUSBUICableConnectedNotifier::RunQueryL |
|
198 // Run the ask on connection message query |
|
199 // ----------------------------------------------------------------------------------------------------------- |
|
200 // |
|
201 void CUSBUICableConnectedNotifier::RunQueryL() |
|
202 { |
|
203 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 |
|
218 CompleteMessage(KErrCancel); |
|
219 CleanupStack::PopAndDestroy(description); |
|
220 CleanupStack::PopAndDestroy(header); |
|
221 |
|
222 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL completed")); |
|
223 } |
|
224 // ---------------------------------------------------------------------------- |
|
225 // CUSBUICableConnectedNotifier::GetCurrentIdL |
|
226 // get the current personality id |
|
227 // ---------------------------------------------------------------------------- |
|
228 // |
|
229 void CUSBUICableConnectedNotifier::GetCurrentIdL(TInt& aCurrentPersonality) |
|
230 { |
|
231 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL")); |
|
232 // Connecting and initialization: |
|
233 CRepository* repository = CRepository::NewL(KCRUidUsbWatcher); |
|
234 CleanupStack::PushL(repository); |
|
235 // Get the current USB mode |
|
236 repository->Get(KUsbWatcherPersonality, aCurrentPersonality); |
|
237 CleanupStack::PopAndDestroy(repository); |
|
238 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed")); |
|
239 } |
|
240 |
|
241 // ---------------------------------------------------------------------------- |
|
242 // CUSBUICableConnectedNotifier::ProcessCommandL() |
|
243 // when discreet pop up is tapped the command will be handled here |
|
244 // ---------------------------------------------------------------------------- |
|
245 // |
|
246 void CUSBUICableConnectedNotifier::ProcessCommandL(TInt aCommandId) |
|
247 { |
|
248 switch ( aCommandId ) |
|
249 { |
|
250 case EUSBUICmdDiscreetTapped: |
|
251 { |
|
252 TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),TUid::Uid(KUSBUIUid)); |
|
253 CreateChosenViewL(KUSBExe(),uidtype); |
|
254 } |
|
255 break; |
|
256 default: |
|
257 |
|
258 break; |
|
259 } |
|
260 } |
|
261 // --------------------------------------------------------------------------- |
|
262 // CUSBUICableConnectedNotifier::CreateChosenViewL() |
|
263 // creates the USB UI setting view |
|
264 // --------------------------------------------------------------------------- |
|
265 // |
|
266 void CUSBUICableConnectedNotifier::CreateChosenViewL(const TDesC & aProcessName,const TUidType & aUidType) const |
|
267 { |
|
268 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() ")); |
|
269 RProcess usbUiProcess; |
|
270 User::LeaveIfError(usbUiProcess.Create(aProcessName, KNullDesC, aUidType)); |
|
271 usbUiProcess.Resume(); |
|
272 usbUiProcess.Close(); |
|
273 FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() ")); |
|
274 |
|
275 } |
|
276 // End of File |