diff -r ee64f059b8e1 -r 0930554dc389 qtinternetradio/ui/src/irfavoritesmodel.cpp --- a/qtinternetradio/ui/src/irfavoritesmodel.cpp Fri May 14 15:43:29 2010 +0300 +++ b/qtinternetradio/ui/src/irfavoritesmodel.cpp Thu May 27 12:46:34 2010 +0300 @@ -14,6 +14,7 @@ * Description: * */ +#include #include #include "irqfavoritesdb.h" @@ -82,6 +83,20 @@ emit dataChanged(index(aIndex), index(aIndex)); } +bool IRFavoritesModel::isLogoReady(int aIndex) const +{ + int logoListCount = iLogos.count(); + if (aIndex >= 0 + && aIndex < logoListCount) + { + return iLogos[aIndex] != NULL; + } + else + { + return false; + } +} + QVariant IRFavoritesModel::data(const QModelIndex &aIndex, int aRole) const { if (!aIndex.isValid()) @@ -166,14 +181,29 @@ } int presetSize = iPresetsList->count(); + + if(!presetSize) + { + return; + } + int uniqId = 0; - - for (int i = 0; i < presetSize; ++i) + + while(presetSize--) { - uniqId = iFavoritesDb->getUniqId(i); + uniqId = iFavoritesDb->getUniqId(presetSize); + + //There is the probability that the return value<0, so I added this judgment. + if(uniqId < 0 ) + { + //if here, the Id, which is mapped to preset's item, can't be found. + //jump out from while + break; + } iFavoritesDb->deletePreset(uniqId); - } - + + } + clearPresetList(); clearAndDestroyLogos(); emit modelChanged(); @@ -209,6 +239,7 @@ } beginRemoveRows(QModelIndex(), aIndex, aIndex); + delete preset; iPresetsList->removeAt(aIndex); if (aIndex indexToBeDelete; + + // delete from DB + for (int i = 0; i < aIndexList.count(); i++) + { + index = aIndexList.at(i).row(); + + if (index < 0 || index >= iPresetsList->size()) + { + continue; + } + + if (0 != iFavoritesDb->deletePreset(iPresetsList->at(index)->uniqID)) + { + retVal = false; + continue; + } + indexToBeDelete.append(index); + } + + qSort(indexToBeDelete); + + + // delete from model + for (int i = indexToBeDelete.count() - 1; i >= 0; i--) + { + index = indexToBeDelete.at(i); + + beginRemoveRows(QModelIndex(), index, index); + IRQPreset *preset = iPresetsList->at(index); + delete preset; + iPresetsList->removeAt(index); + if (index