qtinternetradio/ui/src/irmainmodel.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 #include <hbglobal.h>
       
    20 
       
    21 #include "iruidefines.h"
       
    22 #include "irmainmodel.h"
       
    23 #include "irsymbiandocument.h"
       
    24 
       
    25 IRMainModel::IRMainModel(QObject *aParent) : QAbstractListModel(aParent)
       
    26 {
       
    27     initModel();
       
    28 }
       
    29 
       
    30 int IRMainModel::rowCount(const QModelIndex &aParent) const
       
    31 {
       
    32     Q_UNUSED(aParent);
       
    33     return iPrimaryTexts.count();
       
    34 }
       
    35 
       
    36 QVariant IRMainModel::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         list.append(iPrimaryTexts.at(row));
       
    49         list.append(iSecondaryTexts.at(row));
       
    50         return list;
       
    51     }
       
    52     else if (aRole == Qt::BackgroundRole)
       
    53     {
       
    54         if (aIndex.row() % 2 == 0)
       
    55         {
       
    56             return QBrush(KListEvenRowColor);
       
    57         }
       
    58         else
       
    59         {
       
    60             return QBrush(KListOddRowColor);
       
    61         }
       
    62     }
       
    63     
       
    64     return QVariant();
       
    65 }
       
    66 
       
    67 void IRMainModel::initModel()
       
    68 {
       
    69     iPrimaryTexts << hbTrId("txt_irad_list_recently_played_stations") 
       
    70                   << hbTrId("txt_irad_list_stations_by_country_region")
       
    71                   << hbTrId("txt_irad_list_stations_by_language")
       
    72                   << hbTrId("txt_irad_list_recently_played_songs");
       
    73     iSecondaryTexts << tr("BBC World Service, Cloud FM ...") << tr("US, UK, France, Korea, Mexico ...") 
       
    74                     << tr("English, French, German...")
       
    75                     << tr("Recently played songs");
       
    76 }
       
    77 void IRMainModel::checkUpdate()
       
    78 {
       
    79     IRSymbianDocument *document = IRSymbianDocument::getInstance();
       
    80     QString primary = hbTrId("txt_irad_subtitle_stations_from_play_list");     
       
    81     QString secondary = tr("Stations from play list file");
       
    82     if (document->isPlsAvailable())
       
    83     {
       
    84         //if pls item is not in collections view, add
       
    85         if (iPrimaryTexts.indexOf(primary) == -1)
       
    86         {
       
    87             int number = iPrimaryTexts.count();
       
    88             beginInsertRows(QModelIndex(), number, number);
       
    89             iPrimaryTexts << primary;
       
    90             iSecondaryTexts << secondary;
       
    91             endInsertRows();
       
    92         }
       
    93     }
       
    94     else
       
    95     {
       
    96         //if pls item is in collections view, remove
       
    97         int index = iPrimaryTexts.indexOf(primary);
       
    98         if (index != -1)
       
    99         {
       
   100             beginRemoveRows(QModelIndex(), index, index);
       
   101             iPrimaryTexts.removeAt(index);
       
   102             iSecondaryTexts.removeAt(index);
       
   103             endRemoveRows();
       
   104         }
       
   105     }
       
   106 }