on xenial help sign in
some more work on the launcher backend
b1d8d0fMichael Zanetti
Launcher/LauncherPanel.qml+1−1
@@ -140,7 +140,7 @@ Item {
140 maxAngle: 60
140 maxAngle: 60
141
141
142 onClicked: {
142 onClicked: {
143− root.applicationSelected(LauncherModel.get(index).desktopFile);
143+ root.applicationSelected("/usr/share/applications/" + LauncherModel.get(index).desktopFile);
144 }
144 }
145 }
145 }
146
146
plugins/Unity/Launcher/CMakeLists.txt+2
@@ -16,6 +16,8 @@ set(QMLLAUNCHERPLUGIN_SRC
16 launcheritem.cpp
16 launcheritem.cpp
17 ${UNITY_API_DIR}/unity/shell/launcher/LauncherItemInterface.h
17 ${UNITY_API_DIR}/unity/shell/launcher/LauncherItemInterface.h
18 ${UNITY_API_DIR}/unity/shell/launcher/LauncherModelInterface.h
18 ${UNITY_API_DIR}/unity/shell/launcher/LauncherModelInterface.h
19+ backend/launcherbackend.cpp
20+ backend/applicationlistmodel.cpp
19 )
21 )
20
22
21add_library(UnityLauncher-qml MODULE
23add_library(UnityLauncher-qml MODULE
plugins/Unity/Launcher/launchermodel.cpp+27−24
@@ -19,32 +19,18 @@
19
19
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"
22
24
23−LauncherModel::LauncherModel(QObject *parent): LauncherModelInterface(parent)
25+#include <QDebug>
24−{
25− // FIXME: Dummy data... Aggregate real data from backends
26
26
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");
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);
48}
34}
49
35
50LauncherModel::~LauncherModel()
36LauncherModel::~LauncherModel()
@@ -64,6 +50,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
64{
50{
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
85
73
86void LauncherModel::move(int oldIndex, int newIndex)
74void LauncherModel::move(int oldIndex, int newIndex)
87{
75{
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();
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);
91}
94}
92
95
93QHash<int, QByteArray> LauncherModel::roleNames() const
96QHash<int, QByteArray> LauncherModel::roleNames() const
plugins/Unity/Launcher/launchermodel.h+4
@@ -20,11 +20,14 @@
20#ifndef LAUNCHERMODELH
20#ifndef LAUNCHERMODELH
21#define LAUNCHERMODEL_H
21#define LAUNCHERMODEL_H
22
22
23+// unity-api
23#include <unity/shell/launcher/LauncherModelInterface.h>
24#include <unity/shell/launcher/LauncherModelInterface.h>
24
25
26+// Qt
25#include <QAbstractListModel>
27#include <QAbstractListModel>
26
28
27class LauncherItem;
29class LauncherItem;
30+class LauncherBackend;
28
31
29using namespace unity::shell::launcher;
32using namespace unity::shell::launcher;
30
33
@@ -47,6 +50,7 @@ public:
47
50
48private:
51private:
49 QList<LauncherItem*> m_list;
52 QList<LauncherItem*> m_list;
53+ LauncherBackend *m_backend;
50};
54};
51
55
52#endif // LAUNCHERMODEL_H
56#endif // LAUNCHERMODEL_H