109
void AwayManager::simulateUserActivity()
114
109
void AwayManager::resetIdle()
116
// Set the time of the idleTimer to the current time.
117
111
m_idleTime.start();
120
int AwayManager::idleTime()
122
// Calculate the idle time in milliseconds.
123
return m_idleTime.elapsed();
126
void AwayManager::setManagedIdentitiesAway()
128
// Used to skip X-based activity checking for one round, to avoid jumping
129
// on residual mouse activity after manual screensaver activation.
132
// Call the base implementation.
133
AbstractAwayManager::setManagedIdentitiesAway();
136
void AwayManager::identitiesOnAutoAwayChanged()
138
if (m_idetitiesWithIdleTimesOnAutoAway.count() > 0)
114
void AwayManager::identitiesChanged()
116
QList<int> newIdentityList;
118
const QList<Server*> serverList = m_connectionManager->getServerList();
120
foreach (Server* server, serverList)
122
IdentityPtr identity = server->getIdentity();
124
if (identity && identity->getAutomaticAway() && server->isConnected())
125
newIdentityList.append(identity->id());
128
m_identitiesOnAutoAway = newIdentityList;
133
void AwayManager::identityOnline(int identityId)
135
IdentityPtr identity = Preferences::identityById(identityId);
137
if (identity && identity->getAutomaticAway() &&
138
!m_identitiesOnAutoAway.contains(identityId))
140
m_identitiesOnAutoAway.append(identityId);
146
void AwayManager::identityOffline(int identityId)
148
if (m_identitiesOnAutoAway.removeOne(identityId))
154
void AwayManager::toggleTimer()
156
if (m_identitiesOnAutoAway.count() > 0)
140
158
if (!m_activityTimer->isActive())
141
159
m_activityTimer->start(Preferences::self()->autoAwayPollInterval() * 1000);
248
void AwayManager::implementIdleAutoAway()
250
QHash<int, int>::ConstIterator it;
252
for (it = m_idetitiesWithIdleTimesOnAutoAway.constBegin(); it != m_idetitiesWithIdleTimesOnAutoAway.constEnd(); ++it)
254
// Check if the auto-away timeout (which the user has configured for the given identity)
255
// has already elapsed - if it has we mark the identity as away.
256
if (idleTime() >= it.value())
257
implementManagedAway(it.key());
261
void AwayManager::implementManagedUnaway(const QList<int>& identityList)
263
// Call the base implementation (which does all workflow logic).
264
AbstractAwayManager::implementManagedUnaway(identityList);
266
// Then reset the idle status as the user is not idle anymore.
244
void AwayManager::implementIdleAutoAway(bool activity)
250
const QList<Server*> serverList = m_connectionManager->getServerList();
252
foreach (Server* server, serverList)
254
IdentityPtr identity = server->getIdentity();
256
if (m_identitiesOnAutoAway.contains(identity->id()) && identity->getAutomaticUnaway()
257
&& server->isConnected() && server->isAway())
259
server->requestUnaway();
265
long int idleTime = m_idleTime.elapsed() / 1000;
267
QList<int> identitiesIdleTimeExceeded;
268
QList<int>::ConstIterator it;
270
for (it = m_identitiesOnAutoAway.constBegin(); it != m_identitiesOnAutoAway.constEnd(); ++it)
272
if (idleTime >= Preferences::identityById((*it))->getAwayInactivity() * 60)
273
identitiesIdleTimeExceeded.append((*it));
276
const QList<Server*> serverList = m_connectionManager->getServerList();
278
foreach (Server* server, serverList)
280
int identityId = server->getIdentity()->id();
282
if (identitiesIdleTimeExceeded.contains(identityId) && server->isConnected() && !server->isAway())
283
server->requestAway();
288
void AwayManager::setManagedIdentitiesAway()
290
// Used to skip X-based activity checking for one round, to avoid jumping
291
// on residual mouse activity after manual screensaver activation.
294
const QList<Server*> serverList = m_connectionManager->getServerList();
296
foreach (Server* server, serverList)
298
if (m_identitiesOnAutoAway.contains(server->getIdentity()->id()) && server->isConnected() && !server->isAway())
299
server->requestAway();
303
void AwayManager::setManagedIdentitiesUnaway()
305
const QList<Server*> serverList = m_connectionManager->getServerList();
307
foreach (Server* server, serverList)
309
IdentityPtr identity = server->getIdentity();
311
if (m_identitiesOnAutoAway.contains(identity->id()) && identity->getAutomaticUnaway()
312
&& server->isConnected() && server->isAway())
314
server->requestUnaway();
319
void AwayManager::requestAllAway(const QString& reason)
321
const QList<Server*> serverList = m_connectionManager->getServerList();
323
foreach (Server* server, serverList)
324
if (server->isConnected()) server->requestAway(reason);
327
void AwayManager::requestAllUnaway()
329
const QList<Server*> serverList = m_connectionManager->getServerList();
331
foreach (Server* server, serverList)
332
if (server->isConnected() && server->isAway()) server->requestUnaway();
335
void AwayManager::toggleGlobalAway(bool away)
343
void AwayManager::updateGlobalAwayAction(bool away)
345
// FIXME: For now, our only triggers for resetting the idle time
346
// are mouse movement and the screensaver getting disabled. This
347
// means that typing '/unaway' or '/back' does not reset the idle
348
// time and won't prevent AwayManager from setting a connection
349
// away again shortly after when its identity's maximum auto-away
350
// idle time, counted from the last mouse movement or screensaver
351
// deactivation rather than the actual last user activity (the key
352
// presses), has been exceeded. We work around this here by reset-
353
// ting the idle time whenever any connection changes its state to
354
// unaway in response to the server until we find a better solu-
355
// tion (i.e. a reliable way to let keyboard activity in the sys-
356
// tem reset the idle time).
357
if(!away) resetIdle();
359
Application* konvApp = static_cast<Application*>(kapp);
360
KToggleAction* awayAction = qobject_cast<KToggleAction*>(konvApp->getMainWindow()->actionCollection()->action("toggle_away"));
362
if (!awayAction) return;
366
const QList<Server*> serverList = m_connectionManager->getServerList();
369
foreach (Server* server, serverList)
371
if (server->isAway())
375
if (awayCount == serverList.count())
377
awayAction->setChecked(true);
378
awayAction->setIcon(KIcon("im-user-away"));
383
awayAction->setChecked(false);
384
awayAction->setIcon(KIcon("im-user"));
270
388
#include "awaymanager.moc"