diff --git a/daemon/actions/bundled/handlebuttoneventsconfig.cpp b/daemon/actions/bundled/handlebuttoneventsconfig.cpp index 6aa1061e..8ca5f4c4 100644 --- a/daemon/actions/bundled/handlebuttoneventsconfig.cpp +++ b/daemon/actions/bundled/handlebuttoneventsconfig.cpp @@ -1,178 +1,181 @@ /*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * Copyright (C) 2015 by Kai Uwe Broulik * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "handlebuttoneventsconfig.h" #include "suspendsession.h" #include "upower_interface.h" #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(PowerDevilSuspendSessionConfigFactory, registerPlugin(); ) namespace PowerDevil { namespace BundledActions { HandleButtonEventsConfig::HandleButtonEventsConfig(QObject* parent, const QVariantList& ) : ActionConfig(parent) { } HandleButtonEventsConfig::~HandleButtonEventsConfig() { } void HandleButtonEventsConfig::save() { if (m_lidCloseCombo) { configGroup().writeEntry("lidAction", m_lidCloseCombo->itemData(m_lidCloseCombo->currentIndex()).toUInt()); } if (m_triggerLidActionWhenExternalMonitorPresent) { configGroup().writeEntry("triggerLidActionWhenExternalMonitorPresent", m_triggerLidActionWhenExternalMonitorPresent->isChecked()); } if (m_powerButtonCombo) { configGroup().writeEntry("powerButtonAction", m_powerButtonCombo->itemData(m_powerButtonCombo->currentIndex()).toUInt()); } configGroup().sync(); } void HandleButtonEventsConfig::load() { configGroup().config()->reparseConfiguration(); if (m_lidCloseCombo) { m_lidCloseCombo->setCurrentIndex(m_lidCloseCombo->findData(QVariant::fromValue(configGroup().readEntry("lidAction", 0)))); } if (m_triggerLidActionWhenExternalMonitorPresent) { m_triggerLidActionWhenExternalMonitorPresent->setChecked(configGroup().readEntry("triggerLidActionWhenExternalMonitorPresent", false)); } if (m_powerButtonCombo) { m_powerButtonCombo->setCurrentIndex(m_powerButtonCombo->findData(QVariant::fromValue(configGroup().readEntry("powerButtonAction", 0)))); } } QList< QPair< QString, QWidget* > > HandleButtonEventsConfig::buildUi() { // Create the boxes m_lidCloseCombo = new QComboBox; m_triggerLidActionWhenExternalMonitorPresent = new QCheckBox( i18nc("Execute action on lid close even when external monitor is connected", "Even when an external monitor is connected") ); m_powerButtonCombo = new QComboBox; // Fill the boxes with options! { QList boxes; boxes << m_lidCloseCombo << m_powerButtonCombo; QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates(); Q_FOREACH (QComboBox *box, boxes) { box->addItem(QIcon::fromTheme("dialog-cancel"), i18n("Do nothing"), (uint)SuspendSession::None); if (methods.contains(Solid::PowerManagement::SuspendState)) { box->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode); } if (methods.contains(Solid::PowerManagement::HibernateState)) { box->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } + if (methods.contains(Solid::PowerManagement::HybridSuspendState)) { + box->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Hybrid suspend"), (uint)SuspendSession::SuspendHybridMode); + } box->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); box->addItem(QIcon::fromTheme("system-lock-screen"), i18n("Lock screen"), (uint)SuspendSession::LockScreenMode); if (box != m_lidCloseCombo) { box->addItem(QIcon::fromTheme("system-log-out"), i18n("Prompt log out dialog"), (uint)SuspendSession::LogoutDialogMode); } box->addItem(QIcon::fromTheme("preferences-desktop-screensaver"), i18n("Turn off screen"), (uint)SuspendSession::TurnOffScreenMode); } } connect(m_lidCloseCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); connect(m_triggerLidActionWhenExternalMonitorPresent, SIGNAL(stateChanged(int)), this, SLOT(setChanged())); connect(m_powerButtonCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); bool lidFound = false; bool powerFound = true; // HACK This needs proper API!! // get a list of all devices that are Buttons /* Q_FOREACH (Solid::Device device, Solid::Device::listFromType(Solid::DeviceInterface::Button, QString())) { Solid::Button *button = device.as(); if (button->type() == Solid::Button::LidButton) { lidFound = true; } else if (button->type() == Solid::Button::PowerButton) { powerFound = true; } }*/ auto m_upowerInterface = new OrgFreedesktopUPowerInterface("org.freedesktop.UPower", "/org/freedesktop/UPower", QDBusConnection::systemBus(), this); lidFound = m_upowerInterface->lidIsPresent(); QList< QPair< QString, QWidget* > > retlist; if (lidFound) { retlist.append(qMakePair(i18n("When laptop lid closed"), m_lidCloseCombo)); // an empty label will make it treat the widget as title checkbox and left-align it retlist.append(qMakePair(QLatin1Literal("NONE"), m_triggerLidActionWhenExternalMonitorPresent)); } else { m_lidCloseCombo->deleteLater(); m_lidCloseCombo = nullptr; m_triggerLidActionWhenExternalMonitorPresent->deleteLater(); m_triggerLidActionWhenExternalMonitorPresent = nullptr; } if (powerFound) { retlist.append(qMakePair< QString, QWidget* >(i18n("When power button pressed"), m_powerButtonCombo)); } else { m_powerButtonCombo->deleteLater(); m_powerButtonCombo = nullptr; } // unified width for the comboboxes int comboBoxMaxWidth = 300; if (m_lidCloseCombo) { comboBoxMaxWidth = qMax(comboBoxMaxWidth, m_lidCloseCombo->sizeHint().width()); } if (m_powerButtonCombo) { comboBoxMaxWidth = qMax(comboBoxMaxWidth, m_powerButtonCombo->sizeHint().width()); } if (m_lidCloseCombo) { m_lidCloseCombo->setMinimumWidth(300); m_lidCloseCombo->setMaximumWidth(comboBoxMaxWidth); } if (m_powerButtonCombo) { m_powerButtonCombo->setMinimumWidth(300); m_powerButtonCombo->setMaximumWidth(comboBoxMaxWidth); } return retlist; } } } #include "handlebuttoneventsconfig.moc" diff --git a/daemon/actions/bundled/suspendsessionconfig.cpp b/daemon/actions/bundled/suspendsessionconfig.cpp index 1d36db6e..b9e88294 100644 --- a/daemon/actions/bundled/suspendsessionconfig.cpp +++ b/daemon/actions/bundled/suspendsessionconfig.cpp @@ -1,110 +1,113 @@ /*************************************************************************** * Copyright (C) 2010 by Dario Freddi * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . * ***************************************************************************/ #include "suspendsessionconfig.h" #include #include #include #include #include #include #include #include #include #include "suspendsession.h" K_PLUGIN_FACTORY(PowerDevilSuspendSessionConfigFactory, registerPlugin(); ) namespace PowerDevil { namespace BundledActions { SuspendSessionConfig::SuspendSessionConfig(QObject* parent, const QVariantList&) : ActionConfig(parent) { } SuspendSessionConfig::~SuspendSessionConfig() { } void SuspendSessionConfig::save() { configGroup().writeEntry< uint >("suspendType", m_comboBox->itemData(m_comboBox->currentIndex()).toUInt()); configGroup().writeEntry("idleTime", m_idleTime->value() * 60 * 1000); configGroup().sync(); } void SuspendSessionConfig::load() { configGroup().config()->reparseConfiguration(); uint suspendType = configGroup().readEntry< uint >("suspendType", 0); m_comboBox->setCurrentIndex(m_comboBox->findData(suspendType)); m_idleTime->setValue((configGroup().readEntry("idleTime", 600000) / 60) / 1000); } QList< QPair< QString, QWidget* > > SuspendSessionConfig::buildUi() { QWidget *tempWidget = new QWidget; QHBoxLayout *hlay = new QHBoxLayout; m_comboBox = new KComboBox; m_idleTime = new QSpinBox; m_idleTime->setMaximumWidth(150); m_idleTime->setMinimum(1); m_idleTime->setMaximum(360); m_idleTime->setValue(0); m_idleTime->setSuffix(i18n(" min")); QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates(); if (methods.contains(Solid::PowerManagement::SuspendState)) { m_comboBox->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode); } if (methods.contains(Solid::PowerManagement::HibernateState)) { m_comboBox->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } + if (methods.contains(Solid::PowerManagement::HybridSuspendState)) { + m_comboBox->addItem(QIcon::fromTheme("system-suspend-hybrid"), i18n("Hybrid suspend"), (uint)SuspendSession::SuspendHybridMode); + } m_comboBox->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); m_comboBox->addItem(QIcon::fromTheme("system-lock-screen"), i18n("Lock screen"), (uint)SuspendSession::LockScreenMode); hlay->addWidget(m_idleTime); hlay->addWidget(m_comboBox); hlay->addStretch(); tempWidget->setLayout(hlay); QList< QPair< QString, QWidget* > > retlist; retlist.append(qMakePair< QString, QWidget* >(i18n("After"), tempWidget)); connect(m_comboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setChanged())); connect(m_idleTime, SIGNAL(valueChanged(int)), this, SLOT(setChanged())); return retlist; } } } #include "suspendsessionconfig.moc"