folio: Delete delegates if the application is removed

When an application is detected to be removed from the system, remove the delegate from the homescreen layout as well.
This commit is contained in:
Devin Lin 2025-03-19 20:47:30 -04:00
parent e4323f4ef0
commit d621b23eb0
5 changed files with 55 additions and 8 deletions

View file

@ -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

View file

@ -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();

View file

@ -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

View file

@ -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

View file

@ -11,16 +11,31 @@ PageModel::PageModel(QList<FolioPageDelegate::Ptr> 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) {
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);
}
}
});
}