Unity 8
DBusUnitySessionService Class Reference

#include <plugins/Unity/Session/dbusunitysessionservice.h>

Inherits UnityDBusObject.

Public Slots

Q_SCRIPTABLE void Logout ()
 
Q_SCRIPTABLE void Reboot ()
 
Q_SCRIPTABLE void Shutdown ()
 
Q_SCRIPTABLE void Suspend ()
 
Q_SCRIPTABLE void Hibernate ()
 
Q_SCRIPTABLE void HybridSleep ()
 
Q_SCRIPTABLE void RequestLogout ()
 
Q_SCRIPTABLE void RequestReboot ()
 
Q_SCRIPTABLE void RequestShutdown ()
 
Q_SCRIPTABLE void EndSession ()
 
Q_SCRIPTABLE bool CanHibernate () const
 
Q_SCRIPTABLE bool CanSuspend () const
 
Q_SCRIPTABLE bool CanHybridSleep () const
 
Q_SCRIPTABLE bool CanReboot () const
 
Q_SCRIPTABLE bool CanShutdown () const
 
Q_SCRIPTABLE bool CanLock () const
 
Q_SCRIPTABLE QString UserName () const
 
Q_SCRIPTABLE QString RealName () const
 
Q_SCRIPTABLE QString HostName () const
 
Q_SCRIPTABLE void PromptLock ()
 
Q_SCRIPTABLE void Lock ()
 
Q_SCRIPTABLE bool IsLocked () const
 

Signals

Q_SCRIPTABLE void LogoutRequested (bool have_inhibitors)
 
void logoutRequested (bool have_inhibitors)
 
Q_SCRIPTABLE void RebootRequested (bool have_inhibitors)
 
void rebootRequested (bool have_inhibitors)
 
Q_SCRIPTABLE void ShutdownRequested (bool have_inhibitors)
 
void shutdownRequested (bool have_inhibitors)
 
Q_SCRIPTABLE void LogoutReady ()
 
void logoutReady ()
 
Q_SCRIPTABLE void LockRequested ()
 
void lockRequested ()
 
Q_SCRIPTABLE void Locked ()
 
Q_SCRIPTABLE void Unlocked ()
 

Public Member Functions

Q_INVOKABLE void logout ()
 
Q_INVOKABLE void reboot ()
 
Q_INVOKABLE void shutdown ()
 
Q_INVOKABLE void endSession ()
 

Detailed Description

DBusUnitySessionService provides com.canonical.Unity.Session dbus interface.

com.canonical.Unity.Session interface provides public methods and signals to handle eg. Logout/Reboot/Shutdown.

Definition at line 34 of file dbusunitysessionservice.h.

Member Function Documentation

bool DBusUnitySessionService::CanHibernate ( ) const
slot
Returns
whether the system is capable of hibernating

Definition at line 266 of file dbusunitysessionservice.cpp.

267 {
268  return d->checkLogin1Call(QStringLiteral("CanHibernate"));
269 }
bool DBusUnitySessionService::CanHybridSleep ( ) const
slot
Returns
whether the system is capable of hybrid sleep
Since
unity8

Definition at line 276 of file dbusunitysessionservice.cpp.

277 {
278  return d->checkLogin1Call(QStringLiteral("CanHybridSleep"));
279 }
bool DBusUnitySessionService::CanLock ( ) const
slot
Returns
whether the system is capable of locking the session

Definition at line 291 of file dbusunitysessionservice.cpp.

292 {
293  return true; // FIXME
294 }
bool DBusUnitySessionService::CanReboot ( ) const
slot
Returns
whether the system is capable of rebooting
Since
unity8

Definition at line 281 of file dbusunitysessionservice.cpp.

282 {
283  return d->checkLogin1Call(QStringLiteral("CanReboot"));
284 }
bool DBusUnitySessionService::CanShutdown ( ) const
slot
Returns
whether the system is capable of shutting down

Definition at line 286 of file dbusunitysessionservice.cpp.

287 {
288  return d->checkLogin1Call(QStringLiteral("CanPowerOff"));
289 }
bool DBusUnitySessionService::CanSuspend ( ) const
slot
Returns
whether the system is capable of suspending

Definition at line 271 of file dbusunitysessionservice.cpp.

272 {
273  return d->checkLogin1Call(QStringLiteral("CanSuspend"));
274 }
void DBusUnitySessionService::EndSession ( )
slot

Issue an EndSession request.

