@@ -28,7 +28,12 @@ LauncherModel::LauncherModel(QObject *parent):
28 m_backend(new LauncherBackend(this))
28 m_backend(new LauncherBackend(this))
30 Q_FOREACH (const QString &entry, m_backend->storedApplications()) {
30 Q_FOREACH (const QString &entry, m_backend->storedApplications()) {
31− m_list.append(new LauncherItem(entry, m_backend->displayName(entry), m_backend->icon(entry), this));
31+ LauncherItem *item = new LauncherItem(entry, m_backend->displayName(entry), m_backend->icon(entry), this);
32+ if (m_backend->isPinned(entry)) {
33+ item->setFavorite(true);
35+ item->setRecent(true);
@@ -77,33 +82,25 @@ void LauncherModel::move(int oldIndex, int newIndex)
77 m_list.move(oldIndex, newIndex);
82 m_list.move(oldIndex, newIndex);
78 endMoveRows();
83 endMoveRows();
80− // Mark moved app as pinned
85+ storeAppList();
81− LauncherItem *movedItem = m_list.at(newIndex);
82− if (!m_backend->isPinned(movedItem->desktopFile())) {
83− m_backend->setPinned(m_list.at(newIndex)->desktopFile(), true);
84− QModelIndex modelIndex = index(newIndex);
85− Q_EMIT dataChanged(modelIndex, modelIndex);
88− // Store new order
87+ pin(newIndex);
90− Q_FOREACH(LauncherItem *item, m_list) {
91− if (item->favorite() || item->recent()) {
92− appIds << item->desktopFile();
95− m_backend->setStoredApplications(appIds);
98void LauncherModel::pin(int index)
90void LauncherModel::pin(int index)
100− QString appId = m_list.at(index)->desktopFile();
92+ LauncherItem *item = m_list.at(index);
101− if (!m_backend->storedApplications().contains(appId)) {
93+ if (!item->favorite()) {
102− QStringList oldList = m_backend->storedApplications();
94+
103− m_backend->setStoredApplications(oldList << appId);
95+ item->setFavorite(true);
104− }
96+ item->setRecent(false);
105− if (!m_backend->isPinned(appId)) {
97+
106− m_backend->setPinned(appId, true);
98+ m_backend->setPinned(item->desktopFile(), true);
100+ QModelIndex modelIndex = this->index(index);
101+ Q_EMIT dataChanged(modelIndex, modelIndex);
@@ -117,3 +114,14 @@ QHash<int, QByteArray> LauncherModel::roleNames() const
117 roles.insert(RoleRunning, "runnng");
114 roles.insert(RoleRunning, "runnng");
118 return roles;
115 return roles;
118+void LauncherModel::storeAppList()
121+ Q_FOREACH(LauncherItem *item, m_list) {
122+ if (item->favorite() || item->recent()) {
123+ appIds << item->desktopFile();
126+ m_backend->setStoredApplications(appIds);