qtinternetradio/ui/src/irchannelmodel.cpp
branchGCC_SURGE
changeset 13 c9471d26c7f2
parent 11 f683e24efca3
child 17 38bbf2dcd608
--- a/qtinternetradio/ui/src/irchannelmodel.cpp	Mon Jun 21 22:33:45 2010 +0100
+++ b/qtinternetradio/ui/src/irchannelmodel.cpp	Thu Jul 22 16:31:41 2010 +0100
@@ -19,9 +19,10 @@
 
 #include "irchannelmodel.h"
 #include "irqisdsdatastructure.h"
+#include "irsearchresultdb.h"
 
 IrChannelModel::IrChannelModel(QObject *aParent): QAbstractListModel(aParent)
-                                                , iChannelList(NULL)
+                                                , iChannelList(NULL),iDB(NULL)
 {
     iStationLogo = new HbIcon("qtg_large_internet_radio");   
 }
@@ -34,6 +35,12 @@
     iStationLogo = NULL;
     
     clearAndDestroyLogos();
+
+    if( iDB )
+    {
+        delete iDB;
+        iDB = NULL;
+    }
 }
 
 int IrChannelModel::rowCount(const QModelIndex &aParent) const
@@ -125,6 +132,56 @@
     emit dataAvailable();
 }
 
+void IrChannelModel::initWithCache()
+{
+    if( NULL == iDB )
+    {
+        iDB = new IRSearchResultDB();
+    }
+    
+    QList<IRQChannelItem*> *channelList = iDB->getCahcedChannelList();
+   
+    if( NULL == channelList )
+    {
+        //some error happens
+        return;
+    }
+    
+    clearAndDestroyItems();
+    clearAndDestroyLogos();
+    iChannelList = channelList;    
+}
+
+void IrChannelModel::save2Cache()
+{
+    if( NULL == iChannelList )
+    {
+        return;
+    }
+    
+    //ignore the return value   
+    iDB->cacheChannelList(iChannelList);
+}
+
+IRQChannelItem * IrChannelModel::getChannelItemByIndex(int aIndex)
+{
+    if( aIndex < 0 || aIndex >= iChannelList->count() )
+    {
+        return NULL;
+    }
+    
+    return iChannelList->at(aIndex);
+}
+
+void IrChannelModel::cleanupDatabase()
+{
+    clearAndDestroyItems();
+    clearAndDestroyLogos();
+    iDB->clearCache();
+    
+    emit dataAvailable();
+}
+
 void IrChannelModel::clearAndDestroyLogos()
 {
     for (QMap<int, HbIcon*>::iterator it = iLogos.begin(); it != iLogos.end(); ++it)