on xenial help sign in
adjust model to follow fixes in unity-api
18dce59Michael Zanetti
plugins/Unity/Launcher/launcheritem.cpp+1−1
@@ -36,7 +36,7 @@ LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, con
36
36
37}
37}
38
38
39−QString LauncherItem::appId()
39+QString LauncherItem::appId() const
40{
40{
41 return m_appId;
41 return m_appId;
42}
42}
plugins/Unity/Launcher/launcheritem.h+1−3
@@ -34,10 +34,8 @@ class LauncherItem: public LauncherItemInterface
34public:
34public:
35 LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent = 0);
35 LauncherItem(const QString &appId, const QString &desktopFile, const QString &name, const QString &icon, QObject *parent = 0);
36
36
37− QString appId();
37+ QString appId() const;
38−
39 QString desktopFile() const;
38 QString desktopFile() const;
40−
41 QString name() const;
39 QString name() const;
42 QString icon() const;
40 QString icon() const;
43
41
plugins/Unity/Launcher/launchermodel.cpp+33−17
@@ -57,6 +57,8 @@ QVariant LauncherModel::data(const QModelIndex &index, int role) const
57{
57{
58 LauncherItem *item = m_list.at(index.row());
58 LauncherItem *item = m_list.at(index.row());
59 switch(role) {
59 switch(role) {
60+ case RoleAppId:
61+ return item->desktopFile();
60 case RoleDesktopFile:
62 case RoleDesktopFile:
61 return item->desktopFile();
63 return item->desktopFile();
62 case RoleName:
64 case RoleName:
@@ -87,11 +89,16 @@ void LauncherModel::move(int oldIndex, int newIndex)
87
89
88 storeAppList();
90 storeAppList();
89
91
90− pin(newIndex);
92+ pin(m_list.at(newIndex)->appId());
91}
93}
92
94
93−void LauncherModel::pin(int index)
95+void LauncherModel::pin(const QString &appId)
94{
96{
97+ int index = findApplication(appId);
98+ if (index < 0) {
99+ return;
100+ }
101+
95 LauncherItem *item = m_list.at(index);
102 LauncherItem *item = m_list.at(index);
96 if (!item->pinned()) {
103 if (!item->pinned()) {
97
104
@@ -107,8 +114,13 @@ void LauncherModel::pin(int index)
107 }
114 }
108}
115}
109
116
110−void LauncherModel::remove(int index)
117+void LauncherModel::requestRemove(const QString &appId)
111{
118{
119+ int index = findApplication(appId);
120+ if (index < 0) {
121+ return;
122+ }
123+
112 beginRemoveRows(QModelIndex(), index, index);
124 beginRemoveRows(QModelIndex(), index, index);
113 m_list.takeAt(index)->deleteLater();
125 m_list.takeAt(index)->deleteLater();
114 endRemoveRows();
126 endRemoveRows();
@@ -116,27 +128,20 @@ void LauncherModel::remove(int index)
116 storeAppList();
128 storeAppList();
117}
129}
118
130
119−void LauncherModel::triggerQuickListAction(int itemIndex, int quickListIndex)
131+void LauncherModel::triggerQuickListAction(const QString &appId, int quickListIndex)
120{
132{
121− QString appId = m_list.at(itemIndex)->appId();
133+ int index = findApplication(appId);
134+ if (index < 0) {
135+ return;
136+ }
137+
122− QuickListModel *model = qobject_cast<QuickListModel*>(m_list.at(itemIndex)->quickList());
138+ QuickListModel *model = qobject_cast<QuickListModel*>(m_list.at(index)->quickList());
123 if (model) {
139 if (model) {
124 QString actionId = model->get(quickListIndex).actionId();
140 QString actionId = model->get(quickListIndex).actionId();
125 m_backend->triggerQuickListAction(appId, actionId);
141 m_backend->triggerQuickListAction(appId, actionId);
126 }
142 }
127}
143}
128
144
129−QHash<int, QByteArray> LauncherModel::roleNames() const
130−{
131− QHash<int, QByteArray> roles;
132− roles.insert(RoleDesktopFile, "desktopFile");
133− roles.insert(RoleName, "name");
134− roles.insert(RoleIcon, "icon");
135− roles.insert(RolePinned, "pinned");
136− roles.insert(RoleRunning, "runnng");
137− return roles;
138−}
139−
140void LauncherModel::storeAppList()
145void LauncherModel::storeAppList()
141{
146{
142 QStringList appIds;
147 QStringList appIds;
@@ -147,3 +152,14 @@ void LauncherModel::storeAppList()
147 }
152 }
148 m_backend->setStoredApplications(appIds);
153 m_backend->setStoredApplications(appIds);
149}
154}
155+
156+int LauncherModel::findApplication(const QString &appId)
157+{
158+ for (int i = 0; i < m_list.count(); ++i) {
159+ LauncherItem *item = m_list.at(i);
160+ if (item->appId() == appId) {
161+ return i;
162+ }
163+ }
164+ return -1;
165+}
plugins/Unity/Launcher/launchermodel.h+4−5
@@ -45,14 +45,13 @@ public:
45
45
46 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface* get(int index) const;
46 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface* get(int index) const;
47 Q_INVOKABLE void move(int oldIndex, int newIndex);
47 Q_INVOKABLE void move(int oldIndex, int newIndex);
48− Q_INVOKABLE void pin(int index);
48+ Q_INVOKABLE void pin(const QString &appId);
49− Q_INVOKABLE void remove(int index);
49+ Q_INVOKABLE void requestRemove(const QString &appId);
50− Q_INVOKABLE void triggerQuickListAction(int itemIndex, int quickListIndex);
50+ Q_INVOKABLE void triggerQuickListAction(const QString &appId, int quickListIndex);
51−
52− QHash<int, QByteArray> roleNames() const;
53
51
54private:
52private:
55 void storeAppList();
53 void storeAppList();
54+ int findApplication(const QString &appId);
56
55
57private:
56private:
58 QList<LauncherItem*> m_list;
57 QList<LauncherItem*> m_list;
tests/mocks/Unity/Launcher/MockLauncherItem.cpp+7−1
@@ -22,8 +22,9 @@
22
22
23using namespace unity::shell::launcher;
23using namespace unity::shell::launcher;
24
24
25−MockLauncherItem::MockLauncherItem(const QString& desktopFile, const QString& name, const QString& icon, QObject* parent):
25+MockLauncherItem::MockLauncherItem(const QString &appId, const QString& desktopFile, const QString& name, const QString& icon, QObject* parent):
26 LauncherItemInterface(parent),
26 LauncherItemInterface(parent),
27+ m_appId(appId),
27 m_desktopFile(desktopFile),
28 m_desktopFile(desktopFile),
28 m_name(name),
29 m_name(name),
29 m_icon(icon),
30 m_icon(icon),
@@ -37,6 +38,11 @@ MockLauncherItem::MockLauncherItem(const QString& desktopFile, const QString& na
37
38
38}
39}
39
40
41+QString MockLauncherItem::appId() const
42+{
43+ return m_appId;
44+}
45+
40QString MockLauncherItem::desktopFile() const
46QString MockLauncherItem::desktopFile() const
41{
47{
42 return m_desktopFile;
48 return m_desktopFile;
tests/mocks/Unity/Launcher/MockLauncherItem.h+3−2
@@ -30,10 +30,10 @@ class MockLauncherItem: public LauncherItemInterface
30{
30{
31 Q_OBJECT
31 Q_OBJECT
32public:
32public:
33− MockLauncherItem(const QString& desktopFile, const QString& name, const QString& icon, QObject* parent = 0);
33+ MockLauncherItem(const QString &appId, const QString& desktopFile, const QString& name, const QString& icon, QObject* parent = 0);
34
34
35+ QString appId() const;
35 QString desktopFile() const;
36 QString desktopFile() const;
36−
37 QString name() const;
37 QString name() const;
38 QString icon() const;
38 QString icon() const;
39
39
@@ -55,6 +55,7 @@ public:
55 unity::shell::launcher::QuickListModelInterface *quickList() const;
55 unity::shell::launcher::QuickListModelInterface *quickList() const;
56
56
57private:
57private:
58+ QString m_appId;
58 QString m_desktopFile;
59 QString m_desktopFile;
59 QString m_name;
60 QString m_name;
60 QString m_icon;
61 QString m_icon;
tests/mocks/Unity/Launcher/MockLauncherModel.cpp+37−20
@@ -22,25 +22,25 @@
22
22
23MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
23MockLauncherModel::MockLauncherModel(QObject* parent): LauncherModelInterface(parent)
24{
24{
25− MockLauncherItem *item = new MockLauncherItem("/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
25+ MockLauncherItem *item = new MockLauncherItem("phone-app", "/usr/share/applications/phone-app.desktop", "Phone", "phone-app");
26 m_list.append(item);
26 m_list.append(item);
27− item = new MockLauncherItem("/usr/share/applications/camera-app.desktop", "Camera", "camera");
27+ item = new MockLauncherItem("camera-app", "/usr/share/applications/camera-app.desktop", "Camera", "camera");
28 m_list.append(item);
28 m_list.append(item);
29− item = new MockLauncherItem("/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
29+ item = new MockLauncherItem("gallery-app", "/usr/share/applications/gallery-app.desktop", "Gallery", "gallery");
30 m_list.append(item);
30 m_list.append(item);
31− item = new MockLauncherItem("/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
31+ item = new MockLauncherItem("facebook-webapp", "/usr/share/applications/facebook-webapp.desktop", "Facebook", "facebook");
32 m_list.append(item);
32 m_list.append(item);
33− item = new MockLauncherItem("/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
33+ item = new MockLauncherItem("webbrowser-app", "/usr/share/applications/webbrowser-app.desktop", "Browser", "browser");
34 m_list.append(item);
34 m_list.append(item);
35− item = new MockLauncherItem("/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
35+ item = new MockLauncherItem("twitter-webapp", "/usr/share/applications/twitter-webapp.desktop", "Twitter", "twitter");
36 m_list.append(item);
36 m_list.append(item);
37− item = new MockLauncherItem("/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
37+ item = new MockLauncherItem("gmail-webapp", "/usr/share/applications/gmail-webapp.desktop", "GMail", "gmail");
38 m_list.append(item);
38 m_list.append(item);
39− item = new MockLauncherItem("/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
39+ item = new MockLauncherItem("ubuntu-weather-app", "/usr/share/applications/ubuntu-weather-app.desktop", "Weather", "weather");
40 m_list.append(item);
40 m_list.append(item);
41− item = new MockLauncherItem("/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
41+ item = new MockLauncherItem("notes-app", "/usr/share/applications/notes-app.desktop", "Notepad", "notepad");
42 m_list.append(item);
42 m_list.append(item);
43− item = new MockLauncherItem("/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
43+ item = new MockLauncherItem("ubuntu-calendar-app", "/usr/share/applications/ubuntu-calendar-app.desktop","Calendar", "calendar");
44 m_list.append(item);
44 m_list.append(item);
45}
45}
46
46
@@ -100,23 +100,40 @@ void MockLauncherModel::move(int oldIndex, int newIndex)
100 endMoveRows();
100 endMoveRows();
101}
101}
102
102
103−void MockLauncherModel::pin(int index)
103+void MockLauncherModel::pin(const QString &appId)
104{
104{
105+ int index = findApp(appId);
106+ if (index >= 0) {
105− m_list.at(index)->setPinned(true);
107+ m_list.at(index)->setPinned(true);
106− QModelIndex modelIndex = this->index(index);
108+ QModelIndex modelIndex = this->index(index);
107− Q_EMIT dataChanged(modelIndex, modelIndex);
109+ Q_EMIT dataChanged(modelIndex, modelIndex);
110+ }
108}
111}
109
112
110−void MockLauncherModel::remove(int index)
113+void MockLauncherModel::requestRemove(const QString &appId)
111{
114{
115+ int index = findApp(appId);
116+ if (index >= 0) {
112− beginRemoveRows(QModelIndex(), index, 0);
117+ beginRemoveRows(QModelIndex(), index, 0);
113− m_list.takeAt(index)->deleteLater();
118+ m_list.takeAt(index)->deleteLater();
114− endRemoveRows();
119+ endRemoveRows();
120+ }
115}
121}
116
122
117−void MockLauncherModel::triggerQuickListAction(int itemIndex, int quickListIndex)
123+void MockLauncherModel::triggerQuickListAction(const QString &appId, int quickListIndex)
118{
124{
119− Q_UNUSED(itemIndex)
125+ Q_UNUSED(appId)
120 Q_UNUSED(quickListIndex)
126 Q_UNUSED(quickListIndex)
121 // Nothing to mock yet...
127 // Nothing to mock yet...
122}
128}
129+
130+int MockLauncherModel::findApp(const QString &appId)
131+{
132+ for (int i = 0; i < m_list.count(); ++i) {
133+ MockLauncherItem *item = m_list.at(i);
134+ if (item->appId() == appId) {
135+ return i;
136+ }
137+ }
138+ return -1;
139+}
tests/mocks/Unity/Launcher/MockLauncherModel.h+6−3
@@ -40,9 +40,12 @@ public:
40
40
41 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface *get(int index) const;
41 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface *get(int index) const;
42 Q_INVOKABLE void move(int oldIndex, int newIndex);
42 Q_INVOKABLE void move(int oldIndex, int newIndex);
43− Q_INVOKABLE void pin(int index);
43+ Q_INVOKABLE void pin(const QString &appId);
44− Q_INVOKABLE void remove(int index);
44+ Q_INVOKABLE void requestRemove(const QString &appId);
45− Q_INVOKABLE void triggerQuickListAction(int itemIndex, int quickListIndex);
45+ Q_INVOKABLE void triggerQuickListAction(const QString &appId, int quickListIndex);
46+
47+private:
48+ int findApp(const QString &appId);
46
49
47private:
50private:
48 QList<MockLauncherItem*> m_list;
51 QList<MockLauncherItem*> m_list;