350 iApplicationSettings.AppendL( appStateSettings ); |
349 iApplicationSettings.AppendL( appStateSettings ); |
351 CleanupStack::Pop( appStateSettings ); // CLEANUP>> appStateSettings |
350 CleanupStack::Pop( appStateSettings ); // CLEANUP>> appStateSettings |
352 } |
351 } |
353 } |
352 } |
354 |
353 |
355 |
354 // ----------------------------------------------------------------------------- |
|
355 // CApplicationStateSourcePlugIn::HandleViewEventL |
|
356 // Maps view activations to contexts. |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 void CApplicationStateSourcePlugIn::HandleViewEventL( |
|
360 const TVwsViewEvent& aEvent ) |
|
361 { |
|
362 FUNC_LOG; |
|
363 |
|
364 // Renew listening |
|
365 iVws->NotifyNextActivation(); |
|
366 |
|
367 // Handle the view server event |
|
368 DoHandleViewEventL( aEvent ); |
|
369 |
|
370 // Log event members! |
|
371 INFO_1( "HandleViewEventL: eventType: [%d]", aEvent.iEventType ); |
|
372 |
|
373 INFO_2( "HandleViewEventL: viewOne [appUid:%S] [viewUid%S]", |
|
374 &(const TDesC&)aEvent.iViewOneId.iAppUid.Name(), |
|
375 &(const TDesC&)aEvent.iViewOneId.iViewUid.Name() ); |
|
376 |
|
377 INFO_2( "HandleViewEventL: viewTwo [appUid:%S] [viewUid%S]", |
|
378 &(const TDesC&)aEvent.iViewTwoId.iAppUid.Name(), |
|
379 &(const TDesC&)aEvent.iViewTwoId.iViewUid.Name() ); |
|
380 } |
356 |
381 |
357 //------------------------------------------------------------------------------ |
382 //------------------------------------------------------------------------------ |
358 // CApplicationStateSourcePlugIn::HandleNotifyGeneric |
383 // CApplicationStateSourcePlugIn::HandleNotifyGeneric |
359 //------------------------------------------------------------------------------ |
384 //------------------------------------------------------------------------------ |
360 // |
385 // |
718 break; |
743 break; |
719 } |
744 } |
720 } |
745 } |
721 return index; |
746 return index; |
722 } |
747 } |
723 void CApplicationStateSourcePlugIn::HandleWsEventL( RWsSession& aWsSession ) |
748 |
724 { |
749 |
725 TUid appUid( TUid::Null() ); |
|
726 TPtrC bgApp( *iDefaultAppName ); |
|
727 TPtrC fgApp( *iDefaultAppName ); |
|
728 TPtrC fgView( *iDefaultViewName ); |
|
729 |
|
730 TInt focWndGrp( aWsSession.GetFocusWindowGroup() ); |
|
731 CApaWindowGroupName* wndGrpName = CApaWindowGroupName::NewL( aWsSession ); |
|
732 CleanupStack::PushL( wndGrpName ); |
|
733 wndGrpName->ConstructFromWgIdL( focWndGrp ); |
|
734 appUid = wndGrpName->AppUid(); |
|
735 |
|
736 for ( TInt i = 0; i < iApplicationSettings.Count(); ++i ) |
|
737 { |
|
738 CCFApplicationStateSettings* appSettings = iApplicationSettings[ i ]; |
|
739 if ( appUid == appSettings->Uid() ) |
|
740 { |
|
741 fgApp.Set( appSettings->Name() ); |
|
742 appSettings->GetViewName( appUid, fgView ); |
|
743 bgApp.Set( iPreviousForegroundApplication ); |
|
744 break; |
|
745 } |
|
746 } |
|
747 TBool publishFgApp( EFalse ); |
|
748 TBool publishFgView( EFalse ); |
|
749 TBool publishBgApp( EFalse ); |
|
750 |
|
751 if ( iPreviousForegroundApplication.Compare( fgApp ) != 0 ) |
|
752 { |
|
753 publishFgApp = ETrue; |
|
754 } |
|
755 else if ( iPreviousForegroundView.Compare( fgView ) != 0 ) |
|
756 { |
|
757 publishFgView = ETrue; |
|
758 } |
|
759 |
|
760 if ( bgApp != fgApp ) |
|
761 { |
|
762 publishBgApp = ETrue; |
|
763 } |
|
764 |
|
765 iPreviousForegroundApplication.Set( fgApp ); // Store for next round |
|
766 iPreviousForegroundView.Set( fgView ); |
|
767 |
|
768 RThread thread; |
|
769 |
|
770 if ( publishFgApp ) |
|
771 { |
|
772 iContext->SetTypeL( KApplicationStateForegroundApplicationType ); |
|
773 iContext->SetValueL( fgApp ); |
|
774 iCF.PublishContext( *iContext, thread ); |
|
775 } |
|
776 |
|
777 if ( publishFgApp || publishFgView ) |
|
778 { |
|
779 iContext->SetTypeL( KApplicationStateForegroundApplicationViewType ); |
|
780 iContext->SetValueL( fgView ); |
|
781 iCF.PublishContext( *iContext, thread ); |
|
782 } |
|
783 |
|
784 if ( publishBgApp ) |
|
785 { |
|
786 iContext->SetTypeL( KApplicationStateBackgroundApplicationType ); |
|
787 iContext->SetValueL( bgApp ); |
|
788 iCF.PublishContext( *iContext, thread ); |
|
789 } |
|
790 |
750 |
791 thread.Close(); |
|
792 CleanupStack::PopAndDestroy( wndGrpName ); |
|
793 |
|
794 } |
|
795 |
|
796 // ======================== CWsEventHandler ======================== |
|
797 |
|
798 // --------------------------------------------------------------------------- |
|
799 // C++ constructor. |
|
800 // --------------------------------------------------------------------------- |
|
801 // |
|
802 CWsEventHandler::CWsEventHandler( MWsEventObserver& aObserver ): |
|
803 CActive( CActive::EPriorityStandard ), |
|
804 iObserver( aObserver ) |
|
805 { |
|
806 CActiveScheduler::Add( this ); |
|
807 } |
|
808 |
|
809 // --------------------------------------------------------------------------- |
|
810 // Symbian 2nd phase constructor. |
|
811 // --------------------------------------------------------------------------- |
|
812 // |
|
813 void CWsEventHandler::ConstructL() |
|
814 { |
|
815 // Connect to window server server |
|
816 User::LeaveIfError( iWsSession.Connect() ); |
|
817 |
|
818 // Construct window group |
|
819 iWindowGroup = new( ELeave ) RWindowGroup( iWsSession ); |
|
820 User::LeaveIfError( iWindowGroup->Construct( (TUint32)this, EFalse ) ); |
|
821 User::LeaveIfError( iWindowGroup->EnableGroupChangeEvents() ); |
|
822 iWindowGroup->SetOrdinalPosition( 0, ECoeWinPriorityNeverAtFront ); |
|
823 iWindowGroup->EnableReceiptOfFocus( EFalse ); |
|
824 |
|
825 // Hide the invisible window from the task manager |
|
826 iWindowGroupName = CApaWindowGroupName::NewL( iWsSession ); |
|
827 iWindowGroupName->SetHidden( ETrue ); |
|
828 iWindowGroupName->SetWindowGroupName( *iWindowGroup ); |
|
829 |
|
830 } |
|
831 // --------------------------------------------------------------------------- |
|
832 // Symbian two phased constructor. |
|
833 // --------------------------------------------------------------------------- |
|
834 // |
|
835 CWsEventHandler* CWsEventHandler::NewL( MWsEventObserver& aObserver ) |
|
836 { |
|
837 CWsEventHandler* self = CWsEventHandler::NewLC( aObserver ); |
|
838 CleanupStack::Pop( self ); |
|
839 |
|
840 return self; |
|
841 } |
|
842 |
|
843 // --------------------------------------------------------------------------- |
|
844 // Symbian two phased constructor. |
|
845 // Leaves pointer in the cleanup stack. |
|
846 // --------------------------------------------------------------------------- |
|
847 // |
|
848 CWsEventHandler* CWsEventHandler::NewLC( MWsEventObserver& aObserver ) |
|
849 { |
|
850 CWsEventHandler* self = new ( ELeave ) CWsEventHandler( aObserver ); |
|
851 CleanupStack::PushL( self ); |
|
852 self->ConstructL(); |
|
853 |
|
854 return self; |
|
855 } |
|
856 |
|
857 // --------------------------------------------------------------------------- |
|
858 // C++ destructor. |
|
859 // --------------------------------------------------------------------------- |
|
860 // |
|
861 CWsEventHandler::~CWsEventHandler() |
|
862 { |
|
863 Cancel(); |
|
864 |
|
865 // Cleanup window group name |
|
866 delete iWindowGroupName; |
|
867 |
|
868 // Cleanup window group |
|
869 if( iWindowGroup ) |
|
870 { |
|
871 iWindowGroup->DisableGroupChangeEvents(); |
|
872 iWindowGroup->Close(); |
|
873 delete iWindowGroup; |
|
874 } |
|
875 |
|
876 // Cleanup window server session |
|
877 iWsSession.Close(); |
|
878 } |
|
879 |
|
880 //------------------------------------------------------------------------------ |
|
881 // CWsEventHandler::IssueRequest |
|
882 //------------------------------------------------------------------------------ |
|
883 // |
|
884 void CWsEventHandler::IssueRequest() |
|
885 { |
|
886 // Request events from window server |
|
887 iWsSession.EventReady( &iStatus ); |
|
888 SetActive(); |
|
889 } |
|
890 |
|
891 |
|
892 //------------------------------------------------------------------------------ |
|
893 // CWsEventHandler::RunL |
|
894 //------------------------------------------------------------------------------ |
|
895 // |
|
896 void CWsEventHandler::RunL() |
|
897 { |
|
898 TInt err = iStatus.Int(); |
|
899 if( err == KErrNone ) |
|
900 { |
|
901 // No errors occured, fetch event |
|
902 TWsEvent wsEvent; |
|
903 iWsSession.GetEvent( wsEvent ); |
|
904 |
|
905 // Continue listening |
|
906 IssueRequest(); |
|
907 switch (wsEvent.Type()) |
|
908 { |
|
909 case EEventWindowGroupsChanged : |
|
910 // Forward event to observer |
|
911 iObserver.HandleWsEventL( iWsSession ); |
|
912 break; |
|
913 default: |
|
914 break; |
|
915 } |
|
916 } |
|
917 } |
|
918 |
|
919 //------------------------------------------------------------------------------ |
|
920 // CWsEventHandler::DoCancel |
|
921 //------------------------------------------------------------------------------ |
|
922 // |
|
923 void CWsEventHandler::DoCancel() |
|
924 { |
|
925 // Cancel event ready from window server |
|
926 iWsSession.EventReadyCancel(); |
|
927 } |
|
928 |
|
929 //------------------------------------------------------------------------------ |
|
930 // CWsEventHandler::RunError |
|
931 //------------------------------------------------------------------------------ |
|
932 // |
|
933 TInt CWsEventHandler::RunError( TInt /*aError*/ ) |
|
934 { |
|
935 // Issue a new request, other error handling is not performed since the |
|
936 // problem has occured in the observer code |
|
937 IssueRequest(); |
|
938 |
|
939 return KErrNone; |
|
940 } |
|
941 |
|
942 |
|