on xenial help sign in
update to latest fixes in unity-api
commit68b30f36c26ea733be7f1badca5ecfa3c7598fdf authorMichael Zanetti <michael.zanetti@canonical.com> dateMon 8 Jul 2013, 13:52 (13 years ago) parent18dce59
4 files changed+42−27
plugins/Unity/Launcher/launchermodel.cpp+19−17 plugins/Unity/Launcher/launchermodel.h+2−2 tests/mocks/Unity/Launcher/MockLauncherModel.cpp+19−6 tests/mocks/Unity/Launcher/MockLauncherModel.h+2−2
plugins/Unity/Launcher/launchermodel.cpp+19−17
@@ -92,25 +92,27 @@ void LauncherModel::move(int oldIndex, int newIndex)
9292 pin(m_list.at(newIndex)->appId());
9393}
9494
95−void LauncherModel::pin(const QString &appId)
95+void LauncherModel::pin(const QString &appId, int index)
9696{
97− int index = findApplication(appId);
98− if (index < 0) {
99− return;
100− }
101−
102− LauncherItem *item = m_list.at(index);
103− if (!item->pinned()) {
97+ int currentIndex = findApplication(appId);
10498
99+ if (currentIndex >= 0) {
100+ if (index == -1 || index == currentIndex) {
101+ m_list.at(currentIndex)->setPinned(true);
102+ QModelIndex modelIndex = this->index(currentIndex);
103+ Q_EMIT dataChanged(modelIndex, modelIndex);
104+ } else {
105+ move(currentIndex, index);
106+ }
107+ } else {
108+ beginInsertRows(QModelIndex(), index, index);
109+ LauncherItem *item = new LauncherItem(appId,
110+ m_backend->desktopFile(appId),
111+ m_backend->displayName(appId),
112+ m_backend->icon(appId));
105113 item->setPinned(true);
106− item->setRecent(false);
107−
108− m_backend->setPinned(item->appId(), true);
109−
110− QModelIndex modelIndex = this->index(index);
111− Q_EMIT dataChanged(modelIndex, modelIndex);
112−
113− storeAppList();
114+ m_list.insert(index, item);
115+ endInsertRows();
114116 }
115117}
116118
@@ -128,7 +130,7 @@ void LauncherModel::requestRemove(const QString &appId)
128130 storeAppList();
129131}
130132
131−void LauncherModel::triggerQuickListAction(const QString &appId, int quickListIndex)
133+void LauncherModel::quickListActionInvoked(const QString &appId, int quickListIndex)
132134{
133135 int index = findApplication(appId);
134136 if (index < 0) {
plugins/Unity/Launcher/launchermodel.h+2−2
@@ -45,9 +45,9 @@ public:
4545
4646 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface* get(int index) const;
4747 Q_INVOKABLE void move(int oldIndex, int newIndex);
48− Q_INVOKABLE void pin(const QString &appId);
48+ Q_INVOKABLE void pin(const QString &appId, int index = -1);
4949 Q_INVOKABLE void requestRemove(const QString &appId);
50− Q_INVOKABLE void triggerQuickListAction(const QString &appId, int quickListIndex);
50+ Q_INVOKABLE void quickListActionInvoked(const QString &appId, int quickListIndex);
5151
5252private:
5353 void storeAppList();
tests/mocks/Unity/Launcher/MockLauncherModel.cpp+19−6
@@ -100,13 +100,26 @@ void MockLauncherModel::move(int oldIndex, int newIndex)
100100 endMoveRows();
101101}
102102
103−void MockLauncherModel::pin(const QString &appId)
103+void MockLauncherModel::pin(const QString &appId, int index)
104104{
105− int index = findApp(appId);
106− if (index >= 0) {
105+ int currentIndex = findApp(appId);
106+
107+ if (currentIndex >= 0) {
108+ if (index == -1 || index == currentIndex) {
109+ m_list.at(currentIndex)->setPinned(true);
110+ QModelIndex modelIndex = this->index(currentIndex);
111+ Q_EMIT dataChanged(modelIndex, modelIndex);
112+ } else {
113+ move(currentIndex, index);
114+ }
115+ } else {
116+ beginInsertRows(QModelIndex(), index, index);
117+ m_list.insert(index, new MockLauncherItem(appId,
118+ appId + ".desktop",
119+ appId,
120+ appId + ".png"));
107121 m_list.at(index)->setPinned(true);
108− QModelIndex modelIndex = this->index(index);
109− Q_EMIT dataChanged(modelIndex, modelIndex);
122+ endInsertRows();
110123 }
111124}
112125
@@ -120,7 +133,7 @@ void MockLauncherModel::requestRemove(const QString &appId)
120133 }
121134}
122135
123−void MockLauncherModel::triggerQuickListAction(const QString &appId, int quickListIndex)
136+void MockLauncherModel::quickListActionInvoked(const QString &appId, int quickListIndex)
124137{
125138 Q_UNUSED(appId)
126139 Q_UNUSED(quickListIndex)
tests/mocks/Unity/Launcher/MockLauncherModel.h+2−2
@@ -40,9 +40,9 @@ public:
4040
4141 Q_INVOKABLE unity::shell::launcher::LauncherItemInterface *get(int index) const;
4242 Q_INVOKABLE void move(int oldIndex, int newIndex);
43− Q_INVOKABLE void pin(const QString &appId);
43+ Q_INVOKABLE void pin(const QString &appId, int index = -1);
4444 Q_INVOKABLE void requestRemove(const QString &appId);
45− Q_INVOKABLE void triggerQuickListAction(const QString &appId, int quickListIndex);
45+ Q_INVOKABLE void quickListActionInvoked(const QString &appId, int quickListIndex);
4646
4747private:
4848 int findApp(const QString &appId);