diff -r a2b50a479edf -r 6df133bd92e1 radioapp/radiouiengine/src/radiohistorymodel.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/radioapp/radiouiengine/src/radiohistorymodel.cpp Fri Jun 04 10:21:36 2010 +0100 @@ -0,0 +1,226 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +// System includes +#include + +// User includes +#include "radiohistorymodel.h" +#include "radiohistorymodel_p.h" +#include "radiouiengine.h" +#include "radiohistoryitem.h" +#include "radiostation.h" +#include "radiouiengine.h" +#include "radio_global.h" +#include "radiologger.h" + +/*! + * + */ +RadioHistoryModel::RadioHistoryModel( RadioUiEngine& uiEngine ) : + QAbstractListModel( &uiEngine ), + d_ptr( new RadioHistoryModelPrivate( this, uiEngine ) ) +{ + connectAndTest( &uiEngine, SIGNAL(tunedToFrequency(uint,int)), + this, SLOT(resetCurrentSong()) ); + connectAndTest( &uiEngine, SIGNAL(seekingStarted(int)), + this, SLOT(resetCurrentSong()) ); + + Q_D( RadioHistoryModel ); + d->connectToDatabase(); +} + +/*! + * + */ +RadioHistoryModel::~RadioHistoryModel() +{ + Q_D( RadioHistoryModel ); + delete d_ptr; +} + +/*! + * \reimp + */ +int RadioHistoryModel::rowCount( const QModelIndex& parent ) const +{ + Q_UNUSED( parent ); + Q_D( const RadioHistoryModel ); + return d->rowCount(); +} + +/*! + * \reimp + */ +QVariant RadioHistoryModel::data( const QModelIndex& index, int role ) const +{ + if ( !index.isValid() ) { + return QVariant(); + } + + Q_D( const RadioHistoryModel ); + return d->data( index.row(), role ); +} + +/*! + * Public slot + */ +void RadioHistoryModel::resetCurrentSong() +{ + Q_D( RadioHistoryModel ); + d->mTopItemIsPlaying = false; + emit currentSongReset(); +} + +/*! + * Public slot + */ +void RadioHistoryModel::removeAll() +{ + Q_D( RadioHistoryModel ); + d->removeAll(); +} + +/*! + * Sets the icons to be used in the list + */ +void RadioHistoryModel::setIcons( const QIcon& nonTaggedIcon, const QIcon& taggedIcon ) +{ + Q_D( RadioHistoryModel ); + d->mNonTaggedIcon = nonTaggedIcon; + d->mTaggedIcon = taggedIcon; +} + +/*! + * + */ +bool RadioHistoryModel::isCurrentSongRecognized() const +{ + Q_D( const RadioHistoryModel ); + return d->mTopItemIsPlaying; +} + +/*! + * + */ +void RadioHistoryModel::setShowDetails( bool showDetails ) +{ + Q_D( RadioHistoryModel ); + d->mShowDetails = showDetails; + reset(); +} + +/*! + * + */ +void RadioHistoryModel::setShowTagged( bool showTagged ) +{ + Q_D( RadioHistoryModel ); + d->setViewMode( showTagged ? RadioHistoryModelPrivate::ShowTagged : RadioHistoryModelPrivate::ShowAll ); +} + +/*! + * + */ +void RadioHistoryModel::toggleTagging( const RadioHistoryItem& item, const int row ) +{ + Q_D( RadioHistoryModel ); + d->toggleTagging( item, row ); +} + +/*! + * + */ +RadioHistoryItem RadioHistoryModel::itemAtIndex( const QModelIndex& index ) const +{ + Q_D( const RadioHistoryModel ); + return d->itemAtIndex( index ); +} + +/*! + * + */ +void RadioHistoryModel::addItem( const QString& artist, const QString& title, const RadioStation& station ) +{ + Q_D( RadioHistoryModel ); + d->addItem( artist, title, station ); +} + +/*! + * + */ +void RadioHistoryModel::clearRadioTextPlus() +{ + Q_D( RadioHistoryModel ); + d->mRtItemHolder = ""; + resetCurrentSong(); +} + +/*! + * + */ +void RadioHistoryModel::addRadioTextPlus( int rtClass, const QString& rtItem, const RadioStation& station ) +{ + if ( rtClass == RtPlus::Dummy || rtClass == RtPlus::Artist || rtClass == RtPlus::Title ) { + Q_D( RadioHistoryModel ); + if ( d->mRtItemClass == -1 ) { + d->mRtItemClass = rtClass; + d->mRtItemHolder = rtItem; + } else { + // Received: Artist - Title + if ( d->mRtItemClass == RtPlus::Artist && rtClass == RtPlus::Title ) { + addItem( d->mRtItemHolder, rtItem, station ); + + // Received: Title - Artist + } else if ( rtClass == RtPlus::Artist && d->mRtItemClass == RtPlus::Title ) { + addItem( rtItem, d->mRtItemHolder, station ); + + // Received: Dummy - Title + } else if ( d->mRtItemClass == RtPlus::Dummy && rtClass == RtPlus::Title ) { + addItem( "", rtItem, station ); + + // Received: Title - Dummy + } else if ( rtClass == RtPlus::Dummy && d->mRtItemClass == RtPlus::Title ) { + addItem( "", d->mRtItemHolder, station ); + } + + d->mRtItemHolder = ""; + d->mRtItemClass = -1; + } + } +} + +/*! + * + */ +void RadioHistoryModel::reportChangedData( int start, int end ) +{ + if ( end == -1 ) { + end = start; + } + const QModelIndex startIndex = index( start, 0, QModelIndex() ); + const QModelIndex endIndex = index( end, 0, QModelIndex() ); + emit dataChanged( startIndex, endIndex ); +} + +/*! + * + */ +void RadioHistoryModel::emitItemAdded() +{ + emit itemAdded(); +}