diff options
author | Erik Verbruggen <erik@verbruggen.consulting> | 2021-10-15 15:05:01 +0300 |
---|---|---|
committer | Erik Verbruggen <Erik.Verbruggen@Me.com> | 2021-12-03 12:45:08 +0300 |
commit | 470bf76e6362a4379e6548e466971e3a2e532ccd (patch) | |
tree | f697e03da9fde7e1d97394d867c6c3eed7f314d9 /src/gui/activitywidget.cpp | |
parent | ed603153da4fdc385f90982c88660fe0cec2f7ea (diff) |
Use the refcounted AccountStatePtr as much as possible
The AccountManager creates AccountState objects, and stores them in a
shared pointer.
Previously, the raw pointer was given out, and stored in other objects.
That made removal very tricky: when an account gets removed, the
underlying object gets deleted, and then all classes that listen get
notified of the deletion. Those classes would sometimes put a nullptr
into the AccountState pointer they stored, and in each usage would
(hopefully) check for a nullptr. The problem was that a number of checks
were missing, which the clang static analyser pointed out.
This patch changes nearly all uses of a raw pointer into the shared
pointer, thereby making sure all usages have a valid reference, even
when account deletion happens. The two places where a raw pointer is
still used, now put it into a refcounted pointer as soon as possible.
Diffstat (limited to 'src/gui/activitywidget.cpp')
-rw-r--r-- | src/gui/activitywidget.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/gui/activitywidget.cpp b/src/gui/activitywidget.cpp index 93a6c1bc9..ca372094d 100644 --- a/src/gui/activitywidget.cpp +++ b/src/gui/activitywidget.cpp @@ -93,7 +93,7 @@ ActivityWidget::ActivityWidget(QWidget *parent) connect(_model, &ActivityListModel::activityJobStatusCode, this, &ActivityWidget::slotAccountActivityStatus); - connect(AccountManager::instance(), &AccountManager::accountRemoved, this, [this](AccountState *ast) { + connect(AccountManager::instance(), &AccountManager::accountRemoved, this, [this](AccountStatePtr ast) { if (_accountsWithoutActivities.remove(ast->account()->displayName())) { showLabels(); } @@ -122,12 +122,12 @@ ActivityWidget::~ActivityWidget() delete _ui; } -void ActivityWidget::slotRefreshActivities(AccountState *ptr) +void ActivityWidget::slotRefreshActivities(AccountStatePtr ptr) { _model->slotRefreshActivity(ptr); } -void ActivityWidget::slotRefreshNotifications(AccountState *ptr) +void ActivityWidget::slotRefreshNotifications(AccountStatePtr ptr) { // start a server notification handler if no notification requests // are running @@ -142,7 +142,7 @@ void ActivityWidget::slotRefreshNotifications(AccountState *ptr) } } -void ActivityWidget::slotRemoveAccount(AccountState *ptr) +void ActivityWidget::slotRemoveAccount(AccountStatePtr ptr) { _model->slotRemoveAccount(ptr); } @@ -164,7 +164,7 @@ void ActivityWidget::showLabels() _ui->_bottomLabel->setText(t); } -void ActivityWidget::slotAccountActivityStatus(AccountState *ast, int statusCode) +void ActivityWidget::slotAccountActivityStatus(AccountStatePtr ast, int statusCode) { if (!(ast && ast->account())) { return; @@ -327,8 +327,7 @@ void ActivityWidget::slotSendNotificationRequest(const QString &accountName, con QStringLiteral("DELETE") }; if (validVerbs.contains(verb)) { - AccountStatePtr acc = AccountManager::instance()->account(accountName); - if (acc) { + if (auto acc = AccountManager::instance()->account(accountName)) { NotificationConfirmJob *job = new NotificationConfirmJob(acc->account()); QUrl l(link); job->setLinkAndVerb(l, verb); @@ -559,12 +558,12 @@ void ActivitySettings::slotShowIssuesTab() _tab->setCurrentIndex(_syncIssueTabId); } -void ActivitySettings::slotRemoveAccount(AccountState *ptr) +void ActivitySettings::slotRemoveAccount(AccountStatePtr ptr) { _activityWidget->slotRemoveAccount(ptr); } -void ActivitySettings::slotRefresh(AccountState *ptr) +void ActivitySettings::slotRefresh(AccountStatePtr ptr) { // QElapsedTimer isn't actually constructed as invalid. if (!_timeSinceLastCheck.contains(ptr)) { @@ -590,7 +589,7 @@ void ActivitySettings::slotRefresh(AccountState *ptr) void ActivitySettings::slotRegularNotificationCheck() { for (const auto &a : AccountManager::instance()->accounts()) { - slotRefresh(a.data()); + slotRefresh(a); } } |