source: smplayer/trunk/src/shutdown.cpp@ 176

Last change on this file since 176 was 176, checked in by Silvan Scherrer, 9 years ago

smplayer: update trunk to version 16.4

File size: 3.0 KB
Line 
1/* smplayer, GUI front-end for mplayer.
2 Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include "shutdown.h"
20#include <QProcess>
21
22#ifdef Q_OS_LINUX
23#include <QtDBus>
24#include <QDebug>
25#endif
26
27void Shutdown::shutdown() {
28#ifdef Q_OS_WIN
29 QProcess::startDetached("shutdown -s -f -t 10");
30#endif
31
32#ifdef Q_OS_LINUX
33 bool works = false;
34
35 QDBusMessage response;
36
37 QDBusInterface gnomeSessionManager("org.gnome.SessionManager", "/org/gnome/SessionManager", "org.gnome.SessionManager", QDBusConnection::sessionBus());
38 response = gnomeSessionManager.call("RequestShutdown");
39 if (response.type() == QDBusMessage::ErrorMessage) {
40 qDebug() << "Shutdown::shutdown: error:" << response.errorName() << ":" << response.errorMessage();
41 } else {
42 works = true;
43 }
44
45 if (!works) {
46 QDBusInterface kdeSessionManager("org.kde.ksmserver", "/KSMServer", "org.kde.KSMServerInterface", QDBusConnection::sessionBus());
47 response = kdeSessionManager.call("logout", 0, 2, 2);
48 if (response.type() == QDBusMessage::ErrorMessage) {
49 qDebug() << "Shutdown::shutdown: error:" << response.errorName() << ":" << response.errorMessage();
50 } else {
51 works = true;
52 }
53 }
54
55 if (!works) {
56 QDBusInterface powermanagement("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer",
57 "org.freedesktop.Hal.Device.SystemPowerManagement", QDBusConnection::systemBus());
58 response = powermanagement.call("Shutdown");
59 if (response.type() == QDBusMessage::ErrorMessage) {
60 qDebug() << "Shutdown::shutdown: error:" << response.errorName() << ":" << response.errorMessage();
61 } else {
62 works = true;
63 }
64 }
65
66 if (!works) {
67 QDBusInterface powermanagement("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager",
68 QDBusConnection::systemBus());
69 response = powermanagement.call("Stop");
70 if (response.type() == QDBusMessage::ErrorMessage) {
71 qDebug() << "Shutdown::shutdown: error:" << response.errorName() << ":" << response.errorMessage();
72 } else {
73 works = true;
74 }
75 }
76
77 if (!works) {
78 qDebug("Shutdown::shutdown: shutdown failed");
79
80 QProcess::startDetached("xmessage", QStringList() << "-buttons" << "Accept:0" << "-center" <<
81 "This is a message from SMPlayer\n"
82 "The computer should shut down now.\n"
83 "However shutdown failed.");
84 }
85#endif
86}
87
Note: See TracBrowser for help on using the repository browser.