on xenial help sign in
some more work on pinning and storing the app list
10fc9e5Michael Zanetti
plugins/Unity/Launcher/launchermodel.cpp+31−23
@@ -28,7 +28,12 @@ LauncherModel::LauncherModel(QObject *parent):
28 m_backend(new LauncherBackend(this))
28 m_backend(new LauncherBackend(this))
29{
29{
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);
34+ } else {
35+ item->setRecent(true);
36+ }
32 }
37 }
33}
38}
34
39
@@ -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();
79
84
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);
86− }
87
86
88− // Store new order
87+ pin(newIndex);
89− QStringList appIds;
90− Q_FOREACH(LauncherItem *item, m_list) {
91− if (item->favorite() || item->recent()) {
92− appIds << item->desktopFile();
93− }
94− }
95− m_backend->setStoredApplications(appIds);
96}
88}
97
89
98void LauncherModel::pin(int index)
90void LauncherModel::pin(int index)
99{
91{
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);
99+
100+ QModelIndex modelIndex = this->index(index);
101+ Q_EMIT dataChanged(modelIndex, modelIndex);
102+
103+ storeAppList();
107 }
104 }
108}
105}
109
106
@@ -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;
119}
116}
117+
118+void LauncherModel::storeAppList()
119+{
120+ QStringList appIds;
121+ Q_FOREACH(LauncherItem *item, m_list) {
122+ if (item->favorite() || item->recent()) {
123+ appIds << item->desktopFile();
124+ }
125+ }
126+ m_backend->setStoredApplications(appIds);
127+}
plugins/Unity/Launcher/launchermodel.h+3
@@ -49,6 +49,9 @@ public:
49
49
50 QHash<int, QByteArray> roleNames() const;
50 QHash<int, QByteArray> roleNames() const;
51
51
52+private:
53+ void storeAppList();
54+
52private:
55private:
53 QList<LauncherItem*> m_list;
56 QList<LauncherItem*> m_list;
54 LauncherBackend *m_backend;
57 LauncherBackend *m_backend;