api for favorites and desktop

This commit is contained in:
Marco Martin 2019-07-29 19:03:40 +02:00
parent 85035dda60
commit 6c8ae2501a
2 changed files with 36 additions and 1 deletions

View file

@ -205,7 +205,37 @@ void ApplicationListModel::moveRow(const QModelIndex& /* sourceParent */, int so
moveItem(sourceRow, destinationChild);
}
Q_INVOKABLE void ApplicationListModel::moveItem(int row, int destination)
void ApplicationListModel::setFavoriteItem(int row, bool favorite)
{
if (row < 0 || row >= m_applicationList.length()) {
return;
}
ApplicationData &data = m_applicationList[row];
if (data.favorite == favorite) {
return;
}
data.favorite = favorite;
emit dataChanged(index(row, 0), index(row, 0));
}
void ApplicationListModel::setDesktopItem(int row, bool desktop)
{
if (row < 0 || row >= m_applicationList.length()) {
return;
}
ApplicationData &data = m_applicationList[row];
if (data.desktop == desktop) {
return;
}
data.desktop = desktop;
emit dataChanged(index(row, 0), index(row, 0));
}
void ApplicationListModel::moveItem(int row, int destination)
{
if (row < 0 || destination < 0 || row >= m_applicationList.length() ||
destination >= m_applicationList.length() || row == destination) {

View file

@ -32,6 +32,8 @@ struct ApplicationData {
QString icon;
QString storageId;
QString entryPath;
bool favorite = false;
bool desktop = false;
};
class ApplicationListModel : public QAbstractListModel {
@ -67,6 +69,9 @@ public:
QStringList appOrder() const;
void setAppOrder(const QStringList &order);
Q_INVOKABLE void setFavoriteItem(int row, bool favorite);
Q_INVOKABLE void setDesktopItem(int row, bool desktop);
Q_INVOKABLE void moveItem(int row, int order);
Q_INVOKABLE void runApplication(const QString &storageId);