File indexing completed on 2024-12-22 05:16:01

0001 /*
0002     localegenhelper.h
0003     SPDX-FileCopyrightText: 2021 Han Young <hanyoung@protonmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 #pragma once
0008 #include <PolkitQt1/Authority>
0009 #include <QCoreApplication>
0010 #include <QDBusContext>
0011 #include <QFile>
0012 #include <QObject>
0013 #include <QProcess>
0014 #include <QRegularExpression>
0015 #include <QTimer>
0016 
0017 #include <set>
0018 
0019 using namespace std::chrono;
0020 class LocaleGenHelper : public QObject, protected QDBusContext
0021 {
0022     Q_OBJECT
0023     Q_CLASSINFO("D-Bus Interface", "org.kde.localegenhelper.LocaleGenHelper")
0024 public:
0025     LocaleGenHelper();
0026     Q_SCRIPTABLE void enableLocales(const QStringList &locales);
0027 Q_SIGNALS:
0028     Q_SCRIPTABLE void success();
0029     Q_SCRIPTABLE void error(const QString &msg);
0030 private Q_SLOTS:
0031     void enableLocalesPrivate(PolkitQt1::Authority::Result result);
0032 
0033 private:
0034     void handleLocaleGen(int statusCode, QProcess::ExitStatus status, QProcess *process);
0035     bool editLocaleGen();
0036     void exitAfterTimeOut();
0037     bool shouldGenerate();
0038     void processLocales(const QStringList &locales);
0039 
0040     std::atomic<bool> m_isGenerating = false;
0041     bool m_comment = false;
0042     std::set<QString> m_alreadyEnabled;
0043     PolkitQt1::Authority *m_authority = nullptr;
0044     QStringList m_locales;
0045     QTimer m_timer;
0046 };