1
/***************************************************************************
2
* Copyright (C) 2010 by Dario Freddi <drf@kde.org> *
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 "kdedpowerdevil.h"
22
#include "powerdevilfdoconnector.h"
23
#include "powermanagementadaptor.h"
24
#include "powermanagementpolicyagentadaptor.h"
26
#include "powerdevilbackendloader.h"
27
#include "powerdevilcore.h"
29
#include <QtCore/QTimer>
31
#include <QtDBus/QDBusConnection>
32
#include <QtDBus/QDBusConnectionInterface>
36
#include <KPluginFactory>
38
K_PLUGIN_FACTORY( PowerDevilFactory,
39
registerPlugin<KDEDPowerDevil>(); )
40
K_EXPORT_PLUGIN( PowerDevilFactory( "powerdevildaemon" ) )
42
#define POWERDEVIL_VERSION "1.99"
44
KDEDPowerDevil::KDEDPowerDevil(QObject* parent, const QVariantList &)
47
QTimer::singleShot(0, this, SLOT(init()));
50
KDEDPowerDevil::~KDEDPowerDevil()
54
void KDEDPowerDevil::init()
56
KGlobal::locale()->insertCatalog("powerdevil");
58
KAboutData aboutData("powerdevil", "powerdevil", ki18n("KDE Power Management System"),
59
POWERDEVIL_VERSION, ki18n("KDE Power Management System is PowerDevil, an "
60
"advanced, modular and lightweight Power Management "
62
KAboutData::License_GPL, ki18n("(c) 2010 MetalWorkers Co."),
63
KLocalizedString(), "http://www.kde.org");
65
aboutData.addAuthor(ki18n( "Dario Freddi" ), ki18n("Maintainer"), "drf@kde.org",
66
"http://drfav.wordpress.com");
68
if (QDBusConnection::systemBus().interface()->isServiceRegistered("org.freedesktop.PowerManagement") ||
69
QDBusConnection::systemBus().interface()->isServiceRegistered("com.novell.powersave") ||
70
QDBusConnection::systemBus().interface()->isServiceRegistered("org.freedesktop.Policy.Power")) {
71
kError() << "KDE Power Management system not initialized, another power manager has been detected";
75
m_core = new PowerDevil::Core(this, KComponentData(aboutData));
77
connect(m_core, SIGNAL(coreReady()), this, SLOT(onCoreReady()));
79
// Before doing anything, let's set up our backend
80
PowerDevil::BackendInterface *interface = PowerDevil::BackendLoader::loadBackend(m_core);
84
kError() << "KDE Power Management System init failed!";
88
kDebug() << "Backend loaded, loading core";
89
m_core->loadCore(interface);
93
void KDEDPowerDevil::onCoreReady()
95
kDebug() << "Core is ready, registering various services on the bus...";
96
//DBus logic for the core
97
new PowerManagementAdaptor(m_core);
98
new PowerDevil::FdoConnector(m_core);
100
QDBusConnection::sessionBus().registerService("org.kde.Solid.PowerManagement");
101
QDBusConnection::sessionBus().registerObject("/org/kde/Solid/PowerManagement", m_core);
103
QDBusConnection::systemBus().interface()->registerService("org.freedesktop.Policy.Power");
105
// Start the Policy Agent service
106
new PowerManagementPolicyAgentAdaptor(PowerDevil::PolicyAgent::instance());
108
QDBusConnection::sessionBus().registerService("org.kde.Solid.PowerManagement.PolicyAgent");
109
QDBusConnection::sessionBus().registerObject("/org/kde/Solid/PowerManagement/PolicyAgent", PowerDevil::PolicyAgent::instance());
112
#include "kdedpowerdevil.moc"