X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fqml-client%2Fmodels%2FQDeclarativeDownloadListModel.cpp;h=44d4a0dd17c8f0dbb6fec4fd4ccfe262926180a9;hb=f77461be3060e91809309f18dcbe791d77cdde2a;hp=e990705a9c5a9c15c9b504bf3a8fbc1040da089a;hpb=9de6d5abeb5e02284ffaf786b360776b83077045;p=qtrapids diff --git a/src/qml-client/models/QDeclarativeDownloadListModel.cpp b/src/qml-client/models/QDeclarativeDownloadListModel.cpp index e990705..44d4a0d 100644 --- a/src/qml-client/models/QDeclarativeDownloadListModel.cpp +++ b/src/qml-client/models/QDeclarativeDownloadListModel.cpp @@ -244,34 +244,39 @@ void QDeclarativeDownloadListModel::addItem_(TorrentState const& info, void QDeclarativeDownloadListModel::updateItem_(TorrentState const& info, ParamsMap_t) { qDebug() << Q_FUNC_INFO << " enter"; - /* - item->setData(2, Qt::DisplayRole, - QVariant(GetStatusString((TorrentStatus::Id)info.state))); - item->setData(3, Qt::DisplayRole, - QVariant(formatProgress(info.progress))); - item->setData(4, Qt::DisplayRole, - QVariant(formatSize(info.down_rate))); - item->setData(5, Qt::DisplayRole, - QVariant(formatSize(info.up_rate))); - item->setData(6, Qt::DisplayRole, - QString::number(info.seeds) + "/" + QString::number(info.leeches)); - item->setData(7, Qt::DisplayRole, QString::number(info.ratio)); - - // Calculate ETA - if (info.down_rate > 0) { - qulonglong eta = (info.total_size - info.total_done) / info.down_rate; - item->setData(8, Qt::DisplayRole, formatElapsedTime(eta)); - } else { - item->setData(8, Qt::DisplayRole, "N/A"); + + // Check if we even have the item in model. At this point we should... + if (!d->items_.contains(info.hash)) { + qWarning() << Q_FUNC_INFO << " torrent with hash \'" + << info.hash << "\' not in model"; + return; } -*/ - // TODO: Update items data & Emit data changed. -/* - // Set color for status text - QBrush brushTmp(GetStatusColor((TorrentStatus::Id)info.state)); - item->setForeground(2, brushTmp); - */ + int row = 0; + ItemIndex_t::iterator iterBegin = d->itemIndexes_.begin(); + ItemIndex_t::iterator iterEnd = d->itemIndexes_.end(); + while (iterBegin != iterEnd) { + if (iterBegin.value() == info.hash) { + break; + } + ++row; + ++iterBegin; + } + + // We iterated past the end of map -> index did not exist. + if (iterBegin == iterEnd) { + qWarning() << Q_FUNC_INFO << " torrent with hash \'" + << info.hash << "\' not in item index table"; + return; + } + + // Get the model index for item from base class: + QModelIndex modelIndex = index(row); + // For QHash, insert() replaces existing item with same key. + d->items_.insert(info.hash, info); + + // Notify view about the change. + emit dataChanged(modelIndex, modelIndex); }