mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
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:
parent
e4323f4ef0
commit
d621b23eb0
5 changed files with 55 additions and 8 deletions
|
|
@ -116,9 +116,16 @@ void ApplicationListModel::load()
|
||||||
for (int i = toRemove.size() - 1; i >= 0; --i) {
|
for (int i = toRemove.size() - 1; i >= 0; --i) {
|
||||||
int ind = toRemove[i];
|
int ind = toRemove[i];
|
||||||
|
|
||||||
|
QString storageId;
|
||||||
|
if (m_delegates[ind]->application()) {
|
||||||
|
storageId = m_delegates[ind]->application()->storageId();
|
||||||
|
}
|
||||||
|
|
||||||
beginRemoveRows({}, ind, ind);
|
beginRemoveRows({}, ind, ind);
|
||||||
m_delegates.removeAt(ind);
|
m_delegates.removeAt(ind);
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
|
||||||
|
Q_EMIT applicationRemoved(storageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append new elements
|
// Append new elements
|
||||||
|
|
|
||||||
|
|
@ -40,6 +40,10 @@ public:
|
||||||
|
|
||||||
void load();
|
void load();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
// Emitted when an application was detected to have been removed from the system
|
||||||
|
void applicationRemoved(QString storageId);
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void sycocaDbChanged();
|
void sycocaDbChanged();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,16 @@ FavouritesModel::FavouritesModel(HomeScreen *parent)
|
||||||
: QAbstractListModel{parent}
|
: QAbstractListModel{parent}
|
||||||
, m_homeScreen{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
|
int FavouritesModel::rowCount(const QModelIndex &parent) const
|
||||||
|
|
|
||||||
|
|
@ -151,6 +151,17 @@ ApplicationFolderModel::ApplicationFolderModel(FolioApplicationFolder *parent)
|
||||||
connect(homeScreenState, &HomeScreenState::pageCellHeightChanged, this, [this]() {
|
connect(homeScreenState, &HomeScreenState::pageCellHeightChanged, this, [this]() {
|
||||||
evaluateDelegateIndexes();
|
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
|
int ApplicationFolderModel::rowCount(const QModelIndex & /*parent*/) const
|
||||||
|
|
|
||||||
|
|
@ -11,15 +11,30 @@ PageModel::PageModel(QList<FolioPageDelegate::Ptr> delegates, QObject *parent, H
|
||||||
, m_homeScreen{homeScreen}
|
, m_homeScreen{homeScreen}
|
||||||
, m_delegates{delegates}
|
, m_delegates{delegates}
|
||||||
{
|
{
|
||||||
|
// Listen to widget removal events and delete delegates
|
||||||
connect(homeScreen->widgetsManager(), &WidgetsManager::widgetRemoved, this, [this](Plasma::Applet *applet) {
|
connect(homeScreen->widgetsManager(), &WidgetsManager::widgetRemoved, this, [this](Plasma::Applet *applet) {
|
||||||
if (applet) {
|
if (!applet) {
|
||||||
// delete any instance of this widget
|
return;
|
||||||
for (int i = 0; i < m_delegates.size(); i++) {
|
}
|
||||||
FolioPageDelegate::Ptr delegate = m_delegates[i];
|
|
||||||
if (delegate->type() == FolioDelegate::Widget && delegate->widget()->applet() == applet) {
|
// delete any instance of this widget
|
||||||
removeDelegate(i);
|
for (int i = 0; i < m_delegates.size(); i++) {
|
||||||
break;
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue