File indexing completed on 2024-04-14 05:38:07

0001 /* Copyright (c) 2010 Sune Vuorela <sune@vuorela.dk>
0002  *
0003  * Permission is hereby granted, free of charge, to any person
0004  * obtaining a copy of this software and associated documentation
0005  * files (the "Software"), to deal in the Software without
0006  * restriction, including without limitation the rights to use,
0007  * copy, modify, merge, publish, distribute, sublicense, and/or sell
0008  * copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following
0010  * conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be
0013  * included in all copies or substantial portions of the Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
0016  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
0017  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
0018  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
0019  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
0020  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
0021  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0022  * OTHER DEALINGS IN THE SOFTWARE. */
0023 
0024 #include "RebootListener.h"
0025 #include <QFileSystemWatcher>
0026 #include <QDebug>
0027 #include <KDirWatch>
0028 #include <QTimer>
0029 #include <QFile>
0030 
0031 static const QString reboot_required_path = QStringLiteral("/run/reboot-required");
0032 
0033 AptRebootListener::AptRebootListener(QObject *parent): QObject(parent)
0034 {
0035     m_watcher = new KDirWatch(this);
0036     m_watcher->addFile(reboot_required_path);
0037     connect(m_watcher, &KDirWatch::created, this, &AptRebootListener::slotDirectoryChanged);
0038     m_timer = new QTimer(this);
0039     m_timer->setSingleShot(true);
0040     m_timer->setInterval(500);
0041     connect(m_timer, &QTimer::timeout, this, &AptRebootListener::requestReboot);
0042 }
0043 
0044 void AptRebootListener::checkForReboot()
0045 {
0046     if (QFile::exists(reboot_required_path)) {
0047         m_timer->start();
0048     }
0049 }
0050 
0051 void AptRebootListener::slotDirectoryChanged(const QString &path)
0052 {
0053     if (path == reboot_required_path) {
0054         m_timer->start();
0055     }
0056 }
0057 
0058 #include "moc_RebootListener.cpp"