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
205
|
/*
* screensaverInterfaceImpl.cpp
*
*
* (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
*/
#include "screensaverInterfaceImpl.h"
ScreenSaverInterfaceImpl::ScreenSaverInterfaceImpl(TQT_DBusConnection &conn) :
m_connection(&conn), m_cookieCount(1), m_kdesktopdcoprefobj("kdesktop", "KScreensaverIface")
{
m_screenSaverEnabled = screenSaverIsEnabled();
tqDebug(TQString("ScreenSaver isEnabled = %1").arg(
(m_screenSaverEnabled) ? "yes" : "no"));
}
ScreenSaverInterfaceImpl::~ScreenSaverInterfaceImpl()
{
}
void ScreenSaverInterfaceImpl::restoreState()
{
// restore the state
setScreenSaverState(m_screenSaverEnabled);
}
/*!
* Implement virtual methods
*
*/
void ScreenSaverInterfaceImpl::handleMethodReply(const TQT_DBusMessage &reply)
{
m_connection->send(reply);
}
bool ScreenSaverInterfaceImpl::handleSignalSend(const TQT_DBusMessage &reply)
{
return true;
}
TQString ScreenSaverInterfaceImpl::objectPath() const
{
return TQString(DBUS_SCREENSAVER_SERVICE_PATH);
}
bool ScreenSaverInterfaceImpl::GetActive(bool &retval, TQT_DBusError &dbuserror)
{
DCOPReply reply = m_kdesktopdcoprefobj.call("isBlanked");
retval = false;
if (!reply.isValid())
{
TQString e("ScreenSaverInterfaceImpl::GetActive(): there was some error using DCOP.");
tqDebug(e);
dbuserror = TQT_DBusError::stdFailed(e);
return false;
}
else
{
if (!reply.get(retval))
{
TQString e("ScreenSaverInterfaceImpl::GetActive(): there was some error getting the value from DCOPReply");
tqDebug(e);
dbuserror = TQT_DBusError::stdFailed(e);
return false;
}
}
return true;
}
bool ScreenSaverInterfaceImpl::Lock(TQT_DBusError &dbuserror)
{
DCOPReply reply = m_kdesktopdcoprefobj.call("lock");
if (!reply.isValid())
{
TQString e("ScreenSaverInterfaceImpl::Lock: there was some error using DCOP.");
tqDebug(e);
dbuserror = TQT_DBusError::stdFailed(e);
return false;
}
return true;
}
bool ScreenSaverInterfaceImpl::SetActive(bool &retval, bool b, TQT_DBusError &dbuserror)
{
DCOPReply reply = (b == true) ? m_kdesktopdcoprefobj.call("save") : m_kdesktopdcoprefobj.call("quit") ;
if (!reply.isValid())
{
TQString e("ScreenSaverInterfaceImpl::SetActive: there was some error using DCOP.");
tqDebug(e);
dbuserror = TQT_DBusError::stdFailed(e);
retval = false;
}
else
{
emitActiveChanged(b);
retval = true;
}
return retval;
}
bool ScreenSaverInterfaceImpl::Inhibit(const TQString &application_name,
const TQString &reason_for_inhibit, TQ_UINT32 &cookie, TQT_DBusError &dbuserror)
{
//this is to make sure we have the actual state - it could have been changed meanwhile
//however some other application like kplayer may have disabled the screensaver
//when we call this function
//m_screenSaverEnabled = screenSaverIsEnabled();
bool ret = true;
if (m_screenSaverEnabled && m_cookies.isEmpty()) // disable only once
{
if (!setScreenSaverState(false))
{
dbuserror = TQT_DBusError::stdFailed(TQString("Failed to disable the screen saver"));
ret = false;
}
else
{
emitActiveChanged(true);
}
}
cookie = m_cookieCount++;
ScreenSaverInterfaceImpl::Pair v;
v.name = application_name;
v.value = reason_for_inhibit;
m_cookies[cookie] = v;
tqDebug(TQString("Inhibit: cookie(%1), application(%2), reason(%3)")
.arg(cookie).arg(m_cookies[cookie].name).arg(m_cookies[cookie].value).local8Bit());
return ret;
}
bool ScreenSaverInterfaceImpl::UnInhibit(TQ_UINT32 cookie, TQT_DBusError &dbuserror)
{
tqDebug(TQString("UnInhibit: cookie(%1), application(%2), reason(%3)")
.arg(cookie).arg(m_cookies[cookie].name).arg(m_cookies[cookie].value).local8Bit());
m_cookies.remove(cookie);
if (m_cookies.isEmpty())
{
// restore states when all applications finished
if (!setScreenSaverState(m_screenSaverEnabled))
{
dbuserror = TQT_DBusError::stdFailed(TQString("Failed to switch ScreenSaver %1!")
.arg((m_screenSaverEnabled) ? "on" : "off"));
return false;
}
emitActiveChanged(false);
}
return true;
}
bool ScreenSaverInterfaceImpl::screenSaverIsEnabled()
{
DCOPReply reply = m_kdesktopdcoprefobj.call("isEnabled");
bool retval = false;
if (!reply.isValid())
{
tqDebug("ScreenSaverInterfaceImpl::screenSaverIsEnabled(): there was some error using DCOP.");
return false;
}
else
{
if (!reply.get(retval))
{
tqDebug("ScreenSaverInterfaceImpl::screenSaverIsEnabled(): there was some error getting the value from DCOPReply");
return false;
}
}
return retval;
}
bool ScreenSaverInterfaceImpl::setScreenSaverState(bool on)
{
DCOPReply reply = m_kdesktopdcoprefobj.call("enable", on);
if (!reply.isValid())
{
tqDebug(TQString("Failed to switch ScreenSaver %1!").arg(
(on) ? "on" : "off"));
return false;
}
return true;
}
// End of File
|