Merge lp:~stolowski/unity-scopes-shell/favoriting-fixes into lp:unity-scopes-shell

Proposed by Paweł Stołowski
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 341
Merged at revision: 346
Proposed branch: lp:~stolowski/unity-scopes-shell/favoriting-fixes
Merge into: lp:unity-scopes-shell
Diff against target: 626 lines (+309/-126)
7 files modified
src/Unity/CMakeLists.txt (+1/-0)
src/Unity/favorites.cpp (+160/-0)
src/Unity/favorites.h (+63/-0)
src/Unity/scope.cpp (+4/-4)
src/Unity/scope.h (+2/-2)
src/Unity/scopes.cpp (+76/-118)
src/Unity/scopes.h (+3/-2)
To merge this branch: bzr merge lp:~stolowski/unity-scopes-shell/favoriting-fixes
Reviewer Review Type Date Requested Status
Marcus Tomlinson (community) Approve
Review via email: mp+302253@code.launchpad.net

Commit message

Optimize scope favoriting. Make sure click scope is favorited back if reinstalled.

Description of the change

Optimize and refactor scope favoriting. Make sure click scope is favorited back if reinstalled.

The optimization is mostly achieved by temporarily disabling gesttings signals when storing an updated list of favorites.

To post a comment you must log in.
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Outstanding work Pawel. +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Unity/CMakeLists.txt'
--- src/Unity/CMakeLists.txt 2016-06-02 08:49:55 +0000
+++ src/Unity/CMakeLists.txt 2016-08-10 07:21:23 +0000
@@ -20,6 +20,7 @@
20 collectors.cpp20 collectors.cpp
21 department.cpp21 department.cpp
22 departmentnode.cpp22 departmentnode.cpp
23 favorites.cpp
23 filters.cpp24 filters.cpp
24 filtergroupwidget.cpp25 filtergroupwidget.cpp
25 optionselectorfilter.cpp26 optionselectorfilter.cpp
2627
=== added file 'src/Unity/favorites.cpp'
--- src/Unity/favorites.cpp 1970-01-01 00:00:00 +0000
+++ src/Unity/favorites.cpp 2016-08-10 07:21:23 +0000
@@ -0,0 +1,160 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * Authors:
5 * Pawel Stolowski <pawel.stolowski@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <QGSettings>
21#include <QVariant>
22#include <QDebug>
23#include <unity/scopes/CannedQuery.h>
24#include <unity/UnityExceptions.h>
25#include <algorithm>
26#include "favorites.h"
27
28namespace scopes_ng
29{
30
31Favorites::Favorites(QObject *parent, QGSettings *dashSettings)
32 : QObject(parent),
33 m_dashSettings(dashSettings)
34{
35 if (m_dashSettings) {
36 readFavoritesFromGSettings();
37 QObject::connect(m_dashSettings, &QGSettings::changed, this, &Favorites::dashSettingsChanged);
38 }
39}
40
41void Favorites::readFavoritesFromGSettings()
42{
43 m_favoriteScopes.clear();
44 m_positionLookup.clear();
45
46 int pos = 0 ;
47 auto const favs = m_dashSettings->get(QStringLiteral("favoriteScopes")).toList();
48 for (auto const fv: favs) {
49 try
50 {
51 auto const query = unity::scopes::CannedQuery::from_uri(fv.toString().toStdString());
52 auto scopeId = QString::fromStdString(query.scope_id());
53 m_favoriteScopes.append(scopeId);
54 m_positionLookup[scopeId] = pos++;
55 }
56 catch (const unity::InvalidArgumentException &e)
57 {
58 qWarning() << "Invalid canned query '" << fv.toString() << "'" << QString::fromStdString(e.what());
59 }
60 }
61}
62
63Favorites::~Favorites()
64{
65}
66
67int Favorites::setFavorite(QString const& scopeId, bool value)
68{
69 if (!value) {
70 int pos = position(scopeId);
71 if (pos >= 0) {
72 m_favoriteScopes.removeAt(pos);
73 m_positionLookup.remove(scopeId);
74 for (int i = pos; i<m_favoriteScopes.size(); i++) {
75 m_positionLookup[m_favoriteScopes[i]] = i;
76 }
77 Q_ASSERT(m_favoriteScopes.size() == m_positionLookup.size());
78 storeFavorites();
79 return pos;
80 }
81 } else {
82 int pos = position(scopeId);
83 if (pos < 0) {
84 m_favoriteScopes.push_back(scopeId);
85 pos = m_favoriteScopes.size() - 1;
86 m_positionLookup[scopeId] = pos;
87 }
88 Q_ASSERT(m_favoriteScopes.size() == m_positionLookup.size());
89 storeFavorites();
90 return pos;
91 }
92
93 return -1;
94}
95
96void Favorites::moveFavoriteTo(QString const& scopeId, int pos)
97{
98 int oldPos = position(scopeId);
99 if (oldPos >= 0) {
100 m_favoriteScopes.move(oldPos, pos);
101 auto const range = std::minmax(oldPos, pos);
102 for (int i = range.first; i<=range.second; i++) {
103 m_positionLookup[m_favoriteScopes[i]] = i;
104 }
105 } else {
106 qWarning() << "Favorites::moveFavoriteTo: no such scope" << scopeId;
107 }
108
109 storeFavorites();
110
111 Q_ASSERT(m_favoriteScopes.size() == m_positionLookup.size());
112}
113
114QStringList Favorites::getFavorites()
115{
116 return m_favoriteScopes;
117}
118
119bool Favorites::hasScope(QString const& scopeId) const
120{
121 return m_positionLookup.find(scopeId) != m_positionLookup.end();
122}
123
124int Favorites::position(QString const& scopeId) const
125{
126 auto it = m_positionLookup.find(scopeId);
127 if (it != m_positionLookup.end()) {
128 return it.value();
129 }
130 return -1;
131}
132
133void Favorites::dashSettingsChanged(QString const &key)
134{
135 if (key != QLatin1String("favoriteScopes")) {
136 return;
137 }
138 readFavoritesFromGSettings();
139 Q_EMIT favoritesChanged();
140}
141
142void Favorites::storeFavorites()
143{
144 if (m_dashSettings) {
145 QStringList cannedQueries;
146 for (auto const& fav: m_favoriteScopes)
147 {
148 const QString query = "scope://" + fav;
149 cannedQueries.push_back(query);
150 }
151
152 QObject::disconnect(m_dashSettings, &QGSettings::changed, this, &Favorites::dashSettingsChanged);
153 m_dashSettings->set(QStringLiteral("favoriteScopes"), QVariant(cannedQueries));
154 QObject::connect(m_dashSettings, &QGSettings::changed, this, &Favorites::dashSettingsChanged);
155 }
156}
157
158} // namespace scopes_ng
159
160#include <favorites.moc>
0161
=== added file 'src/Unity/favorites.h'
--- src/Unity/favorites.h 1970-01-01 00:00:00 +0000
+++ src/Unity/favorites.h 2016-08-10 07:21:23 +0000
@@ -0,0 +1,63 @@
1/*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * Authors:
5 * Pawel Stolowski <pawel.stolowski@canonical.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef NG_FAVORITES_H
21#define NG_FAVORITES_H
22
23#include <QStringList>
24#include <QObject>
25#include <QPointer>
26#include <QMap>
27
28class QGSettings;
29
30namespace scopes_ng
31{
32
33class Q_DECL_EXPORT Favorites : public QObject
34{
35 Q_OBJECT
36public:
37 Favorites(QObject *parent, QGSettings *dashSettings);
38 ~Favorites();
39
40 int setFavorite(QString const& scopeId, bool value);
41 void moveFavoriteTo(QString const& scopeId, int pos);
42 bool hasScope(QString const& scopeId) const;
43 int position(QString const& scopeId) const;
44 QStringList getFavorites();
45 void storeFavorites();
46
47Q_SIGNALS:
48 void favoritesChanged();
49
50private Q_SLOTS:
51 void dashSettingsChanged(QString const &key);
52
53private:
54 void readFavoritesFromGSettings();
55
56 QPointer<QGSettings> m_dashSettings;
57 QStringList m_favoriteScopes;
58 QMap<QString, int> m_positionLookup;
59};
60
61} // namespace scopes_ng
62
63#endif // NG_SCOPES_H
064
=== modified file 'src/Unity/scope.cpp'
--- src/Unity/scope.cpp 2016-06-24 14:03:59 +0000
+++ src/Unity/scope.cpp 2016-08-10 07:21:23 +0000
@@ -75,13 +75,13 @@
75const int RESULTS_TTL_LARGE = 3600000; // 1 hour75const int RESULTS_TTL_LARGE = 3600000; // 1 hour
76const int SEARCH_CARDINALITY = 300; // maximum number of results accepted from a single scope76const int SEARCH_CARDINALITY = 300; // maximum number of results accepted from a single scope
7777
78Scope::Ptr Scope::newInstance(scopes_ng::Scopes* parent)78Scope::Ptr Scope::newInstance(scopes_ng::Scopes* parent, bool favorite)
79{79{
80 auto scope = Scope::Ptr(new Scope(parent), &QObject::deleteLater);80 auto scope = Scope::Ptr(new Scope(parent, favorite), &QObject::deleteLater);
81 return scope;81 return scope;
82}82}
8383
84Scope::Scope(scopes_ng::Scopes* parent) :84Scope::Scope(scopes_ng::Scopes* parent, bool favorite) :
85 m_query_id(0)85 m_query_id(0)
86 , m_formFactor(QStringLiteral("phone"))86 , m_formFactor(QStringLiteral("phone"))
87 , m_activeFiltersCount(0)87 , m_activeFiltersCount(0)
@@ -91,7 +91,7 @@
91 , m_resultsDirty(false)91 , m_resultsDirty(false)
92 , m_delayedSearchProcessing(false)92 , m_delayedSearchProcessing(false)
93 , m_hasNavigation(false)93 , m_hasNavigation(false)
94 , m_favorite(false)94 , m_favorite(favorite)
95 , m_initialQueryDone(false)95 , m_initialQueryDone(false)
96 , m_childScopesDirty(true)96 , m_childScopesDirty(true)
97 , m_searchController(new CollectionController)97 , m_searchController(new CollectionController)
9898
=== modified file 'src/Unity/scope.h'
--- src/Unity/scope.h 2016-06-23 09:27:45 +0000
+++ src/Unity/scope.h 2016-08-10 07:21:23 +0000
@@ -110,7 +110,7 @@
110public:110public:
111 typedef QSharedPointer<Scope> Ptr;111 typedef QSharedPointer<Scope> Ptr;
112112
113 static Scope::Ptr newInstance(scopes_ng::Scopes* parent);113 static Scope::Ptr newInstance(scopes_ng::Scopes* parent, bool favorite = false);
114114
115 virtual ~Scope();115 virtual ~Scope();
116116
@@ -205,7 +205,7 @@
205 void previewModelDestroyed(QObject *obj);205 void previewModelDestroyed(QObject *obj);
206206
207protected:207protected:
208 explicit Scope(scopes_ng::Scopes* parent);208 explicit Scope(scopes_ng::Scopes* parent, bool favorite = false);
209209
210 void setStatus(unity::shell::scopes::ScopeInterface::Status status);210 void setStatus(unity::shell::scopes::ScopeInterface::Status status);
211 void invalidateLastSearch();211 void invalidateLastSearch();
212212
=== modified file 'src/Unity/scopes.cpp'
--- src/Unity/scopes.cpp 2016-06-23 12:53:21 +0000
+++ src/Unity/scopes.cpp 2016-08-10 07:21:23 +0000
@@ -24,6 +24,7 @@
24#include "scope.h"24#include "scope.h"
25#include "overviewscope.h"25#include "overviewscope.h"
26#include "ubuntulocationservice.h"26#include "ubuntulocationservice.h"
27#include "favorites.h"
2728
28// Qt29// Qt
29#include <QDebug>30#include <QDebug>
@@ -126,10 +127,8 @@
126 QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/com/canonical/unity/scopes"), QStringLiteral("com.canonical.unity.scopes"), QStringLiteral("InvalidateResults"), this, SLOT(invalidateScopeResults(QString)));127 QDBusConnection::sessionBus().connect(QString(), QStringLiteral("/com/canonical/unity/scopes"), QStringLiteral("com.canonical.unity.scopes"), QStringLiteral("InvalidateResults"), this, SLOT(invalidateScopeResults(QString)));
127128
128 m_dashSettings = QGSettings::isSchemaInstalled("com.canonical.Unity.Dash") ? new QGSettings("com.canonical.Unity.Dash", QByteArray(), this) : nullptr;129 m_dashSettings = QGSettings::isSchemaInstalled("com.canonical.Unity.Dash") ? new QGSettings("com.canonical.Unity.Dash", QByteArray(), this) : nullptr;
129 if (m_dashSettings)130 m_favoriteScopes = new Favorites(this, m_dashSettings);
130 {131 QObject::connect(m_favoriteScopes, &Favorites::favoritesChanged, this, &Scopes::favoritesChanged);
131 QObject::connect(m_dashSettings, &QGSettings::changed, this, &Scopes::dashSettingsChanged);
132 }
133132
134 m_overviewScope = OverviewScope::newInstance(this);133 m_overviewScope = OverviewScope::newInstance(this);
135134
@@ -427,57 +426,41 @@
427426
428void Scopes::processFavoriteScopes()427void Scopes::processFavoriteScopes()
429{428{
429 qDebug() << "Scopes::processFavoriteScopes()";
430
430 if (m_noFavorites) {431 if (m_noFavorites) {
431 return;432 return;
432 }433 }
433434
434 //435 //
435 // read the favoriteScopes array value from gsettings.
436 // process it and turn its values into scope ids.
437 // create new Scope objects or remove existing according to the list of favorities.436 // create new Scope objects or remove existing according to the list of favorities.
438 // notify about scopes model changes accordingly.437 // notify about scopes model changes accordingly.
439 if (m_dashSettings) {438 if (m_dashSettings) {
440 QStringList newFavorites;439 for (auto const& fv: m_favoriteScopes->getFavorites())
441 QMap<QString, int> favScopesLut;
442 for (auto const& fv: m_dashSettings->get(QStringLiteral("favoriteScopes")).toList())
443 {440 {
444 int pos = 0;441 // favorited scope not installed?
445 try442 if (m_cachedMetadata.find(fv) == m_cachedMetadata.end())
446 {443 {
447 auto const query = unity::scopes::CannedQuery::from_uri(fv.toString().toStdString());444 qDebug() << "Favorited scope" << fv << "is no longer available, un-favoriting";
448 const QString id = QString::fromStdString(query.scope_id());445 m_favoriteScopes->setFavorite(fv, false);
449446 }
450 if (m_cachedMetadata.find(id) != m_cachedMetadata.end())447 }
451 {448
452 newFavorites.push_back(id);449 // special-case clickscope; append it to favorites if it was uninstalled (and in consequence removed from favorites) - see LP: #1603186
453 pos = newFavorites.size() - 1;450 if (m_cachedMetadata.contains(CLICK_SCOPE_ID) && !m_favoriteScopes->hasScope(CLICK_SCOPE_ID)) {
454 favScopesLut[id] = pos;451 qDebug() << "Favoriting" << CLICK_SCOPE_ID;
455 }452 m_favoriteScopes->setFavorite(CLICK_SCOPE_ID, true);
456 else453 }
457 {454
458 // If a scope that was favorited no longer exists, unfavorite it in m_dashSettings455 QSet<QString> scopesInTheModel;
459 setFavorite(id, false);
460 }
461 }
462 catch (const InvalidArgumentException &e)
463 {
464 qWarning() << "Invalid canned query '" << fv.toString() << "'" << QString::fromStdString(e.what());
465 }
466 }
467
468 // this prevents further processing if we get called back when calling scope->setFavorite() below
469 if (m_favoriteScopes == newFavorites)
470 return;
471
472 m_favoriteScopes = newFavorites;
473
474 QSet<QString> oldScopes;
475 int row = 0;456 int row = 0;
476 // remove un-favorited scopes457 // remove un-favorited scopes
477 for (auto it = m_scopes.begin(); it != m_scopes.end();)458 for (auto it = m_scopes.begin(); it != m_scopes.end();)
478 {459 {
479 if (!favScopesLut.contains((*it)->id()))460 if (!m_favoriteScopes->hasScope((*it)->id()))
480 {461 {
462 qDebug() << "Scope" << (*it)->id() << "is no longer favorited, removing";
463
481 beginRemoveRows(QModelIndex(), row, row);464 beginRemoveRows(QModelIndex(), row, row);
482 Scope::Ptr toDelete = *it;465 Scope::Ptr toDelete = *it;
483 toDelete->setFavorite(false);466 toDelete->setFavorite(false);
@@ -490,7 +473,7 @@
490 }473 }
491 else474 else
492 {475 {
493 oldScopes.insert((*it)->id());476 scopesInTheModel.insert((*it)->id());
494 ++it;477 ++it;
495 ++row;478 ++row;
496 }479 }
@@ -498,41 +481,35 @@
498481
499 // add new favorites482 // add new favorites
500 row = 0;483 row = 0;
501 for (auto favIt = m_favoriteScopes.begin(); favIt != m_favoriteScopes.end(); )484 for (auto const& fv: m_favoriteScopes->getFavorites())
502 {485 {
503 auto const fav = *favIt;486 if (!scopesInTheModel.contains(fv))
504 if (!oldScopes.contains(fav))
505 {487 {
506 auto it = m_cachedMetadata.find(fav);488 auto it = m_cachedMetadata.find(fv);
507 if (it != m_cachedMetadata.end())489 if (it != m_cachedMetadata.end())
508 {490 {
509 Scope::Ptr scope = Scope::newInstance(this);491 qDebug() << "Scope" << fv << "is favorited, adding to scopes model";
492
493 Scope::Ptr scope = Scope::newInstance(this, true);
510 connect(scope.data(), SIGNAL(isActiveChanged()), this, SLOT(prepopulateNextScopes()));494 connect(scope.data(), SIGNAL(isActiveChanged()), this, SLOT(prepopulateNextScopes()));
511 scope->setScopeData(*(it.value()));495 scope->setScopeData(*(it.value()));
512 scope->setFavorite(true);
513 beginInsertRows(QModelIndex(), row, row);496 beginInsertRows(QModelIndex(), row, row);
514 m_scopes.insert(row, scope);497 m_scopes.insert(row, scope);
515 endInsertRows();498 endInsertRows();
516 }499 }
517 else
518 {
519 qWarning() << "No such scope:" << fav;
520 favIt = m_favoriteScopes.erase(favIt);
521 continue;
522 }
523 }500 }
524 ++row;501 ++row;
525 ++favIt;
526 }502 }
527503
528 // iterate over results, move rows if positions changes504 // iterate over results, move rows if positions changed
529 for (int i = 0; i<m_scopes.size(); )505 for (int i = 0; i<m_scopes.size(); )
530 {506 {
531 auto scope = m_scopes.at(i);507 auto scope = m_scopes.at(i);
532 const QString id = scope->id();508 const QString id = scope->id();
533 if (favScopesLut.contains(id)) {509 int pos = m_favoriteScopes->position(id);
534 int pos = favScopesLut[id];510 if (pos >= 0) {
535 if (pos != i) {511 if (pos != i) {
512 qDebug() << "Moving scope" << id << "to row" << pos << "to match position in favorites";
536 beginMoveRows(QModelIndex(), i, i, QModelIndex(), pos + (pos > i ? 1 : 0));513 beginMoveRows(QModelIndex(), i, i, QModelIndex(), pos + (pos > i ? 1 : 0));
537 m_scopes.move(i, pos);514 m_scopes.move(i, pos);
538 endMoveRows();515 endMoveRows();
@@ -544,17 +521,13 @@
544 }521 }
545}522}
546523
547void Scopes::dashSettingsChanged(QString const& key)524void Scopes::favoritesChanged()
548{525{
549 if (key != QLatin1String("favoriteScopes")) {
550 return;
551 }
552
553 processFavoriteScopes();526 processFavoriteScopes();
554527
555 if (m_overviewScope)528 if (m_overviewScope)
556 {529 {
557 m_overviewScope->updateFavorites(m_favoriteScopes);530 m_overviewScope->updateFavorites(m_favoriteScopes->getFavorites());
558 }531 }
559}532}
560533
@@ -675,7 +648,7 @@
675648
676QStringList Scopes::getFavoriteIds() const649QStringList Scopes::getFavoriteIds() const
677{650{
678 return m_favoriteScopes;651 return m_favoriteScopes->getFavorites();
679}652}
680653
681void Scopes::setFavorite(QString const& scopeId, bool value)654void Scopes::setFavorite(QString const& scopeId, bool value)
@@ -685,32 +658,39 @@
685 qWarning() << "Cannot unfavorite" << scopeId;658 qWarning() << "Cannot unfavorite" << scopeId;
686 return;659 return;
687 }660 }
688 if (m_dashSettings)661
662 int row = m_favoriteScopes->setFavorite(scopeId, value);
663 if (row >= 0)
689 {664 {
690 QStringList cannedQueries;665 if (value) {
691 bool changed = false;666 auto it = m_cachedMetadata.find(scopeId);
692667 if (it != m_cachedMetadata.end())
693 for (auto const& fav: m_favoriteScopes)668 {
694 {669 Scope::Ptr scope = Scope::newInstance(this, true);
695 if (value == false && fav == scopeId) {670 connect(scope.data(), SIGNAL(isActiveChanged()), this, SLOT(prepopulateNextScopes()));
696 changed = true;671 scope->setScopeData(*(it.value()));
697 continue; // skip it672 beginInsertRows(QModelIndex(), row, row);
698 }673 m_scopes.insert(row, scope);
699 // TODO: use CannedQuery::to_uri() when we really support them674 endInsertRows();
700 const QString query = "scope://" + fav;675 } else {
701 cannedQueries.push_back(query);676 qWarning() << "setFavorite: unknown scope" << scopeId;
702 }677 }
703678 } else {
704 if (value && !m_favoriteScopes.contains(scopeId)) {679 for (auto it = m_scopes.begin(); it != m_scopes.end(); it++)
705 const QString query = "scope://" + scopeId;680 {
706 cannedQueries.push_back(query);681 if ((*it)->id() == scopeId) {
707 changed = true;682 beginRemoveRows(QModelIndex(), row, row);
708 }683 Scope::Ptr toDelete = *it;
709684 toDelete->setFavorite(false);
710 if (changed) {685 // we need to delay actual deletion of Scope object so that shell can animate it
711 // update gsettings entry686 m_scopesToDelete.push_back(toDelete);
712 // note: this will trigger notification, so that new favorites are processed by processFavoriteScopes687 // if the timer is already active, we just wait a bit longer, which is no problem
713 m_dashSettings->set(QStringLiteral("favoriteScopes"), QVariant(cannedQueries));688 m_scopesToDeleteTimer.start();
689 it = m_scopes.erase(it);
690 endRemoveRows();
691 break;
692 }
693 }
714 }694 }
715 }695 }
716}696}
@@ -737,34 +717,12 @@
737717
738void Scopes::moveFavoriteTo(QString const& scopeId, int index)718void Scopes::moveFavoriteTo(QString const& scopeId, int index)
739{719{
740 if (m_dashSettings)720 int oldPos = m_favoriteScopes->position(scopeId);
741 {721 if (oldPos != index) {
742 QStringList cannedQueries;722 m_favoriteScopes->moveFavoriteTo(scopeId, index);
743 bool found = false;723 beginMoveRows(QModelIndex(), oldPos, oldPos, QModelIndex(), index + (index > oldPos ? 1 : 0));
744724 m_scopes.move(oldPos, index);
745 int i = 0;725 endMoveRows();
746 for (auto const& fav: m_favoriteScopes)
747 {
748 if (fav == scopeId) {
749 if (index == i)
750 return; // same position
751 found = true;
752 } else {
753 const QString query = "scope://" + fav;
754 cannedQueries.push_back(query);
755 }
756
757 ++i;
758 }
759
760 if (found) {
761 // insert scopeId at new position
762 const QString query = "scope://" + scopeId;
763 cannedQueries.insert(index, query);
764 // update gsettings entry
765 // note: this will trigger notification, so that new favorites are processed by processFavoriteScopes
766 m_dashSettings->set(QStringLiteral("favoriteScopes"), QVariant(cannedQueries));
767 }
768 }726 }
769}727}
770728
771729
=== modified file 'src/Unity/scopes.h'
--- src/Unity/scopes.h 2016-06-10 13:41:37 +0000
+++ src/Unity/scopes.h 2016-08-10 07:21:23 +0000
@@ -47,6 +47,7 @@
47class UbuntuLocationService;47class UbuntuLocationService;
48class LocationAccessHelper;48class LocationAccessHelper;
49class Scope;49class Scope;
50class Favorites;
50class OverviewScope;51class OverviewScope;
5152
52class Q_DECL_EXPORT Scopes : public unity::shell::scopes::ScopesInterface53class Q_DECL_EXPORT Scopes : public unity::shell::scopes::ScopesInterface
@@ -92,7 +93,7 @@
92 virtual QString readPartnerId();93 virtual QString readPartnerId();
9394
94private Q_SLOTS:95private Q_SLOTS:
95 void dashSettingsChanged(QString const &key);96 void favoritesChanged();
96 void processFavoriteScopes();97 void processFavoriteScopes();
97 void populateScopes();98 void populateScopes();
98 void discoveryFinished();99 void discoveryFinished();
@@ -117,7 +118,7 @@
117 QList<QSharedPointer<Scope>> m_scopes;118 QList<QSharedPointer<Scope>> m_scopes;
118 QList<QSharedPointer<Scope>> m_scopesToDelete;119 QList<QSharedPointer<Scope>> m_scopesToDelete;
119 bool m_noFavorites;120 bool m_noFavorites;
120 QStringList m_favoriteScopes;121 Favorites* m_favoriteScopes;
121 QGSettings* m_dashSettings;122 QGSettings* m_dashSettings;
122 QMap<QString, unity::scopes::ScopeMetadata::SPtr> m_cachedMetadata;123 QMap<QString, unity::scopes::ScopeMetadata::SPtr> m_cachedMetadata;
123 QSharedPointer<OverviewScope> m_overviewScope;124 QSharedPointer<OverviewScope> m_overviewScope;

Subscribers

People subscribed via source and target branches

to all changes: