watch for sycoca changes

when a new app is installed
This commit is contained in:
Marco Martin 2015-03-18 14:57:54 +01:00
parent 25e1e12c4d
commit ffa4137cd0
2 changed files with 20 additions and 0 deletions

View file

@ -30,12 +30,16 @@
#include <KService>
#include <KServiceGroup>
#include <KServiceTypeTrader>
#include <KSycoca>
#include <KSycocaEntry>
#include <QDebug>
ApplicationListModel::ApplicationListModel(QObject *parent)
: QAbstractListModel(parent)
{
//can't use the new syntax as this signal is overloaded
connect(KSycoca::self(), SIGNAL(databaseChanged(const QStringList &)),
this, SLOT(sycocaDbChanged(const QStringList &)));
}
ApplicationListModel::~ApplicationListModel()
@ -54,6 +58,17 @@ QHash<int, QByteArray> ApplicationListModel::roleNames() const
return roleNames;
}
void ApplicationListModel::sycocaDbChanged(const QStringList &changes)
{
if (!changes.contains("apps") && !changes.contains("xdgdata-apps")) {
return;
}
m_applicationList.clear();
loadApplications();
}
bool appNameLessThan(const ApplicationData &a1, const ApplicationData &a2)
{
return a1.name.toLower() < a2.name.toLower();
@ -63,6 +78,8 @@ void ApplicationListModel::loadApplications()
{
beginResetModel();
m_applicationList.clear();
KServiceGroup::Ptr group = KServiceGroup::root();
if (!group || !group->isValid()) return;
KServiceGroup::List subGroupList = group->entries(true);

View file

@ -69,6 +69,9 @@ public:
Q_INVOKABLE void loadApplications();
public Q_SLOTS:
void sycocaDbChanged(const QStringList &change);
Q_SIGNALS:
void countChanged();
void appOrderChanged();