1
0
mirror of https://github.com/d47081/qBittorrent.git synced 2025-03-10 12:21:12 +00:00

- Fix possible crash when removing a torrent

This commit is contained in:
Christophe Dumez 2010-02-06 21:31:51 +00:00
parent dd47ce6767
commit 22d0c4a241

@ -224,7 +224,11 @@ void TransferListWidget::setRowColor(int row, QColor color) {
} }
void TransferListWidget::deleteTorrent(int row, bool refresh_list) { void TransferListWidget::deleteTorrent(int row, bool refresh_list) {
emit torrentAboutToBeRemoved(listModel->index(row, 0)); Q_ASSERT(row >= 0);
QModelIndex index = listModel->index(row, 0);
Q_ASSERT(index.isValid());
if(!index.isValid()) return;
emit torrentAboutToBeRemoved(index);
listModel->removeRow(row); listModel->removeRow(row);
if(refresh_list) if(refresh_list)
refreshList(); refreshList();
@ -299,8 +303,7 @@ int TransferListWidget::updateTorrent(int row) {
QString hash = getHashFromRow(row); QString hash = getHashFromRow(row);
QTorrentHandle h = BTSession->getTorrentHandle(hash); QTorrentHandle h = BTSession->getTorrentHandle(hash);
if(!h.is_valid()) { if(!h.is_valid()) {
// Delete torrent // Torrent will be deleted from list by caller
deleteTorrent(row, false);
return s; return s;
} }
try { try {
@ -430,10 +433,9 @@ int TransferListWidget::updateTorrent(int row) {
// Share ratio // Share ratio
if(!isColumnHidden(TR_RATIO)) if(!isColumnHidden(TR_RATIO))
listModel->setData(listModel->index(row, TR_RATIO), QVariant(BTSession->getRealRatio(hash))); listModel->setData(listModel->index(row, TR_RATIO), QVariant(BTSession->getRealRatio(hash)));
}catch(invalid_handle e) { }catch(invalid_handle) {
deleteTorrent(row, false); // Torrent will be deleted by caller
s = STATE_INVALID; s = STATE_INVALID;
qDebug("Caught Invalid handle exception, lucky us.");
} }
return s; return s;
} }
@ -524,7 +526,9 @@ void TransferListWidget::refreshList() {
} }
// Remove bad torrents from list // Remove bad torrents from list
foreach(QString hash, bad_hashes) { foreach(QString hash, bad_hashes) {
deleteTorrent(getRowFromHash(hash), false); int row = getRowFromHash(hash);
if(row >= 0)
deleteTorrent(row, false);
} }
// Update status filters counters // Update status filters counters
emit torrentStatusUpdate(nb_downloading, nb_seeding, nb_active, nb_inactive); emit torrentStatusUpdate(nb_downloading, nb_seeding, nb_active, nb_inactive);
@ -970,6 +974,7 @@ void TransferListWidget::setSelectionLabel(QString label) {
QModelIndexList selectedIndexes = selectionModel()->selectedRows(); QModelIndexList selectedIndexes = selectionModel()->selectedRows();
foreach(const QModelIndex &index, selectedIndexes) { foreach(const QModelIndex &index, selectedIndexes) {
QString hash = getHashFromRow(mapToSource(index).row()); QString hash = getHashFromRow(mapToSource(index).row());
Q_ASSERT(!hash.isEmpty());
QString old_label = proxyModel->data(proxyModel->index(index.row(), TR_LABEL)).toString(); QString old_label = proxyModel->data(proxyModel->index(index.row(), TR_LABEL)).toString();
proxyModel->setData(proxyModel->index(index.row(), TR_LABEL), QVariant(label)); proxyModel->setData(proxyModel->index(index.row(), TR_LABEL), QVariant(label));
TorrentPersistentData::saveLabel(hash, label); TorrentPersistentData::saveLabel(hash, label);