File indexing completed on 2024-04-21 05:31:18

0001 /*
0002     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #include "environment.h"
0007 
0008 // Qt
0009 #include <QDebug>
0010 #include <QProcess>
0011 
0012 // Plasma
0013 #include <plasma/version.h>
0014 
0015 #define LONGDURATION 240
0016 #define SHORTDURATION 40
0017 
0018 namespace Latte{
0019 
0020 const int Environment::SeparatorLength;
0021 
0022 Environment::Environment(QObject *parent)
0023     : QObject(parent)
0024 {
0025 }
0026 
0027 int Environment::separatorLength() const
0028 {
0029     return SeparatorLength;
0030 }
0031 
0032 uint Environment::shortDuration() const
0033 {
0034     return SHORTDURATION;
0035 }
0036 
0037 uint Environment::longDuration() const
0038 {
0039     return LONGDURATION;
0040 }
0041 
0042 uint Environment::frameworksVersion() const
0043 {
0044     return Plasma::version();
0045 }
0046 
0047 uint Environment::plasmaDesktopVersion()
0048 {
0049     if (m_plasmaDesktopVersion == -1) {
0050         m_plasmaDesktopVersion = identifyPlasmaDesktopVersion();
0051     }
0052 
0053     return m_plasmaDesktopVersion;
0054 }
0055 
0056 uint Environment::makeVersion(uint major, uint minor, uint release) const
0057 {
0058     return (((major) << 16) | ((minor) << 8) | (release));
0059 }
0060 
0061 uint Environment::identifyPlasmaDesktopVersion()
0062 {
0063     //! Identify Plasma Desktop version
0064     QStringList plasmaDesktopVersionParts = QString(PLASMA_WORKSPACE_VERSION).split(".");
0065 
0066     if (plasmaDesktopVersionParts.count() == 3) {
0067         qDebug() << " /////////////////////////";
0068         uint maj = plasmaDesktopVersionParts[0].toUInt();
0069         uint min = plasmaDesktopVersionParts[1].toUInt();
0070         uint rel = plasmaDesktopVersionParts[2].toUInt();
0071 
0072         if (maj > 0) {
0073             uint desktopVersion = makeVersion(maj, min, rel);
0074 
0075             QString message("Plasma Desktop version:  " + QString::number(maj) + "."
0076                     + QString::number(min) + "." + QString::number(rel)
0077                     + " (" + QString::number(desktopVersion) + ")");
0078             qDebug() << message;
0079             qDebug() << " /////////////////////////";
0080 
0081             return desktopVersion;
0082         }
0083 
0084         qDebug() << " /////////////////////////";
0085     }
0086 
0087     return 0;
0088 }
0089 
0090 }