File indexing completed on 2024-05-19 04:35:50

0001 // SPDX-FileCopyrightText: 2024 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 
0004 #include "setupcheck.h"
0005 
0006 #include <QStandardPaths>
0007 
0008 using namespace Qt::Literals::StringLiterals;
0009 
0010 SetupCheck::SetupCheck(QObject *parent)
0011     : QObject(parent)
0012 {
0013     check();
0014 }
0015 
0016 void SetupCheck::check()
0017 {
0018     m_missingPrograms.clear();
0019 
0020     const QStringList programs = {
0021         u"oxipng"_s,
0022         u"scour"_s,
0023         u"jpegoptim"_s,
0024         u"cwebp"_s,
0025     };
0026 
0027     for (const auto &program : programs) {
0028         if (QStandardPaths::findExecutable(program).isEmpty()) {
0029             m_missingPrograms << program;
0030         }
0031     }
0032 
0033     m_isValidSetup = m_missingPrograms.isEmpty();
0034     Q_EMIT isValidSetupChanged();
0035     Q_EMIT missingProgramsChanged();
0036 }
0037 
0038 bool SetupCheck::isValidSetup() const
0039 {
0040     return m_isValidSetup;
0041 }
0042 
0043 QStringList SetupCheck::missingPrograms() const
0044 {
0045     return m_missingPrograms;
0046 }