@@ -19,32 +19,18 @@
20#include "launchermodel.h"
20#include "launchermodel.h"
21#include "launcheritem.h"
21#include "launcheritem.h"
22+#include "backend/launcherbackend.h"
23+#include "backend/applicationlistmodel.h"
23−LauncherModel::LauncherModel(QObject *parent): LauncherModelInterface(parent)
25+#include <QDebug>
25− // FIXME: Dummy data... Aggregate real data from backends
27− // Fake favorites
27+LauncherModel::LauncherModel(QObject *parent):
28− LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
28+ LauncherModelInterface(parent),
29− m_list.append(item);
29+ m_backend(new LauncherBackend(this))
30− item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
30+{
31− m_list.append(item);
31+ Q_FOREACH (const QString &entry, m_backend->favoriteApplications()) {
32− item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
32+ m_list.append(new LauncherItem(entry, m_backend->displayName(entry), m_backend->icon(entry), this));
33− m_list.append(item);
33+ }
34− item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
36− item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
38− item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
40− item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
42− item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
44− item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
46− item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
50LauncherModel::~LauncherModel()
36LauncherModel::~LauncherModel()
@@ -64,6 +50,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
65 LauncherItem *item = m_list.at(index.row());
51 LauncherItem *item = m_list.at(index.row());
66 switch(role) {
52 switch(role) {
53+ case RoleDesktopFile:
54+ return item->desktopFile();
67 case RoleName:
55 case RoleName:
68 return item->name();
56 return item->name();
69 case RoleIcon:
57 case RoleIcon:
@@ -85,9 +73,24 @@ unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) con
86void LauncherModel::move(int oldIndex, int newIndex)
74void LauncherModel::move(int oldIndex, int newIndex)
76+ // Perform the move in our list
88 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
77 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
89 m_list.move(oldIndex, newIndex);
78 m_list.move(oldIndex, newIndex);
90 endMoveRows();
79 endMoveRows();
81+ // Mark moved app as pinned
82+ LauncherItem *movedItem = m_list.at(newIndex);
83+ if (!m_backend->isPinned(movedItem->desktopFile()) {
84+ m_backend->setPinned(m_list.at(newIndex)->desktopFile(), true);
85+ emit dataChanged(QModelIndex(), newIndex, newIndex);
90+ Q_FOREACH(LauncherItem *item, m_list) {
91+ appIds << item->desktopFile();
93+ m_backend->setFavoriteApplications(appIds);
93QHash<int, QByteArray> LauncherModel::roleNames() const
96QHash<int, QByteArray> LauncherModel::roleNames() const