on xenial help sign in
quicklist pinning and removing working
10da571Michael Zanetti
Launcher/LauncherPanel.qml+16−3
@@ -198,6 +198,7 @@ Item {
198 property var selectedItem
198 property var selectedItem
199 property int startX
199 property int startX
200 property int startY
200 property int startY
201+ property var quickListPopover
201
202
202 LauncherDelegate {
203 LauncherDelegate {
203 id: fakeDragItem
204 id: fakeDragItem
@@ -237,11 +238,17 @@ Item {
237
238
238 onPressAndHold: {
239 onPressAndHold: {
239 var realItemSize = launcherListView.itemSize + launcherListView.spacing
240 var realItemSize = launcherListView.itemSize + launcherListView.spacing
241+
240 var realContentY = launcherListView.contentY + launcherListView.topMargin
242 var realContentY = launcherListView.contentY + launcherListView.topMargin
241 draggedIndex = Math.floor((mouseY + realContentY) / realItemSize);
243 draggedIndex = Math.floor((mouseY + realContentY) / realItemSize);
242
244
243 launcherListView.interactive = false
245 launcherListView.interactive = false
244
246
247+ var quickListModel = launcherListView.model.get(draggedIndex).quickList
248+ var quickListAppId = launcherListView.model.get(draggedIndex).appId
249+ quickListPopover = PopupUtils.open(popoverComponent, selectedItem,
250+ {model: quickListModel, appId: quickListAppId})
251+
245 var yOffset = draggedIndex > 0 ? (mouseY + realContentY) % (draggedIndex * realItemSize) : mouseY + realContentY
252 var yOffset = draggedIndex > 0 ? (mouseY + realContentY) % (draggedIndex * realItemSize) : mouseY + realContentY
246
253
247 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
254 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
@@ -263,6 +270,7 @@ Item {
263 if (distance > launcherListView.itemSize) {
270 if (distance > launcherListView.itemSize) {
264 print("starting drag")
271 print("starting drag")
265 selectedItem.dragging = true
272 selectedItem.dragging = true
273+ PopupUtils.close(quickListPopover)
266 }
274 }
267 }
275 }
268 if (!selectedItem.dragging) {
276 if (!selectedItem.dragging) {
@@ -331,18 +339,23 @@ Item {
331 Popover {
339 Popover {
332 id: popover
340 id: popover
333 width: units.gu(20)
341 width: units.gu(20)
342+ property var model
343+ property string appId
334
344
335 Column {
345 Column {
336 width: parent.width
346 width: parent.width
337 height: childrenRect.height
347 height: childrenRect.height
338 Repeater {
348 Repeater {
339− model: 2
349+ model: popover.model
340 ListItems.Standard {
350 ListItems.Standard {
341− text: "foo bar baz"
351+ text: model.label
352+ onClicked: {
353+ LauncherModel.quickListActionInvoked(appId, index)
354+ PopupUtils.close(popover)
355+ }
342 }
356 }
343 }
357 }
344 }
358 }
345 }
359 }
346 }
360 }
347−
348}
361}
plugins/Unity/Launcher/backend/launcherbackend.cpp+1−1
@@ -101,7 +101,7 @@ bool LauncherBackend::isPinned(const QString &appId) const
101{
101{
102 // TODO: return app's pinned state from settings
102 // TODO: return app's pinned state from settings
103 Q_UNUSED(appId)
103 Q_UNUSED(appId)
104− return true;
104+ return false;
105}
105}
106
106
107void LauncherBackend::setPinned(const QString &appId, bool pinned)
107void LauncherBackend::setPinned(const QString &appId, bool pinned)
plugins/Unity/Launcher/launcheritem.cpp+8−1
@@ -33,7 +33,10 @@ LauncherItem::LauncherItem(const QString &appId, const QString &desktopFile, con
33 m_count(0),
33 m_count(0),
34 m_quickList(new QuickListModel(this))
34 m_quickList(new QuickListModel(this))
35{
35{
36−
36+ QuickListEntry pinningAction;
37+ pinningAction.setActionId("pin_item");
38+ pinningAction.setText("Pin to Launcher");
39+ m_quickList->appendAction(pinningAction);
37}
40}
38
41
39QString LauncherItem::appId() const
42QString LauncherItem::appId() const
@@ -65,6 +68,10 @@ void LauncherItem::setPinned(bool pinned)
65{
68{
66 if (m_pinned != pinned) {
69 if (m_pinned != pinned) {
67 m_pinned = pinned;
70 m_pinned = pinned;
71+ QuickListEntry entry;
72+ entry.setActionId("pin_item");
73+ entry.setText(pinned ? "Remove from Launcher": "Pin to Launcher");
74+ m_quickList->updateAction(entry);
68 Q_EMIT pinnedChanged(pinned);
75 Q_EMIT pinnedChanged(pinned);
69 }
76 }
70}
77}
plugins/Unity/Launcher/launchermodel.cpp+15−2
@@ -157,10 +157,23 @@ void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex
157 return;
157 return;
158 }
158 }
159
159
160+ LauncherItem *item = m_list.at(index);
160− QuickListModel *model = qobject_cast<QuickListModel*>(m_list.at(index)->quickList());
161+ QuickListModel *model = qobject_cast<QuickListModel*>(item->quickList());
161 if (model) {
162 if (model) {
162 QString actionId = model->get(actionIndex).actionId();
163 QString actionId = model->get(actionIndex).actionId();
164+
165+ // Check if this is one of the launcher actions we handle ourselves
166+ if (actionId == "pin_item") {
167+ if (item->pinned()) {
168+ requestRemove(appId);
169+ } else {
170+ pin(appId);
171+ }
172+
173+ // Nope, we don't know this action, let the backend forward it to the application
174+ } else {
163− m_backend->triggerQuickListAction(appId, actionId);
175+ m_backend->triggerQuickListAction(appId, actionId);
176+ }
164 }
177 }
165}
178}
166
179
plugins/Unity/Launcher/plugin.cpp+2
@@ -41,7 +41,9 @@ void UnityLauncherPlugin::registerTypes(const char *uri)
41
41
42 qmlRegisterUncreatableType<LauncherModelInterface>(uri, 0, 1, "LauncherModelInterface", "Abstract Interface. Cannot be instantiated.");
42 qmlRegisterUncreatableType<LauncherModelInterface>(uri, 0, 1, "LauncherModelInterface", "Abstract Interface. Cannot be instantiated.");
43 qmlRegisterUncreatableType<LauncherItemInterface>(uri, 0, 1, "LauncherItemInterface", "Abstract Interface. Cannot be instantiated.");
43 qmlRegisterUncreatableType<LauncherItemInterface>(uri, 0, 1, "LauncherItemInterface", "Abstract Interface. Cannot be instantiated.");
44+ qmlRegisterUncreatableType<QuickListModelInterface>(uri, 0, 1, "QuickListInterface", "Abstract Interface. Cannot be instantiated.");
44
45
45 qmlRegisterSingletonType<LauncherModel>(uri, 0, 1, "LauncherModel", modelProvider);
46 qmlRegisterSingletonType<LauncherModel>(uri, 0, 1, "LauncherModel", modelProvider);
46 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
47 qmlRegisterUncreatableType<LauncherItem>(uri, 0, 1, "LauncherItem", "Can't create new Launcher Items in QML. Get them from the LauncherModel.");
48+ qmlRegisterUncreatableType<QuickListModel>(uri, 0, 1, "QuickListModel", "Can't create a QuickListModel in QML. Get them from the LauncherItems.");
47}
49}
plugins/Unity/Launcher/quicklistmodel.cpp+11
@@ -37,6 +37,17 @@ void QuickListModel::appendAction(const QuickListEntry &entry)
37 endInsertRows();
37 endInsertRows();
38}
38}
39
39
40+void QuickListModel::updateAction(const QuickListEntry &entry)
41+{
42+ for (int i = 0; i < m_list.count(); ++i) {
43+ if (m_list.at(i).actionId() == entry.actionId()) {
44+ m_list.replace(i, entry);
45+ Q_EMIT dataChanged(index(i), index(i));
46+ return;
47+ }
48+ }
49+}
50+
40QuickListEntry QuickListModel::get(int index) const
51QuickListEntry QuickListModel::get(int index) const
41{
52{
42 return m_list.at(index);
53 return m_list.at(index);
plugins/Unity/Launcher/quicklistmodel.h+10
@@ -36,6 +36,16 @@ public:
36 ~QuickListModel();
36 ~QuickListModel();
37
37
38 void appendAction(const QuickListEntry &entry);
38 void appendAction(const QuickListEntry &entry);
39+
40+ /**
41+ * @brief Update an existing action
42+ * @param entry The new, updated entry
43+ *
44+ * This will only do something if entry.actionId is found in the model.
45+ * To add a new entry, use appendAction().
46+ */
47+ void updateAction(const QuickListEntry &entry);
48+
39 QuickListEntry get(int index) const;
49 QuickListEntry get(int index) const;
40
50
41 int rowCount(const QModelIndex &parent = QModelIndex()) const;
51 int rowCount(const QModelIndex &parent = QModelIndex()) const;