45 const TImplementationProxy KImplementationTable[] = |
45 const TImplementationProxy KImplementationTable[] = |
46 { |
46 { |
47 IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CWrtDataPlugin::NewL ) |
47 IMPLEMENTATION_PROXY_ENTRY( KImplUidDataPlugin, CWrtDataPlugin::NewL ) |
48 }; |
48 }; |
49 |
49 |
|
50 const TInt KTryAgainDelay( 3000000 ); // 3 sec |
|
51 |
50 // ======== MEMBER FUNCTIONS ======== |
52 // ======== MEMBER FUNCTIONS ======== |
51 // --------------------------------------------------------------------------- |
53 // --------------------------------------------------------------------------- |
52 // ImplementationGroupProxy |
54 // ImplementationGroupProxy |
53 // |
55 // |
54 // --------------------------------------------------------------------------- |
56 // --------------------------------------------------------------------------- |
131 void CWrtDataPlugin::Start( TStartReason aReason ) |
139 void CWrtDataPlugin::Start( TStartReason aReason ) |
132 { |
140 { |
133 if( aReason == ESystemStartup || |
141 if( aReason == ESystemStartup || |
134 aReason == EPluginStartup ) |
142 aReason == EPluginStartup ) |
135 { |
143 { |
136 // publish the initial data |
144 // Publish the initial data |
137 TRAP_IGNORE( PublishL()); |
145 TRAP_IGNORE( PublishInitialDataL() ); |
138 } |
146 } |
139 } |
147 } |
140 |
148 |
141 // ---------------------------------------------------------------------------- |
149 // ---------------------------------------------------------------------------- |
142 // CWrtDataPlugin::Stop |
150 // CWrtDataPlugin::Stop |
228 return; |
236 return; |
229 } |
237 } |
230 |
238 |
231 RAiSettingsItemArray contentItemsArr; |
239 RAiSettingsItemArray contentItemsArr; |
232 RAiSettingsItemArray configurationItemsArr; |
240 RAiSettingsItemArray configurationItemsArr; |
233 RAiSettingsItemArray settingItemsArr; |
|
234 |
|
235 TInt count( aSettings.Count() ); |
241 TInt count( aSettings.Count() ); |
236 |
242 |
237 for ( TInt i = 0; i < count; i++ ) |
243 for ( TInt i = 0; i < count; i++ ) |
238 { |
244 { |
239 MAiPluginSettings* setting( aSettings[i] ); |
245 MAiPluginSettings* setting( aSettings[i] ); |
309 |
311 |
310 // Activate the publisher |
312 // Activate the publisher |
311 iData->NotifyPublisherL( KActive ); |
313 iData->NotifyPublisherL( KActive ); |
312 } |
314 } |
313 |
315 |
314 settingItemsArr.Reset(); |
|
315 contentItemsArr.Reset(); |
316 contentItemsArr.Reset(); |
316 configurationItemsArr.Reset(); |
317 configurationItemsArr.Reset(); |
317 |
318 // We own the array so destroy it |
318 // We own the array so destroy it |
|
319 aSettings.ResetAndDestroy(); |
319 aSettings.ResetAndDestroy(); |
320 } |
320 } |
321 |
321 |
322 // ---------------------------------------------------------------------------- |
322 // ---------------------------------------------------------------------------- |
323 // CWrtDataPlugin::SetProperty |
323 // CWrtDataPlugin::SetProperty |
354 // |
354 // |
355 void CWrtDataPlugin::HandleEvent( const TDesC& aEventName, |
355 void CWrtDataPlugin::HandleEvent( const TDesC& aEventName, |
356 const TDesC& aParam ) |
356 const TDesC& aParam ) |
357 { |
357 { |
358 TRAP_IGNORE( iData->ExecuteActionL( aEventName , aParam ) ); |
358 TRAP_IGNORE( iData->ExecuteActionL( aEventName , aParam ) ); |
359 } |
|
360 |
|
361 // ---------------------------------------------------------------------------- |
|
362 // CWrtDataPlugin::HasMenuItem |
|
363 // |
|
364 // ---------------------------------------------------------------------------- |
|
365 // |
|
366 TBool CWrtDataPlugin::HasMenuItem( const TDesC& aMenuItem ) |
|
367 { |
|
368 return iData->HasMenuItem ( aMenuItem ); |
|
369 } |
359 } |
370 |
360 |
371 // ---------------------------------------------------------------------------- |
361 // ---------------------------------------------------------------------------- |
372 // CWrtDataPlugin::IsActive |
362 // CWrtDataPlugin::IsActive |
373 // |
363 // |
677 // --------------------------------------------------------------------------- |
667 // --------------------------------------------------------------------------- |
678 // |
668 // |
679 void CWrtDataPlugin::HideLoadingIcon(MAiContentObserver* aObserver) |
669 void CWrtDataPlugin::HideLoadingIcon(MAiContentObserver* aObserver) |
680 { |
670 { |
681 aObserver->SetProperty( *this, KElement , KDisplay , KHide ); |
671 aObserver->SetProperty( *this, KElement , KDisplay , KHide ); |
|
672 |
|
673 // Do not try to publish initial data anymore |
|
674 StopTimer(); |
682 } |
675 } |
683 |
676 |
684 // --------------------------------------------------------------------------- |
677 // --------------------------------------------------------------------------- |
685 // Publishes widget's texts and images |
678 // Publishes widget's texts and images |
686 // --------------------------------------------------------------------------- |
679 // --------------------------------------------------------------------------- |
687 // |
680 // |
688 void CWrtDataPlugin::PublishL() |
681 void CWrtDataPlugin::PublishInitialDataL() |
689 { |
682 { |
690 TInt observers( iObservers.Count() ); |
683 TInt observers( iObservers.Count() ); |
691 TInt transactionId = reinterpret_cast<TInt>( this ); |
684 TInt transactionId = reinterpret_cast<TInt>( this ); |
692 |
685 |
693 for ( int i = 0; i < observers; i++ ) |
686 for ( int i = 0; i < observers; i++ ) |
694 { |
687 { |
695 MAiContentObserver* observer = iObservers[i]; |
688 MAiContentObserver* observer = iObservers[i]; |
696 |
689 |
|
690 CleanupStack::PushL( TCleanupItem( CancelTransaction, observer ) ); |
|
691 |
697 if ( observer->StartTransaction( transactionId ) == KErrNone ) |
692 if ( observer->StartTransaction( transactionId ) == KErrNone ) |
698 {// Publish default data |
693 {// Publish default data |
699 iData->PublishDefaultImageL(observer); |
694 iData->PublishInitialDataL(observer); |
700 observer->Commit( transactionId ); |
695 observer->Commit( transactionId ); |
701 } |
696 } |
|
697 |
|
698 CleanupStack::Pop( observer ); |
702 |
699 |
703 // Release memory of the published text |
700 // Release memory of the published text |
704 iDataArray.ResetAndDestroy(); |
701 iDataArray.ResetAndDestroy(); |
705 // Release memory of the published icons |
702 // Release memory of the published icons |
706 iIconArray.Reset(); |
703 iIconArray.Reset(); |
785 } |
782 } |
786 } |
783 } |
787 return (error == KErrNone ); |
784 return (error == KErrNone ); |
788 } |
785 } |
789 |
786 |
|
787 // --------------------------------------------------------------------------- |
|
788 // Cleanup callback for cancelling a transactions in case of leave |
|
789 // --------------------------------------------------------------------------- |
|
790 // |
|
791 void CWrtDataPlugin::CancelTransaction( TAny* aObserver ) |
|
792 { |
|
793 if ( aObserver ) |
|
794 { |
|
795 MAiContentObserver* obs = reinterpret_cast< MAiContentObserver*>( aObserver ); |
|
796 TInt transactionId = reinterpret_cast<TInt>( aObserver ); |
|
797 obs->CancelTransaction( transactionId ); |
|
798 } |
|
799 } |
|
800 |
|
801 // --------------------------------------------------------------------------- |
|
802 // Create and start republish timer |
|
803 // --------------------------------------------------------------------------- |
|
804 // |
|
805 void CWrtDataPlugin::StartTimer() |
|
806 { |
|
807 TRAP_IGNORE( |
|
808 if ( !iTimer ) |
|
809 { |
|
810 iTimer = CPeriodic::NewL( CActive::EPriorityStandard ); |
|
811 } |
|
812 |
|
813 if ( !iTimer->IsActive() ) |
|
814 { |
|
815 TTimeIntervalMicroSeconds32 delay( KTryAgainDelay ); |
|
816 iTimer->Start( delay, delay, TCallBack( Timeout, this ) ); |
|
817 } |
|
818 ); |
|
819 } |
|
820 |
|
821 // --------------------------------------------------------------------------- |
|
822 // Cancel republish timer |
|
823 // --------------------------------------------------------------------------- |
|
824 // |
|
825 void CWrtDataPlugin::CancelTimer() |
|
826 { |
|
827 if ( iTimer ) |
|
828 { |
|
829 iTimer->Cancel(); |
|
830 } |
|
831 } |
|
832 |
|
833 // --------------------------------------------------------------------------- |
|
834 // Stop and delete republish timer |
|
835 // --------------------------------------------------------------------------- |
|
836 // |
|
837 void CWrtDataPlugin::StopTimer() |
|
838 { |
|
839 if ( iTimer ) |
|
840 { |
|
841 iTimer->Cancel(); |
|
842 delete iTimer; |
|
843 iTimer = NULL; |
|
844 } |
|
845 } |
|
846 |
|
847 // --------------------------------------------------------------------------- |
|
848 // Initial data republish callback |
|
849 // --------------------------------------------------------------------------- |
|
850 // |
|
851 TInt CWrtDataPlugin::Timeout( TAny* aPtr ) |
|
852 { |
|
853 CWrtDataPlugin* self = static_cast<CWrtDataPlugin*>( aPtr ); |
|
854 |
|
855 // Cancel timer before publishing |
|
856 self->CancelTimer(); |
|
857 |
|
858 TInt observers( self->iObservers.Count() ); |
|
859 TInt transactionId = reinterpret_cast<TInt>( self ); |
|
860 TBool success( ETrue ); |
|
861 |
|
862 // Publish for each observer |
|
863 for ( int i = 0; i < observers; i++ ) |
|
864 { |
|
865 MAiContentObserver* observer = self->iObservers[i]; |
|
866 |
|
867 if ( observer->StartTransaction( transactionId ) == KErrNone ) |
|
868 { |
|
869 // Publish default image |
|
870 TRAPD( err, self->iData->PublishDefaultImageL( observer ) ); |
|
871 if ( KErrNone != err ) |
|
872 { |
|
873 observer->CancelTransaction( transactionId ); |
|
874 success = EFalse; |
|
875 } |
|
876 else |
|
877 { |
|
878 // |
|
879 observer->Commit( transactionId ); |
|
880 } |
|
881 } |
|
882 } |
|
883 |
|
884 // Start timer again if there is error in publishing |
|
885 if ( !success ) |
|
886 { |
|
887 self->StartTimer(); |
|
888 } |
|
889 else |
|
890 { |
|
891 self->StopTimer(); |
|
892 } |
|
893 |
|
894 // Release memory of the published icons |
|
895 self->iIconArray.Reset(); |
|
896 |
|
897 return KErrNone; |
|
898 } |
|
899 |
|
900 |
|
901 |
790 // End of file |
902 // End of file |