# HG changeset patch # User hgs # Date 1272053841 -10800 # Node ID 4712310216c0b20da37e148199fe0c3a2050de11 # Parent 47c263f7e521c62b31f30fe98e44ba86d72e166b 201003 diff -r 47c263f7e521 -r 4712310216c0 layers.sysdef.xml --- a/layers.sysdef.xml Tue Jan 26 12:55:41 2010 +0200 +++ b/layers.sysdef.xml Fri Apr 23 23:17:21 2010 +0300 @@ -1,9 +1,9 @@ - ]> - + @@ -11,14 +11,10 @@ - - - + + + + - - - - - diff -r 47c263f7e521 -r 4712310216c0 package_definition.xml --- a/package_definition.xml Tue Jan 26 12:55:41 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 47c263f7e521 -r 4712310216c0 sysdef_1_4_0.dtd --- a/sysdef_1_4_0.dtd Tue Jan 26 12:55:41 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff -r 47c263f7e521 -r 4712310216c0 sysdef_1_5_1.dtd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sysdef_1_5_1.dtd Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 47c263f7e521 -r 4712310216c0 usbclasses/group/bld.inf --- a/usbclasses/group/bld.inf Tue Jan 26 12:55:41 2010 +0200 +++ b/usbclasses/group/bld.inf Fri Apr 23 23:17:21 2010 +0300 @@ -23,9 +23,4 @@ //#include "../sicdusbplugin/group/bld.inf" //#include "../ptpserver/group/bld.inf" #include "../pictbridgeengine/group/bld.inf" -//Wusan@20091210: DEF143281: sf build break because of -// msmmplugin & usbhidclassdriver do not contribute to. -//PS, this comment and the below 2 line will be deleted after review! -//#include "../msmmplugin/group/bld.inf" -//#include "../usbhidclassdriver/group/bld.inf" #include "../usbphoneasmodem/group/bld.inf" diff -r 47c263f7e521 -r 4712310216c0 usbengines/usbwatcher/group/usbwatcherserver.mmp --- a/usbengines/usbwatcher/group/usbwatcherserver.mmp Tue Jan 26 12:55:41 2010 +0200 +++ b/usbengines/usbwatcher/group/usbwatcherserver.mmp Fri Apr 23 23:17:21 2010 +0300 @@ -37,6 +37,8 @@ SOURCE cusbdevicelock.cpp SOURCE cusbdevconstarter.cpp SOURCE cusbglobalsystemstateobserver.cpp +SOURCE tusbindicatorhandler.cpp + USERINCLUDE ../inc diff -r 47c263f7e521 -r 4712310216c0 usbengines/usbwatcher/inc/cusbwatcher.h --- a/usbengines/usbwatcher/inc/cusbwatcher.h Tue Jan 26 12:55:41 2010 +0200 +++ b/usbengines/usbwatcher/inc/cusbwatcher.h Fri Apr 23 23:17:21 2010 +0300 @@ -30,7 +30,7 @@ #include "debug.h" #include "musbwatchernotify.h" #include "cusbwatchersession.h" - +#include "tusbindicatorhandler.h" class CUsbActiveState; @@ -438,7 +438,16 @@ * OTG Watcher */ CUsbOtgWatcher* iOtgWatcher; //OTG - + + /* + * USB indicator handler to handle device side indicator + */ + TUsbIndicatorHandler iUsbIndicatorHandler; + + /* + * Starting mode is normal? + */ + TBool iNormalStart; }; #include "cusbwatcher.inl" diff -r 47c263f7e521 -r 4712310216c0 usbengines/usbwatcher/inc/tusbindicatorhandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbengines/usbwatcher/inc/tusbindicatorhandler.h Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: Header file for class TUsbIndicatorHandler +* +*/ + + +#ifndef TUSBINDICATORHANDLER_H +#define TUSBINDICATORHANDLER_H + +#include +#include + + +/** +* USB indicator handler class for device side. +* +* This class shows USB indicator when device state changes to Configured, +* and hides USB indicator when device leaves Configured state. Suspended + * state does not change the indicator. +* +* @since TB9.2 +*/ +NONSHARABLE_CLASS( TUsbIndicatorHandler ) + { + +public: + /** + * Constructor + */ + TUsbIndicatorHandler(); + + /** + * Set USB indicator (On/Off, maybe more in future) according to + * the change of USB device state + * + * @param aStateOld previous USB device state + * @param aStateNew current USB device state + */ + void HandleDeviceStateChange( TUsbDeviceState aStateOld, + TUsbDeviceState aStateNew ); + +private: + /** + * Show USB indicator (On/Off, maybe more in future) + * + * @since TB9.2 + * @param aUsbIndicatorState the state of the indicator, 0: OFF, 1: ON + */ + void ShowUsbIndicator( TInt aUsbIndicatorState ); + +private: + /** + * The device state before suspend. + * Used to filter out suspend from others; + */ + TUsbDeviceState iDevStateB4Suspend; + + ///////////////////////////////////////////////////////////////////////// + // Test code + friend class CtTUsbIndicatorHandler; + TBool iUsbIndicator; + // + ///////////////////////////////////////////////////////////////////////// + + }; + + +#endif // TUSBINDICATORHANDLER_H + +// End of File diff -r 47c263f7e521 -r 4712310216c0 usbengines/usbwatcher/rom/mtp_symbian_temp.iby --- a/usbengines/usbwatcher/rom/mtp_symbian_temp.iby Tue Jan 26 12:55:41 2010 +0200 +++ b/usbengines/usbwatcher/rom/mtp_symbian_temp.iby Fri Apr 23 23:17:21 2010 +0300 @@ -185,18 +185,6 @@ #endif // SYMBIAN_EXCLUDE_MTP #endif // MTP_TASKDP_IBY -// contactdp -#ifndef MTP_CONTACTDP_IBY -#define MTP_CONTACTDP_IBY -#if !defined(SYMBIAN_EXCLUDE_MTP) -// MTP Data Provider API -ECOM_PLUGIN(mtpcontactdp.dll, mtpcontactdp.rsc) -// MTP plugin registration resource file -data=EPOCROOT##epoc32\data\Z\resource\mtp\102872bd.rsc resource\mtp\102872bd.rsc -data=EPOCROOT##epoc32\data\Z\resource\apps\mtpcontactviewdefinition.rsc resource\apps\mtpcontactviewdefinition.rsc -#endif // SYMBIAN_EXCLUDE_MTP -#endif // MTP_CONTACTDP_IBY - // bluetooth #ifndef MTP_BT_IBY #define MTP_BT_IBY diff -r 47c263f7e521 -r 4712310216c0 usbengines/usbwatcher/src/cusbactivestate.cpp --- a/usbengines/usbwatcher/src/cusbactivestate.cpp Tue Jan 26 12:55:41 2010 +0200 +++ b/usbengines/usbwatcher/src/cusbactivestate.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -95,13 +95,25 @@ LOG_FUNC LEAVEIFERROR( iStatus.Int() ); // Close process if error happens here - LOG2( "DeviceState change: %d ==> %d", iPreviousState, iCurrentState ); + TUsbDeviceState newState = iCurrentState; iUsbMan.DeviceStateNotification( KUsbAllStates, iCurrentState, iStatus ); SetActive(); - iOwner.StateChangeNotify( iPreviousState, newState ); - iPreviousState = newState; + + // Notify only if there is a change + if ( newState != iPreviousState ) + { + LOG2( "USB device state changed: %d ==> %d", iPreviousState, + newState ); + iOwner.StateChangeNotify( iPreviousState, newState ); + iPreviousState = newState; + } + else + { + LOG2("USB device change ignored: %d -> %d", iPreviousState, + newState ); + } } // ---------------------------------------------------------------------------- diff -r 47c263f7e521 -r 4712310216c0 usbengines/usbwatcher/src/cusbwatcher.cpp --- a/usbengines/usbwatcher/src/cusbwatcher.cpp Tue Jan 26 12:55:41 2010 +0200 +++ b/usbengines/usbwatcher/src/cusbwatcher.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -222,7 +222,14 @@ { LOG_FUNC - if( IsDeviceA() ) // Will be handled by UsbOtgWatcher + // Handling USB indicator. This is valid for both A- and B-device cases. + // Not show USB indicator in charging mode + if ( iNormalStart ) + { + iUsbIndicatorHandler.HandleDeviceStateChange( aStateOld, aStateNew ); + } + + if ( IsDeviceA() ) // Will be handled by UsbOtgWatcher { LOG( "Device state change ignored by UsbWatcher in A-device state" ); return; @@ -533,13 +540,6 @@ LOG2( "aPersonalityId=%d, aNonBlocking=%d", aPersonalityId, aNonBlocking ); - if( IsDeviceA() ) - { - LOG( "SetPersonality not allowed in A-device state" ); - Notify( KErrAccessDenied ); - return; - } - // Check if personality is exist TBool found = EFalse; @@ -679,17 +679,21 @@ { LOG_FUNC - if( IsDeviceA() ) - { - LOG( "Not allowed in A-device state" ); - Notify( KErrAccessDenied ); - return; - } TUsbDeviceState state = iActiveState->CurrentState(); - LOG1( "Device state : %d", state ); + LOG2( "IsDeviceA: %d, Device state : %d", IsDeviceA(), state ); - if( state != EUsbDeviceStateUndefined ) + // As A-device, only cenrep will be updated for the reasons of + // - In A-host state, device state will be undefined + // - In A-peripheral state, personality change can not happen otherwise + // the connection will be lost + if ( IsDeviceA() || ( EUsbDeviceStateUndefined == state ) ) + { + // if no connection -> just save the setting + LOG( "CUsbWatcher::SwitchPersonality: Notify" ); + Notify( KErrNone ); + } + else { switch ( iState ) { @@ -722,12 +726,6 @@ break; } } - else - { - // if no connection -> just save the setting - LOG( "CUsbWatcher::SwitchPersonality: Notify" ); - Notify( KErrNone ); - } } // ---------------------------------------------------------------------------- @@ -743,6 +741,7 @@ if( iState == EUsbIdle ) { iStarted = EFalse; + iNormalStart = EFalse; if( globalState == ESwStateCharging ) { LOG( "Global state: charging" ); @@ -770,6 +769,7 @@ ( ESwStateNormalBTSap == globalState ) )) { LOG( "Global state: normal" ); + iNormalStart = ETrue; if( ! iUsbDeviceLock->Locked() ) { iGlobalStateObserver->Cancel(); diff -r 47c263f7e521 -r 4712310216c0 usbengines/usbwatcher/src/tusbindicatorhandler.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbengines/usbwatcher/src/tusbindicatorhandler.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,102 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: This implements TUsbIndicatorHandler class. +* +*/ + + +#include +#include // SAknNotifierPackage +#include //EAknIndicatorUSBConnection +#include "tusbindicatorhandler.h" +#include "debug.h" + +// --------------------------------------------------------------------------- +// C++ Constructor +// --------------------------------------------------------------------------- +// +TUsbIndicatorHandler::TUsbIndicatorHandler() + : iDevStateB4Suspend( EUsbDeviceStateUndefined ) + , iUsbIndicator(EFalse) + { + } + +// --------------------------------------------------------------------------- +// Change USB Indicator +// --------------------------------------------------------------------------- +// +void TUsbIndicatorHandler::HandleDeviceStateChange( TUsbDeviceState aStateOld, + TUsbDeviceState aStateNew ) + { + LOG_FUNC + + LOG2( "USB device state changed: %d ==> %d", aStateOld, aStateNew ); + + if ( EUsbDeviceStateConfigured == aStateNew ) // Entering configed state + { + // filter out case of configed -> suspended -> configed + if ( ( EUsbDeviceStateSuspended != aStateOld ) || + ( EUsbDeviceStateConfigured != iDevStateB4Suspend) ) + { + ShowUsbIndicator( ETrue ); + } + } + else if ( EUsbDeviceStateSuspended == aStateNew ) + // If current state is suspend, we do not change the indicator, but save + // the previous state + { + iDevStateB4Suspend = aStateOld; + } + else // New device state is not configured, nor suspended + { + // Hide USB indicator if previous state is either configured, or + // suspended AND state before is not configured + if( ( EUsbDeviceStateConfigured == aStateOld ) || + ( ( EUsbDeviceStateSuspended == aStateOld ) && + ( EUsbDeviceStateConfigured == iDevStateB4Suspend ) ) ) + { + ShowUsbIndicator( EFalse ); + } + } + } + +// --------------------------------------------------------------------------- +// Show USB Indicator +// --------------------------------------------------------------------------- +// +void TUsbIndicatorHandler::ShowUsbIndicator( TInt aUsbIndicatorState ) + { + LOG_FUNC + + iUsbIndicator = aUsbIndicatorState; + LOG1( "USB indicator state %d", aUsbIndicatorState ); + RNotifier notifier; + TInt err = notifier.Connect(); + if ( KErrNone == err ) + { + TPckgBuf< SAknNotifierPackage > pckg; + pckg().iParamData.iSmallIndicatorUid = + TUid::Uid( EAknIndicatorUSBConnection ); + pckg().iParamData.iValue = aUsbIndicatorState ? + EAknIndicatorStateOn : EAknIndicatorStateOff ; + notifier.StartNotifier( KAknSmallIndicatorUid, pckg ); + notifier.Close(); + } + else + { + LOG1( "RNotifier::Connect error: %d", err ); + } + } + +// End of file diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuinotif/group/bld.inf --- a/usbuis/usbuinotif/group/bld.inf Tue Jan 26 12:55:41 2010 +0200 +++ b/usbuis/usbuinotif/group/bld.inf Fri Apr 23 23:17:21 2010 +0300 @@ -28,7 +28,6 @@ PRJ_MMPFILES usbuinotif.mmp -usbavkonnotif.mmp PRJ_TESTMMPFILES diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuinotif/group/usbavkonnotif.mmp --- a/usbuis/usbuinotif/group/usbavkonnotif.mmp Tue Jan 26 12:55:41 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). - * All rights reserved. - * This component and the accompanying materials are made available - * under the terms of "Eclipse Public License v1.0" - * which accompanies this distribution, and is available - * at the URL "http://www.eclipse.org/legal/epl-v10.html". - * - * Initial Contributors: - * Nokia Corporation - initial contribution. - * - * Contributors: - * - * Description: Project definition file for project USBUINotif. - * - */ - -#include -#include //this is needed for RESOURCE_FILES_DIR - -TARGET usbavkonnotif.dll -TARGETTYPE dll -UID 0x101fdfae 0x102068DD -TARGETPATH SHARED_LIB_DIR - -CAPABILITY CAP_GENERAL_DLL -VENDORID VID_DEFAULT - -SOURCEPATH ../src - -SOURCE usbuincableconnectednotifier.cpp usbavkonmain.cpp -SOURCE usbnotifier.cpp - -USERINCLUDE ../inc - -SYSTEMINCLUDE ../../inc ../../../inc MW_LAYER_PLATFORM_EXPORT_PATH(SecondaryDisplay/) //for internal and private API headers - -MW_LAYER_SYSTEMINCLUDE -LIBRARY ECOM.LIB // Symbian E-Com Plugin definitions and types -LIBRARY euser.lib cone.lib // Symbian OS frameworklibraries -LIBRARY avkon.lib // UI library -LIBRARY bafl.lib // Basic Application Framework -LIBRARY commonengine.lib // Series 60 common components -LIBRARY eikcoctl.lib eiksrv.lib // Eikon libraries -LIBRARY eikdlg.lib // Eikon dialogs -LIBRARY estor.lib // for Cover Display UI support -LIBRARY FeatMgr.lib // for fetching if Cover Display is supported -LIBRARY centralrepository.lib // Central Repository -LIBRARY aknmemorycardui.lib // for unlocking the MMC -LIBRARY efsrv.lib // File server -LIBRARY eikcore.lib // for icons -LIBRARY aknskins.lib -LIBRARY aknskinsrv.lib -LIBRARY aknicon.lib -LIBRARY egul.lib -LIBRARY usbman.lib // for personality IDs and descriptions -LIBRARY aknnotifierwrapper.lib // Avkon's notifier wrapper -LIBRARY apparc.lib -LIBRARY akncapserverclient.lib // for suppressing the application key - -DEBUGLIBRARY flogger.lib // File logging services diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuinotif/group/usbuinotif.mmp --- a/usbuis/usbuinotif/group/usbuinotif.mmp Tue Jan 26 12:55:41 2010 +0200 +++ b/usbuis/usbuinotif/group/usbuinotif.mmp Fri Apr 23 23:17:21 2010 +0300 @@ -29,6 +29,7 @@ SOURCEPATH ../src SOURCE usbuinmain.cpp SOURCE usbnotifier.cpp +SOURCE usbuincableconnectednotifier.cpp SOURCE usbuinqueriesnotifiermdrv.cpp SOURCE usbuinotifotgwarning.cpp SOURCE usbuinotifotgerror.cpp @@ -47,8 +48,9 @@ USERINCLUDE ../inc -SYSTEMINCLUDE ../../inc ../../../inc MW_LAYER_PLATFORM_EXPORT_PATH(SecondaryDisplay/) //for internal and private API headers -SYSTEMINCLUDE /epoc32/include/ecom +SYSTEMINCLUDE ../../inc ../../../inc MW_LAYER_PLATFORM_EXPORT_PATH(secondarydisplay/) //for internal and private API headers +SYSTEMINCLUDE /EPOC32/INCLUDE/ECOM +SYSTEMINCLUDE /epoc32/include/mw/hb/hbcore MW_LAYER_SYSTEMINCLUDE @@ -74,6 +76,7 @@ LIBRARY aknnotifierwrapper.lib // Avkon's notifier wrapper LIBRARY apparc.lib LIBRARY akncapserverclient.lib // for suppressing the application key +LIBRARY hbcore.lib DEBUGLIBRARY flogger.lib // File logging services diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuinotif/inc/usbuincableconnectednotifier.h --- a/usbuis/usbuinotif/inc/usbuincableconnectednotifier.h Tue Jan 26 12:55:41 2010 +0200 +++ b/usbuis/usbuinotif/inc/usbuincableconnectednotifier.h Fri Apr 23 23:17:21 2010 +0300 @@ -20,8 +20,8 @@ // INCLUDES -#include -#include +#include +#include #include "usbnotifier.h" // Base class // CLASS DECLARATION @@ -31,8 +31,8 @@ * * @lib */ -NONSHARABLE_CLASS(CUSBUICableConnectedNotifier) : public CUSBUINotifierBase, - public MEikCommandObserver +NONSHARABLE_CLASS(CUSBUICableConnectedNotifier) : public CUSBUINotifierBase, + public MHbDeviceDialogObserver { public: // Constructors and destructor @@ -84,10 +84,22 @@ void GetParamsL(const TDesC8& aBuffer, TInt aReplySlot, const RMessagePtr2& aMessage); + +private: + // functions from MHbDeviceDialogObserver + /** - * Handles the command on USB connected note - */ - void ProcessCommandL(TInt aCommandId); + * lunches the QT usb ui setting + * @param aData is a CHbSymbianVariantMap daya which contains the keys + */ + void DataReceived(CHbSymbianVariantMap& aData); + /* + * Virtual function from MHbDeviceDialogObserver + * Not implemented + */ + void DeviceDialogClosed(TInt aCompletionCode); + + private: //New functions @@ -98,10 +110,12 @@ void GetCurrentIdL(TInt& aCurrentPersonality); /** * Get the mode name and header for current personality + * The parameters are pushed to the cleanup stack in order + * aDescription, aHeader. * @param aDescription The returned current personality string. * @param aHeader The header string for message query. */ - void GetPersonalityStringL(HBufC*& aHeader,HBufC*& aDescription ); + void GetPersonalityStringLC(HBufC*& aHeader,HBufC*& aDescription ); /** * Runs the connected discreet note @@ -110,16 +124,28 @@ /** - * creates the USB UI setting view - * @param aProcessName The process name (USBClassChangeUI.exe) + * launches the (USB) application + * @param aProcessName The process name (*.exe) * @param TUidType */ - void CreateChosenViewL(const TDesC & aProcessName,const TUidType & aUidType) const; + void LaunchApplication(const TDesC & aProcessName,const TUidType & aUidType) const; + + /** + * Adds a parameter to the dialog parameters. + */ + void AddParameterL( + CHbSymbianVariantMap* aParameters, + const TDesC& aKey, + const TAny* aData, + CHbSymbianVariant::TType aDataType); + private: /** * C++ default constructor. */ CUSBUICableConnectedNotifier(); + + CHbDeviceDialog* iDialog; }; #endif // USBUINCABLECONNECTEDNOTIFIER_H diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuinotif/rom/usbuinotif.iby --- a/usbuis/usbuinotif/rom/usbuinotif.iby Tue Jan 26 12:55:41 2010 +0200 +++ b/usbuis/usbuinotif/rom/usbuinotif.iby Fri Apr 23 23:17:21 2010 +0300 @@ -22,7 +22,6 @@ #ifdef __USB_MULTIPERSONALITY ECOM_PLUGIN(usbuinotif.dll, 102068DC.rsc) -file=ABI_DIR\BUILD_DIR\usbavkonnotif.dll SHARED_LIB_DIR\usbavkonnotif.dll #endif //__USB_MULTIPERSONALITY #endif //__USBUINOTIF_IBY__ \ No newline at end of file diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuinotif/src/usbavkonmain.cpp --- a/usbuis/usbuinotif/src/usbavkonmain.cpp Tue Jan 26 12:55:41 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -/* - * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). - * All rights reserved. - * This component and the accompanying materials are made available - * under the terms of "Eclipse Public License v1.0" - * which accompanies this distribution, and is available - * at the URL "http://www.eclipse.org/legal/epl-v10.html". - * - * Initial Contributors: - * Nokia Corporation - initial contribution. - * - * Contributors: - * - * Description: Methods for USB UI notifiers. - * - */ - -// INCLUDE FILES -#include -#include - -#include "usbuincableconnectednotifier.h" -#include "usbuinqueriesnotifier.h" -#include "usbuinotifdebug.h" - -// CONSTANTS -const TInt KUSBUINotifierArrayIncrement = 1; - - -// ================= EXPORTED FUNCTIONS ======================================= - -// ---------------------------------------------------------------------------- -// -// Instantiate notifiers -// -// ---------------------------------------------------------------------------- - -LOCAL_C void CreateUSBUINotifiersL( - CArrayPtrFlat* aNotifiers ) - { - FLOG(_L("[USBUINOTIF]\t CreateUSBUINotifiersL")); - - CUSBUICableConnectedNotifier* cableConnectedNotifier = - CUSBUICableConnectedNotifier::NewL(); - CleanupStack::PushL( cableConnectedNotifier ); - aNotifiers->AppendL( cableConnectedNotifier ); - CleanupStack::Pop( cableConnectedNotifier ); - - - FLOG(_L("[USBUINOTIF]\t CreateUSBUINotifiersL completed")); - } - -// ---------------------------------------------------------------------------- -// -// Lib main entry point: Creates a notifiers array. -// -// ---------------------------------------------------------------------------- - -EXPORT_C CArrayPtr* NotifierArray() - { - FLOG(_L("[USBUINOTIF]\t NotifierArray")); - - CArrayPtrFlat* notifiers = NULL; - - TRAPD( err, notifiers = - new (ELeave)CArrayPtrFlat( - KUSBUINotifierArrayIncrement )); - - if ( err == KErrNone ) - { - if( notifiers ) - { - TRAPD( errCreate, CreateUSBUINotifiersL( notifiers )); - if( errCreate ) - { - TInt count = notifiers->Count(); - while(count--) - { - (*notifiers)[count]->Release(); - } - delete notifiers; - notifiers = NULL; - } - - FLOG(_L("[USBUINOTIF]\t NotifierArray completed")); - } - } - else - { - FLOG(_L("[USBUINOTIF]\t NotifierArray Failed!!!")); - } - - return notifiers; - } - -// End of File diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp --- a/usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp Tue Jan 26 12:55:41 2010 +0200 +++ b/usbuis/usbuinotif/src/usbuincableconnectednotifier.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -21,32 +21,20 @@ #include #include // Localisation stringloader #include // Unicode character conversion utilities -#include -#include +#include #include // Own resources #include #include -//for loading icons USB fork and empty -#include -#include -#include -#include -//for cover display support -#include -#include // Dialog index for cover UI -#include #include // KExecutableImageUid -#include #include "usbuincableconnectednotifier.h" // Own class definition #include "usbuinotifdebug.h" // Debugging macros #include "UsbWatcherInternalCRKeys.h" -#include "usbpersonalityids.h" #include "usbuinotif.hrh" // Literals -_LIT(KUSBExe, "usbclasschangeui.exe"); -const TInt KUSBUIUid = 0x102068E2; +_LIT(KUSBExe, "usbapplication.exe"); +const TInt KUSBUIUid = 0x2002BCA3; _LIT(KFileDrive,"z:"); _LIT(KUSBUIconFileName, "usbui.mif"); @@ -91,6 +79,8 @@ //this virtual function call is to the local CUSBUICableConnectedNotifier:: //Cancel, not to any possibly derived class implementation. Cancel(); + delete iDialog; + FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::destructor completed")); } @@ -175,7 +165,7 @@ // Get the strings for ask on connection message query // ----------------------------------------------------------------------------------------------------------- // -void CUSBUICableConnectedNotifier::GetPersonalityStringL( +void CUSBUICableConnectedNotifier::GetPersonalityStringLC( HBufC*& aHeader,HBufC*& aDescription ) { FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL")); @@ -187,9 +177,9 @@ User::LeaveIfError(usbman.GetDescription(CurrentPersonalityID, aDescription)); CleanupStack::PopAndDestroy(&usbman); - + CleanupStack::PushL(aDescription); aHeader = StringLoader::LoadL(R_USB_MODE_MSG_HEADER); - + CleanupStack::PushL(aHeader); FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetPersonalityStringL completed")); } @@ -201,24 +191,45 @@ void CUSBUICableConnectedNotifier::RunQueryL() { FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL()")); - - HBufC* header = NULL; - HBufC* description =NULL; - GetPersonalityStringL(header, description); - - CleanupStack::PushL(header); - CleanupStack::PushL(description); - - TFileName usbUiIconFilename( KFileDrive ); - usbUiIconFilename += KDC_APP_BITMAP_DIR; - usbUiIconFilename += KUSBUIconFileName; - CAknDiscreetPopup::ShowGlobalPopupL(*header,*description, KAknsIIDQgnPropUsb, AknIconUtils::AvkonIconFileName(), - EMbmAvkonQgn_prop_usb, EMbmAvkonQgn_prop_usb_mask,KAknDiscreetPopupDurationLong, EUSBUICmdDiscreetTapped,( MEikCommandObserver* ) this); - CompleteMessage(KErrCancel); + _LIT(KNotificationType,"com.nokia.hb.devicenotificationdialog/1.0"); + _LIT(KTouchActivation, "touchActivation"); + _LIT(KIconName, "iconName"); + _LIT(KTitle, "title"); + _LIT(KText, "text"); + + HBufC* header = NULL; + HBufC* description =NULL; + GetPersonalityStringLC(header, description); + + TFileName usbUiIconFilename( KFileDrive ); + usbUiIconFilename += KDC_APP_BITMAP_DIR; + usbUiIconFilename += KUSBUIconFileName; + if( iDialog ) + { + delete iDialog; + iDialog = NULL; + } + iDialog = CHbDeviceDialog::NewL(); + CHbSymbianVariantMap *parameters =CHbSymbianVariantMap::NewL(); + CleanupStack::PushL(parameters); + + AddParameterL(parameters, KTitle, header, CHbSymbianVariant::EDes); + AddParameterL(parameters, KText, description, CHbSymbianVariant::EDes); + AddParameterL(parameters, KIconName, &usbUiIconFilename, CHbSymbianVariant::EDes); + TBool activation=ETrue; + AddParameterL(parameters, KTouchActivation, &activation, CHbSymbianVariant::EBool); + + FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL() show") ); + TBool error = iDialog->Show(KNotificationType ,*parameters, this); + FTRACE( FPrint( + _L( "[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL() error = %d" ), + error ) ); + + CleanupStack::PopAndDestroy(parameters); + CleanupStack::PopAndDestroy(header); CleanupStack::PopAndDestroy(description); - CleanupStack::PopAndDestroy(header); - + FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::RunQueryL completed")); } // ---------------------------------------------------------------------------- @@ -233,44 +244,100 @@ CRepository* repository = CRepository::NewL(KCRUidUsbWatcher); CleanupStack::PushL(repository); // Get the current USB mode - repository->Get(KUsbWatcherPersonality, aCurrentPersonality); + TInt ret = repository->Get(KUsbWatcherPersonality, aCurrentPersonality); + FTRACE( FPrint( + _L( "[USBWATCHER]\t CUSBUICableConnectedNotifier::GetCurrentIdL() ret = %d" ), + ret ) ); CleanupStack::PopAndDestroy(repository); FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::GetCurrentIdL completed")); } // ---------------------------------------------------------------------------- -// CUSBUICableConnectedNotifier::ProcessCommandL() -// when discreet pop up is tapped the command will be handled here +// CUSBUICableConnectedNotifier::DataReceived +// launches the QT usb ui setting // ---------------------------------------------------------------------------- // -void CUSBUICableConnectedNotifier::ProcessCommandL(TInt aCommandId) +void CUSBUICableConnectedNotifier::DataReceived(CHbSymbianVariantMap& aData) { - switch ( aCommandId ) - { - case EUSBUICmdDiscreetTapped: - { - TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00),TUid::Uid(KUSBUIUid)); - CreateChosenViewL(KUSBExe(),uidtype); - } - break; - default: - - break; - } + FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::DataReceived")); + _LIT(KResult, "result"); + _LIT(KActivated, "activated"); + TInt result = 0; + MDesCArray& keys = aData.Keys(); + HBufC* key = NULL; + for(TInt i = 0; i < keys.MdcaCount(); i++) + { + result = keys.MdcaPoint(i).Compare(KResult); + if (result == 0) + { + key = HBufC::New(KResult().Length()); + if (key) + { + *key = KResult; + const CHbSymbianVariant* variant = aData.Get(*key); + delete key; + HBufC* value = static_cast(variant->Data()); + result = value->Des().Compare(KActivated); + if (result == 0) + { + TUidType uidtype(KExecutableImageUid, TUid::Uid(0x00), + TUid::Uid(KUSBUIUid)); + LaunchApplication(KUSBExe(), uidtype); + } + break; + } + } + } } + +// ---------------------------------------------------------------------------- +// CUSBUICableConnectedNotifier::DeviceDialogClosed +// Not implemented +// ---------------------------------------------------------------------------- +// + void CUSBUICableConnectedNotifier::DeviceDialogClosed(TInt /*aCompletionCode*/) + { + // no implementation + } + // --------------------------------------------------------------------------- -// CUSBUICableConnectedNotifier::CreateChosenViewL() -// creates the USB UI setting view +// CUSBUICableConnectedNotifier::LaunchApplication() +// launches the application // --------------------------------------------------------------------------- // - void CUSBUICableConnectedNotifier::CreateChosenViewL(const TDesC & aProcessName,const TUidType & aUidType) const +void CUSBUICableConnectedNotifier::LaunchApplication(const TDesC & aProcessName, + const TUidType & aUidType) const { - FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() ")); - RProcess usbUiProcess; - User::LeaveIfError(usbUiProcess.Create(aProcessName, KNullDesC, aUidType)); - usbUiProcess.Resume(); - usbUiProcess.Close(); - FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::CreateDesiredViewL() ")); + FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication()")); + RProcess usbUiProcess; + TInt result = usbUiProcess.Create(aProcessName, KNullDesC, aUidType); + FTRACE( FPrint( + _L( "[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() result = %d" ), + result ) ); + usbUiProcess.Resume(); + usbUiProcess.Close(); + FLOG(_L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::LaunchApplication() completed")); + } +// --------------------------------------------------------------------------- +// CUSBUICableConnectedNotifier::AddParameter() +// Adds a string parameter to the dialog parameters. +// --------------------------------------------------------------------------- +// +void CUSBUICableConnectedNotifier::AddParameterL( + CHbSymbianVariantMap* aParameters, + const TDesC& aKey, + const TAny* aData, + CHbSymbianVariant::TType aDataType) + { + FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::AddStringParameter()") ); + FTRACE( FPrint( + _L( "[USBWATCHER]\t CUSBUICableConnectedNotifier::RunQueryL() aKey = %S" ), + &aKey ) ); + CHbSymbianVariant* variant = CHbSymbianVariant::NewL(aData, aDataType); + //aParameters takes variant ownership + User::LeaveIfError(aParameters->Add(aKey, variant)); + FLOG( _L("[USBUINOTIF]\t CUSBUICableConnectedNotifier::AddStringParameter() completed") ); } + // End of File diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuinotif/src/usbuinmain.cpp --- a/usbuis/usbuinotif/src/usbuinmain.cpp Tue Jan 26 12:55:41 2010 +0200 +++ b/usbuis/usbuinotif/src/usbuinmain.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -20,21 +20,17 @@ #include #include #include -#include -#include #include "usbuincableconnectednotifier.h" #include "usbuinqueriesnotifier.h" - - #include "usbuinotifdebug.h" #include "usbuinotifotgwarning.h" #include "usbuinotifotgerror.h" #include "usbuinotifmsmmerror.h" // CONSTANTS -const TInt KUSBUINotifierArrayIncrement = 4; -_LIT( KUSBUINotifdll, "usbavkonnotif.dll" ); +const TInt KUSBUINotifierArrayIncrement = 5; + // ================= EXPORTED FUNCTIONS ======================================= // ---------------------------------------------------------------------------- // @@ -46,20 +42,12 @@ { FLOG(_L("[USBUINOTIF]\t CreateUSBUINotifiersL")); - /* The CableconnectionNotifier is created on the Avkon Wrapper - * because it contains the discreet popups which are only possible - * to be launched in a UI framework - */ - CAknCommonNotifierWrapper* master = - CAknCommonNotifierWrapper::NewL(KCableConnectedNotifierUid, - KCableConnectedNotifierUid, - MEikSrvNotifierBase2::ENotifierPriorityVHigh, - KUSBUINotifdll, - 1); // no synchronous reply used. - CleanupStack::PushL(master); - - aNotifiers->AppendL(master ); - CleanupStack::Pop( master ); + CUSBUICableConnectedNotifier* cableConnectedNotifier = + CUSBUICableConnectedNotifier::NewL(); + CleanupStack::PushL( cableConnectedNotifier ); + aNotifiers->AppendL( cableConnectedNotifier ); + CleanupStack::Pop( cableConnectedNotifier ); + CUSBUIQueriesNotifier* queriesNotifier = CUSBUIQueriesNotifier::NewL(); CleanupStack::PushL( queriesNotifier ); aNotifiers->AppendL( queriesNotifier ); diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/icons/usb_icon_mode_2.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/icons/usb_icon_mode_2.svg Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/icons/usb_icon_mode_4.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/icons/usb_icon_mode_4.svg Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/icons/usb_icon_mode_5.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/icons/usb_icon_mode_5.svg Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/inc/mydebug.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/inc/mydebug.h Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,37 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#ifndef MYDEBUG_H +#define MYDEBUG_H + +#include + +#if defined(_DEBUG) + inline QDebug myDebug() + { + return qDebug(); + } +#else + inline QNoDebug myDebug() + { + return QNoDebug(); + } +#endif + + +#endif // MYDEBUG_H diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/inc/usbmainview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/inc/usbmainview.h Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,96 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef USBMAINVIEW_H +#define USBMAINVIEW_H + +#include +#include + +class UsbUiSettingModel; +class QGraphicsLinearLayout; +class HbListWidgetItem; +class HbListWidget; +class HbTextEdit; +class HbRadioButtonList; + +class UsbMainView : public HbView +{ + Q_OBJECT + friend class TestUsbUiModelActive; + +public: + explicit UsbMainView( QObject *parent = 0 ); + virtual ~UsbMainView(); + +public slots: + /** + * Update view item(s) between the selected rows. + * @param topLeft The top row index + * @param bottomRight The bottom row index + */ + void updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight); + + /* + * Set the personality user has selected in the radio button list + * @param personalityIndex The selection index in the radio button list + */ + void setPersonality( int personalityIndex ); + +signals: + +private: + /* + * creates the main view window row by row + */ + void createMainView(); + /* + * creates the first row in the view containing an icon and a mode name + * @param localPropertiesGroup main view layout + */ + void createIconNameRow(QGraphicsLinearLayout *localPropertiesGroup); + /* + * creates the second row from the view containing the description of the selected mode + * @param localPropertiesGroup main view layout + */ + void createDescriptionArea(QGraphicsLinearLayout *localPropertiesGroup); + /* + * creates the third row from the view containing the radio button list of the existing usb modes + * @param localPropertiesGroup main view layout + */ + void createRadioButtonArea(QGraphicsLinearLayout *localPropertiesGroup); + +private: + // main view layout owned by this class + QGraphicsLinearLayout *mMainLayout; + // setting model not owned by the view, + // has to be deleted + UsbUiSettingModel *mModel; + //owned by the view + HbListWidgetItem *mListItem; + // owned by the view + HbListWidget *mlist; + // owned by the view + HbTextEdit *mlabel; + // owned by the view + HbRadioButtonList *mradio; + // not owned by the view + // need to be deleted + HbIcon *mIcon ; +}; + +#endif /* USBMAINVIEW_H */ diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/inc/usbuimodelactive.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/inc/usbuimodelactive.h Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,121 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef USBUIMODELACTIVE_H +#define USBUIMODELACTIVE_H + +#include +#include +#include + +class UsbUiModelActivePrivate; + +/*! + \class UsbUiModelActive + \brief Helper class for using active objects in Qt classes. + + UsbUiModelActive is a helper class for using active objects + from any Qt class. It wraps a CActive-derived class in an interface + that uses Qt's signal-slot mechanism for communicating status changes + of the active object. + + */ +class UsbUiModelActive : public QObject +{ + Q_OBJECT + friend class UsbUiModelActivePrivate; + +public: + explicit UsbUiModelActive( int priority = CActive::EPriorityStandard, + QObject *parent = NULL ); + ~UsbUiModelActive(); + + inline TRequestStatus &RequestStatus(); + inline void SetActive(); + inline void Cancel(); + inline bool IsActive(); + +public: + int SetUsbPersonality(int personality); + void CancelSetPersonality(); + +signals: + void requestCompleted( int status ); + +private: + /*! + * emits a signal when the request is completed + * @param status is the error + */ + void emitRequestCompleted( int status ); + +private: + UsbUiModelActivePrivate *d; + + /** Handle to USBWatcher for setting the personality */ + RUsbWatcher iUsbWatcher; +}; + + +/*! + \class UsbUiModelActivePrivate + \brief Private class of UsbUiModelActive, for using active objects in Qt classes. + + UsbUiModelActivePrivate is a helper class for using active objects + from any Qt class. It derives from CActive and allows other classes to use + it for passing to asynchronous function calls through its RequestStatus method. + + */ +class UsbUiModelActivePrivate : public CActive +{ + friend class UsbUiModelActive; + +public: + explicit UsbUiModelActivePrivate( UsbUiModelActive *parent, int priority ); + ~UsbUiModelActivePrivate(); + +private: + virtual void RunL(); + virtual void DoCancel(); + virtual TInt RunError( TInt aError ); + +private: + UsbUiModelActive *q; + +}; + +inline bool UsbUiModelActive::IsActive() +{ + return d->IsActive(); +} + +inline TRequestStatus &UsbUiModelActive::RequestStatus() +{ + return d->iStatus; +} + +inline void UsbUiModelActive::SetActive() +{ + d->SetActive(); +} + +inline void UsbUiModelActive::Cancel() +{ + d->Cancel(); +} + +#endif /* USBUIMODELACTIVE_H */ diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/inc/usbuisettingmodel.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/inc/usbuisettingmodel.h Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,168 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef USBUISETTINGMODEL_H +#define USBUISETTINGMODEL_H + + +#include +#include +#include +#include +#include + +const int KDefaultColumn = 0; +typedef QList< QMap< int, QVariant > > UsbUiModelDataSource; + +class RUsb; +class UsbUiModelActive; + +class UsbUiSettingModel : public QAbstractItemModel +{ + Q_OBJECT + friend class TestUsbUiModelActive; + +public: +enum usbSettingsIndex { + DefaultMode, + Description, + UsbModeList, + EndOfSettings + }; +enum SettingsRoleValues { + SettingType = Qt::UserRole, + SettingsModeNameList, + }; +public: + UsbUiSettingModel( QObject *parent = 0 ); + virtual ~UsbUiSettingModel(); + + /* + * Returns the index of the item in the model specified by the given row, column and parent index. + * @param row is the row number of the specified item + * @param column is the column number of the specified item + * @param parent QModelIndex parent + */ + virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; + /* + * Returns QModelIndex() because this model item has no parent + * @param child is the index of item model, the parent of which is going to be returned + * @param child is not used in here + */ + virtual QModelIndex parent( const QModelIndex &child ) const; + /* + * Returns the number of rows under the given parent + * @param parent QModelIndex parent + */ + virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; + /* + * Returns the number of columns for the children of the given parent. + * @param parent QModelIndex parent + */ + virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; + /* + *Returns the data stored under the given role for the item referred to by the index. + */ + virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; + /* + * Sets the role data for the item at index to value. Returns true if successful; otherwise returns false. + */ + virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); + + const QModelIndex* sourceData() const; + +public slots: + /* + * Provides notification of changes in selected usb mode + * @param key is not used + * @param value is the value read from cenrep key + */ + void usbModeChanged( const XQSettingsKey &key, const QVariant &value ); + /* + * it checks the response from usbwatcher to see if the new mode change has been successful + * it will go back to the previous personality if it has not been successfull + * @param status is the error code returned from usbwatcher + */ + void setPersonalityCompleted (int status ); + +private: + /* + * creats the logical name of the modename string for the list + * @param modeId is the usb personality id + */ + QString modeListName( int modeId ); + /* + * Get the current USB personality ID + * Returns 0, if the key is missing or the value cannot be converted + * to integer. + * @return The current personality id + */ + int currentMode(); + /* + * sets the value to different roles of the model's first row + */ + void setDefaultModeSetting(); + /* + * sets the value to different roles of the model's description row + */ + void setDescriptionSetting(); + /** + * Set the USB mode list and the current selection in the list. + * The personality IDs are stored to mPersonalityIds and the personality names + * to mSettingsList. + * @param modeId The current mode ID + */ + bool setUsbModelistSetting( int modeId ); + /** + * calls the model's set functions + * @param modeId The current mode ID + */ + void setUsbSettings( int modeId ); + /** + * updates the model rows and emits signal datachanged + * @param newPersonality is the new personality id + */ + void setNewUsbMode(int newPersonality); + + /** + * Check from the USB Manager if the USB personality is hidden. + * @param usbman Already opened USB Manager session + * @param personalityId The ID of the personality to be checked. + * @return For hidden personality, true is returned. + */ + bool isPersonalityHidden(RUsb &usbman, TInt personalityId); + + /** + * Check if the USB personality is hidden. + * The personality is hidden, if it does not exist in mPersonalityIds. + * @param personalityId The ID of the personality to be checked. + * @return For hidden personality, true is returned. + */ + bool isPersonalityHidden(TInt personalityId); + private: + + UsbUiModelDataSource mSettingsList; + int mCurrentMode; + // stored, so that we can show the correct personality when it fails to set the new one + int mPreviousMode; + + XQSettingsManager mSettingsManager; + QList mPersonalityIds; + UsbUiModelActive *mModelActive; +}; + +#endif // USBUISETTINGMODEL_H diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/inc/usbviewmanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/inc/usbviewmanager.h Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef USBVIEWMANAGER_H +#define USBVIEWMANAGER_H + +#include "usbmainview.h" + + +class HbMainWindow; + +class UsbViewManager : public QObject + { + Q_OBJECT + +public: + explicit UsbViewManager(HbMainWindow* mainWindow, QObject *parent = 0 ); + ~UsbViewManager(); + + void addView(); + +private: + HbMainWindow* mWindow; + UsbMainView* mMainView; // owned + + }; + + +#endif /* USBVIEWMANAGER_H */ diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/rom/usbsettings.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/rom/usbsettings.iby Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef USBSETTING_IBY +#define USBSETTING_IBY +// Use standard macros +#include + +file=/epoc32/release/armv5/urel/usbapplication.exe PROGRAMS_DIR/usbapplication.exe +data=/epoc32/data/z/resource/apps/usbapplication.rsc APP_RESOURCE_DIR/usbapplication.rsc +data=/epoc32/data/z/private/10003a3f/import/apps/usbapplication_reg.rsc /private/10003a3f/import/apps/usbapplication_reg.rsc +data=/epoc32/data/z/resource/usbapplication.qm RESOURCE_FILES_DIR/usbapplication.qm + +#endif diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/main.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +#include +#include +#include +#include +#include "usbviewmanager.h" + +int main(int argc, char *argv[]) +{ + HbApplication app(argc, argv); + + // add translator for application library + QString locale = QLocale::system().name(); + QTranslator translator; + QString filename = QString("usbapplication_") + locale; +#ifdef Q_OS_SYMBIAN + // TRAP is must here, otherwise it crashes +TRAP_IGNORE( + bool loaded(false); + loaded = translator.load( filename, QString("z:/resource") ); + if (!loaded) + translator.load(filename, QString("c:/resource") ); +); +#else + translator.load(filename, QString("resource") ); +#endif //Q_OS_SYMBIAN + app.installTranslator(&translator); + + HbMainWindow mainWindow; + + // create the view manager, which handles 3 HbViews and add into mainWindow. + UsbViewManager* mViewManager = new UsbViewManager( &mainWindow, &app ); + mViewManager->addView(); + + mainWindow.show(); + return app.exec(); +} diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbapplication.qm Binary file usbuis/usbuiqt/src/usbapplication.qm has changed diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbapplication.qrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbapplication.qrc Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,6 @@ + + + + usbview.docml + + diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbapplication.ts --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbapplication.ts Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,126 @@ + + + + + + Description for USB Ovi Suite personality. This gives user help about the selected personality. + Manage your phone with Ovi Suite and sync your media content. + Manage your phone with Ovi Suite and sync your media content. + + Text ID + description + Te + False + + + USB mode name for Ovi Suite personality. This is used in USB application in a radio button list. Note that this string should use exactly the same words as txt_usb_modename_5. + Ovi Suite + Ovi Suite + + Comment + modelistname + Co + False + + + USB mode name for Mass storage personality. This is used in USB application in a radio button list. Note that this string should use exactly the same words as txt_usb_modename_2. + Mass storage + Mass storage + + Layout ID + modelistname + La + False + + + USB mode name for Mass storage personality. This is used in USB application as the default (selected) mode. + Mass storage + Mass storage + + View ID (draft) + modename + Vi + False + + + USB mode name for Phone as modem personality. This is used in USB application in a radio button list. Note that this string should use exactly the same words as txt_usb_modename_6. + Connect PC to Web + Connect PC to Web + + + modelistname + + False + + + Description for USB Mass storage personality. This gives user help about the selected personality. + Access your phoneÂ’s memory card from the device you are connected to. + Access your phoneÂ’s memory card from the device you are connected to. + + Position ID + description + Po + False + + + USB mode name for MTP personality. This is used in USB application in a radio button list. Note that this string should use exactly the same words as txt_usb_modename_4. + Media transfer + Media transfer + + + modelistname + + False + + + USB mode name for Ovi Suite personality. This is used in USB application as the default (selected) mode. + Ovi Suite + Ovi Suite + + File name + modename + Fi + False + + + Description for USB Phone as Modem personality. This gives user help about the selected personality. + Use your mobile phone as a modem + Use your mobile phone as a modem + + + description + + False + + + Description for USB MTP personality. This gives user help about the selected personality. + Sync your media content with Windows Media Player or Nokia Ovi Player, or connect to compatible stereos. + Sync your media content with Windows Media Player or Nokia Ovi Player, or connect to compatible stereos. + + + description + + False + + + USB mode name for Phone as Modem personality. This is used in USB application as the default (selected) mode. + Connect PC to Web + Connect PC to Web + + + modename + + False + + + USB mode name for MTP personality. This is used in USB application as the default (selected) mode. + Media transfer + Media transfer + + + modename + + False + + + diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbapplication.xls Binary file usbuis/usbuiqt/src/usbapplication.xls has changed diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbapplication_reg.rss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbapplication_reg.rss Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,18 @@ +// ============================================================================ +// * Generated by qmake (2.01a) (Qt 4.6.0) on: 2009-12-16T13:39:42 +// * This file is generated by qmake and should not be modified by the +// * user. +// ============================================================================ + +#include +#include + +UID2 KUidAppRegistrationResourceFile +UID3 0xECD2B4FE + +RESOURCE APP_REGISTRATION_INFO + { + app_file="usbapplication"; + localisable_resource_file="\\resource\\apps\\usbapplication"; + + } diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbicons.qrc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbicons.qrc Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,7 @@ + + + ../icons/usb_icon_mode_2.svg + ../icons/usb_icon_mode_4.svg + ../icons/usb_icon_mode_5.svg + + diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbmainview.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbmainview.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,180 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +#include "usbmainview.h" +#include +#include +#include +#include +#include +#include + +#include "usbuisettingmodel.h" +#include "mydebug.h" +/*! + * default constructor + */ +UsbMainView::UsbMainView( QObject *parent ) +: HbView(), mModel(NULL) +{ + myDebug() << ">>> UsbMainView::UsbMainView"; + setParent( parent ); + setTitle( qtTrId("USB") ); + mMainLayout = new QGraphicsLinearLayout( Qt::Vertical, this ); + mModel = new UsbUiSettingModel(); + createMainView(); + setLayout( mMainLayout ); + myDebug() << "<<< UsbMainView::UsbMainView"; +} + +/*! + * creates the main view + */ +void UsbMainView::createMainView() +{ + myDebug() << ">>> UsbMainView::createMainView"; + QGraphicsLinearLayout *mainViewLayout = new QGraphicsLinearLayout( Qt::Vertical, mMainLayout ); + mListItem = NULL; + mlist = NULL; + mlabel = NULL; + mradio = NULL; + mIcon = NULL; + createIconNameRow( mainViewLayout ); + createDescriptionArea( mainViewLayout ); + createRadioButtonArea( mainViewLayout ); + mMainLayout->addItem( mainViewLayout ); + bool connected = connect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), + this, SLOT( updateSettingItems( QModelIndex, QModelIndex ) ) ); + myDebug() << "<<< UsbMainView::createMainView model connected=" << connected; + connected = connect(mradio, SIGNAL( itemSelected( int ) ), + this, SLOT( setPersonality( int ) ) ); + myDebug() << "<<< UsbMainView::createMainView mradio connected=" << connected; + myDebug() << "<<< UsbMainView::createMainView"; +} +/*! + * creating the creates the first row in the view containing an icon and a mode name + */ +void UsbMainView::createIconNameRow( QGraphicsLinearLayout *aLocalPropertiesGroup ) +{ + myDebug() << ">>> UsbMainView::createIconNameRow"; + QGraphicsLinearLayout *listLayout = new QGraphicsLinearLayout( Qt::Vertical, mMainLayout ); + mlist = new HbListWidget( this ); + mlist->setMaximumSize( 300, 50 ); //todo + mListItem= new HbListWidgetItem(); + QModelIndex index = mModel->index( UsbUiSettingModel::DefaultMode, KDefaultColumn ); + // QVariant iconName = mModel->data( index, Qt::DecorationRole ); + mIcon = new HbIcon( mModel->data( index, Qt::DecorationRole ).toString() ); + mListItem->setDecorationIcon( *mIcon ); + mListItem->setText( mModel->data( index,Qt::DisplayRole ).toString() ); + mListItem->setText( mModel->data( index,Qt::DisplayRole ).toString() ); + mlist->insertItem( 1, mListItem ); + listLayout->addItem( mlist ); + aLocalPropertiesGroup->addItem( listLayout ); + myDebug() << "<<< UsbMainView::createIconNameRow"; +} +/*! + * creates the second row from the view containing the description of the selected mode + */ +void UsbMainView::createDescriptionArea( QGraphicsLinearLayout *aLocalPropertiesGroup ) +{ + myDebug() << ">>> UsbMainView::createDescriptionArea"; + QGraphicsLinearLayout *desLayout = new QGraphicsLinearLayout( Qt::Vertical, mMainLayout ); + QModelIndex index = mModel->index( UsbUiSettingModel::Description, KDefaultColumn ); + mlabel = new HbTextEdit( mModel->data( index, Qt::DisplayRole ).toString() ); + mlabel->setReadOnly( true ); + mlabel->setCursorVisibility( Hb::TextCursorHidden ); + desLayout->addItem( mlabel ); + desLayout->setAlignment( mlabel, Qt::AlignTop ); + aLocalPropertiesGroup->addItem( desLayout ); + myDebug() << "<<< UsbMainView::createDescriptionArea"; +} + +/*! + * creates the third row from the view containing the radio button list of the existing usb modes + */ +void UsbMainView::createRadioButtonArea(QGraphicsLinearLayout *aLocalPropertiesGroup) +{ + myDebug() << ">>> UsbMainView::createRadioButtonArea"; + QGraphicsLinearLayout *radioLayout = new QGraphicsLinearLayout( Qt::Vertical, mMainLayout ); + QModelIndex index = mModel->index( UsbUiSettingModel::UsbModeList, KDefaultColumn ); + QStringList radioList = mModel->data( index, UsbUiSettingModel::SettingsModeNameList ).toStringList(); + int selectedIndex = mModel->data( index, Qt::EditRole ).toInt(); + mradio = new HbRadioButtonList( radioList, selectedIndex ); + radioLayout->addItem( mradio ); + radioLayout->setAlignment( mradio, Qt::AlignBottom ); + aLocalPropertiesGroup->addItem(radioLayout); + myDebug() << "<<< UsbMainView::createRadioButtonArea"; +} + +/*! + Slot for receiving notification of data changes from the model. + Identify the setting changed and update the corresponding UI item. + */ +void UsbMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight) +{ + myDebug() << ">>> UsbMainView::updateSettingItems"; + // update only the part of the view specified by the model row(s) + for ( int row = topLeft.row(); row <= bottomRight.row(); row++ ) { + myDebug() << " UsbMainView::updateSettingItems row=" << row; + QModelIndex index = mModel->index( row, KDefaultColumn ); + // Distinguish which setting value is changed. + switch ( row ) { + case UsbUiSettingModel::DefaultMode : + // set the selected personality icon and name + mIcon->setIconName( mModel->data( index, Qt::DecorationRole ).toString() ); + mListItem->setDecorationIcon( *mIcon ); + mListItem->setText( mModel->data( index,Qt::DisplayRole ).toString() ); + break; + case UsbUiSettingModel::Description : + // set the description of the selected personality. + mlabel->setPlainText( mModel->data( index, Qt::DisplayRole ).toString() ); + mlabel->setReadOnly( true ); + mlabel->setCursorVisibility( Hb::TextCursorHidden ); + break; + case UsbUiSettingModel::UsbModeList : + // only the selection can change, no changes in the list of personalities + mradio->setSelected( mModel->data( index, Qt::EditRole ).toInt() ); + break; + default : + myDebug() << " UsbMainView::updateSettingItems unknown row " << row; + break; + } + } + myDebug() << "<<< UsbMainView::updateSettingItems"; +} + +/* + * Slot for receiving notification from the change in radio button list + */ +void UsbMainView::setPersonality( int personalityIndex ) +{ + myDebug() << ">>> UsbMainView::setPersonality"; + QModelIndex index = mModel->index( UsbUiSettingModel::UsbModeList, KDefaultColumn ); + mModel->setData( index, personalityIndex, Qt::EditRole ); + myDebug() << "<<< UsbMainView::setPersonality"; +} + +/*! + * Destructor + * destructs the items which are not owned by this class + */ +UsbMainView::~UsbMainView() +{ + myDebug() << ">>> UsbMainView::~UsbMainView"; + delete mModel; + delete mIcon; + myDebug() << "<<< UsbMainView::~UsbMainView"; +} diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbuimodelactive.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbuimodelactive.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,136 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "usbuimodelactive.h" +#include "mydebug.h" + +//const ?type ?constant_var = ?constant; + + +/*! + Constructor. + */ +UsbUiModelActive::UsbUiModelActive( int priority, QObject *parent ) +: QObject( parent ) +{ + myDebug() << ">>> UsbUiModelActive::UsbUiModelActive"; + d = new UsbUiModelActivePrivate( this, priority ); + int err= iUsbWatcher.Connect(); + myDebug() << "iUsbWatcher.Connect() returned "; + myDebug() << err; + myDebug() << "<<< UsbUiModelActive::UsbUiModelActive"; +} + +/*! + Destructor. + */ +UsbUiModelActive::~UsbUiModelActive() +{ + myDebug() << ">>> UsbUiModelActive::~UsbUiModelActive"; + delete d; + iUsbWatcher.Close(); + myDebug() << "<<< UsbUiModelActive::~UsbUiModelActive"; +} +/*! + * emits a signal when the request is completed + */ +void UsbUiModelActive::emitRequestCompleted( int status ) +{ + myDebug() << ">>> UsbUiModelActive::emitRequestCompleted status: "; + myDebug() << status; + emit requestCompleted( status ); + myDebug() << "<<< UsbUiModelActive::emitRequestCompleted"; +} + +/*! + * UsbUiModelActive::SetUSBModeL + * Sets the Central Repository key to the parameter. + */ +int UsbUiModelActive::SetUsbPersonality(int personality) + { + myDebug() << ">>> UsbUiModelActive::SetUsbPersonality"; + myDebug() << "requested personality is "; + myDebug() << personality; + // Change the personality asynchrously, result checked in RunL() + if( IsActive() ) + { + Cancel(); + } + myDebug() << "setting new personality"; + iUsbWatcher.SetPersonality(RequestStatus(), personality); + SetActive(); + myDebug() << "<<< UsbUiModelActive::SetUsbPersonality, returns 0"; + return 0; + } +/*! + * cancles the personality set in usbwatcher + */ +void UsbUiModelActive::CancelSetPersonality() + { + iUsbWatcher.CancelSetPersonality(); + } + +/*! + Constructor. + */ +UsbUiModelActivePrivate::UsbUiModelActivePrivate( + UsbUiModelActive *parent, int priority ) +: CActive( (TInt) priority ), q( parent ) +{ + myDebug() << ">>> UsbUiModelActivePrivate::UsbUiModelActivePrivate"; + CActiveScheduler::Add( this ); + myDebug() << "<<< UsbUiModelActivePrivate::UsbUiModelActivePrivate"; +} + + +/*! + Destructor. + */ +UsbUiModelActivePrivate::~UsbUiModelActivePrivate() +{ + Cancel(); +} + + +/*! + * Called by the active scheduler when the request has been completed. + */ +void UsbUiModelActivePrivate::RunL() +{ + myDebug() << ">>> UsbUiModelActivePrivate::RunL"; + q->emitRequestCompleted( iStatus.Int() ); + myDebug() << "<<< UsbUiModelActivePrivate::RunL"; +} + + +/*! + Called by the active scheduler when the request has been cancelled. + */ +void UsbUiModelActivePrivate::DoCancel() +{ + q->CancelSetPersonality(); +} + + +/*! + Called by the active scheduler when an error in RunL has occurred. + */ +TInt UsbUiModelActivePrivate::RunError( TInt aError ) +{ + q->emitRequestCompleted( aError ); + return KErrNone; +} diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbuisettingmodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbuisettingmodel.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,362 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "usbuisettingmodel.h" +#include "usbuimodelactive.h" +#include "mydebug.h" +#include +#include +#include +#include + +const QString TextIdPrefix = ("txt_usb_"); +const QString ModeIconNamePrefix = (":/icons/usb_icon_mode_"); + +/*! + Constructor. + */ +UsbUiSettingModel::UsbUiSettingModel( QObject *parent ) + : QAbstractItemModel( parent ) +{ + mModelActive = new UsbUiModelActive(); + + for ( int i = 0; i < UsbUiSettingModel::EndOfSettings; i++ ) { + // Initialize the list with empty values. + mSettingsList.append( QMap< int, QVariant >() ); + } + + mCurrentMode = currentMode(); + mPreviousMode = mCurrentMode; + setUsbSettings(mCurrentMode); + bool ret = mSettingsManager.startMonitoring( + XQSettingsKey( XQSettingsKey::TargetCentralRepository, + KCRUidUsbWatcher.iUid, KUsbWatcherPersonality ) ); + myDebug() << ">>> UsbUiSettingModel::startMonitoring value=" + << ret; + + // signal: personality changed in the central repository + connect( &mSettingsManager, + SIGNAL( valueChanged( const XQSettingsKey&, const QVariant& ) ), + this, + SLOT( usbModeChanged( const XQSettingsKey&, const QVariant& ) ) ); + + // signal: response from usbwatcher to our attempt to set the personality + connect( mModelActive, + SIGNAL( requestCompleted( int status ) ), + this, + SLOT( setPersonalityCompleted (int status ))); + +} +/*! + * calls the model's set functions to initialize the model's data + */ +void UsbUiSettingModel::setUsbSettings( int aModeId ) + { + setUsbModelistSetting( aModeId ); + setDefaultModeSetting(); + setDescriptionSetting(); + } + +/*! + Destructor. + */ +UsbUiSettingModel::~UsbUiSettingModel() +{ + myDebug() << ">>> UsbUiSettingModel::~UsbUiSettingModel"; + mSettingsManager.stopMonitoring( + XQSettingsKey( XQSettingsKey::TargetCentralRepository, + KCRUidUsbWatcher.iUid, KUsbWatcherPersonality ) ); + delete mModelActive; + myDebug() << "<<< UsbUiSettingModel::~UsbUiSettingModel"; +} + +/*! + Provides notification of changes in selected usb mode + */ +void UsbUiSettingModel::usbModeChanged( const XQSettingsKey &key, + const QVariant &value ) +{ +Q_UNUSED(key); + myDebug() << ">>> UsbUiSettingModel::usbModeChanged"; + // key is not checked, as we monitor only one key + + setNewUsbMode(value.toInt()); + + myDebug() << "<<< UsbUiSettingModel::usbModeChanged"; +} +/*! + * updates the model rows and emits signal datachanged + */ +void UsbUiSettingModel::setNewUsbMode(int newPersonality) + + { + myDebug() << ">>> UsbUiSettingModel::setNewUsbMode value=" + << newPersonality; + + mCurrentMode = newPersonality; + setUsbSettings(mCurrentMode); + + emit dataChanged( createIndex( DefaultMode, KDefaultColumn ), + createIndex( UsbModeList, KDefaultColumn ) ); + + myDebug() << "<<< UsbUiSettingModel::setNewUsbMode"; + } +/*! + * Returns the index of the item in the model specified by the given row, column and parent index. + */ +QModelIndex UsbUiSettingModel::index( int row, int column, const QModelIndex &parent ) const +{ + return hasIndex( row, column, parent ) ? createIndex( row, column ) : QModelIndex(); +} + + +/* + This model does not support hierarchy, so this returns an empty model index. + */ +QModelIndex UsbUiSettingModel::parent( const QModelIndex &child ) const +{ + Q_UNUSED( child ); + return QModelIndex(); +} +/*! + * Returns the number of rows under the given parent + */ +int UsbUiSettingModel::rowCount( const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + return mSettingsList.count(); +} + + +/*! + * Returns the number of columns for the children of the given parent. + * This model is one-dimensional, so this returns 1. + */ +int UsbUiSettingModel::columnCount( const QModelIndex &parent ) const +{ + Q_UNUSED( parent ); + return 1; +} +/*! + * Returns the data stored under the given role for the item referred to by the index. + */ +QVariant UsbUiSettingModel::data( const QModelIndex &index, int role ) const +{ + return mSettingsList.value( index.row() ).value( role ); +} + + +/*! + * This is called when usb mode is changed, it only sets the personality when the given role is EditRole + */ +bool UsbUiSettingModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + myDebug() << ">>> UsbUiSettingModel::setData"; + bool success = false; + if ( role == Qt::EditRole ) { + // Only allow changes on the value with role EditRole. Others are managed here. + switch ( index.row() ) { + case UsbModeList: { + mModelActive->SetUsbPersonality( mPersonalityIds.at( value.toInt() ) ); + success = true; + // also update the rest of the model with the about to be selected mode right away + setNewUsbMode(mPersonalityIds.at( value.toInt() )); + break; + } + case DefaultMode: + //no break + case Description: + //no break + default: + myDebug() << " UsbUiSettingModel::setData not supported row " << index.row(); + break; + } + } + myDebug() << "<<< UsbUiSettingModel::setData return " << success; + return success; +} + +/*! + * Getter for the source data. + */ +const QModelIndex* UsbUiSettingModel::sourceData() const +{ + return new QModelIndex( createIndex( 0, 0 ) ); +} + +/*! + * creats the logical name of the modename string for the list + */ +QString UsbUiSettingModel::modeListName( int modeId ) +{ + QString textId = TextIdPrefix + "modelistname_" + QString::number( modeId ); + QString modeName = qtTrId( textId.toAscii() ); + return modeName; +} + +/*! + * Get the current USB mode (personality) ID + */ +int UsbUiSettingModel::currentMode() +{ + myDebug() << ">>> UsbUiSettingModel::CurrentMode"; + int currentMode = mSettingsManager.readItemValue( + XQSettingsKey( XQSettingsKey::TargetCentralRepository, + KCRUidUsbWatcher.iUid, KUsbWatcherPersonality ) ).toInt(); + myDebug() << "<<< UsbUiSettingModel::CurrentMode " << currentMode; + return currentMode; +} + +/*! + * sets the value to different roles of the model's first row + */ +void UsbUiSettingModel::setDefaultModeSetting() +{ + QString iconName; + QString modeName; + //empty iconName and modeName are used for a hidden personality + if ( !isPersonalityHidden(mCurrentMode) ) { + iconName = ModeIconNamePrefix + QString::number( mCurrentMode ) + ".svg"; + QString textId = TextIdPrefix + "modename_" + QString::number( mCurrentMode ); + modeName = qtTrId( textId.toAscii() ); + } + + myDebug() << ">>> UsbUiSettingModel::setDefaultModeSetting iconName=" + << iconName << " modeName=" << modeName; + QMap< int, QVariant > val = mSettingsList.at( DefaultMode ); + if ( val.isEmpty() ) { + val[ SettingType ] = QVariant( DefaultMode ); + } + val[ Qt::DecorationRole ] = QVariant(iconName) ; + val[ Qt::DisplayRole ]= QVariant(modeName) ; + mSettingsList.replace( DefaultMode, val ); + myDebug() << "<<< UsbUiSettingModel::setDefaultModeSetting"; +} + +/*! + Updates all values related to the mode description. + */ +void UsbUiSettingModel::setDescriptionSetting() +{ + QString description; + //the description will be empty for a hidden personality + if ( !isPersonalityHidden(mCurrentMode) ) { + QString textId = TextIdPrefix + "description_" + + QString::number( mCurrentMode ); + description = qtTrId( textId.toAscii() ); + } + myDebug() << ">>> UsbUiSettingModel::setDescriptionSetting description=" + << description; + QMap< int, QVariant > val = mSettingsList.at( Description ); + if ( val.isEmpty() ) { + + val[ SettingType ] = QVariant( Description ); + + } + // The display role stores the string representation of the actual value. + val[ Qt::DisplayRole ] = QVariant( description ); + mSettingsList.replace( Description, val ); + myDebug() << "<<< UsbUiSettingModel::setDescriptionSetting"; +} + +/*! + Updates all values related to the visibility setting. + Updates the selectable USB modes only in the 1st call. + */ +bool UsbUiSettingModel::setUsbModelistSetting( int aModeId ) +{ + myDebug() << ">>> UsbUiSettingModel::setUsbModelistSetting aModeIndex=" + << aModeId; + bool ret = true; + QMap< int, QVariant > val = mSettingsList.at(UsbModeList); + if ( val.isEmpty() ) { + val[ SettingType ] = QVariant( UsbModeList ); + + RUsb iUsbman; + if ( iUsbman.Connect() == KErrNone ) { + + RArray personalityIds; + mPersonalityIds.clear(); + if ( iUsbman.GetPersonalityIds( personalityIds ) == KErrNone ) { + QStringList modeList; + for ( int i = 0; i < personalityIds.Count(); i++ ) { + if ( !isPersonalityHidden(iUsbman, personalityIds[i]) ) { + mPersonalityIds.append( personalityIds[i] ); + modeList.append( modeListName( mPersonalityIds[i] ) ); + } + } + val[ SettingsModeNameList ] = QVariant( modeList ); + } + } + else{ + ret = false; + } + iUsbman.Close(); + } + //index will be -1 for hidden personality + val[ Qt::EditRole ] = QVariant( mPersonalityIds.indexOf(aModeId) ); + mSettingsList.replace( UsbModeList, val ); + myDebug() << "<<< UsbUiSettingModel::setUsbModelistSetting"; + return ret; +} + +/*! + * it checks the response from usbwatcher to see if the new mode change has been successful + * it will go back to the previous personality if it has not been successfull + */ +void UsbUiSettingModel::setPersonalityCompleted (int status ) +{ + myDebug() << ">>> UsbUiSettingModel::setPersonalityCompleted status= " + << status; + // status contains Symbian error code from usbwatcher + // if the status is KErrNone, we are ready to process the next request + if (status != KErrNone) + { + // changing the personality failed, so we need to set back the previous personality + // the value will be read from central repository and also updates mCurrentMode + mPreviousMode = mSettingsManager.readItemValue( + XQSettingsKey( XQSettingsKey::TargetCentralRepository, + KCRUidUsbWatcher.iUid, KUsbWatcherPersonality ) ).toInt(); + setNewUsbMode(mPreviousMode); + } + + // after handling the return code we know the the current personality works + // and we will not go back to the previous one + mPreviousMode = mCurrentMode; + myDebug() << "<<< UsbUiSettingModel::setPersonalityCompleted"; +} + +bool UsbUiSettingModel::isPersonalityHidden(RUsb &usbman, TInt personalityId) +{ + myDebug() << ">>> UsbUiSettingModel::isPersonalityHidden from USB Manager"; + bool hidden = false; + TUint32 property = 0; + TInt ret = usbman.GetPersonalityProperty(personalityId, property); + if (ret == KErrNone) { + myDebug() << "property " << property; + if (property & KUsbPersonalityPropertyHidden) { + hidden = true; + } + } + myDebug() << "<<< UsbUiSettingModel::isPersonalityHidden " << hidden; + return hidden; +} + +bool UsbUiSettingModel::isPersonalityHidden(TInt personalityId) +{ + return ( mPersonalityIds.indexOf(personalityId) == -1 ); +} diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbview.docml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbview.docml Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/src/usbviewmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/src/usbviewmanager.cpp Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include +#include "UsbViewManager.h" +#include "UsbMainView.h" + + +UsbViewManager::UsbViewManager( HbMainWindow* mainWindow, QObject *parent ) +: QObject( parent ), + mWindow(mainWindow) + { + } + +UsbViewManager::~UsbViewManager() + { + + } + +/*! + Create views(main view, gadget gallery view and gadget details view). + Add them to MainWindow. + */ +void UsbViewManager::addView() + { + // Create main view and add + mMainView = new UsbMainView( this ); + mWindow->addView(mMainView); + + } + diff -r 47c263f7e521 -r 4712310216c0 usbuis/usbuiqt/usbapplication.pro --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbuis/usbuiqt/usbapplication.pro Fri Apr 23 23:17:21 2010 +0300 @@ -0,0 +1,74 @@ +# +# ============================================================================ +# Name : usbapplication.pro +# Part of : USB / USB Settings Application *** Info from the SWAD +# Description : Project definition file for project USB Settings Application +# Version : %version: 3 % << Don't touch! Updated by Synergy at check-out. +# +# Copyright © 2009 Nokia. All rights reserved. +# This material, including documentation and any related computer +# programs, is protected by copyright controlled by Nokia. All +# rights are reserved. Copying, including reproducing, storing, +# adapting or translating, any or all of this material requires the +# prior written consent of Nokia. This material also contains +# confidential information which may not be disclosed to others +# without the prior written consent of Nokia. +# ============================================================================ +# + +TEMPLATE = app +TARGET = usbapplication +QT += core \ + gui \ + xml +HEADERS += inc/usbuisettingmodel.h \ + inc/usbuimodelactive.h \ + inc/usbviewmanager.h \ + inc/usbmainview.h +SOURCES += src/usbuisettingmodel.cpp \ + src/usbuimodelactive.cpp \ + src/usbviewmanager.cpp \ + src/usbmainview.cpp \ + src/main.cpp \ + src/usbapplication_reg.rss +INCLUDEPATH += $$MW_LAYER_SYSTEMINCLUDE +LIBS += -lcentralrepository +LIBS += -lusbwatcher +LIBS += -lxqsettingsmanager +LIBS += -lusbman +LIBS += -lhbcore +LIBS += -lhbwidgets +LIBS += -lhbtools +FORMS += +RESOURCES += src/usbicons.qrc \ + src/usbapplication.qrc +CONFIG += qt \ + hb + +TRANSLATIONS=usbapplication.ts + +symbian: { + + TARGET.UID3 = 0x2002BCA3 + TARGET.CAPABILITY = LocalServices \ + WriteDeviceData + + # for pkg + usbuitranslation.sources = src/usbapplication.qm + usbuitranslation.path = /resource + DEPLOYMENT += usbuitranslation + + BLD_INF_RULES.prj_exports += "./src/usbapplication.qm z:/resource/usbapplication.qm" + +} + +# placeholder for creating sis file +createsis.commands += ( makesis -v usbapplication.pkg ); \ + && \ + ( signsis.exe usbapplication.sis usbapplication_signed.sisx Nokia_RnDCert_02.der Nokia_RnDCert_02.key ); \ + && \ + ( del usbapplication.sis ); +QMAKE_EXTRA_TARGETS += createsis + +BLD_INF_RULES.prj_exports += \ + "rom/usbsettings.iby CORE_MW_LAYER_IBY_EXPORT_PATH(usbsettings.iby)" \ \ No newline at end of file