1 /***************************************************************************
2 * Copyright (C) 2008 by Dario Freddi <drf@kdemod.ath.cx> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA . *
18 ***************************************************************************/
20 #include "PowerDevilKCM.h"
22 #include "ConfigWidget.h"
23 #include "ErrorWidget.h"
25 #include <config-powerdevil.h>
27 #include <KPluginFactory>
29 #include <klocalizedstring.h>
31 #include <QtDBus/QDBusMessage>
32 #include <QtDBus/QDBusInterface>
33 #include <QtDBus/QDBusConnectionInterface>
35 K_PLUGIN_FACTORY(PowerDevilKCMFactory
,
36 registerPlugin
<PowerDevilKCM
>();
38 K_EXPORT_PLUGIN(PowerDevilKCMFactory("kcmpowerdevil"))
40 PowerDevilKCM::PowerDevilKCM(QWidget
*parent
, const QVariantList
&) :
41 KCModule(PowerDevilKCMFactory::componentData(), parent
),
42 m_dbus(QDBusConnection::sessionBus())
44 KGlobal::locale()->insertCatalog("powerdevil");
46 m_layout
= new QVBoxLayout(this);
47 m_layout
->setMargin(0);
49 setButtons(Apply
| Help
);
52 new KAboutData("kcmpowerdevil", "powerdevil", ki18n("PowerDevil Configuration"),
53 POWERDEVIL_VERSION
, ki18n("A configurator for PowerDevil"),
54 KAboutData::License_GPL
, ki18n("(c), 2008 Dario Freddi"),
55 ki18n("From this module, you can configure the Daemon, create "
56 "and edit powersaving profiles, and see your system's "
59 about
->addAuthor(ki18n("Dario Freddi"), ki18n("Main Developer") , "drf@kdemod.ath.cx",
60 "http://drfav.wordpress.com");
64 setQuickHelp(i18n("<h1>PowerDevil configuration</h1> <p>This module lets you configure "
65 "PowerDevil. PowerDevil is a daemon (so it runs in background) that is started "
66 "upon KDE startup.</p> <p>PowerDevil has 2 levels of configuration: a general one, "
67 "that is always applied, and a profile-based one, that lets you configure a specific "
68 "behavior in every situation. You can also have a look at your system capabilities in "
69 "the last tab. To get you started, first configure the options in the first 2 tabs. "
70 "Then switch to the fourth one, and create/edit your profiles. Last but not least, "
71 "assign your profiles in the third Tab. You do not have to restart PowerDevil, just click "
72 "\"Apply\", and you are done.</p>"));
78 void PowerDevilKCM::initModule()
80 QDBusInterface
iface("org.kde.kded", "/modules/powerdevil");
82 if (iface
.isValid()) {
83 QDBusConnection conn
= QDBusConnection::systemBus();
85 if (conn
.interface()->isServiceRegistered("org.freedesktop.PowerManagement") ||
86 conn
.interface()->isServiceRegistered("org.freedesktop.Policy.Power")) {
87 initError(i18n("Another power manager has been detected. PowerDevil will not start if "
88 "other power managers are active. If you want to use PowerDevil as your primary "
89 "power manager, please remove the existing one and restart PowerDevil service."));
91 } else if (conn
.interface()->isServiceRegistered("com.novell.powersave")) {
92 initError(i18n("It seems powersaved is running on this system. PowerDevil will not start if "
93 "other power managers are active. If you want to use PowerDevil as your primary "
94 "power manager, please stop powersaved and restart PowerDevil service."));
101 initError(i18n("PowerDevil seems not to be started. Either you have its service turned off, "
102 "or there is a problem in D-Bus."));
107 void PowerDevilKCM::initView()
109 unloadExistingWidgets();
111 m_widget
= new ConfigWidget(this);
112 m_layout
->addWidget(m_widget
);
114 connect(m_widget
, SIGNAL(changed(bool)), SIGNAL(changed(bool)));
115 connect(m_widget
, SIGNAL(reloadRequest()), SLOT(streamToDBus()));
116 connect(m_widget
, SIGNAL(reloadModule()), SLOT(forceReload()));
119 void PowerDevilKCM::initError(const QString
&error
)
121 unloadExistingWidgets();
123 m_error
= new ErrorWidget(this);
124 m_layout
->addWidget(m_error
);
126 m_error
->setError(error
);
129 void PowerDevilKCM::unloadExistingWidgets()
132 m_widget
->deleteLater();
136 m_error
->deleteLater();
140 void PowerDevilKCM::load()
148 void PowerDevilKCM::save()
158 void PowerDevilKCM::defaults()
163 void PowerDevilKCM::forceReload()
165 unloadExistingWidgets();
170 void PowerDevilKCM::streamToDBus()
172 QDBusMessage msg
= QDBusMessage::createMethodCall("org.kde.kded", "/modules/powerdevil",
173 "org.kde.PowerDevil", "reloadAndStream");
175 msg
= QDBusMessage::createMethodCall("org.kde.kded", "/modules/powerdevil",
176 "org.kde.PowerDevil", "refreshStatus");
178 msg
= QDBusMessage::createMethodCall("org.kde.kded", "/modules/powerdevil",
179 "org.kde.PowerDevil", "setUpPollingSystem");
181 msg
= QDBusMessage::createMethodCall("org.kde.kded", "/modules/powerdevil",
182 "org.kde.PowerDevil", "refreshStatus");
186 #include "PowerDevilKCM.moc"