File indexing completed on 2022-11-29 15:21:48

0001 // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0002 // SPDX-FileCopyrightText: 2021 Harald Sitter <sitter@kde.org>
0003 
0004 #include <QDebug>
0005 #include <QProcess>
0006 #include <QFile>
0007 
0008 #include <KAuth>
0009 #include <KLocalizedString>
0010 
0011 class NoModeSetHelper : public QObject
0012 {
0013     Q_OBJECT
0014 public Q_SLOTS:
0015     KAuth::ActionReply disable(const QVariantMap &args)
0016     {
0017         Q_UNUSED(args);
0018         if (!QFile::exists(m_grubCfg)) {
0019             auto reply = KAuth::ActionReply::HelperErrorReply();
0020             reply.setErrorDescription(xi18nc("@info:status", "Configuration file <filename>%1</filename> not found.", m_grubCfg));
0021             return reply;
0022         }
0023         if (!QFile::remove(m_grubCfg)) {
0024             auto reply = KAuth::ActionReply::HelperErrorReply();
0025             reply.setErrorDescription(xi18nc("@info:status", "Deleting the configuration file <filename>%1</filename> failed."));
0026             return reply;
0027         }
0028 
0029         QProcess proc;
0030         proc.start("/usr/sbin/update-grub2", QStringList());
0031         if (!proc.waitForFinished()) {
0032             auto reply = KAuth::ActionReply::HelperErrorReply();
0033             reply.setErrorDescription(i18nc("@info:status", "Updating the bootloader configuration timed out."));
0034             return reply;
0035         }
0036         if (proc.exitCode() != 0) {
0037             auto reply = KAuth::ActionReply::HelperErrorReply();
0038             reply.setErrorDescription(i18nc("@info:status",
0039                                             "Updating the bootloader configuration failed - exit code: %1", QString::number(proc.exitCode())));
0040             return reply;
0041         }
0042 
0043         return KAuth::ActionReply::SuccessReply();
0044     }
0045 
0046     KAuth::ActionReply grubcfgexists(const QVariantMap &args)
0047     {
0048         Q_UNUSED(args);
0049         if (!QFile::exists(m_grubCfg)) {
0050             return KAuth::ActionReply::HelperErrorReply();
0051         }
0052         return KAuth::ActionReply::SuccessReply();
0053     }
0054 
0055 private:
0056     const QString m_grubCfg = QStringLiteral("/etc/default/grub.d/neon-installation-nomodeset.cfg");
0057 };
0058 
0059 KAUTH_HELPER_MAIN("org.kde.nomodeset", NoModeSetHelper)
0060 
0061 #include "helper.moc"