qtinternetradio/ui/src/irsonghistorymodel.cpp
changeset 3 ee64f059b8e1
parent 0 09774dfdd46b
child 5 0930554dc389
equal deleted inserted replaced
2:2e1adbfc62af 3:ee64f059b8e1
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
       
    18 #include <QBrush>
       
    19 #include <hbglobal.h>
    17 #include <hbglobal.h>
    20 
    18 
    21 #include "irqsonghistoryinfo.h"
    19 #include "irqsonghistoryinfo.h"
    22 #include "irqsonghistoryengine.h"
    20 #include "irqsonghistoryengine.h"
    23 #include "irsonghistorymodel.h"
    21 #include "irsonghistorymodel.h"
    24 #include "iruidefines.h"
       
    25 
    22 
    26 IRSongHistoryModel::IRSongHistoryModel(QObject *aParent) : QAbstractListModel(aParent)
    23 IRSongHistoryModel::IRSongHistoryModel(QObject *aParent) : QAbstractListModel(aParent)
    27 {     
    24 {     
    28     iHistoryEngine = IRQSongHistoryEngine::openInstance();
    25     mHistoryEngine = IRQSongHistoryEngine::openInstance();
    29     getAllList();
    26     getAllList();
    30 }
    27 }
    31 
    28 
    32 IRSongHistoryModel::~IRSongHistoryModel()
    29 IRSongHistoryModel::~IRSongHistoryModel()
    33 {
    30 {
    34     while (!iSongHistoryList.isEmpty())
    31     while (!mSongHistoryList.isEmpty())
    35     {
    32     {
    36         delete iSongHistoryList.takeFirst();
    33         delete mSongHistoryList.takeFirst();
    37     }
    34     }
    38     
    35     
    39     if (iHistoryEngine)
    36     if (mHistoryEngine)
    40     {
    37     {
    41         iHistoryEngine->closeInstance();
    38         mHistoryEngine->closeInstance();
    42         iHistoryEngine = NULL;
    39         mHistoryEngine = NULL;
    43     }
    40     }
    44 }
    41 }
    45 
    42 
    46 int IRSongHistoryModel::rowCount(const QModelIndex &aParent) const
    43 int IRSongHistoryModel::rowCount(const QModelIndex &aParent) const
    47 {
    44 {
    48     Q_UNUSED(aParent);
    45     Q_UNUSED(aParent);
    49     return iSongHistoryList.count();
    46     return mSongHistoryList.count();
    50 }
    47 }
    51  
    48  
    52  
    49  
    53 QVariant IRSongHistoryModel::data(const QModelIndex &aIndex, int aRole) const
    50 QVariant IRSongHistoryModel::data(const QModelIndex &aIndex, int aRole) const
    54 {
    51 {
    57         return QVariant();
    54         return QVariant();
    58     }
    55     }
    59     
    56     
    60     int row = aIndex.row();
    57     int row = aIndex.row();
    61 
    58 
    62     if (aIndex.row() >= iSongHistoryList.count())
    59     if (aIndex.row() >= mSongHistoryList.count())
    63     {
    60     {
    64         return QVariant();
    61         return QVariant();
    65     }
    62     }
    66     
    63     
    67     if (aRole == Qt::DisplayRole)
    64     if (aRole == Qt::DisplayRole)
    68     {
    65     {
    69         QVariantList list;      
    66         QVariantList list;      
    70         
    67              
    71         QString songName = iSongHistoryList.at(row)->getSongName();
    68         QString artistName = mSongHistoryList.at(row)->getArtistName().trimmed();
    72         songName = songName.trimmed();
    69         if( "" == artistName )
       
    70         {
       
    71             artistName = hbTrId("txt_irad_list_unknown_artist");
       
    72         }
       
    73       
       
    74         QString songName = mSongHistoryList.at(row)->getSongName().trimmed();
    73         if( "" == songName )
    75         if( "" == songName )
    74         {
    76         {
    75             songName = hbTrId("txt_irad_list_unknown_song");
    77             songName = hbTrId("txt_irad_list_unknown_song");
    76         }
    78         }
    77         
    79         
    78         songName = QString::number(row+1) + ". " + "\" " + songName + " \"";        
    80         if (Qt::Vertical == mOrientation)
    79         list.append(songName);
       
    80         
       
    81         QString artistName;
       
    82         artistName = iSongHistoryList.at(row)->getArtistName();
       
    83         artistName = artistName.trimmed();
       
    84         if( "" == artistName )
       
    85         {
    81         {
    86             artistName = "< " + hbTrId("txt_irad_list_unknown_artist") + " >";
    82             list.append("<" + artistName + ">");
       
    83             list.append("<" + songName + ">");
    87         }
    84         }
    88         else
    85         else
    89         {
    86         {
    90             artistName = "< " + iSongHistoryList.at(row)->getArtistName() + " >";
    87             list.append("<" + artistName +"> - <" + songName + ">");
       
    88             list.append("<Not ready>");
    91         }
    89         }
    92         list.append(artistName);
       
    93         return list;
    90         return list;
    94     }    
       
    95     else if (aRole == Qt::BackgroundRole)
       
    96     {
       
    97         
       
    98             if (aIndex.row() % 2 == 0)
       
    99             {
       
   100                 return QBrush(KListEvenRowColor);
       
   101             }
       
   102             else
       
   103             {
       
   104                 return QBrush(KListOddRowColor);
       
   105             }        
       
   106     }
    91     }
   107 
    92 
   108     return QVariant();
    93     return QVariant();
   109 }
    94 }
   110 
    95 
   111 IRQSongInfo* IRSongHistoryModel::getSongHistoryInfo(int aIndex)
    96 IRQSongInfo* IRSongHistoryModel::getSongHistoryInfo(int aIndex)
   112 {
    97 {
   113     if (aIndex >= 0 && aIndex < iSongHistoryList.count())
    98     if (aIndex >= 0 && aIndex < mSongHistoryList.count())
   114     {
    99     {
   115         return iSongHistoryList.at(aIndex);
   100         return mSongHistoryList.at(aIndex);
   116     }
   101     }
   117 
   102 
   118     return NULL;
   103     return NULL;
   119 }
   104 }
   120 
   105 
   121 void IRSongHistoryModel::clearAllList()
   106 void IRSongHistoryModel::clearAllList()
   122 {
   107 {
   123     while (!iSongHistoryList.isEmpty())
   108     while (!mSongHistoryList.isEmpty())
   124     {
   109     {
   125         IRQSongInfo *firstItem = iSongHistoryList.takeFirst();
   110         IRQSongInfo *firstItem = mSongHistoryList.takeFirst();
   126         delete firstItem;
   111         delete firstItem;
   127     }
   112     }
   128      
   113      
   129     emit modelChanged();
   114     emit modelChanged();
   130 }
   115 }
   136 }
   121 }
   137  
   122  
   138 
   123 
   139 void IRSongHistoryModel::getAllList()
   124 void IRSongHistoryModel::getAllList()
   140 {
   125 {
   141     iHistoryEngine->getAllSongHistory(iSongHistoryList);
   126     mHistoryEngine->getAllSongHistory(mSongHistoryList);
   142 
   127 
   143     emit modelChanged();
   128     emit modelChanged();
   144 } 
   129 } 
   145 
   130 
   146 void IRSongHistoryModel::clearHisotrySongDB()
   131 void IRSongHistoryModel::clearHisotrySongDB()
   147 {
   132 {
   148     while (!iSongHistoryList.isEmpty())
   133     while (!mSongHistoryList.isEmpty())
   149     {
   134     {
   150         IRQSongInfo *firstItem = iSongHistoryList.takeFirst();
   135         IRQSongInfo *firstItem = mSongHistoryList.takeFirst();
   151         delete firstItem;
   136         delete firstItem;
   152     }
   137     }
   153     iHistoryEngine->clearAllSongHistory();     
   138     mHistoryEngine->clearAllSongHistory();     
   154     emit modelChanged();
   139     emit modelChanged();
   155 }
   140 }
       
   141 
       
   142 void IRSongHistoryModel::setOrientation(Qt::Orientation aOrientation)
       
   143 {
       
   144     mOrientation = aOrientation;
       
   145 }