~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to powerdevil/daemon/kdedpowerdevil.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010 by Dario Freddi <drf@kde.org>                      *
 
3
 *                                                                         *
 
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.                                   *
 
8
 *                                                                         *
 
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.                          *
 
13
 *                                                                         *
 
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
 ***************************************************************************/
 
19
 
 
20
#include "kdedpowerdevil.h"
 
21
 
 
22
#include "powerdevilfdoconnector.h"
 
23
#include "powermanagementadaptor.h"
 
24
#include "powermanagementpolicyagentadaptor.h"
 
25
 
 
26
#include "powerdevilbackendloader.h"
 
27
#include "powerdevilcore.h"
 
28
 
 
29
#include <QtCore/QTimer>
 
30
 
 
31
#include <QtDBus/QDBusConnection>
 
32
#include <QtDBus/QDBusConnectionInterface>
 
33
 
 
34
#include <KAboutData>
 
35
#include <KDebug>
 
36
#include <KPluginFactory>
 
37
 
 
38
K_PLUGIN_FACTORY( PowerDevilFactory,
 
39
                  registerPlugin<KDEDPowerDevil>(); )
 
40
K_EXPORT_PLUGIN( PowerDevilFactory( "powerdevildaemon" ) )
 
41
 
 
42
#define POWERDEVIL_VERSION "1.99"
 
43
 
 
44
KDEDPowerDevil::KDEDPowerDevil(QObject* parent, const QVariantList &)
 
45
    : KDEDModule(parent)
 
46
{
 
47
    QTimer::singleShot(0, this, SLOT(init()));
 
48
}
 
49
 
 
50
KDEDPowerDevil::~KDEDPowerDevil()
 
51
{
 
52
}
 
53
 
 
54
void KDEDPowerDevil::init()
 
55
{
 
56
    KGlobal::locale()->insertCatalog("powerdevil");
 
57
 
 
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 "
 
61
                                                   "daemon"),
 
62
                         KAboutData::License_GPL, ki18n("(c) 2010 MetalWorkers Co."),
 
63
                         KLocalizedString(), "http://www.kde.org");
 
64
 
 
65
    aboutData.addAuthor(ki18n( "Dario Freddi" ), ki18n("Maintainer"), "drf@kde.org",
 
66
                        "http://drfav.wordpress.com");
 
67
 
 
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";
 
72
        return;
 
73
    }
 
74
 
 
75
    m_core = new PowerDevil::Core(this, KComponentData(aboutData));
 
76
 
 
77
    connect(m_core, SIGNAL(coreReady()), this, SLOT(onCoreReady()));
 
78
 
 
79
    // Before doing anything, let's set up our backend
 
80
    PowerDevil::BackendInterface *interface = PowerDevil::BackendLoader::loadBackend(m_core);
 
81
 
 
82
    if (!interface) {
 
83
        // Ouch
 
84
        kError() << "KDE Power Management System init failed!";
 
85
        m_core->loadCore(0);
 
86
    } else {
 
87
        // Let's go!
 
88
        kDebug() << "Backend loaded, loading core";
 
89
        m_core->loadCore(interface);
 
90
    }
 
91
}
 
92
 
 
93
void KDEDPowerDevil::onCoreReady()
 
94
{
 
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);
 
99
 
 
100
    QDBusConnection::sessionBus().registerService("org.kde.Solid.PowerManagement");
 
101
    QDBusConnection::sessionBus().registerObject("/org/kde/Solid/PowerManagement", m_core);
 
102
 
 
103
    QDBusConnection::systemBus().interface()->registerService("org.freedesktop.Policy.Power");
 
104
 
 
105
    // Start the Policy Agent service
 
106
    new PowerManagementPolicyAgentAdaptor(PowerDevil::PolicyAgent::instance());
 
107
 
 
108
    QDBusConnection::sessionBus().registerService("org.kde.Solid.PowerManagement.PolicyAgent");
 
109
    QDBusConnection::sessionBus().registerObject("/org/kde/Solid/PowerManagement/PolicyAgent", PowerDevil::PolicyAgent::instance());
 
110
}
 
111
 
 
112
#include "kdedpowerdevil.moc"