File indexing completed on 2024-05-19 05:49:21

0001 /***************************************************************************
0002  *   Copyright © 2009 Jonathan Thomas <echidnaman@kubuntu.org>             *
0003  *   Copyright © 2009-2021 Harald Sitter <apachelogger@ubuntu.com>         *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or         *
0006  *   modify it under the terms of the GNU General Public License as        *
0007  *   published by the Free Software Foundation; either version 2 of        *
0008  *   the License or (at your option) version 3 or any later version        *
0009  *   accepted by the membership of KDE e.V. (or its successor approved     *
0010  *   by the membership of KDE e.V.), which shall act as a proxy            *
0011  *   defined in Section 14 of version 3 of the license.                    *
0012  *                                                                         *
0013  *   This program is distributed in the hope that it will be useful,       *
0014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0016  *   GNU General Public License for more details.                          *
0017  *                                                                         *
0018  *   You should have received a copy of the GNU General Public License     *
0019  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
0020  ***************************************************************************/
0021 
0022 #include "rebootevent.h"
0023 
0024 #include <QtCore/QFile>
0025 
0026 #include <KProcess>
0027 #include <KDirWatch>
0028 #warning fixme reboot event has no kde version handling anymore
0029 // #include <kdeversion.h>
0030 
0031 RebootEvent::RebootEvent(QObject* parent)
0032         : Event(parent, "Restart")
0033 {
0034     auto stampDirWatch = new KDirWatch(this);
0035     stampDirWatch->addFile("/var/lib/update-notifier/dpkg-run-stamp");
0036     connect(stampDirWatch, &KDirWatch::dirty, this, &RebootEvent::show);
0037     show(); // noop when nothing to show
0038 }
0039 
0040 RebootEvent::~RebootEvent()
0041 {}
0042 
0043 void RebootEvent::show()
0044 {
0045     if (isHidden()) {
0046         return;
0047     }
0048 
0049     if (!QFile::exists("/var/run/reboot-required")) {
0050         return;
0051     }
0052 
0053     QString icon = QString("system-reboot");
0054     QString text(i18nc("Notification when the upgrade requires a restart",
0055                        "A system restart is needed to complete the update process"));
0056     QStringList actions;
0057     actions << i18nc("Restart the computer", "Restart");
0058     actions << i18nc("Button to dismiss this notification once", "Ignore for now");
0059     actions << i18nc("Button to make this notification never show up again",
0060                      "Never show again");
0061 
0062     Event::show(icon, text, actions);
0063 }
0064 
0065 void RebootEvent::run()
0066 {
0067     // 1,1,3 == ShutdownConfirmYes ShutdownTypeReboot ShutdownModeInteractive
0068     KProcess::startDetached(QStringList() << "qdbus" << "org.kde.ksmserver" << "/KSMServer"
0069                             << "org.kde.KSMServerInterface.logout" << "1" << "1" << "3");
0070     Event::run();
0071 }