diff -r 63aabac4416d -r f54ebcfc1b80 radioapp/radiouiengine/src/radiomonitorservice.cpp --- a/radioapp/radiouiengine/src/radiomonitorservice.cpp Fri Apr 16 14:58:55 2010 +0300 +++ b/radioapp/radiouiengine/src/radiomonitorservice.cpp Mon May 03 12:31:41 2010 +0300 @@ -18,15 +18,24 @@ // User includes #include "radiomonitorservice.h" #include "radiouiengine.h" -#include "radioserviceconst.h" +#include "radiostationmodel.h" +#include "radiostation.h" +#include "radioservicedef.h" +#include "radionotificationdata.h" + +#define RUN_NOTIFY( type, data ) \ + do { \ + QVariant variant; \ + variant.setValue( RadioNotificationData( RadioServiceNotification::type, data ) ); \ + notify( variant ); \ + } while ( 0 ) /*! * */ RadioMonitorService::RadioMonitorService( RadioUiEngine& engine ) : XQServiceProvider( RADIO_MONITOR_SERVICE, &engine ), - mUiEngine( engine ), - mRequestIndex( 0 ) + mUiEngine( engine ) { publishAll(); } @@ -41,9 +50,41 @@ /*! * */ +void RadioMonitorService::notifyFavoriteCount( const int favoriteCount ) +{ + RUN_NOTIFY( FavoriteCount, favoriteCount ); +} + +/*! + * + */ +void RadioMonitorService::notifyAntennaStatus( bool connected ) +{ + RUN_NOTIFY( AntennaConnected, connected ); +} + +/*! + * + */ +void RadioMonitorService::notifyRadioStatus( RadioStatus::Status radioStatus ) +{ + RUN_NOTIFY( RadioStatus, radioStatus ); +} + +/*! + * + */ +void RadioMonitorService::notifyFrequency( const uint frequency ) +{ + RUN_NOTIFY( Frequency, frequency ); +} + +/*! + * + */ void RadioMonitorService::notifyName( const QString& name ) { - notify( RadioServiceNotification::Name, name ); + RUN_NOTIFY( Name, name ); } /*! @@ -51,7 +92,7 @@ */ void RadioMonitorService::notifyGenre( const QString& genre ) { - notify( RadioServiceNotification::Genre, genre ); + RUN_NOTIFY( Genre, genre ); } /*! @@ -59,15 +100,15 @@ */ void RadioMonitorService::notifyRadioText( const QString& radioText ) { - notify( RadioServiceNotification::RadioText, radioText ); + RUN_NOTIFY( RadioText, radioText ); } /*! * */ -void RadioMonitorService::notifyHomepage( const QString& homepage ) +void RadioMonitorService::notifyHomePage( const QString& homePage ) { - notify( RadioServiceNotification::Homepage, homepage ); + RUN_NOTIFY( HomePage, homePage ); } /*! @@ -75,7 +116,7 @@ */ void RadioMonitorService::notifySong( const QString& song ) { - notify( RadioServiceNotification::Song, song ); + RUN_NOTIFY( Song, song ); } /*! @@ -84,16 +125,72 @@ */ void RadioMonitorService::requestNotifications() { - mRequestIndex = setCurrentRequestAsync(); + mRequestIndexes.append( setCurrentRequestAsync() ); +} + +/*! + * Public slot + * + */ +void RadioMonitorService::requestAllData() +{ + const RadioStation station = mUiEngine.model().currentStation(); + + QVariantList notificationList; + + QVariant notification; + notification.setValue( RadioNotificationData( RadioServiceNotification::FavoriteCount, mUiEngine.model().favoriteCount() ) ); + notificationList.append( notification ); + + notification.setValue( RadioNotificationData( RadioServiceNotification::Frequency, station.frequency() ) ); + notificationList.append( notification ); + + if ( !station.name().isEmpty() ) { + notification.setValue( RadioNotificationData( RadioServiceNotification::Name, station.name() ) ); + notificationList.append( notification ); + } + + if ( station.genre() > 0 ) { + notification.setValue( RadioNotificationData( RadioServiceNotification::Genre, mUiEngine.genreToString( station.genre(), GenreTarget::HomeScreen ) ) ); + notificationList.append( notification ); + } + + if ( !station.radioText().isEmpty() ) { + notification.setValue( RadioNotificationData( RadioServiceNotification::RadioText, station.radioText() ) ); + notificationList.append( notification ); + } + + if ( !station.url().isEmpty() ) { + notification.setValue( RadioNotificationData( RadioServiceNotification::HomePage, station.url() ) ); + notificationList.append( notification ); + } + + //TODO: To be implemented +// notification.setValue( RadioNotificationData( RadioServiceNotification::Song, ) ); +// notificationList.append( notification ); + + completeRequest( setCurrentRequestAsync(), notificationList ); } /*! * */ -void RadioMonitorService::notify( int notificationId, const QString& message ) +void RadioMonitorService::notify( const QVariant& notification ) { - if ( mRequestIndex > 0 ) { - completeRequest( mRequestIndex, QString( "%1 %2" ).arg( notificationId ).arg( message ) ); - mRequestIndex = 0; + QVariantList list; + list.append( notification ); + notifyList( list ); +} + +/*! + * + */ +void RadioMonitorService::notifyList( const QVariantList& list ) +{ + if ( mRequestIndexes.count() > 0 ) { + foreach ( int requestIndex, mRequestIndexes ) { + completeRequest( requestIndex, list ); + } + mRequestIndexes.clear(); } }