From 833913cac292bbb4035e80672b9c28ab7506c779 Mon Sep 17 00:00:00 2001 From: blue Date: Sun, 23 Jun 2019 14:31:03 +0300 Subject: [PATCH] clearing presences and statuses on disconnect of an account --- ui/models/account.cpp | 8 ++++++++ ui/models/account.h | 4 ++++ ui/models/contact.cpp | 15 +++++++++++++++ ui/models/contact.h | 1 + ui/models/item.cpp | 8 ++++++++ ui/models/item.h | 2 ++ 6 files changed, 38 insertions(+) diff --git a/ui/models/account.cpp b/ui/models/account.cpp index f41d85d..352b79d 100644 --- a/ui/models/account.cpp +++ b/ui/models/account.cpp @@ -30,6 +30,9 @@ void Models::Account::setState(Shared::ConnectionState p_state) if (state != p_state) { state = p_state; changed(2); + if (state == Shared::disconnected) { + toOfflineState(); + } } } @@ -198,3 +201,8 @@ void Models::Account::setError(const QString& p_resource) } } +void Models::Account::toOfflineState() +{ + setAvailability(Shared::offline); + Item::toOfflineState(); +} diff --git a/ui/models/account.h b/ui/models/account.h index e09863f..43a72c2 100644 --- a/ui/models/account.h +++ b/ui/models/account.h @@ -8,6 +8,7 @@ namespace Models { class Account : public Item { + Q_OBJECT public: explicit Account(const QMap &data, Item *parentItem = 0); ~Account(); @@ -50,6 +51,9 @@ namespace Models { QString error; Shared::ConnectionState state; Shared::Availability availability; + + protected slots: + void toOfflineState() override; }; } diff --git a/ui/models/contact.cpp b/ui/models/contact.cpp index 8fedbc2..643659b 100644 --- a/ui/models/contact.cpp +++ b/ui/models/contact.cpp @@ -320,3 +320,18 @@ const Models::Account * Models::Contact::getParentAccount() const return static_cast(p); } + +void Models::Contact::toOfflineState() +{ + emit childIsAboutToBeRemoved(this, 0, childItems.size()); + for (int i = 0; i < childItems.size(); ++i) { + Item* item = childItems[i]; + disconnect(item, SIGNAL(childChanged(Models::Item*, int, int)), this, SLOT(refresh())); + Item::_removeChild(i); + item->deleteLater(); + } + childItems.clear(); + presences.clear(); + emit childRemoved(); + refresh(); +} diff --git a/ui/models/contact.h b/ui/models/contact.h index 6370cb4..7914a88 100644 --- a/ui/models/contact.h +++ b/ui/models/contact.h @@ -50,6 +50,7 @@ protected: protected slots: void refresh(); + void toOfflineState() override; protected: void setAvailability(Shared::Availability p_state); diff --git a/ui/models/item.cpp b/ui/models/item.cpp index 9615d82..f5a9465 100644 --- a/ui/models/item.cpp +++ b/ui/models/item.cpp @@ -140,3 +140,11 @@ void Models::Item::changed(int col) emit childChanged(this, row(), col); } } + +void Models::Item::toOfflineState() +{ + for (std::deque::iterator itr = childItems.begin(), end = childItems.end(); itr != end; ++itr) { + Item* it = *itr; + it->toOfflineState(); + } +} diff --git a/ui/models/item.h b/ui/models/item.h index 6c71b6c..629561e 100644 --- a/ui/models/item.h +++ b/ui/models/item.h @@ -59,6 +59,8 @@ class Item : public QObject{ Item* parent; protected slots: + virtual void toOfflineState(); + }; }