Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -22,7 +22,7 @@ endif() find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Widgets DBus X11Extras) -find_package(KF5 REQUIRED COMPONENTS Activities Auth IdleTime Config DBusAddons Solid I18n GlobalAccel KIO NotifyConfig Screen KDELibs4Support Wayland) +find_package(KF5 REQUIRED COMPONENTS Activities Auth IdleTime Config DBusAddons Solid I18n GlobalAccel KIO NotifyConfig Screen Notifications Crash DocTools Wayland) find_package(LibKWorkspace CONFIG REQUIRED) find_package(KF5BluezQt) Index: daemon/CMakeLists.txt =================================================================== --- daemon/CMakeLists.txt +++ daemon/CMakeLists.txt @@ -79,6 +79,7 @@ KF5::WidgetsAddons KF5::Notifications KF5::XmlGui + KF5::Crash PW::KWorkspace ) @@ -106,8 +107,8 @@ powerdevilpolicyagent.h PowerDevil::PolicyAgent powermanagementpolicyagentadaptor PowerManagementPolicyAgentAdaptor) -qt5_add_dbus_adaptor(powerdevil_SRCS ${KDE4_DBUS_INTERFACES_DIR}/kf5_org.freedesktop.PowerManagement.xml powerdevilfdoconnector.h PowerDevil::FdoConnector powermanagementfdoadaptor PowerManagementFdoAdaptor) -qt5_add_dbus_adaptor(powerdevil_SRCS ${KDE4_DBUS_INTERFACES_DIR}/kf5_org.freedesktop.PowerManagement.Inhibit.xml powerdevilfdoconnector.h PowerDevil::FdoConnector powermanagementinhibitadaptor PowerManagementInhibitAdaptor) +qt5_add_dbus_adaptor(powerdevil_SRCS ${SOLID_DBUS_INTERFACES_DIR}/kf5_org.freedesktop.PowerManagement.xml powerdevilfdoconnector.h PowerDevil::FdoConnector powermanagementfdoadaptor PowerManagementFdoAdaptor) +qt5_add_dbus_adaptor(powerdevil_SRCS ${SOLID_DBUS_INTERFACES_DIR}/kf5_org.freedesktop.PowerManagement.Inhibit.xml powerdevilfdoconnector.h PowerDevil::FdoConnector powermanagementinhibitadaptor PowerManagementInhibitAdaptor) # Backends Index: daemon/actions/bundled/CMakeLists.txt =================================================================== --- daemon/actions/bundled/CMakeLists.txt +++ daemon/actions/bundled/CMakeLists.txt @@ -4,6 +4,7 @@ ${actionconfig_SRCS}) target_link_libraries(powerdevil${_name}action_config powerdevilui + powerdevilcore Qt5::Widgets KF5::CoreAddons KF5::I18n @@ -18,7 +19,7 @@ add_powerdevil_bundled_action(keyboardbrightnesscontrol) add_powerdevil_bundled_action(dimdisplay) add_powerdevil_bundled_action(runscript KF5::KIOCore KF5::KIOWidgets) -add_powerdevil_bundled_action(suspendsession KF5::KIOCore KF5::KIOWidgets KF5::Solid KF5::KDELibs4Support) +add_powerdevil_bundled_action(suspendsession KF5::KIOCore KF5::KIOWidgets KF5::Solid) if(HAVE_WIRELESS_SUPPORT) add_powerdevil_bundled_action(wirelesspowersaving KF5::NetworkManagerQt KF5::BluezQt) endif() @@ -31,13 +32,13 @@ ${actionconfig_SRCS}) target_link_libraries(powerdevilhandlebuttoneventsaction_config powerdevilui + powerdevilcore Qt5::Widgets KF5::CoreAddons KF5::I18n KF5::ConfigGui KF5::Solid KF5::XmlGui - KF5::KDELibs4Support ) install(TARGETS powerdevilhandlebuttoneventsaction_config DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES powerdevilhandlebuttoneventsaction.desktop DESTINATION ${SERVICES_INSTALL_DIR}) Index: daemon/actions/bundled/handlebuttoneventsconfig.cpp =================================================================== --- daemon/actions/bundled/handlebuttoneventsconfig.cpp +++ daemon/actions/bundled/handlebuttoneventsconfig.cpp @@ -23,8 +23,9 @@ #include "suspendsession.h" #include "upower_interface.h" +#include "powerdevilcore.h" + #include -#include #include #include @@ -94,14 +95,14 @@ QList boxes; boxes << m_lidCloseCombo << m_powerButtonCombo; - QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates(); + const auto methods = PowerDevil::Core::instance()->suspendMethods(); Q_FOREACH (QComboBox *box, boxes) { box->addItem(QIcon::fromTheme("dialog-cancel"), i18n("Do nothing"), (uint)SuspendSession::None); - if (methods.contains(Solid::PowerManagement::SuspendState)) { + if (methods & PowerDevil::BackendInterface::ToRam) { box->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode); } - if (methods.contains(Solid::PowerManagement::HibernateState)) { + if (methods & PowerDevil::BackendInterface::ToDisk) { box->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } box->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); Index: daemon/actions/bundled/suspendsessionconfig.cpp =================================================================== --- daemon/actions/bundled/suspendsessionconfig.cpp +++ daemon/actions/bundled/suspendsessionconfig.cpp @@ -20,11 +20,11 @@ #include "suspendsessionconfig.h" +#include "powerdevilcore.h" + #include #include -#include - #include #include #include @@ -78,14 +78,15 @@ m_idleTime->setValue(0); m_idleTime->setSuffix(i18n(" min")); - QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates(); + const auto methods = PowerDevil::Core::instance()->suspendMethods(); - if (methods.contains(Solid::PowerManagement::SuspendState)) { + if (methods & PowerDevil::BackendInterface::ToRam) { m_comboBox->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode); } - if (methods.contains(Solid::PowerManagement::HibernateState)) { + if (methods & PowerDevil::BackendInterface::ToDisk) { m_comboBox->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } + 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); Index: daemon/powerdevilcore.h =================================================================== --- daemon/powerdevilcore.h +++ daemon/powerdevilcore.h @@ -59,7 +59,8 @@ explicit Core(QObject* parent); virtual ~Core(); - void reloadProfile(int state); + BackendInterface::SuspendMethods suspendMethods() const; + void generateDefaultProfiles(); void emitNotification(const QString &evid, const QString &message = QString(), const QString &iconname = QString()); @@ -73,6 +74,9 @@ // More... +public: + static Core *instance(); + public Q_SLOTS: void loadCore(PowerDevil::BackendInterface *backend); // Set of common action - useful for the DBus interface Index: daemon/powerdevilcore.cpp =================================================================== --- daemon/powerdevilcore.cpp +++ daemon/powerdevilcore.cpp @@ -18,6 +18,7 @@ ***************************************************************************/ #include "powerdevilcore.h" +#include "powerdevilapp.h" #include "PowerDevilSettings.h" @@ -54,6 +55,13 @@ namespace PowerDevil { +Core *m_instance = nullptr; + +Core *Core::instance() +{ + return m_instance; +} + Core::Core(QObject* parent) : QObject(parent) , m_hasDualGpu(false) @@ -63,6 +71,8 @@ , m_activityConsumer(new KActivities::Consumer(this)) , m_pendingWakeupEvent(true) { + m_instance = this; + KAuth::Action discreteGpuAction("org.kde.powerdevil.discretegpuhelper.hasdualgpu"); discreteGpuAction.setHelperId("org.kde.powerdevil.discretegpuhelper"); KAuth::ExecuteJob *discreteGpuJob = discreteGpuAction.execute(); @@ -79,12 +89,29 @@ Core::~Core() { + m_instance = nullptr; + qCDebug(POWERDEVIL) << "Core unloading"; // Unload all actions before exiting, and clear the cache ActionPool::instance()->unloadAllActiveActions(); ActionPool::instance()->clearCache(); } +BackendInterface::SuspendMethods Core::suspendMethods() const +{ + if (!m_backend) + return BackendInterface::UnknownSuspendMethod; + return m_backend->supportedSuspendMethods(); +} + +void Core::generateDefaultProfiles() +{ + const auto methods = suspendMethods(); + const bool toRam = methods & PowerDevil::BackendInterface::ToRam; + const bool toDisk = methods & PowerDevil::BackendInterface::ToDisk; + ProfileGenerator::generateProfiles(toRam, toDisk); +} + void Core::loadCore(BackendInterface* backend) { if (!backend) { @@ -111,9 +138,7 @@ // Is it brand new? if (m_profilesConfig->groupList().isEmpty()) { // Generate defaults - bool toRam = m_backend->supportedSuspendMethods() & PowerDevil::BackendInterface::ToRam; - bool toDisk = m_backend->supportedSuspendMethods() & PowerDevil::BackendInterface::ToDisk; - ProfileGenerator::generateProfiles(toRam, toDisk); + generateDefaultProfiles(); m_profilesConfig->reparseConfiguration(); } Index: kcmodule/activities/CMakeLists.txt =================================================================== --- kcmodule/activities/CMakeLists.txt +++ kcmodule/activities/CMakeLists.txt @@ -17,7 +17,6 @@ target_link_libraries(kcm_powerdevilactivitiesconfig KF5::Solid KF5::Activities - KF5::KDELibs4Support powerdevilconfigcommonprivate ) Index: kcmodule/activities/activitypage.cpp =================================================================== --- kcmodule/activities/activitypage.cpp +++ kcmodule/activities/activitypage.cpp @@ -73,8 +73,8 @@ QVBoxLayout *lay = new QVBoxLayout(); // Message widget - m_messageWidget = new KMessageWidget(i18n("The activity service is running with bare functionalities.\n" - "Names and icons of the activities might not be available.")); + m_messageWidget = QSharedPointer(new KMessageWidget(i18n("The activity service is running with bare functionalities.\n" + "Names and icons of the activities might not be available."))); m_messageWidget.data()->setMessageType(KMessageWidget::Warning); m_messageWidget.data()->hide(); @@ -143,10 +143,10 @@ case KActivities::Consumer::NotRunning: // Create error overlay, if not present if (m_errorOverlay.isNull()) { - m_errorOverlay = new ErrorOverlay(this, i18n("The activity service is not running.\n" - "It is necessary to have the activity manager running " - "to configure activity-specific power management behavior."), - this); + m_errorOverlay = QSharedPointer(new ErrorOverlay(this, i18n("The activity service is not running.\n" + "It is necessary to have the activity manager running " + "to configure activity-specific power management behavior."), + this)); } break; case KActivities::Consumer::Running: @@ -236,9 +236,9 @@ return; } - m_errorOverlay = new ErrorOverlay(this, i18n("The Power Management Service appears not to be running.\n" - "This can be solved by starting or scheduling it inside \"Startup and Shutdown\""), - this); + m_errorOverlay = QSharedPointer(new ErrorOverlay(this, i18n("The Power Management Service appears not to be running.\n" + "This can be solved by starting or scheduling it inside \"Startup and Shutdown\""), + this)); } #include "activitypage.moc" Index: kcmodule/activities/activitywidget.cpp =================================================================== --- kcmodule/activities/activitywidget.cpp +++ kcmodule/activities/activitywidget.cpp @@ -24,9 +24,10 @@ #include "../daemon/actions/bundled/suspendsession.h" +#include "powerdevilcore.h" + #include #include -#include #include #include #include @@ -91,16 +92,16 @@ using namespace PowerDevil::BundledActions; - QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates(); - - if (methods.contains(Solid::PowerManagement::SuspendState)) { + const auto methods = PowerDevil::Core::instance()->suspendMethods(); + if (methods & PowerDevil::BackendInterface::ToRam) { m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), (uint)SuspendSession::ToRamMode); } - if (methods.contains(Solid::PowerManagement::HibernateState)) { + if (methods & PowerDevil::BackendInterface::ToDisk) { m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), (uint)SuspendSession::ToDiskMode); } + m_ui->alwaysActionBox->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), (uint)SuspendSession::ShutdownMode); m_ui->actLikeComboBox->clear(); Index: kcmodule/global/CMakeLists.txt =================================================================== --- kcmodule/global/CMakeLists.txt +++ kcmodule/global/CMakeLists.txt @@ -16,7 +16,6 @@ KF5::KIOWidgets KF5::Solid KF5::NotifyConfig - KF5::KDELibs4Support powerdevilconfigcommonprivate ) Index: kcmodule/global/GeneralPage.cpp =================================================================== --- kcmodule/global/GeneralPage.cpp +++ kcmodule/global/GeneralPage.cpp @@ -24,10 +24,11 @@ #include "actions/bundled/suspendsession.h" +#include "powerdevilcore.h" + #include #include #include -#include #include #include @@ -101,15 +102,16 @@ } } - QSet< Solid::PowerManagement::SleepState > methods = Solid::PowerManagement::supportedSleepStates(); - BatteryCriticalCombo->addItem(QIcon::fromTheme("dialog-cancel"), i18n("Do nothing"), PowerDevil::BundledActions::SuspendSession::None); - if (methods.contains(Solid::PowerManagement::SuspendState)) { + + const auto methods = PowerDevil::Core::instance()->suspendMethods(); + if (methods & PowerDevil::BackendInterface::ToRam) { BatteryCriticalCombo->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), PowerDevil::BundledActions::SuspendSession::ToRamMode); } - if (methods.contains(Solid::PowerManagement::HibernateState)) { + if (methods & PowerDevil::BackendInterface::ToDisk) { BatteryCriticalCombo->addItem(QIcon::fromTheme("system-suspend-hibernate"), i18n("Hibernate"), PowerDevil::BundledActions::SuspendSession::ToDiskMode); } + BatteryCriticalCombo->addItem(QIcon::fromTheme("system-shutdown"), i18n("Shut down"), PowerDevil::BundledActions::SuspendSession::ShutdownMode); notificationsButton->setIcon(QIcon::fromTheme("preferences-desktop-notification")); @@ -200,9 +202,9 @@ m_errorOverlay.data()->deleteLater(); } - m_errorOverlay = new ErrorOverlay(this, i18n("The Power Management Service appears not to be running.\n" - "This can be solved by starting or scheduling it inside \"Startup and Shutdown\""), - this); + m_errorOverlay = QSharedPointer(new ErrorOverlay(this, i18n("The Power Management Service appears not to be running.\n" + "This can be solved by starting or scheduling it inside \"Startup and Shutdown\""), + this)); } #include "GeneralPage.moc" Index: kcmodule/profiles/CMakeLists.txt =================================================================== --- kcmodule/profiles/CMakeLists.txt +++ kcmodule/profiles/CMakeLists.txt @@ -18,7 +18,6 @@ KF5::Solid KF5::ConfigGui KF5::ConfigWidgets - KF5::KDELibs4Support powerdevilui powerdevilconfigcommonprivate ) Index: kcmodule/profiles/EditPage.cpp =================================================================== --- kcmodule/profiles/EditPage.cpp +++ kcmodule/profiles/EditPage.cpp @@ -24,6 +24,7 @@ #include #include +#include #include @@ -50,7 +51,6 @@ #include #include -#include K_PLUGIN_FACTORY(PowerDevilProfilesKCMFactory, registerPlugin(); @@ -78,12 +78,7 @@ m_profilesConfig = KSharedConfig::openConfig("powermanagementprofilesrc", KConfig::SimpleConfig | KConfig::CascadeConfig); if (m_profilesConfig->groupList().isEmpty()) { - // Use the generator - QSet methods = Solid::PowerManagement::supportedSleepStates(); - PowerDevil::ProfileGenerator::generateProfiles( - methods.contains(Solid::PowerManagement::SuspendState), - methods.contains(Solid::PowerManagement::HibernateState) - ); + PowerDevil::Core::instance()->generateDefaultProfiles(); m_profilesConfig->reparseConfiguration(); } @@ -195,11 +190,7 @@ "Are you sure you want to continue?"), i18n("Restore Default Profiles")); if (ret == KMessageBox::Continue) { qCDebug(POWERDEVIL) << "Restoring defaults."; - QSet methods = Solid::PowerManagement::supportedSleepStates(); - PowerDevil::ProfileGenerator::generateProfiles( - methods.contains(Solid::PowerManagement::SuspendState), - methods.contains(Solid::PowerManagement::HibernateState) - ); + PowerDevil::Core::instance()->generateDefaultProfiles(); load(); @@ -271,9 +262,9 @@ m_errorOverlay.data()->deleteLater(); } - m_errorOverlay = new ErrorOverlay(this, i18n("The Power Management Service appears not to be running.\n" - "This can be solved by starting or scheduling it inside \"Startup and Shutdown\""), - this); + m_errorOverlay = QSharedPointer(new ErrorOverlay(this, i18n("The Power Management Service appears not to be running.\n" + "This can be solved by starting or scheduling it inside \"Startup and Shutdown\""), + this)); } #include "EditPage.moc"