on xenial help sign in
quicklist pinning and removing working
commit10da5713f89f1faab20d901379cc5849c770c2c4 authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 24 Jul 2013, 12:42 (13 years ago) parent78a5186
7 files changed+63−7
Launcher/LauncherPanel.qml+16−3 plugins/Unity/Launcher/backend/launcherbackend.cpp+1−1 plugins/Unity/Launcher/launcheritem.cpp+8−1 plugins/Unity/Launcher/launchermodel.cpp+15−2 plugins/Unity/Launcher/plugin.cpp+2 plugins/Unity/Launcher/quicklistmodel.cpp+11 plugins/Unity/Launcher/quicklistmodel.h+10
Launcher/LauncherPanel.qml+16−3
@@ -198,6 +198,7 @@ Item {
198198 property var selectedItem
199199 property int startX
200200 property int startY
201+ property var quickListPopover
201202
202203 LauncherDelegate {
203204 id: fakeDragItem
@@ -237,11 +238,17 @@ Item {
237238
238239 onPressAndHold: {
239240 var realItemSize = launcherListView.itemSize + launcherListView.spacing
241+
240242 var realContentY = launcherListView.contentY + launcherListView.topMargin
241243 draggedIndex = Math.floor((mouseY + realContentY) / realItemSize);
242244
243245 launcherListView.interactive = false
244246
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+
245252 var yOffset = draggedIndex > 0 ? (mouseY + realContentY) % (draggedIndex * realItemSize) : mouseY + realContentY
246253
247254 fakeDragItem.iconName = launcherListView.model.get(draggedIndex).icon
@@ -263,6 +270,7 @@ Item {
263270 if (distance > launcherListView.itemSize) {
264271 print("starting drag")
265272 selectedItem.dragging = true
273+ PopupUtils.close(quickListPopover)
266274 }
267275 }
268276 if (!selectedItem.dragging) {
@@ -331,18 +339,23 @@ Item {
331339 Popover {
332340 id: popover
333341 width: units.gu(20)
342+ property var model
343+ property string appId
334344
335345 Column {
336346 width: parent.width
337347 height: childrenRect.height
338348 Repeater {
339− model: 2
349+ model: popover.model
340350 ListItems.Standard {
341− text: "foo bar baz"
351+ text: model.label
352+ onClicked: {
353+ LauncherModel.quickListActionInvoked(appId, index)
354+ PopupUtils.close(popover)
355+ }
342356 }
343357 }
344358 }
345359 }
346360 }
347−
348361}
plugins/Unity/Launcher/backend/launcherbackend.cpp+1−1
@@ -101,7 +101,7 @@ bool LauncherBackend::isPinned(const QString &appId) const
101101{
102102 // TODO: return app's pinned state from settings
103103 Q_UNUSED(appId)
104− return true;
104+ return false;
105105}
106106
107107void 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
3333 m_count(0),
3434 m_quickList(new QuickListModel(this))
3535{
36−
36+ QuickListEntry pinningAction;
37+ pinningAction.setActionId("pin_item");
38+ pinningAction.setText("Pin to Launcher");
39+ m_quickList->appendAction(pinningAction);
3740}
3841
3942QString LauncherItem::appId() const
@@ -65,6 +68,10 @@ void LauncherItem::setPinned(bool pinned)
6568{
6669 if (m_pinned != pinned) {
6770 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);
6875 Q_EMIT pinnedChanged(pinned);
6976 }
7077}
plugins/Unity/Launcher/launchermodel.cpp+15−2
@@ -157,10 +157,23 @@ void LauncherModel::quickListActionInvoked(const QString &appId, int actionIndex
157157 return;
158158 }
159159
160− QuickListModel *model = qobject_cast<QuickListModel*>(m_list.at(index)->quickList());
160+ LauncherItem *item = m_list.at(index);
161+ QuickListModel *model = qobject_cast<QuickListModel*>(item->quickList());
161162 if (model) {
162163 QString actionId = model->get(actionIndex).actionId();
163− m_backend->triggerQuickListAction(appId, 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 {
175+ m_backend->triggerQuickListAction(appId, actionId);
176+ }
164177 }
165178}
166179
plugins/Unity/Launcher/plugin.cpp+2
@@ -41,7 +41,9 @@ void UnityLauncherPlugin::registerTypes(const char *uri)
4141
4242 qmlRegisterUncreatableType<LauncherModelInterface>(uri, 0, 1, "LauncherModelInterface", "Abstract Interface. Cannot be instantiated.");
4343 qmlRegisterUncreatableType<LauncherItemInterface>(uri, 0, 1, "LauncherItemInterface", "Abstract Interface. Cannot be instantiated.");
44+ qmlRegisterUncreatableType<QuickListModelInterface>(uri, 0, 1, "QuickListInterface", "Abstract Interface. Cannot be instantiated.");
4445
4546 qmlRegisterSingletonType<LauncherModel>(uri, 0, 1, "LauncherModel", modelProvider);
4647 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.");
4749}
plugins/Unity/Launcher/quicklistmodel.cpp+11
@@ -37,6 +37,17 @@ void QuickListModel::appendAction(const QuickListEntry &entry)
3737 endInsertRows();
3838}
3939
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+
4051QuickListEntry QuickListModel::get(int index) const
4152{
4253 return m_list.at(index);
plugins/Unity/Launcher/quicklistmodel.h+10
@@ -36,6 +36,16 @@ public:
3636 ~QuickListModel();
3737
3838 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+
3949 QuickListEntry get(int index) const;
4050
4151 int rowCount(const QModelIndex &parent = QModelIndex()) const;