1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
/***************************************************************************
* Copyright (C) 2008 by Dario Freddi <drf@kde.org> *
* *
* 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 <Solid/Device>
#include <Solid/DeviceInterface>
#include <Solid/Battery>
#include <Solid/PowerManagement>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusReply>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusConnectionInterface>
#include <QtDBus/QDBusMetaType>
#include <QtDBus/QDBusServiceWatcher>
#include <KNotifyConfigWidget>
#include <KPluginFactory>
#include <KSharedConfig>
#include <KAboutData>
#include <KLocalizedString>
K_PLUGIN_FACTORY(PowerDevilGeneralKCMFactory,
registerPlugin<GeneralPage>();
)
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<const Solid::Battery*> (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();
}
}
void GeneralPage::onServiceUnregistered(const QString& service)
{
Q_UNUSED(service);
if (!m_errorOverlay.isNull()) {
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);
}
#include "GeneralPage.moc"
|