File indexing completed on 2025-02-09 06:35:13

0001 /*
0002     SPDX-FileCopyrightText: 2023 Jeremy Whiting <jeremy.whiting@collabora.com>
0003     SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 */
0005 
0006 #include "ThirdPartyEntry.h"
0007 
0008 #include <QDebug>
0009 #include <QProcess>
0010 
0011 ThirdPartyEntry::ThirdPartyEntry(const QString &scriptPath)
0012     : Entry(ki18nc("Unused but needs to be : to avoid assertion in Entry constructor", ":"), QString())
0013     , m_scriptPath(scriptPath)
0014 {
0015     for (const auto &language : {Entry::Language::System, Entry::Language::English}) {
0016         QProcess process;
0017 
0018         switch (language) {
0019         case Entry::Language::English: {
0020             QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
0021             env.insert("LANGUAGE", "en_US:C"); // Add an environment variable
0022             process.setProcessEnvironment(env);
0023             break;
0024         }
0025         case Entry::Language::System:
0026             break;
0027         }
0028 
0029         process.start(scriptPath, QStringList());
0030         process.waitForFinished();
0031         processOutput(QString::fromUtf8(process.readAllStandardOutput()).split('\n'), language);
0032     }
0033 }
0034 
0035 QString ThirdPartyEntry::localizedLabel(Language language) const
0036 {
0037     return m_labels[language];
0038 }
0039 
0040 QString ThirdPartyEntry::localizedValue(Language language) const
0041 {
0042     return m_values[language];
0043 }
0044 
0045 void ThirdPartyEntry::processOutput(const QStringList &output, Language language)
0046 {
0047     Q_ASSERT(output.size() >= 2);
0048     m_labels[language] = output.at(0);
0049     m_values[language] = output.at(1);
0050 }