on xenial help sign in
some more work on pinning and storing the app list
commit10fc9e5fa91fc98a5d3336d3d8e93fe297fbac7d authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 2 Jul 2013, 13:35 (13 years ago) parent15b29ef
2 files changed+34−23
plugins/Unity/Launcher/launchermodel.cpp+31−23 plugins/Unity/Launcher/launchermodel.h+3
plugins/Unity/Launcher/launchermodel.cpp+31−23
@@ -28,7 +28,12 @@ LauncherModel::LauncherModel(QObject *parent):
2828 m_backend(new LauncherBackend(this))
2929{
3030 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+ }
3237 }
3338}
3439
@@ -77,33 +82,25 @@ void LauncherModel::move(int oldIndex, int newIndex)
7782 m_list.move(oldIndex, newIndex);
7883 endMoveRows();
7984
80− // Mark moved app as pinned
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− }
85+ storeAppList();
8786
88− // Store new order
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);
87+ pin(newIndex);
9688}
9789
9890void LauncherModel::pin(int index)
9991{
100− QString appId = m_list.at(index)->desktopFile();
101− if (!m_backend->storedApplications().contains(appId)) {
102− QStringList oldList = m_backend->storedApplications();
103− m_backend->setStoredApplications(oldList << appId);
104− }
105− if (!m_backend->isPinned(appId)) {
106− m_backend->setPinned(appId, true);
92+ LauncherItem *item = m_list.at(index);
93+ if (!item->favorite()) {
94+
95+ item->setFavorite(true);
96+ item->setRecent(false);
97+
98+ m_backend->setPinned(item->desktopFile(), true);
99+
100+ QModelIndex modelIndex = this->index(index);
101+ Q_EMIT dataChanged(modelIndex, modelIndex);
102+
103+ storeAppList();
107104 }
108105}
109106
@@ -117,3 +114,14 @@ QHash<int, QByteArray> LauncherModel::roleNames() const
117114 roles.insert(RoleRunning, "runnng");
118115 return roles;
119116}
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:
4949
5050 QHash<int, QByteArray> roleNames() const;
5151
52+private:
53+ void storeAppList();
54+
5255private:
5356 QList<LauncherItem*> m_list;
5457 LauncherBackend *m_backend;