qtinternetradio/ui/src/irplaycontroller.cpp
changeset 3 ee64f059b8e1
parent 2 2e1adbfc62af
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    23 #endif
    23 #endif
    24 
    24 
    25 #include "irplaycontroller.h"
    25 #include "irplaycontroller.h"
    26 #include "irapplication.h"
    26 #include "irapplication.h"
    27 #include "irqmediaplayer.h"
    27 #include "irqmediaplayer.h"
    28 #include "irabstractviewmanager.h"
    28 #include "irviewmanager.h"
    29 #include "irqisdsdatastructure.h"
    29 #include "irqisdsdatastructure.h"
    30 #include "irlastplayedstationinfo.h"
    30 #include "irlastplayedstationinfo.h"
    31 #include "irqnetworkcontroller.h" 
    31 #include "irqnetworkcontroller.h" 
    32 #include "irqsonghistoryengine.h"
    32 #include "irqsonghistoryengine.h"
    33 #include "irqmetadata.h"
    33 #include "irqmetadata.h"
    34 #include "irqsettings.h"
    34 #include "irqsettings.h"
    35 #include "irqfavoritesdb.h"
    35 #include "irqfavoritesdb.h"
    36 #include "irqstatisticsreporter.h"
    36 #include "irqstatisticsreporter.h"
       
    37 #include "irenummapper.h"
    37 
    38 
    38 #ifdef Q_CC_NOKIAX86
    39 #ifdef Q_CC_NOKIAX86
    39 void getRadioServerAddress(QString & aUrl);
    40 void getRadioServerAddress(QString & aUrl);
    40 #endif
    41 #endif
       
    42 
       
    43 BEGIN_ENUM_MAP( KTerminationTypeMap )
       
    44     ENUM_MAP_ITEM( EIRQUserTerminated, IRQStatisticsReporter::EIRUserTerminated ),
       
    45     ENUM_MAP_ITEM( EIRQNoConnectionToServer, IRQStatisticsReporter::EIRNoConnToServer ),
       
    46     ENUM_MAP_ITEM( EIRQNoConnectionToNetwork, IRQStatisticsReporter::EIRNoConnToNetwork )            
       
    47 END_ENUM_MAP( KTerminationTypeMap )
       
    48 
       
    49 #define MAP_TO_ENGINE_TerminationType(ui_enum) \
       
    50           MAP_TO_ENGINE_ENUM( IRQTerminatedType, \
       
    51              IRQStatisticsReporter::IRTerminatedType, \
       
    52              ui_enum, KTerminationTypeMap )
       
    53     
       
    54 BEGIN_ENUM_MAP( KServerResultMap )
       
    55     ENUM_MAP_ITEM( EIRQPlayerErrorServerFull, IRQStatisticsReporter::EIRServerFull ),
       
    56     ENUM_MAP_ITEM( EIRQPlayerErrorTimeOut, IRQStatisticsReporter::EIRTimeOut ),
       
    57     ENUM_MAP_ITEM( EIRQPlayerErrorConnectingFailed, IRQStatisticsReporter::EIRConnectFailed )              
       
    58 END_ENUM_MAP( KServerResultMap )
       
    59 
       
    60 #define MAP_TO_ENGINE_ServerResult(ui_enum) \
       
    61           MAP_TO_ENGINE_ENUM( IRQError, \
       
    62              IRQStatisticsReporter::IRServerResult, \
       
    63              ui_enum, KServerResultMap )
       
    64              
       
    65 BEGIN_ENUM_MAP( KConnectedFromMap )
       
    66     ENUM_MAP_ITEM( EIRQIsds, IRQStatisticsReporter::EIRIsds ),
       
    67     ENUM_MAP_ITEM( EIRQPresetAdhoc, IRQStatisticsReporter::EIRPresetAdhoc ),
       
    68     ENUM_MAP_ITEM( EIRQPresetIsds, IRQStatisticsReporter::EIRPresetIsds ),
       
    69     ENUM_MAP_ITEM( EIRQHistoryAdhoc, IRQStatisticsReporter::EIRHistoryAdhoc ),
       
    70     ENUM_MAP_ITEM( EIRQHistoryIsds, IRQStatisticsReporter::EIRHistoryIsds ),
       
    71     ENUM_MAP_ITEM( EIRQAdhocManual, IRQStatisticsReporter::EIRAdhocManual ),                
       
    72     ENUM_MAP_ITEM( EIRQAdhocExternal, IRQStatisticsReporter::EIRAdhocExternal )            
       
    73 END_ENUM_MAP( KConnectedFromMap )
       
    74 
       
    75 #define MAP_TO_ENGINE_ConnectedFrom(ui_enum) \
       
    76           MAP_TO_ENGINE_ENUM( IRQConnectedFrom, \
       
    77              IRQStatisticsReporter::IRConnectedFrom, \
       
    78              ui_enum, KConnectedFromMap )                 
    41 
    79 
    42 //                                        public functions
    80 //                                        public functions
    43 
    81 
    44 /*
    82 /*
    45  * Description : constructor
    83  * Description : constructor
    47 IRPlayController::IRPlayController(IRApplication* aApplication) :
    85 IRPlayController::IRPlayController(IRApplication* aApplication) :
    48     iApplication(aApplication),
    86     iApplication(aApplication),
    49     iMediaPlayer(new IRQMediaPlayer()),
    87     iMediaPlayer(new IRQMediaPlayer()),
    50     iStatisticsReporter(NULL),
    88     iStatisticsReporter(NULL),
    51     iConnectedFrom(EIRQIsds),
    89     iConnectedFrom(EIRQIsds),
    52     iSessionStarted(false),  
       
    53     iGetServerResult(false),
    90     iGetServerResult(false),
    54     iBufferingDialog(NULL),
    91     iBufferingDialog(NULL),
    55     iNowPlayingPreset(new IRQPreset()),
    92     iNowPlayingPreset(new IRQPreset()),
    56     iMetaData(NULL),
    93     iMetaData(NULL),
    57     iSongHistoryEngine(IRQSongHistoryEngine::openInstance()),
    94     iSongHistoryEngine(IRQSongHistoryEngine::openInstance()),
    58     iPlayState(EStopped),
    95     iPlayState(EIdle),
    59     iResuming(false),
    96     iResuming(false),
    60     iTryingBitrate(0),
    97     iTryingBitrate(0),
    61     iUrlArray(0),
    98     iUrlArray(0),
    62     iRealBitrate(0),
    99     iRealBitrate(0),
    63     iLastError(EIRQErrorNone),
   100     iLastError(EIRQErrorNone),
    64     iStopReason(EIRQUnknownTermination)
   101     iStopReason(EIRQUnknownTermination)
    65 {
   102 {
    66     connectSignalSlot(); 
   103     connectSignalSlot(); 
    67     iStatisticsReporter = iApplication->getStatisticsReporter();
   104     iStatisticsReporter = IRQStatisticsReporter::openInstance();
    68 }
   105 }
    69 
   106 
    70 /*
   107 /*
    71  * Description : destructor
   108  * Description : destructor
    72  */
   109  */
    73 IRPlayController::~IRPlayController()
   110 IRPlayController::~IRPlayController()
    74 {
   111 {
    75     iApplication = NULL;
       
    76     iPlayState = EStopped;
       
    77 
       
    78     delete iBufferingDialog;
   112     delete iBufferingDialog;
    79     iBufferingDialog = NULL;
   113     iBufferingDialog = NULL;
    80 
   114 
    81     stop(EIRQUserTerminated);
   115     stop(EIRQUserTerminated);
    82     delete iMediaPlayer;
   116     delete iMediaPlayer;
    86     iNowPlayingPreset = NULL;
   120     iNowPlayingPreset = NULL;
    87 
   121 
    88     delete iUrlArray;
   122     delete iUrlArray;
    89     iUrlArray = NULL;
   123     iUrlArray = NULL;
    90 
   124 
    91     iMetaData = NULL;
       
    92 
       
    93     if (iSongHistoryEngine)
   125     if (iSongHistoryEngine)
    94     {
   126     {
    95         iSongHistoryEngine->closeInstance();
   127         iSongHistoryEngine->closeInstance();
    96         iSongHistoryEngine = NULL;
   128         iSongHistoryEngine = NULL;
       
   129     }
       
   130     
       
   131     if (iStatisticsReporter)
       
   132     {
       
   133         iStatisticsReporter->closeInstance();
    97     }
   134     }
    98 }
   135 }
    99 
   136 
   100 /*
   137 /*
   101  * Description : connect to a channel specified by aPreset.
   138  * Description : connect to a channel specified by aPreset.
   215 /*
   252 /*
   216  * Description : End Session
   253  * Description : End Session
   217  */
   254  */
   218 void IRPlayController::endSession(IRQTerminatedType aStopReason)
   255 void IRPlayController::endSession(IRQTerminatedType aStopReason)
   219 {
   256 {
   220     if(iStatisticsReporter && iSessionStarted)
   257     if(iStatisticsReporter)
   221     {
   258     {
   222         if(!iGetServerResult)
   259         if(!iGetServerResult)
   223         {
   260         {
   224             iStatisticsReporter->logServerResult(iLastPlayedUrl,EIRQPlayerErrorConnectingFailed);
   261             iStatisticsReporter->logServerResult(iLastPlayedUrl,IRQStatisticsReporter::EIRConnectFailed);
   225         }
   262         }
   226         iStatisticsReporter->sessionEnded(aStopReason);
   263         iStatisticsReporter->sessionEnded(MAP_TO_ENGINE_TerminationType(aStopReason));
   227         iSessionStarted = false;
       
   228     }
   264     }
   229 }
   265 }
   230 
   266 
   231 /*
   267 /*
   232  * Description : get current volume setting from media player or
   268  * Description : get current volume setting from media player or
   305  * Return      : pointer to the now playing preset
   341  * Return      : pointer to the now playing preset
   306  */
   342  */
   307 IRQPreset * IRPlayController::getNowPlayingPreset() const
   343 IRQPreset * IRPlayController::getNowPlayingPreset() const
   308 {
   344 {
   309     return iNowPlayingPreset;
   345     return iNowPlayingPreset;
       
   346 }
       
   347 
       
   348 QString IRPlayController::getNowPlayingUrl() const
       
   349 {
       
   350     return iLastPlayedUrl;
       
   351 }
       
   352 
       
   353 int IRPlayController::getNowPlayingBitRate() const
       
   354 {
       
   355     return iRealBitrate;
   310 }
   356 }
   311 
   357 
   312 /*
   358 /*
   313  * Description : return current metadata
   359  * Description : return current metadata
   314  * Return      : pointer to current metadata
   360  * Return      : pointer to current metadata
   365  * Description : data connection has been established. Signal is emitted by media player.
   411  * Description : data connection has been established. Signal is emitted by media player.
   366  * 
   412  * 
   367  */
   413  */
   368 void IRPlayController::connectionEstablished(int aBitrate)
   414 void IRPlayController::connectionEstablished(int aBitrate)
   369 {
   415 {
   370     if(iStatisticsReporter && iSessionStarted)
   416     if(iStatisticsReporter)
   371     {
   417     {
   372         iStatisticsReporter->logServerResult(iLastPlayedUrl,EIRQErrorNone);
   418         iStatisticsReporter->logServerResult(iLastPlayedUrl,IRQStatisticsReporter::EIRConnected);
   373         iGetServerResult = true;
   419         iGetServerResult = true;
   374         iStatisticsReporter->markSessionStart();
   420         iStatisticsReporter->markSessionStart();
   375     }
   421     }
   376 
   422 
   377     iMetaData = NULL;
   423     iMetaData = NULL;
   412     case EIRQPlayerErrorServerFull:
   458     case EIRQPlayerErrorServerFull:
   413     case EIRQPlayerErrorTimeOut:
   459     case EIRQPlayerErrorTimeOut:
   414     case EIRQPlayerErrorConnectingFailed:
   460     case EIRQPlayerErrorConnectingFailed:
   415         if(iStatisticsReporter)
   461         if(iStatisticsReporter)
   416         {
   462         {
   417             iStatisticsReporter->logServerResult(iLastPlayedUrl,iLastError);
   463             iStatisticsReporter->logServerResult(iLastPlayedUrl,MAP_TO_ENGINE_ServerResult(iLastError));
   418             iGetServerResult = true;
   464             iGetServerResult = true;
   419         }
   465         }
   420 		
   466 		
   421         // if there's NO other URL to try, show warning.
   467         // if there's NO other URL to try, show warning.
   422         if (iNowPlayingPreset->getChannelURLCount() == 1)
   468         if (iNowPlayingPreset->getChannelURLCount() == 1)
   423         {
   469         {
   424 		    endSession(EIRQNoConnectionToServer);
   470 		    stop(EIRQNoConnectionToServer);
   425             break;
   471             break;
   426         }
   472         }
   427 
   473 
   428         if (iResuming)
   474         if (iResuming)
   429         {
   475         {
   438         {
   484         {
   439             return;
   485             return;
   440         }
   486         }
   441         else
   487         else
   442         {
   488         {
   443             endSession(EIRQNoConnectionToServer);
   489             stop(EIRQNoConnectionToServer);
   444         }
   490         }
   445         break;
   491         break;
   446 
   492 
   447     case EIRQPlayerErrorConnectionLost:
   493     case EIRQPlayerErrorConnectionLost:
   448         qDebug("IRPlayController::handleError, connection lost");
   494         qDebug("IRPlayController::handleError, connection lost");
   506             // Save the station information to database
   552             // Save the station information to database
   507             IRQMetaData tmpMetaData;
   553             IRQMetaData tmpMetaData;
   508             tmpMetaData.setBitrate(iRealBitrate);
   554             tmpMetaData.setBitrate(iRealBitrate);
   509             tmpMetaData.setStreamUrl(iLastPlayedUrl);
   555             tmpMetaData.setStreamUrl(iLastPlayedUrl);
   510             iSongHistoryEngine->handleMetaDataReceived(tmpMetaData, *iNowPlayingPreset);
   556             iSongHistoryEngine->handleMetaDataReceived(tmpMetaData, *iNowPlayingPreset);
   511             // open stereo according to settings
   557             // open stereo defaultly
   512             if (1 == iApplication->getSettings()->getStereoMode())
   558             iMediaPlayer->enableStereoEffect();
   513             {
       
   514                 iMediaPlayer->enableStereoEffect();
       
   515             }
       
   516         }
   559         }
   517     }
   560     }
   518 }
   561 }
   519 
   562 
   520 /*
   563 /*
   686     if(iNowPlayingPreset)
   729     if(iNowPlayingPreset)
   687     {
   730     {
   688         channelId = iNowPlayingPreset->presetId;
   731         channelId = iNowPlayingPreset->presetId;
   689     }
   732     }
   690 	      
   733 	      
   691     if(iStatisticsReporter && !iSessionStarted)
   734     if(iStatisticsReporter)
   692     {
   735     {
   693         iSessionStarted = iStatisticsReporter->sessionStarted(channelId,iConnectedFrom);
   736         iStatisticsReporter->sessionStarted(channelId,MAP_TO_ENGINE_ConnectedFrom(iConnectedFrom));
   694     }
   737     }
   695 }
   738 }
   696 
   739 
   697 #ifdef _DEBUG
   740 #ifdef _DEBUG
   698 int IRPlayController::bitrateTrying() const
   741 int IRPlayController::bitrateTrying() const