diff --git a/kcmodule/activities/activitypage.cpp b/kcmodule/activities/activitypage.cpp index c0d4ed64..dfca02c9 100644 --- a/kcmodule/activities/activitypage.cpp +++ b/kcmodule/activities/activitypage.cpp @@ -1,244 +1,246 @@ /*************************************************************************** * Copyright (C) 2011 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 "activitypage.h" #include "activitywidget.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(PowerDevilActivitiesKCMFactory, registerPlugin(); ) K_EXPORT_PLUGIN(PowerDevilActivitiesKCMFactory("powerdevilactivitiesconfig","powerdevil")) ActivityPage::ActivityPage(QWidget *parent, const QVariantList &args) : KCModule(0, parent, args) , m_activityConsumer(new KActivities::Consumer(this)) { setButtons(Apply | Help); /*KAboutData *about = new KAboutData("powerdevilactivitiesconfig", "powerdevilactivitiesconfig", ki18n("Activities Power Management Configuration"), "", ki18n("A per-activity configurator of KDE Power Management System"), KAboutData::License_GPL, ki18n("(c), 2010 Dario Freddi"), ki18n("From this module, you can fine tune power management settings for each of your activities.")); about->addAuthor(ki18n("Dario Freddi"), ki18n("Maintainer") , "drf@kde.org", "http://drfav.wordpress.com"); setAboutData(about);*/ // Build the UI m_tabWidget = new QTabWidget(); 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.data()->setMessageType(KMessageWidget::Warning); - m_messageWidget.data()->hide(); + m_messageWidget->setMessageType(KMessageWidget::Warning); + m_messageWidget->hide(); - lay->addWidget(m_messageWidget.data()); + lay->addWidget(m_messageWidget); lay->addWidget(m_tabWidget); setLayout(lay); onActivityServiceStatusChanged(m_activityConsumer->serviceStatus()); connect(m_activityConsumer, &KActivities::Consumer::serviceStatusChanged, this, &ActivityPage::onActivityServiceStatusChanged); QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.Solid.PowerManagement", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); connect(watcher, SIGNAL(serviceRegistered(QString)), this, SLOT(onServiceRegistered(QString))); connect(watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(onServiceUnregistered(QString))); if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.Solid.PowerManagement")) { onServiceRegistered("org.kde.Solid.PowerManagement"); } else { onServiceUnregistered("org.kde.Solid.PowerManagement"); } } ActivityPage::~ActivityPage() { } void ActivityPage::load() { Q_FOREACH (ActivityWidget *widget, m_activityWidgets) { widget->load(); } Q_EMIT changed(false); } void ActivityPage::save() { Q_FOREACH (ActivityWidget *widget, m_activityWidgets) { widget->save(); } Q_EMIT changed(false); // Ask to refresh status QDBusMessage call = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement", "refreshStatus"); // Perform call QDBusConnection::sessionBus().asyncCall(call); } void ActivityPage::fillUi() { } void ActivityPage::onActivityServiceStatusChanged(KActivities::Consumer::ServiceStatus status) { switch (status) { case KActivities::Consumer::Unknown: // fall through case KActivities::Consumer::NotRunning: // Create error overlay, if not present - if (m_errorOverlay.isNull()) { + if (!m_errorOverlay) { 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); } break; case KActivities::Consumer::Running: if (m_previousServiceStatus != KActivities::Consumer::Running) { - if (!m_errorOverlay.isNull()) { - m_errorOverlay.data()->deleteLater(); + if (m_errorOverlay) { + m_errorOverlay->deleteLater(); + m_errorOverlay = nullptr; if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.Solid.PowerManagement")) { onServiceRegistered("org.kde.Solid.PowerManagement"); } else { onServiceUnregistered("org.kde.Solid.PowerManagement"); } } populateTabs(); } - if (m_messageWidget.data()->isVisible()) { - m_messageWidget.data()->hide(); + if (m_messageWidget->isVisible()) { + m_messageWidget->hide(); } break; } m_previousServiceStatus = status; } void ActivityPage::populateTabs() { if (m_activityConsumer->serviceStatus() != KActivities::Consumer::Running) { return; } int index = 0; Q_FOREACH (const QString &activity, m_activityConsumer->activities()) { KActivities::Info *info = new KActivities::Info(activity, this); const QString icon = info->icon(); const QString name = info->name(); qCDebug(POWERDEVIL) << activity << info->isValid() << info->availability(); QScrollArea *scrollArea = new QScrollArea(); scrollArea->setFrameShape(QFrame::NoFrame); scrollArea->setFrameShadow(QFrame::Plain); scrollArea->setLineWidth(0); scrollArea->setWidgetResizable(true); ActivityWidget *activityWidget = new ActivityWidget(activity); scrollArea->setWidget(activityWidget); activityWidget->load(); m_activityWidgets.append(activityWidget); connect(activityWidget, SIGNAL(changed(bool)), this, SIGNAL(changed(bool))); if (!icon.isEmpty()) { m_tabWidget->addTab(scrollArea, QIcon::fromTheme(icon), name); } else { m_tabWidget->addTab(scrollArea, name); } if (m_activityConsumer->currentActivity() == activity) { m_tabWidget->setCurrentIndex(index); } ++index; } } void ActivityPage::defaults() { KCModule::defaults(); } void ActivityPage::onServiceRegistered(const QString& service) { Q_UNUSED(service); - if (!m_errorOverlay.isNull()) { - m_errorOverlay.data()->deleteLater(); + if (m_errorOverlay) { + m_errorOverlay->deleteLater(); + m_errorOverlay = nullptr; } } void ActivityPage::onServiceUnregistered(const QString& service) { Q_UNUSED(service); - if (!m_errorOverlay.isNull()) { + if (m_errorOverlay) { 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); } #include "activitypage.moc" diff --git a/kcmodule/activities/activitypage.h b/kcmodule/activities/activitypage.h index cc4e3cdf..8fbe7dcd 100644 --- a/kcmodule/activities/activitypage.h +++ b/kcmodule/activities/activitypage.h @@ -1,65 +1,65 @@ /*************************************************************************** * Copyright (C) 2011 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 ACTIVITYPAGE_H #define ACTIVITYPAGE_H #include #include class QTabWidget; class KMessageWidget; class ErrorOverlay; class ActivityWidget; class ActivityPage : public KCModule { Q_OBJECT public: ActivityPage(QWidget *parent, const QVariantList &args); virtual ~ActivityPage(); void fillUi(); void load(); void save(); virtual void defaults(); private Q_SLOTS: void onActivityServiceStatusChanged(KActivities::Consumer::ServiceStatus status); void onServiceRegistered(const QString &service); void onServiceUnregistered(const QString &service); private: void populateTabs(); QTabWidget *m_tabWidget; KActivities::Consumer *m_activityConsumer; QList< ActivityWidget* > m_activityWidgets; - QWeakPointer< ErrorOverlay > m_errorOverlay; - QWeakPointer< KMessageWidget > m_messageWidget; + ErrorOverlay *m_errorOverlay = nullptr; + KMessageWidget *m_messageWidget = nullptr; KActivities::Consumer::ServiceStatus m_previousServiceStatus; }; #endif // ACTIVITYPAGE_H diff --git a/kcmodule/global/GeneralPage.cpp b/kcmodule/global/GeneralPage.cpp index f9b5b6f7..78a6fe20 100644 --- a/kcmodule/global/GeneralPage.cpp +++ b/kcmodule/global/GeneralPage.cpp @@ -1,208 +1,209 @@ /*************************************************************************** * Copyright (C) 2008 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 "GeneralPage.h" #include "ErrorOverlay.h" #include "PowerDevilSettings.h" #include "actions/bundled/suspendsession.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(PowerDevilGeneralKCMFactory, registerPlugin(); ) GeneralPage::GeneralPage(QWidget *parent, const QVariantList &args) : KCModule(0, parent, args) { setButtons(Apply | Help); // KAboutData *about = // new KAboutData("powerdevilglobalconfig", "powerdevilglobalconfig", ki18n("Global Power Management Configuration"), // "", ki18n("A global power management configurator for KDE Power Management System"), // KAboutData::License_GPL, ki18n("(c), 2010 Dario Freddi"), // ki18n("From this module, you can configure the main Power Management daemon, assign profiles to " // "states, and do some advanced fine tuning on battery handling")); // // about->addAuthor(ki18n("Dario Freddi"), ki18n("Maintainer") , "drf@kde.org", // "http://drfav.wordpress.com"); // // setAboutData(about); setupUi(this); fillUi(); QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.Solid.PowerManagement", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); connect(watcher, SIGNAL(serviceRegistered(QString)), this, SLOT(onServiceRegistered(QString))); connect(watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(onServiceUnregistered(QString))); if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.Solid.PowerManagement")) { onServiceRegistered("org.kde.Solid.PowerManagement"); } else { onServiceUnregistered("org.kde.Solid.PowerManagement"); } } GeneralPage::~GeneralPage() { } void GeneralPage::fillUi() { bool hasPowerSupplyBattery = false; bool hasPeripheralBattery = false; Q_FOREACH (const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString())) { const Solid::Battery *b = qobject_cast (device.asDeviceInterface(Solid::DeviceInterface::Battery)); if (b->isPowerSupply()) { hasPowerSupplyBattery = true; } else { hasPeripheralBattery = true; } } 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)) { BatteryCriticalCombo->addItem(QIcon::fromTheme("system-suspend"), i18n("Suspend"), PowerDevil::BundledActions::SuspendSession::ToRamMode); } if (methods.contains(Solid::PowerManagement::HibernateState)) { 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")); // modified fields... connect(notificationsButton, SIGNAL(clicked()), SLOT(configureNotifications())); connect(lowSpin, SIGNAL(valueChanged(int)), SLOT(changed())); connect(criticalSpin, SIGNAL(valueChanged(int)), SLOT(changed())); connect(lowPeripheralSpin, SIGNAL(valueChanged(int)), SLOT(changed())); connect(BatteryCriticalCombo, SIGNAL(currentIndexChanged(int)), SLOT(changed())); if (!hasPowerSupplyBattery) { BatteryCriticalLabel->hide(); BatteryCriticalCombo->hide(); lowLabel->hide(); lowSpin->hide(); criticalLabel->hide(); criticalSpin->hide(); } if (!hasPeripheralBattery) { lowPeripheralLabel->hide(); lowPeripheralSpin->hide(); } if (!hasPeripheralBattery && !hasPeripheralBattery) { batteryLevelsLabel->hide(); } } void GeneralPage::load() { lowSpin->setValue(PowerDevilSettings::batteryLowLevel()); criticalSpin->setValue(PowerDevilSettings::batteryCriticalLevel()); lowPeripheralSpin->setValue(PowerDevilSettings::peripheralBatteryLowLevel()); BatteryCriticalCombo->setCurrentIndex(BatteryCriticalCombo->findData(PowerDevilSettings::batteryCriticalAction())); } void GeneralPage::configureNotifications() { KNotifyConfigWidget::configure(this, "powerdevil"); } void GeneralPage::save() { PowerDevilSettings::setBatteryLowLevel(lowSpin->value()); PowerDevilSettings::setBatteryCriticalLevel(criticalSpin->value()); PowerDevilSettings::setPeripheralBatteryLowLevel(lowPeripheralSpin->value()); PowerDevilSettings::setBatteryCriticalAction(BatteryCriticalCombo->itemData(BatteryCriticalCombo->currentIndex()).toInt()); PowerDevilSettings::self()->save(); // Notify Daemon QDBusMessage call = QDBusMessage::createMethodCall("org.kde.Solid.PowerManagement", "/org/kde/Solid/PowerManagement", "org.kde.Solid.PowerManagement", "refreshStatus"); // Perform call QDBusConnection::sessionBus().asyncCall(call); // And now we are set with no change Q_EMIT changed(false); } void GeneralPage::defaults() { KCModule::defaults(); } void GeneralPage::onServiceRegistered(const QString& service) { Q_UNUSED(service); - if (!m_errorOverlay.isNull()) { - m_errorOverlay.data()->deleteLater(); + if (m_errorOverlay) { + m_errorOverlay->deleteLater(); + m_errorOverlay = nullptr; } } void GeneralPage::onServiceUnregistered(const QString& service) { Q_UNUSED(service); - if (!m_errorOverlay.isNull()) { - m_errorOverlay.data()->deleteLater(); + if (m_errorOverlay) { + m_errorOverlay->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); } #include "GeneralPage.moc" diff --git a/kcmodule/global/GeneralPage.h b/kcmodule/global/GeneralPage.h index 9f513964..201e0480 100644 --- a/kcmodule/global/GeneralPage.h +++ b/kcmodule/global/GeneralPage.h @@ -1,50 +1,50 @@ /*************************************************************************** * Copyright (C) 2008 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 GENERALPAGE_H #define GENERALPAGE_H #include #include "ui_generalPage.h" class ErrorOverlay; class GeneralPage : public KCModule, private Ui_generalPage { Q_OBJECT public: GeneralPage(QWidget *parent, const QVariantList &args); virtual ~GeneralPage(); void fillUi(); void load(); void save(); virtual void defaults(); private Q_SLOTS: void configureNotifications(); void onServiceRegistered(const QString &service); void onServiceUnregistered(const QString &service); private: - QWeakPointer< ErrorOverlay > m_errorOverlay; + ErrorOverlay *m_errorOverlay = nullptr; }; #endif /* GENERALPAGE_H */ diff --git a/kcmodule/profiles/EditPage.cpp b/kcmodule/profiles/EditPage.cpp index c164950a..135365bf 100644 --- a/kcmodule/profiles/EditPage.cpp +++ b/kcmodule/profiles/EditPage.cpp @@ -1,279 +1,280 @@ /*************************************************************************** * Copyright (C) 2008-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 "EditPage.h" #include "actioneditwidget.h" #include "ErrorOverlay.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include K_PLUGIN_FACTORY(PowerDevilProfilesKCMFactory, registerPlugin(); ) EditPage::EditPage(QWidget *parent, const QVariantList &args) : KCModule(0, parent, args) { setButtons(Apply | Help | Default); // KAboutData *about = // new KAboutData("powerdevilprofilesconfig", "powerdevilprofilesconfig", ki18n("Power Profiles Configuration"), // "", ki18n("A profile configurator for KDE Power Management System"), // KAboutData::License_GPL, ki18n("(c), 2010 Dario Freddi"), // ki18n("From this module, you can manage KDE Power Management System's power profiles, by tweaking " // "existing ones or creating new ones.")); // // about->addAuthor(ki18n("Dario Freddi"), ki18n("Maintainer") , "drf@kde.org", // "http://drfav.wordpress.com"); // // setAboutData(about); setupUi(this); 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) ); m_profilesConfig->reparseConfiguration(); } qCDebug(POWERDEVIL) << m_profilesConfig.data()->groupList() << m_profilesConfig.data()->entryMap().keys(); // Create widgets for each profile ActionEditWidget *editWidget = new ActionEditWidget("AC", tabWidget); m_editWidgets.insert("AC", editWidget); acWidgetLayout->addWidget(editWidget); connect(editWidget, SIGNAL(changed(bool)), this, SLOT(onChanged(bool))); editWidget = new ActionEditWidget("Battery", tabWidget); m_editWidgets.insert("Battery", editWidget); batteryWidgetLayout->addWidget(editWidget); connect(editWidget, SIGNAL(changed(bool)), this, SLOT(onChanged(bool))); editWidget = new ActionEditWidget("LowBattery", tabWidget); m_editWidgets.insert("LowBattery", editWidget); lowBatteryWidgetLayout->addWidget(editWidget); connect(editWidget, SIGNAL(changed(bool)), this, SLOT(onChanged(bool))); QDBusServiceWatcher *watcher = new QDBusServiceWatcher("org.kde.Solid.PowerManagement", QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForRegistration | QDBusServiceWatcher::WatchForUnregistration, this); connect(watcher, SIGNAL(serviceRegistered(QString)), this, SLOT(onServiceRegistered(QString))); connect(watcher, SIGNAL(serviceUnregistered(QString)), this, SLOT(onServiceUnregistered(QString))); bool hasBattery = false; Q_FOREACH(const Solid::Device &device, Solid::Device::listFromType(Solid::DeviceInterface::Battery, QString())) { const Solid::Battery *b = qobject_cast (device.asDeviceInterface(Solid::DeviceInterface::Battery)); if (b->isPowerSupply() && (b->type() == Solid::Battery::PrimaryBattery || b->type() == Solid::Battery::UpsBattery)) { hasBattery = true; break; } } if (!hasBattery) { tabWidget->setTabEnabled(1, false); tabWidget->setTabEnabled(2, false); tabWidget->tabBar()->hide(); } if (QDBusConnection::sessionBus().interface()->isServiceRegistered("org.kde.Solid.PowerManagement")) { onServiceRegistered("org.kde.Solid.PowerManagement"); } else { onServiceUnregistered("org.kde.Solid.PowerManagement"); } } void EditPage::onChanged(bool value) { ActionEditWidget *editWidget = qobject_cast< ActionEditWidget* >(sender()); if (!editWidget) { return; } m_profileEdited[editWidget->configName()] = value; if (value) { Q_EMIT changed(true); } checkAndEmitChanged(); } void EditPage::load() { qCDebug(POWERDEVIL) << "Loading routine called"; for (QHash< QString, ActionEditWidget* >::const_iterator i = m_editWidgets.constBegin(); i != m_editWidgets.constEnd(); ++i) { i.value()->load(); m_profileEdited[i.value()->configName()] = false; } } void EditPage::save() { for (auto it = m_editWidgets.constBegin(); it != m_editWidgets.constEnd(); ++it) { (*it)->save(); } notifyDaemon(); Q_EMIT changed(false); } void EditPage::notifyDaemon() { QDBusConnection::sessionBus().asyncCall( QDBusMessage::createMethodCall( QStringLiteral("org.kde.Solid.PowerManagement"), QStringLiteral("/org/kde/Solid/PowerManagement"), QStringLiteral("org.kde.Solid.PowerManagement"), QStringLiteral("refreshStatus") ) ); } void EditPage::restoreDefaultProfiles() { // Confirm int ret = KMessageBox::warningContinueCancel(this, i18n("The KDE Power Management System will now generate a set of defaults " "based on your computer's capabilities. This will also erase " "all existing modifications you made. " "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) ); load(); notifyDaemon(); } } void EditPage::openUrl(const QString &url) { new KRun(QUrl(url), this); } void EditPage::defaults() { restoreDefaultProfiles(); } void EditPage::checkAndEmitChanged() { bool value = false; for (QHash< QString, bool >::const_iterator i = m_profileEdited.constBegin(); i != m_profileEdited.constEnd(); ++i) { if (i.value()) { value = i.value(); } } Q_EMIT changed(value); } void EditPage::onServiceRegistered(const QString& service) { Q_UNUSED(service); QDBusPendingCallWatcher *currentProfileWatcher = new QDBusPendingCallWatcher(QDBusConnection::sessionBus().asyncCall( QDBusMessage::createMethodCall( QStringLiteral("org.kde.Solid.PowerManagement"), QStringLiteral("/org/kde/Solid/PowerManagement"), QStringLiteral("org.kde.Solid.PowerManagement"), QStringLiteral("currentProfile") ) ), this); QObject::connect(currentProfileWatcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) { QDBusPendingReply reply = *watcher; if (!reply.isError()) { const QString ¤tProfile = reply.value(); if (currentProfile == QLatin1String("Battery")) { tabWidget->setCurrentIndex(1); } else if (currentProfile == QLatin1String("LowBattery")) { tabWidget->setCurrentIndex(2); } } watcher->deleteLater(); }); - if (!m_errorOverlay.isNull()) { - m_errorOverlay.data()->deleteLater(); + if (m_errorOverlay) { + m_errorOverlay->deleteLater(); + m_errorOverlay = nullptr; } } void EditPage::onServiceUnregistered(const QString& service) { Q_UNUSED(service); - if (!m_errorOverlay.isNull()) { - m_errorOverlay.data()->deleteLater(); + if (m_errorOverlay) { + m_errorOverlay->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); } #include "EditPage.moc" diff --git a/kcmodule/profiles/EditPage.h b/kcmodule/profiles/EditPage.h index f07f3ea5..f02868df 100644 --- a/kcmodule/profiles/EditPage.h +++ b/kcmodule/profiles/EditPage.h @@ -1,70 +1,70 @@ /*************************************************************************** * Copyright (C) 2008 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 EDITPAGE_H #define EDITPAGE_H #include #include #include "ui_profileEditPage.h" class ActionEditWidget; namespace PowerDevil { class ActionConfig; } class ErrorOverlay; class QCheckBox; class KToolBar; class EditPage : public KCModule, private Ui_profileEditPage { Q_OBJECT public: explicit EditPage(QWidget *parent, const QVariantList &args); virtual ~EditPage() = default; void load(); void save(); virtual void defaults(); private Q_SLOTS: void onChanged(bool changed); void restoreDefaultProfiles(); void notifyDaemon(); void openUrl(const QString &url); void onServiceRegistered(const QString &service); void onServiceUnregistered(const QString &service); void checkAndEmitChanged(); private: KSharedConfig::Ptr m_profilesConfig; QHash< QString, bool > m_profileEdited; - QWeakPointer< ErrorOverlay > m_errorOverlay; + ErrorOverlay *m_errorOverlay = nullptr; QHash< QString, ActionEditWidget* > m_editWidgets; }; #endif /* EDITPAGE_H */