on xenial help sign in
some more work on the launcher backend
commitb1d8d0f876e494a8e8336a4010e7a4a45bc0a3b5 authorMichael Zanetti <michael.zanetti@canonical.com> dateTue 2 Jul 2013, 12:01 (13 years ago) parent959d967
4 files changed+34−25
Launcher/LauncherPanel.qml+1−1 plugins/Unity/Launcher/CMakeLists.txt+2 plugins/Unity/Launcher/launchermodel.cpp+27−24 plugins/Unity/Launcher/launchermodel.h+4
Launcher/LauncherPanel.qml+1−1
@@ -140,7 +140,7 @@ Item {
140140 maxAngle: 60
141141
142142 onClicked: {
143− root.applicationSelected(LauncherModel.get(index).desktopFile);
143+ root.applicationSelected("/usr/share/applications/" + LauncherModel.get(index).desktopFile);
144144 }
145145 }
146146
plugins/Unity/Launcher/CMakeLists.txt+2
@@ -16,6 +16,8 @@ set(QMLLAUNCHERPLUGIN_SRC
1616 launcheritem.cpp
1717 ${UNITY_API_DIR}/unity/shell/launcher/LauncherItemInterface.h
1818 ${UNITY_API_DIR}/unity/shell/launcher/LauncherModelInterface.h
19+ backend/launcherbackend.cpp
20+ backend/applicationlistmodel.cpp
1921 )
2022
2123add_library(UnityLauncher-qml MODULE
plugins/Unity/Launcher/launchermodel.cpp+27−24
@@ -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
plugins/Unity/Launcher/launchermodel.h+4
@@ -20,11 +20,14 @@
2020#ifndef LAUNCHERMODELH
2121#define LAUNCHERMODEL_H
2222
23+// unity-api
2324#include <unity/shell/launcher/LauncherModelInterface.h>
2425
26+// Qt
2527#include <QAbstractListModel>
2628
2729class LauncherItem;
30+class LauncherBackend;
2831
2932using namespace unity::shell::launcher;
3033
@@ -47,6 +50,7 @@ public:
4750
4851private:
4952 QList<LauncherItem*> m_list;
53+ LauncherBackend *m_backend;
5054};
5155
5256#endif // LAUNCHERMODEL_H