summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleix Pol <[email protected]>2016-10-17 15:16:37 +0200
committerAleix Pol <[email protected]>2016-10-17 15:16:37 +0200
commit9ba2483fa819ccc3d4b36486c22c40fb5488b9d8 (patch)
treea5d622d9b50bcfb47e45125cc521c83ccee3179d
parent7dbb667426f9c2290d2f14043e0742c352a900ff (diff)
Smooth transaction management
-rw-r--r--libdiscover/Transaction/TransactionModel.cpp8
-rw-r--r--libdiscover/Transaction/TransactionModel.h1
-rw-r--r--libdiscover/backends/KNSBackend/KNSBackend.cpp7
3 files changed, 12 insertions, 4 deletions
diff --git a/libdiscover/Transaction/TransactionModel.cpp b/libdiscover/Transaction/TransactionModel.cpp
index 39a9343..9a76431 100644
--- a/libdiscover/Transaction/TransactionModel.cpp
+++ b/libdiscover/Transaction/TransactionModel.cpp
@@ -180,15 +180,19 @@ void TransactionModel::cancelTransaction(Transaction *trans)
void TransactionModel::removeTransaction(Transaction *trans)
{
Q_ASSERT(trans);
- int r = indexOf(trans).row();
+ int r = m_transactions.indexOf(trans);
Q_ASSERT(r>=0);
+ disconnect(trans, nullptr, this, nullptr);
+
beginRemoveRows(QModelIndex(), r, r);
m_transactions.removeAt(r);
endRemoveRows();
+
emit transactionRemoved(trans);
if (m_transactions.isEmpty())
- emit lastTransactionFinished();
+ emit lastTransactionFinished();
+ trans->deleteLater();
}
void TransactionModel::transactionChanged(int role)
diff --git a/libdiscover/Transaction/TransactionModel.h b/libdiscover/Transaction/TransactionModel.h
index fb4c9e8..d5ef28f 100644
--- a/libdiscover/Transaction/TransactionModel.h
+++ b/libdiscover/Transaction/TransactionModel.h
@@ -60,6 +60,7 @@ public:
void cancelTransaction(Transaction *trans);
void removeTransaction(Transaction *trans);
+ bool contains(Transaction* transaction) const { return m_transactions.contains(transaction); }
int progress() const;
private:
diff --git a/libdiscover/backends/KNSBackend/KNSBackend.cpp b/libdiscover/backends/KNSBackend/KNSBackend.cpp
index 5e7a415..2068394 100644
--- a/libdiscover/backends/KNSBackend/KNSBackend.cpp
+++ b/libdiscover/backends/KNSBackend/KNSBackend.cpp
@@ -150,6 +150,7 @@ public:
: Transaction(parent, res, role)
, m_id(res->entry().id())
{
+ TransactionModel::global()->addTransaction(this);
auto manager = res->knsBackend()->downloadManager();
switch(role) {
@@ -163,7 +164,6 @@ public:
Q_UNREACHABLE();
}
setCancellable(false);
- TransactionModel::global()->addTransaction(this);
connect(manager, &KNS3::DownloadManager::entryStatusChanged, this, &KNSTransaction::anEntryChanged);
}
@@ -190,7 +190,10 @@ public:
}
~KNSTransaction() override {
- TransactionModel::global()->removeTransaction(this);
+ if (TransactionModel::global()->contains(this)) {
+ qWarning() << "deleting Transaction before it's done";
+ TransactionModel::global()->removeTransaction(this);
+ }
}
void cancel() override {}