This method calls the EndSession() Upstart DBus method on the current DBus session bus.

Definition at line 257 of file dbusunitysessionservice.cpp.

258 {
259  const QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("com.ubuntu.Upstart"),
260  QStringLiteral("/com/ubuntu/Upstart"),
261  QStringLiteral("com.ubuntu.Upstart0_6"),
262  QStringLiteral("EndSession"));
263  QDBusConnection::sessionBus().asyncCall(msg);
264 }
void DBusUnitySessionService::Hibernate ( )
slot

Hibernate the system

This method puts the system into hibernation without user's confirmation.

Definition at line 395 of file dbusunitysessionservice.cpp.

396 {
397  d->makeLogin1Call(QStringLiteral("Hibernate"), {false});
398 }
QString DBusUnitySessionService::HostName ( ) const
slot
Returns
the local hostname

Definition at line 320 of file dbusunitysessionservice.cpp.

321 {
322  char hostName[512];
323  if (gethostname(hostName, sizeof(hostName)) == -1) {
324  qWarning() << "Could not determine local hostname";
325  return QString();
326  }
327  hostName[sizeof(hostName) - 1] = '\0';
328  return QString::fromLocal8Bit(hostName);
329 }
void DBusUnitySessionService::HybridSleep ( )
slot

Hybrid sleep

This method puts the system into hybrid sleep without user's confirmation.

Since
unity8

Definition at line 400 of file dbusunitysessionservice.cpp.

401 {
402  d->makeLogin1Call(QStringLiteral("HybridSleep"), {false});
403 }
bool DBusUnitySessionService::IsLocked ( ) const
slot
Returns
whether the session is currently locked

Definition at line 363 of file dbusunitysessionservice.cpp.

364 {
365  return !d->isSessionActive;
366 }
void DBusUnitySessionService::Lock ( )
slot

Locks the session immediately

Definition at line 337 of file dbusunitysessionservice.cpp.

338 {
339  // lock the session using the org.freedesktop.DisplayManager system DBUS service
340  const QString sessionPath = QString::fromLocal8Bit(qgetenv("XDG_SESSION_PATH"));
341  QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.DisplayManager"),
342  sessionPath,
343  QStringLiteral("org.freedesktop.DisplayManager.Session"),
344  QStringLiteral("Lock"));
345 
346  QDBusPendingCall pendingCall = QDBusConnection::systemBus().asyncCall(msg);
347  QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pendingCall, this);
348  connect(watcher, &QDBusPendingCallWatcher::finished,
349  this, [this](QDBusPendingCallWatcher* watcher) {
350 
351  QDBusPendingReply<QVariant> reply = *watcher;
352  watcher->deleteLater();
353  if (reply.isError()) {
354  qWarning() << "Lock call failed" << reply.error().message();
355  return;
356  }
357 
358  // emit Locked when the call succeeds
359  Q_EMIT Locked();
360  });
361 }
Q_SCRIPTABLE void Locked()
Q_SCRIPTABLE void DBusUnitySessionService::Locked ( )
signal

Emitted after the session has been locked.

Q_SCRIPTABLE void DBusUnitySessionService::LockRequested ( )
signal

Emitted as a result of calling PromptLock()

void DBusUnitySessionService::Logout ( )
slot

Logout the system.

This method directly logs out the system without user's confirmation. Ordinary applications should avoid calling this method. Please call RequestLogout() to ask the user to decide logout or not.

Definition at line 250 of file dbusunitysessionservice.cpp.

251 {
252  // TODO ask the apps to quit and then emit the signal
253  Q_EMIT LogoutReady();
254  Q_EMIT logoutReady();
255 }
Q_SCRIPTABLE void LogoutReady()
Q_SCRIPTABLE void DBusUnitySessionService::LogoutReady ( )
signal

LogoutReady signal

This signal is emitted when all the apps are closed. And the system is safe to logout.

Q_SCRIPTABLE void DBusUnitySessionService::LogoutRequested ( bool  have_inhibitors)
signal

LogoutRequested signal

This signal is emitted when some applications request the system to logout.

Parameters
have_inhibitorsif there are any special running applications which inhibit the logout.
void DBusUnitySessionService::PromptLock ( )
slot

Request that the session get locked, emits signal LockRequested()

Definition at line 331 of file dbusunitysessionservice.cpp.

332 {
333  Q_EMIT LockRequested();
334  Q_EMIT lockRequested();
335 }
Q_SCRIPTABLE void LockRequested()
QString DBusUnitySessionService::RealName ( ) const
slot
Returns
the real name of the current user

