2016-03-17 04:46:40 -04:00
|
|
|
#include "endsessionwait.h"
|
|
|
|
#include "ui_endsessionwait.h"
|
|
|
|
|
|
|
|
EndSessionWait::EndSessionWait(shutdownType type, QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::EndSessionWait)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case powerOff:
|
|
|
|
ui->label->setText("Power Off");
|
2016-06-13 09:22:03 -04:00
|
|
|
ui->askWhatToDo->setVisible(false);
|
2016-03-17 04:46:40 -04:00
|
|
|
break;
|
|
|
|
case reboot:
|
|
|
|
ui->label->setText("Reboot");
|
2016-06-13 09:22:03 -04:00
|
|
|
ui->askWhatToDo->setVisible(false);
|
2016-03-17 04:46:40 -04:00
|
|
|
break;
|
|
|
|
case logout:
|
|
|
|
ui->label->setText("Log out");
|
2016-06-13 09:22:03 -04:00
|
|
|
ui->askWhatToDo->setVisible(false);
|
2016-03-17 04:46:40 -04:00
|
|
|
break;
|
2016-06-13 07:40:01 -04:00
|
|
|
case dummy:
|
|
|
|
ui->label->setText("Dummy");
|
2016-06-13 09:22:03 -04:00
|
|
|
ui->askWhatToDo->setVisible(false);
|
|
|
|
break;
|
|
|
|
case ask:
|
|
|
|
ui->poweringOff->setVisible(false);
|
2016-03-17 04:46:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
this->type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
EndSessionWait::~EndSessionWait()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
2016-06-13 09:22:03 -04:00
|
|
|
void EndSessionWait::close() {
|
|
|
|
QPropertyAnimation* anim = new QPropertyAnimation(this, "windowOpacity");
|
|
|
|
anim->setDuration(250);
|
|
|
|
anim->setStartValue(1.0);
|
|
|
|
anim->setEndValue(0.0);
|
|
|
|
connect(anim, &QPropertyAnimation::finished, [=]() {
|
|
|
|
QDialog::close();
|
|
|
|
});
|
|
|
|
anim->start(QAbstractAnimation::DeleteWhenStopped);
|
|
|
|
}
|
|
|
|
|
2016-03-17 04:46:40 -04:00
|
|
|
void EndSessionWait::showFullScreen() {
|
2016-06-13 09:22:03 -04:00
|
|
|
this->setWindowOpacity(0.0);
|
2016-03-17 04:46:40 -04:00
|
|
|
QDialog::showFullScreen();
|
2016-06-13 09:22:03 -04:00
|
|
|
QPropertyAnimation* anim = new QPropertyAnimation(this, "windowOpacity");
|
|
|
|
anim->setDuration(250);
|
|
|
|
anim->setStartValue(0.0);
|
|
|
|
anim->setEndValue(1.0);
|
|
|
|
anim->start(QAbstractAnimation::DeleteWhenStopped);
|
2016-03-17 04:46:40 -04:00
|
|
|
|
2016-06-13 09:22:03 -04:00
|
|
|
if (this->type != dummy && this->type != ask) {
|
2016-06-13 07:40:01 -04:00
|
|
|
QProcess p;
|
|
|
|
p.start("wmctrl -lp");
|
2016-03-17 04:46:40 -04:00
|
|
|
p.waitForStarted();
|
|
|
|
while (p.state() != 0) {
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
2016-06-13 07:40:01 -04:00
|
|
|
QList<WmWindow*> *wlist = new QList<WmWindow*>();
|
2016-03-17 04:46:40 -04:00
|
|
|
|
|
|
|
QString output(p.readAllStandardOutput());
|
|
|
|
for (QString window : output.split("\n")) {
|
|
|
|
QStringList parts = window.split(" ");
|
|
|
|
parts.removeAll("");
|
|
|
|
if (parts.length() >= 4) {
|
|
|
|
if (parts[2].toInt() != QCoreApplication::applicationPid()) {
|
2016-06-13 07:40:01 -04:00
|
|
|
WmWindow *w = new WmWindow(this);
|
|
|
|
w->setPID(parts[2].toInt());
|
|
|
|
QString title;
|
|
|
|
for (int i = 4; i != parts.length(); i++) {
|
|
|
|
title = title.append(" " + parts[i]);
|
|
|
|
}
|
|
|
|
title = title.remove(0, 1);
|
|
|
|
|
|
|
|
w->setTitle(title);
|
|
|
|
wlist->append(w);
|
2016-03-17 04:46:40 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-13 07:40:01 -04:00
|
|
|
|
|
|
|
for (WmWindow* window : *wlist) {
|
|
|
|
p.start("wmctrl -c " + window->title());
|
|
|
|
p.waitForStarted();
|
|
|
|
while (p.state() != 0) {
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool appsOpen = true;
|
|
|
|
|
|
|
|
while (appsOpen) {
|
|
|
|
appsOpen = false;
|
|
|
|
p.start("wmctrl -lp");
|
|
|
|
p.waitForStarted();
|
|
|
|
while (p.state() != 0) {
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
QString output(p.readAllStandardOutput());
|
|
|
|
for (QString window : output.split("\n")) {
|
|
|
|
QStringList parts = window.split(" ");
|
|
|
|
parts.removeAll("");
|
|
|
|
if (parts.length() >= 4) {
|
|
|
|
if (parts[2].toInt() != QCoreApplication::applicationPid()) {
|
|
|
|
appsOpen = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
performEndSession();
|
|
|
|
}
|
2016-03-17 04:46:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void EndSessionWait::on_pushButton_clicked()
|
|
|
|
{
|
|
|
|
QProcess p;
|
|
|
|
p.start("wmctrl -lp");
|
|
|
|
p.waitForStarted();
|
|
|
|
while (p.state() != 0) {
|
|
|
|
QApplication::processEvents();
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<WmWindow*> *wlist = new QList<WmWindow*>();
|
|
|
|
|
|
|
|
QString output(p.readAllStandardOutput());
|
|
|
|
for (QString window : output.split("\n")) {
|
|
|
|
QStringList parts = window.split(" ");
|
|
|
|
parts.removeAll("");
|
|
|
|
if (parts.length() >= 4) {
|
|
|
|
if (parts[2].toInt() != QCoreApplication::applicationPid()) {
|
|
|
|
WmWindow *w = new WmWindow(this);
|
|
|
|
w->setPID(parts[2].toInt());
|
|
|
|
QString title;
|
|
|
|
for (int i = 4; i != parts.length(); i++) {
|
|
|
|
title = title.append(" " + parts[i]);
|
|
|
|
}
|
|
|
|
title = title.remove(0, 1);
|
|
|
|
|
|
|
|
w->setTitle(title);
|
|
|
|
wlist->append(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
performEndSession();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndSessionWait::performEndSession() {
|
2016-04-01 06:05:25 -04:00
|
|
|
QFile(QDir::home().absolutePath() + "/.theshell.lck").remove();
|
|
|
|
|
2016-03-29 02:42:24 -04:00
|
|
|
QSettings settings;
|
|
|
|
QString logoutSoundPath = settings.value("sounds/logout", "").toString();
|
|
|
|
if (logoutSoundPath == "") {
|
|
|
|
logoutSoundPath = "/usr/share/sounds/contemporary/logout.ogg";
|
|
|
|
settings.setValue("sounds/logout", logoutSoundPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
QMediaPlayer* sound = new QMediaPlayer();
|
|
|
|
|
|
|
|
connect(sound, SIGNAL(error(QMediaPlayer::Error)), this, SLOT(EndSessionNow()));
|
|
|
|
connect(sound, &QMediaPlayer::stateChanged, [=]() {
|
|
|
|
if (sound->state() == QMediaPlayer::StoppedState) {
|
|
|
|
EndSessionNow();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
sound->setMedia(QUrl::fromLocalFile(logoutSoundPath));
|
|
|
|
sound->play();
|
|
|
|
|
|
|
|
QGraphicsOpacityEffect *fadeEffect = new QGraphicsOpacityEffect(this);
|
2016-06-13 09:22:03 -04:00
|
|
|
ui->poweringOff->setGraphicsEffect(fadeEffect);
|
2016-03-29 02:42:24 -04:00
|
|
|
QPropertyAnimation *a = new QPropertyAnimation(fadeEffect, "opacity");
|
|
|
|
a->setDuration(500);
|
|
|
|
a->setStartValue(1);
|
|
|
|
a->setEndValue(0);
|
|
|
|
a->start();
|
|
|
|
|
|
|
|
connect(a, &QPropertyAnimation::finished, [=]() {
|
2016-06-13 09:22:03 -04:00
|
|
|
ui->poweringOff->setVisible(false);
|
2016-03-29 02:42:24 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndSessionWait::EndSessionNow() {
|
2016-05-29 03:03:52 -04:00
|
|
|
QDBusMessage message;
|
|
|
|
QList<QVariant> arguments;
|
|
|
|
arguments.append(true);
|
2016-03-17 04:46:40 -04:00
|
|
|
switch (type) {
|
|
|
|
case powerOff:
|
2016-05-29 03:03:52 -04:00
|
|
|
message = QDBusMessage::createMethodCall("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "PowerOff");
|
|
|
|
message.setArguments(arguments);
|
|
|
|
QDBusConnection::systemBus().send(message);
|
|
|
|
|
2016-03-17 04:46:40 -04:00
|
|
|
break;
|
|
|
|
case reboot:
|
2016-05-29 03:03:52 -04:00
|
|
|
message = QDBusMessage::createMethodCall("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "Reboot");
|
|
|
|
message.setArguments(arguments);
|
|
|
|
QDBusConnection::systemBus().send(message);
|
2016-03-17 04:46:40 -04:00
|
|
|
break;
|
|
|
|
case logout:
|
|
|
|
QApplication::exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndSessionWait::on_pushButton_2_clicked()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
2016-06-13 09:22:03 -04:00
|
|
|
|
|
|
|
void EndSessionWait::on_CancelAsk_clicked()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndSessionWait::on_PowerOff_clicked()
|
|
|
|
{
|
|
|
|
ui->askWhatToDo->setVisible(false);
|
|
|
|
ui->poweringOff->setVisible(true);
|
|
|
|
this->type = powerOff;
|
2016-06-13 09:29:15 -04:00
|
|
|
ui->label->setText("Power Off");
|
2016-06-13 09:22:03 -04:00
|
|
|
this->showFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndSessionWait::on_Reboot_clicked()
|
|
|
|
{
|
|
|
|
ui->askWhatToDo->setVisible(false);
|
|
|
|
ui->poweringOff->setVisible(true);
|
|
|
|
this->type = reboot;
|
2016-06-13 09:29:15 -04:00
|
|
|
ui->label->setText("Reboot");
|
2016-06-13 09:22:03 -04:00
|
|
|
this->showFullScreen();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EndSessionWait::on_LogOut_clicked()
|
|
|
|
{
|
|
|
|
ui->askWhatToDo->setVisible(false);
|
|
|
|
ui->poweringOff->setVisible(true);
|
|
|
|
this->type = logout;
|
2016-06-13 09:29:15 -04:00
|
|
|
ui->label->setText("Log Out");
|
2016-06-13 09:22:03 -04:00
|
|
|
this->showFullScreen();
|
|
|
|
}
|