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 ()
 
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

§ CanHibernate

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

Definition at line 273 of file dbusunitysessionservice.cpp.

274 {
275  return d->checkLogin1Call(QStringLiteral("CanHibernate"));
276 }

§ CanHybridSleep

bool DBusUnitySessionService::CanHybridSleep ( ) const
slot
Returns
whether the system is capable of hybrid sleep
Since
unity8

Definition at line 283 of file dbusunitysessionservice.cpp.

284 {
285  return d->checkLogin1Call(QStringLiteral("CanHybridSleep"));
286 }

§ CanLock

bool DBusUnitySessionService::CanLock ( ) const
slot
Returns
whether the system is capable of locking the session

Definition at line 298 of file dbusunitysessionservice.cpp.

299 {
300  return true; // FIXME
301 }

§ CanReboot

bool DBusUnitySessionService::CanReboot ( ) const
slot
Returns
whether the system is capable of rebooting
Since
unity8

Definition at line 288 of file dbusunitysessionservice.cpp.

289 {
290  return d->checkLogin1Call(QStringLiteral("CanReboot"));
291 }

§ CanShutdown

bool DBusUnitySessionService::CanShutdown ( ) const
slot
Returns
whether the system is capable of shutting down

Definition at line 293 of file dbusunitysessionservice.cpp.

294 {
295  return d->checkLogin1Call(QStringLiteral("CanPowerOff"));
296 }

§ CanSuspend

bool DBusUnitySessionService::CanSuspend ( ) const
slot
Returns
whether the system is capable of suspending

Definition at line 278 of file dbusunitysessionservice.cpp.

279 {
280  return d->checkLogin1Call(QStringLiteral("CanSuspend"));
281 }

§ EndSession

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 264 of file dbusunitysessionservice.cpp.

265 {
266  const QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("com.ubuntu.Upstart"),
267  QStringLiteral("/com/ubuntu/Upstart"),
268  QStringLiteral("com.ubuntu.Upstart0_6"),
269  QStringLiteral("EndSession"));
270  QDBusConnection::sessionBus().asyncCall(msg);
271 }

§ Hibernate

void DBusUnitySessionService::Hibernate ( )
slot

Hibernate the system

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

Definition at line 433 of file dbusunitysessionservice.cpp.

434 {
435  PromptLock();
436  d->makeLogin1Call(QStringLiteral("Hibernate"), {false});
437 }

§ HostName

QString DBusUnitySessionService::HostName ( ) const
slot
Returns
the local hostname

Definition at line 322 of file dbusunitysessionservice.cpp.

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

§ HybridSleep

void DBusUnitySessionService::HybridSleep ( )
slot

Hybrid sleep

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

Since
unity8

Definition at line 439 of file dbusunitysessionservice.cpp.

440 {
441  PromptLock();
442  d->makeLogin1Call(QStringLiteral("HybridSleep"), {false});
443 }

§ IsLocked

bool DBusUnitySessionService::IsLocked ( ) const
slot
Returns
whether the session is currently locked

Definition at line 400 of file dbusunitysessionservice.cpp.

401 {
402  return !d->isSessionActive;
403 }

§ Lock

void DBusUnitySessionService::Lock ( )
slot

Locks the session immediately

Definition at line 342 of file dbusunitysessionservice.cpp.

343 {
344  // Normal lock (with animation, as compared to PromptLock above). Usually
345  // used by indicator-session to lock the session in place.
346  //
347  // FIXME: We also -- as a bit of a hack around indicator-session not fully
348  // supporting a phone profile -- switch to greeter here. The unity7 flow is
349  // that the user chooses "Lock/Switch" from the indicator, and then can go
350  // to greeter by selecting "Switch" again from the indicator, which is now
351  // exposed by the desktop_lockscreen profile. But since in unity8, we try
352  // to expose most things all the time, we don't use the separate lockscreen
353  // profile. Instead, we just go directly to the greeter the first time
354  // a user presses "Lock/Switch". This isn't what this DBus call is
355  // supposed to do, but we can live with it for now.
356  //
357  // Here's a bug about indicator-session growing a converged Touch profile:
358  // https://launchpad.net/bugs/1557716
359  //
360  // We only do this here in the animated-lock call because that's the only
361  // time the indicator locks without also asking the display manager to
362  // switch sessions on us. And since we are switching screens, we also
363  // don't bother respecting the animate request, simply doing a PromptLock.
364  PromptLock();
365  switchToGreeter();
366 }

§ Locked

Q_SCRIPTABLE void DBusUnitySessionService::Locked ( )
signal

Emitted after the session has been locked.

§ LockRequested

Q_SCRIPTABLE void DBusUnitySessionService::LockRequested ( )
signal

Emitted as a result of calling PromptLock()

§ Logout

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 257 of file dbusunitysessionservice.cpp.

258 {
259  // TODO ask the apps to quit and then emit the signal
260  Q_EMIT LogoutReady();
261  Q_EMIT logoutReady();
262 }
Q_SCRIPTABLE void LogoutReady()

§ 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.

§ LogoutRequested

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.

§ PromptLock

void DBusUnitySessionService::PromptLock ( )
slot

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

Definition at line 333 of file dbusunitysessionservice.cpp.

334 {
335  // Prompt as in quick. No locking animation needed. Usually used by
336  // indicator-session in combination with a switch to greeter or other
337  // user session.
338  Q_EMIT LockRequested();
339  Q_EMIT lockRequested();
340 }
Q_SCRIPTABLE void LockRequested()

§ RealName

QString DBusUnitySessionService::RealName ( ) const
slot
Returns
the real name of the current user

Definition at line 308 of file dbusunitysessionservice.cpp.

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

§ Reboot

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 411 of file dbusunitysessionservice.cpp.

412 {
413  d->makeLogin1Call(QStringLiteral("Reboot"), {false});
414 }

§ RebootRequested

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.

§ RequestLogout

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 405 of file dbusunitysessionservice.cpp.

406 {
407  Q_EMIT LogoutRequested(false);
408  Q_EMIT logoutRequested(false);
409 }
Q_SCRIPTABLE void LogoutRequested(bool have_inhibitors)

§ RequestReboot

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 416 of file dbusunitysessionservice.cpp.

417 {
418  Q_EMIT RebootRequested(false);
419  Q_EMIT rebootRequested(false);
420 }
Q_SCRIPTABLE void RebootRequested(bool have_inhibitors)

§ RequestShutdown

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 445 of file dbusunitysessionservice.cpp.

446 {
447  Q_EMIT ShutdownRequested(false);
448  Q_EMIT shutdownRequested(false);
449 }
Q_SCRIPTABLE void ShutdownRequested(bool have_inhibitors)

§ Shutdown

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 422 of file dbusunitysessionservice.cpp.

423 {
424  d->makeLogin1Call(QStringLiteral("PowerOff"), {false});
425 }

§ ShutdownRequested

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.

§ Suspend

void DBusUnitySessionService::Suspend ( )
slot

Suspend the system

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

Definition at line 427 of file dbusunitysessionservice.cpp.

428 {
429  PromptLock();
430  d->makeLogin1Call(QStringLiteral("Suspend"), {false});
431 }

§ Unlocked

Q_SCRIPTABLE void DBusUnitySessionService::Unlocked ( )
signal

Emitted after the session has been unlocked.

§ UserName

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

Definition at line 303 of file dbusunitysessionservice.cpp.

304 {
305  return QString::fromUtf8(g_get_user_name());
306 }

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