Definition at line 306 of file dbusunitysessionservice.cpp.

307 {
308  struct passwd *p = getpwuid(geteuid());
309  if (p) {
310  const QString gecos = QString::fromLocal8Bit(p->pw_gecos);
311  if (!gecos.isEmpty()) {
312  const QStringList splitGecos = gecos.split(QLatin1Char(','));
313  return splitGecos.first();
314  }
315  }
316 
317  return QString();
318 }
void DBusUnitySessionService::Reboot ( )
slot

Reboot the system.

This method directly reboots the system without user's confirmation. Ordinary applications should avoid calling this method. Please call RequestReboot() to ask the user to decide reboot or not.

Definition at line 374 of file dbusunitysessionservice.cpp.

375 {
376  d->makeLogin1Call(QStringLiteral("Reboot"), {false});
377 }
Q_SCRIPTABLE void DBusUnitySessionService::RebootRequested ( bool  have_inhibitors)
signal

RebootRequested signal

This signal is emitted when some applications request the system to reboot.

Parameters
have_inhibitorsif there are any special running applications which inhibit the reboot.
void DBusUnitySessionService::RequestLogout ( )
slot

Issue a logout request.

This method emits the LogoutRequested signal to the shell with a boolean which indicates if there's any inhibitors. The shell should receive this signal and display a dialog to ask the user to confirm the logout action. If confirmed, shell can call Logout() method to logout.

Definition at line 368 of file dbusunitysessionservice.cpp.

369 {
370  Q_EMIT LogoutRequested(false);
371  Q_EMIT logoutRequested(false);
372 }
Q_SCRIPTABLE void LogoutRequested(bool have_inhibitors)
void DBusUnitySessionService::RequestReboot ( )
slot

Issue a reboot request.

This method emits the RebootRequested signal to the shell with a boolean which indicates if there's any inhibitors. The shell should receive this signal and display a dialog to ask the user to confirm the reboot action. If confirmed, shell can call Reboot() method to reboot.

Definition at line 379 of file dbusunitysessionservice.cpp.

380 {
381  Q_EMIT RebootRequested(false);
382  Q_EMIT rebootRequested(false);
383 }
Q_SCRIPTABLE void RebootRequested(bool have_inhibitors)
void DBusUnitySessionService::RequestShutdown ( )
slot

Issue a shutdown request.

This method emits the ShutdownRequested signal to the shell with a boolean which indicates if there's any inhibitors. The shell should receive this signal and display a dialog to ask the user to confirm the reboot action. If confirmed, shell can call Shutdown() method to shutdown.

Definition at line 405 of file dbusunitysessionservice.cpp.

406 {
407  Q_EMIT ShutdownRequested(false);
408  Q_EMIT shutdownRequested(false);
409 }
Q_SCRIPTABLE void ShutdownRequested(bool have_inhibitors)
void DBusUnitySessionService::Shutdown ( )
slot

Shutdown the system.

This method directly shuts down the system without user's confirmation. Ordinary applications should avoid calling this method. Please call RequestShutdown() to ask the user to decide shutdown or not.

Definition at line 385 of file dbusunitysessionservice.cpp.

386 {
387  d->makeLogin1Call(QStringLiteral("PowerOff"), {false});
388 }
Q_SCRIPTABLE void DBusUnitySessionService::ShutdownRequested ( bool  have_inhibitors)
signal

ShutdownRequested signal

This signal is emitted when some applications request the system to shutdown.

Parameters
have_inhibitorsif there are any special running applications which inhibit the shutdown.
void DBusUnitySessionService::Suspend ( )
slot

Suspend the system

This method puts the system into sleep without user's confirmation.

Definition at line 390 of file dbusunitysessionservice.cpp.

391 {
392  d->makeLogin1Call(QStringLiteral("Suspend"), {false});
393 }
Q_SCRIPTABLE void DBusUnitySessionService::Unlocked ( )
signal

Emitted after the session has been unlocked.

QString DBusUnitySessionService::UserName ( ) const
slot
Returns
the login name of the current user

Definition at line 296 of file dbusunitysessionservice.cpp.

297 {
298  struct passwd *p = getpwuid(geteuid());
299  if (p) {
300  return QString::fromUtf8(p->pw_name);
301  }
302 
303  return QString();
304 }

The documentation for this class was generated from the following files: