summaryrefslogtreecommitdiffstats
path: root/kdesktop/dbus/screensaver/screensaverInterfaceImpl.h
blob: 0b79f16937fffa158b9c503029da30ea362efdf7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 * screensaverInterfaceImpl.h
 *
 *  (C) 2024 Emanoil Kotsev
 *  deloptes (AT) gmail.com
 *
 * tdebase Copyright (C) 2009 tdebase development team
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
#ifndef KDESKTOP_SCREENSAVERINTERFACEIMPL_H_
#define KDESKTOP_SCREENSAVERINTERFACEIMPL_H_

#include <dcopref.h>
#include <tqpair.h>
#include <tqmap.h>
#include <tqdbusconnection.h>

#include "dbus/screensaver/screensaverInterface.h"

#define DBUS_SCREENSAVER_SERVICE      "TDEDbusScreenSaver"
#define DBUS_SCREENSAVER_SERVICE_NAME "org.freedesktop.ScreenSaver"
#define DBUS_SCREENSAVER_SERVICE_PATH "/org/freedesktop/ScreenSaver"

class ScreenSaverInterfaceImpl : public org::freedesktop::ScreenSaverInterface
{
    /**
     *
     * Idle inhibition is achieved by the application calling an Inhibit method on a well-known D-Bus name.
     *
     * Inhibition will stop when the UnInhibit method is called, or the application disconnects from the
     * D-Bus session bus (which usually happens upon exit).
     * Implementations of this well-known bus name must have an object /org/freedesktop/ScreenSaver which
     * implements the org.freedesktop.ScreenSaver interface.
     *
     * https://specifications.freedesktop.org/idle-inhibit-spec/latest/ch03.html
     */

public:
    ScreenSaverInterfaceImpl(TQT_DBusConnection&);
    virtual ~ScreenSaverInterfaceImpl();

    void restoreState();

protected:
    /**
     * void Lock()
     *       This method gets called when the service daemon
     *       locks the screen
     */
    virtual bool Lock(TQT_DBusError& error);

    /**
     *  Name:           SimulateUserActivity
     *  Args:           (none)
     *  Returns:        (nothing)
     *  Description:    Simulate use activity to prevent screen saver being spawned
     *
     *  Not implemented
     */
    virtual bool SimulateUserActivity(TQT_DBusError& error);

    /**
     *  Name:           GetActive
     *  Args:           (none)
     *  Returns:        DBUS_TYPE_BOOLEAN
     *  Descriptions:   Returns the value of the current state of activity.
     *                  See setActive().
     *
     * Not implemented
     */
    virtual bool GetActive(bool& arg0, TQT_DBusError& error);

    /**
     * Name:           GetActiveTime
     * Args:           (none)
     * Returns:        DBUS_TYPE_UINT32
     * Descriptions:   Returns the number of seconds that the screensaver has
     *                 been active.  Returns zero if the screensaver is not
     *                 active.
     *
     * Not implemented
     */
    virtual bool GetActiveTime(TQ_UINT32& seconds, TQT_DBusError& error);

    /**
     *
     * Name:           GetSessionIdleTime
     * Args:           (none)
     * Returns:        DBUS_TYPE_UINT32
     * Descriptions:   Returns the number of seconds that the session has
     *                 been idle.  Returns zero if the session is not idle.
     *
     * Not implemented
     */
    virtual bool GetSessionIdleTime(TQ_UINT32& seconds, TQT_DBusError& error);

    /**
     * Name:           SetActive
     * Args:           DBUS_TYPE_BOOLEAN state
     *                  state:  TRUE to request activation,
     *                          FALSE to request deactivation
     * Returns:        (nothing)
     * Description:    Request a change in the state of the screensaver.
     *                 Set to TRUE to request that the screensaver activate.
     *                 Active means that the screensaver has blanked the
     *                 screen and may run a graphical theme.  This does
     *                 not necessary mean that the screen is locked.
     *
     * Not implemented
     */
    virtual bool SetActive(bool& arg0, bool e, TQT_DBusError& error);

    /**
     *
     *  Name:           Inhibit
     *  Args:           DBUS_TYPE_STRING "application-name"
     *                      A unique identifier for the application, usually a reverse domain
     *                      (such as 'org.freedesktop.example').
     *                  DBUS_TYPE_STRING "reason for inhibit"
     *                      A human-readable and possibly translated string
     *                      explaining the reason why idleness is inhibited
     *                      (such as 'Playing a movie').
     *  Returns:        INT cookie
     *                  This is a random number used to identify the request.
     *                  To be passed to UnInhibit when done.
     *  Description:    Request that saving the screen due to system idleness
     *                  be blocked until UnInhibit is called or the
     *                  calling process exits.
     *
     * https://specifications.freedesktop.org/idle-inhibit-spec/latest/re01.html
     * https://lists.freedesktop.org/archives/xdg/2007-March/009187.html
     */

    virtual bool Inhibit(const TQString& application_name, const TQString& reason_for_inhibit, TQ_UINT32& cookie, TQT_DBusError& error);

    /**
     *
     * Name:           UnInhibit
     * Args:           DBUS_TYPE_UINT32 cookie
     *                      A cookie representing the inhibition request,
     *                      as returned by the 'Inhibit' function.
     * Returns:        (nothing)
     * Description:    Cancel a previous call to Inhibit() identified by the cookie.
     */
    virtual bool UnInhibit(TQ_UINT32 cookie, TQT_DBusError& error);

    /**
     *
     * Name:           Throttle
     * Args:           DBUS_TYPE_STRING "application-name"
     *                 DBUS_TYPE_STRING "reason for throttle"
     *                 INT cookie
     *                 This is a random number used to identify the request.
     * Description:    Request that running themes while the screensaver is
     *                 active be blocked until UnThrottle is called or the
     *                 calling process exits.
     *
     * Not implemented
     */
    virtual bool Throttle(const TQString& application_name, const TQString& reason_for_inhibit, TQ_UINT32& cookie, TQT_DBusError& error);

    /**
     * Name:           UnThrottle
     * Args:           DBUS_TYPE_UINT32 cookie
     * Returns:        (nothing)
     * Description:    Cancel a previous call to Throttle() identified by the cookie.
     * Not implemented
     */
    virtual bool UnThrottle(TQ_UINT32 cookie, TQT_DBusError& error);

    virtual void handleMethodReply(const TQT_DBusMessage& reply);
    virtual bool handleSignalSend(const TQT_DBusMessage& reply);
    virtual TQString objectPath() const;

private:
    bool screenSaverIsEnabled();
    bool forceScreenSaver(bool);

    struct Pair {
        TQString name;
        TQString value;
    };

    TQT_DBusConnection *m_connection;
    TQMap<TQ_UINT32,Pair> m_cookies;
    TQ_UINT32 m_ccount;

    DCOPRef m_kdesktopdcoprefobj;
    bool isScreenSaverEnabled;
};

#endif /* KDESKTOP_SCREENSAVERINTERFACEIMPL_H_ */