@@ -19,32 +19,18 @@
1919
2020#include "launchermodel.h"
2121#include "launcheritem.h"
22+#include "backend/launcherbackend.h"
23+#include "backend/applicationlistmodel.h"
2224
23−LauncherModel::LauncherModel(QObject *parent): LauncherModelInterface(parent)
24−{
25− // FIXME: Dummy data... Aggregate real data from backends
25+#include <QDebug>
2626
27− // Fake favorites
28− LauncherItem *item = new LauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
29− m_list.append(item);
30− item = new LauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
31− m_list.append(item);
32− item = new LauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
33− m_list.append(item);
34− item = new LauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
35− m_list.append(item);
36− item = new LauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
37− m_list.append(item);
38− item = new LauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
39− m_list.append(item);
40− item = new LauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
41− m_list.append(item);
42− item = new LauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
43− m_list.append(item);
44− item = new LauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
45− m_list.append(item);
46− item = new LauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
47− m_list.append(item);
27+LauncherModel::LauncherModel(QObject *parent):
28+ LauncherModelInterface(parent),
29+ m_backend(new LauncherBackend(this))
30+{
31+ Q_FOREACH (const QString &entry, m_backend->favoriteApplications()) {
32+ m_list.append(new LauncherItem(entry, m_backend->displayName(entry), m_backend->icon(entry), this));
33+ }
4834}
4935
5036LauncherModel::~LauncherModel()
@@ -64,6 +50,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
6450{
6551 LauncherItem *item = m_list.at(index.row());
6652 switch(role) {
53+ case RoleDesktopFile:
54+ return item->desktopFile();
6755 case RoleName:
6856 return item->name();
6957 case RoleIcon:
@@ -85,9 +73,24 @@ unity::shell::launcher::LauncherItemInterface *LauncherModel::get(int index) con
8573
8674void LauncherModel::move(int oldIndex, int newIndex)
8775{
76+ // Perform the move in our list
8877 beginMoveRows(QModelIndex(), oldIndex, oldIndex, QModelIndex(), newIndex);
8978 m_list.move(oldIndex, newIndex);
9079 endMoveRows();
80+
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);
86+ }
87+
88+ // Store new order
89+ QStringList appIds;
90+ Q_FOREACH(LauncherItem *item, m_list) {
91+ appIds << item->desktopFile();
92+ }
93+ m_backend->setFavoriteApplications(appIds);
9194}
9295
9396QHash<int, QByteArray> LauncherModel::roleNames() const