on xenial help sign in
Indicators convergence: use the "phone" profile everywhere Fixes: #1520492

Approved by: Albert Astals Cid

commit67aa7985e8783fad80499f57a009b56c6fb9a98c authorLukáš Tinkl <lukas.tinkl@canonical.com> dateTue 8 Dec 2015, 15:37 (11 years ago) parentef9a87a855329d
16 files changed+75−39
plugins/Unity/Indicators/CMakeLists.txt+2−1 plugins/Unity/Indicators/actionrootstate.h+1−1 plugins/Unity/Indicators/indicator.cpp+2−3 plugins/Unity/Indicators/indicator.h+1−1 plugins/Unity/Indicators/indicatorsmanager.cpp+30−14 plugins/Unity/Indicators/indicatorsmanager.h+4−1 plugins/Unity/Indicators/indicatorsmodel.cpp+5−5 plugins/Unity/Indicators/indicatorsmodel.h+1−1 plugins/Unity/Indicators/menucontentactivator.h+1−1 plugins/Unity/Indicators/modelprinter.h+1−1 plugins/Unity/Platform/CMakeLists.txt+2 plugins/Unity/Platform/platform.cpp+13−4 plugins/Unity/Platform/platform.h+7−1 qml/Components/VolumeControl.qml+2−2 qml/Shell.qml+2−2 tests/plugins/Unity/Indicators/CMakeLists.txt+1−1
plugins/Unity/Indicators/CMakeLists.txt+2−1
@@ -29,6 +29,7 @@ set(IndicatorsQML_SOURCES
2929 sharedunitymenumodel.cpp
3030 unitymenumodelcache.cpp
3131 unitymenumodelstack.cpp
32+ ${CMAKE_SOURCE_DIR}/plugins/Unity/Platform/platform.cpp
3233)
3334add_definitions(-DUNITYINDICATORS_LIBRARY)
3435
@@ -42,6 +43,6 @@ target_link_libraries(IndicatorsQml
4243 ${QMENUMODEL_LDFLAGS}
4344)
4445
45−qt5_use_modules(IndicatorsQml Core Qml Quick)
46+qt5_use_modules(IndicatorsQml Core Qml Quick DBus)
4647
4748add_unity8_plugin(Unity.Indicators 0.1 Unity/Indicators TARGETS IndicatorsQml)
plugins/Unity/Indicators/actionrootstate.h+1−1
@@ -30,7 +30,7 @@ class UNITYINDICATORS_EXPORT ActionRootState : public RootStateObject
3030 Q_PROPERTY(QString actionName READ actionName WRITE setActionName NOTIFY actionNameChanged)
3131
3232public:
33− ActionRootState(QObject *parent = 0);
33+ ActionRootState(QObject *parent = nullptr);
3434
3535 QDBusActionGroup *actionGroup() const;
3636 void setActionGroup(QDBusActionGroup *actionGroup);
plugins/Unity/Indicators/indicator.cpp+2−3
@@ -44,10 +44,9 @@ void Indicator::init(const QString& busName, const QSettings& settings)
4444
4545 setId(settings.value(QStringLiteral("Indicator Service/Name")).toString());
4646
47− QString actionObjectPath = settings.value(QStringLiteral("Indicator Service/ObjectPath")).toString();
47+ const QString actionObjectPath = settings.value(QStringLiteral("Indicator Service/ObjectPath")).toString();
4848
4949 QVariantMap properties;
50− properties.clear();
5150 properties.insert(QStringLiteral("busType"), 1);
5251 properties.insert(QStringLiteral("busName"), busName);
5352 properties.insert(QStringLiteral("actionsObjectPath"), actionObjectPath);
@@ -87,7 +86,7 @@ void Indicator::setProfile(const QString& profile)
8786 pos = m_settings.value(QStringLiteral("Indicator Service/Position"), QVariant::fromValue(0));
8887 setPosition(pos.toInt());
8988
90− QString menuObjectPath = m_settings.value(profile + "/ObjectPath").toString();
89+ const QString menuObjectPath = m_settings.value(profile + "/ObjectPath").toString();
9190 QVariantMap map = m_properties.toMap();
9291 map.insert(QStringLiteral("menuObjectPath"), menuObjectPath);
9392 setIndicatorProperties(map);
plugins/Unity/Indicators/indicator.h+1−1
@@ -32,7 +32,7 @@ class UNITYINDICATORS_EXPORT Indicator : public QObject
3232public:
3333 typedef QSharedPointer<Indicator> Ptr;
3434
35− Indicator(QObject *parent = 0);
35+ Indicator(QObject *parent = nullptr);
3636 virtual ~Indicator();
3737
3838 void init(const QString& busName, const QSettings& settings);
plugins/Unity/Indicators/indicatorsmanager.cpp+30−14
@@ -51,20 +51,19 @@ IndicatorsManager::IndicatorsManager(QObject* parent)
5151IndicatorsManager::~IndicatorsManager()
5252{
5353 unload();
54−
5554}
5655
5756void IndicatorsManager::load()
5857{
5958 unload();
6059
61− QStringList xdgLocations = shellDataDirs();//QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
60+ const QStringList xdgLocations = shellDataDirs();
6261
6362 m_fsWatcher.reset(new QFileSystemWatcher(this));
6463
6564 Q_FOREACH(const QString& xdgLocation, xdgLocations)
6665 {
67− QString indicator_path = QDir::cleanPath(xdgLocation + "/unity/indicators");
66+ const QString indicator_path = QDir::cleanPath(xdgLocation + "/unity/indicators");
6867 QDir indicator_dir(indicator_path);
6968 if (indicator_dir.exists())
7069 {
@@ -103,7 +102,7 @@ void IndicatorsManager::loadDir(const QDir& dir)
103102{
104103 startVerify(dir.canonicalPath());
105104
106− QFileInfoList indicator_files = dir.entryInfoList(QStringList(), QDir::Files|QDir::NoDotAndDotDot);
105+ const QFileInfoList indicator_files = dir.entryInfoList(QStringList(), QDir::Files|QDir::NoDotAndDotDot);
107106 Q_FOREACH(const QFileInfo& indicator_file, indicator_files)
108107 {
109108 loadFile(indicator_file);
@@ -115,26 +114,30 @@ void IndicatorsManager::loadDir(const QDir& dir)
115114void IndicatorsManager::loadFile(const QFileInfo& file_info)
116115{
117116 QSettings indicator_settings(file_info.absoluteFilePath(), QSettings::IniFormat, this);
118− QString name = indicator_settings.value(QStringLiteral("Indicator Service/Name")).toString();
117+ const QString name = indicator_settings.value(QStringLiteral("Indicator Service/Name")).toString();
118+
119+ if (m_platform.isPC() && name == "indicator-keyboard") {
120+ return; // convergence: skip this indicator until it works in Mir
121+ }
119122
120− auto iter = m_indicatorsData.find(name);
121− if (iter != m_indicatorsData.end())
123+ auto iter = m_indicatorsData.constFind(name);
124+ if (iter != m_indicatorsData.constEnd())
122125 {
123− QString newFileInfoDir = QDir::cleanPath(file_info.canonicalPath());
126+ const QString newFileInfoDir = QDir::cleanPath(file_info.canonicalPath());
124127 IndicatorData* currentData = (*iter);
125128 currentData->m_verified = true;
126129
127130 int file_info_location = -1;
128131 int current_data_location = -1;
129132
130− QString currentDataDir = QDir::cleanPath(currentData->m_fileInfo.canonicalPath());
133+ const QString currentDataDir = QDir::cleanPath(currentData->m_fileInfo.canonicalPath());
131134
132135 // if we've already got this indicator, we need to make sure we're not overwriting data which is
133136 // from a lower priority standard path
134137 QStringList xdgLocations = shellDataDirs();
135138 for (int i = 0; i < xdgLocations.size(); i++)
136139 {
137− QString indicatorDir = QDir::cleanPath(xdgLocations[i] + "/unity/indicators");
140+ const QString indicatorDir = QDir::cleanPath(xdgLocations[i] + "/unity/indicators");
138141
139142 if (newFileInfoDir == indicatorDir)
140143 {
@@ -194,7 +197,7 @@ void IndicatorsManager::unloadFile(const QFileInfo& file)
194197 {
195198 if (!data->m_verified)
196199 {
197− QString name = data->m_name;
200+ const QString name = data->m_name;
198201 Q_EMIT indicatorAboutToBeUnloaded(name);
199202
200203 delete data;
@@ -253,7 +256,7 @@ void IndicatorsManager::endVerify(const QString& path)
253256 {
254257 if (!data->m_verified)
255258 {
256− QString name = data->m_name;
259+ const QString name = data->m_name;
257260 Q_EMIT indicatorAboutToBeUnloaded(name);
258261
259262 delete data;
@@ -271,7 +274,7 @@ Indicator::Ptr IndicatorsManager::indicator(const QString& indicator_name)
271274 return Indicator::Ptr();
272275 }
273276
274− IndicatorData *data = m_indicatorsData[indicator_name];
277+ IndicatorData *data = m_indicatorsData.value(indicator_name);
275278 if (data->m_indicator)
276279 {
277280 return data->m_indicator;
@@ -281,7 +284,20 @@ Indicator::Ptr IndicatorsManager::indicator(const QString& indicator_name)
281284 data->m_indicator = new_indicator;
282285 QSettings settings(data->m_fileInfo.absoluteFilePath(), QSettings::IniFormat, this);
283286 new_indicator->init(data->m_fileInfo.fileName(), settings);
284− new_indicator->setProfile(m_profile);
287+
288+ // convergence:
289+ // 1) enable session indicator conditionally, typically when running in a multisession/multiuser environment
290+ // 2) on a PC, switch the battery/power indicator to desktop mode,
291+ // can't control brightness for now and phone-on-desktop broken (FIXME)
292+ //
293+ // The rest of the indicators respect their default profile (which is "phone", even on desktop PCs)
294+ if ((new_indicator->identifier() == QStringLiteral("indicator-session") && m_platform.isMultiSession())
295+ || (new_indicator->identifier() == QStringLiteral("indicator-power") && m_platform.isPC())) {
296+ new_indicator->setProfile("desktop");
297+ } else {
298+ new_indicator->setProfile(m_profile);
299+ }
300+
285301 QObject::connect(this, &IndicatorsManager::profileChanged, new_indicator.data(), &Indicator::setProfile);
286302 return new_indicator;
287303}
plugins/Unity/Indicators/indicatorsmanager.h+4−1
@@ -21,6 +21,7 @@
2121
2222#include "indicator.h"
2323#include "unityindicatorsglobal.h"
24+#include "../Platform/platform.h"
2425
2526#include <QObject>
2627#include <QFileSystemWatcher>
@@ -34,7 +35,7 @@ class UNITYINDICATORS_EXPORT IndicatorsManager : public QObject
3435 Q_PROPERTY(bool loaded READ isLoaded NOTIFY loadedChanged)
3536 Q_PROPERTY(QString profile READ profile WRITE setProfile NOTIFY profileChanged)
3637public:
37− explicit IndicatorsManager(QObject* parent = 0);
38+ explicit IndicatorsManager(QObject* parent = nullptr);
3839 ~IndicatorsManager();
3940
4041 Q_INVOKABLE void load();
@@ -75,6 +76,8 @@ private:
7576 QSharedPointer<QFileSystemWatcher> m_fsWatcher;
7677 bool m_loaded;
7778 QString m_profile;
79+
80+ Platform m_platform;
7881};
7982
8083#endif // INDICATORS_MANAGER_H
plugins/Unity/Indicators/indicatorsmodel.cpp+5−5
@@ -236,7 +236,7 @@ int IndicatorsModel::columnCount(const QModelIndex &) const
236236 return 1;
237237}
238238
239−Q_INVOKABLE QVariant IndicatorsModel::data(int row, int role) const
239+QVariant IndicatorsModel::data(int row, int role) const
240240{
241241 return data(index(row, 0), role);
242242}
@@ -247,26 +247,26 @@ QVariant IndicatorsModel::data(const QModelIndex &index, int role) const
247247 if (!index.isValid() || index.row() >= m_indicators.size())
248248 return QVariant();
249249
250− Indicator::Ptr indicator = m_indicators[index.row()];
250+ Indicator::Ptr indicator = m_indicators.at(index.row());
251251
252252 switch (role)
253253 {
254254 case IndicatorsModelRole::Identifier:
255255 if (indicator)
256256 {
257− return QVariant(indicator->identifier());
257+ return indicator->identifier();
258258 }
259259 break;
260260 case IndicatorsModelRole::Position:
261261 if (indicator)
262262 {
263− return QVariant(indicator->position());
263+ return indicator->position();
264264 }
265265 break;
266266 case IndicatorsModelRole::IndicatorProperties:
267267 if (indicator)
268268 {
269− return QVariant(indicator->indicatorProperties());
269+ return indicator->indicatorProperties();
270270 }
271271 break;
272272 default:
plugins/Unity/Indicators/indicatorsmodel.h+1−1
@@ -38,7 +38,7 @@ class UNITYINDICATORS_EXPORT IndicatorsModel : public QAbstractListModel
3838
3939public:
4040
41− IndicatorsModel(QObject *parent=0);
41+ IndicatorsModel(QObject *parent=nullptr);
4242 ~IndicatorsModel();
4343
4444 Q_INVOKABLE void load();
plugins/Unity/Indicators/menucontentactivator.h+1−1
@@ -34,7 +34,7 @@ public:
3434 AbstractTimer(QObject *parent) : QObject(parent), m_isRunning(false) {}
3535 virtual int interval() const = 0;
3636 virtual void setInterval(int msecs) = 0;
37− virtual void start() { m_isRunning = true; };
37+ virtual void start() { m_isRunning = true; }
3838 virtual void stop() { m_isRunning = false; }
3939 bool isRunning() const { return m_isRunning; }
4040Q_SIGNALS:
plugins/Unity/Indicators/modelprinter.h+1−1
@@ -32,7 +32,7 @@ class ModelPrinter : public QObject
3232 Q_PROPERTY(UnityMenuModel* model READ sourceModel WRITE setSourceModel NOTIFY modelChanged)
3333 Q_PROPERTY(QString text READ text NOTIFY textChanged)
3434public:
35− ModelPrinter(QObject* parent=0);
35+ ModelPrinter(QObject* parent=nullptr);
3636
3737 void setSourceModel(UnityMenuModel* sourceModel);
3838 UnityMenuModel* sourceModel() const;
plugins/Unity/Platform/CMakeLists.txt+2
@@ -1,3 +1,5 @@
1+find_package(Qt5DBus REQUIRED)
2+
13set(platformplugin_SRCS
24 platform.cpp
35 plugin.cpp)
plugins/Unity/Platform/platform.cpp+13−4
@@ -20,16 +20,20 @@
2020
2121Platform::Platform(QObject *parent)
2222 : QObject(parent)
23− , m_iface(QStringLiteral("org.freedesktop.hostname1"), QStringLiteral("/org/freedesktop/hostname1"), QStringLiteral("org.freedesktop.hostname1"),
24− QDBusConnection::systemBus(), this)
2523{
2624 QMetaObject::invokeMethod(this, "init");
2725}
2826
2927void Platform::init()
3028{
31− m_chassis = m_iface.property("Chassis").toString();
32− m_isPC = (m_chassis == QLatin1String("desktop") || m_chassis == QLatin1String("laptop") || m_chassis == QLatin1String("server"));
29+ QDBusInterface iface("org.freedesktop.hostname1", "/org/freedesktop/hostname1", "org.freedesktop.hostname1",
30+ QDBusConnection::systemBus(), this);
31+ QDBusInterface seatIface("org.freedesktop.login1", "/org/freedesktop/login1/seat/self", "org.freedesktop.login1.Seat",
32+ QDBusConnection::systemBus(), this);
33+
34+ m_chassis = iface.property("Chassis").toString();
35+ m_isPC = (m_chassis == "desktop" || m_chassis == "laptop" || m_chassis == "server");
36+ m_isMultiSession = seatIface.property("CanMultiSession").toBool() && seatIface.property("CanGraphical").toBool();
3337}
3438
3539QString Platform::chassis() const
@@ -41,3 +45,8 @@ bool Platform::isPC() const
4145{
4246 return m_isPC;
4347}
48+
49+bool Platform::isMultiSession() const
50+{
51+ return m_isMultiSession;
52+}
plugins/Unity/Platform/platform.h+7−1
@@ -38,6 +38,10 @@ class Platform: public QObject
3838 * Whether the machine is an ordinary PC (desktop, laptop or server)
3939 */
4040 Q_PROPERTY(bool isPC READ isPC CONSTANT)
41+ /**
42+ * Whether the system is capable of running multiple (graphical) sessions
43+ */
44+ Q_PROPERTY(bool isMultiSession READ isMultiSession CONSTANT)
4145
4246public:
4347 Platform(QObject *parent = nullptr);
@@ -46,13 +50,15 @@ public:
4650 QString chassis() const;
4751 bool isPC() const;
4852
53+ bool isMultiSession() const;
54+
4955private Q_SLOTS:
5056 void init();
5157
5258private:
53− QDBusInterface m_iface;
5459 QString m_chassis;
5560 bool m_isPC;
61+ bool m_isMultiSession;
5662};
5763
5864#endif // PLATFORM_H
qml/Components/VolumeControl.qml+2−2
@@ -36,7 +36,7 @@ Item {
3636 GlobalShortcut {
3737 id: muteShortcut
3838 shortcut: Qt.Key_VolumeMute
39− Keys.onPressed: toggleMute()
39+ onTriggered: toggleMute()
4040 }
4141
4242 QMenuModel.QDBusActionGroup {
@@ -46,7 +46,7 @@ Item {
4646 objectPath: "/com/canonical/indicator/sound"
4747
4848 property variant actionObject: action("volume")
49− property variant muteActionObject: action("mute")
49+ property variant muteActionObject: indicators.indicatorsModel.profile === "desktop" ? action("mute") : action("silent-mode")
5050 property variant indicatorsAction: action("indicator-shown")
5151 }
5252
qml/Shell.qml+2−2
@@ -516,7 +516,7 @@ Item {
516516
517517 indicatorsModel: Indicators.IndicatorsModel {
518518 // tablet and phone both use the same profile
519− profile: shell.usageScenario === "desktop" ? "desktop" : "phone"
519+ profile: "phone"
520520 Component.onCompleted: load();
521521 }
522522 }
@@ -525,7 +525,7 @@ Item {
525525 greeterShown: greeter.shown
526526 }
527527
528− property bool topmostApplicationIsFullscreen:
528+ readonly property bool topmostApplicationIsFullscreen:
529529 ApplicationManager.focusedApplicationId &&
530530 ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).fullscreen
531531
tests/plugins/Unity/Indicators/CMakeLists.txt+1−1
@@ -21,7 +21,7 @@ macro(indicator_test TEST)
2121 ${TEST}Test.cpp
2222 ${test_ADDITIONAL_CPPS}
2323 )
24− qt5_use_modules(${TEST}Exec Test Core Qml)
24+ qt5_use_modules(${TEST}Exec Test Core Qml DBus)
2525 target_link_libraries(${TEST}Exec
2626 ${test_ADDITIONAL_LIBS}
2727 ${GLIB_LIBRARIES}