diff --git a/containments/homescreens/folio/applicationlistmodel.cpp b/containments/homescreens/folio/applicationlistmodel.cpp index 00415082..6fd392bf 100644 --- a/containments/homescreens/folio/applicationlistmodel.cpp +++ b/containments/homescreens/folio/applicationlistmodel.cpp @@ -116,9 +116,16 @@ void ApplicationListModel::load() for (int i = toRemove.size() - 1; i >= 0; --i) { int ind = toRemove[i]; + QString storageId; + if (m_delegates[ind]->application()) { + storageId = m_delegates[ind]->application()->storageId(); + } + beginRemoveRows({}, ind, ind); m_delegates.removeAt(ind); endRemoveRows(); + + Q_EMIT applicationRemoved(storageId); } // Append new elements diff --git a/containments/homescreens/folio/applicationlistmodel.h b/containments/homescreens/folio/applicationlistmodel.h index 52f418dd..849825f9 100644 --- a/containments/homescreens/folio/applicationlistmodel.h +++ b/containments/homescreens/folio/applicationlistmodel.h @@ -40,6 +40,10 @@ public: void load(); +Q_SIGNALS: + // Emitted when an application was detected to have been removed from the system + void applicationRemoved(QString storageId); + public Q_SLOTS: void sycocaDbChanged(); diff --git a/containments/homescreens/folio/favouritesmodel.cpp b/containments/homescreens/folio/favouritesmodel.cpp index 35fb6079..f160cb22 100644 --- a/containments/homescreens/folio/favouritesmodel.cpp +++ b/containments/homescreens/folio/favouritesmodel.cpp @@ -24,6 +24,16 @@ FavouritesModel::FavouritesModel(HomeScreen *parent) : QAbstractListModel{parent} , m_homeScreen{parent} { + // Listen to application removal events and delete delegates + connect(m_homeScreen->applicationListModel(), &ApplicationListModel::applicationRemoved, this, [this](const QString &storageId) { + for (int i = 0; i < m_delegates.size(); i++) { + auto delegate = m_delegates[i].delegate; + + if (delegate->type() == FolioDelegate::Application && delegate->application()->storageId() == storageId) { + removeEntry(i); + } + } + }); } int FavouritesModel::rowCount(const QModelIndex &parent) const diff --git a/containments/homescreens/folio/folioapplicationfolder.cpp b/containments/homescreens/folio/folioapplicationfolder.cpp index d697dc82..fdbee04d 100644 --- a/containments/homescreens/folio/folioapplicationfolder.cpp +++ b/containments/homescreens/folio/folioapplicationfolder.cpp @@ -151,6 +151,17 @@ ApplicationFolderModel::ApplicationFolderModel(FolioApplicationFolder *parent) connect(homeScreenState, &HomeScreenState::pageCellHeightChanged, this, [this]() { evaluateDelegateIndexes(); }); + + // Listen to application removal events and delete delegates + connect(m_folder->m_homeScreen->applicationListModel(), &ApplicationListModel::applicationRemoved, this, [this](const QString &storageId) { + for (int i = 0; i < m_folder->m_delegates.size(); i++) { + auto delegate = m_folder->m_delegates[i].delegate; + + if (delegate->type() == FolioDelegate::Application && delegate->application()->storageId() == storageId) { + removeDelegate(i); + } + } + }); } int ApplicationFolderModel::rowCount(const QModelIndex & /*parent*/) const diff --git a/containments/homescreens/folio/pagemodel.cpp b/containments/homescreens/folio/pagemodel.cpp index 0abe3438..fe6aca8e 100644 --- a/containments/homescreens/folio/pagemodel.cpp +++ b/containments/homescreens/folio/pagemodel.cpp @@ -11,15 +11,30 @@ PageModel::PageModel(QList delegates, QObject *parent, H , m_homeScreen{homeScreen} , m_delegates{delegates} { + // Listen to widget removal events and delete delegates connect(homeScreen->widgetsManager(), &WidgetsManager::widgetRemoved, this, [this](Plasma::Applet *applet) { - if (applet) { - // delete any instance of this widget - for (int i = 0; i < m_delegates.size(); i++) { - FolioPageDelegate::Ptr delegate = m_delegates[i]; - if (delegate->type() == FolioDelegate::Widget && delegate->widget()->applet() == applet) { - removeDelegate(i); - break; - } + if (!applet) { + return; + } + + // delete any instance of this widget + for (int i = 0; i < m_delegates.size(); i++) { + FolioPageDelegate::Ptr delegate = m_delegates[i]; + + if (delegate->type() == FolioDelegate::Widget && delegate->widget()->applet() == applet) { + removeDelegate(i); + break; + } + } + }); + + // Listen to application removal events and delete delegates + connect(homeScreen->applicationListModel(), &ApplicationListModel::applicationRemoved, this, [this](const QString &storageId) { + for (int i = 0; i < m_delegates.size(); i++) { + FolioPageDelegate::Ptr delegate = m_delegates[i]; + + if (delegate->type() == FolioDelegate::Application && delegate->application()->storageId() == storageId) { + removeDelegate(i); } } });