Don't show the OrientationSensor if it's not supported
Test Plan: I don't get the OrientationSensor SNI on my laptop, which is fine, because it was useless. Reviewers: #kwin, #plasma, zzag Reviewed By: #kwin, #plasma, zzag Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D19955
This commit is contained in:
parent
4020056532
commit
75c0c415cc
2 changed files with 28 additions and 27 deletions
|
@ -66,20 +66,44 @@ OrientationSensor::OrientationSensor(QObject *parent)
|
|||
connect(m_sensor, &QOrientationSensor::activeChanged, this, &OrientationSensor::refresh);
|
||||
}
|
||||
|
||||
void OrientationSensor::activate()
|
||||
{
|
||||
m_userEnabled = !m_userEnabled;
|
||||
startStopSensor();
|
||||
emit userEnabledChanged(m_userEnabled);
|
||||
}
|
||||
|
||||
void OrientationSensor::refresh()
|
||||
{
|
||||
if (!m_sni) {
|
||||
if (m_orientation == Orientation::Undefined) {
|
||||
delete m_sni;
|
||||
m_sni = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_sni) {
|
||||
m_sni = new KStatusNotifierItem(QStringLiteral("kwin-automatic-rotation"), this);
|
||||
m_sni->setStandardActionsEnabled(false);
|
||||
m_sni->setCategory(KStatusNotifierItem::Hardware);
|
||||
m_sni->setStatus(KStatusNotifierItem::Passive);
|
||||
// TODO: proper icon with state
|
||||
m_sni->setIconByName(QStringLiteral("preferences-desktop-display"));
|
||||
// we start disabled, it gets updated when the sensor becomes active
|
||||
|
||||
connect(m_sni, &KStatusNotifierItem::activateRequested, this, &OrientationSensor::activate);
|
||||
}
|
||||
|
||||
if (m_sensor->isActive()) {
|
||||
m_sni->setTitle(i18n("Allow Rotation"));
|
||||
m_sni->setToolTipTitle(i18n("Automatic screen rotation is enabled"));
|
||||
} else {
|
||||
QString text;
|
||||
switch(m_orientation) {
|
||||
case Orientation::Undefined:
|
||||
Q_UNREACHABLE(); //we don't want an sni if it's undefined
|
||||
break;
|
||||
case Orientation::FaceUp:
|
||||
case Orientation::FaceDown:
|
||||
case Orientation::Undefined:
|
||||
text = i18n("Undefined");
|
||||
break;
|
||||
case Orientation::TopUp:
|
||||
|
@ -106,7 +130,7 @@ void OrientationSensor::setEnabled(bool enabled)
|
|||
m_enabled = enabled;
|
||||
if (m_enabled) {
|
||||
loadConfig();
|
||||
setupStatusNotifier();
|
||||
refresh();
|
||||
m_adaptor = new OrientationSensorAdaptor(this);
|
||||
} else {
|
||||
delete m_sni;
|
||||
|
@ -125,29 +149,6 @@ void OrientationSensor::loadConfig()
|
|||
m_userEnabled = m_config->group("OrientationSensor").readEntry("Enabled", true);
|
||||
}
|
||||
|
||||
void OrientationSensor::setupStatusNotifier()
|
||||
{
|
||||
if (m_sni) {
|
||||
return;
|
||||
}
|
||||
m_sni = new KStatusNotifierItem(QStringLiteral("kwin-automatic-rotation"), this);
|
||||
m_sni->setStandardActionsEnabled(false);
|
||||
m_sni->setCategory(KStatusNotifierItem::Hardware);
|
||||
m_sni->setStatus(KStatusNotifierItem::Passive);
|
||||
// TODO: proper icon with state
|
||||
m_sni->setIconByName(QStringLiteral("preferences-desktop-display"));
|
||||
// we start disabled, it gets updated when the sensor becomes active
|
||||
|
||||
refresh();
|
||||
connect(m_sni, &KStatusNotifierItem::activateRequested, this,
|
||||
[this] {
|
||||
m_userEnabled = !m_userEnabled;
|
||||
startStopSensor();
|
||||
emit userEnabledChanged(m_userEnabled);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void OrientationSensor::startStopSensor()
|
||||
{
|
||||
if (m_enabled && m_userEnabled) {
|
||||
|
|
|
@ -76,10 +76,10 @@ Q_SIGNALS:
|
|||
void userEnabledChanged(bool);
|
||||
|
||||
private:
|
||||
void setupStatusNotifier();
|
||||
void startStopSensor();
|
||||
void loadConfig();
|
||||
void refresh();
|
||||
void activate();
|
||||
|
||||
QOrientationSensor *m_sensor;
|
||||
bool m_enabled = false;
|
||||
|
|
Loading…
Reference in a new issue