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

« back to all changes in this revision

Viewing changes to powerdevil/daemon/powerdevilcore.h

  • 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
 
 
21
#ifndef POWERDEVILCORE_H
 
22
#define POWERDEVILCORE_H
 
23
 
 
24
#include "powerdevilbackendinterface.h"
 
25
 
 
26
#include <QtCore/QWeakPointer>
 
27
#include <QtCore/QStringList>
 
28
 
 
29
#include <KComponentData>
 
30
 
 
31
typedef QMap< QString, QString > StringStringMap;
 
32
 
 
33
class KDirWatch;
 
34
class QTimer;
 
35
class KNotification;
 
36
namespace Solid {
 
37
class Battery;
 
38
}
 
39
 
 
40
namespace PowerDevil
 
41
{
 
42
 
 
43
class BackendInterface;
 
44
class Action;
 
45
 
 
46
class KDE_EXPORT Core : public QObject
 
47
{
 
48
    Q_OBJECT
 
49
    Q_DISABLE_COPY(Core)
 
50
    Q_CLASSINFO("D-Bus Interface", "org.kde.Solid.PowerManagement")
 
51
 
 
52
public:
 
53
    explicit Core(QObject* parent, const KComponentData &componentData);
 
54
    virtual ~Core();
 
55
 
 
56
    void reloadProfile(int state);
 
57
 
 
58
    void emitNotification(const QString &evid, const QString &message = QString(),
 
59
                          const QString &iconname = "dialog-ok-apply");
 
60
 
 
61
    BackendInterface *backend();
 
62
 
 
63
    // More...
 
64
 
 
65
public Q_SLOTS:
 
66
    void loadCore(PowerDevil::BackendInterface *backend);
 
67
    // Set of common action - useful for the DBus interface
 
68
    uint backendCapabilities();
 
69
    void refreshStatus();
 
70
    void reloadProfile();
 
71
    void reloadCurrentProfile();
 
72
    void reparseConfiguration();
 
73
 
 
74
    StringStringMap availableProfiles() const;
 
75
 
 
76
    void loadProfile(const QString &name);
 
77
    QString currentProfile() const;
 
78
 
 
79
    int brightness() const;
 
80
    void setBrightness(int percent);
 
81
 
 
82
    qulonglong batteryRemainingTime() const;
 
83
 
 
84
    void increaseBrightness();
 
85
    void decreaseBrightness();
 
86
 
 
87
    void suspendToRam();
 
88
    void suspendToDisk();
 
89
    void suspendHybrid();
 
90
 
 
91
    void onResumeFromSuspend();
 
92
 
 
93
Q_SIGNALS:
 
94
    void coreReady();
 
95
    void profileChanged(const QString &newProfile);
 
96
    void configurationReloaded();
 
97
    void brightnessChanged(int percent);
 
98
    void batteryRemainingTimeChanged(qulonglong time);
 
99
    void resumingFromSuspend();
 
100
 
 
101
private:
 
102
    void registerActionTimeout(Action *action, int timeout);
 
103
    void unregisterActionTimeouts(Action *action);
 
104
 
 
105
    void triggerSuspendSession(uint action);
 
106
 
 
107
    friend class Action;
 
108
 
 
109
    BackendInterface *m_backend;
 
110
    QStringList m_loadedBatteriesUdi;
 
111
 
 
112
    QWeakPointer< KNotification > notification;
 
113
    KComponentData m_applicationData;
 
114
    KSharedConfigPtr m_profilesConfig;
 
115
 
 
116
    QString m_currentProfile;
 
117
 
 
118
    QHash< QString, int > m_batteriesPercent;
 
119
 
 
120
    QTimer *m_criticalBatteryTimer;
 
121
 
 
122
    // Idle time management
 
123
    QHash< int, int > m_registeredIdleTimeouts;
 
124
    QHash< Action*, QList< int > > m_registeredActionTimeouts;
 
125
    QList< Action* > m_pendingResumeFromIdleActions;
 
126
 
 
127
private Q_SLOTS:
 
128
    void onBackendReady();
 
129
    void onBackendError(const QString &error);
 
130
    void onAcAdapterStateChanged(PowerDevil::BackendInterface::AcAdapterState);
 
131
    void onBatteryChargePercentChanged(int,const QString&);
 
132
    void onBrightnessChanged(float);
 
133
    void onBatteryRemainingTimeChanged(qulonglong);
 
134
    void onKIdleTimeoutReached(int,int);
 
135
    void onResumingFromIdle();
 
136
    void onDeviceAdded(const QString &udi);
 
137
    void onDeviceRemoved(const QString &udi);
 
138
    void onCriticalBatteryTimerExpired();
 
139
    void checkBatteryStatus();
 
140
    void powerOffButtonTriggered();
 
141
};
 
142
 
 
143
}
 
144
 
 
145
Q_DECLARE_METATYPE(StringStringMap)
 
146
 
 
147
#endif // POWERDEVILCORE_H