28 #include "irapplication.h" |
28 #include "irapplication.h" |
29 #include "irqmediaplayer.h" |
29 #include "irqmediaplayer.h" |
30 #include "irviewmanager.h" |
30 #include "irviewmanager.h" |
31 #include "irqisdsdatastructure.h" |
31 #include "irqisdsdatastructure.h" |
32 #include "irlastplayedstationinfo.h" |
32 #include "irlastplayedstationinfo.h" |
33 #include "irqnetworkcontroller.h" |
33 #include "irqnetworkcontroller.h" |
34 #include "irqsonghistoryengine.h" |
|
35 #include "irqmetadata.h" |
34 #include "irqmetadata.h" |
36 #include "irqsettings.h" |
35 #include "irqsettings.h" |
37 #include "irqfavoritesdb.h" |
36 #include "irqfavoritesdb.h" |
38 #include "irqstatisticsreporter.h" |
37 #include "irqstatisticsreporter.h" |
39 #include "irenummapper.h" |
38 #include "irenummapper.h" |
40 #include "irqlogger.h" |
39 #include "irqlogger.h" |
|
40 #include "irdbwrapper.h" |
|
41 #include "urlinfowrapper.h" |
|
42 #include "channelhistorywrapper.h" |
|
43 #include "songhistorywrapper.h" |
41 #ifdef HS_WIDGET_ENABLED |
44 #ifdef HS_WIDGET_ENABLED |
42 #include "irservicedef.h" |
45 #include "irservicedef.h" |
43 #endif |
46 #endif |
44 |
47 |
45 #ifdef Q_CC_NOKIAX86 |
48 #ifdef PLATSIM_DEBUG_CONF |
46 void getRadioServerAddress(QString & aUrl); |
49 void getRadioServerAddress(QString & aUrl); |
47 #endif |
50 #endif |
48 |
51 |
49 BEGIN_ENUM_MAP( KTerminationTypeMap ) |
52 BEGIN_ENUM_MAP( KTerminationTypeMap ) |
50 ENUM_MAP_ITEM( EIRQUserTerminated, IRQStatisticsReporter::EIRUserTerminated ), |
53 ENUM_MAP_ITEM( EIRQUserTerminated, IRQStatisticsReporter::EIRUserTerminated ), |
101 iNowPlayingPresetBackup(new IRQPreset()), |
104 iNowPlayingPresetBackup(new IRQPreset()), |
102 iConnectedFrom(EIRQIsds), |
105 iConnectedFrom(EIRQIsds), |
103 iConnectedFromBackup(EIRQIsds), |
106 iConnectedFromBackup(EIRQIsds), |
104 iStationLogoAvailable(false), |
107 iStationLogoAvailable(false), |
105 iStationLogoAvailableBackup(false), |
108 iStationLogoAvailableBackup(false), |
106 iMetaData(NULL), |
109 iMetaData(NULL), |
107 iSongHistoryEngine(NULL), |
|
108 iPlayState(EIdle), |
110 iPlayState(EIdle), |
109 iResuming(false), |
111 iResuming(false), |
110 iTryingBitrate(0), |
112 iTryingBitrate(0), |
111 iUrlArray(0), |
113 iUrlArray(0), |
112 iRealBitrate(0), |
114 iRealBitrate(0), |
113 iLastError(EIRQErrorNone), |
115 iLastError(EIRQErrorNone), |
114 iStopReason(EIRQUnknownTermination), |
116 iStopReason(EIRQUnknownTermination), |
115 iErrorNote(NULL) |
117 iErrorNote(NULL), |
|
118 iDbWrapper(NULL), |
|
119 iHistoryWrapper(NULL), |
|
120 iUrlInfoWrapper(NULL) |
116 { |
121 { |
117 // use the last played station to initiliaze the backup value. |
122 // use the last played station to initiliaze the backup value. |
118 // can regard the player is bootup, and initilize its LCD screen with last played station info if available. |
123 // can regard the player is bootup, and initilize its LCD screen with last played station info if available. |
119 IRQPreset *lastPlayedPreset = NULL; |
124 IRQPreset *lastPlayedPreset = NULL; |
120 if( !iApplication->isEmbeddedInstance() ) |
125 if( !iApplication->isEmbeddedInstance() ) |
263 * Use the last played url as station's url. |
272 * Use the last played url as station's url. |
264 */ |
273 */ |
265 void IRPlayController::resume() |
274 void IRPlayController::resume() |
266 { |
275 { |
267 qDebug("IRPlayController::resume(), Entering"); |
276 qDebug("IRPlayController::resume(), Entering"); |
268 if (iMediaPlayer && (EStopped == iPlayState)) |
277 if (iMediaPlayer && (EStopped == iPlayState) && iNowPlayingPreset) |
269 { |
278 { |
270 iResuming = true; |
279 iResuming = true; |
271 |
280 |
272 if (iLastPlayedUrl != "") |
281 //Check whether quality settings have been changed. |
273 { |
282 QString firstTryUrl = getFirstTryUrl(iNowPlayingPreset); |
274 qDebug("IRPlayController::resume(), iLastPlayedUrl is not empty, doPlay()"); |
283 if (firstTryUrl.isEmpty()) |
|
284 { |
|
285 return; |
|
286 } |
|
287 else if( firstTryUrl==iLastPlayedUrl ) |
|
288 { |
|
289 qDebug("IRPlayController::resume(), play by iLastPlayedUrl, doPlay()"); |
|
290 |
275 doPlay(iLastPlayedUrl); |
291 doPlay(iLastPlayedUrl); |
276 } |
292 } |
|
293 else |
|
294 { |
|
295 iLastPlayedUrlBackup = iLastPlayedUrl; |
|
296 iLastPlayedUrl = firstTryUrl; |
|
297 |
|
298 qDebug("IRPlayController::resume(), play by new url, doPlay()"); |
|
299 doPlay(firstTryUrl); |
|
300 } |
277 } |
301 } |
278 qDebug("IRPlayController::resume(), Exiting"); |
302 qDebug("IRPlayController::resume(), Exiting"); |
279 } |
303 } |
280 |
304 |
281 /* |
305 /* |
696 } |
735 } |
697 |
736 |
698 iPlayState = EPlaying; |
737 iPlayState = EPlaying; |
699 iApplication->stopLoadingAnimation(); |
738 iApplication->stopLoadingAnimation(); |
700 |
739 |
701 iApplication->getViewManager()->activateView(EIRView_PlayingView); |
740 iApplication->getViewManager()->activateView(EIRView_PlayingView); |
|
741 |
|
742 emit playingStarted(); |
|
743 |
|
744 // Save the station information to database iNowPlayingPreset |
|
745 saveStation2DB(iNowPlayingPreset); |
702 if( !iApplication->isEmbeddedInstance() ) |
746 if( !iApplication->isEmbeddedInstance() ) |
703 { |
747 { |
704 //update last played station |
748 //update last played station |
705 IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo(); |
749 IRLastPlayedStationInfo *lastPlayedStationInfo = iApplication->getLastPlayedStationInfo(); |
706 lastPlayedStationInfo->updateLastPlayedStation(iNowPlayingPreset,iConnectedFrom); |
750 lastPlayedStationInfo->updateLastPlayedStation(iNowPlayingPreset,iConnectedFrom); |
707 lastPlayedStationInfo->commitLastPlayedStation(); |
751 lastPlayedStationInfo->commitLastPlayedStation(); |
708 } |
752 } |
709 |
753 |
710 //increase the played times of current preset |
754 // if the metadata is available, show it. here, preset->nickName is already available |
711 iApplication->getFavoritesDB()->increasePlayedTimes(*iNowPlayingPreset); |
|
712 |
|
713 emit playingStarted(); |
|
714 |
|
715 // if the metadata is available, show it. |
|
716 emit metaDataAvailable(iMetaData); |
755 emit metaDataAvailable(iMetaData); |
|
756 |
|
757 //save the metadata to the db |
|
758 if( NULL != iMetaData ) |
|
759 { |
|
760 saveSong2DB(*iMetaData,*iNowPlayingPreset); |
|
761 } |
717 |
762 |
718 if( !iApplication->isEmbeddedInstance() ) |
|
719 { |
|
720 // Save the station information to database |
|
721 IRQMetaData tmpMetaData; |
|
722 tmpMetaData.setBitrate(iRealBitrate); |
|
723 tmpMetaData.setStreamUrl(iLastPlayedUrl); |
|
724 iSongHistoryEngine->handleMetaDataReceived(tmpMetaData, *iNowPlayingPreset); |
|
725 } |
|
726 |
|
727 // open stereo defaultly |
763 // open stereo defaultly |
728 iMediaPlayer->enableStereoEffect(); |
764 iMediaPlayer->enableStereoEffect(); |
729 } |
765 } |
730 } |
766 } |
731 |
767 |
743 * Description : handle the receiption of metadata. Notify now playing view to update display |
779 * Description : handle the receiption of metadata. Notify now playing view to update display |
744 * Parameters : aIRmetaData : the metadata object |
780 * Parameters : aIRmetaData : the metadata object |
745 */ |
781 */ |
746 void IRPlayController::handleMetaDataReceived(IRQMetaData& aIRmetaData) |
782 void IRPlayController::handleMetaDataReceived(IRQMetaData& aIRmetaData) |
747 { |
783 { |
748 iMetaData = &aIRmetaData; |
784 //when we get metadata, we just update the member but not save to song history db for |
749 //TO DO: there maybe a potential bug when the user cancel the play, |
785 //if the preset is user-defined, we do not get the preset ID in current. |
750 if ((aIRmetaData.getSongName().trimmed() != "") |
786 //just after the 100 percent progress, the play state will be playing |
751 || (aIRmetaData.getArtistName().trimmed() != "")) |
787 iMetaData = &aIRmetaData; |
752 { |
|
753 //when we are play the musicplayer and get the metadata from lower layer, we save the |
|
754 //song's metadata into the db. After we save it to db, we emit the next signal to notify the UI |
|
755 iSongHistoryEngine->handleSongMetaDataReceived(*iMetaData, |
|
756 *iNowPlayingPreset); |
|
757 } |
|
758 |
788 |
759 if (EPlaying == iPlayState) |
789 if (EPlaying == iPlayState) |
760 { |
790 { |
761 // This signal will cause addBanner() work. Sometimes the metadata will come before |
791 // This signal will cause addBanner() work. Sometimes the metadata will come before |
762 // the buffering is 100%, we need to avoid to show playing banner before 100% buffering. |
792 // the buffering is 100%, we need to avoid to show playing banner before 100% buffering. |
|
793 saveSong2DB(*iMetaData, *iNowPlayingPreset); |
763 emit metaDataAvailable(iMetaData); |
794 emit metaDataAvailable(iMetaData); |
764 } |
795 } |
765 } |
796 } |
766 |
797 |
767 /* |
798 /* |
925 * Description : start a session |
956 * Description : start a session |
926 */ |
957 */ |
927 void IRPlayController::startSession() |
958 void IRPlayController::startSession() |
928 { |
959 { |
929 iGetServerResult = false; |
960 iGetServerResult = false; |
930 |
|
931 int channelId = 0; |
|
932 if(iNowPlayingPreset) |
|
933 { |
|
934 channelId = iNowPlayingPreset->presetId; |
|
935 } |
|
936 |
961 |
937 if(iStatisticsReporter) |
962 if(iStatisticsReporter) |
938 { |
963 { |
939 iStatisticsReporter->sessionStarted(channelId,MAP_TO_ENGINE_ConnectedFrom(iConnectedFrom)); |
964 if (iNowPlayingPreset && iNowPlayingPreset->type) // for isds station, use the channel id |
940 } |
965 { |
941 } |
966 iStatisticsReporter->sessionStarted(iNowPlayingPreset->presetId,MAP_TO_ENGINE_ConnectedFrom(iConnectedFrom)); |
942 |
967 } |
943 #ifdef _DEBUG |
968 else // for user defined station, use 0 as channel id instead of the id generated from IRDB |
944 int IRPlayController::bitrateTrying() const |
969 { |
945 { |
970 iStatisticsReporter->sessionStarted(0,MAP_TO_ENGINE_ConnectedFrom(iConnectedFrom)); |
946 return iTryingBitrate; |
971 } |
947 } |
972 } |
948 #endif |
973 } |
|
974 |
|
975 void IRPlayController::saveStation2DB(IRQPreset *aPreset) |
|
976 { |
|
977 if (NULL == aPreset) |
|
978 { |
|
979 return; |
|
980 } |
|
981 |
|
982 columnMap stationInfoSet; |
|
983 |
|
984 stationInfoSet.insert(channelName,aPreset->name); |
|
985 |
|
986 if (aPreset->nickName.isEmpty()) |
|
987 { |
|
988 aPreset->nickName = aPreset->name; |
|
989 } |
|
990 stationInfoSet.insert(channelNickName,aPreset->nickName); |
|
991 |
|
992 if (aPreset->type) // isds station |
|
993 { |
|
994 stationInfoSet.insert(channelId, QString::number(aPreset->presetId)); |
|
995 } |
|
996 else |
|
997 { |
|
998 // for user defined station, should query its existence at first |
|
999 // if not, since putHistoryInfo() does NOT allow url info, same user defined station |
|
1000 // can only have name and nick name info, which will leads to two different channel id generated. |
|
1001 QString userDefinedUrl; |
|
1002 if (EIRQErrorNone == aPreset->getChannelUrlAt(0,userDefinedUrl)) |
|
1003 { |
|
1004 stationInfoSet.insert(channelUrl,userDefinedUrl); |
|
1005 stationInfoSet.insert(channelType,QString::number(aPreset->type)); |
|
1006 QList<uint> *channelIdList = iDbWrapper->getChannelId(&stationInfoSet); |
|
1007 if (channelIdList && (channelIdList->count() > 0)) |
|
1008 { |
|
1009 aPreset->presetId = channelIdList->at(0); |
|
1010 stationInfoSet.insert(channelId, QString::number(channelIdList->at(0))); |
|
1011 |
|
1012 } |
|
1013 if (channelIdList) |
|
1014 { |
|
1015 channelIdList->clear(); |
|
1016 delete channelIdList; |
|
1017 channelIdList = NULL; |
|
1018 } |
|
1019 stationInfoSet.remove(channelType); |
|
1020 stationInfoSet.remove(channelUrl); |
|
1021 } |
|
1022 } |
|
1023 |
|
1024 stationInfoSet.insert(genreName, aPreset->genreName); |
|
1025 stationInfoSet.insert(genreId, aPreset->genreId); |
|
1026 stationInfoSet.insert(languageName, aPreset->languageName); |
|
1027 stationInfoSet.insert(languageCode, aPreset->languageCode); |
|
1028 |
|
1029 stationInfoSet.insert(countryName, aPreset->countryName); |
|
1030 stationInfoSet.insert(countryCode, aPreset->countryCode); |
|
1031 stationInfoSet.insert(description, aPreset->description); |
|
1032 stationInfoSet.insert(shortDesc, aPreset->shortDesc); |
|
1033 |
|
1034 stationInfoSet.insert(lastModified, aPreset->lastModified); |
|
1035 stationInfoSet.insert(musicStoreStatus, aPreset->musicStoreStatus); |
|
1036 |
|
1037 stationInfoSet.insert(imgUrl, aPreset->imgUrl); |
|
1038 |
|
1039 stationInfoSet.insert(advertisementUrl, aPreset->advertisementUrl); |
|
1040 stationInfoSet.insert(advertisementInUse, aPreset->advertisementInUse); |
|
1041 |
|
1042 // should remove url and channel type before put, otherwise false will be returned |
|
1043 stationInfoSet.remove(channelUrl); |
|
1044 stationInfoSet.remove(channelType); |
|
1045 |
|
1046 bool ret = false; |
|
1047 if (aPreset->type) // isds station |
|
1048 { |
|
1049 ret = iHistoryWrapper->putChannelHistory(&stationInfoSet); |
|
1050 } |
|
1051 else // fetch the channel id for user defined station, generated by DB |
|
1052 { |
|
1053 uint generatedChannelId = 0; |
|
1054 ret = iHistoryWrapper->putChannelHistory(&stationInfoSet,&generatedChannelId); |
|
1055 aPreset->presetId = generatedChannelId; |
|
1056 } |
|
1057 |
|
1058 if ((false == ret)||(0 == aPreset->presetId)) |
|
1059 { |
|
1060 return; |
|
1061 } |
|
1062 |
|
1063 columnUrlInfoInsertMap urlInfoSet; |
|
1064 QString url; |
|
1065 unsigned int bitrate; |
|
1066 for (int i=0; i < aPreset->getChannelURLCount(); i++) |
|
1067 { |
|
1068 aPreset->getChannelUrlAt(i,url); |
|
1069 aPreset->getChannelBitrate(i,bitrate); |
|
1070 urlInfoSet.insert(url,bitrate); |
|
1071 } |
|
1072 |
|
1073 iUrlInfoWrapper->resetUrlInfo(&urlInfoSet, aPreset->presetId); |
|
1074 } |
949 |
1075 |
950 void saveStationLogoFlag(bool aIsStationLogoAvailable) |
1076 void saveStationLogoFlag(bool aIsStationLogoAvailable) |
951 { |
1077 { |
952 QSettings settings(KIrSettingOrganization, KIrSettingApplication); |
1078 QSettings settings(KIrSettingOrganization, KIrSettingApplication); |
953 QVariant data(QVariant::Bool); |
1079 QVariant data(QVariant::Bool); |
954 data.setValue(aIsStationLogoAvailable); |
1080 data.setValue(aIsStationLogoAvailable); |
955 settings.setValue(KIrSettingStationLogoAvailable,data); |
1081 settings.setValue(KIrSettingStationLogoAvailable,data); |
956 } |
1082 } |
957 |
1083 |
958 //get IP address configuration of test radio server |
1084 //get IP address configuration of test radio server |
959 #ifdef Q_CC_NOKIAX86 |
1085 #ifdef PLATSIM_DEBUG_CONF |
960 void getRadioServerAddress(QString & aUrl) |
1086 void getRadioServerAddress(QString & aUrl) |
961 { |
1087 { |
962 QFile file("C:\\data\\QTIRConfigure.txt"); |
1088 QFile file("C:\\data\\QTIRConfigure.txt"); |
963 |
1089 |
964 if (file.open(QIODevice::ReadOnly)) |
1090 if (file.open(QIODevice::ReadOnly)) |