- if (p != items_.end()) {
- if (info.is_new) {
- qWarning() << "item with similar info hash marked as new";
- }
- updateItem_(p.value(), info, other_info);
- } else {
- if (!info.is_new) {
- qDebug() << "torrent info arrived but there is no torrent for it";
- return;
- }
- addItem_(info, other_info);
+ switch (info.action) {
+ case TorrentState::action_add :
+ if (p == items_.end()) {
+ addItem_(info, other_info);
+ } else {
+ qWarning() << "item with similar info hash marked as added";
+ updateItem_(p.value(), info, other_info);
+ }
+ break;
+ case TorrentState::action_update :
+ if (p != items_.end()) {
+ updateItem_(p.value(), info, other_info);
+ } else {
+ qWarning() << "item does not exist in list but information update arrived";
+ }
+ break;
+ case TorrentState::action_remove :
+ if (p != items_.end()) {
+ removeItem_(p.value(), info);
+ } else {
+ qWarning() << "item removal request arrived but there is no such item";
+ }
+ break;
+ default:
+ qWarning() << "unknown action requested: " << info.action;
+ break;
+ }
+ }
+
+ void DownloadView::removeItem_(DownloadViewItem *item, TorrentState const& info)
+ {
+ QString hash = item->getHash();
+
+ int removed = items_.remove(hash);
+ if (!removed)
+ qDebug() << "Inconsistent download view state on item removal";
+
+ int index = indexOfTopLevelItem(item);
+ if (index >= 0) {
+ takeTopLevelItem(index);