809 |
786 |
810 // Load filenames from CLF |
787 // Load filenames from CLF |
811 void CSlideshowPlugin::LoadRandomSlidesL() |
788 void CSlideshowPlugin::LoadRandomSlidesL() |
812 { |
789 { |
813 SSPLOGGER_ENTERFN("LoadRandomSlidesL()"); |
790 SSPLOGGER_ENTERFN("LoadRandomSlidesL()"); |
814 |
791 |
815 // No need to do anything, if model hasn't become |
|
816 // outdated since last loading |
|
817 if (iCLFModelUpToDate) |
|
818 { |
|
819 return; |
|
820 } |
|
821 |
|
822 // Start by getting rid of possibly loaded slides |
792 // Start by getting rid of possibly loaded slides |
823 iModel->DeleteAll(); |
793 iModel->DeleteAll(); |
824 |
794 |
825 // Make sure CLF is ready |
795 // connect to MDS |
826 ConnectToCLFL(); |
796 ConnectToMDSSessionL(); |
827 |
797 |
828 // Refresh CLF model |
798 // Wait for query of MDS to complete before continuing |
829 iCLFError = KErrNone; |
799 WaitForMDS(); |
830 iCLFModel->RefreshL(); |
800 |
831 |
801 SSPLOGGER_LEAVEFN("LoadRandomSlidesL()"); |
832 // Wait for refresh to complete before continuing |
802 } |
833 WaitForCLF(); |
803 |
834 |
804 |
835 // On error bail out |
805 // Requests display mode from host |
836 if (iCLFError != KErrNone) |
806 void CSlideshowPlugin::SetDisplayMode() |
837 { |
807 { |
838 SSPLOGGER_WRITEF(_L("SSP: CLF refresh error %d"), iCLFError); |
808 if (!iHost) |
|
809 { |
839 return; |
810 return; |
840 } |
811 } |
841 |
812 |
842 // Model is up to date |
813 // Exit partial mode |
843 iCLFModelUpToDate = ETrue; |
814 iHost->ExitPartialMode(); |
844 |
815 } |
845 // CLF model should now contain the image files in Gallery, proceed to |
816 |
846 // load into our model |
817 |
847 TInt nItems = iCLFModel->ItemCount(); |
818 // Requests lights |
848 |
819 void CSlideshowPlugin::Lights(TInt aSecs) |
849 // Loop through, add filenames |
820 { |
850 TInt count = 0; |
821 // Request nothing, if no time set (don't force lights off) |
851 for (TInt i = 0; i < nItems; i++) |
822 if ((iHost) && (aSecs > 0)) |
852 { |
823 { |
853 // TFileName fileName; |
824 SSPLOGGER_WRITEF(_L("SSP: Request lights for %d secs"), aSecs); |
854 TPtrC fileName; |
825 iHost->RequestLights(aSecs); |
855 TInt error = KErrNone; |
826 } |
|
827 } |
|
828 |
|
829 |
|
830 // Configure the plugin |
|
831 void CSlideshowPlugin::ConfigureL(TAny* /* aParam */) |
|
832 { |
|
833 // Look for screensaver slideset setting interface |
|
834 RImplInfoPtrArray array; |
|
835 const TUid slidesetInterface = { 0x102823AD }; |
|
836 const TUid slidesetImplUidScreensaver = { 0x102823AF }; |
|
837 const TEComResolverParams emptyParams; |
|
838 |
|
839 REComSession::ListImplementationsL( |
|
840 slidesetInterface, |
|
841 emptyParams, |
|
842 KRomOnlyResolverUid, |
|
843 array); |
|
844 CleanupResetAndDestroyPushL(array); |
|
845 |
|
846 // Loop through implementations and look for screensaver |
|
847 // slideset implementation (this is not really completely |
|
848 // necessary, because we already know the implementation UID, |
|
849 // but we want to be sure it's there, and on ROM only |
|
850 TInt nCount = array.Count(); |
|
851 TUid implUid; |
|
852 |
|
853 for (TInt i = 0; i < nCount; i++) |
|
854 { |
|
855 CImplementationInformation* info = array[i]; |
856 |
856 |
857 const MCLFItem& item = iCLFModel->Item(i); |
857 if (info->ImplementationUid() == slidesetImplUidScreensaver) |
858 |
|
859 error = item.GetField(ECLFFieldIdFileNameAndPath, fileName); |
|
860 |
|
861 // If OK, add to model |
|
862 if (error == KErrNone) |
|
863 { |
858 { |
|
859 // Found |
|
860 implUid = info->ImplementationUid(); |
|
861 break; |
|
862 } |
|
863 } |
|
864 |
|
865 // Did we get it? |
|
866 if (implUid != slidesetImplUidScreensaver) |
|
867 { |
|
868 User::Leave(KErrNotFound); |
|
869 } |
|
870 |
|
871 // Instantiate the interface |
|
872 CPslnSlidesetDialogInterface* plugin = |
|
873 CPslnSlidesetDialogInterface::NewL(implUid); |
|
874 |
|
875 TInt dlgRet = KErrNone; |
|
876 if (plugin) |
|
877 { |
|
878 dlgRet = plugin->ExecuteDialogLD(); |
|
879 } |
|
880 |
|
881 // Cleanup |
|
882 array.ResetAndDestroy(); |
|
883 CleanupStack::PopAndDestroy(); // array |
|
884 |
|
885 User::LeaveIfError(dlgRet); |
|
886 } |
|
887 |
|
888 |
|
889 // Updates the saved information about display |
|
890 void CSlideshowPlugin::UpdateDisplayInfo() |
|
891 { |
|
892 iDi.iSize = sizeof(TScreensaverDisplayInfo); |
|
893 iHost->DisplayInfo(&iDi); |
|
894 } |
|
895 |
|
896 |
|
897 // Flushes pending draws |
|
898 void CSlideshowPlugin::FlushDrawBuffer() |
|
899 { |
|
900 iEikEnv->WsSession().Flush(); |
|
901 } |
|
902 |
|
903 |
|
904 // ----------------------------------------------------------------------------- |
|
905 // CSlideshowPlugin::SettingsChanged |
|
906 // Called when Themes reports a settings change through P & S |
|
907 // ----------------------------------------------------------------------------- |
|
908 TInt CSlideshowPlugin::SettingsChanged() |
|
909 { |
|
910 // If current key value is nonzero, it means the settings |
|
911 // have just changed, otherwise, no action necessary |
|
912 TInt value = 0; |
|
913 iSettingsChangedProperty.Get(value); |
|
914 |
|
915 if (value == EScreenSaverPluginSettingsChanged) |
|
916 { |
|
917 #if 0 |
|
918 // Slide file has changed - re-load images |
|
919 TRAP_IGNORE(LoadSlidesL()); |
|
920 // Pre-fetch the fist image to be drawn |
|
921 iModel->PrepareNextSlide( |
|
922 (iSettings->iSlideshowType == KSlideshowTypeRandom), |
|
923 iDi.iRect.Size()); |
|
924 #endif |
|
925 iSettingsChangedProperty.Set(EScreenSaverPluginSettingsNoChange); |
|
926 } |
|
927 |
|
928 return KErrNone; |
|
929 } |
|
930 |
|
931 |
|
932 // ----------------------------------------------------------------------------- |
|
933 // CSlideshowPlugin::ConnectToMDSSessionL |
|
934 // Connects to MDS Listing Framework. Can be called many times, |
|
935 // connects only once |
|
936 // ----------------------------------------------------------------------------- |
|
937 void CSlideshowPlugin::ConnectToMDSSessionL() |
|
938 { |
|
939 if (!iMdESession) |
|
940 { |
|
941 iMdESession = CMdESession::NewL( *this ); |
|
942 } |
|
943 } |
|
944 |
|
945 // ----------------------------------------------------------------------------- |
|
946 // CSlideshowPlugin::WaitForMDS |
|
947 // Begins wait for MDS session connected |
|
948 // ----------------------------------------------------------------------------- |
|
949 void CSlideshowPlugin::WaitForMDS() |
|
950 { |
|
951 if (iWaitActive) |
|
952 { |
|
953 return; |
|
954 } |
|
955 else |
|
956 { |
|
957 iWaitActive = ETrue; |
|
958 iWaiter.Start(); |
|
959 } |
|
960 } |
|
961 |
|
962 // ----------------------------------------------------------------------------- |
|
963 // CSlideshowPlugin::WaitForMDS |
|
964 // Ends wait for MDS |
|
965 // ----------------------------------------------------------------------------- |
|
966 void CSlideshowPlugin::EndWaitForMDS() |
|
967 { |
|
968 if (!iWaitActive) |
|
969 { |
|
970 return; |
|
971 } |
|
972 else |
|
973 { |
|
974 iWaiter.AsyncStop(); |
|
975 iWaitActive = EFalse; |
|
976 } |
|
977 } |
|
978 |
|
979 // ----------------------------------------------------------------------------- |
|
980 // CSlideshowPlugin::HandleSessionOpened |
|
981 // Session is open successfully, then start a query for images |
|
982 // ----------------------------------------------------------------------------- |
|
983 void CSlideshowPlugin::HandleSessionOpened(CMdESession& /*aSession*/, TInt aError) |
|
984 { |
|
985 if ( KErrNone != aError ) |
|
986 { |
|
987 // Error occurred when opening session. iMdeSession must be deleted and new |
|
988 // session opened if we wish to use MdE. |
|
989 delete iMdESession; |
|
990 iMdESession = NULL; |
|
991 return; |
|
992 } |
|
993 // The session was opened successfully. |
|
994 TRAP(aError, OpenQueryL() ); |
|
995 } |
|
996 |
|
997 // ----------------------------------------------------------------------------- |
|
998 // CSlideshowPlugin::OpenQueryL |
|
999 // ----------------------------------------------------------------------------- |
|
1000 void CSlideshowPlugin::OpenQueryL() |
|
1001 { |
|
1002 CMdENamespaceDef& defaultNamespaceDef = iMdESession->GetDefaultNamespaceDefL(); |
|
1003 CMdEObjectDef& imageObjDef = defaultNamespaceDef.GetObjectDefL( MdeConstants::Image::KImageObject ); |
|
1004 |
|
1005 // query objects with object definition "Image" |
|
1006 CMdEObjectQuery* query = iMdESession->NewObjectQueryL( defaultNamespaceDef, imageObjDef, this ); |
|
1007 |
|
1008 query->FindL( KDefaultRandomLoadingNumber ); |
|
1009 } |
|
1010 |
|
1011 // ----------------------------------------------------------------------------- |
|
1012 // CSlideshowPlugin::HandleSessionError |
|
1013 // error happened when open the session, close session and end the waiting |
|
1014 // ----------------------------------------------------------------------------- |
|
1015 void CSlideshowPlugin::HandleSessionError(CMdESession& /*aSession*/, TInt /*aError*/) |
|
1016 { |
|
1017 if ( iMdESession ) |
|
1018 { |
|
1019 delete iMdESession; |
|
1020 iMdESession = NULL; |
|
1021 } |
|
1022 // error happened when open the session, so end the waiting for MDS session. |
|
1023 EndWaitForMDS(); |
|
1024 } |
|
1025 |
|
1026 // ----------------------------------------------------------------------------- |
|
1027 // CSlideshowPlugin::HandleQueryCompleted |
|
1028 // query completed, load the images |
|
1029 // ----------------------------------------------------------------------------- |
|
1030 void CSlideshowPlugin::HandleQueryCompleted(CMdEQuery& aQuery, TInt aError) |
|
1031 { |
|
1032 if ( aError == KErrNone ) |
|
1033 { |
|
1034 LoadImagesToModel( aQuery ); |
|
1035 } |
|
1036 EndWaitForMDS(); |
|
1037 } |
|
1038 |
|
1039 // ----------------------------------------------------------------------------- |
|
1040 // CSlideshowPlugin::HandleQueryCompleted |
|
1041 // part of query completed, load the completed images |
|
1042 // ----------------------------------------------------------------------------- |
|
1043 void CSlideshowPlugin::HandleQueryNewResults( CMdEQuery& aQuery, |
|
1044 TInt aFirstNewItemIndex, |
|
1045 TInt aNewItemCount) |
|
1046 { |
|
1047 LoadImagesToModel( aQuery, aFirstNewItemIndex, aNewItemCount ); |
|
1048 EndWaitForMDS(); |
|
1049 } |
|
1050 |
|
1051 // ----------------------------------------------------------------------------- |
|
1052 // CSlideshowPlugin::LoadImagesToModel |
|
1053 // load the images when query is successfully |
|
1054 // ----------------------------------------------------------------------------- |
|
1055 void CSlideshowPlugin::LoadImagesToModel(const CMdEQuery& aQuery, |
|
1056 TInt aFirstNewItemIndex, |
|
1057 TInt aNewItemCount) |
|
1058 { |
|
1059 CMdEObjectQuery& query= ( CMdEObjectQuery& ) aQuery; |
|
1060 // query is completed |
|
1061 if( aQuery.Count() > 0 ) |
|
1062 { |
|
1063 // some items were found! |
|
1064 // Loop through, add filenames |
|
1065 TInt startIndex = aFirstNewItemIndex; |
|
1066 TInt nItem = aNewItemCount; |
|
1067 if ( aFirstNewItemIndex == 0 && aFirstNewItemIndex == aNewItemCount ) |
|
1068 { |
|
1069 startIndex = 0; |
|
1070 nItem = aQuery.Count(); |
|
1071 } |
|
1072 TInt count = 0; |
|
1073 for ( ; startIndex < nItem; startIndex++) |
|
1074 { |
|
1075 // TFileName fileName; |
|
1076 TBufC<256> fileName; |
|
1077 |
|
1078 const CMdEObject& obj = query.Result(startIndex); |
|
1079 fileName = obj.Uri(); |
|
1080 |
864 // Check that the file exists. If not, it is still OK, if it is |
1081 // Check that the file exists. If not, it is still OK, if it is |
865 // on the memory card - it may show up later. Omit files from other |
1082 // on the memory card - it may show up later. Omit files from other |
866 // drives that do not exist at the time of loading |
1083 // drives that do not exist at the time of loading |
867 // TODO: Can be removed, as slides are loaded on every start |
1084 // TODO: Can be removed, as slides are loaded on every start |
868 TBool exists = BaflUtils::FileExists(iEikEnv->FsSession(), fileName); |
1085 TBool exists = BaflUtils::FileExists(iEikEnv->FsSession(), fileName); |
881 // No point in adding files that cannot be displayed anyway |
1098 // No point in adding files that cannot be displayed anyway |
882 continue; |
1099 continue; |
883 } |
1100 } |
884 #endif |
1101 #endif |
885 // Create a slide with the filename and store it in the model |
1102 // Create a slide with the filename and store it in the model |
886 CSlideshowSlide* pSlide = CSlideshowSlide::NewL(fileName, isOnMC); |
1103 TRAPD(err, AppendSlideToModelL( fileName, isOnMC ) ); |
887 CleanupStack::PushL(pSlide); |
1104 if ( KErrNone != err ) |
888 iModel->AppendSlideL(pSlide); |
1105 { |
889 CleanupStack::Pop(pSlide); |
1106 // appending error, go on to append next slide |
890 |
1107 continue; |
|
1108 } |
891 SSPLOGGER_WRITEF(_L("SSP: Slide %d added, file: %S"), count, &fileName); |
1109 SSPLOGGER_WRITEF(_L("SSP: Slide %d added, file: %S"), count, &fileName); |
892 count++; |
1110 count++; |
893 } |
1111 } |
894 } |
1112 } |
895 |
1113 } |
896 SSPLOGGER_LEAVEFN("LoadRandomSlidesL()"); |
1114 |
897 } |
1115 // ----------------------------------------------------------------------------- |
898 |
1116 // CSlideshowPlugin::AppendSlideToModelL |
899 |
1117 // Add slide to model |
900 // Requests display mode from host |
1118 // ----------------------------------------------------------------------------- |
901 void CSlideshowPlugin::SetDisplayMode() |
1119 void CSlideshowPlugin::AppendSlideToModelL(TDesC& aFileName, TBool aIsOnMC) |
902 { |
1120 { |
903 if (!iHost) |
1121 CSlideshowSlide* pSlide = CSlideshowSlide::NewL(aFileName, aIsOnMC); |
904 { |
1122 CleanupStack::PushL(pSlide); |
905 return; |
1123 iModel->AppendSlideL(pSlide); |
906 } |
1124 CleanupStack::Pop(pSlide); |
907 |
1125 } |
908 // Exit partial mode |
|
909 iHost->ExitPartialMode(); |
|
910 } |
|
911 |
|
912 |
|
913 // Requests lights |
|
914 void CSlideshowPlugin::Lights(TInt aSecs) |
|
915 { |
|
916 // Request nothing, if no time set (don't force lights off) |
|
917 if ((iHost) && (aSecs > 0)) |
|
918 { |
|
919 SSPLOGGER_WRITEF(_L("SSP: Request lights for %d secs"), aSecs); |
|
920 iHost->RequestLights(aSecs); |
|
921 } |
|
922 } |
|
923 |
|
924 |
|
925 // Configure the plugin |
|
926 void CSlideshowPlugin::ConfigureL(TAny* /* aParam */) |
|
927 { |
|
928 // Look for screensaver slideset setting interface |
|
929 RImplInfoPtrArray array; |
|
930 const TUid slidesetInterface = { 0x102823AD }; |
|
931 const TUid slidesetImplUidScreensaver = { 0x102823AF }; |
|
932 const TEComResolverParams emptyParams; |
|
933 |
|
934 REComSession::ListImplementationsL( |
|
935 slidesetInterface, |
|
936 emptyParams, |
|
937 KRomOnlyResolverUid, |
|
938 array); |
|
939 CleanupResetAndDestroyPushL(array); |
|
940 |
|
941 // Loop through implementations and look for screensaver |
|
942 // slideset implementation (this is not really completely |
|
943 // necessary, because we already know the implementation UID, |
|
944 // but we want to be sure it's there, and on ROM only |
|
945 TInt nCount = array.Count(); |
|
946 TUid implUid; |
|
947 |
|
948 for (TInt i = 0; i < nCount; i++) |
|
949 { |
|
950 CImplementationInformation* info = array[i]; |
|
951 |
|
952 if (info->ImplementationUid() == slidesetImplUidScreensaver) |
|
953 { |
|
954 // Found |
|
955 implUid = info->ImplementationUid(); |
|
956 break; |
|
957 } |
|
958 } |
|
959 |
|
960 // Did we get it? |
|
961 if (implUid != slidesetImplUidScreensaver) |
|
962 { |
|
963 User::Leave(KErrNotFound); |
|
964 } |
|
965 |
|
966 // Instantiate the interface |
|
967 CPslnSlidesetDialogInterface* plugin = |
|
968 CPslnSlidesetDialogInterface::NewL(implUid); |
|
969 |
|
970 TInt dlgRet = KErrNone; |
|
971 if (plugin) |
|
972 { |
|
973 dlgRet = plugin->ExecuteDialogLD(); |
|
974 } |
|
975 |
|
976 // Cleanup |
|
977 array.ResetAndDestroy(); |
|
978 CleanupStack::PopAndDestroy(); // array |
|
979 |
|
980 User::LeaveIfError(dlgRet); |
|
981 } |
|
982 |
|
983 |
|
984 // Updates the saved information about display |
|
985 void CSlideshowPlugin::UpdateDisplayInfo() |
|
986 { |
|
987 iDi.iSize = sizeof(TScreensaverDisplayInfo); |
|
988 iHost->DisplayInfo(&iDi); |
|
989 } |
|
990 |
|
991 |
|
992 // Flushes pending draws |
|
993 void CSlideshowPlugin::FlushDrawBuffer() |
|
994 { |
|
995 iEikEnv->WsSession().Flush(); |
|
996 } |
|
997 |
|
998 |
|
999 // ----------------------------------------------------------------------------- |
|
1000 // CSlideshowPlugin::SettingsChanged |
|
1001 // Called when Themes reports a settings change through P & S |
|
1002 // ----------------------------------------------------------------------------- |
|
1003 TInt CSlideshowPlugin::SettingsChanged() |
|
1004 { |
|
1005 // If current key value is nonzero, it means the settings |
|
1006 // have just changed, otherwise, no action necessary |
|
1007 TInt value = 0; |
|
1008 iSettingsChangedProperty.Get(value); |
|
1009 |
|
1010 if (value == EScreenSaverPluginSettingsChanged) |
|
1011 { |
|
1012 #if 0 |
|
1013 // Slide file has changed - re-load images |
|
1014 TRAP_IGNORE(LoadSlidesL()); |
|
1015 // Pre-fetch the fist image to be drawn |
|
1016 iModel->PrepareNextSlide( |
|
1017 (iSettings->iSlideshowType == KSlideshowTypeRandom), |
|
1018 iDi.iRect.Size()); |
|
1019 #endif |
|
1020 iSettingsChangedProperty.Set(EScreenSaverPluginSettingsNoChange); |
|
1021 } |
|
1022 |
|
1023 return KErrNone; |
|
1024 } |
|
1025 |
|
1026 |
|
1027 // ----------------------------------------------------------------------------- |
|
1028 // CSlideshowPlugin::ConnectToCLFL |
|
1029 // Connects to Content Listing Framework. Can be called many times, |
|
1030 // connects only once |
|
1031 // ----------------------------------------------------------------------------- |
|
1032 void CSlideshowPlugin::ConnectToCLFL() |
|
1033 { |
|
1034 if (!iCLFEngine) |
|
1035 { |
|
1036 iCLFEngine = ContentListingFactory::NewContentListingEngineLC(); |
|
1037 CleanupStack::Pop(); // LC |
|
1038 } |
|
1039 |
|
1040 if (!iCLFModel) |
|
1041 { |
|
1042 iCLFModel = iCLFEngine->CreateListModelLC(*this); |
|
1043 CleanupStack::Pop(); // LC |
|
1044 } |
|
1045 |
|
1046 // Set image types to model |
|
1047 RArray<TInt> typeArray; |
|
1048 CleanupClosePushL(typeArray); |
|
1049 typeArray.AppendL(ECLFMediaTypeImage); |
|
1050 iCLFModel->SetWantedMediaTypesL(typeArray.Array()); |
|
1051 CleanupStack::PopAndDestroy(&typeArray); |
|
1052 } |
|
1053 |
|
1054 |
|
1055 // Begins wait for CLF |
|
1056 void CSlideshowPlugin::WaitForCLF() |
|
1057 { |
|
1058 if (iWaitActive) |
|
1059 { |
|
1060 return; |
|
1061 } |
|
1062 else |
|
1063 { |
|
1064 iWaitActive = ETrue; |
|
1065 iWaiter.Start(); |
|
1066 } |
|
1067 } |
|
1068 |
|
1069 |
|
1070 // Ends wait for CLF |
|
1071 void CSlideshowPlugin::EndWaitForCLF() |
|
1072 { |
|
1073 if (!iWaitActive) |
|
1074 { |
|
1075 return; |
|
1076 } |
|
1077 else |
|
1078 { |
|
1079 iWaiter.AsyncStop(); |
|
1080 iWaitActive = EFalse; |
|
1081 } |
|
1082 } |
|
1083 |
|
1084 // End Of file. |
1126 // End Of file. |