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

« back to all changes in this revision

Viewing changes to powerdevil/daemon/powerdevilpolicyagent.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 POWERDEVIL_POWERDEVILPOLICYAGENT_H
 
22
#define POWERDEVIL_POWERDEVILPOLICYAGENT_H
 
23
 
 
24
#include <QtCore/QObject>
 
25
#include <QtCore/QHash>
 
26
#include <QtCore/QWeakPointer>
 
27
 
 
28
#include <QtDBus/QDBusContext>
 
29
 
 
30
#include <kdemacros.h>
 
31
 
 
32
class QDBusServiceWatcher;
 
33
class QDBusInterface;
 
34
 
 
35
namespace PowerDevil
 
36
{
 
37
 
 
38
class KDE_EXPORT PolicyAgent : public QObject, protected QDBusContext
 
39
{
 
40
    Q_OBJECT
 
41
    Q_DISABLE_COPY(PolicyAgent)
 
42
 
 
43
    Q_CLASSINFO("D-Bus Interface", "org.kde.Solid.PowerManagement.PolicyAgent")
 
44
 
 
45
public:
 
46
    enum RequiredPolicy {
 
47
        None = 0,
 
48
        InterruptSession = 1,
 
49
        ChangeProfile = 2,
 
50
        ChangeScreenSettings = 4
 
51
    };
 
52
    Q_DECLARE_FLAGS(RequiredPolicies, RequiredPolicy)
 
53
 
 
54
    static PolicyAgent *instance();
 
55
 
 
56
    virtual ~PolicyAgent();
 
57
 
 
58
    /**
 
59
     * This function performs a policy check on given policies, and returns a set of unsatisfiable policies,
 
60
     * or \c None if all the policies are satisfiable and the action can be carried on.
 
61
     */
 
62
    RequiredPolicies requirePolicyCheck(RequiredPolicies policies);
 
63
 
 
64
    RequiredPolicies unavailablePolicies();
 
65
 
 
66
public Q_SLOTS:
 
67
    // Exported slots
 
68
    uint AddInhibition(uint types, const QString &appName, const QString &reason);
 
69
    void ReleaseInhibition(uint cookie);
 
70
 
 
71
    void releaseAllInhibitions();
 
72
 
 
73
Q_SIGNALS:
 
74
    void unavailablePoliciesChanged(PowerDevil::PolicyAgent::RequiredPolicies newpolicies);
 
75
 
 
76
private Q_SLOTS:
 
77
    void onServiceUnregistered(const QString &serviceName);
 
78
    void onConsoleKitRegistered(const QString&);
 
79
    void onConsoleKitUnregistered(const QString&);
 
80
    void onConsoleKitActiveSessionChanged(const QString &activeSession);
 
81
 
 
82
private:
 
83
    explicit PolicyAgent(QObject* parent = 0);
 
84
 
 
85
    void init();
 
86
    void startSessionInterruption();
 
87
    void finishSessionInterruption();
 
88
 
 
89
    void addInhibitionTypeHelper(uint cookie, RequiredPolicies types);
 
90
 
 
91
    // This function serves solely for fd.o connector
 
92
    uint addInhibitionWithExplicitDBusService(uint types, const QString &appName,
 
93
                                              const QString &reason, const QString &service);
 
94
 
 
95
    bool m_ckAvailable;
 
96
    QWeakPointer< QDBusInterface > m_ckSessionInterface;
 
97
    QWeakPointer< QDBusInterface > m_ckSeatInterface;
 
98
    bool m_sessionIsBeingInterrupted;
 
99
 
 
100
    QHash< uint, QPair< QString, QString > > m_cookieToAppName;
 
101
    QHash< uint, QString > m_cookieToBusService;
 
102
    QHash< RequiredPolicy, QList< uint > > m_typesToCookie;
 
103
 
 
104
    uint m_lastCookie;
 
105
 
 
106
    QWeakPointer< QDBusServiceWatcher > m_busWatcher;
 
107
    QWeakPointer< QDBusServiceWatcher > m_ckWatcher;
 
108
 
 
109
    bool m_wasLastActiveSession;
 
110
 
 
111
    friend class Core;
 
112
    friend class FdoConnector;
 
113
};
 
114
 
 
115
}
 
116
 
 
117
#endif // POWERDEVIL_POWERDEVILPOLICYAGENT_H