radioapp/radiouiengine/src/radioplaylogmodel.cpp
changeset 14 63aabac4416d
parent 13 46974bebc798
equal deleted inserted replaced
13:46974bebc798 14:63aabac4416d
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // System includes
    18 // System includes
    19 #include <qstringlist>
    19 #include <QStringList>
    20 
    20 
    21 // User includes
    21 // User includes
    22 #include "radioplaylogmodel.h"
    22 #include "radioplaylogmodel.h"
    23 #include "radioplaylogmodel_p.h"
    23 #include "radioplaylogmodel_p.h"
    24 #include "radiouiengine.h"
    24 #include "radiouiengine.h"
    25 #include "radioplaylogitem.h"
    25 #include "radioplaylogitem.h"
       
    26 #include "radiostation.h"
       
    27 #include "radiouiengine.h"
    26 #include "radio_global.h"
    28 #include "radio_global.h"
    27 #include "radiologger.h"
    29 #include "radiologger.h"
    28 
    30 
    29 /*!
    31 /*!
    30  *
    32  *
    80     Q_D( const RadioPlayLogModel );
    82     Q_D( const RadioPlayLogModel );
    81     if ( role == Qt::DisplayRole ) {
    83     if ( role == Qt::DisplayRole ) {
    82         RadioPlayLogItem item = d->mItems.at( index.row() );
    84         RadioPlayLogItem item = d->mItems.at( index.row() );
    83 
    85 
    84         QStringList list;
    86         QStringList list;
    85         list.append( item.artist() + " - " + item.title() );
    87         if ( d->mShowDetails ) {
    86         QString secondLine = QString( "Count: %1. Favorite: %2" ).arg( item.playCount() ).arg( item.isFavorite() );
    88             list.append( item.artist() + " - " + item.title() );
    87         list.append( secondLine );
    89             list.append( item.time() + " " + item.station() + " " + RadioUiEngine::parseFrequency( item.frequency() ) );
       
    90         } else {
       
    91             list.append( item.artist() );
       
    92             list.append( item.title() );
       
    93         }
    88 
    94 
    89         return list;
    95         return list;
    90     }
    96     }
    91 
    97 
    92     return QVariant();
    98     return QVariant();
   158 }
   164 }
   159 
   165 
   160 /*!
   166 /*!
   161  *
   167  *
   162  */
   168  */
   163 void RadioPlayLogModel::addItem( const QString& artist, const QString& title )
   169 void RadioPlayLogModel::setShowDetails( bool showDetails )
       
   170 {
       
   171     Q_D( RadioPlayLogModel );
       
   172     d->mShowDetails = showDetails;
       
   173     reset();
       
   174 }
       
   175 
       
   176 /*!
       
   177  *
       
   178  */
       
   179 void RadioPlayLogModel::addItem( const QString& artist, const QString& title, const RadioStation& station )
   164 {
   180 {
   165     Q_D( RadioPlayLogModel );
   181     Q_D( RadioPlayLogModel );
   166 
   182 
   167     RadioPlayLogItem item;
   183     RadioPlayLogItem item;
   168     const int itemIndex = findItem( artist, title, item );
   184     const int itemIndex = findItem( artist, title, item );
   170         item.increasePlayCount();
   186         item.increasePlayCount();
   171         updateItem( itemIndex, item, true );
   187         updateItem( itemIndex, item, true );
   172     } else {
   188     } else {
   173         item.setArtist( artist );
   189         item.setArtist( artist );
   174         item.setTitle( title );
   190         item.setTitle( title );
       
   191         item.setStation( station.name() );
       
   192         item.setFrequency( station.frequency() );
       
   193         item.setCurrentTime();
   175 
   194 
   176         beginInsertRows( QModelIndex(), 0, 0 );
   195         beginInsertRows( QModelIndex(), 0, 0 );
   177 
   196 
   178         d->mItems.prepend( item );
   197         d->mItems.prepend( item );
   179 
   198 
   195 }
   214 }
   196 
   215 
   197 /*!
   216 /*!
   198  *
   217  *
   199  */
   218  */
   200 void RadioPlayLogModel::addRadioTextPlus( int rtClass, const QString& rtItem )
   219 void RadioPlayLogModel::addRadioTextPlus( int rtClass, const QString& rtItem, const RadioStation& station )
   201 {
   220 {
   202     if ( rtClass == RtPlus::Artist || rtClass == RtPlus::Title ) {
   221     if ( rtClass == RtPlus::Artist || rtClass == RtPlus::Title ) {
   203         Q_D( RadioPlayLogModel );
   222         Q_D( RadioPlayLogModel );
   204         if ( d->mRtItemHolder.isEmpty() ) {
   223         if ( d->mRtItemHolder.isEmpty() ) {
   205             d->mRtItemHolder = rtItem;
   224             d->mRtItemHolder = rtItem;
   206         } else {
   225         } else {
   207             if ( rtClass == RtPlus::Title ) {
   226             if ( rtClass == RtPlus::Title ) {
   208                 addItem( d->mRtItemHolder, rtItem );
   227                 addItem( d->mRtItemHolder, rtItem, station );
   209             } else {
   228             } else {
   210                 addItem( rtItem, d->mRtItemHolder );
   229                 addItem( rtItem, d->mRtItemHolder, station );
   211             }
   230             }
   212             d->mRtItemHolder = "";
   231             d->mRtItemHolder = "";
   213         }
   232         }
   214     }
   233     }
   215 }
   234 }