diff --git a/CMakeLists.txt b/CMakeLists.txt index 7807b164..7b647bdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,85 +1,83 @@ project(PowerDevil) set(PROJECT_VERSION "5.12.1") set(PROJECT_VERSION_MAJOR 5) cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR) set(QT_MIN_VERSION "5.7.0") find_package(ECM 1.2.0 REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) include(FeatureSummary) include(WriteBasicConfigVersionFile) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) # require at least gcc 4.8 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") if ("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS "4.8") message(SEND_ERROR "Version ${CMAKE_CXX_COMPILER_VERSION} of the ${CMAKE_CXX_COMPILER_ID} C++ compiler is not supported. Please use version 4.8 or later.") endif() 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(LibKWorkspace CONFIG REQUIRED) find_package(KF5BluezQt) set_package_properties(KF5BluezQt PROPERTIES DESCRIPTION "Qt wrapper for BlueZ 5 DBus API" TYPE OPTIONAL PURPOSE "Support for wireless energy saving actions" ) find_package(KF5NetworkManagerQt) set_package_properties(KF5NetworkManagerQt PROPERTIES DESCRIPTION "Qt wrapper for NetworkManager API" TYPE OPTIONAL PURPOSE "Support for wireless energy saving actions" ) set(HAVE_WIRELESS_SUPPORT FALSE) if(KF5NetworkManagerQt_FOUND AND KF5BluezQt_FOUND) set(HAVE_WIRELESS_SUPPORT TRUE) endif() add_feature_info( "Wireless power saving" HAVE_WIRELESS_SUPPORT "Support turning off signal-transmitting devices to save energy" ) find_package(UDev REQUIRED) find_package(XCB REQUIRED COMPONENTS XCB RANDR DPMS) if(WITH_DDCUTIL) find_package(DDCUtil) set_package_properties(DDCUtil PROPERTIES DESCRIPTION "DDCUtil library support" TYPE OPTIONAL PURPOSE "Set monitor settings over DDC/CI channel" ) else() add_feature_info("DDCUtil" "Off" "DDCUtil library support is disabled by default as recomemded by authors, add -DWITH_DDCUTIL=On to enable") endif() include_directories ( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/daemon ) add_definitions(-DQT_NO_KEYWORDS) add_definitions(-DQT_NO_KEYWORDS) add_subdirectory(daemon) add_subdirectory(kcmodule) add_subdirectory(doc) -add_subdirectory(kconf_update) - install( FILES powerdevil.notifyrc DESTINATION ${KNOTIFYRC_INSTALL_DIR} ) if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES) endif() diff --git a/daemon/powerdevilapp.cpp b/daemon/powerdevilapp.cpp index ccf6987d..0737b22b 100644 --- a/daemon/powerdevilapp.cpp +++ b/daemon/powerdevilapp.cpp @@ -1,154 +1,209 @@ /*************************************************************************** * 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 "powerdevilapp.h" #include "powerdevilfdoconnector.h" #include "powermanagementadaptor.h" #include "powermanagementpolicyagentadaptor.h" #include "powerdevilcore.h" #include "powerdevil_debug.h" #include #include #include #include #include +#include +#include #include #include #include #include #include +#include +#include PowerDevilApp::PowerDevilApp(int &argc, char **argv) : QGuiApplication(argc, argv) , m_core(Q_NULLPTR) { + migratePre512KeyboardShortcuts(); } PowerDevilApp::~PowerDevilApp() { delete m_core; } void PowerDevilApp::init() { // KGlobal::insertCatalog("powerdevil"); // KAboutData aboutData("powerdevil", "powerdevil", ki18n("KDE Power Management System"), // PROJECT_VERSION, ki18n("KDE Power Management System is PowerDevil, an " // "advanced, modular and lightweight Power Management " // "daemon"), // KAboutData::License_GPL, ki18n("(c) 2010 MetalWorkers Co."), // KLocalizedString(), "http://www.kde.org"); // // aboutData.addAuthor(ki18n( "Dario Freddi" ), ki18n("Maintainer"), "drf@kde.org", // "http://drfav.wordpress.com"); if (QDBusConnection::systemBus().interface()->isServiceRegistered(QLatin1String("org.freedesktop.PowerManagement")) || QDBusConnection::systemBus().interface()->isServiceRegistered(QLatin1String("com.novell.powersave")) || QDBusConnection::systemBus().interface()->isServiceRegistered(QLatin1String("org.freedesktop.Policy.Power"))) { qCCritical(POWERDEVIL) << "KDE Power Management system not initialized, another power manager has been detected"; return; } // not parenting Core to PowerDevilApp as it is the deleted too late on teardown // where the X connection is already lost leading to a a crash (Bug 371127) m_core = new PowerDevil::Core(nullptr/*, KComponentData(aboutData)*/); connect(m_core, SIGNAL(coreReady()), this, SLOT(onCoreReady())); // Before doing anything, let's set up our backend const QStringList paths = QCoreApplication::libraryPaths(); QFileInfoList fileInfos; for (const QString &path : paths) { QDir dir(path + QLatin1String("/kf5/powerdevil/"), QStringLiteral("*"), QDir::SortFlags(QDir::QDir::Name), QDir::NoDotAndDotDot | QDir::Files); fileInfos.append(dir.entryInfoList()); } QFileInfo backendFileInfo; Q_FOREACH (const QFileInfo &f, fileInfos) { if (f.baseName().toLower() == QLatin1String("powerdevilupowerbackend")) { backendFileInfo = f; break; } } QPluginLoader *loader = new QPluginLoader(backendFileInfo.filePath(), m_core); QObject *instance = loader->instance(); if (!instance) { qCDebug(POWERDEVIL) << loader->errorString(); qCCritical(POWERDEVIL) << "KDE Power Management System init failed!"; m_core->loadCore(0); return; } auto interface = qobject_cast(instance); if (!interface) { qCDebug(POWERDEVIL) << "Failed to cast plugin instance to BackendInterface, check your plugin"; qCCritical(POWERDEVIL) << "KDE Power Management System init failed!"; m_core->loadCore(0); return; } qCDebug(POWERDEVIL) << "Backend loaded, loading core"; m_core->loadCore(interface); } void PowerDevilApp::onCoreReady() { qCDebug(POWERDEVIL) << "Core is ready, registering various services on the bus..."; //DBus logic for the core new PowerManagementAdaptor(m_core); new PowerDevil::FdoConnector(m_core); QDBusConnection::sessionBus().registerService(QLatin1String("org.kde.Solid.PowerManagement")); QDBusConnection::sessionBus().registerObject(QLatin1String("/org/kde/Solid/PowerManagement"), m_core); QDBusConnection::systemBus().interface()->registerService("org.freedesktop.Policy.Power"); // Start the Policy Agent service qDBusRegisterMetaType>(); qDBusRegisterMetaType(); new PowerManagementPolicyAgentAdaptor(PowerDevil::PolicyAgent::instance()); QDBusConnection::sessionBus().registerService(QLatin1String("org.kde.Solid.PowerManagement.PolicyAgent")); QDBusConnection::sessionBus().registerObject(QLatin1String("/org/kde/Solid/PowerManagement/PolicyAgent"), PowerDevil::PolicyAgent::instance()); } + +/* + * 5.11 -> 5.12 migrated shortcuts from kded5 to the correct component name org_kde_powerdevil for good reasons +however despite a kconfupdate script working correctly and moving the old keys, +because kglobalaccel is running whilst we update it synced the old values, and then ignores the powerdevil copy +on future loads + +this removes the old powermanagent entries in the kded5 component at powerdevil startup +//which is at runtime where we can talk to kglobalaccel and then re-register ours + +this method can probably be deleted at some point in the future +*/ +void PowerDevilApp::migratePre512KeyboardShortcuts() +{ + auto configGroup = KSharedConfig::openConfig("powermanagementprofilesrc")->group("migration"); + if (!configGroup.hasKey("kdedShortcutMigration")) { + const QStringList actionIds({ + "Decrease Keyboard Brightness", + "Decrease Screen Brightness", + "Hibernate", + "Increase Keyboard Brightness", + "Increase Screen Brightness", + "PowerOff", + "Sleep", + "Toggle Keyboard Backlight" + }); + for (const QString &actionId: actionIds) { + QAction oldAction; + oldAction.setObjectName(actionId); + oldAction.setProperty("componentName", "kded5"); + + //claim the old shortcut so we can remove it.. + KGlobalAccel::self()->setShortcut(&oldAction, QList(), KGlobalAccel::Autoloading); + auto shortcuts = KGlobalAccel::self()->shortcut(&oldAction); + KGlobalAccel::self()->removeAllShortcuts(&oldAction); + + QAction newAction; + newAction.setObjectName(actionId); + newAction.setProperty("componentName", "org_kde_powerdevil"); + if (!shortcuts.isEmpty()) { + //register with no autoloading to sync config, we then delete our QAction, and powerdevil will + //re-register as normal + KGlobalAccel::self()->setShortcut(&newAction, shortcuts, KGlobalAccel::NoAutoloading); + } + } + } + configGroup.writeEntry(QStringLiteral("kdedShortcutMigration"), true); + configGroup.sync(); +} + int main(int argc, char **argv) { QGuiApplication::setDesktopSettingsAware(false); PowerDevilApp app(argc, argv); KDBusService service(KDBusService::Unique); KCrash::setFlags(KCrash::AutoRestart); app.setQuitOnLastWindowClosed(false); app.init(); return app.exec(); } #include "powerdevilapp.moc" diff --git a/daemon/powerdevilapp.h b/daemon/powerdevilapp.h index d99a08c2..bca57590 100644 --- a/daemon/powerdevilapp.h +++ b/daemon/powerdevilapp.h @@ -1,51 +1,52 @@ /*************************************************************************** * 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 . * ***************************************************************************/ #ifndef POWERDEVILAPP_H #define POWERDEVILAPP_H #include #include namespace PowerDevil { class Core; class BackendInterface; } using InhibitionInfo = QPair; class PowerDevilApp : public QGuiApplication { Q_OBJECT Q_DISABLE_COPY(PowerDevilApp) public: explicit PowerDevilApp(int &argc, char **argv); virtual ~PowerDevilApp(); void init(); private Q_SLOTS: void onCoreReady(); private: PowerDevil::Core *m_core; + void migratePre512KeyboardShortcuts(); }; #endif // POWERDEVILAPP_H diff --git a/kconf_update/CMakeLists.txt b/kconf_update/CMakeLists.txt deleted file mode 100644 index b3204a8d..00000000 --- a/kconf_update/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -install(FILES powerdevil_move_shortcuts.upd DESTINATION ${KCONF_UPDATE_INSTALL_DIR}) diff --git a/kconf_update/powerdevil_move_shortcuts.upd b/kconf_update/powerdevil_move_shortcuts.upd deleted file mode 100644 index 5a10708a..00000000 --- a/kconf_update/powerdevil_move_shortcuts.upd +++ /dev/null @@ -1,12 +0,0 @@ -Version=5 -Id=powerdevil_move_shortcuts -File=kglobalshortcutsrc -Group=kded5, org_kde_powerdevil -Key=Hibernate -Key=PowerOff -Key=Sleep -Key=Decrease Keyboard Brightness -Key=Decrease Screen Brightness -Key=Increase Keyboard Brightness -Key=Increase Screen Brightness -Key=Toggle Keyboard Backlight