File indexing completed on 2022-11-29 15:04:34

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef LATTEENVIRONMENT_H
0007 #define LATTEENVIRONMENT_H
0008 
0009 // Qt
0010 #include <QObject>
0011 #include <QQmlEngine>
0012 #include <QJSEngine>
0013 
0014 
0015 namespace Latte{
0016 
0017 class Environment final: public QObject
0018 {
0019     Q_OBJECT
0020 
0021     Q_PROPERTY(int separatorLength READ separatorLength CONSTANT)
0022 
0023     Q_PROPERTY(uint shortDuration READ shortDuration NOTIFY shortDurationChanged)
0024     Q_PROPERTY(uint longDuration READ longDuration NOTIFY longDurationChanged)
0025 
0026     Q_PROPERTY(uint frameworksVersion READ frameworksVersion NOTIFY frameworksVersionChanged)
0027     Q_PROPERTY(uint plasmaDesktopVersion READ plasmaDesktopVersion NOTIFY plasmaDesktopVersionChanged)
0028 
0029 public:
0030     static const int SeparatorLength = 5;
0031 
0032     explicit Environment(QObject *parent = nullptr);
0033 
0034     int separatorLength() const;
0035 
0036     uint shortDuration() const;
0037     uint longDuration() const;
0038 
0039     uint frameworksVersion() const;
0040     uint plasmaDesktopVersion();
0041 
0042 public slots:
0043     Q_INVOKABLE uint makeVersion(uint major, uint minor, uint release) const;
0044 
0045 signals:
0046     void frameworksVersionChanged();
0047     void longDurationChanged();
0048     void plasmaDesktopVersionChanged();
0049     void shortDurationChanged();
0050 
0051 private:
0052     void loadPlasmaDesktopVersion();
0053 
0054     uint identifyPlasmaDesktopVersion();
0055 
0056 private:
0057     int m_plasmaDesktopVersion{ -1};
0058 
0059 };
0060 
0061 static QObject *environment_qobject_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
0062 {
0063     Q_UNUSED(engine)
0064     Q_UNUSED(scriptEngine)
0065 
0066 // NOTE: QML engine is the owner of this resource
0067     return new Environment;
0068 }
0069 
0070 }
0071 
0072 #endif