on xenial help sign in
Merge from trunk
commit611329ad606793f502e43d44dbdda78d7f1299f9 authorMichael Terry <michael.terry@canonical.com> dateWed 4 Sep 2013, 13:08 (13 years ago) parentbf53eac58e3cb6
25 files changed+340−217
Components/EdgeDemo.qml+2−1 Components/EdgeDemoOverlay.qml+5 Dash/DashBar.qml+2−3 Greeter/Infographics.qml+1−2 Greeter/graphics/infographic_circle.png Greeter/graphics/infographic_circle_back.png Panel/Indicators/DefaultIndicatorWidget.qml+1−1 Panel/Indicators/DefaultIndicatorWidget2.qml+43−16 Panel/Indicators/NetworkIndicatorWidget.qml+1−1 build+9 debian/changelog+38 debian/control+1 main.cpp+3−2 plugins/Unity/Indicators/qml/MenuItemFactory.qml+1−16 plugins/Unity/Indicators/rootactionstate.cpp+44−14 plugins/Unity/Indicators/rootactionstate.h+9−6 plugins/Unity/Launcher/CMakeLists.txt+4 plugins/Unity/Launcher/backend/launcherbackend.cpp+159−99 plugins/Unity/Launcher/backend/launcherbackend.h+10−12 plugins/Unity/categories.cpp−3 plugins/Unity/categories.h+1−2 tests/mocks/Unity/fake_categories.cpp−3 tests/mocks/Unity/fake_categories.h+1−2 tests/plugins/Unity/Launcher/CMakeLists.txt+4 tests/plugins/Unity/Launcher/launcherbackendtest.cpp+1−34
Components/EdgeDemo.qml+2−1
@@ -218,8 +218,9 @@ Item {
218218 d.finalEdgeDemo = d.overlay.createObject(demo.underlay, {
219219 "edge": "none",
220220 "title": i18n.tr("Well done"),
221− "text": i18n.tr("You have now mastered the edge gestures and can start using the phone"),
221+ "text": i18n.tr("You have now mastered the edge gestures and can start using the phone<br><br>Tap anywhere to start"),
222222 "anchors.fill": demo.dash,
223+ "showSkip": false,
223224 });
224225 }
225226 if (d.finalEdgeDemo) {
Components/EdgeDemoOverlay.qml+5
@@ -43,6 +43,11 @@ Showable {
4343 */
4444 property alias skipText: skipLabel.text
4545
46+ /*
47+ * This is the visible status of the skip button.
48+ */
49+ property alias showSkip: skipLabel.visible
50+
4651 /*
4752 * Whether this demo is running currently.
4853 */
Dash/DashBar.qml+2−3
@@ -83,9 +83,8 @@ Item {
8383 }
8484
8585 delegate:
86− Item {
87− signal clicked()
88−
86+ // FIXME: Use Panel's integrated trigger() once that works again.
87+ MouseArea {
8988 width: itemSize
9089 height: dashBar.height
9190 anchors.top: parent.top
Greeter/Infographics.qml+1−2
@@ -286,9 +286,8 @@ Item {
286286 objectName: "backgroundCircle"
287287
288288 anchors.fill: parent
289− opacity: 0.9
290289
291− source: "graphics/infographic_circle.png"
290+ source: "graphics/infographic_circle_back.png"
292291 }
293292
294293 Timer {
Greeter/graphics/infographic_circle.pngdeleted

Binary file not shown.

Greeter/graphics/infographic_circle_back.pngnew file

Binary file not shown.

Panel/Indicators/DefaultIndicatorWidget.qml+1−1
@@ -24,7 +24,7 @@ import Unity.IndicatorsLegacy 0.1 as Indicators
2424Indicators.IndicatorWidget {
2525 id: indicatorWidget
2626
27− width: itemRow.width + units.gu(1)
27+ width: itemRow.width + units.gu(0.5)
2828
2929 property alias label: itemLabel.text
3030 property alias iconSource: itemImage.source
Panel/Indicators/DefaultIndicatorWidget2.qml+43−16
@@ -24,10 +24,11 @@ import Unity.Indicators 0.1 as Indicators
2424Indicators.IndicatorWidget {
2525 id: indicatorWidget
2626
27− width: itemRow.width + units.gu(1)
27+ width: itemRow.width + units.gu(0.5)
2828
29− property alias label: itemLabel.text
30− property alias iconSource: itemImage.source
29+ property alias leftLabel: itemLeftLabel.text
30+ property alias rightLabel: itemRightLabel.text
31+ property var icons: undefined
3132
3233 Row {
3334 id: itemRow
@@ -39,19 +40,43 @@ Indicators.IndicatorWidget {
3940 }
4041 spacing: units.gu(0.5)
4142
42− // FIXME : Should us Ubuntu.Icon . results in low res images
43− Image {
44− id: itemImage
45− objectName: "itemImage"
46− visible: source != ""
47− height: indicatorWidget.iconSize
48− width: indicatorWidget.iconSize
43+ Label {
44+ id: itemLeftLabel
45+ objectName: "leftLabel"
46+ color: Theme.palette.selected.backgroundText
47+ opacity: 0.8
48+ font.family: "Ubuntu"
49+ fontSize: "medium"
4950 anchors.verticalCenter: parent.verticalCenter
51+ visible: text != ""
52+ }
53+
54+ Row {
55+ width: childrenRect.width
56+ anchors {
57+ top: parent.top
58+ bottom: parent.bottom
59+ }
60+ spacing: units.gu(0.5)
61+
62+ Repeater {
63+ model: indicatorWidget.icons
64+
65+ Image {
66+ id: itemImage
67+ objectName: "itemImage"
68+ visible: source != ""
69+ source: modelData
70+ height: indicatorWidget.iconSize
71+ width: indicatorWidget.iconSize
72+ anchors.verticalCenter: parent.verticalCenter
73+ }
74+ }
5075 }
5176
5277 Label {
53− id: itemLabel
54− objectName: "itemLabel"
78+ id: itemRightLabel
79+ objectName: "rightLabel"
5580 color: Theme.palette.selected.backgroundText
5681 opacity: 0.8
5782 font.family: "Ubuntu"
@@ -63,14 +88,16 @@ Indicators.IndicatorWidget {
6388
6489 onActionStateChanged: {
6590 if (actionState == undefined) {
66− label = "";
67− iconSource = "";
91+ leftLabel = "";
92+ rightLabel = "";
93+ icons = undefined;
6894 enabled = false;
6995 return;
7096 }
7197
72− label = actionState.label;
73− iconSource = actionState.icon;
98+ leftLabel = actionState.leftLabel ? actionState.leftLabel : "";
99+ rightLabel = actionState.rightLabel ? actionState.rightLabel : "";
100+ icons = actionState.icons;
74101 enabled = actionState.visible;
75102 }
76103}
Panel/Indicators/NetworkIndicatorWidget.qml+1−1
@@ -24,7 +24,7 @@ import Unity.IndicatorsLegacy 0.1 as Indicators
2424Indicators.IndicatorWidget {
2525 id: indicatorWidget
2626
27− width: networkIcon.width + units.gu(1)
27+ width: networkIcon.width + units.gu(0.5)
2828
2929 property int signalStrength: 0
3030 property int connectionState: Indicators.NetworkConnection.Initial
build+9
@@ -57,6 +57,15 @@ mk_build_deps() {
5757 [ ! -f unity8-build-deps*deb -o $CODE_DIR/debian/control -nt unity8-build-deps*deb ] && mk-build-deps --install --root-cmd sudo $CODE_DIR/debian/control
5858}
5959
60+if [ -f "/usr/bin/ccache" ] ; then
61+ if [ "x$CC" = "x" ]; then
62+ export CC='ccache gcc'
63+ fi
64+ if [ "x$CXX" = "x" ] ; then
65+ export CXX='ccache g++'
66+ fi
67+fi
68+
6069if [ -f "/usr/bin/ninja" ] ; then
6170 GENERATOR="-G Ninja"
6271 # Ninja does not need -j, it parallelizes automatically.
debian/changelog+38
@@ -1,3 +1,41 @@
1+unity8 (7.81.3+13.10.20130904.1-0ubuntu1) saucy; urgency=low
2+
3+ [ Nicolas d'Offay ]
4+ * Switched infographic background at design's request.
5+
6+ [ Ubuntu daily release ]
7+ * Automatic snapshot from revision 287
8+
9+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 04 Sep 2013 07:34:57 +0000
10+
11+unity8 (7.81.3+13.10.20130904-0ubuntu1) saucy; urgency=low
12+
13+ [ mhall119 ]
14+ * Add a little bit of text to the last step of the tour telling the
15+ user how to end it and get to their phone.
16+
17+ [ Jussi Pakkanen ]
18+ * Use CCache if it is installed.
19+
20+ [ Nick Dedekind ]
21+ * Multiple icon/label support for indicators.
22+
23+ [ Albert Astals ]
24+ * Remove unneeded role.
25+
26+ [ Lars Uebernickel ]
27+ * Fall back to "ubuntu-mobile" icon theme if $UBUNTU_ICON_THEME is
28+ unset.
29+
30+ [ Michael Zanetti ]
31+ * Use MouseAreas in DashBar to enable clicking again.
32+ * load launcher default config from existing dconf key.
33+
34+ [ Ubuntu daily release ]
35+ * Automatic snapshot from revision 285
36+
37+ -- Ubuntu daily release <ps-jenkins@lists.canonical.com> Wed, 04 Sep 2013 03:02:57 +0000
38+
139unity8 (7.81.3+13.10.20130903.1-0ubuntu1) saucy; urgency=low
240
341 [ Michael Zanetti ]
debian/control+1
@@ -9,6 +9,7 @@ Build-Depends: cmake,
99 libgl1-mesa-dev[!armhf] | libgl-dev[!armhf],
1010 libgl1-mesa-dri,
1111 libgles2-mesa-dev[armhf],
12+ libgsettings-qt-dev,
1213 libhud-client2-dev,
1314 libjson-perl,
1415 libnih-dbus-dev,
main.cpp+3−2
@@ -65,9 +65,10 @@ void appendImportPaths(QQmlEngine *engine, const QStringList &paths)
6565
6666void resolveIconTheme() {
6767 const char *ubuntuIconTheme = getenv("UBUNTU_ICON_THEME");
68− if (ubuntuIconTheme != NULL) {
69− QIcon::setThemeName(ubuntuIconTheme);
68+ if (ubuntuIconTheme == NULL) {
69+ ubuntuIconTheme = "ubuntu-mobile";
7070 }
71+ QIcon::setThemeName(ubuntuIconTheme);
7172}
7273} // namespace {
7374
plugins/Unity/Indicators/qml/MenuItemFactory.qml+1−16
@@ -73,23 +73,8 @@ Item {
7373 'max-icon': 'icon'});
7474 }
7575
76− // FIXME: The interval should be [0.0 - 1.0]. Unfortunately, when
77− // reaching the boundaries (0.0 or 1.0), the value is converted
78− // to an integer when automatically wrapped in a variant when
79− // passed to QStateAction::updateState(…). The server chokes on
80− // those values, complaining that they’re not of the right type…
8176 onChangeState: {
82− if (value == Math.round(value)) {
83− if (value >= maximumValue) {
84− model.changeState(modelIndex, maximumValue - 0.000001);
85− } else if (value <= minimumValue) {
86− model.changeState(modelIndex, minimumValue + 0.000001);
87− } else {
88− model.changeState(modelIndex, value * 1.000001);
89− }
90− } else {
91− model.changeState(modelIndex, value);
92− }
77+ model.changeState(modelIndex, value);
9378 }
9479 }
9580 }
plugins/Unity/Indicators/rootactionstate.cpp+44−14
@@ -108,25 +108,32 @@ bool RootActionState::isValid() const
108108 return m_menu && m_menu->rowCount() > 0;
109109}
110110
111−QString RootActionState::label() const
111+QString RootActionState::leftLabel() const
112112{
113113 if (!isValid()) return QString();
114114
115− return m_cachedState.value("label", QVariant::fromValue(QString())).toString();
115+ return m_cachedState.value("pre-label", QVariant::fromValue(QString())).toString();
116116}
117117
118−QString RootActionState::icon() const
118+QString RootActionState::rightLabel() const
119119{
120120 if (!isValid()) return QString();
121121
122− return m_cachedState.value("icon", QVariant::fromValue(QString())).toString();
122+ return m_cachedState.value("label", QVariant::fromValue(QString())).toString();
123+}
124+
125+QStringList RootActionState::icons() const
126+{
127+ if (!isValid()) return QStringList();
128+
129+ return m_cachedState.value("icons", QVariant::fromValue(QStringList())).toStringList();
123130}
124131
125132QString RootActionState::accessibleName() const
126133{
127134 if (!isValid()) return QString();
128135
129− return m_cachedState.value("accessible-name", QVariant::fromValue(QString())).toString();
136+ return m_cachedState.value("accessible-desc", QVariant::fromValue(QString())).toString();
130137}
131138
132139bool RootActionState::isVisible() const
@@ -198,16 +205,39 @@ QVariant RootActionState::toQVariant(GVariant* state) const
198205 while (g_variant_iter_loop (&iter, "{sv}", &key, &vvalue))
199206 {
200207 QString str = QString::fromUtf8(key);
201− if (str == "icon") {
208+ if (str == "icon" && !qmap.contains("icons")) {
209+ QStringList icons;
210+
202211 // FIXME - should be sending a url.
203− GIcon *icon = g_icon_deserialize (vvalue);
204− if (icon) {
205− qmap.insert(str, iconUri(icon));
206− g_object_unref (icon);
212+ GIcon *gicon = g_icon_deserialize (vvalue);
213+ if (gicon) {
214+ icons << iconUri(gicon);
215+ g_object_unref (gicon);
207216 }
208− else {
209− qmap.insert(str, QVariant(""));
217+ qmap.insert("icons", icons);
218+
219+ } else if (str == "icons") {
220+
221+ QStringList icons;
222+
223+ if (g_variant_type_is_array(g_variant_get_type(vvalue))) {
224+
225+
226+ for (int i = 0, iMax = g_variant_n_children(vvalue); i < iMax; i++) {
227+ GVariant *child = g_variant_get_child_value(vvalue, i);
228+
229+ // FIXME - should be sending a url.
230+ GIcon *gicon = g_icon_deserialize (child);
231+ if (gicon) {
232+ icons << iconUri(gicon);
233+ g_object_unref (gicon);
234+ }
235+ g_variant_unref(child);
236+ }
210237 }
238+ // will overwrite icon.
239+ qmap.insert("icons", icons);
240+
211241 } else {
212242 qmap.insert(str, ActionStateParser::toQVariant(vvalue));
213243 }
@@ -230,12 +260,12 @@ QVariant RootActionState::toQVariant(GVariant* state) const
230260 &visible);
231261
232262 qmap["label"] = label ? QString::fromUtf8(label) : "";
233− qmap["accessible-name"] = accessible_name ? QString::fromUtf8(accessible_name) : "";
263+ qmap["accessible-desc"] = accessible_name ? QString::fromUtf8(accessible_name) : "";
234264 qmap["visible"] = visible;
235265
236266 gicon = g_icon_new_for_string (icon, NULL);
237267 if (gicon) {
238− qmap["icon"] = iconUri(gicon);
268+ qmap["icons"] = QStringList() << iconUri(gicon);
239269 g_object_unref (gicon);
240270 }
241271
plugins/Unity/Indicators/rootactionstate.h+9−6
@@ -32,8 +32,9 @@ class UNITYINDICATORS_EXPORT RootActionState : public ActionStateParser
3232 Q_PROPERTY(UnityMenuModel* menu READ menu WRITE setMenu NOTIFY menuChanged)
3333
3434 Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
35− Q_PROPERTY(QString label READ label NOTIFY labelChanged)
36− Q_PROPERTY(QString icon READ icon NOTIFY iconChanged)
35+ Q_PROPERTY(QString leftLabel READ leftLabel NOTIFY leftLabelChanged)
36+ Q_PROPERTY(QString rightLabel READ rightLabel NOTIFY rightLabelChanged)
37+ Q_PROPERTY(QStringList icons READ icons NOTIFY iconsChanged)
3738 Q_PROPERTY(QString accessibleName READ accessibleName NOTIFY accessibleNameChanged)
3839 Q_PROPERTY(bool visible READ isVisible NOTIFY visibleChanged)
3940public:
@@ -47,8 +48,9 @@ public:
4748 void setIndex(int index);
4849
4950 bool isValid() const;
50− QString label() const;
51− QString icon() const;
51+ QString leftLabel() const;
52+ QString rightLabel() const;
53+ QStringList icons() const;
5254 QString accessibleName() const;
5355 bool isVisible() const;
5456
@@ -62,8 +64,9 @@ Q_SIGNALS:
6264 void indexChanged();
6365
6466 void validChanged();
65− void labelChanged();
66− void iconChanged();
67+ void leftLabelChanged();
68+ void rightLabelChanged();
69+ void iconsChanged();
6770 void accessibleNameChanged();
6871 void visibleChanged();
6972
plugins/Unity/Launcher/CMakeLists.txt+4
@@ -1,11 +1,13 @@
11include(FindPkgConfig)
22pkg_check_modules(LAUNCHER_API REQUIRED unity-shell-launcher=2)
3+pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt)
34
45add_definitions(-DSM_BUSNAME=systemBus)
56
67include_directories(
78 ${CMAKE_CURRENT_SOURCE_DIR}
89 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
10+ ${GSETTINGS_QT_INCLUDE_DIRS}
911)
1012
1113set(QMLLAUNCHERPLUGIN_SRC
@@ -25,6 +27,8 @@ add_library(UnityLauncher-qml MODULE
2527 ${QMLLAUNCHERPLUGIN_SRC}
2628 )
2729
30+target_link_libraries(UnityLauncher-qml ${GSETTINGS_QT_LDFLAGS})
31+
2832qt5_use_modules(UnityLauncher-qml DBus Qml)
2933
3034# export the qmldir and qmltypes files
plugins/Unity/Launcher/backend/launcherbackend.cpp+159−99
@@ -24,6 +24,18 @@
2424#include <QDir>
2525#include <QDBusArgument>
2626#include <QFileInfo>
27+#include <QGSettings>
28+
29+class LauncherBackendItem
30+{
31+public:
32+ LauncherBackendItem(): pinned(false) {}
33+
34+ QString desktopFile;
35+ QString displayName;
36+ QString icon;
37+ bool pinned;
38+};
2739
2840LauncherBackend::LauncherBackend(bool useStorage, QObject *parent):
2941 QObject(parent),
@@ -32,95 +44,109 @@ LauncherBackend::LauncherBackend(bool useStorage, QObject *parent):
3244 if (useStorage) {
3345 m_accounts = new AccountsService(this);
3446 }
35− setUser(qgetenv("USER"));
47+ m_user = qgetenv("USER");
48+ syncFromAccounts();
3649}
3750
3851LauncherBackend::~LauncherBackend()
3952{
40− clearItems();
41−}
53+ m_storedApps.clear();
4254
43−void LauncherBackend::clearItems()
44−{
45− for (LauncherBackendItem &app: m_storedApps) {
46− delete app.settings;
55+ Q_FOREACH(LauncherBackendItem *item, m_itemCache) {
56+ delete item;
4757 }
48− m_storedApps.clear();
58+ m_itemCache.clear();
4959}
5060
5161QStringList LauncherBackend::storedApplications() const
5262{
53− auto files = QStringList();
54− for (const LauncherBackendItem &app: m_storedApps) {
55− files << app.settings->fileName();
56− }
57− return files;
63+ return m_storedApps;
5864}
5965
6066void LauncherBackend::setStoredApplications(const QStringList &appIds)
6167{
62− // Record all existing pinned apps, so we can notice them in new list
63− auto pinnedItems = QStringList();
64− for (LauncherBackendItem &app: m_storedApps) {
65− if (app.pinned) {
66− pinnedItems.append(app.settings->fileName());
68+ if (appIds.count() < m_storedApps.count()) {
69+ Q_FOREACH(const QString &appId, m_storedApps) {
70+ if (!appIds.contains(appId)) {
71+ delete m_itemCache.take(appId);
72+ }
6773 }
6874 }
69−
70− clearItems();
71−
72− for (const QString &appId: appIds) {
73− loadApp(makeAppDetails(appId, pinnedItems.contains(desktopFile(appId))));
74− }
75−
75+ m_storedApps = appIds;
7676 syncToAccounts();
7777}
7878
7979QString LauncherBackend::desktopFile(const QString &appId) const
8080{
81− QFileInfo fileInfo(QDir("/usr/share/applications"), appId);
82− return fileInfo.absoluteFilePath();
81+ LauncherBackendItem *item = m_itemCache.value(appId);
82+ if (item) {
83+ return item->desktopFile;
84+ }
85+
86+ return findDesktopFile(appId);
8387}
8488
8589QString LauncherBackend::displayName(const QString &appId) const
8690{
87− auto desktopFile = parseDesktopFile(appId);
88− auto displayName = desktopFile->value("Desktop Entry/Name").toString();
89− delete desktopFile;
90− return displayName;
91+ LauncherBackendItem *item = m_itemCache.value(appId);
92+ if (item) {
93+ return item->displayName;
94+ }
95+
96+ QString df = findDesktopFile(appId);
97+ if (!df.isEmpty()) {
98+ LauncherBackendItem *item = parseDesktopFile(df);
99+ m_itemCache.insert(appId, item);
100+ return item->displayName;
101+ }
102+
103+ return QString();
91104}
92105
93106QString LauncherBackend::icon(const QString &appId) const
94107{
95− auto desktopFile = parseDesktopFile(appId);
96− auto iconName = desktopFile->value("Desktop Entry/Icon").toString();
97− delete desktopFile;
98−
99− if (!iconName.isEmpty()) {
100− QFileInfo iconFileInfo(iconName);
101− if (iconFileInfo.isRelative()) {
102− iconName = "image://theme/" + iconName;
108+ QString iconName;
109+ LauncherBackendItem *item = m_itemCache.value(appId);
110+ if (item) {
111+ iconName = item->icon;
112+ } else {
113+ QString df = findDesktopFile(appId);
114+ if (!df.isEmpty()) {
115+ LauncherBackendItem *item = parseDesktopFile(df);
116+ m_itemCache.insert(appId, item);
117+ iconName = item->icon;
103118 }
104119 }
105120
106− return iconName;
121+ QFileInfo info(iconName);
122+ if (info.exists()) {
123+ return info.absoluteFilePath();
124+ }
125+ return "image://theme/" + iconName;
107126}
108127
109128bool LauncherBackend::isPinned(const QString &appId) const
110129{
111− auto index = findItem(appId);
112− if (index < 0) {
113− return false;
114− } else {
115− return m_storedApps[index].pinned;
130+ LauncherBackendItem *item = m_itemCache.value(appId);
131+ if (item) {
132+ return item->pinned;
116133 }
134+ return false;
117135}
118136
119137void LauncherBackend::setPinned(const QString &appId, bool pinned)
120138{
121− auto index = findItem(appId);
122− if (index >= 0 && !m_storedApps[index].pinned) {
123− m_storedApps[index].pinned = pinned;
139+ if (!m_storedApps.contains(appId)) {
140+ return;
141+ }
142+
143+ LauncherBackendItem *item = m_itemCache.value(appId);
144+ if (!item) {
145+ item = new LauncherBackendItem();
146+ m_itemCache.insert(appId, item);
147+ }
148+ if (item->pinned != pinned) {
149+ item->pinned = pinned;
124150 syncToAccounts();
125151 }
126152}
@@ -153,8 +179,10 @@ int LauncherBackend::count(const QString &appId) const
153179
154180void LauncherBackend::setUser(const QString &username)
155181{
156− m_user = username;
157− syncFromAccounts();
182+ if (qgetenv("USER") == "lightdm" && m_user != username) {
183+ m_user = username;
184+ syncFromAccounts();
185+ }
158186}
159187
160188void LauncherBackend::triggerQuickListAction(const QString &appId, const QString &quickListId)
@@ -169,75 +197,118 @@ void LauncherBackend::syncFromAccounts()
169197 QList<QVariantMap> apps;
170198 bool defaults = true;
171199
172− clearItems();
200+ m_storedApps.clear();
173201
174− if (m_user != "" && m_accounts != nullptr) {
175− auto variant = m_accounts->getUserProperty(m_user, "launcher-items");
202+ if (m_accounts && m_user.isEmpty()) {
203+ QVariant variant = m_accounts->getUserProperty(m_user, "launcher-items");
176204 apps = qdbus_cast<QList<QVariantMap>>(variant.value<QDBusArgument>());
177205 defaults = isDefaultsItem(apps);
178206 }
179207
180− // TODO: load default pinned ones from default config, instead of hardcoding here...
181− if (defaults) {
182− apps <<
183− makeAppDetails("dialer-app.desktop", true) <<
184− makeAppDetails("messaging-app.desktop", true) <<
185− makeAppDetails("address-book-app.desktop", true) <<
186− makeAppDetails("camera-app.desktop", true) <<
187− makeAppDetails("gallery-app.desktop", true) <<
188− makeAppDetails("facebook-webapp.desktop", true) <<
189− makeAppDetails("webbrowser-app.desktop", true) <<
190− makeAppDetails("twitter-webapp.desktop", true) <<
191− makeAppDetails("gmail-webapp.desktop", true) <<
192− makeAppDetails("ubuntu-weather-app.desktop", true) <<
193− makeAppDetails("notes-app.desktop", true) <<
194− makeAppDetails("calendar-app.desktop", true);
195− }
196−
197− for (const QVariant &app: apps) {
198− loadApp(app.toMap());
208+ if (m_accounts && defaults) { // Checking accounts as it'll be null when !useStorage
209+ QGSettings gSettings("com.canonical.Unity.Launcher", "/com/canonical/unity/launcher/");
210+ Q_FOREACH(const QString &entry, gSettings.get("favorites").toStringList()) {
211+ if (entry.startsWith("application://")) {
212+ QString appId = entry;
213+ appId.remove("application://");
214+ QString df = findDesktopFile(appId);
215+
216+ if (!df.isEmpty()) {
217+ m_storedApps << appId;
218+
219+ if (!m_itemCache.contains(appId)) {
220+ m_itemCache.insert(appId, parseDesktopFile(df));
221+ }
222+ m_itemCache.value(appId)->pinned = true;
223+ }
224+ }
225+ }
226+ } else {
227+ for (const QVariant &app: apps) {
228+ loadFromVariant(app.toMap());
229+ }
199230 }
200231}
201232
202233void LauncherBackend::syncToAccounts()
203234{
204− if (m_user != "" && m_accounts != nullptr) {
235+ if (m_accounts && !m_user.isEmpty()) {
205236 QList<QVariantMap> items;
206237
207− for (LauncherBackendItem &app: m_storedApps) {
208− items << makeAppDetails(app.settings->fileName(), app.pinned);
238+ Q_FOREACH(const QString &appId, m_storedApps) {
239+ items << itemToVariant(appId);
209240 }
210241
211242 m_accounts->setUserProperty(m_user, "launcher-items", QVariant::fromValue(items));
212243 }
213244}
214245
215−QSettings *LauncherBackend::parseDesktopFile(const QString &appId) const
246+QString LauncherBackend::findDesktopFile(const QString &appId) const
216247{
217− auto fullAppId = desktopFile(appId);
218− return new QSettings(fullAppId, QSettings::IniFormat);
248+ int dashPos = -1;
249+ QString helper = appId;
250+
251+ do {
252+ if (dashPos != -1) {
253+ helper = helper.replace(dashPos, 1, '/');
254+ }
255+
256+ QFileInfo fileInfo(QDir("/usr/share/applications"), helper);
257+ if (fileInfo.exists()) {
258+ return fileInfo.absoluteFilePath();
259+ }
260+
261+ dashPos = helper.indexOf("-");
262+ } while (dashPos != -1);
263+
264+ return QString();
219265}
220266
221−void LauncherBackend::loadApp(const QVariantMap &details)
267+LauncherBackendItem* LauncherBackend::parseDesktopFile(const QString &desktopFile) const
222268{
223− auto appId = details.value("id").toString();
224− auto isPinned = details.value("is-pinned").toBool();
269+ QSettings settings(desktopFile, QSettings::IniFormat);
270+
225271
226− if (appId.isEmpty()) {
272+ LauncherBackendItem* item = new LauncherBackendItem();
273+ item->desktopFile = desktopFile;
274+ item->displayName = settings.value("Desktop Entry/Name").toString();
275+ item->icon = settings.value("Desktop Entry/Icon").toString();
276+ item->pinned = false;
277+ return item;
278+}
279+
280+void LauncherBackend::loadFromVariant(const QVariantMap &details)
281+{
282+ if (!details.contains("id")) {
227283 return;
228284 }
285+ QString appId = details.value("id").toString();
286+
287+ LauncherBackendItem *item = m_itemCache.value(appId);
288+ if (item) {
289+ delete item;
290+ }
291+
292+ item = new LauncherBackendItem();
293+
294+ item->desktopFile = details.value("desktopFile").toString();
295+ item->displayName = details.value("name").toString();
296+ item->icon = details.value("icon").toString();
297+ item->pinned = details.value("is-pinned").toBool();
229298
230− LauncherBackendItem item;
231− item.settings = parseDesktopFile(appId);
232− item.pinned = isPinned;
233− m_storedApps.append(item);
299+ m_itemCache.insert(appId, item);
300+ m_storedApps.append(appId);
234301}
235302
236−QVariantMap LauncherBackend::makeAppDetails(const QString &appId, bool pinned) const
303+QVariantMap LauncherBackend::itemToVariant(const QString &appId) const
237304{
305+ LauncherBackendItem *item = m_itemCache.value(appId);
238306 QVariantMap details;
239307 details.insert("id", appId);
240− details.insert("is-pinned", pinned);
308+ details.insert("name", item->displayName);
309+ details.insert("icon", item->icon);
310+ details.insert("desktopFile", item->desktopFile);
311+ details.insert("is-pinned", item->pinned);
241312 return details;
242313}
243314
@@ -248,14 +319,3 @@ bool LauncherBackend::isDefaultsItem(const QList<QVariantMap> &apps) const
248319 // list of one item with the 'defaults' field set to true.
249320 return (apps.size() == 1 && apps[0].value("defaults").toBool());
250321}
251−
252−int LauncherBackend::findItem(const QString &appId) const
253−{
254− auto fullAppId = desktopFile(appId);
255− for (int i = 0; i < m_storedApps.size(); ++i) {
256− if (m_storedApps[i].settings->fileName() == fullAppId) {
257− return i;
258− }
259− }
260− return -1;
261−}
plugins/Unity/Launcher/backend/launcherbackend.h+10−12
@@ -31,6 +31,8 @@ class AccountsService;
3131 * @brief An interface that provides all the data needed by the launcher.
3232 */
3333
34+class LauncherBackendItem;
35+
3436class LauncherBackend : public QObject
3537{
3638 Q_OBJECT
@@ -141,23 +143,19 @@ Q_SIGNALS:
141143 void countChanged(const QString &appId, int count);
142144
143145private:
144− QSettings *parseDesktopFile(const QString &appId) const;
145− QVariantMap makeAppDetails(const QString &appId, bool pinned) const;
146− void loadApp(const QVariantMap &details);
147− int findItem(const QString &appId) const;
146+ QString findDesktopFile(const QString &appId) const;
147+ LauncherBackendItem* parseDesktopFile(const QString &desktopFile) const;
148+
149+ QVariantMap itemToVariant(const QString &appId) const;
150+ void loadFromVariant(const QVariantMap &details);
151+
148152 bool isDefaultsItem(const QList<QVariantMap> &apps) const;
149153 void syncFromAccounts();
150154 void syncToAccounts();
151− void clearItems();
152155
153− class LauncherBackendItem
154− {
155− public:
156− QSettings *settings;
157− bool pinned;
158− };
156+ QList<QString> m_storedApps;
157+ mutable QHash<QString, LauncherBackendItem*> m_itemCache;
159158
160− QList<LauncherBackendItem> m_storedApps;
161159 AccountsService *m_accounts;
162160 QString m_user;
163161};
plugins/Unity/categories.cpp−3
@@ -43,7 +43,6 @@ Categories::Categories(QObject* parent)
4343 m_roles[Categories::RoleHints] = "hints";
4444 m_roles[Categories::RoleResults] = "results";
4545 m_roles[Categories::RoleCount] = "count";
46− m_roles[Categories::RoleCategoryIndex] = "categoryIndex";
4746
4847 // TODO This should not be needed but accumulatting the count changes
4948 // makes the visualization more stable and also makes crashes on fast
@@ -222,8 +221,6 @@ Categories::data(const QModelIndex& index, int role) const
222221 return QVariant::fromValue(m_overriddenCategories[id]->rowCount());
223222 }
224223 return QVariant::fromValue(getResults(index.row())->rowCount());
225− case RoleCategoryIndex:
226− return QVariant::fromValue(index.row());
227224 default:
228225 return QVariant();
229226 }
plugins/Unity/categories.h+1−2
@@ -50,8 +50,7 @@ public:
5050 RoleProgressSource,
5151 RoleHints,
5252 RoleResults,
53− RoleCount,
54− RoleCategoryIndex
53+ RoleCount
5554 };
5655
5756 Q_INVOKABLE void overrideResults(const QString& categoryId, QAbstractItemModel* model);
tests/mocks/Unity/fake_categories.cpp−3
@@ -36,7 +36,6 @@ Categories::Categories(QObject* parent)
3636 m_roles[Categories::RoleHints] = "hints";
3737 m_roles[Categories::RoleResults] = "results";
3838 m_roles[Categories::RoleCount] = "count";
39− m_roles[Categories::RoleCategoryIndex] = "categoryIndex";
4039
4140 // TODO This should not be needed but accumulatting the count changes
4241 // makes the visualization more stable and also makes crashes on fast
@@ -173,8 +172,6 @@ Categories::data(const QModelIndex& index, int role) const
173172 return QVariant::fromValue(getFilter(index.row()));
174173 case RoleCount:
175174 return QVariant::fromValue(getFilter(index.row())->rowCount());
176− case RoleCategoryIndex:
177− return QVariant::fromValue(index.row());
178175 default:
179176 return QVariant();
180177 }
tests/mocks/Unity/fake_categories.h+1−2
@@ -41,8 +41,7 @@ public:
4141 RoleContentType,
4242 RoleHints,
4343 RoleResults,
44− RoleCount,
45− RoleCategoryIndex
44+ RoleCount
4645 };
4746
4847 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
tests/plugins/Unity/Launcher/CMakeLists.txt+4
@@ -1,8 +1,11 @@
1+pkg_check_modules(GSETTINGS_QT REQUIRED gsettings-qt)
2+
13include_directories(
24 ${CMAKE_CURRENT_BINARY_DIR}
35 ${CMAKE_SOURCE_DIR}/plugins/AccountsService
46 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher
57 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/backend
8+ ${GSETTINGS_QT_INCLUDE_DIRS}
69 )
710
811add_definitions(-DSM_BUSNAME=sessionBus)
@@ -19,4 +22,5 @@ add_executable(launcherbackendtestExec
1922 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/backend/launcherbackend.cpp
2023 ${CMAKE_SOURCE_DIR}/plugins/Unity/Launcher/common/quicklistentry.cpp
2124 )
25+target_link_libraries(launcherbackendtestExec ${GSETTINGS_QT_LDFLAGS})
2226qt5_use_modules(launcherbackendtestExec Test Core DBus)
tests/plugins/Unity/Launcher/launcherbackendtest.cpp+1−34
@@ -32,46 +32,13 @@ private Q_SLOTS:
3232 LauncherBackend backend(false);
3333
3434 backend.setStoredApplications(QStringList() << "relative.path" << "/full/path");
35− QCOMPARE(backend.storedApplications(), QStringList() << "/usr/share/applications/relative.path" << "/full/path");
36−
37− QCOMPARE(backend.desktopFile("one.desktop"), QString("/usr/share/applications/one.desktop"));
38− QCOMPARE(backend.desktopFile("two"), QString("/usr/share/applications/two"));
39− QCOMPARE(backend.desktopFile("/full"), QString("/full"));
40−
41− QCOMPARE(backend.desktopFile("/usr/share/applications/one.desktop"), QString("/usr/share/applications/one.desktop"));
42− }
43−
44− void testDesktopReading()
45− {
46− LauncherBackend backend(false);
47−
48− QCOMPARE(backend.displayName(SRCDIR "/rel-icon.desktop"), QString("Relative Icon"));
49− QCOMPARE(backend.icon(SRCDIR "/rel-icon.desktop"), QString("image://theme/rel-icon"));
50−
51− QCOMPARE(backend.displayName(SRCDIR "/abs-icon.desktop"), QString("Absolute Icon"));
52− QCOMPARE(backend.icon(SRCDIR "/abs-icon.desktop"), QString("/path/to/icon.png"));
53−
54− QCOMPARE(backend.displayName(SRCDIR "/no-icon.desktop"), QString("No Icon"));
55− QCOMPARE(backend.icon(SRCDIR "/no-icon.desktop"), QString(""));
56−
57− QCOMPARE(backend.displayName(SRCDIR "/no-name.desktop"), QString(""));
58− QCOMPARE(backend.icon(SRCDIR "/no-name.desktop"), QString("image://theme/no-name"));
59−
60− QCOMPARE(backend.displayName(SRCDIR "/no-exist.desktop"), QString(""));
61− QCOMPARE(backend.icon(SRCDIR "/no-exist.desktop"), QString(""));
35+ QCOMPARE(backend.storedApplications(), QStringList() << "relative.path" << "/full/path");
6236 }
6337
6438 void testPinning()
6539 {
6640 LauncherBackend backend(false);
6741
68− // Confirm that default entries are all pinned
69− auto defaultApps = backend.storedApplications();
70− QVERIFY(defaultApps.size() > 0);
71− for (auto app: defaultApps) {
72− QCOMPARE(backend.isPinned(app), true);
73− }
74−
7542 backend.setStoredApplications(QStringList() << "one" << "two");
7643 QCOMPARE(backend.isPinned("one"), false);
7744 QCOMPARE(backend.isPinned("two"), false);