qtinternetradio/ui/src/irplsmodel.cpp
changeset 0 09774dfdd46b
child 3 ee64f059b8e1
equal deleted inserted replaced
-1:000000000000 0:09774dfdd46b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QBrush>
       
    19 
       
    20 #include "iruidefines.h"
       
    21 #include "irplsmodel.h"
       
    22 #include "irsymbiandocument.h"
       
    23 
       
    24 
       
    25 IRPlsModel::IRPlsModel(QObject *aParent) : QAbstractListModel(aParent), iDocument(NULL)
       
    26 {
       
    27     iDocument = IRSymbianDocument::getInstance();
       
    28 }
       
    29 
       
    30 int IRPlsModel::rowCount(const QModelIndex &aParent) const
       
    31 {
       
    32     Q_UNUSED(aParent);
       
    33     return iDocument->getNumberOfEntries();
       
    34 }
       
    35 
       
    36 QVariant IRPlsModel::data(const QModelIndex &aIndex, int aRole) const
       
    37 {
       
    38     if (!aIndex.isValid())
       
    39         return QVariant();
       
    40 
       
    41     if (aIndex.row() >= rowCount(QModelIndex()))
       
    42         return QVariant();
       
    43     
       
    44     if (aRole == Qt::DisplayRole)
       
    45     {
       
    46         int row = aIndex.row();
       
    47         QVariantList list;
       
    48         IRPlsPlayListItem *item = iDocument->getEntry(row);
       
    49         list.append(item->title());
       
    50         list.append(item->file());
       
    51         return list;
       
    52     }
       
    53     else if (aRole == Qt::BackgroundRole)
       
    54     {
       
    55         if (aIndex.row() % 2 == 0)
       
    56         {
       
    57             return QBrush(KListEvenRowColor);
       
    58         }
       
    59         else
       
    60         {
       
    61             return QBrush(KListOddRowColor);
       
    62         }
       
    63     }
       
    64     
       
    65     return QVariant();
       
    66 }
       
    67 
       
    68 const QString& IRPlsModel::getFile(int aIndex) const
       
    69 {
       
    70     IRPlsPlayListItem *item = iDocument->getEntry(aIndex);
       
    71     return item->file();
       
    72 }
       
    73 
       
    74 const QString& IRPlsModel::getTitle(int aIndex) const
       
    75 {
       
    76     IRPlsPlayListItem *item = iDocument->getEntry(aIndex);
       
    77     return item->title();
       
    78 }